Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add modular-arithmetic types to Geb external API #61

@rokopt

Description

@rokopt

The substobj and substmorph types in https://github.com/anoma/geb/blob/main/src/specs/geb.lisp should be extended with those required for built-in modular arithmetic.

Specifically, there will be a new object called something like fs n for each non-zero natural n (not for zero, because arithmetic mod 0 is Nat itself, and circuits can only support fixed-size natural numbers).

There will be the following new morphisms with the following signatures, where bool is coprod so1 so1, and fs <n> means for every non-zero natural number <n>:

  • For each natural number m including zero and less than n, const m : so1 -> fs n
  • inj : fs m -> fs n (injects one bounded type into another -- may wrap around if m > n; equal to id if m == n)
  • + : prod (fs m) (fs n) -> fs p
  • * : prod (fs m) (fs n) -> fs p
  • - : prod (fs m) (fs n) -> fs p
  • / : prod (fs m) (fs n) -> fs p
  • % : prod (fs m) (fs n) -> fs p
  • == : prod (fs m) (fs n) -> bool
  • < : prod (fs m) (fs n) -> bool

Because the arithmetic is modular, overflows just cause wraparound. Division and modulus by zero will produce errors at witness generation time in VampIR. (Once we support dependent types in Geb, we will be able to allow users to include proof content demonstrating that they are not dividing by zero.)

VampIR higher-order functions might be helpful in integrating this with #60 ; see https://github.com/anoma/vamp-ir/blob/main/tests/funcs.pir for examples.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions