Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
Public Member Functions | List of all members
gadgetlib2::Monomial Class Reference

Monomial. More...

#include <variable.hpp>

Public Member Functions

 Monomial (const Variable &var)
 
 Monomial (const Variable &var, const FElem &coeff)
 
 Monomial (const FElem &val)
 
 Monomial (const LinearTerm &linearTerm)
 
FElem eval (const VariableAssignment &assignment) const
 
const Variable::set getUsedVariables () const
 
const FElem getCoefficient () const
 
::std::string asString () const
 
Monomial operator- () const
 
Monomialoperator*= (const Monomial &other)
 

Detailed Description

Monomial.

Definition at line 543 of file variable.hpp.

Constructor & Destructor Documentation

◆ Monomial() [1/4]

gadgetlib2::Monomial::Monomial ( const Variable var)
inline

Definition at line 553 of file variable.hpp.

553  : coeff_(1), variables_()
554  {
555  variables_.insert(var);
556  }

◆ Monomial() [2/4]

gadgetlib2::Monomial::Monomial ( const Variable var,
const FElem coeff 
)
inline

Definition at line 557 of file variable.hpp.

558  : coeff_(coeff), variables_()
559  {
560  variables_.insert(var);
561  }

◆ Monomial() [3/4]

gadgetlib2::Monomial::Monomial ( const FElem val)
inline

Definition at line 562 of file variable.hpp.

562 : coeff_(val), variables_() {}

◆ Monomial() [4/4]

gadgetlib2::Monomial::Monomial ( const LinearTerm linearTerm)

Definition at line 635 of file variable.cpp.

636  : coeff_(linearTerm.coeff_), variables_()
637 {
638  variables_.insert(linearTerm.variable_);
639 }

Member Function Documentation

◆ asString()

std::string gadgetlib2::Monomial::asString ( ) const

Definition at line 657 of file variable.cpp.

658 {
659 #ifdef DEBUG
660  if (variables_.size() == 0) {
661  return coeff_.asString();
662  }
663  string retval;
664  if (coeff_ != 1) {
665  retval += coeff_.asString() + "*";
666  }
667  auto iter = variables_.begin();
668  retval += iter->name();
669  for (++iter; iter != variables_.end(); ++iter) {
670  retval += "*" + iter->name();
671  }
672  return retval;
673 #else
674  return "";
675 #endif
676 }
Here is the call graph for this function:

◆ eval()

FElem gadgetlib2::Monomial::eval ( const VariableAssignment assignment) const

Definition at line 641 of file variable.cpp.

642 {
643  FElem retval = coeff_;
644  for (const Variable &var : variables_) {
645  retval *= var.eval(assignment);
646  }
647  return retval;
648 }

◆ getCoefficient()

const FElem gadgetlib2::Monomial::getCoefficient ( ) const

Definition at line 655 of file variable.cpp.

655 { return coeff_; }

◆ getUsedVariables()

const Variable::set gadgetlib2::Monomial::getUsedVariables ( ) const

Definition at line 650 of file variable.cpp.

651 {
652  return Variable::set(variables_.begin(), variables_.end());
653 }

◆ operator*=()

Monomial & gadgetlib2::Monomial::operator*= ( const Monomial other)

Definition at line 685 of file variable.cpp.

686 {
687  coeff_ *= other.coeff_;
688  variables_.insert(other.variables_.begin(), other.variables_.end());
689  return *this;
690 }

◆ operator-()

Monomial gadgetlib2::Monomial::operator- ( ) const

Definition at line 678 of file variable.cpp.

679 {
680  Monomial retval = *this;
681  retval.coeff_ = -retval.coeff_;
682  return retval;
683 }

The documentation for this class was generated from the following files:
gadgetlib2::Monomial::Monomial
Monomial(const Variable &var)
Definition: variable.hpp:553
gadgetlib2::Variable::set
::std::set< Variable, VariableStrictOrder > set
A set of Variables should be declared as follows: Variable::set s1;.
Definition: variable.hpp:341
gadgetlib2::FElem::asString
::std::string asString() const
Definition: variable.hpp:127