Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Balanced algebras: partial algebras, ideals, units, associating and gregarious elements

Definition
BalancedAlgebra_core

by LG · Sep 14, 2026 · Mathlib 0df444a (Lean v4.33.1)

algebracategory-theoryidealspartial-algebra

This file fixes the vocabulary of A. Winkler's Ideals in Balanced Algebras and the Genesis of Mathematics (§1, §4, §4.2).

An algebra on a type AAA is a partial binary operation on AAA: a rule that assigns a value a⋅b∈Aa\cdot b\in Aa⋅b∈A to some, not necessarily all, pairs (a,b)(a,b)(a,b). It is represented by a total function A→A→Option AA\to A\to\mathrm{Option}\,AA→A→OptionA, the value none\mathrm{none}none recording that the product is undefined; a⋅b↓a\cdot b\downarrowa⋅b↓ abbreviates "a⋅ba\cdot ba⋅b is defined". Two derived operations name the bracketings of a triple product, (a⋅b)⋅c(a\cdot b)\cdot c(a⋅b)⋅c and a⋅(b⋅c)a\cdot(b\cdot c)a⋅(b⋅c), each undefined as soon as either of its two steps is.

On top of this the file defines, for a subset B⊆AB\subseteq AB⊆A and elements of AAA:

  1. left ideal (a⋅b∈Ba\cdot b\in Ba⋅b∈B whenever b∈Bb\in Bb∈B and the product is defined), right ideal (dually), and subalgebra;
  2. the right orbit aAaAaA and the left orbit AaAaAa;
  3. balance: (a⋅b)⋅c(a\cdot b)\cdot c(a⋅b)⋅c is defined if and only if a⋅(b⋅c)a\cdot(b\cdot c)a⋅(b⋅c) is, for all a,b,ca,b,ca,b,c;
  4. left unit (u⋅a=au\cdot a=au⋅a=a whenever defined), right unit, source (a left unit uuu with a⋅ua\cdot ua⋅u defined only for a=ua=ua=u), sink (dual);
  5. associating element ((ab)c(ab)c(ab)c defined   ⟺  \iff⟺ a(bc)a(bc)a(bc) defined, with equal values when both are defined), and association (all elements associating);
  6. gregarious element (a⋅b↓a\cdot b\downarrowa⋅b↓ and b⋅c↓b\cdot c\downarrowb⋅c↓ together imply that at least one of the two bracketings of abcabcabc is defined);
  7. left cancellable element (b⋅x=b⋅yb\cdot x=b\cdot yb⋅x=b⋅y, both defined, forces x=yx=yx=y).

Two structural lemmas unfold the triple products: a bracketed product equals some q\mathrm{some}\ qsome q exactly when its two steps are defined and compose to qqq.

This is the model on which the mission's goal theorem and all its milestones are stated; it is reusable for any development about partial magmas, where definedness rather than equality carries the content.

Definition code
import Mathlib

/-!
# Balanced algebras: the basic vocabulary

Formalization of the basic notions of

  Andrew Winkler, *Ideals in Balanced Algebras and the Genesis of Mathematics*,
  manuscript, March 20, 2020, §1 (Algebras), §4 (Associators and Associations),
  §4.1 (Principal Ideals), §4.2 (The Gregarious Ideal).

An *algebra* on a type `A` is a partial binary operation on `A`: an arrow with codomain
`A` whose domain is a subobject of `A × A`.  Here it is modelled by a function
`op : A → A → Option A`, where `op a b = none` means that `a · b` is not defined.
-/

namespace BalancedAlgebra

universe u

/-- An *algebra* on `A` (a partial magma): a binary operation defined on a subset of
`A × A`.  `op a b = none` means the product `a · b` is undefined. -/
structure PartialAlgebra (A : Type u) where
  /-- The partial product. -/
  op : A → A → Option A

namespace PartialAlgebra

variable {A : Type u}

/-- A value of `Option A` is *defined* when it is of the form `some x`. -/
def IsDef (o : Option A) : Prop := ∃ x : A, o = some x

/-- `a · b` is defined. -/
def IsDefined (P : PartialAlgebra A) (a b : A) : Prop := IsDef (P.op a b)

/-- The left-bracketed triple product `(a · b) · c`, undefined if either step is. -/
def lprod (P : PartialAlgebra A) (a b c : A) : Option A :=
  (P.op a b).bind fun x => P.op x c

/-- The right-bracketed triple product `a · (b · c)`, undefined if either step is. -/
def rprod (P : PartialAlgebra A) (a b c : A) : Option A :=
  (P.op b c).bind fun y => P.op a y

@[simp] theorem lprod_eq_some {P : PartialAlgebra A} {a b c q : A} :
    P.lprod a b c = some q ↔ ∃ x, P.op a b = some x ∧ P.op x c = some q := by
  unfold lprod
  cases h : P.op a b with
  | none => simp
  | some x => simp

@[simp] theorem rprod_eq_some {P : PartialAlgebra A} {a b c q : A} :
    P.rprod a b c = some q ↔ ∃ y, P.op b c = some y ∧ P.op a y = some q := by
  unfold rprod
  cases h : P.op b c with
  | none => simp
  | some y => simp

/-- `B` is a *left ideal*: `A · B ⊆ B`. -/
def LeftIdeal (P : PartialAlgebra A) (B : Set A) : Prop :=
  ∀ a b c : A, b ∈ B → P.op a b = some c → c ∈ B

/-- `B` is a *right ideal*: `B · A ⊆ B`. -/
def RightIdeal (P : PartialAlgebra A) (B : Set A) : Prop :=
  ∀ a b c : A, a ∈ B → P.op a b = some c → c ∈ B

/-- `B` is a *subalgebra*: `B · B ⊆ B`. -/
def IsSubalgebra (P : PartialAlgebra A) (B : Set A) : Prop :=
  ∀ a b c : A, a ∈ B → b ∈ B → P.op a b = some c → c ∈ B

/-- The *right orbit* `a · A` of `a`. -/
def rightOrbit (P : PartialAlgebra A) (a : A) : Set A := {c | ∃ b : A, P.op a b = some c}

/-- The *left orbit* `A · a` of `a`. -/
def leftOrbit (P : PartialAlgebra A) (a : A) : Set A := {c | ∃ b : A, P.op b a = some c}

/-- `P` is *balanced*: `(a · b) · c` is defined if and only if `a · (b · c)` is. -/
def Balanced (P : PartialAlgebra A) : Prop :=
  ∀ a b c : A, IsDef (P.lprod a b c) ↔ IsDef (P.rprod a b c)

/-- `u` is a *left unit*: whenever `u · a` is defined it equals `a`. -/
def IsLeftUnit (P : PartialAlgebra A) (u : A) : Prop :=
  ∀ a c : A, P.op u a = some c → c = a

/-- `v` is a *right unit*: whenever `a · v` is defined it equals `a`. -/
def IsRightUnit (P : PartialAlgebra A) (v : A) : Prop :=
  ∀ a c : A, P.op a v = some c → c = a

/-- `u` is a *source*: a left unit such that `a · u` is defined only for `a = u`. -/
def IsSource (P : PartialAlgebra A) (u : A) : Prop :=
  P.IsLeftUnit u ∧ ∀ a : A, P.IsDefined a u → a = u

/-- `v` is a *sink*: a right unit such that `v · b` is defined only for `b = v`. -/
def IsSink (P : PartialAlgebra A) (v : A) : Prop :=
  P.IsRightUnit v ∧ ∀ b : A, P.IsDefined v b → b = v

/-- `b` is *associating*: for all `a`, `c`, the product `(a · b) · c` is defined iff
`a · (b · c)` is, and whenever both are defined they are equal. -/
def Associating (P : PartialAlgebra A) (b : A) : Prop :=
  ∀ a c : A,
    (IsDef (P.lprod a b c) ↔ IsDef (P.rprod a b c)) ∧
      ∀ x y : A, P.lprod a b c = some x → P.rprod a b c = some y → x = y

/-- `P` is an *association*: every element is associating. -/
def IsAssociation (P : PartialAlgebra A) : Prop := ∀ b : A, P.Associating b

/-- `b` is *gregarious*: whenever `a · b` and `b · c` are both defined, at least one of
`(a · b) · c` and `a · (b · c)` is defined. -/
def Gregarious (P : PartialAlgebra A) (b : A) : Prop :=
  ∀ a c : A, P.IsDefined a b → P.IsDefined b c →
    IsDef (P.lprod a b c) ∨ IsDef (P.rprod a b c)

/-- `b` is *left cancellable*: `b · x = b · y` (both defined) forces `x = y`. -/
def LeftCancellable (P : PartialAlgebra A) (b : A) : Prop :=
  ∀ x y c : A, P.op b x = some c → P.op b y = some c → x = y

end PartialAlgebra

end BalancedAlgebra
Source
Andrew Winkler, *Ideals in Balanced Algebras and the Genesis of Mathematics*, manuscript dated 20 March 2020, §1 (pp. 1–3), §4 (p. 6), §4.2 (pp. 6–7)
Read-back

What the Lean code literally says, in plain math · Aristotle (Harmonic)

Non-blind read-back — not independent testimony. This read-back was written by the same agent that drafted the Lean statement it describes, at the explicit instruction of the proposal owner. It was not produced blind by an independent auditor, so it cannot be used as independent evidence that the formalization is faithful; a reviewer comparing it against the source should keep in mind that both texts come from the same author.

This file introduces a single carrier notion and a list of predicates on it.

The carrier. A partial algebra on a type AAA is a structure with one field: a function op:A→A→Option A\mathrm{op}:A\to A\to\mathrm{Option}\,Aop:A→A→OptionA. Nothing is assumed about it. For o:Option Ao:\mathrm{Option}\,Ao:OptionA, the predicate IsDef(o)\mathrm{IsDef}(o)IsDef(o) asserts ∃x∈A, o=some x\exists x\in A,\ o=\mathrm{some}\ x∃x∈A, o=some x, and IsDefined(a,b)\mathrm{IsDefined}(a,b)IsDefined(a,b) abbreviates IsDef(op(a,b))\mathrm{IsDef}(\mathrm{op}(a,b))IsDef(op(a,b)). Since Option\mathrm{Option}Option has exactly the values none\mathrm{none}none and some x\mathrm{some}\ xsome x, IsDef(o)\mathrm{IsDef}(o)IsDef(o) says precisely that o≠noneo\neq\mathrm{none}o=none.

Triple products. lprod(a,b,c)\mathrm{lprod}(a,b,c)lprod(a,b,c) is defined as: evaluate op(a,b)\mathrm{op}(a,b)op(a,b); if it is none\mathrm{none}none, the result is none\mathrm{none}none; if it is some x\mathrm{some}\ xsome x, the result is op(x,c)\mathrm{op}(x,c)op(x,c). Symmetrically rprod(a,b,c)\mathrm{rprod}(a,b,c)rprod(a,b,c) evaluates op(b,c)\mathrm{op}(b,c)op(b,c) first and then applies op(a,−)\mathrm{op}(a,-)op(a,−) to the outcome. Two lemmas state the unfoldings: lprod(a,b,c)=some q\mathrm{lprod}(a,b,c)=\mathrm{some}\ qlprod(a,b,c)=some q holds if and only if there exists xxx with op(a,b)=some x\mathrm{op}(a,b)=\mathrm{some}\ xop(a,b)=some x and op(x,c)=some q\mathrm{op}(x,c)=\mathrm{some}\ qop(x,c)=some q, and likewise for rprod\mathrm{rprod}rprod with the middle witness on the other side.

Predicates on subsets. For BBB an arbitrary subset of AAA (possibly empty, possibly all of AAA): LeftIdeal(B)\mathrm{LeftIdeal}(B)LeftIdeal(B) says that for all a,b,ca,b,ca,b,c, if b∈Bb\in Bb∈B and op(a,b)=some c\mathrm{op}(a,b)=\mathrm{some}\ cop(a,b)=some c then c∈Bc\in Bc∈B; RightIdeal(B)\mathrm{RightIdeal}(B)RightIdeal(B) says that for all a,b,ca,b,ca,b,c, if a∈Ba\in Ba∈B and op(a,b)=some c\mathrm{op}(a,b)=\mathrm{some}\ cop(a,b)=some c then c∈Bc\in Bc∈B — note that in this second one the membership hypothesis is on the left factor of the product; IsSubalgebra(B)\mathrm{IsSubalgebra}(B)IsSubalgebra(B) requires both factors in BBB. All three are vacuously true for B=∅B=\emptysetB=∅.

Orbits. rightOrbit(a)={c:∃b, op(a,b)=some c}\mathrm{rightOrbit}(a)=\{c:\exists b,\ \mathrm{op}(a,b)=\mathrm{some}\ c\}rightOrbit(a)={c:∃b, op(a,b)=some c} and leftOrbit(a)={c:∃b, op(b,a)=some c}\mathrm{leftOrbit}(a)=\{c:\exists b,\ \mathrm{op}(b,a)=\mathrm{some}\ c\}leftOrbit(a)={c:∃b, op(b,a)=some c}. Both may be empty.

Balance. Balanced\mathrm{Balanced}Balanced asserts: for all a,b,ca,b,ca,b,c, IsDef(lprod(a,b,c))  ⟺  IsDef(rprod(a,b,c))\mathrm{IsDef}(\mathrm{lprod}(a,b,c))\iff\mathrm{IsDef}(\mathrm{rprod}(a,b,c))IsDef(lprod(a,b,c))⟺IsDef(rprod(a,b,c)). It constrains definedness only, never values.

Units and their extremes. uuu is a left unit if for all a,ca,ca,c, op(u,a)=some c\mathrm{op}(u,a)=\mathrm{some}\ cop(u,a)=some c implies c=ac=ac=a; vvv is a right unit if op(a,v)=some c\mathrm{op}(a,v)=\mathrm{some}\ cop(a,v)=some c implies c=ac=ac=a. These are conditional: an element with no defined products at all is both. uuu is a source if it is a left unit and, for every aaa with a⋅ua\cdot ua⋅u defined, a=ua=ua=u; vvv is a sink if it is a right unit and, for every bbb with v⋅bv\cdot bv⋅b defined, b=vb=vb=v.

Associating and gregarious. bbb is associating if for all a,ca,ca,c two things hold: IsDef(lprod(a,b,c))  ⟺  IsDef(rprod(a,b,c))\mathrm{IsDef}(\mathrm{lprod}(a,b,c))\iff\mathrm{IsDef}(\mathrm{rprod}(a,b,c))IsDef(lprod(a,b,c))⟺IsDef(rprod(a,b,c)), and for all x,yx,yx,y, lprod(a,b,c)=some x\mathrm{lprod}(a,b,c)=\mathrm{some}\ xlprod(a,b,c)=some x together with rprod(a,b,c)=some y\mathrm{rprod}(a,b,c)=\mathrm{some}\ yrprod(a,b,c)=some y implies x=yx=yx=y. An algebra is an association if every element of AAA is associating. bbb is gregarious if for all a,ca,ca,c: IsDefined(a,b)\mathrm{IsDefined}(a,b)IsDefined(a,b) and IsDefined(b,c)\mathrm{IsDefined}(b,c)IsDefined(b,c) imply IsDef(lprod(a,b,c)) ∨ IsDef(rprod(a,b,c))\mathrm{IsDef}(\mathrm{lprod}(a,b,c))\ \lor\ \mathrm{IsDef}(\mathrm{rprod}(a,b,c))IsDef(lprod(a,b,c)) ∨ IsDef(rprod(a,b,c)) — an inclusive disjunction about definedness only, with no claim that the two values agree. An element that is never a middle factor of a defined pair is gregarious vacuously.

Cancellation. bbb is left cancellable if for all x,y,cx,y,cx,y,c: op(b,x)=some c\mathrm{op}(b,x)=\mathrm{some}\ cop(b,x)=some c and op(b,y)=some c\mathrm{op}(b,y)=\mathrm{some}\ cop(b,y)=some c imply x=yx=yx=y. Only products that are defined and equal to the same element are compared; an element with no defined products is left cancellable.

Every notion above is stated for an arbitrary type AAA, with no finiteness, decidability or nonemptiness assumption; over the empty type all of them hold trivially.

Human review
  • Endorsed by Shuze Chen · Sep 14, 2026

  • Endorsed by LG · Sep 14, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me