z3 0.0.20160427 → 0.0.20161008

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/Rakefile +56 -0
  4. data/examples/bit_tricks +21 -38
  5. data/examples/circuit_problems +170 -0
  6. data/lib/z3/ast.rb +21 -3
  7. data/lib/z3/context.rb +9 -7
  8. data/lib/z3/exception.rb +1 -2
  9. data/lib/z3/expr/arith_expr.rb +29 -11
  10. data/lib/z3/expr/array_expr.rb +5 -0
  11. data/lib/z3/expr/bitvec_expr.rb +293 -13
  12. data/lib/z3/expr/bool_expr.rb +30 -6
  13. data/lib/z3/expr/expr.rb +155 -2
  14. data/lib/z3/expr/float_expr.rb +185 -0
  15. data/lib/z3/expr/int_expr.rb +20 -5
  16. data/lib/z3/expr/real_expr.rb +1 -3
  17. data/lib/z3/expr/rounding_mode_expr.rb +5 -0
  18. data/lib/z3/expr/set_expr.rb +66 -0
  19. data/lib/z3/func_decl.rb +5 -5
  20. data/lib/z3/goal.rb +64 -0
  21. data/lib/z3/interface.rb +21 -222
  22. data/lib/z3/low_level.rb +84 -58
  23. data/lib/z3/low_level_auto.rb +1509 -1563
  24. data/lib/z3/model.rb +39 -37
  25. data/lib/z3/printer.rb +54 -12
  26. data/lib/z3/probe.rb +69 -0
  27. data/lib/z3/solver.rb +20 -20
  28. data/lib/z3/sort/array_sort.rb +24 -0
  29. data/lib/z3/sort/bitvec_sort.rb +1 -1
  30. data/lib/z3/sort/float_sort.rb +92 -0
  31. data/lib/z3/sort/rounding_mode_sort.rb +41 -0
  32. data/lib/z3/sort/set_sort.rb +31 -0
  33. data/lib/z3/sort/sort.rb +39 -5
  34. data/lib/z3/tactic.rb +69 -0
  35. data/lib/z3/very_low_level.rb +33 -29
  36. data/lib/z3/very_low_level_auto.rb +505 -517
  37. data/lib/z3.rb +13 -0
  38. data/spec/array_expr_spec.rb +18 -0
  39. data/spec/array_sort_spec.rb +11 -0
  40. data/spec/bitvec_expr_spec.rb +196 -44
  41. data/spec/bitvec_sort_spec.rb +29 -27
  42. data/spec/bool_expr_spec.rb +57 -55
  43. data/spec/bool_sort_spec.rb +17 -15
  44. data/spec/coverage_helper.rb +11 -0
  45. data/spec/expr_spec.rb +151 -147
  46. data/spec/float_expr_spec.rb +167 -0
  47. data/spec/float_sort_spec.rb +44 -0
  48. data/spec/goal_spec.rb +17 -0
  49. data/spec/int_expr_spec.rb +76 -63
  50. data/spec/int_sort_spec.rb +16 -14
  51. data/spec/integration/algebra_problems_spec.rb +4 -4
  52. data/spec/integration/cicruit_problem_spec.rb +23 -0
  53. data/spec/integration/geometry_problem_spec.rb +4 -4
  54. data/spec/integration/kinematics_problems_spec.rb +3 -3
  55. data/spec/model_spec.rb +39 -37
  56. data/spec/printer_spec.rb +49 -18
  57. data/spec/probe_spec.rb +17 -0
  58. data/spec/real_expr_spec.rb +59 -51
  59. data/spec/real_sort_spec.rb +22 -20
  60. data/spec/rounding_mode_expr_spec.rb +16 -0
  61. data/spec/rounding_mode_sort_spec.rb +13 -0
  62. data/spec/set_expr_spec.rb +61 -0
  63. data/spec/set_sort_spec.rb +27 -0
  64. data/spec/solver_spec.rb +37 -27
  65. data/spec/sort_spec.rb +38 -36
  66. data/spec/spec_helper.rb +59 -2
  67. data/spec/tactic_spec.rb +9 -0
  68. metadata +44 -4
@@ -0,0 +1,185 @@
1
+ module Z3
2
+ class FloatExpr < Expr
3
+
4
+ def ==(other)
5
+ FloatExpr.Eq(self, other)
6
+ end
7
+
8
+ def !=(other)
9
+ FloatExpr.Ne(self, other)
10
+ end
11
+
12
+ def <(other)
13
+ FloatExpr.Lt(self, other)
14
+ end
15
+
16
+ def <=(other)
17
+ FloatExpr.Le(self, other)
18
+ end
19
+
20
+ def >(other)
21
+ FloatExpr.Gt(self, other)
22
+ end
23
+
24
+ def >=(other)
25
+ FloatExpr.Ge(self, other)
26
+ end
27
+
28
+ def add(other, mode)
29
+ FloatExpr.Add(self, other, mode)
30
+ end
31
+
32
+ def sub(other, mode)
33
+ FloatExpr.Sub(self, other, mode)
34
+ end
35
+
36
+ def mul(other, mode)
37
+ FloatExpr.Mul(self, other, mode)
38
+ end
39
+
40
+ def div(other, mode)
41
+ FloatExpr.Div(self, other, mode)
42
+ end
43
+
44
+ def rem(other)
45
+ FloatExpr.Rem(self, other)
46
+ end
47
+
48
+ def abs
49
+ sort.new LowLevel.mk_fpa_abs(self)
50
+ end
51
+
52
+ def -@
53
+ sort.new LowLevel.mk_fpa_neg(self)
54
+ end
55
+
56
+ def infinite?
57
+ BoolSort.new.new LowLevel.mk_fpa_is_infinite(self)
58
+ end
59
+
60
+ def nan?
61
+ BoolSort.new.new LowLevel.mk_fpa_is_nan(self)
62
+ end
63
+
64
+ def negative?
65
+ BoolSort.new.new LowLevel.mk_fpa_is_negative(self)
66
+ end
67
+
68
+ def normal?
69
+ BoolSort.new.new LowLevel.mk_fpa_is_normal(self)
70
+ end
71
+
72
+ def positive?
73
+ BoolSort.new.new LowLevel.mk_fpa_is_positive(self)
74
+ end
75
+
76
+ def subnormal?
77
+ BoolSort.new.new LowLevel.mk_fpa_is_subnormal(self)
78
+ end
79
+
80
+ def zero?
81
+ BoolSort.new.new LowLevel.mk_fpa_is_zero(self)
82
+ end
83
+
84
+ def max(other)
85
+ FloatExpr.Max(self, other)
86
+ end
87
+
88
+ def min(other)
89
+ FloatExpr.Min(self, other)
90
+ end
91
+
92
+ def exponent_string
93
+ LowLevel.fpa_get_numeral_exponent_string(self)
94
+ end
95
+
96
+ def significand_string
97
+ LowLevel.fpa_get_numeral_significand_string(self)
98
+ end
99
+
100
+ public_class_method :new
101
+
102
+ class << self
103
+ def coerce_to_same_float_sort(*args)
104
+ args = coerce_to_same_sort(*args)
105
+ raise Z3::Exception, "Float value with same sizes expected" unless args[0].is_a?(FloatExpr)
106
+ args
107
+ end
108
+
109
+ def coerce_to_mode_sort(m)
110
+ raise Z3::Exception, "Mode expected" unless m.is_a?(RoundingModeExpr)
111
+ m
112
+ end
113
+
114
+ def Eq(a, b)
115
+ a, b = coerce_to_same_float_sort(a, b)
116
+ BoolSort.new.new(LowLevel.mk_fpa_eq(a, b))
117
+ end
118
+
119
+ def Ne(a, b)
120
+ ~Eq(a,b)
121
+ end
122
+
123
+ def Gt(a, b)
124
+ a, b = coerce_to_same_float_sort(a, b)
125
+ BoolSort.new.new(LowLevel.mk_fpa_gt(a, b))
126
+ end
127
+
128
+ def Lt(a, b)
129
+ a, b = coerce_to_same_float_sort(a, b)
130
+ BoolSort.new.new(LowLevel.mk_fpa_lt(a, b))
131
+ end
132
+
133
+ def Ge(a, b)
134
+ a, b = coerce_to_same_float_sort(a, b)
135
+ BoolSort.new.new(LowLevel.mk_fpa_geq(a, b))
136
+ end
137
+
138
+ def Le(a, b)
139
+ a, b = coerce_to_same_float_sort(a, b)
140
+ BoolSort.new.new(LowLevel.mk_fpa_leq(a, b))
141
+ end
142
+
143
+ def Add(a, b, m)
144
+ a, b = coerce_to_same_float_sort(a, b)
145
+ m = coerce_to_mode_sort(m)
146
+ a.sort.new(LowLevel.mk_fpa_add(m, a, b))
147
+ end
148
+
149
+ def Sub(a, b, m)
150
+ a, b = coerce_to_same_float_sort(a, b)
151
+ m = coerce_to_mode_sort(m)
152
+ a.sort.new(LowLevel.mk_fpa_sub(m, a, b))
153
+ end
154
+
155
+ def Mul(a, b, m)
156
+ a, b = coerce_to_same_float_sort(a, b)
157
+ m = coerce_to_mode_sort(m)
158
+ a.sort.new(LowLevel.mk_fpa_mul(m, a, b))
159
+ end
160
+
161
+ def Div(a, b, m)
162
+ a, b = coerce_to_same_float_sort(a, b)
163
+ m = coerce_to_mode_sort(m)
164
+ a.sort.new(LowLevel.mk_fpa_div(m, a, b))
165
+ end
166
+
167
+ def Rem(a, b)
168
+ a, b = coerce_to_same_float_sort(a, b)
169
+ a.sort.new(LowLevel.mk_fpa_rem(a, b))
170
+ end
171
+
172
+ # Weirdly this dies when trying to calll Z3_get_ast_kind, while min works on same call
173
+ #
174
+ # def Max(a, b)
175
+ # a, b = coerce_to_same_float_sort(a, b)
176
+ # a.sort.new(LowLevel.mk_fpa_max(a, b))
177
+ # end
178
+
179
+ def Min(a, b)
180
+ a, b = coerce_to_same_float_sort(a, b)
181
+ a.sort.new(LowLevel.mk_fpa_min(a, b))
182
+ end
183
+ end
184
+ end
185
+ end
@@ -1,15 +1,30 @@
1
1
  module Z3
2
- class IntExpr < Expr
3
- include ArithExpr
4
-
2
+ class IntExpr < ArithExpr
5
3
  def mod(other)
6
- ::Z3.Mod(self, other)
4
+ IntExpr.Mod(self, other)
7
5
  end
8
6
 
9
7
  def rem(other)
10
- ::Z3.Rem(self, other)
8
+ IntExpr.Rem(self, other)
11
9
  end
12
10
 
13
11
  public_class_method :new
12
+ class << self
13
+ def coerce_to_same_int_sort(*args)
14
+ args = coerce_to_same_sort(*args)
15
+ raise Z3::Exception, "Int value expected" unless args[0].is_a?(IntExpr)
16
+ args
17
+ end
18
+
19
+ def Mod(a, b)
20
+ a, b = coerce_to_same_int_sort(a, b)
21
+ a.sort.new(LowLevel.mk_mod(a, b))
22
+ end
23
+
24
+ def Rem(a, b)
25
+ a, b = coerce_to_same_int_sort(a, b)
26
+ a.sort.new(LowLevel.mk_rem(a, b))
27
+ end
28
+ end
14
29
  end
15
30
  end
@@ -1,7 +1,5 @@
1
1
  module Z3
2
- class RealExpr < Expr
3
- include ArithExpr
4
-
2
+ class RealExpr < ArithExpr
5
3
  public_class_method :new
6
4
  end
7
5
  end
@@ -0,0 +1,5 @@
1
+ module Z3
2
+ class RoundingModeExpr < Expr
3
+ public_class_method :new
4
+ end
5
+ end
@@ -0,0 +1,66 @@
1
+ module Z3
2
+ class SetExpr < Expr
3
+ public_class_method :new
4
+
5
+ def element_sort
6
+ sort.element_sort
7
+ end
8
+
9
+ def is_superset_of(other)
10
+ SetExpr.Subset(other, self)
11
+ end
12
+
13
+ def is_subset_of(other)
14
+ SetExpr.Subset(self, other)
15
+ end
16
+
17
+ def complement
18
+ sort.new(LowLevel.mk_set_complement(self))
19
+ end
20
+
21
+ def union(other)
22
+ SetExpr.Union(self, other)
23
+ end
24
+
25
+ def intersection(other)
26
+ SetExpr.Union(self, other)
27
+ end
28
+
29
+ def difference(other)
30
+ SetExpr.Difference(self, other)
31
+ end
32
+
33
+ def include?(element)
34
+ element = element_sort.cast(element)
35
+ BoolSort.new.new(LowLevel.mk_set_member(element, self))
36
+ end
37
+
38
+ class << self
39
+ def coerce_to_same_set_sort(*args)
40
+ args = coerce_to_same_sort(*args)
41
+ raise Z3::Exception, "Set value with same element sort expected" unless args[0].is_a?(SetExpr)
42
+ args
43
+ end
44
+
45
+ def Subset(a, b)
46
+ a, b = coerce_to_same_set_sort(a, b)
47
+ BoolSort.new.new(LowLevel.mk_set_subset(a, b))
48
+ end
49
+
50
+ def Union(*args)
51
+ args = coerce_to_same_set_sort(*args)
52
+ args[0].sort.new(LowLevel.mk_set_union(args))
53
+ end
54
+
55
+ def Intersection(*args)
56
+ args = coerce_to_same_set_sort(*args)
57
+ args[0].sort.new(LowLevel.mk_set_intersect(args))
58
+ end
59
+
60
+ def Difference(a, b)
61
+ a, b = coerce_to_same_set_sort(a, b)
62
+ a.sort.new(LowLevel.mk_set_difference(a, b))
63
+ end
64
+ end
65
+ end
66
+ end
data/lib/z3/func_decl.rb CHANGED
@@ -6,26 +6,26 @@ module Z3
6
6
  end
7
7
 
8
8
  def name
9
- Z3::LowLevel.get_symbol_string(Z3::LowLevel.get_decl_name(self))
9
+ LowLevel.get_symbol_string(LowLevel.get_decl_name(self))
10
10
  end
11
11
 
12
12
  def arity
13
- Z3::LowLevel.get_arity(self)
13
+ LowLevel.get_arity(self)
14
14
  end
15
15
 
16
16
  def domain(i)
17
17
  a = arity
18
18
  raise Z3::Exception, "Trying to access domain #{i} but function arity is #{a}" if i < 0 or i >= a
19
- Sort.from_pointer(Z3::LowLevel::get_domain(self, i))
19
+ Sort.from_pointer(LowLevel::get_domain(self, i))
20
20
  end
21
21
 
22
22
  def range
23
- Sort.from_pointer(Z3::LowLevel::get_range(self))
23
+ Sort.from_pointer(LowLevel::get_range(self))
24
24
  end
25
25
 
26
26
  # def ast_parameter(i)
27
27
  # # vs arity ?
28
- # Z3::Ast.new(Z3::LowLevel.get_decl_ast_parameter(self, i))
28
+ # Z3::Ast.new(LowLevel.get_decl_ast_parameter(self, i))
29
29
  # end
30
30
 
31
31
  def to_s
data/lib/z3/goal.rb ADDED
@@ -0,0 +1,64 @@
1
+ module Z3
2
+ class Goal
3
+ attr_reader :_goal
4
+ def initialize(_goal)
5
+ @_goal = _goal
6
+ end
7
+
8
+ def assert(ast)
9
+ raise Z3::Exception, "AST required" unless ast.is_a?(AST)
10
+ LowLevel.goal_assert(self, ast)
11
+ end
12
+
13
+ def reset
14
+ LowLevel.goal_reset(self)
15
+ end
16
+
17
+ def depth
18
+ LowLevel.goal_depth(self)
19
+ end
20
+
21
+ def size
22
+ LowLevel.goal_size(self)
23
+ end
24
+
25
+ def num_exprs
26
+ LowLevel.goal_num_exprs(self)
27
+ end
28
+
29
+ def precision
30
+ LowLevel.goal_precision(self)
31
+ end
32
+
33
+ def inconsistent?
34
+ # Does it convert bool or do we need to ?
35
+ LowLevel.goal_inconsistent(self)
36
+ end
37
+
38
+ def decided_sat?
39
+ # Does it convert bool or do we need to ?
40
+ LowLevel.goal_is_decided_sat(self)
41
+ end
42
+
43
+ def decided_unsat?
44
+ # Does it convert bool or do we need to ?
45
+ LowLevel.goal_is_decided_unsat(self)
46
+ end
47
+
48
+ def formula(num)
49
+ raise Z3::Exception, "Out of range" unless num.between?(0, size-1)
50
+ # We should probably deal with out of bounds here
51
+ Expr.new_from_pointer(LowLevel.goal_formula(self, num))
52
+ end
53
+
54
+ def to_s
55
+ LowLevel.goal_to_string(self)
56
+ end
57
+
58
+ class << self
59
+ def new(models=false, unsat_cores=false, proofs=false)
60
+ super LowLevel.mk_goal(!!models, !!unsat_cores, !!proofs)
61
+ end
62
+ end
63
+ end
64
+ end
data/lib/z3/interface.rb CHANGED
@@ -1,4 +1,6 @@
1
+ # Everything here might go away
1
2
  module Z3
3
+ # Variables
2
4
  def Int(v)
3
5
  IntSort.new.var(v)
4
6
  end
@@ -15,6 +17,7 @@ module Z3
15
17
  BitvecSort.new(n).var(v)
16
18
  end
17
19
 
20
+ # Constants
18
21
  def True
19
22
  BoolSort.new.True
20
23
  end
@@ -27,205 +30,44 @@ module Z3
27
30
  Expr.sort_for_const(v).from_const(v)
28
31
  end
29
32
 
30
- def And(*args)
31
- args = coerce_to_same_sort(*args)
32
- case args[0]
33
- when BoolExpr
34
- BoolSort.new.new(Z3::LowLevel.mk_and(args))
35
- when BitvecExpr
36
- args.inject do |a,b|
37
- a.sort.new(Z3::LowLevel.mk_bvand(a, b))
38
- end
39
- else
40
- raise ArgumentError, "Can't perform logic operations on #{a.sort} exprs, only Bool and Bitvec"
41
- end
42
- end
43
-
44
- def Or(*args)
45
- args = coerce_to_same_sort(*args)
46
- case args[0]
47
- when BoolExpr
48
- BoolSort.new.new(Z3::LowLevel.mk_or(args))
49
- when BitvecExpr
50
- args.inject do |a,b|
51
- a.sort.new(Z3::LowLevel.mk_bvor(a, b))
52
- end
53
- else
54
- raise ArgumentError, "Can't perform logic operations on #{a.sort} exprs, only Bool and Bitvec"
55
- end
56
- end
57
-
58
- def Xor(*args)
59
- args = coerce_to_same_sort(*args)
60
- case args[0]
61
- when BoolExpr
62
- args.inject do |a,b|
63
- BoolSort.new.new(Z3::LowLevel.mk_xor(a, b))
64
- end
65
- when BitvecExpr
66
- args.inject do |a,b|
67
- a.sort.new(Z3::LowLevel.mk_bvxor(a, b))
68
- end
69
- else
70
- raise ArgumentError, "Can't perform logic operations on #{a.sort} exprs, only Bool and Bitvec"
71
- end
72
- end
73
-
74
- def Implies(a,b)
75
- a, b = coerce_to_same_bool_sort(a, b)
76
- BoolSort.new.new(Z3::LowLevel.mk_implies(a, b))
77
- end
78
-
79
- def Iff(a,b)
80
- a, b = coerce_to_same_bool_sort(a, b)
81
- BoolSort.new.new(Z3::LowLevel.mk_iff(a, b))
33
+ # Multiargument constructors
34
+ def Distinct(*args)
35
+ Expr.Distinct(*args)
82
36
  end
83
37
 
84
- def IfThenElse(a, b, c)
85
- a, = coerce_to_same_bool_sort(a)
86
- b, c = coerce_to_same_sort(b, c)
87
- b.sort.new(Z3::LowLevel.mk_ite(a, b, c))
38
+ def Eq(*args)
39
+ Expr.Eq(*args)
88
40
  end
89
41
 
90
42
  def Add(*args)
91
- raise ArgumentError if args.empty?
92
- args = coerce_to_same_sort(*args)
93
- case args[0]
94
- when ArithExpr
95
- args[0].sort.new(LowLevel.mk_add(args))
96
- when BitvecExpr
97
- args.inject do |a,b|
98
- a.sort.new(LowLevel.mk_bvadd(a,b))
99
- end
100
- else
101
- raise ArgumentError, "Can't perform logic operations on #{args[0].sort} exprs, only Int/Real/Bitvec"
102
- end
103
- end
104
-
105
- def Sub(*args)
106
- args = coerce_to_same_sort(*args)
107
- case args[0]
108
- when ArithExpr
109
- args[0].sort.new(LowLevel.mk_sub(args))
110
- when BitvecExpr
111
- args.inject do |a,b|
112
- a.sort.new(LowLevel.mk_bvsub(a,b))
113
- end
114
- else
115
- raise ArgumentError, "Can't perform logic operations on #{args[0].sort} values, only Int/Real/Bitvec"
116
- end
43
+ Expr.Add(*args)
117
44
  end
118
45
 
119
46
  def Mul(*args)
120
- args = coerce_to_same_sort(*args)
121
- case args[0]
122
- when ArithExpr
123
- args[0].sort.new(LowLevel.mk_mul(args))
124
- when BitvecExpr
125
- args.inject do |a,b|
126
- a.sort.new(LowLevel.mk_bvmul(a,b))
127
- end
128
- else
129
- raise ArgumentError, "Can't perform logic operations on #{args[0].sort} values, only Int/Real/Bitvec"
130
- end
131
- end
132
-
133
- def Div(a,b)
134
- a, b = coerce_to_same_arith_sort(a, b)
135
- a.sort.new(LowLevel.mk_div(a, b))
136
- end
137
-
138
- def Mod(a,b)
139
- a, b = coerce_to_same_int_sort(a, b)
140
- a.sort.new(LowLevel.mk_mod(a, b))
141
- end
142
-
143
- def Rem(a,b)
144
- a, b = coerce_to_same_int_sort(a, b)
145
- a.sort.new(LowLevel.mk_rem(a, b))
47
+ Expr.Mul(*args)
146
48
  end
147
49
 
148
- def Power(a, b)
149
- # Wait, is this even legitimate that it's I**I and R**R?
150
- a, b = coerce_to_same_arith_sort(a, b)
151
- a.sort.new(LowLevel.mk_power(a, b))
152
- end
153
-
154
- def Eq(a, b)
155
- a, b = coerce_to_same_sort(a, b)
156
- BoolSort.new.new(LowLevel.mk_eq(a, b))
157
- end
158
-
159
- def Distinct(*args)
160
- args = coerce_to_same_sort(*args)
161
- BoolSort.new.new(LowLevel.mk_distinct(args))
162
- end
163
-
164
- def Gt(a, b)
165
- a, b = coerce_to_same_sort(a, b)
166
- case a
167
- when ArithExpr
168
- BoolSort.new.new(LowLevel.mk_gt(a, b))
169
- when BitvecExpr
170
- BoolSort.new.new(LowLevel.mk_bvsgt(a, b))
171
- else
172
- raise ArgumentError, "Can't compare #{a.sort} values"
173
- end
174
- end
175
-
176
- def Ge(a, b)
177
- a, b = coerce_to_same_sort(a, b)
178
- case a
179
- when ArithExpr
180
- BoolSort.new.new(LowLevel.mk_ge(a, b))
181
- when BitvecExpr
182
- BoolSort.new.new(LowLevel.mk_bvsge(a, b))
183
- else
184
- raise ArgumentError, "Can't compare #{a.sort} values"
185
- end
186
- end
187
-
188
- def Lt(a, b)
189
- a, b = coerce_to_same_sort(a, b)
190
- case a
191
- when ArithExpr
192
- BoolSort.new.new(LowLevel.mk_lt(a, b))
193
- when BitvecExpr
194
- BoolSort.new.new(LowLevel.mk_bvslt(a, b))
195
- else
196
- raise ArgumentError, "Can't compare #{a.sort} values"
197
- end
50
+ def Or(*args)
51
+ BoolExpr.Or(*args)
198
52
  end
199
53
 
200
- def Le(a, b)
201
- a, b = coerce_to_same_sort(a, b)
202
- case a
203
- when ArithExpr
204
- BoolSort.new.new(LowLevel.mk_le(a, b))
205
- when BitvecExpr
206
- BoolSort.new.new(LowLevel.mk_bvsle(a, b))
207
- else
208
- raise ArgumentError, "Can't compare #{a.sort} values"
209
- end
54
+ def And(*args)
55
+ BoolExpr.And(*args)
210
56
  end
211
57
 
212
- def Not(a)
213
- a = Value.from_const(a) unless a.is_a?(Value)
214
- raise Z3::Exception, "No idea how to autoconvert `#{a.class}': `#{a.inspect}'" unless a.is_a?(BoolValue)
215
- BoolSort.new.new(LowLevel.mk_not(a))
58
+ def Xor(*args)
59
+ Expr.Xor(*args)
216
60
  end
217
61
 
218
- # Presume arithmetic (sign-extend)
219
- def RShift(a, b)
220
- a, b = coerce_to_same_bv_sort(a, b)
221
- a.sort.new(LowLevel.mk_bvashr(a, b))
62
+ def Implies(a,b)
63
+ BoolExpr.Implies(a,b)
222
64
  end
223
65
 
224
- def LShift(a, b)
225
- a, b = coerce_to_same_bv_sort(a, b)
226
- a.sort.new(LowLevel.mk_bvshl(a, b))
66
+ def IfThenElse(a,b,c)
67
+ BoolExpr.IfThenElse(a,b,c)
227
68
  end
228
69
 
70
+ # Global functions
229
71
  def version
230
72
  LowLevel.get_version.join(".")
231
73
  end
@@ -234,49 +76,6 @@ module Z3
234
76
  LowLevel.global_param_set(k,v)
235
77
  end
236
78
 
237
- private
238
-
239
- def coerce_to_same_sort(*args)
240
- # This will raise exception unless one of the sorts is highest
241
- # So [true, IntSort]
242
- max_sort = args.map{|a| a.is_a?(Expr) ? a.sort : Expr.sort_for_const(a)}.max
243
- args.map do |a|
244
- if a.is_a?(Expr)
245
- if a.sort == max_sort
246
- a
247
- else
248
- max_sort.from_value(a)
249
- end
250
- else
251
- max_sort.from_const(a)
252
- end
253
- end
254
- end
255
-
256
- def coerce_to_same_bool_sort(*args)
257
- args = coerce_to_same_sort(*args)
258
- raise Z3::Exception, "Bool value expected" unless args[0].is_a?(BoolExpr)
259
- args
260
- end
261
-
262
- def coerce_to_same_arith_sort(*args)
263
- args = coerce_to_same_sort(*args)
264
- raise Z3::Exception, "Int or Real value expected" unless args[0].is_a?(IntExpr) or args[0].is_a?(RealExpr)
265
- args
266
- end
267
-
268
- def coerce_to_same_bv_sort(*args)
269
- args = coerce_to_same_sort(*args)
270
- raise Z3::Exception, "Bitvec value with same size expected" unless args[0].is_a?(BitvecExpr)
271
- args
272
- end
273
-
274
- def coerce_to_same_int_sort(*args)
275
- args = coerce_to_same_sort(*args)
276
- raise Z3::Exception, "Int value expected" unless args[0].is_a?(IntExpr)
277
- args
278
- end
279
-
280
79
  class << self
281
80
  include Z3
282
81
  end