MCPcopy
hub / github.com/google/mangle / premiseNegAtom

Function premiseNegAtom

engine/premise.go:58–87  ·  view source on GitHub ↗

premiseNegAtom semi-positive evaluation, i.e. looks up a and fails if it is present.

(a ast.Atom, store factstore.ReadOnlyFactStore, subst unionfind.UnionFind)

Source from the content-addressed store, hash-verified

56
57// premiseNegAtom semi-positive evaluation, i.e. looks up a and fails if it is present.
58func premiseNegAtom(a ast.Atom, store factstore.ReadOnlyFactStore, subst unionfind.UnionFind) ([]unionfind.UnionFind, error) {
59 n, err := functional.EvalAtom(a, subst)
60 if err != nil {
61 return nil, err
62 }
63
64 if n.Predicate.IsBuiltin() {
65 ok, _, err := builtin.Decide(n, &subst)
66 if err != nil {
67 return nil, err
68 }
69 if ok {
70 return nil, nil // negated: no solution
71 }
72 return []unionfind.UnionFind{subst}, nil
73 }
74 solutions := []unionfind.UnionFind{subst}
75 // If we find a single fact that unifies, then subst is not a solution.
76 err = store.GetFacts(n, func(fact ast.Atom) error {
77 if _, err := unionfind.UnifyTermsExtend(n.Args, fact.Args, subst); err == nil {
78 solutions = nil
79 return errBreak
80 }
81 return nil
82 })
83 if err != nil && err != errBreak {
84 return nil, err
85 }
86 return solutions, nil
87}
88
89func premiseEq(left, right ast.BaseTerm, subst unionfind.UnionFind) ([]unionfind.UnionFind, error) {
90 left, right, err := functional.EvalBaseTermPair(left, right, subst)

Callers 2

oneStepEvalPremiseMethod · 0.85
EvalPremiseMethod · 0.85

Calls 5

EvalAtomFunction · 0.92
DecideFunction · 0.92
UnifyTermsExtendFunction · 0.92
IsBuiltinMethod · 0.80
GetFactsMethod · 0.65

Tested by

no test coverage detected