Grace/Cumulus/Algebra/Polynomial/Algebra.g17

Open in Workbench Download source

Imports

Grace.Cumulus.Algebra.Algebras.Basic · Grace.Cumulus.Algebra.Polynomial.BundledEvaluation · Grace.Cumulus.Algebra.Ring.Pow

Declarations

Source

1-- Polynomial rings as algebras over their coefficient ring: evaluation as2-- the algebra homomorphism with prescribed variable images, its uniqueness,3-- renaming of variables along a map of index sets, and the flattening of a4-- polynomial ring over a polynomial ring with numeral index sets.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.Algebra.Polynomial.Algebra11import Grace.Cumulus.Algebra.Algebras.Basic12import Grace.Cumulus.Algebra.Polynomial.BundledEvaluation13import Grace.Cumulus.Algebra.Ring.Pow1415-- The definitions.1617-- The polynomial ring over K in the variables I, as an algebra over K by18-- the constants.19def polynomialAlgebra (K I : Set) : Set :=20  Algebra.mk(K, polynomialRing(K, I), polynomialConstant(K, I))2122-- The polynomial ring over the polynomial ring, as an algebra over K.23def iteratedPolynomialAlgebra (K I J : Set) : Set :=24  Algebra.mk(K, polynomialRing(polynomialRing(K, I), J),25    compose(polynomialConstant(polynomialRing(K, I), J),26      polynomialConstant(K, I), Ring.carrier(K),27      Ring.carrier(polynomialRing(K, I)),28      Ring.carrier(polynomialRing(polynomialRing(K, I), J))))2930-- The variables of K[J] indexed along σ : I → J.31def variableAssignment (K I J σ : Set) : Set :=32  { p ∈ I × Ring.carrier(polynomialRing(K, J)) | snd(p) = X(K, J, σ(fst(p))) }3334-- Renaming: the K-algebra homomorphism K[I] → K[J] sending X_i to X_σ(i).35def polynomialRename (K I J σ : Set) : Set :=36  evaluationHom(K, polynomialRing(K, J), I, polynomialConstant(K, J),37    variableAssignment(K, I, J, σ))3839-- The projections of the polynomial algebra and of the iterated one.40theorem polynomialAlgebra.base (K I : Set)41  shows Algebra.base(polynomialAlgebra(K, I)) = K42proof43  simp [polynomialAlgebra, Algebra.mk.base]4445theorem polynomialAlgebra.ring (K I : Set)46  shows Algebra.ring(polynomialAlgebra(K, I)) = polynomialRing(K, I)47proof48  simp [polynomialAlgebra, Algebra.mk.ring]4950theorem polynomialAlgebra.map (K I : Set)51  shows Algebra.map(polynomialAlgebra(K, I)) = polynomialConstant(K, I)52proof53  simp [polynomialAlgebra, Algebra.mk.map]5455theorem polynomialAlgebra.carrierOf (K I : Set)56  shows algebraCarrier(polynomialAlgebra(K, I)) =57    Ring.carrier(polynomialRing(K, I))58proof59  simp [algebraCarrier, polynomialAlgebra, Algebra.mk.ring]6061theorem iteratedPolynomialAlgebra.base (K I J : Set)62  shows Algebra.base(iteratedPolynomialAlgebra(K, I, J)) = K63proof64  simp [iteratedPolynomialAlgebra, Algebra.mk.base]6566theorem iteratedPolynomialAlgebra.ring (K I J : Set)67  shows Algebra.ring(iteratedPolynomialAlgebra(K, I, J)) =68    polynomialRing(polynomialRing(K, I), J)69proof70  simp [iteratedPolynomialAlgebra, Algebra.mk.ring]7172theorem iteratedPolynomialAlgebra.map (K I J : Set)73  shows Algebra.map(iteratedPolynomialAlgebra(K, I, J)) =74    compose(polynomialConstant(polynomialRing(K, I), J),75      polynomialConstant(K, I), Ring.carrier(K),76      Ring.carrier(polynomialRing(K, I)),77      Ring.carrier(polynomialRing(polynomialRing(K, I), J)))78proof79  simp [iteratedPolynomialAlgebra, Algebra.mk.map]8081theorem iteratedPolynomialAlgebra.carrierOf (K I J : Set)82  shows algebraCarrier(iteratedPolynomialAlgebra(K, I, J)) =83    Ring.carrier(polynomialRing(polynomialRing(K, I), J))84proof85  simp [algebraCarrier, iteratedPolynomialAlgebra, Algebra.mk.ring]8687-- The variable assignment along σ is a function into K[J] with the88-- values X_σ(i).89theorem variableAssignment.function (K I J σ : Set)90  requires base : CommRing(K)91  requires map : σ : I → J92  shows variableAssignment(K, I, J, σ) : I → Ring.carrier(polynomialRing(K, J))93proof94  constructor95  . intros p member96    exact member.left97  constructor98  . intros x y relatedY z relatedZ99    obtain ⟨inY, shapeY⟩ := relatedY100    obtain ⟨_, shapeZ⟩ := relatedZ101    simp [fst.pair, snd.pair] at shapeY, shapeZ102    cc103  . intros i input104    have member := X.mem at K, J, σ(i) with base105    refine ⟨X(K, J, σ(i)), member, _⟩106    apply variableAssignment.membership.backward107    refine ⟨(product.pair with input, member), _⟩108    simp [fst.pair, snd.pair]109110theorem variableAssignment.apply (K I J σ i : Set)111  requires base : CommRing(K)112  requires map : σ : I → J113  requires index : i ∈ I114  shows variableAssignment(K, I, J, σ)(i) = X(K, J, σ(i))115proof116  have function := variableAssignment.function with base, map117  have shape := FunctionBetween.relates_apply with function, index118  have data := variableAssignment.membership.forward with shape119  simp [fst.pair, snd.pair] at data120  exact data.right121122section Polynomials123variable (K I : Set)124hypothesis base : CommRing(K)125126-- The polynomial algebra.127theorem polynomialAlgebra.algebra128  shows Algebra(polynomialAlgebra(K, I))129proof130  have ring := polynomialRing.comm_ring at K, I with base131  have hom := polynomialConstant.hom at K, I with base132  unfold polynomialAlgebra133  exact Algebra.intro with base, ring, hom134135-- Evaluation at values in an algebra B over K is the K-algebra136-- homomorphism sending X_j to v(j), and it is the only one.137theorem evaluationHom.algebra_hom (B v : Set)138  requires algebra : Algebra(B)139  requires over : Algebra.base(B) = K140  requires values : v : I → algebraCarrier(B)141  shows evaluationHom(K, Algebra.ring(B), I, Algebra.map(B), v) :142    polynomialAlgebra(K, I) →ₐ B143proof144  have ringB := Algebra.comm_ring with algebra145  have structureMap := Algebra.structure_hom with algebra146  rw over at structureMap147  have valuesIn : v : I → Ring.carrier(Algebra.ring(B))148    unfold algebraCarrier at values149    exact values150  have hom := evaluationHom.hom at K, Algebra.ring(B), I, Algebra.map(B), v151    with base, ringB, structureMap, valuesIn152  have polynomial := polynomialAlgebra.algebra at K, I with base153  unfold AlgebraHom154  refine ⟨polynomial, algebra, ?_, ?_, ?_⟩155  . rw [polynomialAlgebra.base, over]156  . rw polynomialAlgebra.ring157    exact hom158  . intros a ha159    rw polynomialAlgebra.base at ha160    rw polynomialAlgebra.map161    exact evaluationHom.map_constant with base, ringB, structureMap, valuesIn,162      ha163164theorem evaluationHom.algebra_X (B v j : Set)165  requires algebra : Algebra(B)166  requires over : Algebra.base(B) = K167  requires values : v : I → algebraCarrier(B)168  requires index : j ∈ I169  shows evaluationHom(K, Algebra.ring(B), I, Algebra.map(B), v)(X(K, I, j)) =170    v(j)171proof172  have ringB := Algebra.comm_ring with algebra173  have structureMap := Algebra.structure_hom with algebra174  rw over at structureMap175  have valuesIn : v : I → Ring.carrier(Algebra.ring(B))176    unfold algebraCarrier at values177    exact values178  exact evaluationHom.map_X with base, ringB, structureMap, valuesIn, index179180theorem AlgebraHom.polynomial_ext (B f g : Set)181  requires first : f : polynomialAlgebra(K, I) →ₐ B182  requires second : g : polynomialAlgebra(K, I) →ₐ B183  requires agree : ∀ j ∈ I, f(X(K, I, j)) = g(X(K, I, j))184  shows f = g185proof186  have fHom := AlgebraHom.ring_hom with first187  have gHom := AlgebraHom.ring_hom with second188  rw polynomialAlgebra.ring at fHom, gHom189  have constants : ∀ a ∈ K,190      f(polynomialConstant(K, I)(a)) = g(polynomialConstant(K, I)(a))191    intros a ha192    have member : a ∈ Ring.carrier(Algebra.base(polynomialAlgebra(K, I)))193      rw polynomialAlgebra.base194      exact ha195    have fBase := AlgebraHom.map_base with first, member196    have gBase := AlgebraHom.map_base with second, member197    rw polynomialAlgebra.map at fBase, gBase198    cc199  exact polynomialRing.hom_ext with base, fHom, gHom, constants, agree200201-- A homomorphism out of K[I] followed by one back that fixes the202-- variables fixes every polynomial.203theorem AlgebraHom.polynomial_round_trip (B f g : Set)204  requires forward : f : polynomialAlgebra(K, I) →ₐ B205  requires backward : g : B →ₐ polynomialAlgebra(K, I)206  requires variables : ∀ j ∈ I, g(f(X(K, I, j))) = X(K, I, j)207  shows ∀ x ∈ algebraCarrier(polynomialAlgebra(K, I)), g(f(x)) = x208proof209  have algebra := polynomialAlgebra.algebra at K, I with base210  have forwardFunction := AlgebraHom.function with forward211  have backwardFunction := AlgebraHom.function with backward212  have composite := AlgebraHom.compose with forward, backward213  have identityHom := AlgebraHom.identity with algebra214  have onVariables : ∀ j ∈ I,215      compose(g, f, algebraCarrier(polynomialAlgebra(K, I)), algebraCarrier(B),216        algebraCarrier(polynomialAlgebra(K, I)))(X(K, I, j)) =217      identity(algebraCarrier(polynomialAlgebra(K, I)))(X(K, I, j))218    intros j hj219    have member : X(K, I, j) ∈ algebraCarrier(polynomialAlgebra(K, I))220      rw polynomialAlgebra.carrierOf221      exact X.mem at K, I, j with base222    have step := compose.apply with forwardFunction, backwardFunction, member223    have fixed := identity.apply with member224    have law := variables with j, hj225    cc226  have equal := AlgebraHom.polynomial_ext with composite, identityHom,227    onVariables228  intros x hx229  have step := compose.apply with forwardFunction, backwardFunction, hx230  have fixed := identity.apply with hx231  rw equal at step232  cc233234-- The variables as members of the polynomial algebra, and two homomorphisms235-- out of K[I] that agree on the variables agree everywhere; stated for236-- composites, so that a proof need not name the composite maps.237theorem X.algebra_mem (j : Set)238  requires index : j ∈ I239  shows X(K, I, j) ∈ algebraCarrier(polynomialAlgebra(K, I))240proof241  rw polynomialAlgebra.carrierOf242  exact X.mem at K, I, j with *243244theorem polynomial_composites_agree (A B C f g u v x : Set)245  requires first : f : polynomialAlgebra(K, I) →ₐ A246  requires second : g : A →ₐ C247  requires third : u : polynomialAlgebra(K, I) →ₐ B248  requires fourth : v : B →ₐ C249  requires agree : ∀ j ∈ I, g(f(X(K, I, j))) = v(u(X(K, I, j)))250  requires member : x ∈ algebraCarrier(polynomialAlgebra(K, I))251  shows g(f(x)) = v(u(x))252proof253  have fFunction := AlgebraHom.function with first254  have gFunction := AlgebraHom.function with second255  have uFunction := AlgebraHom.function with third256  have vFunction := AlgebraHom.function with fourth257  have left := AlgebraHom.compose with first, second258  have right := AlgebraHom.compose with third, fourth259  have variables : ∀ j ∈ I,260      compose(g, f, algebraCarrier(polynomialAlgebra(K, I)),261        algebraCarrier(A), algebraCarrier(C))(X(K, I, j)) =262      compose(v, u, algebraCarrier(polynomialAlgebra(K, I)),263        algebraCarrier(B), algebraCarrier(C))(X(K, I, j))264    intros j jIn265    have variable := X.algebra_mem at K, I, j with *266    rw compose.apply with fFunction, gFunction, variable267    rw compose.apply with uFunction, vFunction, variable268    exact agree with j, jIn269  have same := AlgebraHom.polynomial_ext with base, left, right, variables270  have leftApply := compose.apply with fFunction, gFunction, member271  have rightApply := compose.apply with uFunction, vFunction, member272  rw ← leftApply273  rw ← rightApply274  rw same275276theorem polynomial_composite_agree (A C f g h x : Set)277  requires first : f : polynomialAlgebra(K, I) →ₐ A278  requires second : g : A →ₐ C279  requires third : h : polynomialAlgebra(K, I) →ₐ C280  requires agree : ∀ j ∈ I, g(f(X(K, I, j))) = h(X(K, I, j))281  requires member : x ∈ algebraCarrier(polynomialAlgebra(K, I))282  shows g(f(x)) = h(x)283proof284  have fFunction := AlgebraHom.function with first285  have gFunction := AlgebraHom.function with second286  have left := AlgebraHom.compose with first, second287  have variables : ∀ j ∈ I,288      compose(g, f, algebraCarrier(polynomialAlgebra(K, I)),289        algebraCarrier(A), algebraCarrier(C))(X(K, I, j)) =290      h(X(K, I, j))291    intros j jIn292    have variable := X.algebra_mem at K, I, j with *293    rw compose.apply with fFunction, gFunction, variable294    exact agree with j, jIn295  have same := AlgebraHom.polynomial_ext with base, left, third, variables296  have leftApply := compose.apply with fFunction, gFunction, member297  rw ← leftApply298  rw same299300-- Renaming along σ : I → J is a homomorphism sending X_j to X_σ(j), and301-- along a bijection it is an isomorphism.302theorem polynomialRename.hom (J σ : Set)303  requires map : σ : I → J304  shows polynomialRename(K, I, J, σ) :305    polynomialAlgebra(K, I) →ₐ polynomialAlgebra(K, J)306proof307  have algebra := polynomialAlgebra.algebra at K, J with base308  have over := polynomialAlgebra.base at K, J309  have values : FunctionBetween(variableAssignment(K, I, J, σ), I,310      algebraCarrier(polynomialAlgebra(K, J)))311    rw polynomialAlgebra.carrierOf312    exact variableAssignment.function with base, map313  have hom := evaluationHom.algebra_hom at K, I, polynomialAlgebra(K, J),314    variableAssignment(K, I, J, σ) with base, algebra, over, values315  rw [polynomialAlgebra.ring, polynomialAlgebra.map] at hom316  unfold polynomialRename317  exact hom318319theorem polynomialRename.map_X (J σ j : Set)320  requires map : σ : I → J321  requires index : j ∈ I322  shows polynomialRename(K, I, J, σ)(X(K, I, j)) = X(K, J, σ(j))323proof324  have target := polynomialRing.comm_ring at K, J with base325  have constants := polynomialConstant.hom at K, J with base326  have values := variableAssignment.function with base, map327  have value := variableAssignment.apply with base, map, index328  unfold polynomialRename329  rw evaluationHom.map_X with base, target, constants, values, index330  exact value331332theorem polynomialRename.iso (J σ : Set)333  requires bijection : BijectiveBetween(σ, I, J)334  shows polynomialRename(K, I, J, σ) :335    polynomialAlgebra(K, I) ≃ₐ polynomialAlgebra(K, J)336proof337  have injective := Bijective.injective with bijection338  have function := Injective.function with injective339  have inverse := converse.function_of_bijective with bijection340  have forward := polynomialRename.hom with base, function341  have backward := polynomialRename.hom at K, J, I, converse(σ, I, J)342    with base, inverse343  -- Renaming back after renaming forward fixes every variable of K[I].344  have leftAgree : ∀ j ∈ I,345      polynomialRename(K, J, I, converse(σ, I, J))(346        polynomialRename(K, I, J, σ)(X(K, I, j))) = X(K, I, j)347    intros j hj348    have imageIn := FunctionBetween.apply_closed with function, hj349    have first := polynomialRename.map_X with base, function, hj350    have second := polynomialRename.map_X at K, J, I, converse(σ, I, J), σ(j)351      with base, inverse, imageIn352    have back := Bijective.inverse_apply with bijection, hj353    cc354  have left := AlgebraHom.polynomial_round_trip with forward, backward,355    leftAgree356  -- And renaming forward after renaming back fixes every variable of K[J].357  have rightAgree : ∀ k ∈ J,358      polynomialRename(K, I, J, σ)(359        polynomialRename(K, J, I, converse(σ, I, J))(X(K, J, k))) = X(K, J, k)360    intros k hk361    have preimageIn := FunctionBetween.apply_closed with inverse, hk362    have first := polynomialRename.map_X at K, J, I, converse(σ, I, J), k363      with base, inverse, hk364    have second := polynomialRename.map_X with base, function, preimageIn365    have back := Bijective.apply_inverse with bijection, hk366    cc367  have right := AlgebraHom.polynomial_round_trip with backward, forward,368    rightAgree369  exact AlgebraIso.of_inverse with forward, backward, left, right370371end Polynomials372373-- The assignment splitting the variables of K[m + n]: a position below m374-- goes to the inner variable X_i as a constant of K[m][n], and m + j to375-- the outer variable X_j.376def splitAssignment (K m n : Set) : Set :=377  { p ∈ add(m, n) × Ring.carrier(polynomialRing(polynomialRing(K, m), n)) |378    (fst(p) ∈ m ∧379      snd(p) = polynomialConstant(polynomialRing(K, m), n)(X(K, m, fst(p)))) ∨380    (∃ j ∈ n, fst(p) = add(m, j) ∧ snd(p) = X(polynomialRing(K, m), n, j)) }381382theorem splitAssignment.function (K : Set, m n : Nat)383  requires base : CommRing(K)384  shows splitAssignment(K, m, n) :385    add(m, n) → Ring.carrier(polynomialRing(polynomialRing(K, m), n))386proof387  have inner := polynomialRing.comm_ring at K, m with base388  constructor389  . intros p member390    exact member.left391  constructor392  . intros x y relatedY z relatedZ393    obtain ⟨inY, shapeY⟩ := relatedY394    obtain ⟨_, shapeZ⟩ := relatedZ395    simp [fst.pair, snd.pair] at shapeY, shapeZ396    rcases shapeY with innerY | outerY397    . obtain ⟨xIn, yValue⟩ := innerY398      rcases shapeZ with innerZ | outerZ399      . obtain ⟨_, zValue⟩ := innerZ400        cc401      . obtain ⟨j, hj, xEq, zValue⟩ := outerZ402        simp [fst.pair, snd.pair] at xEq, zValue403        exfalso404        have jNat := natural.member at n with hj405        have apart := membership.ne_add at m, x, j with xIn, jNat406        exact apart with xEq407    . obtain ⟨j, hj, xEq, yValue⟩ := outerY408      simp [fst.pair, snd.pair] at xEq, yValue409      rcases shapeZ with innerZ | outerZ410      . obtain ⟨xIn, zValue⟩ := innerZ411        exfalso412        have jNat := natural.member at n with hj413        have apart := membership.ne_add at m, x, j with xIn, jNat414        exact apart with xEq415      . obtain ⟨l, hl, xEq2, zValue⟩ := outerZ416        simp [fst.pair, snd.pair] at xEq2, zValue417        have same : add(m, j) = add(m, l) by cc418        have cancel := add.left_cancel at j, l, m419        have equal := cancel with same420        cc421  . intros k input422    have split := membership.add_cases at m, n, k with input423    rcases split with kIn | shifted424    . have xIn := X.mem at K, m, k with base425      have member := polynomialConstant.mem at polynomialRing(K, m), n,426        X(K, m, k) with inner427      refine ⟨polynomialConstant(polynomialRing(K, m), n)(X(K, m, k)), member,428        _⟩429      apply splitAssignment.membership.backward430      refine ⟨(product.pair with input, member), _⟩431      simp [fst.pair, snd.pair]432    . obtain ⟨j, hj, kEq⟩ := shifted433      have member := X.mem at polynomialRing(K, m), n, j with inner434      refine ⟨X(polynomialRing(K, m), n, j), member, _⟩435      apply splitAssignment.membership.backward436      refine ⟨(product.pair with input, member), _⟩437      simp [fst.pair, snd.pair]438439theorem splitAssignment.inner (K : Set, m n : Nat) (i : Set)440  requires base : CommRing(K)441  requires index : i ∈ m442  shows splitAssignment(K, m, n)(i) =443    polynomialConstant(polynomialRing(K, m), n)(X(K, m, i))444proof445  have inclusion := natural.subset_add at m, n446  have input := inclusion with i, index447  have function := splitAssignment.function at K, m, n with base448  have shape := FunctionBetween.relates_apply with function, input449  have data := splitAssignment.membership.forward with shape450  simp [fst.pair, snd.pair] at data451  rcases data.right with innerCase | outerCase452  . exact innerCase.right453  . obtain ⟨j, hj, iEq, value⟩ := outerCase454    simp [fst.pair, snd.pair] at iEq, value455    exfalso456    have jNat := natural.member at n with hj457    have apart := membership.ne_add at m, i, j with index, jNat458    exact apart with iEq459460theorem splitAssignment.outer (K : Set, m n : Nat) (j : Set)461  requires base : CommRing(K)462  requires index : j ∈ n463  shows splitAssignment(K, m, n)(add(m, j)) = X(polynomialRing(K, m), n, j)464proof465  have jNat := natural.member at n with index466  have input := membership.add_offset at m, n, j with index467  have function := splitAssignment.function at K, m, n with base468  have shape := FunctionBetween.relates_apply with function, input469  have data := splitAssignment.membership.forward with shape470  simp [fst.pair, snd.pair] at data471  rcases data.right with innerCase | outerCase472  . obtain ⟨member, value⟩ := innerCase473    exfalso474    have apart := membership.ne_add at m, add(m, j), j with member, jNat475    apply apart476    rfl477  . obtain ⟨l, hl, equation, value⟩ := outerCase478    simp [fst.pair, snd.pair] at equation, value479    have cancel := add.left_cancel at j, l, m480    have equal := cancel with equation481    cc482483-- Flattening K[m][n] onto K[m + n]: the inner ring goes in by the484-- inclusion of m into m + n, the outer variables by the offset; the485-- inverse splits the variables of K[m + n].486def innerFlatten (K m n : Set) : Set :=487  evaluationHom(K, polynomialRing(K, add(m, n)), m,488    polynomialConstant(K, add(m, n)),489    variableAssignment(K, m, add(m, n), identity(m)))490491def flattenHom (K m n : Set) : Set :=492  evaluationHom(polynomialRing(K, m), polynomialRing(K, add(m, n)), n,493    innerFlatten(K, m, n), variableAssignment(K, n, add(m, n), offsetMap(m, n)))494495def unflattenHom (K m n : Set) : Set :=496  evaluationHom(K, polynomialRing(polynomialRing(K, m), n), add(m, n),497    compose(polynomialConstant(polynomialRing(K, m), n),498      polynomialConstant(K, m), Ring.carrier(K),499      Ring.carrier(polynomialRing(K, m)),500      Ring.carrier(polynomialRing(polynomialRing(K, m), n))),501    splitAssignment(K, m, n))502503section Flattening504variable (K : Set, m n : Nat)505hypothesis base : CommRing(K)506507-- The constants of K[m][n] from K, as a ring homomorphism, and its values.508theorem iteratedConstant.hom509  shows compose(polynomialConstant(polynomialRing(K, m), n),510      polynomialConstant(K, m), Ring.carrier(K),511      Ring.carrier(polynomialRing(K, m)),512      Ring.carrier(polynomialRing(polynomialRing(K, m), n))) :513    K →+* polynomialRing(polynomialRing(K, m), n)514proof515  have innerRing := polynomialRing.comm_ring at K, m with base516  have innerConstants := polynomialConstant.hom at K, m with base517  have outerConstants := polynomialConstant.hom at polynomialRing(K, m), n518    with innerRing519  exact RingHom.comp with base, innerConstants, outerConstants520521theorem iteratedConstant.apply (a : Set)522  requires member : a ∈ Ring.carrier(K)523  shows compose(polynomialConstant(polynomialRing(K, m), n),524      polynomialConstant(K, m), Ring.carrier(K),525      Ring.carrier(polynomialRing(K, m)),526      Ring.carrier(polynomialRing(polynomialRing(K, m), n)))(a) =527    polynomialConstant(polynomialRing(K, m), n)(polynomialConstant(K, m)(a))528proof529  have innerRing := polynomialRing.comm_ring at K, m with base530  have innerConstants := polynomialConstant.hom at K, m with base531  have outerConstants := polynomialConstant.hom at polynomialRing(K, m), n532    with innerRing533  have innerFunction := innerConstants.right.right.left534  have outerFunction := outerConstants.right.right.left535  exact compose.apply with innerFunction, outerFunction, member536537theorem iteratedPolynomialAlgebra.algebra538  shows Algebra(iteratedPolynomialAlgebra(K, m, n))539proof540  have inner := polynomialRing.comm_ring at K, m with base541  have outer := polynomialRing.comm_ring at polynomialRing(K, m), n with inner542  have hom := iteratedConstant.hom at K, m, n with base543  unfold iteratedPolynomialAlgebra544  exact Algebra.intro with base, outer, hom545546-- The inner flattening K[m] → K[m + n]: a ring homomorphism fixing the547-- constants and sending X_i to X_i.548theorem innerFlatten.hom549  shows innerFlatten(K, m, n) :550    polynomialRing(K, m) →+* polynomialRing(K, add(m, n))551proof552  have sumRing := polynomialRing.comm_ring at K, add(m, n) with base553  have constants := polynomialConstant.hom at K, add(m, n) with base554  have inclusion := identity.inclusion with (natural.subset_add at m, n)555  have values := variableAssignment.function with base, inclusion556  unfold innerFlatten557  exact evaluationHom.hom with base, sumRing, constants, values558559theorem innerFlatten.map_constant (a : Set)560  requires member : a ∈ Ring.carrier(K)561  shows innerFlatten(K, m, n)(polynomialConstant(K, m)(a)) =562    polynomialConstant(K, add(m, n))(a)563proof564  have sumRing := polynomialRing.comm_ring at K, add(m, n) with base565  have constants := polynomialConstant.hom at K, add(m, n) with base566  have inclusion := identity.inclusion with (natural.subset_add at m, n)567  have values := variableAssignment.function with base, inclusion568  unfold innerFlatten569  exact evaluationHom.map_constant with base, sumRing, constants, values, member570571theorem innerFlatten.map_X (i : Set)572  requires index : i ∈ m573  shows innerFlatten(K, m, n)(X(K, m, i)) = X(K, add(m, n), i)574proof575  have sumRing := polynomialRing.comm_ring at K, add(m, n) with base576  have constants := polynomialConstant.hom at K, add(m, n) with base577  have inclusion := identity.inclusion with (natural.subset_add at m, n)578  have values := variableAssignment.function with base, inclusion579  have step := evaluationHom.map_X with base, sumRing, constants, values, index580  have value := variableAssignment.apply with base, inclusion, index581  have fixed := identity.apply with index582  unfold innerFlatten583  rw [step, value, fixed]584  rfl585586-- The flattening K[m][n] → K[m + n]: a ring homomorphism extending the587-- inner flattening on the constants and sending X_j to X_{m + j}.588theorem flattenHom.hom589  shows flattenHom(K, m, n) :590    polynomialRing(polynomialRing(K, m), n) →+* polynomialRing(K, add(m, n))591proof592  have innerRing := polynomialRing.comm_ring at K, m with base593  have sumRing := polynomialRing.comm_ring at K, add(m, n) with base594  have innerHom := innerFlatten.hom at K, m, n with base595  have offset := offsetMap.function at m, n596  have values := variableAssignment.function with base, offset597  unfold flattenHom598  exact evaluationHom.hom with innerRing, sumRing, innerHom, values599600theorem flattenHom.map_inner (q : Set)601  requires member : q ∈ Ring.carrier(polynomialRing(K, m))602  shows flattenHom(K, m, n)(polynomialConstant(polynomialRing(K, m), n)(q)) =603    innerFlatten(K, m, n)(q)604proof605  have innerRing := polynomialRing.comm_ring at K, m with base606  have sumRing := polynomialRing.comm_ring at K, add(m, n) with base607  have innerHom := innerFlatten.hom at K, m, n with base608  have offset := offsetMap.function at m, n609  have values := variableAssignment.function with base, offset610  unfold flattenHom611  exact evaluationHom.map_constant with innerRing, sumRing, innerHom, values,612    member613614theorem flattenHom.map_inner_constant (a : Set)615  requires member : a ∈ Ring.carrier(K)616  shows flattenHom(K, m, n)(polynomialConstant(polynomialRing(K, m), n)(617      polynomialConstant(K, m)(a))) =618    polynomialConstant(K, add(m, n))(a)619proof620  have innerIn := polynomialConstant.mem at K, m, a with base621  have flat := flattenHom.map_inner at K, m, n, polynomialConstant(K, m)(a)622    with base, innerIn623  have flatInner := innerFlatten.map_constant at K, m, n, a with base, member624  cc625626theorem flattenHom.map_inner_X (i : Set)627  requires index : i ∈ m628  shows flattenHom(K, m, n)(629      polynomialConstant(polynomialRing(K, m), n)(X(K, m, i))) =630    X(K, add(m, n), i)631proof632  have xIn := X.mem at K, m, i with base633  have flat := flattenHom.map_inner at K, m, n, X(K, m, i) with base, xIn634  have flatInner := innerFlatten.map_X at K, m, n, i with base, index635  cc636637theorem flattenHom.map_X (j : Set)638  requires index : j ∈ n639  shows flattenHom(K, m, n)(X(polynomialRing(K, m), n, j)) =640    X(K, add(m, n), add(m, j))641proof642  have innerRing := polynomialRing.comm_ring at K, m with base643  have sumRing := polynomialRing.comm_ring at K, add(m, n) with base644  have innerHom := innerFlatten.hom at K, m, n with base645  have offset := offsetMap.function at m, n646  have values := variableAssignment.function with base, offset647  have step := evaluationHom.map_X with innerRing, sumRing, innerHom, values,648    index649  have value := variableAssignment.apply with base, offset, index650  have shifted := offsetMap.apply at m, n, j with index651  unfold flattenHom652  rw [step, value, shifted]653  rfl654655-- The unflattening K[m + n] → K[m][n]: a ring homomorphism sending the656-- constants to constants of constants, X_i for i below m to the constant657-- X_i, and X_{m + j} to X_j.658theorem unflattenHom.hom659  shows unflattenHom(K, m, n) :660    polynomialRing(K, add(m, n)) →+* polynomialRing(polynomialRing(K, m), n)661proof662  have innerRing := polynomialRing.comm_ring at K, m with base663  have outerRing := polynomialRing.comm_ring at polynomialRing(K, m), n664    with innerRing665  have scalars := iteratedConstant.hom at K, m, n with base666  have values := splitAssignment.function at K, m, n with base667  unfold unflattenHom668  exact evaluationHom.hom with base, outerRing, scalars, values669670theorem unflattenHom.map_constant (a : Set)671  requires member : a ∈ Ring.carrier(K)672  shows unflattenHom(K, m, n)(polynomialConstant(K, add(m, n))(a)) =673    polynomialConstant(polynomialRing(K, m), n)(polynomialConstant(K, m)(a))674proof675  have innerRing := polynomialRing.comm_ring at K, m with base676  have outerRing := polynomialRing.comm_ring at polynomialRing(K, m), n677    with innerRing678  have scalars := iteratedConstant.hom at K, m, n with base679  have values := splitAssignment.function at K, m, n with base680  have step := evaluationHom.map_constant with base, outerRing, scalars, values,681    member682  unfold unflattenHom683  rw step684  exact iteratedConstant.apply at K, m, n, a with base, member685686theorem unflattenHom.map_inner_X (i : Set)687  requires index : i ∈ m688  shows unflattenHom(K, m, n)(X(K, add(m, n), i)) =689    polynomialConstant(polynomialRing(K, m), n)(X(K, m, i))690proof691  have innerRing := polynomialRing.comm_ring at K, m with base692  have outerRing := polynomialRing.comm_ring at polynomialRing(K, m), n693    with innerRing694  have scalars := iteratedConstant.hom at K, m, n with base695  have values := splitAssignment.function at K, m, n with base696  have inclusion := natural.subset_add at m, n697  have input := inclusion with i, index698  have step := evaluationHom.map_X with base, outerRing, scalars, values, input699  have value := splitAssignment.inner at K, m, n, i with base, index700  unfold unflattenHom701  rw [step, value]702  rfl703704theorem unflattenHom.map_outer_X (j : Set)705  requires index : j ∈ n706  shows unflattenHom(K, m, n)(X(K, add(m, n), add(m, j))) =707    X(polynomialRing(K, m), n, j)708proof709  have innerRing := polynomialRing.comm_ring at K, m with base710  have outerRing := polynomialRing.comm_ring at polynomialRing(K, m), n711    with innerRing712  have scalars := iteratedConstant.hom at K, m, n with base713  have values := splitAssignment.function at K, m, n with base714  have input := membership.add_offset at m, n, j with index715  have step := evaluationHom.map_X with base, outerRing, scalars, values, input716  have value := splitAssignment.outer at K, m, n, j with base, index717  unfold unflattenHom718  rw [step, value]719  rfl720721-- Both are homomorphisms of algebras over K.722theorem flattenHom.algebra_hom723  shows flattenHom(K, m, n) :724    iteratedPolynomialAlgebra(K, m, n) →ₐ polynomialAlgebra(K, m + n)725proof726  have iterated := iteratedPolynomialAlgebra.algebra at K, m, n with base727  have target := polynomialAlgebra.algebra at K, add(m, n) with base728  have hom := flattenHom.hom at K, m, n with base729  unfold AlgebraHom730  refine ⟨iterated, target, ?_, ?_, ?_⟩731  . rw [iteratedPolynomialAlgebra.base, polynomialAlgebra.base]732    rfl733  . rw [iteratedPolynomialAlgebra.ring, polynomialAlgebra.ring]734    exact hom735  . intros a ha736    rw iteratedPolynomialAlgebra.base at ha737    rw [iteratedPolynomialAlgebra.map, polynomialAlgebra.map]738    rw iteratedConstant.apply at K, m, n, a with base, ha739    exact flattenHom.map_inner_constant at K, m, n, a with base, ha740741theorem unflattenHom.algebra_hom742  shows unflattenHom(K, m, n) :743    polynomialAlgebra(K, m + n) →ₐ iteratedPolynomialAlgebra(K, m, n)744proof745  have iterated := iteratedPolynomialAlgebra.algebra at K, m, n with base746  have over := iteratedPolynomialAlgebra.base at K, m, n747  have values : FunctionBetween(splitAssignment(K, m, n), add(m, n),748      algebraCarrier(iteratedPolynomialAlgebra(K, m, n)))749    rw iteratedPolynomialAlgebra.carrierOf750    exact splitAssignment.function at K, m, n with base751  have hom := evaluationHom.algebra_hom at K, add(m, n),752    iteratedPolynomialAlgebra(K, m, n), splitAssignment(K, m, n)753    with base, iterated, over, values754  rw [iteratedPolynomialAlgebra.ring, iteratedPolynomialAlgebra.map] at hom755  unfold unflattenHom756  exact hom757758-- Unflattening after flattening fixes K[m][n], and flattening after759-- unflattening fixes K[m + n].760theorem flattenHom.left_inverse761  shows ∀ p ∈ Ring.carrier(polynomialRing(polynomialRing(K, m), n)),762    unflattenHom(K, m, n)(flattenHom(K, m, n)(p)) = p763proof764  have forward := flattenHom.hom at K, m, n with base765  have backward := unflattenHom.hom at K, m, n with base766  have constants : ∀ a ∈ K,767      unflattenHom(K, m, n)(flattenHom(K, m, n)(polynomialConstant(768        polynomialRing(K, m), n)(polynomialConstant(K, m)(a)))) =769      polynomialConstant(polynomialRing(K, m), n)(polynomialConstant(K, m)(a))770    intros a ha771    have flat := flattenHom.map_inner_constant at K, m, n, a with base, ha772    have back := unflattenHom.map_constant at K, m, n, a with base, ha773    cc774  have inner : ∀ i ∈ m,775      unflattenHom(K, m, n)(flattenHom(K, m, n)(776        polynomialConstant(polynomialRing(K, m), n)(X(K, m, i)))) =777      polynomialConstant(polynomialRing(K, m), n)(X(K, m, i))778    intros i hi779    have flat := flattenHom.map_inner_X at K, m, n, i with base, hi780    have back := unflattenHom.map_inner_X at K, m, n, i with base, hi781    cc782  have outer : ∀ j ∈ n,783      unflattenHom(K, m, n)(flattenHom(K, m, n)(784        X(polynomialRing(K, m), n, j))) = X(polynomialRing(K, m), n, j)785    intros j hj786    have flat := flattenHom.map_X at K, m, n, j with base, hj787    have back := unflattenHom.map_outer_X at K, m, n, j with base, hj788    cc789  exact polynomialRing.iterated_round_trip with base, forward, backward,790    constants, inner, outer791792theorem flattenHom.right_inverse793  shows ∀ q ∈ Ring.carrier(polynomialRing(K, add(m, n))),794    flattenHom(K, m, n)(unflattenHom(K, m, n)(q)) = q795proof796  have forward := unflattenHom.hom at K, m, n with base797  have backward := flattenHom.hom at K, m, n with base798  have constants : ∀ a ∈ K,799      flattenHom(K, m, n)(unflattenHom(K, m, n)(800        polynomialConstant(K, add(m, n))(a))) =801      polynomialConstant(K, add(m, n))(a)802    intros a ha803    have back := unflattenHom.map_constant at K, m, n, a with base, ha804    have flat := flattenHom.map_inner_constant at K, m, n, a with base, ha805    cc806  have variables : ∀ k ∈ add(m, n),807      flattenHom(K, m, n)(unflattenHom(K, m, n)(X(K, add(m, n), k))) =808      X(K, add(m, n), k)809    intros k hk810    have split := membership.add_cases at m, n, k with hk811    rcases split with kIn | shifted812    . have back := unflattenHom.map_inner_X at K, m, n, k with base, kIn813      have flat := flattenHom.map_inner_X at K, m, n, k with base, kIn814      cc815    . obtain ⟨j, hj, kEq⟩ := shifted816      have back := unflattenHom.map_outer_X at K, m, n, j with base, hj817      have flat := flattenHom.map_X at K, m, n, j with base, hj818      cc819  exact polynomialRing.round_trip with base, forward, backward, constants,820    variables821822-- K[m][n] is K[m + n]: the inner variable X_i goes to X_i and the outer823-- variable X_j to X_{m + j}.824theorem polynomialRing.flatten825  shows ∃ e,826    (e : iteratedPolynomialAlgebra(K, m, n) ≃ₐ polynomialAlgebra(K, m + n)) ∧827    (∀ i ∈ m, e(polynomialConstant(polynomialRing(K, m), n)(X(K, m, i))) =828      X(K, m + n, i)) ∧829    (∀ j ∈ n, e(X(polynomialRing(K, m), n, j)) = X(K, m + n, add(m, j)))830proof831  have forward := flattenHom.algebra_hom at K, m, n with base832  have backward := unflattenHom.algebra_hom at K, m, n with base833  have leftInverse := flattenHom.left_inverse at K, m, n with base834  have rightInverse := flattenHom.right_inverse at K, m, n with base835  have left : ∀ x ∈ algebraCarrier(iteratedPolynomialAlgebra(K, m, n)),836      unflattenHom(K, m, n)(flattenHom(K, m, n)(x)) = x837    intros x hx838    rw iteratedPolynomialAlgebra.carrierOf at hx839    exact leftInverse with x, hx840  have right : ∀ y ∈ algebraCarrier(polynomialAlgebra(K, add(m, n))),841      flattenHom(K, m, n)(unflattenHom(K, m, n)(y)) = y842    intros y hy843    rw polynomialAlgebra.carrierOf at hy844    exact rightInverse with y, hy845  have iso := AlgebraIso.of_inverse with forward, backward, left, right846  have innerLaw : ∀ i ∈ m,847      flattenHom(K, m, n)(848        polynomialConstant(polynomialRing(K, m), n)(X(K, m, i))) =849      X(K, add(m, n), i)850    intros i hi851    exact flattenHom.map_inner_X at K, m, n, i with base, hi852  have outerLaw : ∀ j ∈ n,853      flattenHom(K, m, n)(X(polynomialRing(K, m), n, j)) =854      X(K, add(m, n), add(m, j))855    intros j hj856    exact flattenHom.map_X at K, m, n, j with base, hj857  witness flattenHom(K, m, n)858  exact ⟨iso, innerLaw, outerLaw⟩859860end Flattening861862-- Transport of a polynomial ring along a homomorphism φ of coefficient863-- algebras: the constants go through φ and each variable to itself.864def polynomialTransport (A C φ I : Set) : Set :=865  evaluationHom(Algebra.ring(A), polynomialRing(Algebra.ring(C), I), I,866    compose(polynomialConstant(Algebra.ring(C), I), φ,867      Ring.carrier(Algebra.ring(A)), Ring.carrier(Algebra.ring(C)),868      Ring.carrier(polynomialRing(Algebra.ring(C), I))),869    variableAssignment(Algebra.ring(C), I, I, identity(I)))870871section TransportHom872variable (A C φ I : Set)873hypothesis hom : φ : A →ₐ C874875-- The data of the transport: its constants map, a ring homomorphism, and876-- its variable assignment.877theorem polynomialTransport.scalars878  shows compose(polynomialConstant(Algebra.ring(C), I), φ,879      Ring.carrier(Algebra.ring(A)), Ring.carrier(Algebra.ring(C)),880      Ring.carrier(polynomialRing(Algebra.ring(C), I))) :881    Algebra.ring(A) →+* polynomialRing(Algebra.ring(C), I)882proof883  have ringA := Algebra.comm_ring with (AlgebraHom.source with hom)884  have ringC := Algebra.comm_ring with (AlgebraHom.target with hom)885  have ringHom := AlgebraHom.ring_hom with hom886  have constants := polynomialConstant.hom at Algebra.ring(C), I with ringC887  exact RingHom.comp with ringA, ringHom, constants888889theorem polynomialTransport.values890  shows variableAssignment(Algebra.ring(C), I, I, identity(I)) :891    I → Ring.carrier(polynomialRing(Algebra.ring(C), I))892proof893  have ringC := Algebra.comm_ring with (AlgebraHom.target with hom)894  exact variableAssignment.function with ringC, (identity.function at I)895896-- The transport is a ring homomorphism with the prescribed values.897theorem polynomialTransport.ring_hom898  shows polynomialTransport(A, C, φ, I) :899    polynomialRing(Algebra.ring(A), I) →+* polynomialRing(Algebra.ring(C), I)900proof901  have ringA := Algebra.comm_ring with (AlgebraHom.source with hom)902  have ringC := Algebra.comm_ring with (AlgebraHom.target with hom)903  have polyC := polynomialRing.comm_ring at Algebra.ring(C), I with ringC904  have scalars := polynomialTransport.scalars at A, C, φ, I with hom905  have values := polynomialTransport.values at A, C, φ, I with hom906  unfold polynomialTransport907  exact evaluationHom.hom with ringA, polyC, scalars, values908909theorem polynomialTransport.map_constant (a : Set)910  requires member : a ∈ Ring.carrier(Algebra.ring(A))911  shows polynomialTransport(A, C, φ, I)(912      polynomialConstant(Algebra.ring(A), I)(a)) =913    polynomialConstant(Algebra.ring(C), I)(φ(a))914proof915  have ringA := Algebra.comm_ring with (AlgebraHom.source with hom)916  have ringC := Algebra.comm_ring with (AlgebraHom.target with hom)917  have polyC := polynomialRing.comm_ring at Algebra.ring(C), I with ringC918  have scalars := polynomialTransport.scalars at A, C, φ, I with hom919  have values := polynomialTransport.values at A, C, φ, I with hom920  have ringHom := AlgebraHom.ring_hom with hom921  have constants := polynomialConstant.hom at Algebra.ring(C), I with ringC922  have phiFunction := ringHom.right.right.left923  have constantFunction := constants.right.right.left924  have step := evaluationHom.map_constant with ringA, polyC, scalars, values,925    member926  unfold polynomialTransport927  rw step928  exact compose.apply with phiFunction, constantFunction, member929930theorem polynomialTransport.map_X (j : Set)931  requires index : j ∈ I932  shows polynomialTransport(A, C, φ, I)(X(Algebra.ring(A), I, j)) =933    X(Algebra.ring(C), I, j)934proof935  have ringA := Algebra.comm_ring with (AlgebraHom.source with hom)936  have ringC := Algebra.comm_ring with (AlgebraHom.target with hom)937  have polyC := polynomialRing.comm_ring at Algebra.ring(C), I with ringC938  have scalars := polynomialTransport.scalars at A, C, φ, I with hom939  have values := polynomialTransport.values at A, C, φ, I with hom940  have step := evaluationHom.map_X with ringA, polyC, scalars, values, index941  have value := variableAssignment.apply with ringC, (identity.function at I),942    index943  have fixed := identity.apply with index944  unfold polynomialTransport945  rw [step, value, fixed]946  rfl947948-- The transport is a homomorphism of algebras over the common base.949theorem polynomialTransport.hom950  shows polynomialTransport(A, C, φ, I) :951    restrictScalars(polynomialAlgebra(Algebra.ring(A), I), Algebra.base(A),952      Algebra.map(A)) →ₐ953    restrictScalars(polynomialAlgebra(Algebra.ring(C), I), Algebra.base(C),954      Algebra.map(C))955proof956  have algebraA := AlgebraHom.source with hom957  have algebraC := AlgebraHom.target with hom958  have bases := AlgebraHom.base_eq with hom959  have ringA := Algebra.comm_ring with algebraA960  have ringC := Algebra.comm_ring with algebraC961  have baseA := Algebra.base_comm_ring with algebraA962  have baseC := Algebra.base_comm_ring with algebraC963  have mapA := Algebra.structure_hom with algebraA964  have mapC := Algebra.structure_hom with algebraC965  have polyA := polynomialAlgebra.algebra at Algebra.ring(A), I with ringA966  have polyC := polynomialAlgebra.algebra at Algebra.ring(C), I with ringC967  have scalarsA : RingHom(Algebra.map(A), Algebra.base(A),968      Algebra.base(polynomialAlgebra(Algebra.ring(A), I)))969    rw polynomialAlgebra.base970    exact mapA971  have scalarsC : RingHom(Algebra.map(C), Algebra.base(C),972      Algebra.base(polynomialAlgebra(Algebra.ring(C), I)))973    rw polynomialAlgebra.base974    exact mapC975  have sourceAlgebra := restrictScalars.algebra with polyA, baseA, scalarsA976  have targetAlgebra := restrictScalars.algebra with polyC, baseC, scalarsC977  have ringHom := polynomialTransport.ring_hom at A, C, φ, I with hom978  unfold AlgebraHom979  refine ⟨sourceAlgebra, targetAlgebra, ?_, ?_, ?_⟩980  . rw [restrictScalars.base, restrictScalars.base]981    exact bases982  . rw [restrictScalars.ring, restrictScalars.ring, polynomialAlgebra.ring,983      polynomialAlgebra.ring]984    exact ringHom985  . intros a ha986    rw restrictScalars.base at ha987    have haC : a ∈ Ring.carrier(Algebra.base(C))988      rw ← bases989      exact ha990    rw [restrictScalars.map, restrictScalars.map, polynomialAlgebra.map,991      polynomialAlgebra.map, polynomialAlgebra.base, polynomialAlgebra.base,992      polynomialAlgebra.carrierOf, polynomialAlgebra.carrierOf]993    have mapAFunction := mapA.right.right.left994    have mapCFunction := mapC.right.right.left995    have constantsA := polynomialConstant.hom at Algebra.ring(A), I with ringA996    have constantsC := polynomialConstant.hom at Algebra.ring(C), I with ringC997    have constAFunction := constantsA.right.right.left998    have constCFunction := constantsC.right.right.left999    have stepA := compose.apply with mapAFunction, constAFunction, ha1000    have stepC := compose.apply with mapCFunction, constCFunction, haC1001    have imageIn := FunctionBetween.apply_closed with mapAFunction, ha1002    have mapped := polynomialTransport.map_constant at A, C, φ, I,1003      Algebra.map(A)(a) with hom, imageIn1004    have agree := AlgebraHom.map_base with hom, ha1005    cc10061007end TransportHom10081009-- Transports along inverse homomorphisms are inverse on the polynomials.1010theorem polynomialTransport.inverse (A C φ ψ I : Set)1011  requires forward : φ : A →ₐ C1012  requires backward : ψ : C →ₐ A1013  requires cancel : ∀ a ∈ Ring.carrier(Algebra.ring(A)), ψ(φ(a)) = a1014  shows ∀ p ∈ Ring.carrier(polynomialRing(Algebra.ring(A), I)),1015    polynomialTransport(C, A, ψ, I)(polynomialTransport(A, C, φ, I)(p)) = p1016proof1017  have ringA := Algebra.comm_ring with (AlgebraHom.source with forward)1018  have first := polynomialTransport.ring_hom at A, C, φ, I with forward1019  have second := polynomialTransport.ring_hom at C, A, ψ, I with backward1020  have phiHom := AlgebraHom.ring_hom with forward1021  have phiFunction := phiHom.right.right.left1022  have constants : ∀ a ∈ Ring.carrier(Algebra.ring(A)),1023      polynomialTransport(C, A, ψ, I)(polynomialTransport(A, C, φ, I)(1024        polynomialConstant(Algebra.ring(A), I)(a))) =1025      polynomialConstant(Algebra.ring(A), I)(a)1026    intros a ha1027    have mappedA := polynomialTransport.map_constant at A, C, φ, I, a1028      with forward, ha1029    have imageIn := FunctionBetween.apply_closed with phiFunction, ha1030    have mappedC := polynomialTransport.map_constant at C, A, ψ, I, φ(a)1031      with backward, imageIn1032    have back := cancel with a, ha1033    cc1034  have variables : ∀ j ∈ I,1035      polynomialTransport(C, A, ψ, I)(polynomialTransport(A, C, φ, I)(1036        X(Algebra.ring(A), I, j))) = X(Algebra.ring(A), I, j)1037    intros j hj1038    have mappedA := polynomialTransport.map_X with forward, hj1039    have mappedC := polynomialTransport.map_X with backward, hj1040    cc1041  exact polynomialRing.round_trip with ringA, first, second, constants,1042    variables10431044section Transport1045variable (A C φ I : Set)1046hypothesis iso : φ : A ≃ₐ C10471048-- An isomorphism of algebras over K carries polynomial algebras over their1049-- rings to each other, as algebras over K.1050theorem polynomialAlgebra.map_iso1051  shows ∃ e,1052    (e : restrictScalars(polynomialAlgebra(Algebra.ring(A), I), Algebra.base(A),1053        Algebra.map(A)) ≃ₐ1054      restrictScalars(polynomialAlgebra(Algebra.ring(C), I), Algebra.base(C),1055        Algebra.map(C))) ∧1056    (∀ a ∈ algebraCarrier(A),1057      e(polynomialConstant(Algebra.ring(A), I)(a)) =1058        polynomialConstant(Algebra.ring(C), I)(φ(a))) ∧1059    (∀ j ∈ I, e(X(Algebra.ring(A), I, j)) = X(Algebra.ring(C), I, j))1060proof1061  have forward := iso.left1062  have bijection := iso.right1063  have backward := AlgebraIso.inverse_hom with iso1064  unfold algebraCarrier at bijection1065  -- The inverse cancels φ on the carriers, so the transports along φ and1066  -- its inverse cancel on the polynomials.1067  have leftCancel : ∀ a ∈ Ring.carrier(Algebra.ring(A)),1068      algebraInverse(φ, A, C)(φ(a)) = a1069    intros a ha1070    unfold algebraInverse1071    unfold algebraCarrier1072    exact Bijective.inverse_apply with bijection, ha1073  have rightCancel : ∀ c ∈ Ring.carrier(Algebra.ring(C)),1074      φ(algebraInverse(φ, A, C)(c)) = c1075    intros c hc1076    unfold algebraInverse1077    unfold algebraCarrier1078    exact Bijective.apply_inverse with bijection, hc1079  have forwardHom := polynomialTransport.hom at A, C, φ, I with forward1080  have backwardHom := polynomialTransport.hom at C, A, algebraInverse(φ, A, C),1081    I with backward1082  have leftInverse := polynomialTransport.inverse at _, _, _, _, I1083    with forward, backward, leftCancel1084  have rightInverse := polynomialTransport.inverse at _, _, _, _, I1085    with backward, forward, rightCancel1086  have left : ∀ x ∈ algebraCarrier(restrictScalars(1087      polynomialAlgebra(Algebra.ring(A), I), Algebra.base(A), Algebra.map(A))),1088      polynomialTransport(C, A, algebraInverse(φ, A, C), I)(1089        polynomialTransport(A, C, φ, I)(x)) = x1090    intros x hx1091    rw [restrictScalars.carrier, polynomialAlgebra.carrierOf] at hx1092    exact leftInverse with x, hx1093  have right : ∀ y ∈ algebraCarrier(restrictScalars(1094      polynomialAlgebra(Algebra.ring(C), I), Algebra.base(C), Algebra.map(C))),1095      polynomialTransport(A, C, φ, I)(1096        polynomialTransport(C, A, algebraInverse(φ, A, C), I)(y)) = y1097    intros y hy1098    rw [restrictScalars.carrier, polynomialAlgebra.carrierOf] at hy1099    exact rightInverse with y, hy1100  have transportIso := AlgebraIso.of_inverse with forwardHom, backwardHom, left,1101    right1102  have constants : ∀ a ∈ algebraCarrier(A),1103      polynomialTransport(A, C, φ, I)(1104        polynomialConstant(Algebra.ring(A), I)(a)) =1105      polynomialConstant(Algebra.ring(C), I)(φ(a))1106    intros a ha1107    unfold algebraCarrier at ha1108    exact polynomialTransport.map_constant at A, C, φ, I, a with forward, ha1109  have variables : ∀ j ∈ I,1110      polynomialTransport(A, C, φ, I)(X(Algebra.ring(A), I, j)) =1111        X(Algebra.ring(C), I, j)1112    intros j hj1113    exact polynomialTransport.map_X with forward, hj1114  witness polynomialTransport(A, C, φ, I)1115  exact ⟨transportIso, constants, variables⟩11161117end Transport1118