Documentation
¶
Overview ¶
Package formula provides all the main data-structures for working with propositional formulas in LogicNG and generate them via a formula factory.
Usually the formula factory is the starting point of working with LogicNG.
fac := formula.NewFactory()
From there on you can generate formulas on the factory or use a parser to parse them to the factory. All major algorithms which generate or manipulate formulas will need a formula factory as parameter. Usually within an application you only have one formula factory and keep working with it. Very seldom there should be the need to create more than one factory.
Formula factories are not thread-safe and you can not share formulas between formula factories since a formula in fact is only a unique ID (unit32) on the factory.
Index ¶
- Constants
- func Comparator(a, b interface{}) int
- func DefaultFormulaGraphicalGenerator() *graphical.Generator[Formula]
- func FormulaDepth(fac Factory, formula Formula) int
- func GenerateGraphicalFormulaAST(fac Factory, formula Formula, generator *graphical.Generator[Formula]) *graphical.Representation
- func GenerateGraphicalFormulaDAG(fac Factory, formula Formula, generator *graphical.Generator[Formula]) *graphical.Representation
- func LiteralProfile(fac Factory, formula Formula) map[Literal]int
- func LookupFunctionCache(fac Factory, sort FunctionCacheSort, formula Formula) (any, bool)
- func LookupPredicateCache(fac Factory, sort PredicateCacheSort, formula Formula) (bool, bool)
- func NewTestData(fac Factory) testdata
- func NumberOfAtoms(fac Factory, formula Formula) int
- func NumberOfNodes(fac Factory, formula Formula) int
- func PropComparator(a, b Proposition) int
- func SetFunctionCache(fac Factory, sort FunctionCacheSort, formula Formula, value any)
- func SetPredicateCache(fac Factory, sort PredicateCacheSort, formula Formula, value bool)
- func SetTransformationCache(fac Factory, sort TransformationCacheSort, formula, value Formula)
- func VariableProfile(fac Factory, formula Formula) map[Variable]int
- type AbortableTransformation
- type AuxVarSort
- type CSort
- type CachingFactory
- func (fac *CachingFactory) AMO(variables ...Variable) Formula
- func (fac *CachingFactory) And(operands ...Formula) Formula
- func (fac *CachingFactory) BinaryLeftRight(formula Formula) (left, right Formula, ok bool)
- func (fac *CachingFactory) BinaryOperator(sort FSort, left, right Formula) (Formula, error)
- func (fac *CachingFactory) CC(comparator CSort, rhs uint32, variables ...Variable) Formula
- func (fac *CachingFactory) Clause(operands ...Literal) Formula
- func (fac *CachingFactory) ConfigurationFor(sort configuration.Sort) (config configuration.Config, ok bool)
- func (fac *CachingFactory) Constant(value bool) Formula
- func (fac *CachingFactory) EXO(variables ...Variable) Formula
- func (fac *CachingFactory) Equivalence(left, right Formula) Formula
- func (fac *CachingFactory) Falsum() Formula
- func (fac *CachingFactory) Implication(left, right Formula) Formula
- func (fac *CachingFactory) Lit(name string, phase bool) Literal
- func (fac *CachingFactory) LitNamePhase(literal Literal) (name string, phase, ok bool)
- func (fac *CachingFactory) Literal(name string, phase bool) Formula
- func (fac *CachingFactory) LiteralNamePhase(formula Formula) (name string, phase, ok bool)
- func (fac *CachingFactory) Minterm(operands ...Literal) Formula
- func (fac *CachingFactory) NaryOperands(formula Formula) (ops []Formula, ok bool)
- func (fac *CachingFactory) NaryOperator(sort FSort, operands ...Formula) (Formula, error)
- func (fac *CachingFactory) NewAuxVar(sort AuxVarSort) Variable
- func (fac *CachingFactory) Not(operand Formula) Formula
- func (fac *CachingFactory) NotOperand(formula Formula) (op Formula, ok bool)
- func (fac *CachingFactory) Operands(formula Formula) []Formula
- func (fac *CachingFactory) Or(operands ...Formula) Formula
- func (fac *CachingFactory) PBC(comparator CSort, rhs int, literals []Literal, coefficients []int) Formula
- func (fac *CachingFactory) PBCOps(formula Formula) (comparator CSort, rhs int, literals []Literal, coefficients []int, found bool)
- func (fac *CachingFactory) PutConfiguration(config configuration.Config) error
- func (fac *CachingFactory) SetPrintSymbols(symbols *PrintSymbols)
- func (fac *CachingFactory) Statistics() string
- func (fac *CachingFactory) Symbols() *PrintSymbols
- func (fac *CachingFactory) Var(name string) Variable
- func (fac *CachingFactory) VarName(variable Variable) (name string, ok bool)
- func (fac *CachingFactory) Variable(name string) Formula
- func (fac *CachingFactory) Vars(name ...string) []Variable
- func (fac *CachingFactory) Verum() Formula
- type ExtendedProposition
- type FSort
- type Factory
- type Formula
- func EncodeFormula(fsort FSort, id uint32) Formula
- func LiteralsAsFormulas(literals []Literal) []Formula
- func LookupTransformationCache(fac Factory, sort TransformationCacheSort, formula Formula) (Formula, bool)
- func NewCornerCases(fac Factory) []Formula
- func SubNodes(fac Factory, formula Formula) []Formula
- func VariablesAsFormulas(variables []Variable) []Formula
- func (f Formula) AsLiteral() (Literal, error)
- func (f Formula) AsVariable() (Variable, error)
- func (f Formula) ID() uint32
- func (f Formula) IsAtomic() bool
- func (f Formula) IsConstant() bool
- func (f Formula) IsNeg() bool
- func (f Formula) IsPos() bool
- func (f Formula) Negate(fac Factory) Formula
- func (f Formula) Sort() FSort
- func (f Formula) Sprint(fac Factory) string
- func (f Formula) String() string
- type FormulaSet
- type Function
- type FunctionCacheSort
- type LitSet
- type Literal
- type MutableFormulaSet
- type MutableLitSet
- type MutableVarSet
- type Predicate
- type PredicateCacheSort
- type PrintSymbols
- type Proposition
- type StandardProposition
- type Transformation
- type TransformationCacheSort
- type Tristate
- type VarSet
- type Variable
Constants ¶
const ( AuxCNF = "@RESERVED_CNF_" AuxCC = "@RESERVED_CC_" AuxPBC = "@RESERVED_PBC_" )
Variables ¶
This section is empty.
Functions ¶
func Comparator ¶
func Comparator(a, b interface{}) int
Comparator compares two formulas f1 and f2 with their integer value.
func DefaultFormulaGraphicalGenerator ¶
DefaultFormulaGraphicalGenerator returns a graphical formula generator with sensible defaults.
func FormulaDepth ¶ added in v0.4.0
FormulaDepth returns the depth of the given formula. The depth of an atomic formula is defined as 0, all other operators increase the depth by 1.
func GenerateGraphicalFormulaAST ¶ added in v0.4.0
func GenerateGraphicalFormulaAST( fac Factory, formula Formula, generator *graphical.Generator[Formula], ) *graphical.Representation
GenerateGraphicalFormulaAST generates a graphical representation of the formula with the configuration of the generator as an abstract syntax tree (AST). The resulting representation can then be exported as mermaid or graphviz graph.
func GenerateGraphicalFormulaDAG ¶ added in v0.4.0
func GenerateGraphicalFormulaDAG( fac Factory, formula Formula, generator *graphical.Generator[Formula], ) *graphical.Representation
GenerateGraphicalFormulaDAG generates a graphical representation of the formula with the configuration of the generator as a graph (DAG). The resulting representation can then be exported as mermaid or graphviz graph.
func LiteralProfile ¶ added in v0.4.0
LiteralProfile returns the number of occurrences of each literal in the given formula.
func LookupFunctionCache ¶
func LookupFunctionCache(fac Factory, sort FunctionCacheSort, formula Formula) (any, bool)
LookupFunctionCache searches a cache entry for a given function sort and formula. It returns the optional result and a flag whether there was a cache entry.
func LookupPredicateCache ¶
func LookupPredicateCache(fac Factory, sort PredicateCacheSort, formula Formula) (bool, bool)
LookupPredicateCache searches a cache entry for a given predicate sort and formula. It returns the optional result and a flag whether there was a cache entry.
func NewTestData ¶
func NewTestData(fac Factory) testdata
func NumberOfAtoms ¶ added in v0.4.0
NumberOfAtoms returns the number of atomic formulas of the given formula. An atomic formula is a constant or a literal.
func NumberOfNodes ¶ added in v0.4.0
NumberOfNodes returns the number of nodes (in the DAG) of the given formula.
func PropComparator ¶ added in v0.4.0
func PropComparator(a, b Proposition) int
PropComparator compares two propositions p1 and p2.
func SetFunctionCache ¶
func SetFunctionCache(fac Factory, sort FunctionCacheSort, formula Formula, value any)
SetFunctionCache sets a cache entry for a given function sort, formula and value to cache.
func SetPredicateCache ¶
func SetPredicateCache(fac Factory, sort PredicateCacheSort, formula Formula, value bool)
SetPredicateCache sets a cache entry for a given predicate sort, formula and value to cache.
func SetTransformationCache ¶
func SetTransformationCache(fac Factory, sort TransformationCacheSort, formula, value Formula)
SetTransformationCache sets a cache entry for a given transformation sort, formula and value to cache.
Types ¶
type AbortableTransformation ¶ added in v0.4.0
An AbortableTransformation is a function which maps a formula to another formula. It takes an handler which can be used to abort the computation. If the computation is aborted by the handler, the ok flag in the response is false.
type AuxVarSort ¶ added in v0.3.0
type AuxVarSort string
AuxVarSort encodes the auxiliary variable sort.
type CSort ¶
type CSort byte
CSort encodes the sort of an integer comparator
type CachingFactory ¶
type CachingFactory struct {
// contains filtered or unexported fields
}
A CachingFactory is the default (and currently only) implementation of the formula factory in LogicNG.
In this implementation, the container function is 'smart': A formula factory guarantees that syntactically equivalent formulas are created only once. This mechanism also extends to variants of the formula in terms of associativity and commutativity. Therefore, if the user creates formulas for
A & B B & A (B & A)
all of them are represented by only one formula in memory. This approach is only possible, because formulas in LogicNG are immutable data structures. So once created, a formula can never be altered again.
func (*CachingFactory) AMO ¶
func (fac *CachingFactory) AMO(variables ...Variable) Formula
AMO returns an at-most-one (<= 1) constraint over the given variables.
func (*CachingFactory) And ¶
func (fac *CachingFactory) And(operands ...Formula) Formula
And returns a conjunction of the given operands. If the result is an And formula, it is guaranteed to have at least two operands. An empty conjunction is treated as true, a conjunction with one operand, is treated as this operand.
func (*CachingFactory) BinaryLeftRight ¶
func (fac *CachingFactory) BinaryLeftRight(formula Formula) (left, right Formula, ok bool)
BinaryLeftRight returns the left and right operand of a given formula interpreted as a binary operator. The ok flag indicates whether the binary operator was found on the factory or not.
func (*CachingFactory) BinaryOperator ¶
func (fac *CachingFactory) BinaryOperator(sort FSort, left, right Formula) (Formula, error)
BinaryOperator returns a new binary operator with the given sort and the two operands left and right. Returns an error if the given sort is not a binary operator (implication or equivalence).
func (*CachingFactory) CC ¶
func (fac *CachingFactory) CC(comparator CSort, rhs uint32, variables ...Variable) Formula
CC returns a new cardinality constraint with the given comparator and right-hand-side representing a constraint v_1 + ... + v_n C rhs with C in [<, >, <=, >=, =].
func (*CachingFactory) Clause ¶
func (fac *CachingFactory) Clause(operands ...Literal) Formula
Clause returns a disjunction between the given literals. In contrast to the [Or] Method, the operands are not condensed. Meaning, if the operands contain duplicate literals, the result will also contain these duplicates and therefore lead to potential problems down the road.
func (*CachingFactory) ConfigurationFor ¶
func (fac *CachingFactory) ConfigurationFor( sort configuration.Sort, ) (config configuration.Config, ok bool)
ConfigurationFor returns the configuration for a given configuration sort. The ok flag indicates whether a config for the given sort was found in the factory.
func (*CachingFactory) Constant ¶
func (fac *CachingFactory) Constant(value bool) Formula
Constant returns the Boolean constant represented by the given value.
func (*CachingFactory) EXO ¶
func (fac *CachingFactory) EXO(variables ...Variable) Formula
EXO returns an exactly-one (= 1) constraint over the given variables.
func (*CachingFactory) Equivalence ¶
func (fac *CachingFactory) Equivalence(left, right Formula) Formula
Equivalence returns an equivalence left <=> right.
func (*CachingFactory) Falsum ¶
func (fac *CachingFactory) Falsum() Formula
Falsum returns the Boolean false constant.
func (*CachingFactory) Implication ¶
func (fac *CachingFactory) Implication(left, right Formula) Formula
Implication returns an implication left => right.
func (*CachingFactory) Lit ¶
func (fac *CachingFactory) Lit(name string, phase bool) Literal
Lit returns a Boolean literal with the given name and phase. For a name "A" the positive phase returns the variable "A" whereas the negative phase returns the negated variable "~A". In contrast to the Literal function, a literal type is returned.
func (*CachingFactory) LitNamePhase ¶
func (fac *CachingFactory) LitNamePhase(literal Literal) (name string, phase, ok bool)
LitNamePhase returns the name and phase of the given literal. The ok flag indicates whether the literal was found on the factory or not.
func (*CachingFactory) Literal ¶
func (fac *CachingFactory) Literal(name string, phase bool) Formula
Literal returns a Boolean literal with the given name and phase. For a name "A" the positive phase returns the variable "A" whereas the negative phase returns the negated variable "~A".
func (*CachingFactory) LiteralNamePhase ¶
func (fac *CachingFactory) LiteralNamePhase(formula Formula) (name string, phase, ok bool)
LiteralNamePhase returns the name and phase of a given formula interpreted as literal. The ok flag is false when the given formula was not a literal, or it was not found on the factory.
func (*CachingFactory) Minterm ¶
func (fac *CachingFactory) Minterm(operands ...Literal) Formula
Minterm returns a conjunction between the given literals. In contrast to the [And] Method, the operands are not condensed. Meaning, if the operands contain duplicate literals, the result will also contain these duplicates and therefore lead to potential problems down the road.
func (*CachingFactory) NaryOperands ¶
func (fac *CachingFactory) NaryOperands(formula Formula) (ops []Formula, ok bool)
NaryOperands returns the operands of a given formula interpreted as an n-ary operator. The ok flag indicates whether the n-ary operator was found on the factory or not.
func (*CachingFactory) NaryOperator ¶
func (fac *CachingFactory) NaryOperator(sort FSort, operands ...Formula) (Formula, error)
NaryOperator returns a new n-ary operator with the given sort and the list of operands. Returns an error if the given sort is not a binary operator (conjunction or disjunction).
func (*CachingFactory) NewAuxVar ¶ added in v0.3.0
func (fac *CachingFactory) NewAuxVar(sort AuxVarSort) Variable
NewAuxVariable generates and returns a new auxiliary variable of the given sort.
func (*CachingFactory) Not ¶
func (fac *CachingFactory) Not(operand Formula) Formula
Not returns the negation of the given formula. Constants, literals and negations are negated directly and returned. For all other formulas a new Not formula is returned.
func (*CachingFactory) NotOperand ¶
func (fac *CachingFactory) NotOperand(formula Formula) (op Formula, ok bool)
NotOperand returns the operand of a given formula interpreted as negation. The ok flag indicates whether the negation was found on the factory or not.
func (*CachingFactory) Operands ¶
func (fac *CachingFactory) Operands(formula Formula) []Formula
Operands returns the operands of a given formula. For a negation this is its operand, for an implication and equivalence its left and right operand (in this order), for n-ary operators their operands. All other formulas have no operands.
func (*CachingFactory) Or ¶
func (fac *CachingFactory) Or(operands ...Formula) Formula
Or returns a disjunction of the given operands. If the result is an Or formula, it is guaranteed to have at least two operands. An empty disjunction is treated as false, a disjunction with one operand, is treated as this operand.
func (*CachingFactory) PBC ¶
func (fac *CachingFactory) PBC(comparator CSort, rhs int, literals []Literal, coefficients []int) Formula
PBC returns a pseudo-Boolean constraint with the given comparator and right-hand-side. The single operands are represented by multiplications x_i * l_i with x_i from the coefficients and l_i from the literals. The constraint represented is therefore x_1 * l_1 + ... + x_n * x_n C rhs with C in [<, >, <=, >=, =].
func (*CachingFactory) PBCOps ¶
func (fac *CachingFactory) PBCOps( formula Formula, ) (comparator CSort, rhs int, literals []Literal, coefficients []int, found bool)
PBCOps returns the comparator, right-hand-side, literals, and coefficients of a given formula interpreted as a pseudo-Boolean constraint. The ok flag indicates whether the constraint was found on the factory or not.
func (*CachingFactory) PutConfiguration ¶
func (fac *CachingFactory) PutConfiguration(config configuration.Config) error
PutConfiguration adds a configuration to the factory.
func (*CachingFactory) SetPrintSymbols ¶
func (fac *CachingFactory) SetPrintSymbols(symbols *PrintSymbols)
SetPrintSymbols sets the symbols for printing formulas with Sprint.
func (*CachingFactory) Statistics ¶
func (fac *CachingFactory) Statistics() string
Statistics returns a statistic of the factory as a multi-line string.
func (*CachingFactory) Symbols ¶
func (fac *CachingFactory) Symbols() *PrintSymbols
Symbols returns the print symbols for the factory. These symbols are used when calling Sprint on a formula.
func (*CachingFactory) Var ¶
func (fac *CachingFactory) Var(name string) Variable
Var returns a Boolean variable with the given name. In contrast to the Variable method, a variable type is returned.
func (*CachingFactory) VarName ¶
func (fac *CachingFactory) VarName(variable Variable) (name string, ok bool)
VarName returns the name of the given variable. The ok flag indicates whether the variable was found on the factory or not.
func (*CachingFactory) Variable ¶
func (fac *CachingFactory) Variable(name string) Formula
Variable returns a Boolean variable with the given name as a Formula.
func (*CachingFactory) Vars ¶
func (fac *CachingFactory) Vars(name ...string) []Variable
Vars returns a list of Boolean variable with the given names.
func (*CachingFactory) Verum ¶
func (fac *CachingFactory) Verum() Formula
Verum returns the Boolean true constant.
type ExtendedProposition ¶
type ExtendedProposition[T fmt.Stringer] struct { Backpack T // contains filtered or unexported fields }
An ExtendedProposition is a proposition implementation with a formula and a user provided generic backpack.
func NewExtendedProposition ¶
func NewExtendedProposition[T fmt.Stringer](formula Formula, backpack T) *ExtendedProposition[T]
NewExtendedProposition returns a new extended proposition with the formula and the given backpack.
func (*ExtendedProposition[T]) Formula ¶
func (p *ExtendedProposition[T]) Formula() Formula
Formula returns the formula of the proposition.
func (*ExtendedProposition[T]) Sprint ¶
func (p *ExtendedProposition[T]) Sprint(fac Factory) string
Sprint takes a formula factory and pretty-prints the proposition.
func (*ExtendedProposition[T]) String ¶
func (p *ExtendedProposition[T]) String() string
type FSort ¶
type FSort uint32
FSort encodes the different formula sorts.
const ( SortFalse FSort = iota // constant false SortTrue // constant true SortLiteral // literal (variable + phase) SortNot // negation SortAnd // conjunction SortOr // disjunction SortImpl // implication SortEquiv // equivalence SortCC // cardinality constraint SortPBC // pseudo-Boolean constraint )
type Factory ¶
type Factory interface {
Verum() Formula
Falsum() Formula
Constant(value bool) Formula
Var(name string) Variable
Variable(name string) Formula
Vars(name ...string) []Variable
Lit(name string, phase bool) Literal
Literal(name string, phase bool) Formula
Not(operand Formula) Formula
BinaryOperator(sort FSort, left, right Formula) (Formula, error)
Implication(left, right Formula) Formula
Equivalence(left Formula, right Formula) Formula
NaryOperator(sort FSort, operands ...Formula) (Formula, error)
And(operands ...Formula) Formula
Minterm(operands ...Literal) Formula
Or(operands ...Formula) Formula
Clause(operands ...Literal) Formula
CC(comparator CSort, rhs uint32, variables ...Variable) Formula
AMO(variables ...Variable) Formula
EXO(variables ...Variable) Formula
PBC(comparator CSort, rhs int, literals []Literal, coefficients []int) Formula
VarName(variable Variable) (name string, found bool)
LitNamePhase(literal Literal) (name string, phase, found bool)
LiteralNamePhase(formula Formula) (name string, phase, found bool)
NotOperand(formula Formula) (op Formula, found bool)
BinaryLeftRight(formula Formula) (left, right Formula, found bool)
NaryOperands(formula Formula) (ops []Formula, found bool)
PBCOps(formula Formula) (comparator CSort, rhs int, literals []Literal, coefficients []int, found bool)
Operands(formula Formula) []Formula
NewAuxVar(sort AuxVarSort) Variable
ConfigurationFor(sort configuration.Sort) (configuration.Config, bool)
PutConfiguration(configuration configuration.Config) error
Symbols() *PrintSymbols
SetPrintSymbols(symbols *PrintSymbols)
Statistics() string
// contains filtered or unexported methods
}
A Factory is the central concept of LogicNG and is always required when working with the library. A formula factory is an object consisting of two major components:
- a factory, which creates formulas
- a container, which stores created formulas.
Formula factories are not thread safe!
func NewFactory ¶
NewFactory returns a new caching formula factory. If the optional conserveVars flag is set to true, trivial contradictions and tautologies are not simplified in formulas. E. g. a formula like A & ~A, A | ~A, or A => A can be generated on the formula factory. Therefore it is guaranteed that all variables of the original formula are still present on the formula factory. If set to false, the formulas will be simplified to false or true and therefore variables of the original formula can not be present on the formula factory. The default behaviour is that the flag is set to false.
type Formula ¶
type Formula uint32
Formula represents a Boolean (or pseudo-Boolean) formula in LogicNG. The datatype itself is just an alias to an uint32. The first four bits encode the formula sort whereas the remaining 28 bit are a unique identifier for the formula on the factory. Therefore, a formula is only valid and useful in the context of the factory which was used to generate it.
func EncodeFormula ¶
EncodeFormula takes a formula sort and a unique ID an returns its encoding.
func LiteralsAsFormulas ¶
LiteralsAsFormulas returns a list of literals as a list of formulas.
func LookupTransformationCache ¶
func LookupTransformationCache(fac Factory, sort TransformationCacheSort, formula Formula) (Formula, bool)
LookupTransformationCache searches a cache entry for a given transformation sort and formula. It returns the optional result and a flag whether there was a cache entry.
func NewCornerCases ¶
func SubNodes ¶ added in v0.4.0
SubNodes returns all sub-nodes of the given formula. The order of the sub-nodes is bottom-up, i.e. a sub-node only appears in the result when all of its sub-nodes are already listed.
func VariablesAsFormulas ¶
VariablesAsFormulas returns a list of variables as a list of formulas.
func (Formula) AsLiteral ¶
AsLiteral returns the current formula as a literal type or returns an error if the formula is not a literal.
func (Formula) AsVariable ¶
AsVariable returns the current formula as a variable type or returns an error if the formula is not a variable.
func (Formula) IsAtomic ¶
IsAtomic reports whether the formula is an atomic formula, i.e. a constant, a literal, or a pseudo-Boolean constraint including cardinality constraints.
func (Formula) IsConstant ¶
IsConstant reports whether the formula is a constant.
func (Formula) IsNeg ¶
IsNeg reports whether the formula is negative, i.e. the false constant, a negative literal, or a negation.
func (Formula) IsPos ¶
IsPos reports whether the formula is positive, i.e. the true constant, a positive literal, or any formula which is not a negation.
func (Formula) Sprint ¶
Sprint prints a formula in human-readable form. In order to this, the generating formula factor must be passed as a parameter.
This method panics if the formula cannot be found on the factory.
func (Formula) String ¶
String returns a simple string representation of a formula. Since the default string method does not know the constructing factory, only the formula sort and ID can be printed. If you want a human-readable string output, use the Sprint function which takes the factory as parameter.
type FormulaSet ¶
type FormulaSet = fset[Formula] // Immutable set of formulas
func NewFormulaSet ¶
func NewFormulaSet(formula ...Formula) *FormulaSet
NewFormulaSet generates a new formula set with the given formulas as content.
type Function ¶ added in v0.4.0
A Function is a function which maps a formula to an arbitrary value.
type FunctionCacheSort ¶
type FunctionCacheSort byte
FunctionCacheSort encodes a formula function sort for which the result can be cached.
const ( FuncVariables FunctionCacheSort = iota FuncLiterals FuncDepth FuncSubnodes FuncNumberOfAtoms FuncNumberOfNodes FuncDNNFModelCount )
func (FunctionCacheSort) String ¶
func (i FunctionCacheSort) String() string
type LitSet ¶
type LitSet = fset[Literal] // Immutable set of literals
type Literal ¶
type Literal uint32
Literal represents a Boolean literal in LogicNG. This is just a type alias for the uint32 wrapped by the Formula type. But for type-safety reasons it is often desirable to explicitly know that something is a literal. You can convert between literal and formula with the AsFormula and AsLiteral methods.
func EncodeLiteral ¶
EncodeLiteral takes a unique ID an returns its encoding as a literal.
func VariablesAsLiterals ¶
VariablesAsLiterals returns a list of variables as a list of literals.
type MutableFormulaSet ¶ added in v0.3.0
type MutableFormulaSet = mutableFset[Formula] // Mutable set of formulas
func NewMutableFormulaSet ¶ added in v0.3.0
func NewMutableFormulaSet(formula ...Formula) *MutableFormulaSet
NewMutableFormulaSet generates a new mutable formula set with the given formulas as content.
type MutableLitSet ¶ added in v0.3.0
type MutableLitSet = mutableFset[Literal] // Mutable set of literals
func NewMutableLitSet ¶ added in v0.3.0
func NewMutableLitSet(literal ...Literal) *MutableLitSet
NewMutableLitSet generates a new mutable literal set with the given literal as content.
type MutableVarSet ¶ added in v0.3.0
type MutableVarSet = mutableFset[Variable] // Mutable set of variables
func NewMutableVarSet ¶ added in v0.3.0
func NewMutableVarSet(variable ...Variable) *MutableVarSet
NewMutableVarSet generates a new mutable variable set with the given variables as content.
func NewMutableVarSetCopy ¶ added in v0.3.0
func NewMutableVarSetCopy(variableSet ...*VarSet) *MutableVarSet
NewMutableVarSetCopy returns a new mutable variable set with the content of all the given variable sets as content.
type PredicateCacheSort ¶
type PredicateCacheSort byte
PredicateCacheSort encodes a formula predicate sort for which the result can be cached.
const ( PredNNF PredicateCacheSort = iota PredCNF PredDNF PredAIG )
func (PredicateCacheSort) String ¶
func (i PredicateCacheSort) String() string
type PrintSymbols ¶
type PrintSymbols struct {
Verum string // default: $true
Falsum string // default: $false
Not string // default: ~
Implication string // default: =>
Equivalence string // default: <=>
And string // default: &
Or string // default: |
LeftBracket string // default: (
RightBracket string // default: )
Plus string // default: +
Minus string // default: -
Multiplication string // default: *
Equal string // default: =
Less string // default: <
LessOrEqual string // default: <=
Greater string // default: >
GreaterOrEqual string // default: >=
}
PrintSymbols gathers all symbols for Boolean and pseudo-Boolean formulas for printing formulas. You can use the DefaultSymbols method to use exactly these symbols which can be parsed again be the default parser, or you can define your own symbols.
func DefaultSymbols ¶
func DefaultSymbols() *PrintSymbols
DefaultSymbols returns the standard symbols for printing formulas.
type Proposition ¶
A Proposition is a formula with additional information like a textual description or a user-provided object.
type StandardProposition ¶
type StandardProposition struct {
Description string
// contains filtered or unexported fields
}
A StandardProposition is a simple proposition implementation with a formula and a textual description.
func NewStandardProposition ¶
func NewStandardProposition(formula Formula, description ...string) *StandardProposition
NewStandardProposition returns a new standard proposition with the formula and an optional textual description.
func (*StandardProposition) Formula ¶
func (p *StandardProposition) Formula() Formula
Formula returns the formula of the proposition.
func (*StandardProposition) Sprint ¶
func (p *StandardProposition) Sprint(fac Factory) string
Sprint takes a formula factory and pretty-prints the proposition.
func (*StandardProposition) String ¶
func (p *StandardProposition) String() string
type Transformation ¶ added in v0.4.0
A Transformation is a function which maps a formula to another formula
type TransformationCacheSort ¶
type TransformationCacheSort byte
TransformationCacheSort encodes a formula transformation sort for which the result can be cached.
const ( TransNNF TransformationCacheSort = iota TransCNFFactorization TransDNFFactorization TransAIG TransDistrSimpl TransUnitPropagation TransBDDCNF TransBDDNF )
func (TransformationCacheSort) String ¶
func (i TransformationCacheSort) String() string
type Tristate ¶
type Tristate byte
Tristate represents a Boolean value with the possibility of a third UNDEF value.
func TristateFromBool ¶
TristateFromBool returns the tristate for the given Boolean value.
type VarSet ¶
type VarSet = fset[Variable] // Immutable set of variables
func NewVarSetCopy ¶ added in v0.3.0
NewVarSetCopy returns a new variable set with the content of all the given variable sets as content.
type Variable ¶
type Variable uint32
Variable represents a Boolean variable in LogicNG. This is just a type alias for the uint32 wrapped by the Formula type. But for type-safety reasons it is often desirable to explicitly know that something is a variable. You can convert between variable and formula with the AsFormula and AsVariable methods.
func EncodeVariable ¶
EncodeVariable takes a unique ID an returns its encoding as a variable.
func LiteralsAsVariables ¶
LiteralsAsVariables returns a list of literals as a list of variables or returns an error if there is a negative literal in the list.
Source Files
¶
- csort_string.go
- doc.go
- factory.go
- formula.go
- formula_depth.go
- formula_profile.go
- fsort_string.go
- function.go
- functioncachesort_string.go
- graphical.go
- number_of_atoms.go
- number_of_nodes.go
- predicate.go
- predicatecachesort_string.go
- printer.go
- proposition.go
- set.go
- subnode.go
- testdata.go
- transformation.go
- transformationcachesort_string.go
- tristate.go
- tristate_string.go