Writing a prover on Janus
REFERENCE
Run your own SWI-Prolog prover through DeepLog
A prover is an SWI-Prolog module that a JanusProver loads and runs queries in. It builds on DeepLog’s Prolog library, whose exported predicates follow semantic versioning like the Python API.
The prover
JanusProver loads a prover module once.
consult() loads a program’s clauses into
a module of their own and returns its name, and
query() runs a goal in the prover’s
module. Builtins added with
add_builtin() belong to that prover, so
pass the prover into the goals that may call them.
from pathlib import Path
from deeplog.grounding.prolog import JanusProver
prover = JanusProver(Path("my_prover.pl"))
program = prover.consult([":- dynamic fact/1.", "fact(p(a))."])
rows = prover.query(
"prove(Program, Prover, Goal, Answer)",
{"Program": program, "Prover": prover, "Goal": ("p", ("X",))},
)
answers = [row["Answer"] for row in rows]
The prover module declares its own module name, loads the library, and reads the program through the module name it is given:
:- module(my_prover, []).
:- use_module(deeplog(grounding)).
prove(Program, Prover, GoalSymbol, AnswerSymbol) :-
from_symbol(GoalSymbol, Goal),
( is_builtin(Prover, Goal)
-> call_builtin(Prover, Goal)
; Program:fact(Goal)
),
to_symbol(Goal, AnswerSymbol).
The library
Predicate |
Arguments |
Meaning |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
Prove the builtin |
|
|
Throw the error that |
|
|
Throw the error that |
The SWI-Prolog builtins a program may call are between/3, nth0/3, member/2,
length/2, =/2, \=/2, ==/2, \==/2, is/2, =:=/2, =\=/2, </2,
>/2, =</2 and >=/2.
Only these exports are public. Anything else in the library can change in any release, so a prover never calls into the library with a module prefix.
See also
DeepProbLog built-in predicates for the builtins of the default grounder.
The Janus manual for
py_call/2and how Python values cross into Prolog.