1-- Canonical integer classes2-- 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.Int.Core8import Defs910def integerClass (a b : Set) : Set:=11 ⟦(a, b)⟧[integerPairs, integerEquivalent]1213def integerZero : Integer := integerClass(0, 0)14def integerOfNat (n : Nat) : Integer := integerClass(n, 0)15def integerNegativeOfNat (n : Nat) : Integer := integerClass(0, n)1617theorem integerClass.membership (p a b : Set)18shows p ∈ integerClass(a, b) ↔ (p ∈ integerPairs ∧ relates(integerEquivalent, (a, b), p))19proof20simp [integerClass, equivalenceClass.membership]2122theorem integerClass.integer (a b : Nat)23shows Integer(integerClass(a, b))24proof25unfold Integer26unfold ℤ27unfold integerClass28apply quotient.contains_class29 . exact integerEquivalent.equivalence30 . exact integerPairs.pair at a, b3132theorem integerClass.eq (a b c d : Nat)33requires equivalent : add(a, d) = add(c, b)34shows integerClass(a, b) = integerClass(c, d)35proof36unfold integerClass37apply equivalenceClass.eq38 . exact integerEquivalent.equivalence39 . exact integerPairs.pair at a, b40 . exact integerPairs.pair at c, d41 . have characterization := integerEquivalent.relates_pairs at a, b, c, d42apply characterization.backward43exact equivalent4445theorem integerZero.integer46shows Integer(integerZero)47proof48unfold integerZero49exact integerClass.integer with Naturals.constructor.zero, Naturals.constructor.zero5051theorem integerOfNat.integer (n : Nat)52shows Integer(integerOfNat(n))53proof54unfold integerOfNat55exact integerClass.integer with Naturals.constructor.zero5657theorem integerNegativeOfNat.integer (n : Nat)58shows Integer(integerNegativeOfNat(n))59proof60unfold integerNegativeOfNat61exact integerClass.integer with Naturals.constructor.zero6263theorem integerOfNat.zero64shows integerOfNat(0) = integerZero65proof66simp6768-- Every integer is represented by a difference of two naturals.69theorem Integer.representatives (z : Set)70requires integer : Integer(z)71shows∃ a, Nat(a) ∧∃ b, Nat(b) ∧ z = integerClass(a, b)72proof73unfold Integer at integer74unfold ℤ at integer75obtain⟨bounded, p, pair, shape⟩:= quotient.membership.forward with integer76obtain⟨a, aNat, b, bNat, coordinates⟩:= integerPairs.coordinates with pair77witness a78witness b79unfold integerClass80rw← coordinates81exact shape8283theorem integerClass.equivalent_of_eq (a b c d : Nat)84requires same : integerClass(a, b) = integerClass(c, d)85shows a + d = c + b86proof87haveleft:= integerPairs.pair at a, b with*88haveright:= integerPairs.pair at c, d with*89simp [integerClass] at same90have related := equivalenceClass.related_of_eq with integerEquivalent.equivalence, left, right, same91exact integerEquivalent.relates_pairs.forward with*9293theorem integerOfNat.injective (a b : Nat)94requires same : integerOfNat(a) = integerOfNat(b)95shows a = b96proof97simp [integerOfNat] at same98have sums := integerClass.equivalent_of_eq with*99 simpa [add.right_unit] using sums100