Primary arithmetic: finite forms, transformations, and value
DefinitionLawsOfForm_ArithmeticA form is a finite raw expression built from blank, crossing one expression, and placing two expressions beside each other. Constructor equality is syntactic; structural rearrangements are recorded by a separate relation. Marked is a crossing around blank. Normal selects blank for false and marked for true. The evaluator assigns false to blank, negates under crossing, and takes Boolean disjunction under placement.
ArrangementEq is the least equivalence relation identifying associative and commutative placements and blank as a unit, preserved by crossing and either argument of placement. These are the encoding's spatial conventions. It has no arithmetic contraction rule.
Simplifies is the least reflexive, transitive relation containing ArrangementEq and the two directed initials: two empty marks beside each other simplify to one, and a crossing around an empty mark simplifies to blank. It is preserved by crossing and placement in either argument. It therefore records finite contractions in arbitrary contexts modulo structural rearrangement. Its order initial is only the empty double mark; no arbitrary-content double-crossing rule is assumed.
Calculates is the least symmetric, transitive relation containing Simplifies. Reflexivity is inherited from Simplifies, and reversing a simplification permits expansion. These relations are defined by rules, independently of the evaluator. The syntax includes blank and arbitrary finite nesting, with no atom variables, re-entry, infinite expressions, or extra assumptions.
import Mathlib.Data.Bool.Basic
set_option autoImplicit false
namespace LawsOfForm
inductive Form where
| blank : Form
| cross : Form → Form
| beside : Form → Form → Form
deriving DecidableEq, Repr
def marked : Form := Form.cross Form.blank
def normal : Bool → Form
| false => Form.blank
| true => marked
def value : Form → Bool
| .blank => false
| .cross a => !(value a)
| .beside a b => value a || value b
inductive ArrangementEq : Form → Form → Prop where
| refl (a : Form) : ArrangementEq a a
| symm {a b : Form} : ArrangementEq a b → ArrangementEq b a
| trans {a b c : Form} : ArrangementEq a b → ArrangementEq b c → ArrangementEq a c
| assoc (a b c : Form) : ArrangementEq (.beside (.beside a b) c) (.beside a (.beside b c))
| comm (a b : Form) : ArrangementEq (.beside a b) (.beside b a)
| unit (a : Form) : ArrangementEq (.beside .blank a) a
| cross {a b : Form} : ArrangementEq a b → ArrangementEq (.cross a) (.cross b)
| left {a b : Form} (c : Form) : ArrangementEq a b → ArrangementEq (.beside a c) (.beside b c)
| right (a : Form) {b c : Form} : ArrangementEq b c → ArrangementEq (.beside a b) (.beside a c)
inductive Simplifies : Form → Form → Prop where
| refl (a : Form) : Simplifies a a
| trans {a b c : Form} : Simplifies a b → Simplifies b c → Simplifies a c
| arrangement {a b : Form} : ArrangementEq a b → Simplifies a b
| number : Simplifies (.beside marked marked) marked
| order : Simplifies (.cross marked) .blank
| cross {a b : Form} : Simplifies a b → Simplifies (.cross a) (.cross b)
| left {a b : Form} (c : Form) : Simplifies a b → Simplifies (.beside a c) (.beside b c)
| right (a : Form) {b c : Form} : Simplifies b c → Simplifies (.beside a b) (.beside a c)
inductive Calculates : Form → Form → Prop where
| simplify {a b : Form} : Simplifies a b → Calculates a b
| symm {a b : Form} : Calculates a b → Calculates b a
| trans {a b c : Form} : Calculates a b → Calculates b c → Calculates a c
end LawsOfForm
Read-back
What the Lean code literally says, in plain math · Codex (GPT-6)
Form. A form is a finite formal expression constructed in exactly one of three ways: the blank form ; a crossed form for any form ; or an ordered beside form for any forms . These constructors are distinct, and equality of expressions with the same constructor requires equality of their corresponding arguments. In particular, blank is itself a form, either argument of a beside form may be blank, a crossing may enclose blank, and any of these constructions may be nested finitely many times. Structural equality of forms is decidable, and a representation of each form is provided.
marked. Among the finite formal expressions generated by a blank form , a unary constructor , and an ordered binary constructor , the distinguished form called marked is defined to be exactly , a crossing whose argument is blank.
normal. Let forms be finite formal expressions generated by a blank form , a unary constructor , and an ordered binary constructor . The function from Boolean values to forms called normal sends false to and true to ; these are its two cases and cover every Boolean input.
value. Let forms be finite formal expressions generated by a blank form , a unary constructor , and an ordered binary constructor . The Boolean value of every form is defined recursively by , for every form , and for every pair of forms . Here negation swaps true and false, and the disjunction is inclusive: a beside form has value false exactly when both argument values are false, and has value true in each of the other three Boolean cases, including when both argument values are true. The recursion applies to all forms, including blank arguments and arbitrarily deeply but finitely nested crossings and beside forms.
ArrangementEq. Let forms be finite formal expressions generated by a blank form , a unary constructor , and an ordered binary constructor . The relation , called arrangement equality, is the least relation on forms generated by the following rules, with every variable ranging over all forms, including blank: for every ; implies ; and imply ; for every ; for every ; for every ; implies ; for every , implies ; and for every , implies . Being the least such relation means that its instances are exactly those obtainable by finitely applying these rules.
Simplifies. Let forms be finite formal expressions generated by a blank form , a unary constructor , and an ordered binary constructor , and let every variable below range over all such forms, including blank. Define to be the least relation containing , , , and for every indicated choice of forms, and closed under reversal, composition, and the rules that implies and for every , while implies for every . The relation , called simplifies, is the least relation generated by eight rules: for every ; and imply ; implies ; ; ; implies ; for every , implies ; and for every , implies . Both least relations consist exactly of instances obtained by finitely applying their respective rules; the reflexive rule permits a form to simplify to itself without any change, and the two displayed specific simplifications apply to precisely the indicated expressions, with marked expanded as .
Calculates. Let forms be finite formal expressions generated by a blank form , a unary constructor , and an ordered binary constructor , and let every variable below range over all such forms, including blank. Let be the least relation containing , , , and for every indicated choice of forms, closed under reversal and composition, and closed under , for every , and for every . Let be the least relation containing every pair in , every identity pair , and the two pairs and , and closed under composition, , for every , and for every . The relation , called calculates, is the least relation generated by three rules: implies ; implies ; and together with implies . Each least relation consists exactly of instances obtainable through finitely many applications of its rules. In particular, the identity simplifications supply for every form, including blank, and reversal applies to every calculation obtained from a simplification or from the other calculation rules.