@@ -6,15 +6,14 @@ open BigOperators
6
6
7
7
namespace GatesDef
8
8
variable {N : Nat}
9
- -- variable [Fact (Nat.Prime N)]
10
9
def is_bool (a : ZMod N): Prop := (1 -a)*a = 0
11
10
def add (a b : ZMod N): ZMod N := a + b
12
11
def mul_acc (a b c : ZMod N): ZMod N := a + (b * c)
13
12
def neg (a : ZMod N): ZMod N := a * (-1 )
14
13
def sub (a b : ZMod N): ZMod N := a - b
15
14
def mul (a b : ZMod N): ZMod N := a * b
16
- def div_unchecked [Fact (Nat.Prime N)] (a b out : ZMod N): Prop := (b ≠ 0 ∧ out*b = a) ∨ (a = 0 ∧ b = 0 ∧ out = 0 )
17
- def div [Fact (Nat.Prime N)] (a b out : ZMod N): Prop := b ≠ 0 ∧ out*b = a
15
+ def div_unchecked (a b out : ZMod N): Prop := (b ≠ 0 ∧ out*b = a) ∨ (a = 0 ∧ b = 0 ∧ out = 0 )
16
+ def div (a b out : ZMod N): Prop := b ≠ 0 ∧ out*b = a
18
17
def inv (a out : ZMod N): Prop := a ≠ 0 ∧ out*a = 1
19
18
def xor (a b out : ZMod N): Prop := is_bool a ∧ is_bool b ∧ out = a+b-a*b-a*b
20
19
def or (a b out : ZMod N): Prop := is_bool a ∧ is_bool b ∧ out = a+b-a*b
@@ -28,16 +27,15 @@ def lookup (b0 b1 i0 i1 i2 i3 out : ZMod N): Prop :=
28
27
-- however this doesn't guarantee that the number is unique.
29
28
def cmp_8 (a b out : ZMod N): Prop :=
30
29
∃z w: Fin (binary_length N), z.val % N = a.val ∧ w.val % N = b.val ∧
31
- ((a = b ∧ out = 0 ) ∨
32
- (a .val < b .val ∧ out = -1 ) ∨
33
- (a .val > b .val ∧ out = 1 ))
30
+ ((z = w ∧ out = 0 ) ∨
31
+ (z .val < w .val ∧ out = -1 ) ∨
32
+ (z .val > w .val ∧ out = 1 ))
34
33
35
34
-- In gnark 9 the number is reduced to the smallest representation, ensuring it is unique.
36
35
def cmp_9 (a b out : ZMod N): Prop :=
37
- ∃z w: Fin (binary_length N), z.val = a.val ∧ w.val = b.val ∧
38
- ((a = b ∧ out = 0 ) ∨
36
+ (a = b ∧ out = 0 ) ∨
39
37
(a.val < b.val ∧ out = -1 ) ∨
40
- (a.val > b.val ∧ out = 1 ))
38
+ (a.val > b.val ∧ out = 1 )
41
39
42
40
def is_zero (a out: ZMod N): Prop := (a ≠ 0 ∧ out = 0 ) ∨ (a = 0 ∧ out = 1 )
43
41
def eq (a b : ZMod N): Prop := a = b
@@ -80,7 +78,7 @@ structure Gates_base (α : Type) : Type where
80
78
to_binary : α → (n : Nat) → Vector α n → Prop
81
79
from_binary : Vector α d → α → Prop
82
80
83
- def GatesGnark_8 (N : Nat) [Fact (Nat.Prime N)] : Gates_base (ZMod N) := {
81
+ def GatesGnark8 (N : Nat) [Fact (Nat.Prime N)] : Gates_base (ZMod N) := {
84
82
is_bool := GatesDef.is_bool,
85
83
add := GatesDef.add,
86
84
mul_acc := GatesDef.mul_acc,
@@ -104,8 +102,8 @@ def GatesGnark_8 (N : Nat) [Fact (Nat.Prime N)] : Gates_base (ZMod N) := {
104
102
from_binary := GatesDef.from_binary
105
103
}
106
104
107
- def GatesGnark_9 (N : Nat) [Fact (Nat.Prime N)] : Gates_base (ZMod N) := {
108
- GatesGnark_8 N with
105
+ def GatesGnark9 (N : Nat) [Fact (Nat.Prime N)] : Gates_base (ZMod N) := {
106
+ GatesGnark8 N with
109
107
cmp := GatesDef.cmp_9
110
108
le := GatesDef.le_9
111
109
}
0 commit comments