clingo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
Public Member Functions | Public Attributes | List of all members
Gringo::UnOpTerm Struct Reference

#include <term.hh>

Inheritance diagram for Gringo::UnOpTerm:
Inheritance graph
Collaboration diagram for Gringo::UnOpTerm:
Collaboration graph

Public Member Functions

 UnOpTerm (UnOp op, UTerm &&arg)
 
virtual void rename (FWString name)
 
virtual SimplifyRet simplify (DotsMap &dots, ScriptMap &scripts, unsigned &auxNum, bool positional, bool arithmetic)
 
virtual ProjectRet project (bool rename, unsigned &auxNum)
 
virtual bool hasVar () const
 Whether the term contains a VarTerm. More...
 
virtual void collect (VarTermBoundVec &vars, bool bound) const
 
virtual void collect (VarSet &vars, unsigned minLevel=0, unsigned maxLevel=std::numeric_limits< unsigned >::max()) const
 
virtual Value eval () const
 
virtual bool match (Value const &val) const
 
virtual FWSignature getSig () const
 
virtual UTerm renameVars (RenameMap &names) const
 
virtual UGTerm gterm (RenameMap &names, ReferenceMap &refs) const
 
virtual unsigned getLevel () const
 
virtual bool isNotNumeric () const
 
virtual Invertibility getInvertibility () const
 
virtual void print (std::ostream &out) const
 
virtual void unpool (UTermVec &x) const
 
virtual UTerm rewriteArithmetics (ArithmeticsMap &arith, unsigned &auxNum)
 
virtual bool operator== (Term const &other) const
 
virtual size_t hash () const
 
virtual UnOpTermclone () const
 
virtual bool hasPool () const
 
virtual void collectIds (VarSet &vars) const
 
virtual UTerm replace (Defines &defs, bool replace=true)
 
virtual double estimate (double size, VarSet const &bound) const
 
virtual Value isEDB () const
 
virtual ~UnOpTerm ()
 
- Public Member Functions inherited from Gringo::Term
bool isZero () const
 
virtual void collect (VarTermSet &vars) const
 
bool bind (VarSet &bound)
 
SGRef _newRef (RenameMap &names, ReferenceMap &refs) const
 
UGTerm gterm () const
 
virtual ~Term ()
 
template<class T , class U , class V >
void replace (std::unique_ptr< T > &dst, std::unique_ptr< U > &&src, std::unique_ptr< V > &&alt)
 
template<class It , class TermUnpool , class Callback >
void unpool (It const &begin, It const &end, TermUnpool const &f, Callback const &g)
 
template<class Vec , class TermUnpool >
void unpoolJoin (Vec &vec, TermUnpool const &f)
 
- Public Member Functions inherited from Gringo::Printable
virtual ~Printable ()
 
- Public Member Functions inherited from Gringo::Hashable
virtual ~Hashable ()
 
- Public Member Functions inherited from Gringo::Locatable
virtual Location const & loc () const =0
 
virtual void loc (Location const &loc)=0
 
virtual ~Locatable ()
 
- Public Member Functions inherited from Gringo::Comparable< Term >
virtual bool operator!= (Termconst &other) const
 
virtual ~Comparable ()
 
- Public Member Functions inherited from Gringo::Clonable< Term >
virtual ~Clonable ()
 

Public Attributes

UnOp const op
 
UTerm arg
 

Additional Inherited Members

- Public Types inherited from Gringo::Term
enum  Invertibility { CONSTANT = 0, INVERTIBLE = 1, NOT_INVERTIBLE = 2 }
 
using ProjectRet = std::tuple< UTerm, UTerm, UTerm >
 Return value of Term::project (replace, projected, project). More...
 
using SVal = std::shared_ptr< Value >
 
using VarSet = std::unordered_set< FWString >
 
using RenameMap = std::unordered_map< FWString, std::pair< FWString, SVal >>
 
using ReferenceMap = std::unordered_map< Term *, SGRef, value_hash< Term * >, value_equal_to< Term * >>
 
using DotsMap = std::vector< std::tuple< UTerm, UTerm, UTerm >>
 Type that stores for each rewritten DotsTerm the associated variable and the lower and upper bound. More...
 
using ScriptMap = std::vector< std::tuple< UTerm, FWString, UTermVec >>
 
using ArithmeticsMap = std::vector< std::unordered_map< UTerm, UTerm, value_hash< UTerm >, value_equal_to< UTerm >>>
 
- Static Public Member Functions inherited from Gringo::Term
static FWString uniqueName (unsigned &auxNum, char const *prefix="#X")
 Creates a unique variable name. More...
 
static UTerm uniqueVar (Location const &loc, unsigned &auxNum, unsigned level=0, const char *prefix="#X")
 Creates a unique variable using #aux(auxNum) as name. More...
 
static UTerm uniqueVal (Location const &loc, unsigned &auxNum, const char *prefix="#X")
 
static UTerm insert (ArithmeticsMap &arith, unsigned &auxNum, UTerm &&term)
 Inserts a term into arith creating a new unique variable if necessary. More...
 
template<class T , class U >
static void replace (std::unique_ptr< T > &dst, std::unique_ptr< U > &&src)
 Set dst to src if src is non-zero. More...
 
template<class A , class UnpoolA , class Callback >
static void unpool (A const &a, UnpoolA const &fA, Callback const &g)
 Unpools a, calling g on each obtained element. More...
 
template<class A , class B , class UnpoolA , class UnpoolB , class Callback >
static void unpool (A const &a, B const &b, UnpoolA const &fA, UnpoolB const &fB, Callback const &g)
 Unpools a and b, calculates cross product, calling g on each obtained tuple. More...
 
template<class It , class Unpool , class Callback >
static void unpool (It const &begin, It const &end, Unpool const &f, Callback const &g)
 Iterates of [begin, end] unpooling with f, calculates cross product, calling g on each obtained tuple. More...
 
template<class Vec , class Unpool >
static void unpoolJoin (Vec &vec, Unpool const &f)
 Unpools each element of vec using f, and move the union of all pools back to f. More...
 

Constructor & Destructor Documentation

Gringo::UnOpTerm::UnOpTerm ( UnOp  op,
UTerm &&  arg 
)
Gringo::UnOpTerm::~UnOpTerm ( )
virtual

Member Function Documentation

UnOpTerm * Gringo::UnOpTerm::clone ( ) const
virtual

Implements Gringo::Clonable< Term >.

Here is the call graph for this function:

void Gringo::UnOpTerm::collect ( VarTermBoundVec vars,
bool  bound 
) const
virtual

Collects variables in Terms.

Precondition
Must be called after simplify and project to properly account for bound variables.

Implements Gringo::Term.

void Gringo::UnOpTerm::collect ( VarSet vars,
unsigned  minLevel = 0,
unsigned  maxLevel = std::numeric_limits<unsigned>::max() 
) const
virtual

Implements Gringo::Term.

void Gringo::UnOpTerm::collectIds ( VarSet vars) const
virtual

Implements Gringo::Term.

double Gringo::UnOpTerm::estimate ( double  size,
VarSet const &  bound 
) const
virtual

Implements Gringo::Term.

Value Gringo::UnOpTerm::eval ( ) const
virtual

Evaluates the term to a value.

Precondition
Must be called after simplify.

Implements Gringo::Term.

Here is the call graph for this function:

Term::Invertibility Gringo::UnOpTerm::getInvertibility ( ) const
virtual

Obtain the invertibility of a term.

Precondition
Must be called after simplify.

Implements Gringo::Term.

unsigned Gringo::UnOpTerm::getLevel ( ) const
virtual

Returns the nesting level of a term. That is the largest level of a nested variable or zero for ground terms.

Precondition
Must be called after assignLevel.

Implements Gringo::Term.

FWSignature Gringo::UnOpTerm::getSig ( ) const
virtual

Implements Gringo::Term.

UGTerm Gringo::UnOpTerm::gterm ( RenameMap names,
ReferenceMap refs 
) const
virtual

Implements Gringo::Term.

Here is the call graph for this function:

size_t Gringo::UnOpTerm::hash ( ) const
virtual

Implements Gringo::Hashable.

Here is the call graph for this function:

bool Gringo::UnOpTerm::hasPool ( ) const
virtual

Implements Gringo::Term.

bool Gringo::UnOpTerm::hasVar ( ) const
virtual

Whether the term contains a VarTerm.

Implements Gringo::Term.

Value Gringo::UnOpTerm::isEDB ( ) const
virtual

Implements Gringo::Term.

bool Gringo::UnOpTerm::isNotNumeric ( ) const
virtual

Obtain the type of a term.

Precondition
Must be called after simplify. Whether evaluation of a term is guaranteed to not produce numeric values. Basically, this means that the term is either a non-numeric constant or a function symbol.

Implements Gringo::Term.

bool Gringo::UnOpTerm::match ( Value const &  val) const
virtual

Implements Gringo::Term.

bool Gringo::UnOpTerm::operator== ( Term const &  other) const
virtual

Implements Gringo::Comparable< Term >.

Here is the call graph for this function:

void Gringo::UnOpTerm::print ( std::ostream &  out) const
virtual

Implements Gringo::Printable.

Term::ProjectRet Gringo::UnOpTerm::project ( bool  rename,
unsigned &  auxNum 
)
virtual

Removes anonymous variables in projectable positions (in outermost function symbols) from a term. The first element of the return value is a replacement term for the current term, which might be null if the term does not have to be replace.. The second and third can be used to create a projection rule where the second is the head and the third is the body element.

Precondition
Must be called after simplify.
num = 0; sig = base; lit = q(X,_)
(lit', projected, project) = lit.project(&sig, num)
assert(lit' == #p_q(base,X,#p))
assert(projected == #p_q(base,#X1,#p))
assert(project == #p_q(base,#X1,#Y2))

Implements Gringo::Term.

Here is the call graph for this function:

void Gringo::UnOpTerm::rename ( FWString  name)
virtual

Rename the outermost term.

Precondition
the term must either be a function term or value term holding an identifier.
Note
unnecessary; can be deleted

Implements Gringo::Term.

UTerm Gringo::UnOpTerm::renameVars ( RenameMap names) const
virtual

Implements Gringo::Term.

Here is the call graph for this function:

UTerm Gringo::UnOpTerm::replace ( Defines defs,
bool  replace = true 
)
virtual

Implements Gringo::Term.

Here is the call graph for this function:

UTerm Gringo::UnOpTerm::rewriteArithmetics ( ArithmeticsMap arith,
unsigned &  auxNum 
)
virtual

Removes non-invertible arithmetics.

Note
The term is unusable if the method returned a non-zero replacement term.
Precondition
Must be called after assignLevel.

Implements Gringo::Term.

Here is the call graph for this function:

Term::SimplifyRet Gringo::UnOpTerm::simplify ( DotsMap dots,
ScriptMap scripts,
unsigned &  auxNum,
bool  positional,
bool  arithmetic 
)
virtual

Removes all occurrences of DotsTerm instances, simplifies the term and sets the invertibility. To reduce the number of cases in later algorithms moves invertible terms to the left:

  • 1+X -> X+1
  • (1+(1-X)) -> ((-X)+1)+1 Replaces undefined arithmetic operations with 0:
  • f(X)+0 -> 0
    Note
    The term is unusable if the method returned a non-zero replacement term.
    Precondition
    Must be called after unpool.

Implements Gringo::Term.

Here is the call graph for this function:

void Gringo::UnOpTerm::unpool ( UTermVec x) const
virtual

Removes all occurrences of PoolTerm instances. Returns all unpooled incarnations of the term.

Note
The term becomes unusable after the method returns.
Postcondition
The pool does not contain PoolTerm instances.

Implements Gringo::Term.

Here is the call graph for this function:

Member Data Documentation

UTerm Gringo::UnOpTerm::arg
UnOp const Gringo::UnOpTerm::op

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