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
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::LowLevel
5
- class << self
6
- def get_version
7
- a = FFI::MemoryPointer.new(:int)
8
- b = FFI::MemoryPointer.new(:int)
9
- c = FFI::MemoryPointer.new(:int)
10
- d = FFI::MemoryPointer.new(:int)
11
- Z3::VeryLowLevel.Z3_get_version(a,b,c,d)
12
- [a.get_uint(0), b.get_uint(0), c.get_uint(0), d.get_uint(0)]
13
- end
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
- def set_error_handler(&block)
16
- Z3::VeryLowLevel.Z3_set_error_handler(_ctx_pointer, block)
17
- end
16
+ def set_error_handler(&block)
17
+ Z3::VeryLowLevel.Z3_set_error_handler(_ctx_pointer, block)
18
+ end
18
19
 
19
- def mk_context
20
- Z3::VeryLowLevel.Z3_mk_context(Z3::VeryLowLevel.Z3_mk_config)
21
- end
20
+ def mk_context
21
+ Z3::VeryLowLevel.Z3_mk_context(Z3::VeryLowLevel.Z3_mk_config)
22
+ end
22
23
 
23
- def model_eval(model, ast, model_completion)
24
- rv_ptr = FFI::MemoryPointer.new(:pointer)
25
- result = Z3::VeryLowLevel.Z3_model_eval(_ctx_pointer, model._model, ast._ast, !!model_completion, rv_ptr)
26
- if result == 1
27
- rv_ptr.get_pointer(0)
28
- else
29
- raise Z3::Exception, "Evaluation of `#{ast}' failed"
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
- def mk_and(asts)
34
- Z3::VeryLowLevel.Z3_mk_and(_ctx_pointer, asts.size, asts_vector(asts))
35
- end
34
+ def mk_and(asts)
35
+ Z3::VeryLowLevel.Z3_mk_and(_ctx_pointer, asts.size, asts_vector(asts))
36
+ end
36
37
 
37
- def mk_or(asts)
38
- Z3::VeryLowLevel.Z3_mk_or(_ctx_pointer, asts.size, asts_vector(asts))
39
- end
38
+ def mk_or(asts)
39
+ Z3::VeryLowLevel.Z3_mk_or(_ctx_pointer, asts.size, asts_vector(asts))
40
+ end
40
41
 
41
- def mk_mul(asts)
42
- Z3::VeryLowLevel.Z3_mk_mul(_ctx_pointer, asts.size, asts_vector(asts))
43
- end
42
+ def mk_mul(asts)
43
+ Z3::VeryLowLevel.Z3_mk_mul(_ctx_pointer, asts.size, asts_vector(asts))
44
+ end
44
45
 
45
- def mk_add(asts)
46
- Z3::VeryLowLevel.Z3_mk_add(_ctx_pointer, asts.size, asts_vector(asts))
47
- end
46
+ def mk_add(asts)
47
+ Z3::VeryLowLevel.Z3_mk_add(_ctx_pointer, asts.size, asts_vector(asts))
48
+ end
48
49
 
49
- def mk_sub(asts)
50
- Z3::VeryLowLevel.Z3_mk_sub(_ctx_pointer, asts.size, asts_vector(asts))
51
- end
50
+ def mk_sub(asts)
51
+ Z3::VeryLowLevel.Z3_mk_sub(_ctx_pointer, asts.size, asts_vector(asts))
52
+ end
52
53
 
53
- def mk_distinct(asts)
54
- Z3::VeryLowLevel.Z3_mk_distinct(_ctx_pointer, asts.size, asts_vector(asts))
55
- end
54
+ def mk_distinct(asts)
55
+ Z3::VeryLowLevel.Z3_mk_distinct(_ctx_pointer, asts.size, asts_vector(asts))
56
+ end
56
57
 
57
- # Should be private
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
- def unpack_ast_vector(_ast_vector)
60
- n = Z3::VeryLowLevel.Z3_ast_vector_size(_ctx_pointer, _ast_vector)
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
- def _ctx_pointer
68
- @_ctx_pointer ||= Z3::Context.instance._context
69
- end
66
+ # Should be private
70
67
 
71
- private
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
- def asts_vector(args)
74
- raise if args.empty?
75
- c_args = FFI::MemoryPointer.new(:pointer, args.size)
76
- c_args.write_array_of_pointer args.map(&:_ast)
77
- c_args
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