-- Functions on two and four points: the function on 2 with two given -- values and the function on 4 with four, as graphs, with their values -- read off, and the four cases of membership in 4. -- Part of Cumulus, the Grace17 mathematics library. -- Copyright (c) 2026 Grant Passmore. -- Released under the Apache License 2.0. See LICENSE in the repository root. -- Authors: Grant Passmore module Grace.Cumulus.Set.Function.Quadruples import Grace.Cumulus.Set.Function.Triples import Grace.Cumulus.Nat.Foundation -- Membership in 4, by cases. theorem membership.four (x : Set) shows x ∈ 4 ↔ (x = 0 ∨ x = 1 ∨ x = 2 ∨ x = 3) proof have split := membership.successor_set{n := 3} at x have three := membership.three at x tauto -- Functions on two points. -- The function on 2 with the values a, b in S. def pairMap (S a b : Set) : Set := { p ∈ 2 × S | (fst(p) = 0 ∧ snd(p) = a) ∨ (fst(p) = 1 ∧ snd(p) = b) } section Pairs variable (S a b : Set) hypothesis first : a ∈ S hypothesis second : b ∈ S theorem pairMap.function shows pairMap(S, a, b) : 2 → S proof constructor . intros p member exact member.left constructor . intros x y relatedY z relatedZ obtain ⟨inY, shapeY⟩ := relatedY obtain ⟨_, shapeZ⟩ := relatedZ obtain ⟨_, i, hi, _, _, pairY⟩ := product.membership.forward with inY obtain ⟨xi, rfl⟩ := orderedPair.injective with pairY rw xi at shapeY, shapeZ have cases := membership.two.forward with hi rcases cases with rfl | rfl . simp [fst.pair, snd.pair] at shapeY, shapeZ cc . simp [fst.pair, snd.pair] at shapeY, shapeZ cc . intros x input have cases := membership.two.forward with input rcases cases with rfl | rfl . refine ⟨a, first, _⟩ apply pairMap.membership.backward refine ⟨(product.pair with input, first), _⟩ simp [fst.pair, snd.pair] . refine ⟨b, second, _⟩ apply pairMap.membership.backward refine ⟨(product.pair with input, second), _⟩ simp [fst.pair, snd.pair] -- The two values, read off the graph. theorem pairMap.zero shows pairMap(S, a, b)(0) = a proof have function := pairMap.function with first, second have zero : 0 ∈ 2 by simp [membership.two] have atZero : relates(pairMap(S, a, b), 0, a) apply pairMap.membership.backward refine ⟨(product.pair with zero, first), _⟩ simp [fst.pair, snd.pair] exact FunctionBetween.apply_value with function, zero, atZero theorem pairMap.one shows pairMap(S, a, b)(1) = b proof have function := pairMap.function with first, second have one : 1 ∈ 2 by simp [membership.two] have atOne : relates(pairMap(S, a, b), 1, b) apply pairMap.membership.backward refine ⟨(product.pair with one, second), _⟩ simp [fst.pair, snd.pair] exact FunctionBetween.apply_value with function, one, atOne end Pairs -- Functions on four points. -- The function on 4 with the values a, b, c, d in S. def quadrupleMap (S a b c d : Set) : Set := { p ∈ 4 × S | (fst(p) = 0 ∧ snd(p) = a) ∨ (fst(p) = 1 ∧ snd(p) = b) ∨ (fst(p) = 2 ∧ snd(p) = c) ∨ (fst(p) = 3 ∧ snd(p) = d) } section Quadruples variable (S a b c d : Set) hypothesis first : a ∈ S hypothesis second : b ∈ S hypothesis third : c ∈ S hypothesis fourth : d ∈ S theorem quadrupleMap.function shows quadrupleMap(S, a, b, c, d) : 4 → S proof constructor . intros p member exact member.left constructor . intros x y relatedY z relatedZ obtain ⟨inY, shapeY⟩ := relatedY obtain ⟨_, shapeZ⟩ := relatedZ obtain ⟨_, i, hi, _, _, pairY⟩ := product.membership.forward with inY obtain ⟨xi, rfl⟩ := orderedPair.injective with pairY rw xi at shapeY, shapeZ have cases := membership.four.forward with hi rcases cases with rfl | rfl | rfl | rfl . simp [fst.pair, snd.pair] at shapeY, shapeZ cc . simp [fst.pair, snd.pair] at shapeY, shapeZ cc . simp [fst.pair, snd.pair] at shapeY, shapeZ cc . simp [fst.pair, snd.pair] at shapeY, shapeZ cc . intros x input have cases := membership.four.forward with input rcases cases with rfl | rfl | rfl | rfl . refine ⟨a, first, _⟩ apply quadrupleMap.membership.backward refine ⟨(product.pair with input, first), _⟩ simp [fst.pair, snd.pair] . refine ⟨b, second, _⟩ apply quadrupleMap.membership.backward refine ⟨(product.pair with input, second), _⟩ simp [fst.pair, snd.pair] . refine ⟨c, third, _⟩ apply quadrupleMap.membership.backward refine ⟨(product.pair with input, third), _⟩ simp [fst.pair, snd.pair] . refine ⟨d, fourth, _⟩ apply quadrupleMap.membership.backward refine ⟨(product.pair with input, fourth), _⟩ simp [fst.pair, snd.pair] -- The four values, read off the graph. theorem quadrupleMap.zero shows quadrupleMap(S, a, b, c, d)(0) = a proof have function := quadrupleMap.function with first, second, third, fourth have zero : 0 ∈ 4 by simp [membership.four] have atZero : relates(quadrupleMap(S, a, b, c, d), 0, a) apply quadrupleMap.membership.backward refine ⟨(product.pair with zero, first), _⟩ simp [fst.pair, snd.pair] exact FunctionBetween.apply_value with function, zero, atZero theorem quadrupleMap.one shows quadrupleMap(S, a, b, c, d)(1) = b proof have function := quadrupleMap.function with first, second, third, fourth have one : 1 ∈ 4 by simp [membership.four] have atOne : relates(quadrupleMap(S, a, b, c, d), 1, b) apply quadrupleMap.membership.backward refine ⟨(product.pair with one, second), _⟩ simp [fst.pair, snd.pair] exact FunctionBetween.apply_value with function, one, atOne theorem quadrupleMap.two shows quadrupleMap(S, a, b, c, d)(2) = c proof have function := quadrupleMap.function with first, second, third, fourth have two : 2 ∈ 4 by simp [membership.four] have atTwo : relates(quadrupleMap(S, a, b, c, d), 2, c) apply quadrupleMap.membership.backward refine ⟨(product.pair with two, third), _⟩ simp [fst.pair, snd.pair] exact FunctionBetween.apply_value with function, two, atTwo theorem quadrupleMap.three shows quadrupleMap(S, a, b, c, d)(3) = d proof have function := quadrupleMap.function with first, second, third, fourth have three : 3 ∈ 4 by simp [membership.four] have atThree : relates(quadrupleMap(S, a, b, c, d), 3, d) apply quadrupleMap.membership.backward refine ⟨(product.pair with three, fourth), _⟩ simp [fst.pair, snd.pair] exact FunctionBetween.apply_value with function, three, atThree end Quadruples -- Functions on one point. -- The function on 1 with the value a in S. def pointMap (S a : Set) : Set := { p ∈ 1 × S | snd(p) = a } theorem pointMap.function (S a : Set) requires member : a ∈ S shows pointMap(S, a) : 1 → S proof constructor . intros p inMap exact inMap.left constructor . intros x y relatedY z relatedZ obtain ⟨inY, shapeY⟩ := relatedY obtain ⟨_, shapeZ⟩ := relatedZ obtain ⟨_, i, _, _, _, pairY⟩ := product.membership.forward with inY obtain ⟨_, rfl⟩ := orderedPair.injective with pairY simp [snd.pair] at shapeY, shapeZ cc . intros x input refine ⟨a, member, _⟩ apply pointMap.membership.backward refine ⟨(product.pair with input, member), _⟩ simp [snd.pair] theorem pointMap.zero (S a : Set) requires member : a ∈ S shows pointMap(S, a)(0) = a proof have function := pointMap.function with member have zero : 0 ∈ 1 by simp [membership.one] have atZero : relates(pointMap(S, a), 0, a) apply pointMap.membership.backward refine ⟨(product.pair with zero, member), _⟩ simp [snd.pair] exact FunctionBetween.apply_value with function, zero, atZero