1-- Restrict operation graphs to closed subcarriers.2-- Part of Cumulus, the Grace17 mathematics library.3-- Copyright (c) 2026 Grant Passmore.4-- Released under the Apache License 2.0. See LICENSE in the repository root.5-- Authors: Grant Passmore67module Grace.Cumulus.Algebra.Restriction8import Ring.Core9import Set.Function1011predicate ClosedBinary (S op : Set) :=∀ x ∈ S, ∀ y ∈ S, op(x, y) ∈ S12predicate ClosedUnary (S op : Set) :=∀ x ∈ S, op(x) ∈ S1314theorem ClosedBinary.mem (S op x y : Set)15requires closed : ClosedBinary(S, op)16requires hx : x ∈ S17requires hy : y ∈ S18shows op(x, y) ∈ S19proof20exact closed with x, hx, y, hy2122theorem ClosedUnary.mem (S op x : Set)23requires closed : ClosedUnary(S, op)24requires hx : x ∈ S25shows op(x) ∈ S26proof27exact closed with x, hx2829theorem restrictBinary.function (A S op : Set)30requires function : IsMagma(A, op)31requires subset : S ⊆ A32requires closed : ClosedBinary(S, op)33shows restrict(op, S × S) : S × S → S34proof35have bounded := product.monotone with subset, subset36have values : ∀ p ∈ S × S, op(p) ∈ S37intros p hp38obtain⟨bound, x, hx, y, hy, shape⟩:= product.membership.forward with hp39have output := ClosedBinary.mem with hx, hy40unfold call2 at output41 rwa shape42exact restrict.function at op, A × A, A, S × S, S with*4344theorem restrictBinary.value (A S op x y : Set)45requires function : IsMagma(A, op)46requires subset : S ⊆ A47requires closed : ClosedBinary(S, op)48requires hx : x ∈ S49requires hy : y ∈ S50shows (restrict(op, S × S))(x, y) = op(x, y)51proof52have bounded := product.monotone with subset, subset53have values : ∀ p ∈ S × S, op(p) ∈ S54intros p hp55obtain⟨bound, u, hu, v, hv, shape⟩:= product.membership.forward with hp56have output := ClosedBinary.mem with hu, hv57unfold call2 at output58 rwa shape59have pair := product.pair at x, y, S, S with*60unfold call261exact restrict.apply at op, A × A, A, S × S, S, (x, y) with*6263-- Agreement of operation graphs does not require closure of the smaller carrier.64theorem restrictBinary.value_on_subset (A S op x y : Set)65requires function : IsMagma(A, op)66requires subset : S ⊆ A67requires hx : x ∈ S68requires hy : y ∈ S69shows (restrict(op, S × S))(x, y) = op(x, y)70proof71have bounded := product.monotone with subset, subset72unfold IsMagma at function73have values : ∀ p ∈ S × S, op(p) ∈ A74intros p hp75have member : p ∈ A × A bysimp [Subset]76exact FunctionBetween.apply_closed with function, member77have pair := product.pair at x, y, S, S with*78unfold call279exact restrict.apply with*8081theorem restrictUnary.function (A S op : Set)82requires function : op : A → A83requires subset : S ⊆ A84requires closed : ClosedUnary(S, op)85shows restrict(op, S) : S → S86proof87have values : ∀ x ∈ S, op(x) ∈ S88intros x hx89exact ClosedUnary.mem with*90exact restrict.function with*9192theorem restrictUnary.value (A S op x : Set)93requires function : op : A → A94requires subset : S ⊆ A95requires closed : ClosedUnary(S, op)96requires hx : x ∈ S97shows (restrict(op, S))(x) = op(x)98proof99have values : ∀ y ∈ S, op(y) ∈ S100intros y hy101exact ClosedUnary.mem with hy102exact restrict.apply with*103104theorem restrictBinary.associative (A S op : Set)105requires function : IsMagma(A, op)106requires subset : S ⊆ A107requires closed : ClosedBinary(S, op)108requires law : Associative(A, op)109shows Associative(S, restrict(op, S × S))110proof111intros x hx y hy z hz112have included := subset113have xIn := included with x, hx114have yIn := included with y, hy115have zIn := included with z, hz116have closed0 := ClosedBinary.mem at S, op, x, y with*117have value0 := restrictBinary.value at A, S, op, x, y with*118have closed1 := ClosedBinary.mem at S, op, op(x, y), z with*119have value1 := restrictBinary.value at A, S, op, op(x, y), z with*120have closed2 := ClosedBinary.mem at S, op, y, z with*121have value2 := restrictBinary.value at A, S, op, y, z with*122have closed3 := ClosedBinary.mem at S, op, x, op(y, z) with*123have value3 := restrictBinary.value at A, S, op, x, op(y, z) with*124have original := law with x, xIn, y, yIn, z, zIn125cc126127theorem restrictBinary.commutative (A S op : Set)128requires function : IsMagma(A, op)129requires subset : S ⊆ A130requires closed : ClosedBinary(S, op)131requires law : Commutative(A, op)132shows Commutative(S, restrict(op, S × S))133proof134intros x hx y hy135have included := subset136have xIn := included with x, hx137have yIn := included with y, hy138have closed0 := ClosedBinary.mem with hx, hy139have value0 := restrictBinary.value with hx, hy140have closed1 := ClosedBinary.mem with hy, hx141have value1 := restrictBinary.value with hy, hx142have original := law with x, xIn, y, yIn143cc144145theorem restrictBinary.identity (A S op unit : Set)146requires function : IsMagma(A, op)147requires subset : S ⊆ A148requires closed : ClosedBinary(S, op)149requires law : Identity(A, op, unit)150requires member : unit ∈ S151shows Identity(S, restrict(op, S × S), unit)152proof153unfold Identity154refine⟨member, ?_⟩155intros x hx156have included := subset157have xIn := included with x, hx158have original := law.right with x, xIn159haveleft:= restrictBinary.value at A, S, op, unit, x with*160haveright:= restrictBinary.value at A, S, op, x, unit with*161constructor162 . cc163 . cc164165theorem restrictUnary.inverse (A S add zero neg : Set)166requires addition : IsMagma(A, add)167requires negation : neg : A → A168requires subset : S ⊆ A169requires addClosed : ClosedBinary(S, add)170requires negClosed : ClosedUnary(S, neg)171requires law : Inverse(A, add, zero, neg)172shows Inverse(S, restrict(add, S × S), zero, restrict(neg, S))173proof174have function := restrictUnary.function with*175unfold Inverse176refine⟨function, ?_⟩177intros x hx178have included := subset179have xIn := included with x, hx180have closed0 := ClosedUnary.mem with*181have value0 := restrictUnary.value with hx182have closed1 := ClosedBinary.mem at S, add, neg(x), x with*183have value1 := restrictBinary.value at A, S, add, neg(x), x with*184have closed2 := ClosedBinary.mem at S, add, x, neg(x) with*185have value2 := restrictBinary.value at A, S, add, x, neg(x) with*186have original := law.right with x, xIn187constructor188 . cc189 . cc190191theorem restrictBinary.distributive (A S add mul : Set)192requires addition : IsMagma(A, add)193requires multiplication : IsMagma(A, mul)194requires subset : S ⊆ A195requires addClosed : ClosedBinary(S, add)196requires mulClosed : ClosedBinary(S, mul)197requires law : Distributive(A, add, mul)198shows Distributive(S, restrict(add, S × S), restrict(mul, S × S))199proof200intros x hx y hy z hz201have included := subset202have xIn := included with x, hx203have yIn := included with y, hy204have zIn := included with z, hz205have closed0 := ClosedBinary.mem at S, add, y, z with*206have value0 := restrictBinary.value at A, S, add, y, z with*207have closed1 := ClosedBinary.mem at S, mul, x, call2(add, y, z) with*208have value1 := restrictBinary.value at A, S, mul, x, call2(add, y, z) with*209have closed2 := ClosedBinary.mem at S, mul, x, y with*210have value2 := restrictBinary.value at A, S, mul, x, y with*211have closed3 := ClosedBinary.mem at S, mul, x, z with*212have value3 := restrictBinary.value at A, S, mul, x, z with*213have closed4 := ClosedBinary.mem at S, add, call2(mul, x, y), call2(mul, x, z) with*214have value4 := restrictBinary.value at A, S, add, call2(mul, x, y), call2(mul, x, z) with*215have closed5 := ClosedBinary.mem at S, add, x, y with*216have value5 := restrictBinary.value at A, S, add, x, y with*217have closed6 := ClosedBinary.mem at S, mul, call2(add, x, y), z with*218have value6 := restrictBinary.value at A, S, mul, call2(add, x, y), z with*219have closed7 := ClosedBinary.mem at S, mul, y, z with*220have value7 := restrictBinary.value at A, S, mul, y, z with*221have closed8 := ClosedBinary.mem at S, add, call2(mul, x, z), call2(mul, y, z) with*222have value8 := restrictBinary.value at A, S, add, call2(mul, x, z), call2(mul, y, z) with*223have original := law with x, xIn, y, yIn, z, zIn224constructor225 . cc226 . cc227