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

Polynomial. More...

#include <variable.hpp>

Public Member Functions

 Polynomial ()
 
 Polynomial (const Monomial &monomial)
 
 Polynomial (const Variable &var)
 
 Polynomial (const FElem &val)
 
 Polynomial (const LinearCombination &linearCombination)
 
 Polynomial (const LinearTerm &linearTerm)
 
 Polynomial (int i)
 
FElem eval (const VariableAssignment &assignment) const
 
const Variable::set getUsedVariables () const
 
const std::vector< Monomial > & getMonomials () const
 
const FElem getConstant () const
 
::std::string asString () const
 
Polynomialoperator+= (const Polynomial &other)
 
Polynomialoperator*= (const Polynomial &other)
 
Polynomialoperator-= (const Polynomial &other)
 
Polynomialoperator+= (const LinearTerm &other)
 

Detailed Description

Polynomial.

Definition at line 574 of file variable.hpp.

Constructor & Destructor Documentation

◆ Polynomial() [1/7]

gadgetlib2::Polynomial::Polynomial ( )
inline

Definition at line 581 of file variable.hpp.

581 : monomials_(), constant_(0) {}
Here is the caller graph for this function:

◆ Polynomial() [2/7]

gadgetlib2::Polynomial::Polynomial ( const Monomial monomial)
inline

Definition at line 582 of file variable.hpp.

582  : monomials_(1, monomial), constant_(0)
583  {
584  }

◆ Polynomial() [3/7]

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

Definition at line 585 of file variable.hpp.

585  : monomials_(1, Monomial(var)), constant_(0)
586  {
587  }

◆ Polynomial() [4/7]

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

Definition at line 588 of file variable.hpp.

588 : monomials_(), constant_(val) {}

◆ Polynomial() [5/7]

gadgetlib2::Polynomial::Polynomial ( const LinearCombination linearCombination)

Definition at line 704 of file variable.cpp.

705  : monomials_(), constant_(linearCombination.constant_)
706 {
707  for (const LinearTerm &linearTerm : linearCombination.linearTerms_) {
708  monomials_.push_back(Monomial(linearTerm));
709  }
710 }

◆ Polynomial() [6/7]

gadgetlib2::Polynomial::Polynomial ( const LinearTerm linearTerm)
inline

Definition at line 590 of file variable.hpp.

591  : monomials_(1, Monomial(linearTerm)), constant_(0)
592  {
593  }

◆ Polynomial() [7/7]

gadgetlib2::Polynomial::Polynomial ( int  i)
inline

Definition at line 594 of file variable.hpp.

594 : monomials_(), constant_(i) {}

Member Function Documentation

◆ asString()

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

Definition at line 735 of file variable.cpp.

736 {
737 #ifndef DEBUG
738  return "";
739 #endif
740  if (monomials_.size() == 0) {
741  return constant_.asString();
742  }
743  string retval;
744  auto iter = monomials_.begin();
745  retval += iter->asString();
746  for (++iter; iter != monomials_.end(); ++iter) {
747  retval += " + " + iter->asString();
748  }
749  if (constant_ != 0) {
750  retval += " + " + constant_.asString();
751  }
752  return retval;
753 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eval()

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

Definition at line 712 of file variable.cpp.

713 {
714  FElem retval = constant_;
715  for (const Monomial &monomial : monomials_) {
716  retval += monomial.eval(assignment);
717  }
718  return retval;
719 }
Here is the caller graph for this function:

◆ getConstant()

const FElem gadgetlib2::Polynomial::getConstant ( ) const

Definition at line 733 of file variable.cpp.

733 { return constant_; }

◆ getMonomials()

const vector< Monomial > & gadgetlib2::Polynomial::getMonomials ( ) const

Definition at line 731 of file variable.cpp.

731 { return monomials_; }

◆ getUsedVariables()

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

Definition at line 721 of file variable.cpp.

722 {
723  Variable::set retset;
724  for (const Monomial &monomial : monomials_) {
725  const Variable::set curSet = monomial.getUsedVariables();
726  retset.insert(curSet.begin(), curSet.end());
727  }
728  return retset;
729 }
Here is the caller graph for this function:

◆ operator*=()

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

Definition at line 763 of file variable.cpp.

764 {
765  vector<Monomial> newMonomials;
766  for (const Monomial &thisMonomial : monomials_) {
767  for (const Monomial &otherMonomial : other.monomials_) {
768  newMonomials.push_back(thisMonomial * otherMonomial);
769  }
770  newMonomials.push_back(thisMonomial * other.constant_);
771  }
772  for (const Monomial &otherMonomial : other.monomials_) {
773  newMonomials.push_back(otherMonomial * this->constant_);
774  }
775  constant_ *= other.constant_;
776  monomials_ = ::std::move(newMonomials);
777  return *this;
778 }

◆ operator+=() [1/2]

Polynomial& gadgetlib2::Polynomial::operator+= ( const LinearTerm other)
inline

Definition at line 604 of file variable.hpp.

605  {
606  return *this += Polynomial(Monomial(other));
607  }
Here is the call graph for this function:

◆ operator+=() [2/2]

Polynomial & gadgetlib2::Polynomial::operator+= ( const Polynomial other)

Definition at line 755 of file variable.cpp.

756 {
757  constant_ += other.constant_;
758  monomials_.insert(
759  monomials_.end(), other.monomials_.begin(), other.monomials_.end());
760  return *this;
761 }

◆ operator-=()

Polynomial & gadgetlib2::Polynomial::operator-= ( const Polynomial other)

Definition at line 780 of file variable.cpp.

781 {
782  constant_ -= other.constant_;
783  for (const Monomial &otherMonomial : other.monomials_) {
784  monomials_.push_back(-otherMonomial);
785  }
786  return *this;
787 }

The documentation for this class was generated from the following files:
gadgetlib2::Polynomial::Polynomial
Polynomial()
Definition: variable.hpp:581
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