# PredicateFormulaLink

The **PredicateFormulaLink** is an evaluatable Link that can be used to specify arithmetic formulas that compute SimpleTruthValues. That is, they allow truth value formulas to be symbolically represented in the AtomSpace, and also be used for performing the actual computation that they represent. Functionally, it can be used anywhere the GroundedPredicateNode or DefinedPredicateNodes can be used, as it provides a conceptually similar service, of encapsulating computable truth values.

The DynamicFormulaLink is quite similar, except that it installs the formula into a FormulaTVLink. This allows the TruthValue to automatically update every time it is accessed (that is, the truth value is updated every time it is polled).

## Example: EvaluationLink

The following illustrates the representation and computation of a "typical" truth-value formula found in PLN. It elaborates the idea presented in the "Expressing PLN Rules As Atoms" page.

Start by defining two atoms, with non-trivial TruthValues on them:

(use-modules (opencog) (opencog exec)) (Concept "A" (SimpleTruthValue 0.8 1.0)) (Concept "B" (SimpleTruthValue 0.6 0.9))

Compute a new TruthValue, given by the formula *TV := (1-sA*sB, cA*cB)*:

(cog-evaluate! (PredicateFormula (Minus (Number 1) (Times (StrengthOf (Concept "A")) (StrengthOf (Concept "B")))) (Times (ConfidenceOf (Concept "A")) (ConfidenceOf (Concept "B")))))

Formulas can be attached to EvaluationLinks in the usual fashion:

(cog-evaluate! (Evaluation ; Compute TV = (1-sA*sB, cA*cB) (PredicateFormula (Minus (Number 1) (Times (StrengthOf (Variable "$X")) (StrengthOf (Variable "$Y")))) (Times (ConfidenceOf (Variable "$X")) (ConfidenceOf (Variable "$Y")))) (List (Concept "A") (Concept "B"))))

The above is visually awkward; this can be overcome with the DefineLink. For example, one imagines that the formula might be computing the degree of reddish color of some objects; one would then define

(DefineLink (DefinedPredicate "has a reddish color") (PredicateFormula (Minus (Number 1) (Times (StrengthOf (Variable "$X")) (StrengthOf (Variable "$Y")))) (Times (ConfidenceOf (Variable "$X")) (ConfidenceOf (Variable "$Y")))))

which is then used to give the EvaluationLink a very natural-looking form:

(cog-evaluate! (Evaluation (DefinedPredicate "has a reddish color") (List (Concept "A") (Concept "B"))))

Whenever the TruthValue on `(Concept "A")`

or `(Concept "B")`

changes, the above can be re-run to obtain a new TruthValue on the EvaluationLink.

A more detailed tutorial can be found in the `/examples/atomspace/formulas.scm` file.

## Example: SetTVLink

The previous example uses a formula to compute a truth value, and assign it to the enclosing EvalutationLink. To place this value on some other Atom, use the SetTVLink. Thus, for example:

(cog-execute! (SetTV (Concept "martian rock") (DefinedPredicate "has a reddish color") (List (Concept "A") (Concept "B"))))

A more detailed exploration can be found in the `/examples/atomspace/flows.scm` file.