1-- Coordinate projections of a product: the first and second coordinate2-- of a pair as functions on A × B, bijective when the other factor is a3-- point4-- Part of Cumulus, the Grace17 mathematics library.5-- Copyright (c) 2026 Grant Passmore.6-- Released under the Apache License 2.0. See LICENSE in the repository root.7-- Authors: Grant Passmore89module Grace.Cumulus.Set.Function.Projection10import Image1112-- Coordinates of a pair, as functions on the product.13defunique firstOf (A B p : Set) (x ∈ A) :=∃ y ∈ B, p = (x, y)14requires pair : p ∈ A × B15proof16obtain⟨bound, x, hx, y, hy, shape⟩:= product.membership.forward with pair17refine⟨x, hx, y, hy, shape⟩18uniqueness19intros u hu first v hv second20obtain⟨b, hb, shapeU⟩:= first21obtain⟨d, hd, shapeV⟩:= second22have equal : (u, b) = (v, d) bycc23have coordinates := orderedPair.injective with equal24exact coordinates.left2526defunique secondOf (A B p : Set) (y ∈ B) :=∃ x ∈ A, p = (x, y)27requires pair : p ∈ A × B28proof29obtain⟨bound, x, hx, y, hy, shape⟩:= product.membership.forward with pair30refine⟨y, hy, x, hx, shape⟩31uniqueness32intros u hu first v hv second33obtain⟨a, ha, shapeU⟩:= first34obtain⟨c, hc, shapeV⟩:= second35have equal : (a, u) = (c, v) bycc36have coordinates := orderedPair.injective with equal37exact coordinates.right3839defgraph firstProjection (A B : Set) (p ∈ A × B) : A := firstOf(A, B, p)40proof41have selected := firstOf.selected with member42exact selected.left4344defgraph secondProjection (A B : Set) (p ∈ A × B) : B := secondOf(A, B, p)45proof46have selected := secondOf.selected with member47exact selected.left4849theorem firstProjection.pair (A B x y : Set)50requires hx : x ∈ A51requires hy : y ∈ B52shows firstProjection(A, B)((x, y)) = x53proof54have pair := product.pair at x, y, A, B with*55have selected := firstOf.selected with pair56obtain⟨b, hb, shape⟩:= selected.right57have coordinates := orderedPair.injective with shape58have value := firstProjection.value with pair59cc6061theorem secondProjection.pair (A B x y : Set)62requires hx : x ∈ A63requires hy : y ∈ B64shows secondProjection(A, B)((x, y)) = y65proof66have pair := product.pair at x, y, A, B with*67have selected := secondOf.selected with pair68obtain⟨a, ha, shape⟩:= selected.right69have coordinates := orderedPair.injective with shape70have value := secondProjection.value with pair71cc7273-- Over a single point in the other factor, a projection is a bijection.74theorem firstProjection.bijective_singleton (A b : Set)75shows BijectiveBetween(firstProjection(A, {b}), A × {b}, A)76proof77have function := firstProjection.function at A, {b}78haveself : b ∈ {b} bysimp [singleton.membership]79constructor80 . constructor81 . exact function82 . intros p hp q hq z hz hpz hqz83have valueP := FunctionBetween.apply_value with function, hp, hpz84have valueQ := FunctionBetween.apply_value with function, hq, hqz85obtain⟨boundP, x, hx, y, hy, shapeP⟩:= product.membership.forward with hp86obtain⟨boundQ, u, hu, v, hv, shapeQ⟩:= product.membership.forward with hq87have sameY := singleton.membership.forward with hy88have sameV := singleton.membership.forward with hv89rw shapeP at valueP90rw shapeQ at valueQ91have pairP := firstProjection.pair with hx, hy92have pairQ := firstProjection.pair with hu, hv93rw [shapeP, shapeQ, sameY, sameV]94have equal : x = u bycc95rw equal96rfl97 . constructor98 . exact function99 . intros x hx100have pair := product.pair with hx, self101refine⟨(x, b), pair, ?_⟩102have value := firstProjection.pair with hx, self103have related := FunctionBetween.relates_apply with function, pair104 rwa value at related105106theorem secondProjection.bijective_singleton (a B : Set)107shows BijectiveBetween(secondProjection({a}, B), {a} × B, B)108proof109have function := secondProjection.function at {a}, B110haveself : a ∈ {a} bysimp [singleton.membership]111constructor112 . constructor113 . exact function114 . intros p hp q hq z hz hpz hqz115have valueP := FunctionBetween.apply_value with function, hp, hpz116have valueQ := FunctionBetween.apply_value with function, hq, hqz117obtain⟨boundP, x, hx, y, hy, shapeP⟩:= product.membership.forward with hp118obtain⟨boundQ, u, hu, v, hv, shapeQ⟩:= product.membership.forward with hq119have sameX := singleton.membership.forward with hx120have sameU := singleton.membership.forward with hu121rw shapeP at valueP122rw shapeQ at valueQ123have pairP := secondProjection.pair with hx, hy124have pairQ := secondProjection.pair with hu, hv125rw [shapeP, shapeQ, sameX, sameU]126have equal : y = v bycc127rw equal128rfl129 . constructor130 . exact function131 . intros y hy132have pair := product.pair withself, hy133refine⟨(a, y), pair, ?_⟩134have value := secondProjection.pair withself, hy135have related := FunctionBetween.relates_apply with function, pair136 rwa value at related137