-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be921fd
commit a8daee5
Showing
3 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
machine Main { | ||
|
||
degree 256; | ||
|
||
Pythagoras pythagoras; | ||
|
||
reg pc[@pc]; | ||
reg X[<=]; | ||
reg Y[<=]; | ||
reg Z[<=]; | ||
reg A; | ||
|
||
instr pythagoras X, Y -> Z = pythagoras.pythagoras | ||
instr assert_eq X, Y { X = Y } | ||
|
||
function main { | ||
A <== pythagoras(3, 4); | ||
assert_eq A, 25; | ||
|
||
A <== pythagoras(4, 3); | ||
assert_eq A, 25; | ||
|
||
A <== pythagoras(1, 2); | ||
assert_eq A, 5; | ||
|
||
return; | ||
} | ||
} | ||
|
||
|
||
machine Pythagoras { | ||
|
||
Arith arith; | ||
|
||
reg pc[@pc]; | ||
reg X[<=]; | ||
reg Y[<=]; | ||
reg Z[<=]; | ||
reg A; | ||
reg B; | ||
|
||
|
||
instr add X, Y -> Z = arith.add | ||
instr mul X, Y -> Z = arith.mul | ||
|
||
function pythagoras a: field, b: field -> field { | ||
A <== mul(a, a); | ||
B <== mul(b, b); | ||
A <== add(A, B); | ||
return A; | ||
} | ||
} | ||
|
||
machine Arith(latch, operation_id) { | ||
|
||
operation add<0> x1, x2 -> y; | ||
operation mul<1> x1, x2 -> y; | ||
|
||
col fixed latch = [1]*; | ||
col witness operation_id; | ||
col witness x1; | ||
col witness x2; | ||
col witness y; | ||
|
||
y = operation_id * (x1 * x2) + (1 - operation_id) * (x1 + x2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
machine Main { | ||
|
||
degree 256; | ||
|
||
Pythagoras pythagoras; | ||
|
||
reg pc[@pc]; | ||
reg X[<=]; | ||
reg Y[<=]; | ||
reg Z[<=]; | ||
reg A; | ||
|
||
instr pythagoras X, Y -> Z = pythagoras.pythagoras | ||
instr assert_eq X, Y { X = Y } | ||
|
||
function main { | ||
A <== pythagoras(3, 4); | ||
assert_eq A, 25; | ||
|
||
A <== pythagoras(4, 3); | ||
assert_eq A, 25; | ||
|
||
A <== pythagoras(1, 2); | ||
assert_eq A, 5; | ||
|
||
return; | ||
} | ||
} | ||
|
||
machine Pythagoras { | ||
|
||
Arith arith; | ||
|
||
reg pc[@pc]; | ||
reg X[<=]; | ||
reg Y[<=]; | ||
reg Z[<=]; | ||
reg A; | ||
reg B; | ||
|
||
|
||
instr add X, Y -> Z = arith.add | ||
instr mul X, Y -> Z = arith.mul | ||
|
||
function pythagoras a: field, b: field -> field { | ||
A <== mul(a, a); | ||
B <== mul(b, b); | ||
A <== add(A, B); | ||
return A; | ||
} | ||
} | ||
|
||
machine Arith { | ||
|
||
reg pc[@pc]; | ||
reg X[<=]; | ||
reg Y[<=]; | ||
reg Z[<=]; | ||
reg A; | ||
|
||
instr add X, Y -> Z { X + Y = Z } | ||
instr mul X, Y -> Z { X * Y = Z } | ||
|
||
function add x: field, y: field -> field { | ||
A <== add(x, y); | ||
return A; | ||
} | ||
|
||
function mul x: field, y: field -> field { | ||
A <== mul(x, y); | ||
return A; | ||
} | ||
} |