z3 0.0.20180624 → 0.0.20211213
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -4
- data/Rakefile +15 -8
- data/examples/abc_path +187 -0
- data/examples/abc_path-1.txt +7 -0
- data/examples/algebra_problems +12 -12
- data/examples/aquarium +133 -0
- data/examples/aquarium-1.txt +11 -0
- data/examples/bridges +2 -2
- data/examples/cats_organized_neatly +133 -0
- data/examples/cats_organized_neatly-10.txt +15 -0
- data/examples/cats_organized_neatly-3.txt +8 -0
- data/examples/cats_organized_neatly-48.txt +32 -0
- data/examples/circuit_problems +4 -4
- data/examples/clogic_puzzle +2 -2
- data/examples/color_nonogram +150 -0
- data/examples/color_nonogram-1.txt +23 -0
- data/examples/crossflip +2 -4
- data/examples/dominion +153 -0
- data/examples/dominion-1.txt +8 -0
- data/examples/dominosa +133 -0
- data/examples/dominosa-1.txt +8 -0
- data/examples/eulero +99 -0
- data/examples/eulero-1.txt +5 -0
- data/examples/four_hackers_puzzle +2 -2
- data/examples/futoshiki +128 -0
- data/examples/futoshiki-1.txt +17 -0
- data/examples/kakurasu +73 -0
- data/examples/kakurasu-1.txt +2 -0
- data/examples/kakuro +2 -2
- data/examples/killer_sudoku +88 -0
- data/examples/killer_sudoku-1.txt +17 -0
- data/examples/killer_sudoku-2.txt +53 -0
- data/examples/kinematics_problems +20 -20
- data/examples/knights_puzzle +2 -2
- data/examples/kropki +100 -0
- data/examples/kropki-1.txt +13 -0
- data/examples/letter_connections +2 -2
- data/examples/light_up +2 -2
- data/examples/minisudoku +2 -2
- data/examples/miracle_sudoku +135 -0
- data/examples/miracle_sudoku-1.txt +9 -0
- data/examples/mortal_coil_puzzle +2 -2
- data/examples/nanro +245 -0
- data/examples/nanro-1.txt +8 -0
- data/examples/nine_clocks +106 -0
- data/examples/nonogram +2 -2
- data/examples/pyramid_nonogram +2 -2
- data/examples/regexp_crossword_solver +2 -2
- data/examples/regexp_solver +2 -2
- data/examples/renzoku +124 -0
- data/examples/renzoku-1.txt +17 -0
- data/examples/sandwich_sudoku +101 -0
- data/examples/sandwich_sudoku-1.txt +10 -0
- data/examples/selfref +2 -2
- data/examples/simple_regexp_parser.rb +58 -56
- data/examples/skyscrapers +118 -0
- data/examples/skyscrapers-1.txt +6 -0
- data/examples/skyscrapers-2.txt +11 -0
- data/examples/star_battle +134 -0
- data/examples/star_battle-1.txt +10 -0
- data/examples/stitches +180 -0
- data/examples/stitches-1.txt +11 -0
- data/examples/sudoku +2 -2
- data/examples/suguru +199 -0
- data/examples/suguru-1.txt +17 -0
- data/examples/verbal_arithmetic +2 -2
- data/examples/yajilin +268 -0
- data/examples/yajilin-1.txt +10 -0
- data/lib/z3/ast.rb +8 -0
- data/lib/z3/expr/bitvec_expr.rb +10 -0
- data/lib/z3/expr/expr.rb +16 -15
- data/lib/z3/low_level.rb +6 -2
- data/lib/z3/low_level_auto.rb +180 -36
- data/lib/z3/optimize.rb +5 -4
- data/lib/z3/printer.rb +29 -1
- data/lib/z3/sort/bitvec_sort.rb +1 -0
- data/lib/z3/sort/sort.rb +9 -5
- data/lib/z3/very_low_level.rb +8 -5
- data/lib/z3/very_low_level_auto.rb +45 -9
- data/spec/bitvec_expr_spec.rb +35 -21
- data/spec/bitvec_sort_spec.rb +4 -0
- data/spec/expr_spec.rb +62 -0
- data/spec/integration/abc_path_spec.rb +21 -0
- data/spec/integration/aquarium_spec.rb +27 -0
- data/spec/integration/cats_organized_neatly_spec.rb +14 -0
- data/spec/integration/color_nonogram_spec.rb +28 -0
- data/spec/integration/dominion_spec.rb +14 -0
- data/spec/integration/dominosa_spec.rb +21 -0
- data/spec/integration/eulero_spec.rb +11 -0
- data/spec/integration/futoshiki_spec.rb +23 -0
- data/spec/integration/kakurasu_spec.rb +18 -0
- data/spec/integration/killer_sudoku_spec.rb +10 -0
- data/spec/integration/knights_puzzle_spec.rb +11 -11
- data/spec/integration/kropki_spec.rb +19 -0
- data/spec/integration/miracle_sudoku_spec.rb +15 -0
- data/spec/integration/mortal_coil_puzzle_spec.rb +8 -6
- data/spec/integration/nanro_spec.rb +39 -0
- data/spec/integration/nine_clocks_spec.rb +30 -0
- data/spec/integration/oneofus_spec.rb +7 -15
- data/spec/integration/regexp_crossword_solver_spec.rb +1 -1
- data/spec/integration/renzoku_spec.rb +23 -0
- data/spec/integration/sandwich_sudoku_spec.rb +15 -0
- data/spec/integration/skyscraper_spec.rb +10 -0
- data/spec/integration/star_battle_spec.rb +27 -0
- data/spec/integration/stitches_spec.rb +25 -0
- data/spec/integration/suguru_spec.rb +23 -0
- data/spec/integration/yajilin_spec.rb +25 -0
- data/spec/interface_spec.rb +18 -0
- data/spec/optimize_spec.rb +6 -4
- data/spec/printer_spec.rb +30 -0
- data/spec/set_expr_spec.rb +14 -8
- data/spec/solver_spec.rb +4 -5
- data/spec/spec_helper.rb +15 -0
- metadata +104 -24
data/lib/z3/ast.rb
CHANGED
data/lib/z3/expr/bitvec_expr.rb
CHANGED
@@ -64,6 +64,16 @@ module Z3
|
|
64
64
|
sort.new(LowLevel.mk_rotate_right(num, self))
|
65
65
|
end
|
66
66
|
|
67
|
+
def extract(hi, lo)
|
68
|
+
raise Z3::Exception, "Trying to extract bits out of range" unless sort.size > hi and hi >= lo and lo >= 0
|
69
|
+
BitvecSort.new(hi - lo + 1).new(LowLevel.mk_extract(hi, lo, self))
|
70
|
+
end
|
71
|
+
|
72
|
+
def concat(other)
|
73
|
+
raise Z3::Exception, "Can only concatenate another Bitvec" unless other.is_a?(BitvecExpr)
|
74
|
+
BitvecSort.new(sort.size + other.sort.size).new(LowLevel.mk_concat(self, other))
|
75
|
+
end
|
76
|
+
|
67
77
|
def zero_ext(size)
|
68
78
|
BitvecSort.new(sort.size + size).new(LowLevel.mk_zero_ext(size, self))
|
69
79
|
end
|
data/lib/z3/expr/expr.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Z3
|
2
2
|
class Expr < AST
|
3
3
|
attr_reader :sort
|
4
|
+
|
4
5
|
def initialize(_ast, sort)
|
5
6
|
super(_ast)
|
6
7
|
@sort = sort
|
7
|
-
raise Z3::Exception, "Values must have AST kind numeral or
|
8
|
+
raise Z3::Exception, "Values must have AST kind numeral, app, or quantifier" unless [:numeral, :app, :quantifier].include?(ast_kind)
|
8
9
|
end
|
9
10
|
|
10
11
|
def inspect
|
@@ -22,7 +23,7 @@ module Z3
|
|
22
23
|
class << self
|
23
24
|
def coerce_to_same_sort(*args)
|
24
25
|
# This will raise exception unless one of the sorts is highest
|
25
|
-
max_sort = args.map{|a| a.is_a?(Expr) ? a.sort : Expr.sort_for_const(a)}.max
|
26
|
+
max_sort = args.map { |a| a.is_a?(Expr) ? a.sort : Expr.sort_for_const(a) }.max
|
26
27
|
args.map do |a|
|
27
28
|
max_sort.cast(a)
|
28
29
|
end
|
@@ -110,11 +111,11 @@ module Z3
|
|
110
111
|
when BoolExpr
|
111
112
|
BoolSort.new.new(Z3::LowLevel.mk_and(args))
|
112
113
|
when BitvecExpr
|
113
|
-
args.inject do |a,b|
|
114
|
+
args.inject do |a, b|
|
114
115
|
a.sort.new(Z3::LowLevel.mk_bvand(a, b))
|
115
116
|
end
|
116
117
|
else
|
117
|
-
raise Z3::Exception, "Can't perform logic operations on #{
|
118
|
+
raise Z3::Exception, "Can't perform logic operations on #{args[0].sort} exprs, only Bool and Bitvec"
|
118
119
|
end
|
119
120
|
end
|
120
121
|
|
@@ -124,11 +125,11 @@ module Z3
|
|
124
125
|
when BoolExpr
|
125
126
|
BoolSort.new.new(Z3::LowLevel.mk_or(args))
|
126
127
|
when BitvecExpr
|
127
|
-
args.inject do |a,b|
|
128
|
+
args.inject do |a, b|
|
128
129
|
a.sort.new(Z3::LowLevel.mk_bvor(a, b))
|
129
130
|
end
|
130
131
|
else
|
131
|
-
raise Z3::Exception, "Can't perform logic operations on #{
|
132
|
+
raise Z3::Exception, "Can't perform logic operations on #{args[0].sort} exprs, only Bool and Bitvec"
|
132
133
|
end
|
133
134
|
end
|
134
135
|
|
@@ -136,15 +137,15 @@ module Z3
|
|
136
137
|
args = coerce_to_same_sort(*args)
|
137
138
|
case args[0]
|
138
139
|
when BoolExpr
|
139
|
-
args.inject do |a,b|
|
140
|
+
args.inject do |a, b|
|
140
141
|
BoolSort.new.new(Z3::LowLevel.mk_xor(a, b))
|
141
142
|
end
|
142
143
|
when BitvecExpr
|
143
|
-
args.inject do |a,b|
|
144
|
+
args.inject do |a, b|
|
144
145
|
a.sort.new(Z3::LowLevel.mk_bvxor(a, b))
|
145
146
|
end
|
146
147
|
else
|
147
|
-
raise Z3::Exception, "Can't perform logic operations on #{
|
148
|
+
raise Z3::Exception, "Can't perform logic operations on #{args[0].sort} exprs, only Bool and Bitvec"
|
148
149
|
end
|
149
150
|
end
|
150
151
|
|
@@ -155,8 +156,8 @@ module Z3
|
|
155
156
|
when ArithExpr
|
156
157
|
args[0].sort.new(LowLevel.mk_add(args))
|
157
158
|
when BitvecExpr
|
158
|
-
args.inject do |a,b|
|
159
|
-
a.sort.new(LowLevel.mk_bvadd(a,b))
|
159
|
+
args.inject do |a, b|
|
160
|
+
a.sort.new(LowLevel.mk_bvadd(a, b))
|
160
161
|
end
|
161
162
|
else
|
162
163
|
raise Z3::Exception, "Can't perform logic operations on #{args[0].sort} exprs, only Int/Real/Bitvec"
|
@@ -169,8 +170,8 @@ module Z3
|
|
169
170
|
when ArithExpr
|
170
171
|
args[0].sort.new(LowLevel.mk_sub(args))
|
171
172
|
when BitvecExpr
|
172
|
-
args.inject do |a,b|
|
173
|
-
a.sort.new(LowLevel.mk_bvsub(a,b))
|
173
|
+
args.inject do |a, b|
|
174
|
+
a.sort.new(LowLevel.mk_bvsub(a, b))
|
174
175
|
end
|
175
176
|
else
|
176
177
|
raise Z3::Exception, "Can't perform logic operations on #{args[0].sort} values, only Int/Real/Bitvec"
|
@@ -183,8 +184,8 @@ module Z3
|
|
183
184
|
when ArithExpr
|
184
185
|
args[0].sort.new(LowLevel.mk_mul(args))
|
185
186
|
when BitvecExpr
|
186
|
-
args.inject do |a,b|
|
187
|
-
a.sort.new(LowLevel.mk_bvmul(a,b))
|
187
|
+
args.inject do |a, b|
|
188
|
+
a.sort.new(LowLevel.mk_bvmul(a, b))
|
188
189
|
end
|
189
190
|
else
|
190
191
|
raise Z3::Exception, "Can't perform logic operations on #{args[0].sort} values, only Int/Real/Bitvec"
|
data/lib/z3/low_level.rb
CHANGED
@@ -9,7 +9,7 @@ module Z3
|
|
9
9
|
b = FFI::MemoryPointer.new(:int)
|
10
10
|
c = FFI::MemoryPointer.new(:int)
|
11
11
|
d = FFI::MemoryPointer.new(:int)
|
12
|
-
Z3::VeryLowLevel.Z3_get_version(a,b,c,d)
|
12
|
+
Z3::VeryLowLevel.Z3_get_version(a, b, c, d)
|
13
13
|
[a.get_uint(0), b.get_uint(0), c.get_uint(0), d.get_uint(0)]
|
14
14
|
end
|
15
15
|
|
@@ -63,6 +63,10 @@ module Z3
|
|
63
63
|
Z3::VeryLowLevel.Z3_mk_set_intersect(_ctx_pointer, asts.size, asts_vector(asts))
|
64
64
|
end
|
65
65
|
|
66
|
+
def optimize_check(optimize, asts)
|
67
|
+
Z3::VeryLowLevel.Z3_optimize_check(_ctx_pointer, optimize._optimize, asts.size, asts_vector(asts))
|
68
|
+
end
|
69
|
+
|
66
70
|
# Should be private
|
67
71
|
|
68
72
|
def unpack_ast_vector(_ast_vector)
|
@@ -96,7 +100,7 @@ module Z3
|
|
96
100
|
private
|
97
101
|
|
98
102
|
def asts_vector(args)
|
99
|
-
raise if args.empty?
|
103
|
+
# raise if args.empty?
|
100
104
|
c_args = FFI::MemoryPointer.new(:pointer, args.size)
|
101
105
|
c_args.write_array_of_pointer args.map(&:_ast)
|
102
106
|
c_args
|
data/lib/z3/low_level_auto.rb
CHANGED
@@ -25,6 +25,14 @@ module Z3
|
|
25
25
|
VeryLowLevel.Z3_algebraic_ge(_ctx_pointer, ast1._ast, ast2._ast)
|
26
26
|
end
|
27
27
|
|
28
|
+
def algebraic_get_i(ast) #=> :uint
|
29
|
+
VeryLowLevel.Z3_algebraic_get_i(_ctx_pointer, ast._ast)
|
30
|
+
end
|
31
|
+
|
32
|
+
def algebraic_get_poly(ast) #=> :ast_vector_pointer
|
33
|
+
VeryLowLevel.Z3_algebraic_get_poly(_ctx_pointer, ast._ast)
|
34
|
+
end
|
35
|
+
|
28
36
|
def algebraic_gt(ast1, ast2) #=> :bool
|
29
37
|
VeryLowLevel.Z3_algebraic_gt(_ctx_pointer, ast1._ast, ast2._ast)
|
30
38
|
end
|
@@ -77,10 +85,6 @@ module Z3
|
|
77
85
|
VeryLowLevel.Z3_algebraic_sub(_ctx_pointer, ast1._ast, ast2._ast)
|
78
86
|
end
|
79
87
|
|
80
|
-
def apply_result_convert_model(apply_result, num, model) #=> :model_pointer
|
81
|
-
VeryLowLevel.Z3_apply_result_convert_model(_ctx_pointer, apply_result._apply_result, num, model._model)
|
82
|
-
end
|
83
|
-
|
84
88
|
def apply_result_dec_ref(apply_result) #=> :void
|
85
89
|
VeryLowLevel.Z3_apply_result_dec_ref(_ctx_pointer, apply_result._apply_result)
|
86
90
|
end
|
@@ -213,6 +217,10 @@ module Z3
|
|
213
217
|
VeryLowLevel.Z3_enable_trace(str)
|
214
218
|
end
|
215
219
|
|
220
|
+
def eval_smtlib2_string(str) #=> :string
|
221
|
+
VeryLowLevel.Z3_eval_smtlib2_string(_ctx_pointer, str)
|
222
|
+
end
|
223
|
+
|
216
224
|
def finalize_memory #=> :void
|
217
225
|
VeryLowLevel.Z3_finalize_memory()
|
218
226
|
end
|
@@ -301,14 +309,6 @@ module Z3
|
|
301
309
|
VeryLowLevel.Z3_fixedpoint_inc_ref(_ctx_pointer, fixedpoint._fixedpoint)
|
302
310
|
end
|
303
311
|
|
304
|
-
def fixedpoint_pop(fixedpoint) #=> :void
|
305
|
-
VeryLowLevel.Z3_fixedpoint_pop(_ctx_pointer, fixedpoint._fixedpoint)
|
306
|
-
end
|
307
|
-
|
308
|
-
def fixedpoint_push(fixedpoint) #=> :void
|
309
|
-
VeryLowLevel.Z3_fixedpoint_push(_ctx_pointer, fixedpoint._fixedpoint)
|
310
|
-
end
|
311
|
-
|
312
312
|
def fixedpoint_query(fixedpoint, ast) #=> :int
|
313
313
|
VeryLowLevel.Z3_fixedpoint_query(_ctx_pointer, fixedpoint._fixedpoint, ast._ast)
|
314
314
|
end
|
@@ -581,10 +581,6 @@ module Z3
|
|
581
581
|
VeryLowLevel.Z3_get_index_value(_ctx_pointer, ast._ast)
|
582
582
|
end
|
583
583
|
|
584
|
-
def get_interpolant(ast1, ast2, params) #=> :ast_vector_pointer
|
585
|
-
VeryLowLevel.Z3_get_interpolant(_ctx_pointer, ast1._ast, ast2._ast, params._params)
|
586
|
-
end
|
587
|
-
|
588
584
|
def get_num_probes #=> :uint
|
589
585
|
VeryLowLevel.Z3_get_num_probes(_ctx_pointer)
|
590
586
|
end
|
@@ -593,10 +589,18 @@ module Z3
|
|
593
589
|
VeryLowLevel.Z3_get_num_tactics(_ctx_pointer)
|
594
590
|
end
|
595
591
|
|
592
|
+
def get_numeral_binary_string(ast) #=> :string
|
593
|
+
VeryLowLevel.Z3_get_numeral_binary_string(_ctx_pointer, ast._ast)
|
594
|
+
end
|
595
|
+
|
596
596
|
def get_numeral_decimal_string(ast, num) #=> :string
|
597
597
|
VeryLowLevel.Z3_get_numeral_decimal_string(_ctx_pointer, ast._ast, num)
|
598
598
|
end
|
599
599
|
|
600
|
+
def get_numeral_double(ast) #=> :double
|
601
|
+
VeryLowLevel.Z3_get_numeral_double(_ctx_pointer, ast._ast)
|
602
|
+
end
|
603
|
+
|
600
604
|
def get_numeral_string(ast) #=> :string
|
601
605
|
VeryLowLevel.Z3_get_numeral_string(_ctx_pointer, ast._ast)
|
602
606
|
end
|
@@ -605,10 +609,6 @@ module Z3
|
|
605
609
|
VeryLowLevel.Z3_get_numerator(_ctx_pointer, ast._ast)
|
606
610
|
end
|
607
611
|
|
608
|
-
def get_parser_error #=> :string
|
609
|
-
VeryLowLevel.Z3_get_parser_error(_ctx_pointer)
|
610
|
-
end
|
611
|
-
|
612
612
|
def get_pattern(pattern, num) #=> :ast_pointer
|
613
613
|
VeryLowLevel.Z3_get_pattern(_ctx_pointer, pattern._ast, num)
|
614
614
|
end
|
@@ -661,6 +661,10 @@ module Z3
|
|
661
661
|
VeryLowLevel.Z3_get_range(_ctx_pointer, func_decl._ast)
|
662
662
|
end
|
663
663
|
|
664
|
+
def get_re_sort_basis(sort) #=> :sort_pointer
|
665
|
+
VeryLowLevel.Z3_get_re_sort_basis(_ctx_pointer, sort._ast)
|
666
|
+
end
|
667
|
+
|
664
668
|
def get_relation_arity(sort) #=> :uint
|
665
669
|
VeryLowLevel.Z3_get_relation_arity(_ctx_pointer, sort._ast)
|
666
670
|
end
|
@@ -669,6 +673,10 @@ module Z3
|
|
669
673
|
VeryLowLevel.Z3_get_relation_column(_ctx_pointer, sort._ast, num)
|
670
674
|
end
|
671
675
|
|
676
|
+
def get_seq_sort_basis(sort) #=> :sort_pointer
|
677
|
+
VeryLowLevel.Z3_get_seq_sort_basis(_ctx_pointer, sort._ast)
|
678
|
+
end
|
679
|
+
|
672
680
|
def get_sort(ast) #=> :sort_pointer
|
673
681
|
VeryLowLevel.Z3_get_sort(_ctx_pointer, ast._ast)
|
674
682
|
end
|
@@ -685,6 +693,10 @@ module Z3
|
|
685
693
|
VeryLowLevel.Z3_get_sort_name(_ctx_pointer, sort._ast)
|
686
694
|
end
|
687
695
|
|
696
|
+
def get_string_length(ast) #=> :uint
|
697
|
+
VeryLowLevel.Z3_get_string_length(_ctx_pointer, ast._ast)
|
698
|
+
end
|
699
|
+
|
688
700
|
def get_symbol_int(sym) #=> :int
|
689
701
|
VeryLowLevel.Z3_get_symbol_int(_ctx_pointer, sym)
|
690
702
|
end
|
@@ -725,6 +737,10 @@ module Z3
|
|
725
737
|
VeryLowLevel.Z3_goal_assert(_ctx_pointer, goal._goal, ast._ast)
|
726
738
|
end
|
727
739
|
|
740
|
+
def goal_convert_model(goal, model) #=> :model_pointer
|
741
|
+
VeryLowLevel.Z3_goal_convert_model(_ctx_pointer, goal._goal, model._model)
|
742
|
+
end
|
743
|
+
|
728
744
|
def goal_dec_ref(goal) #=> :void
|
729
745
|
VeryLowLevel.Z3_goal_dec_ref(_ctx_pointer, goal._goal)
|
730
746
|
end
|
@@ -769,6 +785,10 @@ module Z3
|
|
769
785
|
VeryLowLevel.Z3_goal_size(_ctx_pointer, goal._goal)
|
770
786
|
end
|
771
787
|
|
788
|
+
def goal_to_dimacs_string(goal, bool) #=> :string
|
789
|
+
VeryLowLevel.Z3_goal_to_dimacs_string(_ctx_pointer, goal._goal, bool)
|
790
|
+
end
|
791
|
+
|
772
792
|
def goal_to_string(goal) #=> :string
|
773
793
|
VeryLowLevel.Z3_goal_to_string(_ctx_pointer, goal._goal)
|
774
794
|
end
|
@@ -781,10 +801,6 @@ module Z3
|
|
781
801
|
VeryLowLevel.Z3_inc_ref(_ctx_pointer, ast._ast)
|
782
802
|
end
|
783
803
|
|
784
|
-
def interpolation_profile #=> :string
|
785
|
-
VeryLowLevel.Z3_interpolation_profile(_ctx_pointer)
|
786
|
-
end
|
787
|
-
|
788
804
|
def interrupt #=> :void
|
789
805
|
VeryLowLevel.Z3_interrupt(_ctx_pointer)
|
790
806
|
end
|
@@ -801,6 +817,10 @@ module Z3
|
|
801
817
|
VeryLowLevel.Z3_is_as_array(_ctx_pointer, ast._ast)
|
802
818
|
end
|
803
819
|
|
820
|
+
def is_char_sort(sort) #=> :bool
|
821
|
+
VeryLowLevel.Z3_is_char_sort(_ctx_pointer, sort._ast)
|
822
|
+
end
|
823
|
+
|
804
824
|
def is_eq_ast(ast1, ast2) #=> :bool
|
805
825
|
VeryLowLevel.Z3_is_eq_ast(_ctx_pointer, ast1._ast, ast2._ast)
|
806
826
|
end
|
@@ -813,10 +833,18 @@ module Z3
|
|
813
833
|
VeryLowLevel.Z3_is_eq_sort(_ctx_pointer, sort1._ast, sort2._ast)
|
814
834
|
end
|
815
835
|
|
836
|
+
def is_lambda(ast) #=> :bool
|
837
|
+
VeryLowLevel.Z3_is_lambda(_ctx_pointer, ast._ast)
|
838
|
+
end
|
839
|
+
|
816
840
|
def is_numeral_ast(ast) #=> :bool
|
817
841
|
VeryLowLevel.Z3_is_numeral_ast(_ctx_pointer, ast._ast)
|
818
842
|
end
|
819
843
|
|
844
|
+
def is_quantifier_exists(ast) #=> :bool
|
845
|
+
VeryLowLevel.Z3_is_quantifier_exists(_ctx_pointer, ast._ast)
|
846
|
+
end
|
847
|
+
|
820
848
|
def is_quantifier_forall(ast) #=> :bool
|
821
849
|
VeryLowLevel.Z3_is_quantifier_forall(_ctx_pointer, ast._ast)
|
822
850
|
end
|
@@ -1009,6 +1037,30 @@ module Z3
|
|
1009
1037
|
VeryLowLevel.Z3_mk_bvxor(_ctx_pointer, ast1._ast, ast2._ast)
|
1010
1038
|
end
|
1011
1039
|
|
1040
|
+
def mk_char_from_bv(ast) #=> :ast_pointer
|
1041
|
+
VeryLowLevel.Z3_mk_char_from_bv(_ctx_pointer, ast._ast)
|
1042
|
+
end
|
1043
|
+
|
1044
|
+
def mk_char_is_digit(ast) #=> :ast_pointer
|
1045
|
+
VeryLowLevel.Z3_mk_char_is_digit(_ctx_pointer, ast._ast)
|
1046
|
+
end
|
1047
|
+
|
1048
|
+
def mk_char_le(ast1, ast2) #=> :ast_pointer
|
1049
|
+
VeryLowLevel.Z3_mk_char_le(_ctx_pointer, ast1._ast, ast2._ast)
|
1050
|
+
end
|
1051
|
+
|
1052
|
+
def mk_char_sort #=> :sort_pointer
|
1053
|
+
VeryLowLevel.Z3_mk_char_sort(_ctx_pointer)
|
1054
|
+
end
|
1055
|
+
|
1056
|
+
def mk_char_to_bv(ast) #=> :ast_pointer
|
1057
|
+
VeryLowLevel.Z3_mk_char_to_bv(_ctx_pointer, ast._ast)
|
1058
|
+
end
|
1059
|
+
|
1060
|
+
def mk_char_to_int(ast) #=> :ast_pointer
|
1061
|
+
VeryLowLevel.Z3_mk_char_to_int(_ctx_pointer, ast._ast)
|
1062
|
+
end
|
1063
|
+
|
1012
1064
|
def mk_concat(ast1, ast2) #=> :ast_pointer
|
1013
1065
|
VeryLowLevel.Z3_mk_concat(_ctx_pointer, ast1._ast, ast2._ast)
|
1014
1066
|
end
|
@@ -1033,6 +1085,10 @@ module Z3
|
|
1033
1085
|
VeryLowLevel.Z3_mk_div(_ctx_pointer, ast1._ast, ast2._ast)
|
1034
1086
|
end
|
1035
1087
|
|
1088
|
+
def mk_divides(ast1, ast2) #=> :ast_pointer
|
1089
|
+
VeryLowLevel.Z3_mk_divides(_ctx_pointer, ast1._ast, ast2._ast)
|
1090
|
+
end
|
1091
|
+
|
1036
1092
|
def mk_empty_set(sort) #=> :ast_pointer
|
1037
1093
|
VeryLowLevel.Z3_mk_empty_set(_ctx_pointer, sort._ast)
|
1038
1094
|
end
|
@@ -1349,14 +1405,6 @@ module Z3
|
|
1349
1405
|
VeryLowLevel.Z3_mk_int_to_str(_ctx_pointer, ast._ast)
|
1350
1406
|
end
|
1351
1407
|
|
1352
|
-
def mk_interpolant(ast) #=> :ast_pointer
|
1353
|
-
VeryLowLevel.Z3_mk_interpolant(_ctx_pointer, ast._ast)
|
1354
|
-
end
|
1355
|
-
|
1356
|
-
def mk_interpolation_context(config) #=> :ctx_pointer
|
1357
|
-
VeryLowLevel.Z3_mk_interpolation_context(config._config)
|
1358
|
-
end
|
1359
|
-
|
1360
1408
|
def mk_is_int(ast) #=> :ast_pointer
|
1361
1409
|
VeryLowLevel.Z3_mk_is_int(_ctx_pointer, ast._ast)
|
1362
1410
|
end
|
@@ -1369,6 +1417,14 @@ module Z3
|
|
1369
1417
|
VeryLowLevel.Z3_mk_le(_ctx_pointer, ast1._ast, ast2._ast)
|
1370
1418
|
end
|
1371
1419
|
|
1420
|
+
def mk_linear_order(sort, num) #=> :func_decl_pointer
|
1421
|
+
VeryLowLevel.Z3_mk_linear_order(_ctx_pointer, sort._ast, num)
|
1422
|
+
end
|
1423
|
+
|
1424
|
+
def mk_lstring(num, str) #=> :ast_pointer
|
1425
|
+
VeryLowLevel.Z3_mk_lstring(_ctx_pointer, num, str)
|
1426
|
+
end
|
1427
|
+
|
1372
1428
|
def mk_lt(ast1, ast2) #=> :ast_pointer
|
1373
1429
|
VeryLowLevel.Z3_mk_lt(_ctx_pointer, ast1._ast, ast2._ast)
|
1374
1430
|
end
|
@@ -1397,6 +1453,14 @@ module Z3
|
|
1397
1453
|
VeryLowLevel.Z3_mk_params(_ctx_pointer)
|
1398
1454
|
end
|
1399
1455
|
|
1456
|
+
def mk_partial_order(sort, num) #=> :func_decl_pointer
|
1457
|
+
VeryLowLevel.Z3_mk_partial_order(_ctx_pointer, sort._ast, num)
|
1458
|
+
end
|
1459
|
+
|
1460
|
+
def mk_piecewise_linear_order(sort, num) #=> :func_decl_pointer
|
1461
|
+
VeryLowLevel.Z3_mk_piecewise_linear_order(_ctx_pointer, sort._ast, num)
|
1462
|
+
end
|
1463
|
+
|
1400
1464
|
def mk_power(ast1, ast2) #=> :ast_pointer
|
1401
1465
|
VeryLowLevel.Z3_mk_power(_ctx_pointer, ast1._ast, ast2._ast)
|
1402
1466
|
end
|
@@ -1405,6 +1469,10 @@ module Z3
|
|
1405
1469
|
VeryLowLevel.Z3_mk_probe(_ctx_pointer, str)
|
1406
1470
|
end
|
1407
1471
|
|
1472
|
+
def mk_re_allchar(sort) #=> :ast_pointer
|
1473
|
+
VeryLowLevel.Z3_mk_re_allchar(_ctx_pointer, sort._ast)
|
1474
|
+
end
|
1475
|
+
|
1408
1476
|
def mk_re_complement(ast) #=> :ast_pointer
|
1409
1477
|
VeryLowLevel.Z3_mk_re_complement(_ctx_pointer, ast._ast)
|
1410
1478
|
end
|
@@ -1453,10 +1521,22 @@ module Z3
|
|
1453
1521
|
VeryLowLevel.Z3_mk_rotate_right(_ctx_pointer, num, ast._ast)
|
1454
1522
|
end
|
1455
1523
|
|
1524
|
+
def mk_sbv_to_str(ast) #=> :ast_pointer
|
1525
|
+
VeryLowLevel.Z3_mk_sbv_to_str(_ctx_pointer, ast._ast)
|
1526
|
+
end
|
1527
|
+
|
1456
1528
|
def mk_select(ast1, ast2) #=> :ast_pointer
|
1457
1529
|
VeryLowLevel.Z3_mk_select(_ctx_pointer, ast1._ast, ast2._ast)
|
1458
1530
|
end
|
1459
1531
|
|
1532
|
+
def mk_seq_last_index(ast1, ast2) #=> :ast_pointer
|
1533
|
+
VeryLowLevel.Z3_mk_seq_last_index(_ctx_pointer, ast1._ast, ast2._ast)
|
1534
|
+
end
|
1535
|
+
|
1536
|
+
def mk_seq_nth(ast1, ast2) #=> :ast_pointer
|
1537
|
+
VeryLowLevel.Z3_mk_seq_nth(_ctx_pointer, ast1._ast, ast2._ast)
|
1538
|
+
end
|
1539
|
+
|
1460
1540
|
def mk_set_add(ast1, ast2) #=> :ast_pointer
|
1461
1541
|
VeryLowLevel.Z3_mk_set_add(_ctx_pointer, ast1._ast, ast2._ast)
|
1462
1542
|
end
|
@@ -1473,6 +1553,10 @@ module Z3
|
|
1473
1553
|
VeryLowLevel.Z3_mk_set_difference(_ctx_pointer, ast1._ast, ast2._ast)
|
1474
1554
|
end
|
1475
1555
|
|
1556
|
+
def mk_set_has_size(ast1, ast2) #=> :ast_pointer
|
1557
|
+
VeryLowLevel.Z3_mk_set_has_size(_ctx_pointer, ast1._ast, ast2._ast)
|
1558
|
+
end
|
1559
|
+
|
1476
1560
|
def mk_set_member(ast1, ast2) #=> :ast_pointer
|
1477
1561
|
VeryLowLevel.Z3_mk_set_member(_ctx_pointer, ast1._ast, ast2._ast)
|
1478
1562
|
end
|
@@ -1509,6 +1593,14 @@ module Z3
|
|
1509
1593
|
VeryLowLevel.Z3_mk_store(_ctx_pointer, ast1._ast, ast2._ast, ast3._ast)
|
1510
1594
|
end
|
1511
1595
|
|
1596
|
+
def mk_str_le(ast1, ast2) #=> :ast_pointer
|
1597
|
+
VeryLowLevel.Z3_mk_str_le(_ctx_pointer, ast1._ast, ast2._ast)
|
1598
|
+
end
|
1599
|
+
|
1600
|
+
def mk_str_lt(ast1, ast2) #=> :ast_pointer
|
1601
|
+
VeryLowLevel.Z3_mk_str_lt(_ctx_pointer, ast1._ast, ast2._ast)
|
1602
|
+
end
|
1603
|
+
|
1512
1604
|
def mk_str_to_int(ast) #=> :ast_pointer
|
1513
1605
|
VeryLowLevel.Z3_mk_str_to_int(_ctx_pointer, ast._ast)
|
1514
1606
|
end
|
@@ -1521,10 +1613,22 @@ module Z3
|
|
1521
1613
|
VeryLowLevel.Z3_mk_tactic(_ctx_pointer, str)
|
1522
1614
|
end
|
1523
1615
|
|
1616
|
+
def mk_transitive_closure(func_decl) #=> :func_decl_pointer
|
1617
|
+
VeryLowLevel.Z3_mk_transitive_closure(_ctx_pointer, func_decl._ast)
|
1618
|
+
end
|
1619
|
+
|
1620
|
+
def mk_tree_order(sort, num) #=> :func_decl_pointer
|
1621
|
+
VeryLowLevel.Z3_mk_tree_order(_ctx_pointer, sort._ast, num)
|
1622
|
+
end
|
1623
|
+
|
1524
1624
|
def mk_true #=> :ast_pointer
|
1525
1625
|
VeryLowLevel.Z3_mk_true(_ctx_pointer)
|
1526
1626
|
end
|
1527
1627
|
|
1628
|
+
def mk_ubv_to_str(ast) #=> :ast_pointer
|
1629
|
+
VeryLowLevel.Z3_mk_ubv_to_str(_ctx_pointer, ast._ast)
|
1630
|
+
end
|
1631
|
+
|
1528
1632
|
def mk_unary_minus(ast) #=> :ast_pointer
|
1529
1633
|
VeryLowLevel.Z3_mk_unary_minus(_ctx_pointer, ast._ast)
|
1530
1634
|
end
|
@@ -1605,16 +1709,20 @@ module Z3
|
|
1605
1709
|
VeryLowLevel.Z3_model_to_string(_ctx_pointer, model._model)
|
1606
1710
|
end
|
1607
1711
|
|
1712
|
+
def model_translate(model, context) #=> :model_pointer
|
1713
|
+
VeryLowLevel.Z3_model_translate(_ctx_pointer, model._model, context._context)
|
1714
|
+
end
|
1715
|
+
|
1608
1716
|
def optimize_assert(optimize, ast) #=> :void
|
1609
1717
|
VeryLowLevel.Z3_optimize_assert(_ctx_pointer, optimize._optimize, ast._ast)
|
1610
1718
|
end
|
1611
1719
|
|
1612
|
-
def
|
1613
|
-
VeryLowLevel.
|
1720
|
+
def optimize_assert_and_track(optimize, ast1, ast2) #=> :void
|
1721
|
+
VeryLowLevel.Z3_optimize_assert_and_track(_ctx_pointer, optimize._optimize, ast1._ast, ast2._ast)
|
1614
1722
|
end
|
1615
1723
|
|
1616
|
-
def
|
1617
|
-
VeryLowLevel.
|
1724
|
+
def optimize_assert_soft(optimize, ast, str, sym) #=> :uint
|
1725
|
+
VeryLowLevel.Z3_optimize_assert_soft(_ctx_pointer, optimize._optimize, ast._ast, str, sym)
|
1618
1726
|
end
|
1619
1727
|
|
1620
1728
|
def optimize_dec_ref(optimize) #=> :void
|
@@ -1665,6 +1773,10 @@ module Z3
|
|
1665
1773
|
VeryLowLevel.Z3_optimize_get_statistics(_ctx_pointer, optimize._optimize)
|
1666
1774
|
end
|
1667
1775
|
|
1776
|
+
def optimize_get_unsat_core(optimize) #=> :ast_vector_pointer
|
1777
|
+
VeryLowLevel.Z3_optimize_get_unsat_core(_ctx_pointer, optimize._optimize)
|
1778
|
+
end
|
1779
|
+
|
1668
1780
|
def optimize_get_upper(optimize, num) #=> :ast_pointer
|
1669
1781
|
VeryLowLevel.Z3_optimize_get_upper(_ctx_pointer, optimize._optimize, num)
|
1670
1782
|
end
|
@@ -1941,6 +2053,10 @@ module Z3
|
|
1941
2053
|
VeryLowLevel.Z3_solver_check(_ctx_pointer, solver._solver)
|
1942
2054
|
end
|
1943
2055
|
|
2056
|
+
def solver_cube(solver, ast_vector, num) #=> :ast_vector_pointer
|
2057
|
+
VeryLowLevel.Z3_solver_cube(_ctx_pointer, solver._solver, ast_vector, num)
|
2058
|
+
end
|
2059
|
+
|
1944
2060
|
def solver_dec_ref(solver) #=> :void
|
1945
2061
|
VeryLowLevel.Z3_solver_dec_ref(_ctx_pointer, solver._solver)
|
1946
2062
|
end
|
@@ -1969,6 +2085,10 @@ module Z3
|
|
1969
2085
|
VeryLowLevel.Z3_solver_get_model(_ctx_pointer, solver._solver)
|
1970
2086
|
end
|
1971
2087
|
|
2088
|
+
def solver_get_non_units(solver) #=> :ast_vector_pointer
|
2089
|
+
VeryLowLevel.Z3_solver_get_non_units(_ctx_pointer, solver._solver)
|
2090
|
+
end
|
2091
|
+
|
1972
2092
|
def solver_get_num_scopes(solver) #=> :uint
|
1973
2093
|
VeryLowLevel.Z3_solver_get_num_scopes(_ctx_pointer, solver._solver)
|
1974
2094
|
end
|
@@ -1989,18 +2109,38 @@ module Z3
|
|
1989
2109
|
VeryLowLevel.Z3_solver_get_statistics(_ctx_pointer, solver._solver)
|
1990
2110
|
end
|
1991
2111
|
|
2112
|
+
def solver_get_trail(solver) #=> :ast_vector_pointer
|
2113
|
+
VeryLowLevel.Z3_solver_get_trail(_ctx_pointer, solver._solver)
|
2114
|
+
end
|
2115
|
+
|
2116
|
+
def solver_get_units(solver) #=> :ast_vector_pointer
|
2117
|
+
VeryLowLevel.Z3_solver_get_units(_ctx_pointer, solver._solver)
|
2118
|
+
end
|
2119
|
+
|
1992
2120
|
def solver_get_unsat_core(solver) #=> :ast_vector_pointer
|
1993
2121
|
VeryLowLevel.Z3_solver_get_unsat_core(_ctx_pointer, solver._solver)
|
1994
2122
|
end
|
1995
2123
|
|
2124
|
+
def solver_import_model_converter(solver1, solver2) #=> :void
|
2125
|
+
VeryLowLevel.Z3_solver_import_model_converter(_ctx_pointer, solver1._solver, solver2._solver)
|
2126
|
+
end
|
2127
|
+
|
1996
2128
|
def solver_inc_ref(solver) #=> :void
|
1997
2129
|
VeryLowLevel.Z3_solver_inc_ref(_ctx_pointer, solver._solver)
|
1998
2130
|
end
|
1999
2131
|
|
2132
|
+
def solver_interrupt(solver) #=> :void
|
2133
|
+
VeryLowLevel.Z3_solver_interrupt(_ctx_pointer, solver._solver)
|
2134
|
+
end
|
2135
|
+
|
2000
2136
|
def solver_pop(solver, num) #=> :void
|
2001
2137
|
VeryLowLevel.Z3_solver_pop(_ctx_pointer, solver._solver, num)
|
2002
2138
|
end
|
2003
2139
|
|
2140
|
+
def solver_propagate_register(solver, ast) #=> :uint
|
2141
|
+
VeryLowLevel.Z3_solver_propagate_register(_ctx_pointer, solver._solver, ast._ast)
|
2142
|
+
end
|
2143
|
+
|
2004
2144
|
def solver_push(solver) #=> :void
|
2005
2145
|
VeryLowLevel.Z3_solver_push(_ctx_pointer, solver._solver)
|
2006
2146
|
end
|
@@ -2013,6 +2153,10 @@ module Z3
|
|
2013
2153
|
VeryLowLevel.Z3_solver_set_params(_ctx_pointer, solver._solver, params._params)
|
2014
2154
|
end
|
2015
2155
|
|
2156
|
+
def solver_to_dimacs_string(solver, bool) #=> :string
|
2157
|
+
VeryLowLevel.Z3_solver_to_dimacs_string(_ctx_pointer, solver._solver, bool)
|
2158
|
+
end
|
2159
|
+
|
2016
2160
|
def solver_to_string(solver) #=> :string
|
2017
2161
|
VeryLowLevel.Z3_solver_to_string(_ctx_pointer, solver._solver)
|
2018
2162
|
end
|
data/lib/z3/optimize.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Z3
|
2
2
|
class Optimize
|
3
3
|
attr_reader :_optimize
|
4
|
+
|
4
5
|
def initialize
|
6
|
+
raise Z3::Exception, "This is known to crash in Z3 4.8.13"
|
5
7
|
@_optimize = LowLevel.mk_optimize
|
6
8
|
LowLevel.optimize_inc_ref(self)
|
7
9
|
reset_model!
|
@@ -27,9 +29,9 @@ module Z3
|
|
27
29
|
LowLevel.optimize_assert_soft(self, ast)
|
28
30
|
end
|
29
31
|
|
30
|
-
def check
|
32
|
+
def check(*args)
|
31
33
|
reset_model!
|
32
|
-
result = check_sat_results(LowLevel.optimize_check(self))
|
34
|
+
result = check_sat_results(LowLevel.optimize_check(self, args))
|
33
35
|
@has_model = true if result == :sat
|
34
36
|
result
|
35
37
|
end
|
@@ -81,7 +83,7 @@ module Z3
|
|
81
83
|
case check
|
82
84
|
when :sat
|
83
85
|
puts "Counterexample exists"
|
84
|
-
model.each do |n,v|
|
86
|
+
model.each do |n, v|
|
85
87
|
puts "* #{n} = #{v}"
|
86
88
|
end
|
87
89
|
when :unknown
|
@@ -95,7 +97,6 @@ module Z3
|
|
95
97
|
pop
|
96
98
|
end
|
97
99
|
|
98
|
-
|
99
100
|
def reason_unknown
|
100
101
|
LowLevel.optimize_get_reason_unknown(self)
|
101
102
|
end
|
data/lib/z3/printer.rb
CHANGED
@@ -53,7 +53,35 @@ module Z3
|
|
53
53
|
name = decl.name
|
54
54
|
args = a.arguments.map{|x| format_ast(x)}
|
55
55
|
return PrintedExpr.new(name, false) if args.size == 0
|
56
|
-
|
56
|
+
|
57
|
+
# Special case common Bitvec operators
|
58
|
+
case name
|
59
|
+
when "rotate_left", "rotate_right", "zero_extend", "sign_extend"
|
60
|
+
if args.size == 1
|
61
|
+
n = Z3::LowLevel.get_decl_int_parameter(a.func_decl, 0)
|
62
|
+
return PrintedExpr.new("#{name}(#{args[0]}, #{n})", true)
|
63
|
+
end
|
64
|
+
when "bvxor", "bvand", "bvor", "bvadd", "bvsub"
|
65
|
+
if args.size == 2
|
66
|
+
pretty_name = {"bvxor" => "^", "bvand" => "&", "bvor" => "|", "bvadd" => "+", "bvsub" => "-"}[name]
|
67
|
+
return PrintedExpr.new("#{args[0].enforce_parentheses} #{pretty_name} #{args[1].enforce_parentheses}", true)
|
68
|
+
end
|
69
|
+
when "bvnot"
|
70
|
+
if args.size == 1
|
71
|
+
return PrintedExpr.new("~#{args[0].enforce_parentheses}")
|
72
|
+
end
|
73
|
+
when "bvneg"
|
74
|
+
if args.size == 1
|
75
|
+
return PrintedExpr.new("-#{args[0].enforce_parentheses}")
|
76
|
+
end
|
77
|
+
when "extract"
|
78
|
+
if args.size == 1
|
79
|
+
u = Z3::LowLevel.get_decl_int_parameter(a.func_decl, 0)
|
80
|
+
v = Z3::LowLevel.get_decl_int_parameter(a.func_decl, 1)
|
81
|
+
return PrintedExpr.new("#{name}(#{args[0]}, #{u}, #{v})", true)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
57
85
|
if name !~ /[a-z0-9]/
|
58
86
|
if args.size == 2
|
59
87
|
return PrintedExpr.new("#{args[0].enforce_parentheses} #{name} #{args[1].enforce_parentheses}", true)
|