1-- The coordinates of an ordered pair, read back from the pair2-- 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.Set.Tuple8import Core9import Relation1011-- A structure bundled as a nested pair is read back through fst and snd:12-- fst((x, y)) = x and snd((x, y)) = y.13def fstCandidates (p : Set) : Set:= { x ∈⋃ p |∃ y, p = (x, y) }14def sndCandidates (p : Set) : Set:= { y ∈⋃ p |∃ x, p = (x, y) }15def fst (p : Set) : Set:=⋃ fstCandidates(p)16def snd (p : Set) : Set:=⋃ sndCandidates(p)1718theorem orderedPair.first_in_union (x y : Set)19shows x ∈⋃ (x, y)20proof21have inSingleton : x ∈ {x} := singleton.self at x22have singletonIn : {x} ∈ (x, y) bysimp [orderedPair, singleton, pair.membership]23exact union.contains with singletonIn, inSingleton2425theorem orderedPair.second_in_union (x y : Set)26shows y ∈⋃ (x, y)27proof28have inPair : y ∈ {x, y} := pair.right at x, y29have pairIn : {x, y} ∈ (x, y) bysimp [orderedPair, singleton, pair.membership]30exact union.contains with pairIn, inPair3132theorem fstCandidates.pair (x y : Set)33shows fstCandidates((x, y)) = {x}34proof35ext z36constructor37 . intro member38obtain⟨bounded, w, shape⟩:= fstCandidates.membership.forward with member39have same : x = z := orderedPair.first with shape40rw← same41exact singleton.self at x42 . intro member43have same : z = x := singleton.membership.forward with member44have inUnion : x ∈⋃ (x, y) := orderedPair.first_in_union at x, y45rw same46apply fstCandidates.membership.backward47refine⟨inUnion, y, rfl⟩4849theorem sndCandidates.pair (x y : Set)50shows sndCandidates((x, y)) = {y}51proof52ext z53constructor54 . intro member55obtain⟨bounded, w, shape⟩:= sndCandidates.membership.forward with member56obtain⟨sameFirst, same⟩:= orderedPair.injective with shape57rw← same58exact singleton.self at y59 . intro member60have same : z = y := singleton.membership.forward with member61have inUnion : y ∈⋃ (x, y) := orderedPair.second_in_union at x, y62rw same63apply sndCandidates.membership.backward64refine⟨inUnion, x, rfl⟩6566theorem fst.pair (x y : Set)67shows fst((x, y)) = x68proof69simp [fst, fstCandidates.pair, union.singleton]7071theorem snd.pair (x y : Set)72shows snd((x, y)) = y73proof74simp [snd, sndCandidates.pair, union.singleton]75