Skip to content

Use Atomese Formulas, and not scheme, for math #6

Description

@linas

Friendly reminder, because I think it has fallen off the TODO-list. The new atomese formula support is likely to be a lot faster than using (GroundedPredicateNode "scm:foo-formula") See https://github.com/opencog/atomspace/blob/master/examples/atomspace/formulas.scm for a working example; I copy part of it below to give a flavor of it:

; Create a SimpleTruthValue with a non-trivial formula:
; It will be the TV := (1-sA*sB, cA*cB) where sA and sB are strenghts
; and cA, cB are confidence values. The PredicateFormulaLink assembles
; two floating-point values, and create a SimpleTruthValue out of them.
;
(cog-evaluate!
   (PredicateFormula
      (Minus
         (Number 1)
         (Times (StrengthOf (Concept "A")) (StrengthOf (Concept "B"))))
      (Times (ConfidenceOf (Concept "A")) (ConfidenceOf (Concept "B")))))

; The values do not need to be formulas; they can be hard-coded numbers.
(cog-evaluate!
   (PredicateFormula (Number 0.7) (Number 0.314)))

; The below computes a truth value, and attaches it to the
; EvaluationLink. Let's demo this in three parts: first define it,
; then evaluate it, then look at it.
;
(define my-ev-link
   (Evaluation
      (PredicateFormula (Number 0.7) (Number 0.314))
      (List
         (Concept "A")
         (Concept "B"))))

; Evaluate ...
(cog-evaluate! my-ev-link)

; Print.
(display my-ev-link)

; More typically, one wishes to have a formula in the abstract,
; with variables in it, so that one can apply it in any one of
; a number of different situations. In the below, the variables
; are automatically reduced with the Atoms in the ListLink, and
; then the formula is evaluated to obtain a TruthValue.
(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"))))

and so on. The example gives even more details that make it even more PLN-useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions