How to write one
A pragma is a directive of the form#pragma key = value. Put it at the top of
your program. The setting applies whenever that program is compiled and run:
mc probability engine (Monte
Carlo — it estimates probabilities by random sampling instead of computing them
exactly), and draw 20000 samples when it does.
How you know it worked: the mc engine estimates probabilities by sampling,
so by design its results depend on the random seed and become more stable as
prob_samples grows. The exact engine (exact_ddnnf) is deterministic and
ignores the seed. So if changing #pragma prob_seed changes a reported
probability, the mc engine is the one in effect.
CLI flags win over pragmas
The pragma is the program’s built-in default. When you pass the matching flag on the command line, the CLI flag overrides the pragma. So the in-program directive sets what the program wants, and the invocation gets the final say. This lets you override a program’s baked-in choice for one run without editing the file.Pragmas apply only in the entry file
Pragmas are entry-file-scoped. The file you pass toxlog run, xlog prob, or
xlog explain is the entry file, and only its pragmas configure the engine. A
pragma written in an imported module never affects compilation — the directive
is dropped when the module is merged, and the CLI reports it on stderr:
The ten pragmas
A few of the values are short names worth spelling out:
prob_enginepicks how probabilities are computed.exact_ddnnf(the default) computes exact probabilities.mcis Monte Carlo — it estimates them by random sampling, which is approximate.epistemic_modepicks the semantics for epistemic reasoning — reasoning about what the program treats as known versus merely possible.faeelis the default;g91selects an alternative rule for what counts as “known” (the classic Gelfond-1991 semantics). See Epistemic reasoning for the difference.
The probabilistic pragmas (
prob_samples, prob_seed, prob_confidence,
prob_method, prob_max_nonmonotone_iterations) shape Monte Carlo inference and take
effect when prob_engine = mc. prob_max_nonmonotone_iterations is validated at parse
time and must be strictly greater than zero.Magic sets
Themagic_sets pragma controls a query-rewriting optimization. Use it when a
recursive query has some arguments already bound to specific values, and you want
the engine to compute only the facts that query can actually reach — rather than
deriving the entire relation and filtering afterward.
When a recursive query has bound arguments, magic sets rewrites the recursion to
push those bindings inward. The engine then derives only the reachable facts.
Setting on requests the rewrite and off disables it.
The default, auto, applies the rewrite only when the compiler can prove the
rewritten program is equivalent to the original. Where it cannot establish that
equivalence, auto declines and evaluates the program unchanged.
This makes auto safe to leave on. It optimizes what it can prove and never risks
changing your program’s meaning.