z3 0.0.20160427 → 0.0.20161008
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Rakefile +56 -0
- data/examples/bit_tricks +21 -38
- data/examples/circuit_problems +170 -0
- data/lib/z3/ast.rb +21 -3
- data/lib/z3/context.rb +9 -7
- data/lib/z3/exception.rb +1 -2
- data/lib/z3/expr/arith_expr.rb +29 -11
- data/lib/z3/expr/array_expr.rb +5 -0
- data/lib/z3/expr/bitvec_expr.rb +293 -13
- data/lib/z3/expr/bool_expr.rb +30 -6
- data/lib/z3/expr/expr.rb +155 -2
- data/lib/z3/expr/float_expr.rb +185 -0
- data/lib/z3/expr/int_expr.rb +20 -5
- data/lib/z3/expr/real_expr.rb +1 -3
- data/lib/z3/expr/rounding_mode_expr.rb +5 -0
- data/lib/z3/expr/set_expr.rb +66 -0
- data/lib/z3/func_decl.rb +5 -5
- data/lib/z3/goal.rb +64 -0
- data/lib/z3/interface.rb +21 -222
- data/lib/z3/low_level.rb +84 -58
- data/lib/z3/low_level_auto.rb +1509 -1563
- data/lib/z3/model.rb +39 -37
- data/lib/z3/printer.rb +54 -12
- data/lib/z3/probe.rb +69 -0
- data/lib/z3/solver.rb +20 -20
- data/lib/z3/sort/array_sort.rb +24 -0
- data/lib/z3/sort/bitvec_sort.rb +1 -1
- data/lib/z3/sort/float_sort.rb +92 -0
- data/lib/z3/sort/rounding_mode_sort.rb +41 -0
- data/lib/z3/sort/set_sort.rb +31 -0
- data/lib/z3/sort/sort.rb +39 -5
- data/lib/z3/tactic.rb +69 -0
- data/lib/z3/very_low_level.rb +33 -29
- data/lib/z3/very_low_level_auto.rb +505 -517
- data/lib/z3.rb +13 -0
- data/spec/array_expr_spec.rb +18 -0
- data/spec/array_sort_spec.rb +11 -0
- data/spec/bitvec_expr_spec.rb +196 -44
- data/spec/bitvec_sort_spec.rb +29 -27
- data/spec/bool_expr_spec.rb +57 -55
- data/spec/bool_sort_spec.rb +17 -15
- data/spec/coverage_helper.rb +11 -0
- data/spec/expr_spec.rb +151 -147
- data/spec/float_expr_spec.rb +167 -0
- data/spec/float_sort_spec.rb +44 -0
- data/spec/goal_spec.rb +17 -0
- data/spec/int_expr_spec.rb +76 -63
- data/spec/int_sort_spec.rb +16 -14
- data/spec/integration/algebra_problems_spec.rb +4 -4
- data/spec/integration/cicruit_problem_spec.rb +23 -0
- data/spec/integration/geometry_problem_spec.rb +4 -4
- data/spec/integration/kinematics_problems_spec.rb +3 -3
- data/spec/model_spec.rb +39 -37
- data/spec/printer_spec.rb +49 -18
- data/spec/probe_spec.rb +17 -0
- data/spec/real_expr_spec.rb +59 -51
- data/spec/real_sort_spec.rb +22 -20
- data/spec/rounding_mode_expr_spec.rb +16 -0
- data/spec/rounding_mode_sort_spec.rb +13 -0
- data/spec/set_expr_spec.rb +61 -0
- data/spec/set_sort_spec.rb +27 -0
- data/spec/solver_spec.rb +37 -27
- data/spec/sort_spec.rb +38 -36
- data/spec/spec_helper.rb +59 -2
- data/spec/tactic_spec.rb +9 -0
- metadata +44 -4
data/lib/z3/low_level.rb
CHANGED
@@ -1,80 +1,106 @@
|
|
1
1
|
# Seriously do not use this directly in your code
|
2
2
|
# They unwrap inputs, but don't wrap returns yet
|
3
3
|
|
4
|
-
module Z3
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
module Z3
|
5
|
+
module LowLevel
|
6
|
+
class << self
|
7
|
+
def get_version
|
8
|
+
a = FFI::MemoryPointer.new(:int)
|
9
|
+
b = FFI::MemoryPointer.new(:int)
|
10
|
+
c = FFI::MemoryPointer.new(:int)
|
11
|
+
d = FFI::MemoryPointer.new(:int)
|
12
|
+
Z3::VeryLowLevel.Z3_get_version(a,b,c,d)
|
13
|
+
[a.get_uint(0), b.get_uint(0), c.get_uint(0), d.get_uint(0)]
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def set_error_handler(&block)
|
17
|
+
Z3::VeryLowLevel.Z3_set_error_handler(_ctx_pointer, block)
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def mk_context
|
21
|
+
Z3::VeryLowLevel.Z3_mk_context(Z3::VeryLowLevel.Z3_mk_config)
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
def model_eval(model, ast, model_completion)
|
25
|
+
rv_ptr = FFI::MemoryPointer.new(:pointer)
|
26
|
+
result = Z3::VeryLowLevel.Z3_model_eval(_ctx_pointer, model._model, ast._ast, !!model_completion, rv_ptr)
|
27
|
+
if result == 1
|
28
|
+
rv_ptr.get_pointer(0)
|
29
|
+
else
|
30
|
+
raise Z3::Exception, "Evaluation of `#{ast}' failed"
|
31
|
+
end
|
30
32
|
end
|
31
|
-
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
def mk_and(asts)
|
35
|
+
Z3::VeryLowLevel.Z3_mk_and(_ctx_pointer, asts.size, asts_vector(asts))
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
def mk_or(asts)
|
39
|
+
Z3::VeryLowLevel.Z3_mk_or(_ctx_pointer, asts.size, asts_vector(asts))
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
def mk_mul(asts)
|
43
|
+
Z3::VeryLowLevel.Z3_mk_mul(_ctx_pointer, asts.size, asts_vector(asts))
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
def mk_add(asts)
|
47
|
+
Z3::VeryLowLevel.Z3_mk_add(_ctx_pointer, asts.size, asts_vector(asts))
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
def mk_sub(asts)
|
51
|
+
Z3::VeryLowLevel.Z3_mk_sub(_ctx_pointer, asts.size, asts_vector(asts))
|
52
|
+
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
def mk_distinct(asts)
|
55
|
+
Z3::VeryLowLevel.Z3_mk_distinct(_ctx_pointer, asts.size, asts_vector(asts))
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
+
def mk_set_union(asts)
|
59
|
+
Z3::VeryLowLevel.Z3_mk_set_union(_ctx_pointer, asts.size, asts_vector(asts))
|
60
|
+
end
|
58
61
|
|
59
|
-
|
60
|
-
|
61
|
-
(0...n).map do |i|
|
62
|
-
_ast = Z3::VeryLowLevel.Z3_ast_vector_get(_ctx_pointer, _ast_vector, i)
|
63
|
-
Z3::Expr.new_from_pointer(_ast)
|
62
|
+
def mk_set_intersect(asts)
|
63
|
+
Z3::VeryLowLevel.Z3_mk_set_intersect(_ctx_pointer, asts.size, asts_vector(asts))
|
64
64
|
end
|
65
|
-
end
|
66
65
|
|
67
|
-
|
68
|
-
@_ctx_pointer ||= Z3::Context.instance._context
|
69
|
-
end
|
66
|
+
# Should be private
|
70
67
|
|
71
|
-
|
68
|
+
def unpack_ast_vector(_ast_vector)
|
69
|
+
ast_vector_size(_ast_vector).times.map do |i|
|
70
|
+
_ast = ast_vector_get(_ast_vector, i)
|
71
|
+
Expr.new_from_pointer(_ast)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def unpack_statistics(_stats)
|
76
|
+
stats = {}
|
77
|
+
stats_size(_stats).times.map do |i|
|
78
|
+
key = stats_get_key(_stats, i)
|
79
|
+
if stats_is_double(_stats, i)
|
80
|
+
val = stats_get_double_value(_stats, i)
|
81
|
+
elsif stats_is_uint(_stats, i)
|
82
|
+
val = stats_get_uint_value(_stats, i)
|
83
|
+
else
|
84
|
+
raise Z3::Exception, "Stat is neither double nor uint, that's not supposed to happen"
|
85
|
+
end
|
86
|
+
raise Z3::Exception, "Key #{key} duplicated in stats" if stats.has_key?(key)
|
87
|
+
stats[key] = val
|
88
|
+
end
|
89
|
+
stats
|
90
|
+
end
|
72
91
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
92
|
+
def _ctx_pointer
|
93
|
+
@_ctx_pointer ||= Z3::Context.instance._context
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def asts_vector(args)
|
99
|
+
raise if args.empty?
|
100
|
+
c_args = FFI::MemoryPointer.new(:pointer, args.size)
|
101
|
+
c_args.write_array_of_pointer args.map(&:_ast)
|
102
|
+
c_args
|
103
|
+
end
|
78
104
|
end
|
79
105
|
end
|
80
106
|
end
|