SMTStabilizer API
Public API documentation for SMTStabilizer
Loading...
Searching...
No Matches
kernel.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 XiangZhang
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#pragma once
24#include <cstddef>
25#include <vector>
26
27// #include "node/node.h"
28#include "node/node_manager.h"
29namespace stabilizer::kernel {
30
39class Kernel {
40 public:
41 Kernel() = delete;
42
50 Kernel(node::NodeManager &nm, const bool &context_propagation = true, const bool &symmetry_breaking_perturbation = true);
51
62 void apply(node::NodeManager &nm);
63
64 private:
65 std::vector<std::vector<size_t>> d_graph;
66 std::vector<std::vector<std::pair<size_t, size_t>>> d_reversed_graph;
67 std::vector<size_t> d_hash_table;
68 std::vector<size_t> d_context_hash;
69 std::vector<node::Node> d_nodes; // reversed topological order
70 std::vector<size_t> d_processing;
71
72 std::vector<size_t> d_symbols;
73 std::vector<size_t> d_unique_symbols;
74 // std::vector<size_t> d_propagate_num;
75
76 std::vector<uint8_t> d_visited;
77 std::vector<uint8_t> d_is_commutative;
78 std::vector<uint8_t> d_is_symbol;
79
80 // std::unordered_map<size_t, size_t> d_spe_hash_count;
81
83
86
92 bool is_commutative(const size_t &i, const bool &from_cache = true);
93 // void context_propagate();
94
100 void context_propagate(const std::vector<size_t> &processing, const std::vector<size_t> &symbols);
101
105 void specific_propagate();
106
110 void rebuild_graph(); // graph symbols
111
117 void sort_propagate(std::unordered_map<std::string, node::Sort> &sort_key_map, std::vector<std::vector<parser::Parser::DTTypeDecl>> &datatype_blocks);
118 // void propagate();
119
124 void propagate(const std::vector<size_t> &processing);
125};
126} // namespace stabilizer::kernel
127
128// #pragma once
129// #include <cstddef>
130// #include <vector>
131
132// #include "node/node_manager.h"
133// #include "util/node_helper.h"
134// namespace stabilizer::kernel {
135// class Kernel {
136// public:
137// Kernel(const node::NodeManager &nm);
138// ~Kernel();
139
140// bool done();
141
142// void apply();
143
144// private:
145// std::vector<std::vector<size_t>> d_graph;
146// std::vector<std::vector<std::pair<size_t, size_t>>> d_reversed_graph;
147// std::vector<size_t> d_hash_table;
148// std::vector<size_t> d_context_hash;
149// std::vector<size_t> d_processing;
150
151// std::vector<size_t> d_symbols;
152// std::vector<size_t> d_unique_symbols;
153// // std::vector<size_t> d_propagate_num;
154
155// std::vector<bool> d_visited;
156// std::vector<bool> d_is_commutative;
157// std::vector<bool> d_is_symbol;
158
159// size_t d_symbol_num;
160
161// bool is_commutative(const size_t &i, const bool &from_cache = true);
162// void context_propagate(const std::vector<size_t> &processing, const std::vector<size_t> &symbols);
163// void specific_propagate();
164// void rebuild_graph(); // graph symbols
165// void propagate(const std::vector<size_t> &processing);
166// };
167// } // namespace stabilizer::kernel
Internal canonicalization kernel for SMTStabilizer.
Definition kernel.h:39
std::vector< std::vector< size_t > > d_graph
Definition kernel.h:65
void rebuild_graph()
Keep only currently ambiguous graph regions for next iteration.
Definition kernel.cpp:306
std::vector< size_t > d_unique_symbols
Definition kernel.h:73
void apply(node::NodeManager &nm)
Run the full stabilization pass and mutate node manager state.
Definition kernel.cpp:575
std::vector< size_t > d_context_hash
Definition kernel.h:68
bool is_commutative(const size_t &i, const bool &from_cache=true)
Check whether node kind at index i is treated as commutative.
Definition kernel.cpp:110
std::vector< uint8_t > d_visited
Definition kernel.h:76
std::vector< std::vector< std::pair< size_t, size_t > > > d_reversed_graph
Definition kernel.h:66
void context_propagate(const std::vector< size_t > &processing, const std::vector< size_t > &symbols)
Run propagation to a fixed point over a selected subgraph.
Definition kernel.cpp:205
std::vector< size_t > d_hash_table
Definition kernel.h:67
void propagate(const std::vector< size_t > &processing)
One directional propagation pass on the selected nodes.
Definition kernel.cpp:157
std::vector< size_t > d_symbols
Definition kernel.h:72
std::vector< uint8_t > d_is_symbol
Definition kernel.h:78
void sort_propagate(std::unordered_map< std::string, node::Sort > &sort_key_map, std::vector< std::vector< parser::Parser::DTTypeDecl > > &datatype_blocks)
Incorporate sort/datatype structure into propagation and naming.
Definition kernel.cpp:360
bool d_symmetry_breaking_perturbation
Definition kernel.h:85
std::vector< node::Node > d_nodes
Definition kernel.h:69
std::vector< size_t > d_processing
Definition kernel.h:70
std::vector< uint8_t > d_is_commutative
Definition kernel.h:77
void specific_propagate()
Apply local perturbation to break remaining hash collisions.
Definition kernel.cpp:229