Documentation ¶
Overview ¶
Package data defines basic mathematical structures used throughout the library.
Index ¶
- type Matrix
- func Identity(rows, cols int) Matrix
- func NewConstantMatrix(rows, cols int, c *big.Int) Matrix
- func NewMatrix(vectors []Vector) (Matrix, error)
- func NewRandomDetMatrix(rows, cols int, max *big.Int, key *[32]byte) (Matrix, error)
- func NewRandomMatrix(rows, cols int, sampler sample.Sampler) (Matrix, error)
- func (m Matrix) Add(other Matrix) (Matrix, error)
- func (m Matrix) Apply(f func(*big.Int) *big.Int) Matrix
- func (m Matrix) CheckBound(bound *big.Int) error
- func (m Matrix) CheckDims(rows, cols int) bool
- func (m Matrix) Cols() int
- func (m Matrix) Copy() Matrix
- func (m Matrix) Determinant() (*big.Int, error)
- func (m Matrix) DeterminantGauss(p *big.Int) (*big.Int, error)
- func (m Matrix) DimsMatch(other Matrix) bool
- func (m Matrix) Dot(other Matrix) (*big.Int, error)
- func (m Matrix) GaussianElimination(p *big.Int) (Matrix, error)
- func (m Matrix) GetCol(i int) (Vector, error)
- func (m Matrix) InverseMod(p *big.Int) (Matrix, error)
- func (m Matrix) InverseModGauss(p *big.Int) (Matrix, *big.Int, error)
- func (m Matrix) JoinCols(other Matrix) (Matrix, error)
- func (m Matrix) JoinRows(other Matrix) (Matrix, error)
- func (m Matrix) MatMulMatG1(other MatrixG1) (MatrixG1, error)
- func (m Matrix) MatMulMatG2(other MatrixG2) (MatrixG2, error)
- func (m Matrix) MatMulVecG2(other VectorG2) (VectorG2, error)
- func (m Matrix) Minor(i int, j int) (Matrix, error)
- func (m Matrix) Mod(modulo *big.Int) Matrix
- func (m Matrix) Mul(other Matrix) (Matrix, error)
- func (m Matrix) MulG1() MatrixG1
- func (m Matrix) MulG2() MatrixG2
- func (m Matrix) MulScalar(x *big.Int) Matrix
- func (m Matrix) MulVec(v Vector) (Vector, error)
- func (m Matrix) MulXMatY(x, y Vector) (*big.Int, error)
- func (m Matrix) Rows() int
- func (m Matrix) Sub(other Matrix) (Matrix, error)
- func (m Matrix) Tensor(other Matrix) Matrix
- func (m Matrix) ToVec() Vector
- func (m Matrix) Transpose() Matrix
- type MatrixG1
- type MatrixG2
- type Vector
- func GaussianEliminationSolver(mat Matrix, v Vector, p *big.Int) (Vector, error)
- func NewConstantVector(len int, c *big.Int) Vector
- func NewRandomDetVector(len int, max *big.Int, key *[32]byte) (Vector, error)
- func NewRandomVector(len int, sampler sample.Sampler) (Vector, error)
- func NewVector(coordinates []*big.Int) Vector
- func (v Vector) Add(other Vector) Vector
- func (v Vector) Apply(f func(*big.Int) *big.Int) Vector
- func (v Vector) CheckBound(bound *big.Int) error
- func (v Vector) Copy() Vector
- func (v Vector) Dot(other Vector) (*big.Int, error)
- func (v Vector) Mod(modulo *big.Int) Vector
- func (v Vector) MulAsPolyInRing(other Vector) (Vector, error)
- func (v Vector) MulG1() VectorG1
- func (v Vector) MulG2() VectorG2
- func (v Vector) MulScalar(x *big.Int) Vector
- func (v Vector) MulVecG1(g1 VectorG1) VectorG1
- func (v Vector) MulVecG2(g2 VectorG2) VectorG2
- func (v Vector) Neg() Vector
- func (v Vector) String() string
- func (v Vector) Sub(other Vector) Vector
- func (v Vector) Tensor(other Vector) Vector
- type VectorG1
- type VectorG2
- type VectorGT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Matrix ¶
type Matrix []Vector
Matrix wraps a slice of Vector elements. It represents a row-major. order matrix.
The j-th element from the i-th vector of the matrix can be obtained as m[i][j].
func NewConstantMatrix ¶
NewConstantMatrix returns a new Matrix instance with all elements set to constant c.
func NewMatrix ¶
NewMatrix accepts a slice of Vector elements and returns a new Matrix instance. It returns error if not all the vectors have the same number of elements.
func NewRandomDetMatrix ¶
NewRandomDetMatrix returns a new Matrix instance with random elements sampled by a pseudo-random number generator. Elements are sampled from [0, max) and key determines the pseudo-random generator.
func NewRandomMatrix ¶
NewRandomMatrix returns a new Matrix instance with random elements sampled by the provided sample.Sampler. Returns an error in case of sampling failure.
func (Matrix) Add ¶
Add adds matrices m and other. The result is returned in a new Matrix. Error is returned if m and other have different dimensions.
func (Matrix) Apply ¶
Apply applies an element-wise function f to matrix m. The result is returned in a new Matrix.
func (Matrix) CheckBound ¶
CheckBound checks whether all matrix elements are strictly smaller than the provided bound. It returns error if at least one element is >= bound.
func (Matrix) CheckDims ¶
CheckDims checks whether dimensions of matrix m match the provided rows and cols arguments.
func (Matrix) Determinant ¶
Determinant returns the determinant of matrix m. It returns an error if the determinant does not exist.
func (Matrix) DeterminantGauss ¶
DeterminantGauss returns the determinant of matrix m using Gaussian elimination. It returns an error if the determinant does not exist.
func (Matrix) DimsMatch ¶
DimsMatch returns a bool indicating whether matrices m and other have the same dimensions.
func (Matrix) Dot ¶
Dot calculates the dot product (inner product) of matrices m and other, which we define as the sum of the dot product of rows of both matrices. It returns an error if m and other have different dimensions.
func (Matrix) GaussianElimination ¶
GaussianElimination uses Gaussian elimination to transform a matrix into an equivalent upper triangular form
func (Matrix) GetCol ¶
GetCol returns i-th column of matrix m as a vector. It returns error if i >= the number of m's columns.
func (Matrix) InverseMod ¶
InverseMod returns the inverse matrix of m in the group Z_p. Note that as we consider only matrix with integers, the inverse exists only in Z_p.
It returns an error in case matrix is not invertible.
func (Matrix) InverseModGauss ¶
InverseModGauss returns the inverse matrix of m in the group Z_p. The algorithm uses Gaussian elimination. It returns the determinant as well. In case the matrix is not invertible it returns an error.
func (Matrix) JoinCols ¶
JoinCols joins matrices m and other in a new Matrix with columns from both matrices.
func (Matrix) JoinRows ¶
JoinRows joins matrices m and other in a new Matrix with rows from both matrices.
func (Matrix) MatMulMatG1 ¶
MatMulMatG1 multiplies m and other in the sense that if other is t * bn256.G1 for some matrix t, then the function returns m * t * bn256.G1 where m * t is a matrix multiplication.
func (Matrix) MatMulMatG2 ¶
MatMulMatG2 multiplies m and other in the sense that if other is t * bn256.G2 for some matrix t, then the function returns m * t * bn256.G2 where m * t is a matrix multiplication.
func (Matrix) MatMulVecG2 ¶
MatMulVecG2 multiplies m and other in the sense that if other is t * bn256.G2 for some vector t, then the function returns m * t * bn256.G2 where m * t is a matrix-vector multiplication.
func (Matrix) Minor ¶
Minor returns a matrix obtained from m by removing row i and column j. It returns an error if i >= number of rows of m, or if j >= number of columns of m.
func (Matrix) Mod ¶
Mod applies the element-wise modulo operation on matrix m. The result is returned in a new Matrix.
func (Matrix) Mul ¶
Mul multiplies matrices m and other. The result is returned in a new Matrix. Error is returned if m and other have different dimensions.
func (Matrix) MulG1 ¶
MulG1 calculates m * bn256.G1 and returns the result in a new MatrixG1 instance.
func (Matrix) MulG2 ¶
MulG2 calculates m * bn256.G1 and returns the result in a new MatrixG2 instance.
func (Matrix) MulScalar ¶
MulScalar multiplies elements of matrix m by a scalar x. The result is returned in a new Matrix.
func (Matrix) MulVec ¶
MulVec multiplies matrix m and vector v. It returns the resulting vector. Error is returned if the number of columns of m differs from the number of elements of v.
func (Matrix) Sub ¶
Sub adds matrices m and other. The result is returned in a new Matrix. Error is returned if m and other have different dimensions.
func (Matrix) Tensor ¶
Tensor creates a tensor product of matrices m and other. The result is returned in a new Matrix.
type MatrixG1 ¶
type MatrixG1 []VectorG1
MatrixG1 wraps a slice of VectorG1 elements. It represents a row-major. order matrix.
The j-th element from the i-th vector of the matrix can be obtained as m[i][j].
func (MatrixG1) Add ¶
Add sums matrices m and other componentwise. It returns the result in a new MatrixG1 instance.
func (MatrixG1) MulScalar ¶
MulScalar multiplies matrix m by a scalar s. It returns the result in a new MatrixG1 instance.
type MatrixG2 ¶
type MatrixG2 []VectorG2
MatrixG2 wraps a slice of VectorG2 elements. It represents a row-major. order matrix.
The j-th element from the i-th vector of the matrix can be obtained as m[i][j].
type Vector ¶
Vector wraps a slice of *big.Int elements.
func GaussianEliminationSolver ¶
GaussianEliminationSolver solves a vector equation mat * x = v and finds vector x, using Gaussian elimination. Arithmetic operations are considered to be over Z_p, where p should be a prime number. If such x does not exist, then the function returns an error.
func NewConstantVector ¶
NewConstantVector returns a new Vector instance with all elements set to constant c.
func NewRandomDetVector ¶
NewRandomDetVector returns a new Vector instance with (deterministic) random elements sampled by a pseudo-random number generator. Elements are sampled from [0, max) and key determines the pseudo-random generator.
func NewRandomVector ¶
NewRandomVector returns a new Vector instance with random elements sampled by the provided sample.Sampler. Returns an error in case of sampling failure.
func (Vector) Apply ¶
Apply applies an element-wise function f to vector v. The result is returned in a new Vector.
func (Vector) CheckBound ¶
CheckBound checks whether the absolute values of all vector elements are strictly smaller than the provided bound. It returns error if at least one element's absolute value is >= bound.
func (Vector) Dot ¶
Dot calculates the dot product (inner product) of vectors v and other. It returns an error if vectors have different numbers of elements.
func (Vector) Mod ¶
Mod performs modulo operation on vector's elements. The result is returned in a new Vector.
func (Vector) MulAsPolyInRing ¶
MulAsPolyInRing multiplies vectors v and other as polynomials in the ring of polynomials R = Z[x]/((x^n)+1), where n is length of the vectors. Note that the input vector [1, 2, 3] represents a polynomial Z[x] = x²+2x+3. It returns a new polynomial with degree <= n-1.
If vectors differ in size, error is returned.
func (Vector) MulG1 ¶
MulG1 calculates bn256.G1 * v (also g1^v in multiplicative notation) and returns the result (v[0] * bn256.G1, ... , v[n-1] * bn256.G1) in a VectorG1 instance.
func (Vector) MulG2 ¶
MulG2 calculates bn256.G2 * v (also g2^v in multiplicative notation) and returns the result (v[0] * bn256.G2, ... , v[n-1] * bn256.G2) in a VectorG2 instance.
func (Vector) MulScalar ¶
MulScalar multiplies vector v by a given scalar x. The result is returned in a new Vector.
func (Vector) MulVecG1 ¶
MulVecG1 calculates g1 * v (also g1^v in multiplicative notation) and returns the result (v[0] * g1[0], ... , v[n-1] * g1[n-1]) in a VectorG1 instance.
func (Vector) MulVecG2 ¶
MulVecG2 calculates g2 * v (also g2^v in multiplicative notation) and returns the result (v[0] * g2[0], ... , v[n-1] * g2[n-1]) in a VectorG2 instance.
type VectorG1 ¶
VectorG1 wraps a slice of elements from elliptic curve BN256.G1 group.
func (VectorG1) Add ¶
Add sums vectors v1 and v2 (also v1 * v2 in multiplicative notation). It returns the result in a new VectorG1 instance.
type VectorG2 ¶
VectorG2 wraps a slice of elements from elliptic curve BN256.G2 group.
func (VectorG2) Add ¶
Add sums vectors v1 and v2 (also v1 * v2 in multiplicative notation). It returns the result in a new VectorG2 instance.