1-- The set of all functions from A to B2-- 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.Function.Space8import Image9import Powerset1011-- Every function from A to B is a subset of A × B, so the functions form12-- a set carved out of the power set.13def functionSpace (A B : Set) : Set:= { f ∈𝒫(A × B) | FunctionBetween(f, A, B) }1415theorem functionSpace.mem_iff (f A B : Set)16shows f ∈ functionSpace(A, B) ↔ FunctionBetween(f, A, B)17proof18constructor19 . intro h20simp [functionSpace] at h21exact h.right22 . intro h23have included : f ⊆ A × B := h.left24have bounded : f ∈𝒫(A × B) := powerset.membership_iff.backward with included25simp [functionSpace]2627theorem functionSpace.subset_powerset (A B : Set)28shows functionSpace(A, B) ⊆𝒫(A × B)29proof30intros f hf31simp [functionSpace] at hf32exact hf.left3334theorem functionSpace.identity (A : Set)35shows identity(A) ∈ functionSpace(A, A)36proof37exact functionSpace.mem_iff.backward with (identity.function at A)3839theorem functionSpace.constant (A B y : Set)40requires hy : y ∈ B41shows constantFunction(A, B, y) ∈ functionSpace(A, B)42proof43have function := constantFunction.function at A, B, y with hy44exact functionSpace.mem_iff.backward with function4546theorem functionSpace.compose (f g A B C : Set)47requires hf : f ∈ functionSpace(A, B)48requires hg : g ∈ functionSpace(B, C)49shows compose(g, f, A, B, C) ∈ functionSpace(A, C)50proof51have fFunction := functionSpace.mem_iff.forward with hf52have gFunction := functionSpace.mem_iff.forward with hg53have composed := compose.function with fFunction, gFunction54exact functionSpace.mem_iff.backward with composed5556theorem functionSpace.monotone (A B C : Set)57requires h : B ⊆ C58shows functionSpace(A, B) ⊆ functionSpace(A, C)59proof60intros f hf61have function := functionSpace.mem_iff.forward with hf62have widened := FunctionBetween.codomain_of_values at f, A, B, C with function63apply functionSpace.mem_iff.backward64apply widened65intros x hx66exact h with f(x), (FunctionBetween.apply_closed with function, hx)6768theorem functionSpace.empty_codomain (A : Set)69requires nonempty : Nonempty(A)70shows functionSpace(A, ∅) =∅71proof72apply Subset.empty_iff.forward73intros f hf74have function := functionSpace.mem_iff.forward with hf75obtain⟨x, hx⟩:= nonempty76have value := FunctionBetween.apply_closed with function, hx77exfalso78exactset.empty with value7980theorem functionSpace.empty_domain (B : Set)81shows functionSpace(∅, B) = {∅}82proof83ext f84constructor85 . intro hf86have function := functionSpace.mem_iff.forward with hf87have included : f ⊆∅× B := function.left88have emptyProduct := product.left_empty at B89rw emptyProduct at included90have empty := Subset.empty_iff.forward with included91rw empty92exact singleton.self93 . intro hf94simp [singleton.membership] at hf95rw hf96exact functionSpace.mem_iff.backward with (FunctionBetween.empty at B)9798-- A constant function shows that the functions into a nonempty set exist.99theorem functionSpace.nonempty (A B : Set)100requires inhabited : Nonempty(B)101shows Nonempty(functionSpace(A, B))102proof103obtain⟨y, hy⟩:= inhabited104have function := constantFunction.function at A, B, y with hy105have member := functionSpace.mem_iff.backward with function106exact⟨constantFunction(A, B, y), member⟩107