Your own structure: the research interface¶
This page answers the question “how do I work with a structure that is not ready-made in the
library?”. You may have a bracket and want to know which axioms it satisfies, or want an
identity proved from exactly the axioms you choose. The research interface
jacopy.research provides five tools for this: typed sections (SectionType), block
matrices (BlockMatrix), axiom checking (AlgebroidData and AxiomSuite), automatic engine
assembly (assemble_engine), and registration of your own structure kinds
(StructureKind). You can also write your own rewrite rules (Definition).
Setup¶
import jacopy
reg = jacopy.PropertyRegistry()
f, g, h = jacopy.functions("f g h", registry=reg)
X, Y, Z = jacopy.vector_fields("X Y Z")
alpha, beta, gamma = jacopy.forms("alpha beta gamma", degree=1)
from jacopy.research import (
SectionType, GeneralizedSection, Slot, BlockMatrix, Map, Operator, Identity, ZeroOperator,
as_operator, Bracket, AlgebroidData, AxiomSuite, assemble_engine, assembly_report, Scan,
StructureKind, register_structure_kind, register_family, register_family_rule,
antisymmetrize_indices, antisymmetrize, permutation_sign, swap_indices, rename_indices,
WedgeGradedOrderDefinition, WedgeScalarFactorDefinition,
)
from jacopy.research.providers import is_provider, structure_rules, declared_axioms
from jacopy.research.block_matrix import ScaledOperator
from jacopy.research.structure_kinds import unregister
from jacopy.central.algebroid import algebroid, algebroid_engine, DECLARATIONS, LEVELS, jacobiator
from jacopy.central.algebroid.context import AlgebroidBracket
from jacopy.proof.result import prove
from jacopy.core.expr import Integer, Product, Sum, Neg
from jacopy.algebra.derivation import Act
How the objects are set up¶
# (1) An abstract algebroid: only the axioms you choose hold
E = algebroid("E", declare=("right-leibniz",)) # bracket [., .]_E and anchor rho
u, v, w = E.sections("u v w")
# (2) Typed generalized sections of TM + T*M
T = SectionType.generalized_tangent() # TM + Lambda^1 T*M
e1, e2, e3 = T.section(X, alpha), T.section(Y, beta), T.section(Z, gamma)
# (3) The block matrix Psi = (1 theta-sharp; 0 1) for a bivector theta (Poisson package)
from jacopy.packages.poisson import nambu_structure
theta = nambu_structure("θ", p=1)
Psi = BlockMatrix(T, [[1, Map(theta.sharp_vf, "θ♯")], [0, 1]], name="Ψ")
# (4) All the data of a bracket: bracket, anchor, pairing, D and the R-valued Lie action
from jacopy.packages.drinfeld import dorfman_double, canonical_pairing
from jacopy.central.tangent.exterior import d
std = AlgebroidData(
bracket=Bracket.from_components(T, dorfman_double, name="Dorfman"),
anchor=lambda e: e[0], # rho(U + omega) = U
pairing=lambda a, b: (canonical_pairing(*a, *b),), # <e1, e2>, as a tuple of components
D=lambda p: T.section(Integer(0), d(p)), # D<., .> = 0 + d<., .>
lie_R=lambda e, q: (Act(e[0], q),), # L^R_e g = rho(e)(g)
name="Dorfman",
)
suite = AxiomSuite(std, registry=reg, probe=h, structures=(theta,))
# (5) Two operators used below
S_op = Map(theta.sharp_vf, "θ♯")
Lx = Map(lambda x: jacopy.lie_derivative(X)(x), "L_X")
declare=takes a subset of the atomic axioms (DECLARATIONS) or of the ready-made levels (LEVELS, for example"leibniz"= right Leibniz + Jacobi). An axiom that is not declared is never used.A
GeneralizedSectionis not an expression but a tuple of components:tuple(e)gives the components ande[0]is the vector part.jacopy.to_latexis applied component by component.AxiomSuite(..., probe=h): vector-valued identities are tested by evaluating them on the functionh, and \(k\)-form-valued identities on \(k\) fresh vector fields.structures=(theta,): if \(\theta^\sharp\) appears in an expression, its structure must be given explicitly; the engine does not guess the rules of a structure it has not been told about.
Choosing axioms by subset¶
Math |
In code |
Arguments |
Result |
Note |
|---|---|---|---|---|
list of atomic axioms |
|
tuple of names |
The names accepted by |
|
ready-made levels |
|
dict, for example |
A level expands into atomic axioms |
|
algebroid with chosen axioms |
|
name; tuple of axiom or level names |
algebroid |
|
adding a declaration |
|
axiom names |
a new algebroid |
The original is unchanged |
\([u,v]_E\) |
|
sections of E |
\(\left[u,\, v\right]_{E}\) |
Opaque bracket |
\(\rho(u)\) |
|
section of E |
\(\rho\!\left(u\right)\) |
|
\(J(u,v,w)\) |
|
algebroid; three sections |
\(J_{E}\!\left(u,\, v,\, w\right)\) |
The same expression is the same node under every axiom set; the assumptions live in the engine, not in the expression. The right Leibniz rule \([u,fv]_E=\rho(u)(f)\,v+f[u,v]_E\) closes exactly when an axiom set containing it is declared:
def right_leibniz_goal(A):
a, b = A.sections("u v")
return (A.bracket(a, Product(f, b)),
Sum(Product(Act(A.anchor(a), f), b), Product(f, A.bracket(a, b))))
for decl in [(), ("right-leibniz",), ("almost-leibniz",), ("local",)]:
A = algebroid("E", declare=decl)
lhs, rhs = right_leibniz_goal(A)
res = prove(algebroid_engine(A, registry=reg), lhs, rhs, registry=reg)
print(decl, res.status)
El = algebroid("E", declare=("leibniz",))
a1, a2, a3 = El.sections("u v w")
res = prove(algebroid_engine(El, registry=reg), jacobiator(El, a1, a2, a3), jacopy.Zero, registry=reg)
print(res.status, [a.name for a in res.declared])
() RESIDUAL
('right-leibniz',) CLOSED
('almost-leibniz',) CLOSED
('local',) CLOSED
CLOSED ['Leibniz-Jacobi (E): J(u,v,w) = 0']
Typed sections and block matrices¶
Math |
In code |
Arguments |
Result |
Note |
|---|---|---|---|---|
\(TM\oplus T^*M\) |
|
p (default 1) |
|
|
\(TM\oplus\Lambda^2T^*M\oplus\Lambda^5T^*M\) |
|
|
||
your own direct sum |
|
|
a section type |
|
\(X\oplus\alpha\) |
|
components |
section \((X, \alpha)\) |
Same as |
component kind check |
|
expression |
|
|
\(e_1+e_2\) |
|
sections |
\((X + Y, \alpha + \beta)\) |
slot by slot |
\(f\cdot e_1\) |
|
f: function |
\((f \, X, f \, \alpha)\) |
\(C^\infty(M)\)-module structure |
\(\Psi=\begin{pmatrix}1&\theta^\sharp\\0&1\end{pmatrix}\) |
|
type; rows of 0, 1, |
block matrix |
The entry |
\((\Psi e)_i=\sum_j\Psi_{ij}e_j\) |
|
section |
\((X + \theta(\alpha), \alpha)\) |
Same as |
\(\Psi^{-1}=\sum_k(-N)^k\) |
|
|
Derived only for unipotent matrices |
|
is it unipotent? |
|
(a property) |
|
|
\(\Psi\Psi^{-1}\), \(\Psi^2\) |
|
block matrices |
the identity matrix |
|
operator \(\Lambda^1\to TM\) |
|
a function on expressions; a name |
|
|
\(\theta^\sharp\circ\mathcal L_X\) |
|
two operators |
\(\theta(\mathcal{L}_{X}(\beta))\) |
|
\(S+S\), \(-S\), \(S-S\) |
|
operators |
\(\theta(\beta)+\theta(\beta)\), \(-\theta(\beta)\), \(0\) |
|
\(f\cdot S\) |
|
function; operator |
\(f \, \theta(\beta)\) |
|
Checking axioms with AxiomSuite¶
Math |
In code |
Arguments |
Result |
Note |
|---|---|---|---|---|
bracket from a component formula |
|
type; a function |
|
The library’s component brackets have this form |
\([e_1,e_2]_D\) |
|
two sections |
\(([X, Y],\ \mathcal{L}_{X}\beta - \mathcal{L}_{Y}\alpha + d\,\iota_{Y}\alpha)\) |
Dorfman |
\(\rho(e_1)\) |
|
section |
\(X\) |
|
\(\langle e_1,e_2\rangle\) |
|
two sections |
\((\iota_{X}\beta + \iota_{Y}\alpha)\) |
a tuple of components |
\([e_1,fe_2]=f[e_1,e_2]+(\rho(e_1)f)e_2\) |
|
two sections; function |
report: both components |
|
\([e_1,e_2]+[e_2,e_1]=D\langle e_1,e_2\rangle\) |
|
two sections |
|
Needs |
\(\rho[e_1,e_2]=[\rho e_1,\rho e_2]\) |
|
two sections |
|
A residual, if any, is the obstruction |
\(\mathcal L^R_{e_1}\langle e_2,e_3\rangle=\langle[e_1,e_2],e_3\rangle+\langle e_2,[e_1,e_3]\rangle\) |
|
three sections |
|
Needs |
\([e_1,[e_2,e_3]]=[[e_1,e_2],e_3]+[e_2,[e_1,e_3]]\) |
|
three sections; |
|
Can be slow; select components with |
all at once |
|
two sections, a function, optionally a third section |
|
Without |
\([e_1,e_2]_\Psi=\Psi^{-1}[\Psi e_1,\Psi e_2]\) |
|
block matrix |
\(([X + \theta(\alpha), Y + \theta(\beta)] - \theta(\dots),\ \dots)\) |
Only the bracket is twisted |
transport the whole structure |
|
block matrix |
|
\(\rho'=\rho\circ\Psi\), \(\langle\cdot,\cdot\rangle'=\langle\Psi\cdot,\Psi\cdot\rangle\), \(D'=\Psi^{-1}D\) |
Each row of a report is a CheckResult with the fields axiom, component, status,
seconds, steps, residual and note:
rep = suite.run(e1, e2, f)
twisted = std.transport(Psi) # Psi applied to the whole structure
print(rep.all_closed)
print([(r.axiom, r.component, r.status) for r in rep.results])
rep_t = AxiomSuite(twisted, registry=reg, probe=h, structures=(theta,)).run(e1, e2, f)
print(rep_t.all_closed, len(rep_t.results))
True
[('right-Leibniz', 'TM', 'CLOSED'), ('right-Leibniz', 'Λ¹T*M', 'CLOSED'), ('symmetric part', 'TM', 'CLOSED'), ('symmetric part', 'Λ¹T*M', 'CLOSED'), ('anchor morphism', 'ρ on probe', 'CLOSED')]
True 5
The transported Dorfman structure passes the same checks without any assumption on \(\theta\).
assemble_engine: building the engine from the expression¶
assemble_engine looks at the node families that occur in the expressions and adds the
rules they need; assembly_report explains what was added and why.
tw = twisted.bracket(e1, e2)
eng = assemble_engine(*tw, registry=reg, structures=(theta,))
expr = jacopy.wedge(Product(f, alpha), beta)
Math |
In code |
Arguments |
Result |
Note |
|---|---|---|---|---|
node families in an expression |
|
expressions |
|
|
engine with the required rules |
|
expressions; registry; structures; |
|
|
explanation |
|
engine |
list of lines |
Which rule was added and why |
normal form |
|
engine, expression, registry |
\(d\,\theta(\alpha,\beta) + d\langle \beta, X \rangle + \iota_{X}d\beta - \iota_{Y}d\alpha + \iota_{\theta(\alpha)}d\beta - \iota_{\theta(\beta)}d\alpha\) |
|
declaring the Poisson condition |
|
engine |
The report states that the fundamental identity is declared |
|
\((f\alpha)\wedge\beta=f(\alpha\wedge\beta)\) |
|
\(\left(\alpha \wedge \beta\right) \, f\) |
Rule: wedge scalar pull-out |
|
\(\beta\wedge\alpha=-\alpha\wedge\beta\) |
|
\(-\alpha \wedge \beta\) |
Only in concrete degrees |
|
adding your own rule |
|
|
engine |
|
for line in assembly_report(eng):
print(line)
scanned 2 expression(s): Scan(families=['act', 'exterior_derivative', 'interior', 'lie_bracket', 'lie_derivative', 'nambu_sharp'], sharps=['θ'])
base: tilde-calculus engine hosted by θ (Cartan calculus + Koszul/tilde rules) — no fundamental-identity declaration
+ zero product: 0·x = 0 (slot-reachable) [always: zero products inside operator slots]
+ sharp-slot alternating normalization: θ♯(slot) with the slot's MultiEvals in canonical order [sharp slots present (alternation must reach inside them)]
Writing your own rules and axioms¶
Scenario: a bare bundle \(A\) with a bracket and an anchor and no axioms at all. You write two axioms yourself (right Leibniz and antisymmetry), choose which of them are declared through a structure class of your own, and ask for the left Leibniz rule
A Definition has two methods: matches(e) (does the rule apply to this node?) and
rewrite(e) (what replaces it?). role = "assumption" marks the rule as an assumption, and
anchor names the node class the rule looks at.
from jacopy.central.calculus.scalars import is_scalar_function
A = algebroid("A") # bare bundle: bracket and anchor, no axioms
p, q = A.sections("u v")
def split_scalar(x): # x = g*b -> (g, b)
if isinstance(x, Product) and len(x.children) == 2 and is_scalar_function(x.children[0], reg):
return x.children
return None
class RightLeibniz(jacopy.Definition):
name = "right Leibniz: [a, g·b] = ρ(a)(g)·b + g·[a, b]"
role = "assumption"
anchor = AlgebroidBracket
def matches(self, e):
return isinstance(e, AlgebroidBracket) and split_scalar(e.v) is not None
def rewrite(self, e):
g_, b = split_scalar(e.v)
return Sum(Product(Act(A.anchor(e.u), g_), b), Product(g_, A.bracket(e.u, b)))
class Antisymmetry(jacopy.Definition):
name = "antisymmetry: [a, b] = −[b, a]"
role = "assumption"
anchor = AlgebroidBracket
@staticmethod
def order(x): # a fixed order: products to the right
return (isinstance(x, Product), x._repr_inner())
def matches(self, e):
return isinstance(e, AlgebroidBracket) and self.order(e.u) > self.order(e.v)
def rewrite(self, e):
return Neg(A.bracket(e.v, e.u))
class MyStructure: # records which axioms are declared
AXIOMS = {"right-leibniz": RightLeibniz, "antisymmetry": Antisymmetry}
def __init__(self, declared=()):
self.name = "L"
self.declarations = frozenset(declared)
def declares(self, k):
return k in self.declarations
def with_declarations(self, *k):
return MyStructure(self.declarations | set(k))
def engine_rules(self, registry=None, *, phase=None):
rules = []
for k in sorted(self.declarations):
r = self.AXIOMS[k]()
r.owner = self # the structure owns its axiom
rules.append(r)
return rules
def __eq__(self, o):
return isinstance(o, MyStructure) and o.declarations == self.declarations
def __hash__(self):
return hash(("MyStructure", self.declarations))
def __repr__(self):
return f"MyStructure({sorted(self.declarations)})"
lhs = A.bracket(Product(f, p), q) # [f u, v]
rhs = Sum(Product(f, A.bracket(p, q)), Neg(Product(Act(A.anchor(q), f), p))) # f[u,v] - rho(v)(f) u
def prove_with(declared, lhs=lhs, rhs=rhs):
S = MyStructure(declared)
engine = algebroid_engine(A, registry=reg) # definitional rules only
for rule in S.engine_rules(reg):
engine.register(rule) # plus the declared axioms
return S, engine, prove(engine, lhs, rhs, registry=reg)
for declared in [(), ("right-leibniz",), ("antisymmetry",), ("right-leibniz", "antisymmetry")]:
res = prove_with(declared)[2]
print(declared, res.status, len(res.chain.steps) if res.chain else 0)
wrong = Product(f, A.bracket(p, q)) # the false identity [f u, v] = f [u, v]
res_wrong = prove_with(("right-leibniz", "antisymmetry"), lhs, wrong)[2]
print("false identity:", res_wrong.status, "| residual:", jacopy.to_ascii(res_wrong.residual))
() RESIDUAL 1
('right-leibniz',) RESIDUAL 1
('antisymmetry',) RESIDUAL 2
('right-leibniz', 'antisymmetry') CLOSED 4
false identity: RESIDUAL | residual: -ρ(v)(f) * u
Of the four axiom sets, the identity closes only when both axioms are declared. With right Leibniz alone the rule never fires, because \(f\) sits in the first slot and the rule looks at the second. The false identity does not close even with both axioms, and its residual is exactly the missing term \(-\rho(v)(f)\,u\).
Registering your own structure kind¶
MyStructure implements the “provider” protocol: name, declarations, declares,
with_declarations and engine_rules. Once its kind is registered, assemble_engine sets
up the engine by itself.
class MyKind(StructureKind):
name = "my-structure"
host_includes_rules = False
def accepts(self, s): # which objects this kind handles
return isinstance(s, MyStructure)
def key(self, s): # the structure's key
return s.name
def host_engine(self, s, registry): # base engine when s is the first structure
return algebroid_engine(A, registry=registry)
def host_report(self, s): # what the report says about the base
return f"base: algebroid engine of A, first structure {s.name} [{self.name}]"
kind = register_structure_kind(MyKind())
S_full = MyStructure(("right-leibniz", "antisymmetry"))
res = prove(assemble_engine(lhs, rhs, registry=reg, structures=(S_full,)), lhs, rhs, registry=reg)
print(res.status)
CLOSED
Math |
In code |
Arguments |
Result |
Note |
|---|---|---|---|---|
does it follow the protocol? |
|
object |
|
|
the structure’s rules |
|
structure, registry |
the rule objects |
Only the declared ones |
who assumes what? |
|
structures |
|
For reports |
base engine |
|
structure, registry |
|
If you change |
A rule can also be attached to a new node family instead of a structure:
class ZeroBracketDefinition(jacopy.Definition): # [a, 0] = 0
name = "zero slot: [a, 0] = 0"
anchor = AlgebroidBracket
def matches(self, e):
return isinstance(e, AlgebroidBracket) and e.v == Integer(0)
def rewrite(self, e):
return Integer(0)
fam = register_family(AlgebroidBracket, "user_bracket")
frule = register_family_rule("user_bracket", lambda r: ZeroBracketDefinition(),
"user brackets present", order=90)
zb = A.bracket(p, Integer(0))
print(Scan([zb]))
print(prove(assemble_engine(zb, registry=reg, structures=(S_full,)), zb, Integer(0), registry=reg).status)
Scan(families=['user_bracket'], sharps=[])
CLOSED
Family rules belong to no structure, so supply axioms through a structure’s engine_rules,
not as family rules; only then does the result show which axiom of which structure was
used. Registrations are global for the whole Python process; remove them with unregister
when you are done:
for entry in (frule, fam, kind):
unregister(entry)
Index antisymmetrization¶
The component \(\theta^{ab}\) is the evaluation of \(\theta\) on two coframe fields:
from jacopy.central.objects import frame
from jacopy.core.multi_eval import MultiEval
from jacopy.algorithms.simplify import simplify
co = frame().dual()
tab = MultiEval(theta.pi, co.field("a"), co.field("b"), alternating=True, slot_kind="covector")
tcd = MultiEval(theta.pi, co.field("c"), co.field("d"), alternating=True, slot_kind="covector")
T_ab = antisymmetrize_indices(tab, ("a", "b"))
Math |
In code |
Arguments |
Result |
Note |
|---|---|---|---|---|
\(T^{[a_1\dots a_n]}=\frac1{n!}\sum_\sigma \operatorname{sgn}\sigma\,T^{a_{\sigma(1)}\dots}\) |
|
expression; index names |
\(\frac{1}{6}\big(\theta(e^{a},e^{b})\,\theta(e^{c},e^{d}) - \theta(e^{a},e^{c})\,\theta(e^{b},e^{d}) - \dots\big)\) |
Six signed terms; \(d\) stays free |
unweighted \(\sum_\sigma \operatorname{sgn}\sigma\,T^{\dots}\) |
|
expression; names; |
\(\theta(e^{a},e^{b}) - \theta(e^{b},e^{a})\) |
|
\(\operatorname{sgn}\sigma\) |
|
tuple of positions |
|
|
\(a\leftrightarrow b\) |
|
expression; two names |
\(\theta\!\left(e^{b},\, e^{a}\right)\) |
|
simultaneous renaming |
|
expression; dict |
\(\theta\!\left(e^{c},\, e^{d}\right)\) |
Names do not clash |
\(T^{[ab]}+T^{[ba]}=0\) |
|
\(0\) |
Reading the results¶
prove(engine, lhs, rhs, registry=reg) returns a ProofResult. The examples use the closed
proof with both axioms (res2) and the residual with right Leibniz alone (res1).
from jacopy.proof.diagnostics import diagnose
S2, eng2, res2 = prove_with(("right-leibniz", "antisymmetry"))
S1, eng1, res1 = prove_with(("right-leibniz",))
print(res2.status, res2.closed)
print([s.rule for s in res2.chain.steps])
print(sorted({a.kind for a in res2.requires}), len(res2.declared))
print(res1.residual is not None, res2.residual)
print(diagnose(res1.residual, registry=reg, engine=eng1).hints)
CLOSED True
['antisymmetry: [a, b] = −[b, a]', 'right Leibniz: [a, g·b] = ρ(a)(g)·b + g·[a, b]', 'antisymmetry: [a, b] = −[b, a]', 'simplify']
['declared', 'registry', 'structure'] 2
True None
[]
What is read |
In code |
Note |
|---|---|---|
status |
|
|
proof steps |
|
Each step carries the rule that justifies it |
assumptions used |
|
Records with |
only the declared axioms |
|
|
residual term |
|
An expression for |
summary text |
|
Status, goal, assumption lines and the step budget |
source of normalization |
|
|
hints for a residual |
|
Each hint has |
Numerical check. The oracle has no concrete model for axioms you wrote
yourself, so it does not decide here; it reports UNSUPPORTED instead of AGREE:
from jacopy.oracle import check_equal
rep = check_equal(lhs, rhs, registry=reg, owners=(S2,), requires=res2.requires, chain=res2.chain)
print(rep.verdict, "|", rep.detail)
UNSUPPORTED | a declared structure axiom has no F1 model
Rules the engine applies automatically¶
assemble_engine adds these rules itself when it sees the relevant nodes; they appear in the
report lines. The research layer has no prove_* builders: it tests brackets
(AxiomSuite) or sets up an engine for the identity in question (assemble_engine).
Rule |
Mathematical counterpart |
|---|---|
|
\(0\cdot x=0\), also inside operator slots (in every engine) |
|
canonical order via \(\alpha\wedge\beta=(-1)^{\lvert\alpha\rvert\lvert\beta\rvert}\beta\wedge\alpha\); only in concrete degrees (when wedges are present) |
|
\((f\alpha)\wedge\beta=f\,(\alpha\wedge\beta)\) (when wedges are present) |