Grace/Cumulus/Nat/Offsets.g17
Imports
OrderLemmas · Set.Function · Set.Tuple
Declarations
- membership.add_cases theorem derivation
- membership.ne_add theorem derivation
- membership.add_offset theorem derivation
- natural.subset_add theorem derivation
- identity.into_add theorem derivation
- offsetMap def
- offsetMap.function theorem derivation
- offsetMap.apply theorem derivation
Source
1-- Positions below a sum m + n: a position is below m or is m + j for a2-- position j below n, the two cases are exclusive, m is included in m + n3-- by the identity, and the offset j ↦ m + j is a function from n into4-- m + n.5-- Part of Cumulus, the Grace17 mathematics library.6-- Copyright (c) 2026 Grant Passmore.7-- Released under the Apache License 2.0. See LICENSE in the repository root.8-- Authors: Grant Passmore910module Grace.Cumulus.Nat.Offsets11import OrderLemmas12import Set.Function13import Set.Tuple1415-- The cases of membership in m + n, and their exclusivity.16theorem membership.add_cases (m n : Nat) (k : Set)17 requires member : k ∈ add(m, n)18 shows k ∈ m ∨ ∃ j ∈ n, k = add(m, j)19proof20 have mNat : Nat(m) by typecheck21 have nNat : Nat(n) by typecheck22 have kNat := natural.member at add(m, n) with member23 have below := Less.of_membership at k, add(m, n) with member24 have split := Less.or_LessEqual at k, m25 cases split with small | large26 . left27 exact membership.of_Less with kNat, mNat, small28 . right29 obtain ⟨j, jNat, equation⟩ := LessEqual.exists_add at m, k with large30 have jBelow : j < n31 rw equation at below32 exact Less.add_left_cancel at j, n, m with below33 have jIn := membership.of_Less with jNat, nNat, jBelow34 witness j35 exact ⟨jIn, equation⟩3637theorem membership.ne_add (m : Nat) (i j : Set)38 requires member : i ∈ m39 requires natural : Nat(j)40 shows i ≠ add(m, j)41proof42 have below := Less.of_membership at i, m with member43 have above := LessEqual.add_right at m, j44 intro equal45 rw equal at below46 have refuted := LessEqual.not_Less with above47 exact refuted with below4849theorem membership.add_offset (m n : Nat) (j : Set)50 requires index : j ∈ n51 shows add(m, j) ∈ add(m, n)52proof53 have sumNat := add.closed at n, m54 have below := Less.of_membership at j, n with index55 have shifted := Less.add_monotone_left at j, n, m with below56 exact membership.of_Less with (add.closed at j, m), sumNat, shifted5758-- The inclusion of m into m + n, as a subset and as the identity map.59theorem natural.subset_add (m n : Nat)60 shows m ⊆ add(m, n)61proof62 have sumNat := add.closed at n, m63 have bound := LessEqual.add_right at m, n64 intros i hi65 have iNat := natural.member at m with hi66 have below := Less.of_membership at i, m with hi67 have under := Less.transitive_LessEqual with below, bound68 exact membership.of_Less with iNat, sumNat, under6970theorem identity.into_add (m n : Nat)71 shows identity(m) : m → add(m, n)72proof73 have subset := natural.subset_add at m, n74 exact identity.inclusion with subset7576-- The offset j ↦ m + j, a function from n into m + n.77def offsetMap (m n : Set) : Set :=78 { p ∈ n × add(m, n) | snd(p) = add(m, fst(p)) }7980theorem offsetMap.function (m n : Nat)81 shows offsetMap(m, n) : n → add(m, n)82proof83 constructor84 . intros p member85 exact member.left86 constructor87 . intros x y relatedY z relatedZ88 obtain ⟨inY, shapeY⟩ := relatedY89 obtain ⟨_, shapeZ⟩ := relatedZ90 simp [fst.pair, snd.pair] at shapeY, shapeZ91 cc92 . intros j input93 have member := membership.add_offset at m, n, j with input94 refine ⟨add(m, j), member, _⟩95 apply offsetMap.membership.backward96 refine ⟨(product.pair with input, member), _⟩97 simp [fst.pair, snd.pair]9899theorem offsetMap.apply (m n : Nat) (j : Set)100 requires index : j ∈ n101 shows offsetMap(m, n)(j) = add(m, j)102proof103 have function := offsetMap.function at m, n104 have shape := FunctionBetween.relates_apply with function, index105 have data := offsetMap.membership.forward with shape106 simp [fst.pair, snd.pair] at data107 exact data.right108