Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add adder Test(s) #400

Open
DavePearce opened this issue Nov 27, 2024 · 1 comment
Open

Add adder Test(s) #400

DavePearce opened this issue Nov 27, 2024 · 1 comment

Comments

@DavePearce
Copy link
Collaborator

DavePearce commented Nov 27, 2024

Here is my code:

(defcolumns
  (X3 :i16@prove) (X2 :i16@prove) (X1 :i16@prove) (X0 :i16@prove)
  (Y3 :i16@prove) (Y2 :i16@prove) (Y1 :i16@prove) (Y0 :i16@prove)
  (C3 :i1@prove)  (C2 :i1@prove)  (C1 :i1@prove)  (C0 :i1@prove)
  (Z3 :i16)       (Z2 :i16)       (Z1 :i16)       (Z0 :i16))

(defconst OVERFLOW 65536)

(defpurefun (ADDER cin arg1 arg2 out cout)
  (eq! (+ out (* cout OVERFLOW)) (+ arg1 arg2 cin)))

(defconstraint X_Y_Z ()
  (begin
   (ADDER 0 X0 Y0 Z0 C0)
   (ADDER C0 X1 Y1 Z1 C1)
   (ADDER C1 X2 Y2 Z2 C2)
   (ADDER C2 X3 Y3 Z3 C3)))

And an example trace:

{ "<prelude>": {
    "X3": [0], "X2": [0], "X1": [0], "X0": [33000],
    "Y3": [0], "Y2": [0], "Y1": [0], "Y0": [33001],
    "C3": [0], "C2": [0], "C1": [0], "C0": [1],        
    "Z3": [0], "Z2": [0], "Z1": [1], "Z0": [465]
}}

What we could do is actually enumerate all input / output values and check it really works. We could repeat this for other operators related to field agnosticity.

@DavePearce
Copy link
Collaborator Author

(defcolumns
  (X3 :i16@prove) (X2 :i16@prove) (X1 :i16@prove) (X0 :i16@prove)
  (RES :binary@prove)
)

(defpurefun ((IS-ZERO :binary@loob :force) w3 w2 w1 w0) (+ w3 w2 w1 w0))

(defconstraint c1 ()
  (if (IS-ZERO X3 X2 X1 X0)
      (vanishes! RES) (eq! RES 1)))

And an example trace:

{ "<prelude>": {
    "X3": [0], "X2": [0], "X1": [0], "X0": [0],
    "RES": [0]
}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant