purify
C++ Purify implementation with native circuit and BPP support
Loading...
Searching...
No Matches
purify::Expr Class Reference

Symbolic affine expression over indexed variables and field coefficients. More...

#include <expr.hpp>

Public Types

using Term = std::pair< Symbol, FieldElement >
 

Public Member Functions

 Expr ()
 Constructs the zero expression.
 
 Expr (const FieldElement &value)
 Constructs a pure constant expression from a field element.
 
 Expr (std::int64_t value)
 Constructs a pure constant expression from a signed integer.
 
const FieldElementconstant () const
 Returns the constant term of the affine expression.
 
std::vector< Term > & linear ()
 Returns mutable access to the sorted linear term list.
 
const std::vector< Term > & linear () const
 Returns read-only access to the sorted linear term list.
 
std::string to_string () const
 Formats the expression in a stable human-readable form used for debugging and serialization.
 
std::optional< FieldElementevaluate (const WitnessAssignments &values) const
 Evaluates the expression against a possibly partial transcript witness assignment.
 
std::pair< Expr, Exprsplit () const
 Splits the expression into a pure constant and a pure linear component.
 

Static Public Member Functions

static Expr variable (Symbol symbol)
 Returns a single-variable expression with coefficient one.
 

Friends

Expr operator+ (const Expr &lhs, const Expr &rhs)
 Adds two affine expressions and merges like terms.
 
Expr operator+ (const Expr &lhs, std::int64_t rhs)
 Adds an integer constant to an affine expression.
 
Expr operator+ (std::int64_t lhs, const Expr &rhs)
 Adds an affine expression to an integer constant.
 
Expr operator- (const Expr &lhs, const Expr &rhs)
 Subtracts one affine expression from another.
 
Expr operator- (const Expr &lhs, std::int64_t rhs)
 Subtracts an integer constant from an affine expression.
 
Expr operator- (std::int64_t lhs, const Expr &rhs)
 Subtracts an affine expression from an integer constant.
 
Expr operator- (const Expr &value)
 Negates every coefficient in the affine expression.
 
Expr operator* (const Expr &expr, const FieldElement &scalar)
 Scales an affine expression by a field element.
 
Expr operator* (const FieldElement &scalar, const Expr &expr)
 Scales an affine expression by a field element.
 
Expr operator* (const Expr &expr, std::int64_t scalar)
 Scales an affine expression by an integer constant.
 
Expr operator* (std::int64_t scalar, const Expr &expr)
 Scales an affine expression by an integer constant.
 
bool operator== (const Expr &lhs, const Expr &rhs)
 Compares two affine expressions structurally.
 
bool operator< (const Expr &lhs, const Expr &rhs)
 Orders affine expressions structurally for cache keys.
 

Detailed Description

This type is used while deriving circuit relations before they are lowered into native multiplication gates and linear constraints.

Definition at line 71 of file expr.hpp.

Member Typedef Documentation

◆ Term

using purify::Expr::Term = std::pair<Symbol, FieldElement>

Definition at line 73 of file expr.hpp.

Constructor & Destructor Documentation

◆ Expr() [1/3]

purify::Expr::Expr ( )

Definition at line 92 of file expr.cpp.

Referenced by split().

◆ Expr() [2/3]

purify::Expr::Expr ( const FieldElement value)
explicit

Definition at line 94 of file expr.cpp.

◆ Expr() [3/3]

purify::Expr::Expr ( std::int64_t  value)
explicit

Definition at line 96 of file expr.cpp.

Member Function Documentation

◆ constant()

◆ evaluate()

std::optional< FieldElement > purify::Expr::evaluate ( const WitnessAssignments values) const

◆ linear() [1/2]

◆ linear() [2/2]

const std::vector< Term > & purify::Expr::linear ( ) const
inline

Definition at line 96 of file expr.hpp.

◆ split()

std::pair< Expr, Expr > purify::Expr::split ( ) const

Definition at line 140 of file expr.cpp.

References Expr().

◆ to_string()

std::string purify::Expr::to_string ( ) const

◆ variable()

Friends And Related Symbol Documentation

◆ operator* [1/4]

Expr operator* ( const Expr expr,
const FieldElement scalar 
)
friend

Definition at line 311 of file expr.cpp.

◆ operator* [2/4]

Expr operator* ( const Expr expr,
std::int64_t  scalar 
)
friend

Definition at line 327 of file expr.cpp.

◆ operator* [3/4]

Expr operator* ( const FieldElement scalar,
const Expr expr 
)
friend

Definition at line 323 of file expr.cpp.

◆ operator* [4/4]

Expr operator* ( std::int64_t  scalar,
const Expr expr 
)
friend

Definition at line 331 of file expr.cpp.

◆ operator+ [1/3]

Expr operator+ ( const Expr lhs,
const Expr rhs 
)
friend

Definition at line 265 of file expr.cpp.

◆ operator+ [2/3]

Expr operator+ ( const Expr lhs,
std::int64_t  rhs 
)
friend

Definition at line 287 of file expr.cpp.

◆ operator+ [3/3]

Expr operator+ ( std::int64_t  lhs,
const Expr rhs 
)
friend

Definition at line 291 of file expr.cpp.

◆ operator- [1/4]

Expr operator- ( const Expr lhs,
const Expr rhs 
)
friend

Definition at line 295 of file expr.cpp.

◆ operator- [2/4]

Expr operator- ( const Expr lhs,
std::int64_t  rhs 
)
friend

Definition at line 299 of file expr.cpp.

◆ operator- [3/4]

Expr operator- ( const Expr value)
friend

Definition at line 307 of file expr.cpp.

◆ operator- [4/4]

Expr operator- ( std::int64_t  lhs,
const Expr rhs 
)
friend

Definition at line 303 of file expr.cpp.

◆ operator<

bool operator< ( const Expr lhs,
const Expr rhs 
)
friend

Definition at line 369 of file expr.cpp.

◆ operator==

bool operator== ( const Expr lhs,
const Expr rhs 
)
friend

Definition at line 335 of file expr.cpp.


The documentation for this class was generated from the following files: