Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
Public Member Functions | Protected Types | Protected Attributes | Friends | List of all members
gadgetlib2::LinearCombination Class Reference

LinearCombination. More...

#include <variable.hpp>

Collaboration diagram for gadgetlib2::LinearCombination:
Collaboration graph
[legend]

Public Member Functions

 LinearCombination ()
 
 LinearCombination (const Variable &var)
 
 LinearCombination (const LinearTerm &linTerm)
 
 LinearCombination (long i)
 
 LinearCombination (const FElem &elem)
 
LinearCombinationoperator+= (const LinearCombination &other)
 
LinearCombinationoperator-= (const LinearCombination &other)
 
LinearCombinationoperator*= (const FElem &other)
 
FElem eval (const VariableAssignment &assignment) const
 
::std::string asString () const
 
const Variable::set getUsedVariables () const
 

Protected Types

typedef ::std::vector< LinearTerm >::size_type size_type
 

Protected Attributes

::std::vector< LinearTermlinearTerms_
 
FElem constant_
 

Friends

class Polynomial
 
class GadgetLibAdapter
 

Detailed Description

LinearCombination.

Definition at line 503 of file variable.hpp.

Member Typedef Documentation

◆ size_type

Definition at line 508 of file variable.hpp.

Constructor & Destructor Documentation

◆ LinearCombination() [1/5]

gadgetlib2::LinearCombination::LinearCombination ( )
inline

Definition at line 511 of file variable.hpp.

511 : linearTerms_(), constant_(0) {}

◆ LinearCombination() [2/5]

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

Definition at line 512 of file variable.hpp.

512  : linearTerms_(1, var), constant_(0)
513  {
514  }

◆ LinearCombination() [3/5]

gadgetlib2::LinearCombination::LinearCombination ( const LinearTerm linTerm)
inline

Definition at line 515 of file variable.hpp.

516  : linearTerms_(1, linTerm), constant_(0)
517  {
518  }

◆ LinearCombination() [4/5]

gadgetlib2::LinearCombination::LinearCombination ( long  i)
inline

Definition at line 519 of file variable.hpp.

519 : linearTerms_(), constant_(i) {}

◆ LinearCombination() [5/5]

gadgetlib2::LinearCombination::LinearCombination ( const FElem elem)
inline

Definition at line 520 of file variable.hpp.

520 : linearTerms_(), constant_(elem) {}

Member Function Documentation

◆ asString()

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

Definition at line 581 of file variable.cpp.

582 {
583 #ifdef DEBUG
584  ::std::string retval;
585  auto it = linearTerms_.begin();
586  if (it == linearTerms_.end()) {
587  return constant_.asString();
588  } else {
589  retval += it->asString();
590  }
591  for (++it; it != linearTerms_.end(); ++it) {
592  retval += " + " + it->asString();
593  }
594  if (constant_ != 0) {
595  retval += " + " + constant_.asString();
596  }
597  return retval;
598 #else
599  return "";
600 #endif
601 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ eval()

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

Definition at line 572 of file variable.cpp.

573 {
574  FElem evaluation = constant_;
575  for (const LinearTerm &lt : linearTerms_) {
576  evaluation += lt.eval(assignment);
577  }
578  return evaluation;
579 }
Here is the caller graph for this function:

◆ getUsedVariables()

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

Definition at line 603 of file variable.cpp.

604 {
605  Variable::set retSet;
606  for (const LinearTerm &lt : linearTerms_) {
607  retSet.insert(lt.variable());
608  }
609  return retSet;
610 }
Here is the caller graph for this function:

◆ operator*=()

LinearCombination & gadgetlib2::LinearCombination::operator*= ( const FElem other)

Definition at line 563 of file variable.cpp.

564 {
565  constant_ *= other;
566  for (LinearTerm &lt : linearTerms_) {
567  lt *= other;
568  }
569  return *this;
570 }

◆ operator+=()

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

Definition at line 544 of file variable.cpp.

545 {
546  linearTerms_.insert(
547  linearTerms_.end(),
548  other.linearTerms_.cbegin(),
549  other.linearTerms_.cend());
550  constant_ += other.constant_;
551  return *this;
552 }

◆ operator-=()

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

Definition at line 554 of file variable.cpp.

555 {
556  for (const LinearTerm &lt : other.linearTerms_) {
557  linearTerms_.push_back(-lt);
558  }
559  constant_ -= other.constant_;
560  return *this;
561 }

Friends And Related Function Documentation

◆ GadgetLibAdapter

friend class GadgetLibAdapter
friend

Definition at line 530 of file variable.hpp.

◆ Polynomial

friend class Polynomial
friend

Definition at line 529 of file variable.hpp.

Member Data Documentation

◆ constant_

FElem gadgetlib2::LinearCombination::constant_
protected

Definition at line 507 of file variable.hpp.

◆ linearTerms_

::std::vector<LinearTerm> gadgetlib2::LinearCombination::linearTerms_
protected

Definition at line 506 of file variable.hpp.


The documentation for this class was generated from the following files:
gadgetlib2::LinearCombination::constant_
FElem constant_
Definition: variable.hpp:507
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::LinearCombination::linearTerms_
::std::vector< LinearTerm > linearTerms_
Definition: variable.hpp:506
gadgetlib2::FElem::asString
::std::string asString() const
Definition: variable.hpp:127