expr

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

An expression supporting quadratic terms, implemented based on gnark `frontend/internal/expr`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Expression

type Expression []Term

func NewConstantExpression

func NewConstantExpression(c constraint.Element) Expression

NewConstantExpression returns c

func NewLinearExpression

func NewLinearExpression(v int, c constraint.Element) Expression

NewLinearExpression returns c * v

func NewQuadraticExpression

func NewQuadraticExpression(v0, v1 int, c constraint.Element) Expression

NewQuadraticExpression returns c * v0 * v1

func (Expression) Clone

func (e Expression) Clone() Expression

func (Expression) CountOfDegrees

func (e Expression) CountOfDegrees() (int, int, int)

CountOfDegrees returns the number of terms of each degree

func (Expression) Degree

func (e Expression) Degree() int

Degree returns the degree of the polynomial

func (Expression) Equal

func (e Expression) Equal(o Expression) bool

Equals returns true if both SORTED expressions are the same

pre conditions: l and o are sorted

func (Expression) EqualI

func (e Expression) EqualI(o utils.Hashable) bool

EqualI is similar to Equal, but o is utils.Hashable. Then it can be saved in a utils.Map

func (Expression) HashCode

func (e Expression) HashCode() uint64

HashCode returns a fast-to-compute but NOT collision resistant hash code identifier for the linear expression

requires sorted

func (Expression) IsConstant

func (e Expression) IsConstant() bool

func (Expression) Len

func (e Expression) Len() int

Len return the length of the Variable (implements Sort interface)

func (Expression) Less

func (e Expression) Less(i, j int) bool

Less returns true if variableID for term at i is less than variableID for term at j (implements Sort interface)

func (Expression) Swap

func (e Expression) Swap(i, j int)

Swap swaps terms in the Variable (implements Sort interface)

func (Expression) ToBigIntRegular

func (e Expression) ToBigIntRegular(*big.Int) *big.Int

ToBigIntRegular implements gnark toBigIntInterface interface Actually it's impossible to convert an Expression to big.Int, but sometimes it requires such evaluation (like in gnark utils.FromInterface). So a fake implementation is created to provide better instructions for users

type Term

type Term struct {
	// if vid1 is 0, it means linear term.
	// if both vid are 0, it means constant
	VID0  int
	VID1  int
	Coeff constraint.Element
}

func NewTerm

func NewTerm(vID0, vID1 int, coeff constraint.Element) Term

func (*Term) Degree

func (t *Term) Degree() int

func (Term) HashCode

func (t Term) HashCode() uint64

Slightly better (?) hash algorithm than the gnark one

func (*Term) SetCoeff

func (t *Term) SetCoeff(c constraint.Element)

func (Term) ToBigIntRegular

func (t Term) ToBigIntRegular(*big.Int) *big.Int

ToBigIntRegular implements gnark toBigIntInterface interface Actually it's impossible to convert a Term to big.Int, but sometimes it requires such evaluation (like in gnark utils.FromInterface). So a fake implementation is created to provide better instructions for users

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL