Skip to main content

ltms

A logic-based Truth Maintenance System (LTMS) and a pattern-directed reasoning engine in pure Python, after Forbus & de Kleer, Building Problem Solvers (MIT Press, 1993).

The LTMS maintains belief over a set of propositional clauses using Boolean Constraint Propagation (unit propagation), records well-founded support for every derived value, performs dependency-directed backtracking on contradictions, and can explain why anything is believed. A small forward-chaining rule engine sits on top of it.

Documentation site: https://pisanuw.github.io/ltms/ (built from docs/).

New to this? Start with the study companion — a chapter-by-chapter walk-through of the concepts, examples, and exercise solutions. See also PLAN.md for the build plan and STUDY-NOTES.md for the technical digest.

Why

There is no faithful Python LTMS in the wild — JTMS/ATMS have a few toy ports, but the clausal-BCP LTMS with dependency-directed backtracking is the least-ported truth maintenance system outside Lisp/Racket. This is a clean, tested, idiomatic-Python implementation.

What's here

Layer Module What it gives you
Terms + unification ltms.terms, ltms.unify s-expression terms, occurs-checked unification
TRE ltms.tre pattern-directed forward chaining (no belief revision)
JTMS + JTRE ltms.jtms, ltms.jtre justification-based belief, IN/OUT, two-phase retraction
LTMS core ltms.core, ltms.normalize clausal Boolean Constraint Propagation, assumptions, nogoods, CNF
LTRE ltms.ltre reasoning engine: assert!/assume!/retract!, belief-conditioned rules
Facilities ltms.indirect, ltms.cwa, ltms.dds indirect proof, closed-world assumptions, dependency-directed search
Completeness ltms.cltms prime implicates / complete() (optional logical completeness)
Watched literals ltms.watched WatchedLTMS, the SAT-style 2-watched-literals BCP engine
Explanation ltms.explain why_node, explain_node (well-founded proofs)
File DSL ltms.dsl read world models from .kb files, separate from Python

Usage

from ltms import LTRE

e = LTRE()
e.assert_(("or", ("p",), ("q",)))   # p v q
e.assert_(("not", ("p",)))          # ~p
e.is_true(("q",))                   # True  (unit propagation)

e.assume(("rain",), "guess")        # retractable assumption
e.assert_(("implies", ("rain",), ("wet",)))
e.is_true(("wet",))                 # True
e.retract(("rain",), "guess")
e.is_unknown(("wet",))              # True  (belief revised)

World models in files

The world model can live in a .kb data file, separate from Python:

# examples/kb/belief_revision.kb
rain         -> wet ground
sprinkler on -> wet ground
assume rain
expect wet ground true
from ltms.dsl import load_kb_file
load_kb_file("examples/kb/belief_revision.kb")   # runs it; `expect` lines self-check

See examples/ for runnable TRE, LTRE, and dependency-directed-search demos, and exercises/ for worked solutions to the book's chapter exercises (paraphrased statements + original answers/code).

Install (development)

python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"      # add ".[dev,sat]" for the PySAT differential tests
pytest

Notes

BCP uses the book's incremental pvs/sats counters (sound but, by design, not logically complete). A watched-literals rewrite and the completeness extension (CLTMS, prime implicates) are tracked as future work in PLAN.md.

Provenance & licensing

Original code in this repository is MIT licensed (see LICENSE).

This is an independent reimplementation of the algorithms in Building Problem Solvers; it does not copy the original Common Lisp source. The book and its reference code are available from the Northwestern Qualitative Reasoning Group at https://www.qrg.northwestern.edu/BPS/readme.html, where the full-text PDF is offered for free download "thanks to the gracious permission of MIT Press" (MIT Press retains print rights). The book PDF and other reference material are kept local and are not redistributed here. See NOTICE for full attribution.

Metadata

Release files for ltms 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ltms 0.1.0
File Size Uploaded
ltms-0.1.0.tar.gz 357.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ltms 0.1.0
File Interpreter ABI Platform
ltms-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 399.2 kB

Release files / ltms-0.1.0.tar.gz

Download URL ltms-0.1.0.tar.gz
Size 357.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f9f7b7e0250bb06e525cc52e64d99c63bde0b47b964df633e102fe2b93825198
BLAKE2b-256 checksum
How to use checksums
3d07e43dd0c08b1e21296e3a83479760e6e9eb9d0a12f9a4ae406d4f44fcb0b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / ltms-0.1.0-py3-none-any.whl

Download URL ltms-0.1.0-py3-none-any.whl
Size 41.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df54b3771f4eada59143a65d221d8e1ee388c38458c6f15a64a3501ca59be5c5
BLAKE2b-256 checksum
How to use checksums
6998543cb7b33d3d063aa806b0b43634e87f915d4b056486da0fe2fbc8ae4336
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page