z3 0.0.20220828 → 0.0.20221020

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94779e8d2fdaee7a213640164c8113fee96135e5247d9dc161d02dae87da6e94
4
- data.tar.gz: d11a1326c693216fe857b436460d63176b466cc8b9927378940fc5543506a02e
3
+ metadata.gz: abba86119ff297f1b65693b634c5f33b11e53ea24f76b5b851d11918bf061694
4
+ data.tar.gz: bf2253285a83d24d1e7a5264d839506f65b32a45c27203dcf12202daab0c527a
5
5
  SHA512:
6
- metadata.gz: 5282dc961ae5f4f9dbe08c3f0e225ad3e8849522d5f0f7de7deaa233463479197498c91327dc8e6455478ee4469cbec660f6c278a45b09218a45e3d3d8f5736d
7
- data.tar.gz: b884d26fb02ec6714d5ff54e862cbe5dccec2853b4ebcdda84410ccda65fc7693428e163b390a7d71b741a538d5ef9e0c5aac365d8709ff301e0344bb7bd8880
6
+ metadata.gz: d63a2a62b5f8103eca1c0ae9429a5538cb5a0add23ca14fdceb1759f821d5a0f8ddeb22c06efad3780b5498d8c6ff0fea4f9d0c86c3d1e1dbfd443265f3b4f4a
7
+ data.tar.gz: 7cd9d08794c1fa4cb2c47575c3977d35a781874c5f27f03ee31eb251e153062f91e8bd38236da887cc1a1fb6e401250038e98cd44d63197e120d84cd8171ef1f
@@ -1,5 +1,25 @@
1
1
  module Z3
2
2
  class ArrayExpr < Expr
3
3
  public_class_method :new
4
+
5
+ def key_sort
6
+ sort.key_sort
7
+ end
8
+
9
+ def value_sort
10
+ sort.value_sort
11
+ end
12
+
13
+ def store(key, value)
14
+ sort.new LowLevel.mk_store(self, key_sort.cast(key), value_sort.cast(value))
15
+ end
16
+
17
+ def select(key)
18
+ sort.value_sort.new LowLevel.mk_select(self, key_sort.cast(key))
19
+ end
20
+
21
+ def [](key)
22
+ select(key)
23
+ end
4
24
  end
5
25
  end
data/lib/z3/interface.rb CHANGED
@@ -72,6 +72,10 @@ module Z3
72
72
  LowLevel.get_version.join(".")
73
73
  end
74
74
 
75
+ def version_at_least?(a, b=0, c=0, d=0)
76
+ (LowLevel.get_version <=> [a, b, c, d]) >= 0
77
+ end
78
+
75
79
  def set_param(k,v)
76
80
  LowLevel.global_param_set(k,v)
77
81
  end
@@ -4,7 +4,9 @@ module Z3
4
4
  let(:a) { sort.var("a") }
5
5
  let(:b) { sort.var("b") }
6
6
  let(:c) { sort.var("c") }
7
- let(:x) { Z3::Bool("x") }
7
+ let(:x) { Z3::Int("x") }
8
+ let(:y) { Z3::Int("y") }
9
+ let(:z) { Z3::Int("z") }
8
10
 
9
11
  # TODO: Formatting is dreadful
10
12
  it "== and !=" do
@@ -14,5 +16,35 @@ module Z3
14
16
  c => "const(0)",
15
17
  )
16
18
  end
19
+
20
+ it "select" do
21
+ expect([a.select(10) == 20]).to have_solution(
22
+ a => "const(20)",
23
+ )
24
+ expect([a[10] == 20]).to have_solution(
25
+ a => "const(20)",
26
+ )
27
+ expect([a[x] == 10, a[y] == 20]).to have_solution(
28
+ a => "store(const(10), 3, 20)",
29
+ x => "2",
30
+ y => "3",
31
+ )
32
+ end
33
+
34
+ it "store" do
35
+ expect([a == b.store(10, 20), x == a.select(10)]).to have_solution(
36
+ x => 20,
37
+ )
38
+ expect([a == b.store(10, 20), x == a[10]]).to have_solution(
39
+ x => 20,
40
+ )
41
+ expect([a == b.store(10, 20), x == a[y], y == 10]).to have_solution(
42
+ x => 20,
43
+ )
44
+ expect([a == b.store(10, 20), x == a[y], x == 20]).to have_solution(
45
+ x => 20,
46
+ y => 10,
47
+ )
48
+ end
17
49
  end
18
50
  end
@@ -1,7 +1,7 @@
1
1
  module Z3
2
2
  describe ArraySort do
3
- let(:int_int_array) { ArraySort.new(IntSort.new, IntSort.new) }
4
- let(:int_real_array) { ArraySort.new(IntSort.new, RealSort.new) }
3
+ let(:int_int_array) { ArraySort.new(IntSort.new, IntSort.new) }
4
+ let(:int_real_array) { ArraySort.new(IntSort.new, RealSort.new) }
5
5
 
6
6
  it "can instantiate variables" do
7
7
  expect(int_int_array.var("a").inspect).to eq("Array(Int, Int)<a>")
@@ -102,8 +102,9 @@ module Z3
102
102
  expect(positive_infinity.to_s).to eq("+oo")
103
103
  expect(negative_infinity.to_s).to eq("-oo")
104
104
  expect(nan.to_s).to eq("NaN")
105
+
105
106
  # Denormals changed
106
- if Z3.version >= '4.5'
107
+ if Z3.version_at_least?(4, 6)
107
108
  expect(float_double.from_const(1234 * 0.5**1040).to_s).to eq("0.00470733642578125B-1022")
108
109
  expect(float_single.from_const(1234 * 0.5**136).to_s).to eq("1.205078125B-126")
109
110
  # This is what we get, all of these are wrong, by a lot:
@@ -0,0 +1,90 @@
1
+ Solved
2
+ State 0:
3
+ bbb.
4
+ xbxw
5
+ ..ww
6
+ x.xw
7
+ w: 3,3 -> 1,2
8
+
9
+ State 1:
10
+ bbb.
11
+ xbxw
12
+ .www
13
+ x.x.
14
+ b: 1,1 -> 3,0
15
+
16
+ State 2:
17
+ bbbb
18
+ x.xw
19
+ .www
20
+ x.x.
21
+ w: 3,2 -> 1,1
22
+
23
+ State 3:
24
+ bbbb
25
+ xwxw
26
+ .ww.
27
+ x.x.
28
+ b: 2,0 -> 3,2
29
+
30
+ State 4:
31
+ bb.b
32
+ xwxw
33
+ .wwb
34
+ x.x.
35
+ w: 1,2 -> 2,0
36
+
37
+ State 5:
38
+ bbwb
39
+ xwxw
40
+ ..wb
41
+ x.x.
42
+ b: 0,0 -> 1,2
43
+
44
+ State 6:
45
+ .bwb
46
+ xwxw
47
+ .bwb
48
+ x.x.
49
+ b: 1,2 -> 3,3
50
+
51
+ State 7:
52
+ .bwb
53
+ xwxw
54
+ ..wb
55
+ x.xb
56
+ w: 3,1 -> 1,2
57
+
58
+ State 8:
59
+ .bwb
60
+ xwx.
61
+ .wwb
62
+ x.xb
63
+ b: 1,0 -> 3,1
64
+
65
+ State 9:
66
+ ..wb
67
+ xwxb
68
+ .wwb
69
+ x.xb
70
+ w: 2,2 -> 1,0
71
+
72
+ State 10:
73
+ .wwb
74
+ xwxb
75
+ .w.b
76
+ x.xb
77
+ b: 3,0 -> 2,2
78
+
79
+ State 11:
80
+ .ww.
81
+ xwxb
82
+ .wbb
83
+ x.xb
84
+ w: 1,2 -> 0,0
85
+
86
+ State 12:
87
+ www.
88
+ xwxb
89
+ ..bb
90
+ x.xb
@@ -17,7 +17,7 @@ module Z3
17
17
  )
18
18
  end
19
19
 
20
- if Z3.version >= "4.5"
20
+ if Z3.version_at_least?(4, 5)
21
21
  # Only works in z3 4.5, 4.4 (like on Ubuntu) returns bad stuff
22
22
  it "union" do
23
23
  expect([
data/spec/solver_spec.rb CHANGED
@@ -43,7 +43,7 @@ module Z3
43
43
  # This is a very simple example of unknown satisfiablity
44
44
  # so we might need more complex one in the future
45
45
  # This is now satisfiable in 4.6.0
46
- if Z3.version >= "4.6"
46
+ if Z3.version_at_least?(4, 6)
47
47
  it "unknown satisfiability (until 4.6 fix)" do
48
48
  solver.assert a**3 == a
49
49
  expect(solver.check).to eq(:sat)
data/spec/z3_spec.rb CHANGED
@@ -2,4 +2,14 @@ describe Z3 do
2
2
  it "#version return version number of Z3 library" do
3
3
  expect(Z3.version).to match(/\A\d+\.\d+\.\d+\.\d+\z/)
4
4
  end
5
+
6
+ it "#version_at_least return if version matches" do
7
+ version = Z3.version.split(".").map(&:to_i)
8
+ expect(Z3.version_at_least?(*version)).to eq(true)
9
+ expect(Z3.version_at_least?(*version[0,2])).to eq(true)
10
+ expect(Z3.version_at_least?(*version[0,1])).to eq(true)
11
+ expect(Z3.version_at_least?(version[0])).to eq(true)
12
+ expect(Z3.version_at_least?(*version[0,2], 999)).to eq(false)
13
+ expect(Z3.version_at_least?(999)).to eq(false)
14
+ end
5
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: z3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20220828
4
+ version: 0.0.20221020
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Wegrzanowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-28 00:00:00.000000000 Z
11
+ date: 2022-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -287,6 +287,7 @@ files:
287
287
  - spec/integration/examples/knights_puzzle-1.txt
288
288
  - spec/integration/examples/knights_puzzle-2.txt
289
289
  - spec/integration/examples/knights_puzzle-3.txt
290
+ - spec/integration/examples/knights_puzzle-4.txt
290
291
  - spec/integration/four_hackers_puzzle_spec.rb
291
292
  - spec/integration/futoshiki_spec.rb
292
293
  - spec/integration/geometry_problem_spec.rb