mirror of
				https://github.com/Z3Prover/z3
				synced 2025-10-31 11:42:28 +00:00 
			
		
		
		
	experimental feature to access congruence closure of SimpleSolver
This update includes an experimental feature to access a congruence closure data-structure after search.
It comes with several caveats as pre-processing is free to eliminate terms. It is therefore necessary to use a solver that does not eliminate the terms you want to track for congruence of. This is partially addressed by using SimpleSolver or incremental mode solving.
```python
from z3 import *
s = SimpleSolver()
x, y, z = Ints('x y z')
s.add(x == y)
s.add(y == z)
s.check()
print(s.root(x), s.root(y), s.root(z))
print(s.next(x), s.next(y), s.next(z))
```
			
			
This commit is contained in:
		
							parent
							
								
									c0f1f33898
								
							
						
					
					
						commit
						f6d411d54b
					
				
					 21 changed files with 145 additions and 12 deletions
				
			
		|  | @ -903,6 +903,26 @@ extern "C" { | |||
|         Z3_CATCH_RETURN(nullptr); | ||||
|     } | ||||
| 
 | ||||
|     Z3_ast Z3_API Z3_solver_congruence_root(Z3_context c, Z3_solver s, Z3_ast a) { | ||||
|         Z3_TRY; | ||||
|         LOG_Z3_solver_congruence_root(c, s, a); | ||||
|         RESET_ERROR_CODE(); | ||||
|         init_solver(c, s); | ||||
|         expr* r = to_solver_ref(s)->congruence_root(to_expr(a)); | ||||
|         RETURN_Z3(of_expr(r)); | ||||
|         Z3_CATCH_RETURN(nullptr); | ||||
|     } | ||||
| 
 | ||||
|     Z3_ast Z3_API Z3_solver_congruence_next(Z3_context c, Z3_solver s, Z3_ast a) { | ||||
|         Z3_TRY; | ||||
|         LOG_Z3_solver_congruence_next(c, s, a); | ||||
|         RESET_ERROR_CODE(); | ||||
|         init_solver(c, s); | ||||
|         expr* sib = to_solver_ref(s)->congruence_next(to_expr(a)); | ||||
|         RETURN_Z3(of_expr(sib)); | ||||
|         Z3_CATCH_RETURN(nullptr); | ||||
|     } | ||||
| 
 | ||||
|     class api_context_obj : public user_propagator::context_obj { | ||||
|         api::context* c; | ||||
|     public: | ||||
|  |  | |||
|  | @ -7241,6 +7241,22 @@ class Solver(Z3PPObject): | |||
|         cube are likely more useful to cube on.""" | ||||
|         return self.cube_vs | ||||
| 
 | ||||
|     def root(self, t): | ||||
|         t = _py2expr(t, self.ctx) | ||||
|         """Retrieve congruence closure root of the term t relative to the current search state | ||||
|         The function primarily works for SimpleSolver. Terms and variables that are | ||||
|         eliminated during pre-processing are not visible to the congruence closure. | ||||
|         """ | ||||
|         return _to_expr_ref(Z3_solver_congruence_root(self.ctx.ref(), self.solver, t.ast), self.ctx) | ||||
| 
 | ||||
|     def next(self, t): | ||||
|         t = _py2expr(t, self.ctx) | ||||
|         """Retrieve congruence closure sibling of the term t relative to the current search state | ||||
|         The function primarily works for SimpleSolver. Terms and variables that are | ||||
|         eliminated during pre-processing are not visible to the congruence closure. | ||||
|         """ | ||||
|         return _to_expr_ref(Z3_solver_congruence_next(self.ctx.ref(), self.solver, t.ast), self.ctx) | ||||
| 
 | ||||
|     def proof(self): | ||||
|         """Return a proof for the last `check()`. Proof construction must be enabled.""" | ||||
|         return _to_expr_ref(Z3_solver_get_proof(self.ctx.ref(), self.solver), self.ctx) | ||||
|  |  | |||
|  | @ -6882,6 +6882,26 @@ extern "C" { | |||
|     */ | ||||
|     void Z3_API Z3_solver_get_levels(Z3_context c, Z3_solver s, Z3_ast_vector literals, unsigned sz,  unsigned levels[]); | ||||
| 
 | ||||
|     /**
 | ||||
|        \brief retrieve the congruence closure root of an expression. | ||||
|        The root is retrieved relative to the state where the solver was in when it completed. | ||||
|        If it completed during a set of case splits, the congruence roots are relative to these case splits. | ||||
|        That is, the congruences are not consequences but they are true under the current state. | ||||
| 
 | ||||
|        def_API('Z3_solver_congruence_root', AST, (_in(CONTEXT), _in(SOLVER), _in(AST))) | ||||
|     */ | ||||
|     Z3_ast Z3_API Z3_solver_congruence_root(Z3_context c, Z3_solver s, Z3_ast a); | ||||
| 
 | ||||
| 
 | ||||
|     /**
 | ||||
|        \brief retrieve the next expression in the congruence class. The set of congruent siblings form a cyclic list. | ||||
|        Repeated calls on the siblings will result in returning to the original expression. | ||||
| 
 | ||||
|        def_API('Z3_solver_congruence_next', AST, (_in(CONTEXT), _in(SOLVER), _in(AST))) | ||||
|     */ | ||||
|     Z3_ast Z3_API Z3_solver_congruence_next(Z3_context c, Z3_solver s, Z3_ast a); | ||||
| 
 | ||||
| 
 | ||||
|     /**
 | ||||
|        \brief register a callback to that retrieves assumed, inferred and deleted clauses during search. | ||||
|         | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue