Running proofs¶
Expressions are inert until an engine works on them. This page shows how to choose an engine, the three ways to ask for a proof, how to read the result, the ready-made theorem builders for \(TM\) and for algebroids, how to switch on optional rules, how to store and cite theorems, and how to write a rule of your own.
Setup¶
import jacopy
from jacopy.core import Degree, Scalar, Closed
from jacopy.central.algebroid import algebroid, tangent_algebroid, section_map, locality_projector
reg = jacopy.PropertyRegistry()
f, h = jacopy.functions("f h", registry=reg)
X, Y, Z = jacopy.vector_fields("X Y Z")
alpha, beta = jacopy.forms("alpha beta", degree=1)
(omega,) = jacopy.forms("omega", degree=2)
pi = jacopy.bivector("pi")
(T,) = jacopy.tensors("T", upper=1, lower=2)
nabla = jacopy.connection()
e = jacopy.frame("e")
reg.declare(omega, Closed())
E = algebroid("E", declare=("leibniz",)); u, v, w = E.sections("u v w")
A = algebroid("A"); a1, a2, a3 = A.sections("u v w")
(muA,) = jacopy.forms("mu", degree=1, bundle=A.bundle)
K = algebroid("K", declare=("lie", "anchor-morphism")); k1, k2, k3 = K.sections("u v w")
(muK,) = jacopy.forms("mu", degree=1, bundle=K.bundle)
C = algebroid("C", declare=("courant",)); c1, c2, c3 = C.sections("u v w")
R = algebroid("R", declare=("local", "regular")); Pr = locality_projector(R)
Lp = algebroid("Lp", declare=("local", "anchor-morphism")); l1, l2 = Lp.sections("u v")
As = algebroid("As", declare=("antisymmetric",)); s1, s2, s3 = As.sections("u v w")
(muS,) = jacopy.forms("mu", degree=1, bundle=As.bundle)
from jacopy.central.tangent import tangent_engine, d, SN
from jacopy.central.algebroid import algebroid_engine
from jacopy.proof.result import prove as prove_result
from jacopy.proof import (SearchStrategy, PortfolioStrategy, ExpandAndSimplify,
UnrollToFoundations, AgreementOnGenerators, prove_operator_equation, prove_equivalence,
unroll_property, diagnose, ExplicitAssumption, default_engine)
from jacopy.proof.verifier import prove_jacobi as prove_bracket_jacobi
from jacopy.proof.theorems import check_citation
from jacopy.brackets.derived import derived_bracket
import jacopy.central.tangent as tg
from jacopy.central.tangent.lie_bracket import jacobi_combination_theorems
import jacopy.central.algebroid as ag
import jacopy.central.algebroid.defect_formulas as df
Choosing the engine¶
An engine is the set of rules a proof may use. For \(TM\) use tangent_engine; for an
algebroid use algebroid_engine(E), which loads the definitions of \(E\) together with its
declared axioms. algebroid_engine(tangent_algebroid()) returns the tangent engine. Every
engine is given the same registry=reg.
eng = tangent_engine(registry=reg) # definitions on TM
engH = tangent_engine(registry=reg, holonomic_frames=(e,)) # + [e_a, e_b] = 0
engE = algebroid_engine(E, registry=reg) # definitions + axioms of E
engR = algebroid_engine(R, registry=reg, projectors=(Pr,)) # + projector rules
print(len(eng.definitions), len(engE.definitions), len(engR.definitions))
print(len(default_engine().definitions)) # structural rule only
25 28 30
1
Three ways to prove an identity¶
Way |
Pattern |
Returns |
When |
|---|---|---|---|
|
|
The default. Runs the definitions, the product rule and the simplifier together. |
|
|
|
Without |
|
|
|
|
When you want to see the assumptions a proof closed under. It does not run the product-rule pass, so some identities that |
show_equal: a chain if it closes, ProofFailure if it does not. A residual is the
difference that could not be expanded further; it is not a refutation.
chain = jacopy.show_equal(jacopy.lie_derivative(X)(f*h), X(f)*h + f*X(h),
registry=reg, engine=eng)
print("closed:", len(chain.steps), "steps")
try:
jacopy.show_equal(jacopy.lie_derivative(X)(f*Y), f*jacopy.lie_bracket(X, Y),
registry=reg, engine=eng)
except jacopy.ProofFailure as fail:
print("residual:", fail.residual)
closed: 3 steps
residual: (X(f) * Y)
prove_result: status and assumptions.
res = prove_result(eng, jacopy.lie_derivative(X)(Y), jacopy.lie_bracket(X, Y), registry=reg)
print(res.status, res.closed, "|", res.goal)
print(res.summary())
res2 = prove_result(eng, jacopy.multi_eval(d(d(f)), X, Y), registry=reg) # rhs defaults to 0
print(res2.status)
res3 = prove_result(eng, d(f*h), f*d(h) + h*d(f), registry=reg)
print(res3.status, "| residual:", res3.residual)
print([str(a) for a in res3.requires][:2])
CLOSED True | L_X(Y) = [X,Y]_VF
CLOSED: L_X(Y) = [X,Y]_VF — assumption-free
generality: generic-function
via definition: intrinsic L (Cartan-TM): L_X f = ρ(X)(f), L_X Y = [X,Y], (L_X ω)(Y…) = ρ(X)(ω(Y…)) − Σ ω(…,[X,Y_i],…)
budget: 1/1024 steps; jacopy 0.1.0
CLOSED
RESIDUAL | residual: ((-(d(f) * h)) + (-(d(h) * f)) + d((f * h)))
['registry: registry declaration: Graded(degree=0) on f', 'registry: registry declaration: Graded(degree=0) on h']
jacopy.prove and proof strategies.
lhs, rhs = jacopy.lie_bracket(X, Y)(f), -jacopy.lie_bracket(Y, X)(f)
ch = jacopy.prove(lhs, rhs, registry=reg, engine=eng) # = show_equal
ch2 = jacopy.prove(lhs, rhs, registry=reg, engine=eng, prefer="shortest") # graph search
print(len(ch.steps), len(ch2.steps))
pf = PortfolioStrategy([SearchStrategy(prefer="readable", max_states=200), ExpandAndSimplify()])
print(len(pf.prove(lhs, rhs, registry=reg, engine=eng).steps))
deep = UnrollToFoundations(ExpandAndSimplify()).prove(lhs, rhs, registry=reg, engine=eng)
print(len(deep.steps))
5 3
4
5
The scorers, the search budget (max_depth, max_states, beam_width, max_solutions)
and each strategy class are explained in Choosing a proof strategy.
Normal form, operator identities, diagnosing a residual.
jacopy.normalize() brings an expression to normal form; prove_operator_equation
proves an operator identity by agreement on a set of generators; diagnose explains why a
residual stalled.
nf = jacopy.normalize(eng, jacopy.lie_derivative(X)(f*h), reg)
print(nf.expr, nf.converged)
class Functions: # generator set for AgreementOnGenerators
generators = (f,)
ch = prove_operator_equation(jacopy.lie_derivative(X), X, Functions(), registry=reg, engine=eng)
print("L_X = X on functions:", len(ch.steps), "step(s)")
dd = jacopy.exterior_d() # the operator (d(...) is a shortcut function)
report = diagnose(jacopy.Act(dd, jacopy.Act(dd, f)), registry=reg)
print(report.hints[0].category)
((X(f) * h) + (X(h) * f)) True
L_X = X on functions: 1 step(s)
stalled-d-squared
Bracket Jacobi, equivalence, provenance of a declaration, explicit assumptions.
ExplicitAssumption(expr, target) adds a single rewrite \(\text{expr}\to\text{target}\) to an
engine; it is recorded as an assumption.
db = derived_bracket(SN, pi)
print(db.jacobi_obstruction()) # [pi, pi]_SN
print(prove_equivalence(db, db, alpha, beta, registry=reg).steps == [] or "ok")
print(unroll_property(reg.get(omega, Closed)).steps[0].rule)
engX = tangent_engine(registry=reg)
engX.register(ExplicitAssumption(jacopy.lie_bracket(X, Y), jacopy.Zero)) # only [X, Y] = 0
print(len(jacopy.show_equal(jacopy.lie_bracket(X, Y)(f), jacopy.Zero,
registry=reg, engine=engX).steps))
[·,·]_SN(pi, pi)
ok
axiom
3
Reading the result¶
ProofResult.statustakes four values:CLOSED: the proof closed, under the assumptions listed inrequires.RESIDUAL: both sides were brought to normal form and a difference remained. This is not a refutation, only a difference that could not be expanded further.BUDGET: the step limit was reached.INVALID: the types or degrees of the two sides do not match.
res.requireslists everything the proof relies on: declared axioms, declarations read from the registry and cited theorems.res.summary()prints them in readable form.ProofChain.stepsis the list of steps. EachProofStepcarriesrule,roleandprovenance_tag(definition, axiom, theorem, assumption),beforeandafter.chain.initialandchain.finalare the two ends of the chain.
prove_result takes max_steps=1024, the number of rule applications allowed for both sides
together. When it runs out the result is BUDGET, which, like RESIDUAL, is not a
refutation:
for budget in (2, 1024):
print(budget, prove_result(eng, jacopy.multi_eval(d(d(f)), X, Y), registry=reg,
max_steps=budget).status)
2 BUDGET
1024 CLOSED
chain = tg.prove_cartan_magic_on_functions(X, f, registry=reg)
step = chain.steps[0]
print(step.provenance_tag, "|", step.role, "|", step.before, "->", step.after)
print(chain.initial, "=>", chain.final)
print(len(chain.steps), "steps")
axiom | definition | L_X(f) -> X(f)
L_X(f) => 0
6 steps
jacopy.print_chain() prints the whole chain as a tree, one node per step, with the
rule that justifies it.
Ready-made theorem builders: \(TM\)¶
These functions prove a theorem for the objects you pass and return the chain. They are
called as tg.<name> after import jacopy.central.tangent as tg, except
jacobi_combination_theorems, which is imported from jacopy.central.tangent.lie_bracket.
Argument orders and return types differ between builders; check the “Arguments” and
“Returns” columns.
Mathematics |
In code |
Arguments |
Returns |
|---|---|---|---|
\([X,Y]f=-[Y,X]f\) |
|
X, Y; f |
|
\(\sum_{\mathrm{cyc}}[X,[Y,Z]]f=0\) |
|
X, Y, Z; f |
|
Jacobi combination \(=0\) (section level, both signs) |
|
X, Y, Z; f |
|
\([X,fY](h)=X(f)Y(h)+f[X,Y](h)\) |
|
X, f, Y, h (mind the order) |
|
\([X,Y+Z]=[X,Y]+[X,Z]\) |
|
X, Y, Z; f |
|
\([cX,Y]=c[X,Y]\) |
|
c: integer; X, Y; f |
|
\([fX,Y](h)=f[X,Y](h)-Y(f)X(h)\) |
|
f, X, Y, h |
|
\(\nabla_Xf=X(f)\) |
|
connection; X; f |
|
\(\nabla_X(fT)=X(f)T+f\nabla_XT\) |
|
connection; X; f; T |
|
\(\langle e^a,e_b\rangle=\delta^a_b\) |
|
frame; upper, lower index |
|
\(\langle df,X\rangle=X(f)\) |
|
X; f |
|
\((d\alpha)(X,Y)=X\alpha(Y)-Y\alpha(X)-\alpha([X,Y])\) |
|
1-form; X, Y |
|
\((d\,df)(X,Y)=0\) |
|
f; X, Y |
|
\((d\,d\alpha)(X,Y,Z)=0\) |
|
1-form; X, Y, Z; f |
|
\(\mathcal L_Xf=\iota_Xdf+d\iota_Xf\) |
|
X; f |
|
\(\langle\mathcal L_X\alpha,Y\rangle=\langle\iota_Xd\alpha+d\iota_X\alpha,Y\rangle\) |
|
1-form; X, Y |
|
\(\mathcal L_X(df)=d(\mathcal L_Xf)\) |
|
X; f; Y |
|
\((\mathcal L_Xd\alpha)(Y,Z)=(d\mathcal L_X\alpha)(Y,Z)\) |
|
1-form; X, Y, Z; f |
|
\(\mathcal L_X\iota_Y\alpha-\iota_Y\mathcal L_X\alpha=\iota_{[X,Y]}\alpha\) |
|
1-form; X, Y |
|
\([\mathcal L_X,\mathcal L_Y]f=\mathcal L_{[X,Y]}f\) |
|
X, Y; f |
|
\([\mathcal L_X,\mathcal L_Y]\alpha=\mathcal L_{[X,Y]}\alpha\) |
|
1-form; X, Y, Z; f |
|
\(\iota_X\iota_Y\omega+\iota_Y\iota_X\omega=0\) |
|
2-form; X, Y |
|
\(\mathcal L_Ud\iota_W\eta-d\iota_{[U,W]}\eta-d\iota_W\mathcal L_U\eta=0\) |
|
\(\eta\); U, W; Y; f |
|
\(\mathcal L_Wd\iota_V\omega-d\iota_Wd\iota_V\omega=0\) |
|
\(\omega\): 1-form; V, W; Y; f |
|
general proof with bracket identities |
|
lhs; rhs; f |
|
\(\gamma^c_{ab}=-\gamma^c_{ba}\) |
|
frame; c, a, b |
|
\(de^c(e_a,e_b)=-\gamma^c_{ab}\) |
|
frame; c, a, b |
|
\(\langle e^d,\sum_{\mathrm{cyc}}[e_a,[e_b,e_c]]\rangle=0\) |
|
frame; d, a, b, c; f |
|
\(\gamma=0\) in a holonomic frame |
|
frame; c, a, b |
|
\([X,Y]_{SN}=[X,Y]\) |
|
X, Y; f |
|
\([X,f]_{SN}=X(f)\) |
|
X; f |
|
\([X,Y\wedge Z]=[X,Y]\wedge Z+Y\wedge[X,Z]\) |
|
X, Y, Z |
|
\([X\wedge Y,Z]_{SN}=-[Z,X\wedge Y]_{SN}\) |
|
X, Y, Z |
|
Ready-made theorem builders: algebroids¶
These are called after import jacopy.central.algebroid as ag and
import jacopy.central.algebroid.defect_formulas as df. Most builders require a hypothesis,
given in parentheses in the “Arguments” column (for example “anchor-morphism must be
declared”). If the hypothesis is missing, the builder raises ProofFailure or ValueError
instead of assuming it. The df. builders compute the defects of the Cartan calculus on an
algebroid with no axioms, in terms of the Predator \(\mathcal P\) and related tensors.
Mathematics |
In code |
Arguments |
Returns |
|---|---|---|---|
\(\langle d_Ef,u\rangle=\rho(u)f\) |
|
algebroid; u; f |
|
\(\langle d_Ef,u\rangle=\langle Df,u\rangle\) |
|
algebroid; u; f |
|
\((d_E\mu)(u,v)\) by the Palais formula |
|
algebroid; \(\mu\); u, v |
|
\(\mathcal L^E_uf=\rho(u)f\), \(\mathcal L^E_uv=[u,v]_E\) |
|
algebroid; u, v; f |
|
\(\mathcal L^E_uf=(d_E\iota_u+\iota_ud_E)f\) |
|
algebroid; u; f |
|
Cartan formula on an \(E\)-1-form |
|
algebroid; u; \(\mu\); v (mind the order) |
|
\((d_Ed_Ef)(u,v)=0\) |
|
algebroid (anchor-morphism); u, v; f |
|
\((d_Ed_E\mu)(u,v,w)=0\) |
|
algebroid (lie, anchor-morphism); \(\mu\); u, v, w |
|
instance theorem \(J(u,v,w)=0\) |
|
algebroid (jacobi); u, v, w |
|
\(\rho([u,v])=[\rho u,\rho v]\) |
|
algebroid (leibniz); u, v; f |
|
\([u,fv]=\rho(u)(f)v+f[u,v]\) from the metric axioms |
|
algebroid (metric or courant); u, v; f |
|
\(L(Df,u,v)=g(u,v)\,g^{-1}(Df)\) |
|
algebroid (metric or courant); u, v; f |
|
\(\rho(L(Df,u,v))=0\) |
|
algebroid (local pre-Leibniz); u, v; f; |
|
\(P_\rho(u,v)=0\) |
|
algebroid (leibniz); u, v; f |
|
\([\mathcal L_u,\mathcal L_v]f-\mathcal L_{[u,v]}f=\mathcal P(u,v)f\) |
|
algebroid; u, v; f |
|
\((d_Ed_Ef)(u,v)=\mathcal P(u,v)f\) |
|
algebroid; u, v; f |
|
\((\mathcal L_ud_Ef-d_E\mathcal L_uf)(v)=\mathcal P(u,v)f\) |
|
algebroid; u, v; f |
|
defect of \([\mathcal L_u,\mathcal L_v]-\mathcal L_{[u,v]}\) on \(\mu\) |
|
algebroid; \(\mu\); u, v, w |
|
defect of \(d_E^2\mu\) (antisymmetric bracket) |
|
algebroid (antisymmetric); \(\mu\); u, v, w |
|
defect of \(d_E^2\mu\), general bracket |
|
algebroid; \(\mu\); u, v, w |
|
defect of \(\mathcal L_ud_E-d_E\mathcal L_u\) on \(\mu\) |
|
algebroid; \(\mu\); u, v, w |
|
defect of the second calculus condition |
|
algebroid; \(\eta\); u, v, w |
|
defect of the third calculus condition |
|
algebroid; \(\omega\); u, v, w |
|
Extending the engine: optional rules¶
Some definition rules are not switched on in the ready-made engines; the full list is on the
Automatic rules page. Add them with eng.register(Rule(...)). For
example, \((\alpha\wedge\beta)(X,Y)\) and \(\iota_{X\wedge Y}\omega\) do not expand in the
tangent engine unless these rules are added:
from jacopy.central.calculus.indexed_rules import WedgeEvalDefinition
from jacopy.central.objects.multivector_interior import (MultivectorInterior,
MultivectorInteriorDecomposableDefinition)
engW = tangent_engine(registry=reg)
engW.register(WedgeEvalDefinition(reg))
engW.register(MultivectorInteriorDecomposableDefinition())
print(len(jacopy.show_equal(jacopy.multi_eval(jacopy.wedge(alpha, beta), X, Y),
alpha(X)*beta(Y) - alpha(Y)*beta(X), registry=reg, engine=engW).steps))
print(len(jacopy.show_equal(MultivectorInterior(jacopy.wedge(X, Y))(omega), omega(X, Y),
registry=reg, engine=engW).steps))
2
4
Theorems, theorem books and cite¶
A jacopy.Theorem is a proved identity stored with its chain and its assumptions.
A jacopy.TheoremBook keeps theorems. jacopy.cite() adds a theorem to an
engine as a rule, so that it can be used as a single step in another proof; that step is
labelled theorem. A theorem can be cited only if its assumptions also hold in the citing
engine; check_citation checks this.
book = jacopy.TheoremBook()
thm = jacopy.Theorem(
name="lie_antisymmetry", statement="[X,Y](f) = -[Y,X](f)",
lhs=jacopy.lie_bracket(X, Y)(f), rhs=-jacopy.lie_bracket(Y, X)(f),
proof=tg.prove_antisymmetry(X, Y, f, registry=reg),
generality="generic-function",
).with_structural_requires()
book.add(thm)
tg.register_cartan_theorems(book, alpha, X, Y, f, registry=reg) # four ready-made theorems
tg.register_d_squared_zero(book, f, X, Y, registry=reg)
print(book.names())
print(check_citation(thm, eng, registry=reg).ok)
engC = jacopy.cite(jacopy.ExpansionEngine([]), book, "lie_antisymmetry") # theorem -> rule
out, steps = engC.expand(jacopy.lie_bracket(X, Y)(f))
print(out, "|", steps[0].provenance_tag)
print(len(prove_bracket_jacobi(SN, f, X, Y, registry=reg, engine=eng).steps)) # graded Jacobi
('lie_antisymmetry', 'cartan_magic_on_functions', 'cartan_magic_on_one_forms', 'L_iota_commutator', 'iota_anticommute', 'd_squared_zero_on_functions')
True
(-[Y,X]_VF(f)) | theorem
4
Writing your own rule¶
Subclass jacopy.Definition and implement matches and rewrite. Every rule that
comes from outside the library enters the proof record as an assumption. For a single
expression, the shorter route is ExplicitAssumption(expression, target) (shown above).
class XXZero(jacopy.Definition):
name = "example rule: [X, X] -> 0"
def matches(self, expr):
return expr == jacopy.lie_bracket(X, X)
def rewrite(self, expr):
return jacopy.Zero
engU = jacopy.ExpansionEngine([XXZero()])
out, steps = engU.expand(jacopy.lie_bracket(X, X) + Y)
print(out, "|", steps[0].role)
(0 + Y) | assumption
ExpansionEngine.expand applies rules only; it does not simplify, so 0 + Y is left as it
is. A larger example, with axioms owned by a structure of your own, is on the
Your own structure page.