Skip to main content

Knuckledragger

drawing

Knuckledragger (git repo) is an attempt at creating a down to earth, highly automated interactive proof assistant in python. The goal is to support applications like software/hardware verification, calculus, equational reasoning, and numerical bounds.


Installation

To install run

uv pip install git+https://github.com/philzook58/knuckledragger.git

Or to install locally

git clone https://github.com/philzook58/knuckledragger.git
cd knuckledragger
uv pip install -e .

A full installation of extra functionality can be achieved by

uv pip install -e .[solvers,rust,pypcode,dev]

Getting Started

Open In Colab youtube

from kdrag import Calc, Inductive, Proof, Theorem, axiom, cond, define, prove
from kdrag.kernel import LemmaError
import kdrag.notation as notation
# smt is literally a reexporting of z3
from kdrag.smt import (
    And, BitVec, Bools, Const, Consts, DeclareSort, ExprRef,
    ForAll, Function, Implies, Or, Real,
)

# Anything Z3 can do on its own, we can "prove" with no extra work
p, q = Bools("p q")
simple_taut = prove(Implies(p, Or(p, q)))

# The returned objects are Proofs, not ExprRef formulas
assert isinstance(simple_taut, Proof)
assert not isinstance(simple_taut, ExprRef)

# prove will throw an error if the theorem is not provable
try:
    false_lemma = prove(Implies(p, And(p, q)))
    print("This will not be reached")
except LemmaError:
    pass

# Z3 also supports things like Reals, Ints, BitVectors and strings
x = Real("x")
real_trich = prove(ForAll(x, Or(x < 0, x == 0, 0 < x)))

x = BitVec("x", 32)
or_idem = prove(ForAll(x, x | x == x))

###################################################################
###################################################################

# But the point of Knuckledragger is really for the things Z3 can't do in one shot

# Knuckledragger supports algebraic datatypes and induction
Nat = Inductive("MyNat")
Zero = Nat.declare("Zero")
Succ = Nat.declare("Succ", ("pred", Nat))
Nat = Nat.create()

# We can define an addition function by cases
n, m = Consts("n m", Nat)
add = Function("add", Nat, Nat, Nat)
add = define("add", [n, m],
    cond(
        (n.is_Zero, m),
        (n.is_Succ, Nat.Succ(add(n.pred, m))),
    ),
)

# There is a notation overloading mechanism modelled after python's singledispatch
notation.add.register(Nat, add)

# The definitional lemma is not available to the solver unless you give it
add_zero_x = prove(ForAll(n, Nat.Zero + n == n), by=[add.defn])
add_succ_x = prove(ForAll([n, m], Nat.Succ(n) + m == Nat.Succ(n + m)), by=[add.defn])


# More involved proofs can be more easily done in an interactive tactic
# Under the hood, this boils down to calls to prove
# These proofs are best understood by seeing the interactive output in a Jupyter notebook
@Theorem(ForAll(n, n + Nat.Zero == n))
def add_x_zero(l):
    n = l.fix()
    l.induct(n)
    # Base case: Zero + Zero == Zero.
    l.auto(by=[add.defn])
    # Inductive case: the predecessor satisfies the theorem.
    l.auto(by=[add.defn])


###################################################################
###################################################################

# But we can also build our own sorts and axiomatic theories.
# https://en.wikipedia.org/wiki/Group_(mathematics)
G = DeclareSort("G")
mul = Function("mul", G, G, G)
e = Const("e", G)
inv = Function("inv", G, G)

notation.mul.register(G, mul)

x, y, z = Consts("x y z", G)
mul_assoc = axiom(ForAll([x, y, z], x * (y * z) == (x * y) * z))
id_left = axiom(ForAll(x, e * x == x))
inv_left = axiom(ForAll(x, inv(x) * x == e))

# The Calc tactic can allow one to write explicit equational proofs
c = Calc([x], x * inv(x))
c.eq(e * (x * inv(x)), by=[id_left])
c.eq((inv(inv(x)) * inv(x)) * (x * inv(x)), by=[inv_left])
c.eq(inv(inv(x)) * ((inv(x) * x) * inv(x)), by=[mul_assoc])
c.eq(inv(inv(x)) * (e * inv(x)), by=[inv_left])
c.eq(inv(inv(x)) * inv(x), by=[id_left])
c.eq(e, by=[inv_left])
inv_right = c.qed()

For more on using z3py

For more on interactive theorem proving (This is a lot to take in)

A recent summary talk of Knuckledragger was presented at NEPLS 2025

Watch the video

Blog Posts

Comparison to Other Systems

  • Z3: Knuckledragger has a superset of the capabilities of Z3 since it is built on top of it. Enables rigorous chaining of Z3 calls. Better facilities for higher order and quantifier reasoning.
  • sympy and sage: More manual manipulation is to be expected, but also more logically sound. Everything is integrated in a cohesive fabric of first order logic.
  • Lean and Coq: No dependent types, larger trusted code base, a higher baseline of automation.
  • Isabelle and HOLpy: Knuckledragger is similar in many respects to the systems. It has a lack of parametric types and weaker higher order reasoning. Knuckledragger is a library, not a framework. Heavy reuse of already existing python things is preferred whenever possible (Jupyter, z3py, sympy, python idioms). It is seamlessly integrated with z3py.

Design

It is not desirable or within my capabilities to build a giant universe in which to live. The goal is to take a subtle blade and bolt together things that already exist.

Using widespread and commonly supported languages gives a huge leg up in terms of tooling and audience. Python is the modern lingua franca of computing. It has a first class interactive experience and extensive bindings to projects in other languages.

Core functionality comes from Z3. The Z3 python api is a de facto standard. The term and formula data structures of knuckledragger are literally z3 python terms and formula. To some degree, Knuckledragger is a metalayer to guide smt through proofs it could perhaps do on its own, but it would get lost.

A hope is to be able to use easy access to Jupyter, copilot, ML ecosystems, sympy, cvxpy, numpy, scipy, egglog, Julia, Prolog, Maude, calcium, flint, Mathematica, and sage will make metaprogramming in this system very powerful. I maintain the option to just trust these results but hopefully they can be translated into arguments the kernel can understand.

The core logic is more or less multi-sorted first order logic aka SMT-LIB2.

Big features that ATPs do not often support are induction, definitions, and other axiom schema. Knuckledragger supports these.

Other theorem provers of interest: cvc5, Vampire, eprover, Twee, nanoCoP.

The de Bruijn criterion is going to be bent or broken in certain senses. Attention is paid to what is kernel and what is not. Proof objects are basically trees recording chains of lemmas discharged by Automated Theorem Prover (ATP) calls. Soundness will be attempted, accidental misuse will be made difficult but not impossible.

Isabelle and ACL2 are the strongest influences. If you want dependent type theory, you are at a level of investment and sophistication that it behooves you to be in another system. Should there be a strong automated DTT solver someday, I will reconsider.

FAQ

  • Is this for proving about properties about python programs?
    • Not directly. Proving properties of general python programs in a highly assured manner is extremely difficult due to its extreme dynamic nature. There are a couple caveats to this answer.
      1. Knuckledragger does enable you to model your algorithms and extract/interpret them to python.
      2. A subset of purely-function, strongly-typed python can be reflected directly into the Knuckledragger logic.
      3. Domain specific modelling of important python ecosystem libraries is a WIP.
  • Is Knuckledragger python specific?
    • Python is a useful and important platform, but the core of the design can be ported to many languages. The design is based around the chaining of calls to z3 which gets you a lot of distance for free.
      • SBV - Haskell
      • Yours here!

License & Citation

MIT licensed. See LICENSE for more information.

Citing this repository is highly appreciated but not required by the license.

@software{knuckledragger2025,
  author = {Philip Zucker},
  title = {{Knuckledragger: A Low Barrier Proof Assistant}},
  url = {https://github.com/philzook58/knuckledragger},
  month = {1},
  year = {2025}
}

Metadata

Release files for knuckledragger 0.4.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 knuckledragger 0.4.0
File Size Uploaded Provenance Actions
knuckledragger-0.4.0.tar.gz 329.5 kB With provenance Details for knuckledragger-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 706.4 kB

Release files / knuckledragger-0.4.0.tar.gz

Download URL knuckledragger-0.4.0.tar.gz
Size 329.5 kB
Tags Source
SHA-256 checksum
How to use checksums
22bff513680ced11f70b2b1da7ab30a2171f305a2e9f7257b703c03c82bc494f
BLAKE2b-256 checksum
How to use checksums
629f227836e40c11ae759636b02e4e2dd3adde745f9b1ec8eeb813859bd13d57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / knuckledragger-0.4.0-py3-none-any.whl

Download URL knuckledragger-0.4.0-py3-none-any.whl
Size 376.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0ac88408c9ab195e7fc6998e70698a8c02c79614b1949a7e9bc054a8948495b
BLAKE2b-256 checksum
How to use checksums
5060f969d9f27f7812c3a133df98d90368d1bda393e479f8d4fe592c62747fb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Security for knuckledragger 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for knuckledragger-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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