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

#include <variable.hpp>

Inheritance diagram for gadgetlib2::FConst:
Inheritance graph
[legend]
Collaboration diagram for gadgetlib2::FConst:
Collaboration graph
[legend]

Public Member Functions

 FConst (const FConst &src)
 
virtual FConstoperator= (const long n)
 
virtual FConstoperator= (const FConst &src)
 
virtual ::std::string asString () const
 
virtual FieldType fieldType () const
 
virtual FConstoperator+= (const FElemInterface &other)
 
virtual FConstoperator-= (const FElemInterface &other)
 
virtual FConstoperator*= (const FElemInterface &other)
 
virtual bool operator== (const FElemInterface &other) const
 
virtual bool operator== (const FConst &other) const
 
virtual bool operator== (const long n) const
 
virtual FElemInterfacePtr clone () const
 
virtual FElemInterfacePtr inverse () const
 
long asLong () const
 
int getBit (unsigned int i) const
 
virtual FElemInterfacepower (long exponent)
 
- Public Member Functions inherited from gadgetlib2::FElemInterface
virtual ~FElemInterface ()
 

Friends

class FElem
 

Detailed Description

A field agnostic constant. All fields have constants 1 and 0 and this class allows us to hold an element agnostically while the context field is not known. For example, when given the very useful expression '1 - x' where x is a field agnostic formal variable, we must store the constant '1' without knowing over which field this expression will be evaluated. Constants can also hold integer values, which will be evaluated if possible, in runtime. For instance the expression '42 + x' will be evaluated in runtime in the trivial way when working over the prime characteristic Galois Field GF_43 but will cause a runtime error when evaluated over a GF2 extension field in which '42' has no obvious meaning, other than being the answer to life, the universe and everything.

Definition at line 189 of file variable.hpp.

Constructor & Destructor Documentation

◆ FConst()

gadgetlib2::FConst::FConst ( const FConst src)
inline

Definition at line 196 of file variable.hpp.

196 : contents_(src.contents_) {}

Member Function Documentation

◆ asLong()

long gadgetlib2::FConst::asLong ( ) const
inlinevirtual

Implements gadgetlib2::FElemInterface.

Definition at line 232 of file variable.hpp.

232 { return contents_; }
Here is the caller graph for this function:

◆ asString()

virtual ::std::string gadgetlib2::FConst::asString ( ) const
inlinevirtual

Implements gadgetlib2::FElemInterface.

Definition at line 207 of file variable.hpp.

208  {
209  return GADGETLIB2_FMT("%ld", contents_);
210  }
Here is the call graph for this function:

◆ clone()

virtual FElemInterfacePtr gadgetlib2::FConst::clone ( ) const
inlinevirtual
Returns
a unique_ptr to a new copy of the element

Implements gadgetlib2::FElemInterface.

Definition at line 225 of file variable.hpp.

226  {
227  return FElemInterfacePtr(new FConst(*this));
228  }

◆ fieldType()

virtual FieldType gadgetlib2::FConst::fieldType ( ) const
inlinevirtual

Implements gadgetlib2::FElemInterface.

Definition at line 211 of file variable.hpp.

211 { return AGNOSTIC; }

◆ getBit()

int gadgetlib2::FConst::getBit ( unsigned int  i) const
inlinevirtual

Implements gadgetlib2::FElemInterface.

Definition at line 233 of file variable.hpp.

234  {
235  libff::UNUSED(i);
236  GADGETLIB_FATAL("Cannot get bit from FConst.");
237  }

◆ inverse()

FElemInterfacePtr gadgetlib2::FConst::inverse ( ) const
virtual
Returns
a unique_ptr to a new copy of the element's multiplicative inverse

Implements gadgetlib2::FElemInterface.

Definition at line 176 of file variable.cpp.

177 {
178  GADGETLIB_FATAL("Attempted to invert an FConst element.");
179 }

◆ operator*=()

FConst & gadgetlib2::FConst::operator*= ( const FElemInterface other)
virtual

Implements gadgetlib2::FElemInterface.

Definition at line 170 of file variable.cpp.

171 {
172  contents_ *= dynamic_cast<const FConst &>(other).contents_;
173  return *this;
174 }

◆ operator+=()

FConst & gadgetlib2::FConst::operator+= ( const FElemInterface other)
virtual

Implements gadgetlib2::FElemInterface.

Definition at line 158 of file variable.cpp.

159 {
160  contents_ += dynamic_cast<const FConst &>(other).contents_;
161  return *this;
162 }

◆ operator-=()

FConst & gadgetlib2::FConst::operator-= ( const FElemInterface other)
virtual

Implements gadgetlib2::FElemInterface.

Definition at line 164 of file variable.cpp.

165 {
166  contents_ -= dynamic_cast<const FConst &>(other).contents_;
167  return *this;
168 }

◆ operator=() [1/2]

virtual FConst& gadgetlib2::FConst::operator= ( const FConst src)
inlinevirtual

FConst will be field agnostic, allowing us to hold values such as 0 and 1 without knowing the underlying field. This assignment operator will convert to the correct field element.

Implements gadgetlib2::FElemInterface.

Definition at line 202 of file variable.hpp.

203  {
204  contents_ = src.contents_;
205  return *this;
206  }

◆ operator=() [2/2]

virtual FConst& gadgetlib2::FConst::operator= ( const long  n)
inlinevirtual

Implements gadgetlib2::FElemInterface.

Definition at line 197 of file variable.hpp.

198  {
199  contents_ = n;
200  return *this;
201  }

◆ operator==() [1/3]

virtual bool gadgetlib2::FConst::operator== ( const FConst other) const
inlinevirtual

Implements gadgetlib2::FElemInterface.

Definition at line 219 of file variable.hpp.

220  {
221  return contents_ == other.contents_;
222  }

◆ operator==() [2/3]

virtual bool gadgetlib2::FConst::operator== ( const FElemInterface other) const
inlinevirtual

Implements gadgetlib2::FElemInterface.

Definition at line 215 of file variable.hpp.

216  {
217  return other == *this;
218  }

◆ operator==() [3/3]

virtual bool gadgetlib2::FConst::operator== ( const long  n) const
inlinevirtual

This operator is not always mathematically well defined. 'n' will be checked in runtime for fields in which integer values are not well defined.

Implements gadgetlib2::FElemInterface.

Definition at line 223 of file variable.hpp.

223 { return contents_ == n; }

◆ power()

FElemInterface & gadgetlib2::FConst::power ( long  exponent)
virtual

Implements gadgetlib2::FElemInterface.

Definition at line 181 of file variable.cpp.

182 {
183  contents_ = 0.5 + ::std::pow(double(contents_), double(exponent));
184  return *this;
185 }

Friends And Related Function Documentation

◆ FElem

friend class FElem
friend

Definition at line 240 of file variable.hpp.


The documentation for this class was generated from the following files:
gadgetlib2::GADGETLIB2_FMT
::std::string GADGETLIB2_FMT(const char *format,...)
Definition: infrastructure.cpp:49
gadgetlib2::AGNOSTIC
@ AGNOSTIC
Definition: variable.hpp:37
GADGETLIB_FATAL
#define GADGETLIB_FATAL(msg)
Definition: infrastructure.hpp:85
gadgetlib2::FElemInterfacePtr
::std::unique_ptr< FElemInterface > FElemInterfacePtr
Definition: variable.hpp:41