state
stringlengths
0
159k
srcUpToTactic
stringlengths
387
167k
nextTactic
stringlengths
3
9k
declUpToTactic
stringlengths
22
11.5k
declId
stringlengths
38
95
decl
stringlengths
16
1.89k
file_tag
stringlengths
17
73
α β γ : Type u t : Type u → Type u inst✝¹ : Traversable t inst✝ : LawfulTraversable t head✝ : α tail✝ : List α ih : FreeMonoid.toList (List.traverse (Const.mk' ∘ FreeMonoid.of) tail✝) = tail✝ | head✝ :: tail✝
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs =>
rw [← ih]; rfl
@[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs =>
Mathlib.Control.Fold.382_0.ilkJEkQU7vZZ6HB
@[simp] theorem toList_eq_self {xs : List α} : toList xs = xs
Mathlib_Control_Fold
α β γ : Type u t : Type u → Type u inst✝¹ : Traversable t inst✝ : LawfulTraversable t head✝ : α tail✝ : List α ih : FreeMonoid.toList (List.traverse (Const.mk' ∘ FreeMonoid.of) tail✝) = tail✝ | head✝ :: tail✝
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs =>
rw [← ih]
@[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs =>
Mathlib.Control.Fold.382_0.ilkJEkQU7vZZ6HB
@[simp] theorem toList_eq_self {xs : List α} : toList xs = xs
Mathlib_Control_Fold
α β γ : Type u t : Type u → Type u inst✝¹ : Traversable t inst✝ : LawfulTraversable t head✝ : α tail✝ : List α ih : FreeMonoid.toList (List.traverse (Const.mk' ∘ FreeMonoid.of) tail✝) = tail✝ | head✝ :: FreeMonoid.toList (List.traverse (Const.mk' ∘ FreeMonoid.of) tail✝)
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih];
rfl
@[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih];
Mathlib.Control.Fold.382_0.ilkJEkQU7vZZ6HB
@[simp] theorem toList_eq_self {xs : List α} : toList xs = xs
Mathlib_Control_Fold
α β γ : Type u t : Type u → Type u inst✝¹ : Traversable t inst✝ : LawfulTraversable t xs : t α ⊢ length xs = List.length (toList xs)
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih]; rfl #align traversable.to_list_eq_self Traversable.toList_eq_self theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by
unfold length
theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by
Mathlib.Control.Fold.390_0.ilkJEkQU7vZZ6HB
theorem length_toList {xs : t α} : length xs = List.length (toList xs)
Mathlib_Control_Fold
α β γ : Type u t : Type u → Type u inst✝¹ : Traversable t inst✝ : LawfulTraversable t xs : t α ⊢ (foldl (fun l x => { down := l.down + 1 }) { down := 0 } xs).down = List.length (toList xs)
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih]; rfl #align traversable.to_list_eq_self Traversable.toList_eq_self theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length
rw [foldl_toList]
theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length
Mathlib.Control.Fold.390_0.ilkJEkQU7vZZ6HB
theorem length_toList {xs : t α} : length xs = List.length (toList xs)
Mathlib_Control_Fold
α β γ : Type u t : Type u → Type u inst✝¹ : Traversable t inst✝ : LawfulTraversable t xs : t α ⊢ (List.foldl (fun l x => { down := l.down + 1 }) { down := 0 } (toList xs)).down = List.length (toList xs)
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih]; rfl #align traversable.to_list_eq_self Traversable.toList_eq_self theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList]
generalize toList xs = ys
theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList]
Mathlib.Control.Fold.390_0.ilkJEkQU7vZZ6HB
theorem length_toList {xs : t α} : length xs = List.length (toList xs)
Mathlib_Control_Fold
α β γ : Type u t : Type u → Type u inst✝¹ : Traversable t inst✝ : LawfulTraversable t xs : t α ys : List α ⊢ (List.foldl (fun l x => { down := l.down + 1 }) { down := 0 } ys).down = List.length ys
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih]; rfl #align traversable.to_list_eq_self Traversable.toList_eq_self theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys
rw [← Nat.add_zero ys.length]
theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys
Mathlib.Control.Fold.390_0.ilkJEkQU7vZZ6HB
theorem length_toList {xs : t α} : length xs = List.length (toList xs)
Mathlib_Control_Fold
α β γ : Type u t : Type u → Type u inst✝¹ : Traversable t inst✝ : LawfulTraversable t xs : t α ys : List α ⊢ (List.foldl (fun l x => { down := l.down + 1 }) { down := 0 } ys).down = List.length ys + 0
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih]; rfl #align traversable.to_list_eq_self Traversable.toList_eq_self theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys rw [← Nat.add_zero ys.length]
generalize 0 = n
theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys rw [← Nat.add_zero ys.length]
Mathlib.Control.Fold.390_0.ilkJEkQU7vZZ6HB
theorem length_toList {xs : t α} : length xs = List.length (toList xs)
Mathlib_Control_Fold
α β γ : Type u t : Type u → Type u inst✝¹ : Traversable t inst✝ : LawfulTraversable t xs : t α ys : List α n : ℕ ⊢ (List.foldl (fun l x => { down := l.down + 1 }) { down := n } ys).down = List.length ys + n
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih]; rfl #align traversable.to_list_eq_self Traversable.toList_eq_self theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys rw [← Nat.add_zero ys.length] generalize 0 = n
induction' ys with _ _ ih generalizing n
theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys rw [← Nat.add_zero ys.length] generalize 0 = n
Mathlib.Control.Fold.390_0.ilkJEkQU7vZZ6HB
theorem length_toList {xs : t α} : length xs = List.length (toList xs)
Mathlib_Control_Fold
case nil α β γ : Type u t : Type u → Type u inst✝¹ : Traversable t inst✝ : LawfulTraversable t xs : t α n : ℕ ⊢ (List.foldl (fun l x => { down := l.down + 1 }) { down := n } []).down = List.length [] + n
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih]; rfl #align traversable.to_list_eq_self Traversable.toList_eq_self theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys rw [← Nat.add_zero ys.length] generalize 0 = n induction' ys with _ _ ih generalizing n ·
simp
theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys rw [← Nat.add_zero ys.length] generalize 0 = n induction' ys with _ _ ih generalizing n ·
Mathlib.Control.Fold.390_0.ilkJEkQU7vZZ6HB
theorem length_toList {xs : t α} : length xs = List.length (toList xs)
Mathlib_Control_Fold
case cons α β γ : Type u t : Type u → Type u inst✝¹ : Traversable t inst✝ : LawfulTraversable t xs : t α head✝ : α tail✝ : List α ih : ∀ (n : ℕ), (List.foldl (fun l x => { down := l.down + 1 }) { down := n } tail✝).down = List.length tail✝ + n n : ℕ ⊢ (List.foldl (fun l x => { down := l.down + 1 }) { down := n } (head✝ :: tail✝)).down = List.length (head✝ :: tail✝) + n
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih]; rfl #align traversable.to_list_eq_self Traversable.toList_eq_self theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys rw [← Nat.add_zero ys.length] generalize 0 = n induction' ys with _ _ ih generalizing n · simp ·
simp_arith [ih]
theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys rw [← Nat.add_zero ys.length] generalize 0 = n induction' ys with _ _ ih generalizing n · simp ·
Mathlib.Control.Fold.390_0.ilkJEkQU7vZZ6HB
theorem length_toList {xs : t α} : length xs = List.length (toList xs)
Mathlib_Control_Fold
α β γ : Type u t : Type u → Type u inst✝³ : Traversable t inst✝² : LawfulTraversable t m : Type u → Type u inst✝¹ : Monad m inst✝ : LawfulMonad m f : α → β → m α x : α xs : t β ⊢ foldlm f x xs = unop ((foldlM.ofFreeMonoid f) (FreeMonoid.ofList (toList xs))) x
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih]; rfl #align traversable.to_list_eq_self Traversable.toList_eq_self theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys rw [← Nat.add_zero ys.length] generalize 0 = n induction' ys with _ _ ih generalizing n · simp · simp_arith [ih] #align traversable.length_to_list Traversable.length_toList variable {m : Type u → Type u} [Monad m] [LawfulMonad m] theorem foldlm_toList {f : α → β → m α} {x : α} {xs : t β} : foldlm f x xs = List.foldlM f x (toList xs) := calc foldlm f x xs = unop (foldlM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs)) x := by
simp only [foldlm, toList_spec, foldMap_hom_free (foldlM.ofFreeMonoid f), foldlm.ofFreeMonoid_comp_of, foldlM.get, FreeMonoid.ofList_toList]
theorem foldlm_toList {f : α → β → m α} {x : α} {xs : t β} : foldlm f x xs = List.foldlM f x (toList xs) := calc foldlm f x xs = unop (foldlM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs)) x := by
Mathlib.Control.Fold.403_0.ilkJEkQU7vZZ6HB
theorem foldlm_toList {f : α → β → m α} {x : α} {xs : t β} : foldlm f x xs = List.foldlM f x (toList xs)
Mathlib_Control_Fold
α β γ : Type u t : Type u → Type u inst✝³ : Traversable t inst✝² : LawfulTraversable t m : Type u → Type u inst✝¹ : Monad m inst✝ : LawfulMonad m f : α → β → m α x : α xs : t β ⊢ unop ((foldlM.ofFreeMonoid f) (FreeMonoid.ofList (toList xs))) x = List.foldlM f x (toList xs)
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih]; rfl #align traversable.to_list_eq_self Traversable.toList_eq_self theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys rw [← Nat.add_zero ys.length] generalize 0 = n induction' ys with _ _ ih generalizing n · simp · simp_arith [ih] #align traversable.length_to_list Traversable.length_toList variable {m : Type u → Type u} [Monad m] [LawfulMonad m] theorem foldlm_toList {f : α → β → m α} {x : α} {xs : t β} : foldlm f x xs = List.foldlM f x (toList xs) := calc foldlm f x xs = unop (foldlM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs)) x := by simp only [foldlm, toList_spec, foldMap_hom_free (foldlM.ofFreeMonoid f), foldlm.ofFreeMonoid_comp_of, foldlM.get, FreeMonoid.ofList_toList] _ = List.foldlM f x (toList xs) := by
simp [foldlM.ofFreeMonoid, unop_op, flip]
theorem foldlm_toList {f : α → β → m α} {x : α} {xs : t β} : foldlm f x xs = List.foldlM f x (toList xs) := calc foldlm f x xs = unop (foldlM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs)) x := by simp only [foldlm, toList_spec, foldMap_hom_free (foldlM.ofFreeMonoid f), foldlm.ofFreeMonoid_comp_of, foldlM.get, FreeMonoid.ofList_toList] _ = List.foldlM f x (toList xs) := by
Mathlib.Control.Fold.403_0.ilkJEkQU7vZZ6HB
theorem foldlm_toList {f : α → β → m α} {x : α} {xs : t β} : foldlm f x xs = List.foldlM f x (toList xs)
Mathlib_Control_Fold
α β γ : Type u t : Type u → Type u inst✝³ : Traversable t inst✝² : LawfulTraversable t m : Type u → Type u inst✝¹ : Monad m inst✝ : LawfulMonad m f : α → β → m β x : β xs : t α ⊢ foldrm f x xs = List.foldrM f x (toList xs)
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih]; rfl #align traversable.to_list_eq_self Traversable.toList_eq_self theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys rw [← Nat.add_zero ys.length] generalize 0 = n induction' ys with _ _ ih generalizing n · simp · simp_arith [ih] #align traversable.length_to_list Traversable.length_toList variable {m : Type u → Type u} [Monad m] [LawfulMonad m] theorem foldlm_toList {f : α → β → m α} {x : α} {xs : t β} : foldlm f x xs = List.foldlM f x (toList xs) := calc foldlm f x xs = unop (foldlM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs)) x := by simp only [foldlm, toList_spec, foldMap_hom_free (foldlM.ofFreeMonoid f), foldlm.ofFreeMonoid_comp_of, foldlM.get, FreeMonoid.ofList_toList] _ = List.foldlM f x (toList xs) := by simp [foldlM.ofFreeMonoid, unop_op, flip] #align traversable.mfoldl_to_list Traversable.foldlm_toList theorem foldrm_toList (f : α → β → m β) (x : β) (xs : t α) : foldrm f x xs = List.foldrM f x (toList xs) := by
change _ = foldrM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs) x
theorem foldrm_toList (f : α → β → m β) (x : β) (xs : t α) : foldrm f x xs = List.foldrM f x (toList xs) := by
Mathlib.Control.Fold.412_0.ilkJEkQU7vZZ6HB
theorem foldrm_toList (f : α → β → m β) (x : β) (xs : t α) : foldrm f x xs = List.foldrM f x (toList xs)
Mathlib_Control_Fold
α β γ : Type u t : Type u → Type u inst✝³ : Traversable t inst✝² : LawfulTraversable t m : Type u → Type u inst✝¹ : Monad m inst✝ : LawfulMonad m f : α → β → m β x : β xs : t α ⊢ foldrm f x xs = (foldrM.ofFreeMonoid f) (FreeMonoid.ofList (toList xs)) x
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih]; rfl #align traversable.to_list_eq_self Traversable.toList_eq_self theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys rw [← Nat.add_zero ys.length] generalize 0 = n induction' ys with _ _ ih generalizing n · simp · simp_arith [ih] #align traversable.length_to_list Traversable.length_toList variable {m : Type u → Type u} [Monad m] [LawfulMonad m] theorem foldlm_toList {f : α → β → m α} {x : α} {xs : t β} : foldlm f x xs = List.foldlM f x (toList xs) := calc foldlm f x xs = unop (foldlM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs)) x := by simp only [foldlm, toList_spec, foldMap_hom_free (foldlM.ofFreeMonoid f), foldlm.ofFreeMonoid_comp_of, foldlM.get, FreeMonoid.ofList_toList] _ = List.foldlM f x (toList xs) := by simp [foldlM.ofFreeMonoid, unop_op, flip] #align traversable.mfoldl_to_list Traversable.foldlm_toList theorem foldrm_toList (f : α → β → m β) (x : β) (xs : t α) : foldrm f x xs = List.foldrM f x (toList xs) := by change _ = foldrM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs) x
simp only [foldrm, toList_spec, foldMap_hom_free (foldrM.ofFreeMonoid f), foldrm.ofFreeMonoid_comp_of, foldrM.get, FreeMonoid.ofList_toList]
theorem foldrm_toList (f : α → β → m β) (x : β) (xs : t α) : foldrm f x xs = List.foldrM f x (toList xs) := by change _ = foldrM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs) x
Mathlib.Control.Fold.412_0.ilkJEkQU7vZZ6HB
theorem foldrm_toList (f : α → β → m β) (x : β) (xs : t α) : foldrm f x xs = List.foldrM f x (toList xs)
Mathlib_Control_Fold
α β γ : Type u t : Type u → Type u inst✝³ : Traversable t inst✝² : LawfulTraversable t m : Type u → Type u inst✝¹ : Monad m inst✝ : LawfulMonad m g : β → γ f : α → γ → m α a : α l : t β ⊢ foldlm f a (g <$> l) = foldlm (fun x y => f x (g y)) a l
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih]; rfl #align traversable.to_list_eq_self Traversable.toList_eq_self theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys rw [← Nat.add_zero ys.length] generalize 0 = n induction' ys with _ _ ih generalizing n · simp · simp_arith [ih] #align traversable.length_to_list Traversable.length_toList variable {m : Type u → Type u} [Monad m] [LawfulMonad m] theorem foldlm_toList {f : α → β → m α} {x : α} {xs : t β} : foldlm f x xs = List.foldlM f x (toList xs) := calc foldlm f x xs = unop (foldlM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs)) x := by simp only [foldlm, toList_spec, foldMap_hom_free (foldlM.ofFreeMonoid f), foldlm.ofFreeMonoid_comp_of, foldlM.get, FreeMonoid.ofList_toList] _ = List.foldlM f x (toList xs) := by simp [foldlM.ofFreeMonoid, unop_op, flip] #align traversable.mfoldl_to_list Traversable.foldlm_toList theorem foldrm_toList (f : α → β → m β) (x : β) (xs : t α) : foldrm f x xs = List.foldrM f x (toList xs) := by change _ = foldrM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs) x simp only [foldrm, toList_spec, foldMap_hom_free (foldrM.ofFreeMonoid f), foldrm.ofFreeMonoid_comp_of, foldrM.get, FreeMonoid.ofList_toList] #align traversable.mfoldr_to_list Traversable.foldrm_toList @[simp] theorem foldlm_map (g : β → γ) (f : α → γ → m α) (a : α) (l : t β) : foldlm f a (g <$> l) = foldlm (fun x y => f x (g y)) a l := by
simp only [foldlm, foldMap_map, (· ∘ ·), flip]
@[simp] theorem foldlm_map (g : β → γ) (f : α → γ → m α) (a : α) (l : t β) : foldlm f a (g <$> l) = foldlm (fun x y => f x (g y)) a l := by
Mathlib.Control.Fold.419_0.ilkJEkQU7vZZ6HB
@[simp] theorem foldlm_map (g : β → γ) (f : α → γ → m α) (a : α) (l : t β) : foldlm f a (g <$> l) = foldlm (fun x y => f x (g y)) a l
Mathlib_Control_Fold
α β γ : Type u t : Type u → Type u inst✝³ : Traversable t inst✝² : LawfulTraversable t m : Type u → Type u inst✝¹ : Monad m inst✝ : LawfulMonad m g : β → γ f : γ → α → m α a : α l : t β ⊢ foldrm f a (g <$> l) = foldrm (f ∘ g) a l
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Sean Leather -/ import Mathlib.Algebra.Group.Opposite import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Control.Traversable.Instances import Mathlib.Control.Traversable.Lemmas import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Category.KleisliCat #align_import control.fold from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # List folds generalized to `Traversable` Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the reconstructed data structure and, in a state monad, we care about the final state. The obvious way to define `foldl` would be to use the state monad but it is nicer to reason about a more abstract interface with `foldMap` as a primitive and `foldMap_hom` as a defining property. ``` def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ... lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := ... ``` `foldMap` uses a monoid ω to accumulate a value for every element of a data structure and `foldMap_hom` uses a monoid homomorphism to substitute the monoid used by `foldMap`. The two are sufficient to define `foldl`, `foldr` and `toList`. `toList` permits the formulation of specifications in terms of operations on lists. Each fold function can be defined using a specialized monoid. `toList` uses a free monoid represented as a list with concatenation while `foldl` uses endofunctions together with function composition. The definition through monoids uses `traverse` together with the applicative functor `const m` (where `m` is the monoid). As an implementation, `const` guarantees that no resource is spent on reconstructing the structure during traversal. A special class could be defined for `foldable`, similarly to Haskell, but the author cannot think of instances of `foldable` that are not also `Traversable`. -/ universe u v open ULift CategoryTheory MulOpposite namespace Monoid variable {m : Type u → Type u} [Monad m] variable {α β : Type u} /-- For a list, foldl f x [y₀,y₁] reduces as follows: ``` calc foldl f x [y₀,y₁] = foldl f (f x y₀) [y₁] : rfl ... = foldl f (f (f x y₀) y₁) [] : rfl ... = f (f x y₀) y₁ : rfl ``` with ``` f : α → β → α x : α [y₀,y₁] : List β ``` We can view the above as a composition of functions: ``` ... = f (f x y₀) y₁ : rfl ... = flip f y₁ (flip f y₀ x) : rfl ... = (flip f y₁ ∘ flip f y₀) x : rfl ``` We can use traverse and const to construct this composition: ``` calc const.run (traverse (λ y, const.mk' (flip f y)) [y₀,y₁]) x = const.run ((::) <$> const.mk' (flip f y₀) <*> traverse (λ y, const.mk' (flip f y)) [y₁]) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> traverse (λ y, const.mk' (flip f y)) [] )) x ... = const.run ((::) <$> const.mk' (flip f y₀) <*> ( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x ... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘ ((::) <$> const.mk' (flip f y₀)) ) x ... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x ... = const.run ( flip f y₁ ∘ flip f y₀ ) x ... = f (f x y₀) y₁ ``` And this is how `const` turns a monoid into an applicative functor and how the monoid of endofunctions define `Foldl`. -/ @[reducible] def Foldl (α : Type u) : Type u := (End α)ᵐᵒᵖ #align monoid.foldl Monoid.Foldl def Foldl.mk (f : α → α) : Foldl α := op f #align monoid.foldl.mk Monoid.Foldl.mk def Foldl.get (x : Foldl α) : α → α := unop x #align monoid.foldl.get Monoid.Foldl.get @[simps] def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; simp only [FreeMonoid.toList_mul, flip, unop_op, List.foldl_append, op_inj]; rfl #align monoid.foldl.of_free_monoid Monoid.Foldl.ofFreeMonoid @[reducible] def Foldr (α : Type u) : Type u := End α #align monoid.foldr Monoid.Foldr def Foldr.mk (f : α → α) : Foldr α := f #align monoid.foldr.mk Monoid.Foldr.mk def Foldr.get (x : Foldr α) : α → α := x #align monoid.foldr.get Monoid.Foldr.get @[simps] def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where toFun xs := flip (List.foldr f) (FreeMonoid.toList xs) map_one' := rfl map_mul' _ _ := funext fun _ => List.foldr_append _ _ _ _ #align monoid.foldr.of_free_monoid Monoid.Foldr.ofFreeMonoid @[reducible] def foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := MulOpposite <| End <| KleisliCat.mk m α #align monoid.mfoldl Monoid.foldlM def foldlM.mk (f : α → m α) : foldlM m α := op f #align monoid.mfoldl.mk Monoid.foldlM.mk def foldlM.get (x : foldlM m α) : α → m α := unop x #align monoid.mfoldl.get Monoid.foldlM.get @[simps] def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append #align monoid.mfoldl.of_free_monoid Monoid.foldlM.ofFreeMonoid @[reducible] def foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u := End <| KleisliCat.mk m α #align monoid.mfoldr Monoid.foldrM def foldrM.mk (f : α → m α) : foldrM m α := f #align monoid.mfoldr.mk Monoid.foldrM.mk def foldrM.get (x : foldrM m α) : α → m α := x #align monoid.mfoldr.get Monoid.foldrM.get @[simps] def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs) map_one' := rfl map_mul' := by intros; funext; apply List.foldrM_append #align monoid.mfoldr.of_free_monoid Monoid.foldrM.ofFreeMonoid end Monoid namespace Traversable open Monoid Functor section Defs variable {α β : Type u} {t : Type u → Type u} [Traversable t] def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := traverse (Const.mk' ∘ f) #align traversable.fold_map Traversable.foldMap def foldl (f : α → β → α) (x : α) (xs : t β) : α := (foldMap (Foldl.mk ∘ flip f) xs).get x #align traversable.foldl Traversable.foldl def foldr (f : α → β → β) (x : β) (xs : t α) : β := (foldMap (Foldr.mk ∘ f) xs).get x #align traversable.foldr Traversable.foldr /-- Conceptually, `toList` collects all the elements of a collection in a list. This idea is formalized by `lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`. The definition of `toList` is based on `foldl` and `List.cons` for speed. It is faster than using `foldMap FreeMonoid.mk` because, by using `foldl` and `List.cons`, each insertion is done in constant time. As a consequence, `toList` performs in linear. On the other hand, `foldMap FreeMonoid.mk` creates a singleton list around each element and concatenates all the resulting lists. In `xs ++ ys`, concatenation takes a time proportional to `length xs`. Since the order in which concatenation is evaluated is unspecified, nothing prevents each element of the traversable to be appended at the end `xs ++ [x]` which would yield a `O(n²)` run time. -/ def toList : t α → List α := List.reverse ∘ foldl (flip List.cons) [] #align traversable.to_list Traversable.toList def length (xs : t α) : ℕ := down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs #align traversable.length Traversable.length variable {m : Type u → Type u} [Monad m] def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α := (foldMap (foldlM.mk ∘ flip f) xs).get x #align traversable.mfoldl Traversable.foldlm def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β := (foldMap (foldrM.mk ∘ f) xs).get x #align traversable.mfoldr Traversable.foldrm end Defs section ApplicativeTransformation variable {α β γ : Type u} open Function hiding const def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where app _ := f preserves_seq' := by intros; simp only [Seq.seq, map_mul] preserves_pure' := by intros; simp only [map_one, pure] #align traversable.map_fold Traversable.mapFold theorem Free.map_eq_map (f : α → β) (xs : List α) : f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) := rfl #align traversable.free.map_eq_map Traversable.Free.map_eq_map theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) : unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) := rfl #align traversable.foldl.unop_of_free_monoid Traversable.foldl.unop_ofFreeMonoid variable (m : Type u → Type u) [Monad m] [LawfulMonad m] variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] open LawfulTraversable theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) : f (foldMap g x) = foldMap (f ∘ g) x := calc f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl _ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl _ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _ _ = foldMap (f ∘ g) x := rfl #align traversable.fold_map_hom Traversable.foldMap_hom theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) : f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x := foldMap_hom f _ x #align traversable.fold_map_hom_free Traversable.foldMap_hom_free end ApplicativeTransformation section Equalities open LawfulTraversable open List (cons) variable {α β γ : Type u} variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t] @[simp] theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) : Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f := rfl #align traversable.foldl.of_free_monoid_comp_of Traversable.foldl.ofFreeMonoid_comp_of @[simp] theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) : Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f := rfl #align traversable.foldr.of_free_monoid_comp_of Traversable.foldr.ofFreeMonoid_comp_of @[simp] theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) : foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by ext1 x simp [(· ∘ ·), foldlM.ofFreeMonoid, foldlM.mk, flip] rfl #align traversable.mfoldl.of_free_monoid_comp_of Traversable.foldlm.ofFreeMonoid_comp_of @[simp] theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) : foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by ext simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, flip] #align traversable.mfoldr.of_free_monoid_comp_of Traversable.foldrm.ofFreeMonoid_comp_of theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) := Eq.symm <| calc FreeMonoid.toList (foldMap FreeMonoid.of xs) = FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by simp only [List.reverse_reverse] _ = FreeMonoid.toList (List.foldr cons [] (foldMap FreeMonoid.of xs).reverse).reverse := by simp only [List.foldr_eta] _ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by simp [flip, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op] _ = toList xs := by rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))] simp only [toList, foldl, List.reverse_inj, Foldl.get, foldl.ofFreeMonoid_comp_of, Function.comp_apply] #align traversable.to_list_spec Traversable.toList_spec theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) : foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by simp only [foldMap, traverse_map, Function.comp] #align traversable.fold_map_map Traversable.foldMap_map theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) : foldl f x xs = List.foldl f x (toList xs) := by rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid] simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get, FreeMonoid.ofList_toList] #align traversable.foldl_to_list Traversable.foldl_toList theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) : foldr f x xs = List.foldr f x (toList xs) := by change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _ rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free, foldr.ofFreeMonoid_comp_of] #align traversable.foldr_to_list Traversable.foldr_toList theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList, FreeMonoid.map_of, (· ∘ ·)] #align traversable.to_list_map Traversable.toList_map @[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) : foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by simp only [foldl, foldMap_map, (· ∘ ·), flip] #align traversable.foldl_map Traversable.foldl_map @[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) : foldr f a (g <$> l) = foldr (f ∘ g) a l := by simp only [foldr, foldMap_map, (· ∘ ·), flip] #align traversable.foldr_map Traversable.foldr_map @[simp] theorem toList_eq_self {xs : List α} : toList xs = xs := by simp only [toList_spec, foldMap, traverse] induction xs case nil => rfl case cons _ _ ih => conv_rhs => rw [← ih]; rfl #align traversable.to_list_eq_self Traversable.toList_eq_self theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by unfold length rw [foldl_toList] generalize toList xs = ys rw [← Nat.add_zero ys.length] generalize 0 = n induction' ys with _ _ ih generalizing n · simp · simp_arith [ih] #align traversable.length_to_list Traversable.length_toList variable {m : Type u → Type u} [Monad m] [LawfulMonad m] theorem foldlm_toList {f : α → β → m α} {x : α} {xs : t β} : foldlm f x xs = List.foldlM f x (toList xs) := calc foldlm f x xs = unop (foldlM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs)) x := by simp only [foldlm, toList_spec, foldMap_hom_free (foldlM.ofFreeMonoid f), foldlm.ofFreeMonoid_comp_of, foldlM.get, FreeMonoid.ofList_toList] _ = List.foldlM f x (toList xs) := by simp [foldlM.ofFreeMonoid, unop_op, flip] #align traversable.mfoldl_to_list Traversable.foldlm_toList theorem foldrm_toList (f : α → β → m β) (x : β) (xs : t α) : foldrm f x xs = List.foldrM f x (toList xs) := by change _ = foldrM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs) x simp only [foldrm, toList_spec, foldMap_hom_free (foldrM.ofFreeMonoid f), foldrm.ofFreeMonoid_comp_of, foldrM.get, FreeMonoid.ofList_toList] #align traversable.mfoldr_to_list Traversable.foldrm_toList @[simp] theorem foldlm_map (g : β → γ) (f : α → γ → m α) (a : α) (l : t β) : foldlm f a (g <$> l) = foldlm (fun x y => f x (g y)) a l := by simp only [foldlm, foldMap_map, (· ∘ ·), flip] #align traversable.mfoldl_map Traversable.foldlm_map @[simp] theorem foldrm_map (g : β → γ) (f : γ → α → m α) (a : α) (l : t β) : foldrm f a (g <$> l) = foldrm (f ∘ g) a l := by
simp only [foldrm, foldMap_map, (· ∘ ·), flip]
@[simp] theorem foldrm_map (g : β → γ) (f : γ → α → m α) (a : α) (l : t β) : foldrm f a (g <$> l) = foldrm (f ∘ g) a l := by
Mathlib.Control.Fold.425_0.ilkJEkQU7vZZ6HB
@[simp] theorem foldrm_map (g : β → γ) (f : γ → α → m α) (a : α) (l : t β) : foldrm f a (g <$> l) = foldrm (f ∘ g) a l
Mathlib_Control_Fold
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ LeftInverse (Polynomial.eval₂ C (X PUnit.unit)) (eval₂ Polynomial.C fun x => Polynomial.X)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by
let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit)
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by
Mathlib.Data.MvPolynomial.Equiv.61_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R f : R[X] →+* MvPolynomial PUnit.{?u.1943 + 1} R := eval₂RingHom C (X PUnit.unit) ⊢ LeftInverse (Polynomial.eval₂ C (X PUnit.unit)) (eval₂ Polynomial.C fun x => Polynomial.X)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit)
let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit)
Mathlib.Data.MvPolynomial.Equiv.61_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R f : R[X] →+* MvPolynomial PUnit.{?u.1943 + 1} R := eval₂RingHom C (X PUnit.unit) g : MvPolynomial PUnit.{?u.2335 + 1} R →+* R[X] := eval₂Hom Polynomial.C fun x => Polynomial.X ⊢ LeftInverse (Polynomial.eval₂ C (X PUnit.unit)) (eval₂ Polynomial.C fun x => Polynomial.X)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X
show ∀ p, f.comp g p = p
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X
Mathlib.Data.MvPolynomial.Equiv.61_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R f : R[X] →+* MvPolynomial PUnit.{?u.2335 + 1} R := eval₂RingHom C (X PUnit.unit) g : MvPolynomial PUnit.{?u.2335 + 1} R →+* R[X] := eval₂Hom Polynomial.C fun x => Polynomial.X ⊢ ∀ (p : MvPolynomial PUnit.{?u.2335 + 1} R), (RingHom.comp f g) p = p
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p
apply is_id
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p
Mathlib.Data.MvPolynomial.Equiv.61_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun
Mathlib_Data_MvPolynomial_Equiv
case hC R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R f : R[X] →+* MvPolynomial PUnit.{?u.2335 + 1} R := eval₂RingHom C (X PUnit.unit) g : MvPolynomial PUnit.{?u.2335 + 1} R →+* R[X] := eval₂Hom Polynomial.C fun x => Polynomial.X ⊢ RingHom.comp (RingHom.comp f g) C = C
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id ·
ext a
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id ·
Mathlib.Data.MvPolynomial.Equiv.61_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun
Mathlib_Data_MvPolynomial_Equiv
case hC.a.a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a✝ a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R f : R[X] →+* MvPolynomial PUnit.{?u.2335 + 1} R := eval₂RingHom C (X PUnit.unit) g : MvPolynomial PUnit.{?u.2335 + 1} R →+* R[X] := eval₂Hom Polynomial.C fun x => Polynomial.X a : R m✝ : PUnit.{?u.2335 + 1} →₀ ℕ ⊢ coeff m✝ ((RingHom.comp (RingHom.comp f g) C) a) = coeff m✝ (C a)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a
dsimp
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a
Mathlib.Data.MvPolynomial.Equiv.61_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun
Mathlib_Data_MvPolynomial_Equiv
case hC.a.a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a✝ a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R f : R[X] →+* MvPolynomial PUnit.{?u.2335 + 1} R := eval₂RingHom C (X PUnit.unit) g : MvPolynomial PUnit.{?u.2335 + 1} R →+* R[X] := eval₂Hom Polynomial.C fun x => Polynomial.X a : R m✝ : PUnit.{?u.2335 + 1} →₀ ℕ ⊢ coeff m✝ (Polynomial.eval₂ C (X PUnit.unit) (eval₂ Polynomial.C (fun x => Polynomial.X) (C a))) = coeff m✝ (C a)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp
rw [eval₂_C, Polynomial.eval₂_C]
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp
Mathlib.Data.MvPolynomial.Equiv.61_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun
Mathlib_Data_MvPolynomial_Equiv
case hX R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R f : R[X] →+* MvPolynomial PUnit.{?u.2335 + 1} R := eval₂RingHom C (X PUnit.unit) g : MvPolynomial PUnit.{?u.2335 + 1} R →+* R[X] := eval₂Hom Polynomial.C fun x => Polynomial.X ⊢ ∀ (n : PUnit.{?u.2335 + 1}), (RingHom.comp f g) (X n) = X n
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] ·
rintro ⟨⟩
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] ·
Mathlib.Data.MvPolynomial.Equiv.61_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun
Mathlib_Data_MvPolynomial_Equiv
case hX.unit R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R f : R[X] →+* MvPolynomial PUnit.{?u.2335 + 1} R := eval₂RingHom C (X PUnit.unit) g : MvPolynomial PUnit.{?u.2335 + 1} R →+* R[X] := eval₂Hom Polynomial.C fun x => Polynomial.X ⊢ (RingHom.comp f g) (X PUnit.unit) = X PUnit.unit
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩
dsimp
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩
Mathlib.Data.MvPolynomial.Equiv.61_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun
Mathlib_Data_MvPolynomial_Equiv
case hX.unit R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R f : R[X] →+* MvPolynomial PUnit.{?u.2335 + 1} R := eval₂RingHom C (X PUnit.unit) g : MvPolynomial PUnit.{?u.2335 + 1} R →+* R[X] := eval₂Hom Polynomial.C fun x => Polynomial.X ⊢ Polynomial.eval₂ C (X PUnit.unit) (eval₂ Polynomial.C (fun x => Polynomial.X) (X PUnit.unit)) = X PUnit.unit
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp
rw [eval₂_X, Polynomial.eval₂_X]
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp
Mathlib.Data.MvPolynomial.Equiv.61_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a✝ a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R p : R[X] a : R ⊢ eval₂ Polynomial.C (fun x => Polynomial.X) (Polynomial.eval₂ C (X PUnit.unit) (Polynomial.C a)) = Polynomial.C a
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by
rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by
Mathlib.Data.MvPolynomial.Equiv.61_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R p✝ p q : R[X] hp : eval₂ Polynomial.C (fun x => Polynomial.X) (Polynomial.eval₂ C (X PUnit.unit) p) = p hq : eval₂ Polynomial.C (fun x => Polynomial.X) (Polynomial.eval₂ C (X PUnit.unit) q) = q ⊢ eval₂ Polynomial.C (fun x => Polynomial.X) (Polynomial.eval₂ C (X PUnit.unit) (p + q)) = p + q
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by
rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by
Mathlib.Data.MvPolynomial.Equiv.61_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R p✝ : R[X] p : ℕ n : R x✝ : eval₂ Polynomial.C (fun x => Polynomial.X) (Polynomial.eval₂ C (X PUnit.unit) (Polynomial.C n * Polynomial.X ^ p)) = Polynomial.C n * Polynomial.X ^ p ⊢ eval₂ Polynomial.C (fun x => Polynomial.X) (Polynomial.eval₂ C (X PUnit.unit) (Polynomial.C n * Polynomial.X ^ (p + 1))) = Polynomial.C n * Polynomial.X ^ (p + 1)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by
rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X]
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by
Mathlib.Data.MvPolynomial.Equiv.61_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e✝ : ℕ s : σ →₀ ℕ inst✝³ : CommSemiring R inst✝² : CommSemiring S₁ inst✝¹ : CommSemiring S₂ inst✝ : CommSemiring S₃ e : S₁ ≃+* S₂ f : S₂ ≃+* S₃ p : MvPolynomial σ S₁ ⊢ (RingEquiv.trans (mapEquiv σ e) (mapEquiv σ f)) p = (mapEquiv σ (RingEquiv.trans e f)) p
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by
simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map]
@[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by
Mathlib.Data.MvPolynomial.Equiv.115_0.88gPfxLltQQTcHM
@[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e✝ : ℕ s : σ →₀ ℕ inst✝⁶ : CommSemiring R A₁ : Type u_2 A₂ : Type u_3 A₃ : Type u_4 inst✝⁵ : CommSemiring A₁ inst✝⁴ : CommSemiring A₂ inst✝³ : CommSemiring A₃ inst✝² : Algebra R A₁ inst✝¹ : Algebra R A₂ inst✝ : Algebra R A₃ e : A₁ ≃ₐ[R] A₂ f : A₂ ≃ₐ[R] A₃ ⊢ AlgEquiv.trans (mapAlgEquiv σ e) (mapAlgEquiv σ f) = mapAlgEquiv σ (AlgEquiv.trans e f)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by
ext
@[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by
Mathlib.Data.MvPolynomial.Equiv.143_0.88gPfxLltQQTcHM
@[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f)
Mathlib_Data_MvPolynomial_Equiv
case h.a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e✝ : ℕ s : σ →₀ ℕ inst✝⁶ : CommSemiring R A₁ : Type u_2 A₂ : Type u_3 A₃ : Type u_4 inst✝⁵ : CommSemiring A₁ inst✝⁴ : CommSemiring A₂ inst✝³ : CommSemiring A₃ inst✝² : Algebra R A₁ inst✝¹ : Algebra R A₂ inst✝ : Algebra R A₃ e : A₁ ≃ₐ[R] A₂ f : A₂ ≃ₐ[R] A₃ a✝ : MvPolynomial σ A₁ m✝ : σ →₀ ℕ ⊢ coeff m✝ ((AlgEquiv.trans (mapAlgEquiv σ e) (mapAlgEquiv σ f)) a✝) = coeff m✝ ((mapAlgEquiv σ (AlgEquiv.trans e f)) a✝)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext
simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map]
@[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext
Mathlib.Data.MvPolynomial.Equiv.143_0.88gPfxLltQQTcHM
@[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f)
Mathlib_Data_MvPolynomial_Equiv
case h.a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e✝ : ℕ s : σ →₀ ℕ inst✝⁶ : CommSemiring R A₁ : Type u_2 A₂ : Type u_3 A₃ : Type u_4 inst✝⁵ : CommSemiring A₁ inst✝⁴ : CommSemiring A₂ inst✝³ : CommSemiring A₃ inst✝² : Algebra R A₁ inst✝¹ : Algebra R A₂ inst✝ : Algebra R A₃ e : A₁ ≃ₐ[R] A₂ f : A₂ ≃ₐ[R] A₃ a✝ : MvPolynomial σ A₁ m✝ : σ →₀ ℕ ⊢ coeff m✝ ((map (RingHom.comp ↑f ↑e)) a✝) = coeff m✝ ((map ↑(AlgEquiv.trans e f)) a✝)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map]
rfl
@[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map]
Mathlib.Data.MvPolynomial.Equiv.143_0.88gPfxLltQQTcHM
@[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R he : IsEmpty σ ⊢ AlgHom.comp (aeval fun a => IsEmpty.elim he a) (Algebra.ofId R (MvPolynomial σ R)) = AlgHom.id R R
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by
ext
/-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by
Mathlib.Data.MvPolynomial.Equiv.212_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R he : IsEmpty σ ⊢ AlgHom.comp (Algebra.ofId R (MvPolynomial σ R)) (aeval fun a => IsEmpty.elim he a) = AlgHom.id R (MvPolynomial σ R)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by
ext i m
/-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by
Mathlib.Data.MvPolynomial.Equiv.212_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R
Mathlib_Data_MvPolynomial_Equiv
case hf.a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R he : IsEmpty σ i : σ m : σ →₀ ℕ ⊢ coeff m ((AlgHom.comp (Algebra.ofId R (MvPolynomial σ R)) (aeval fun a => IsEmpty.elim he a)) (X i)) = coeff m ((AlgHom.id R (MvPolynomial σ R)) (X i))
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m
exact IsEmpty.elim' he i
/-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m
Mathlib.Data.MvPolynomial.Equiv.212_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ MvPolynomial (S₁ ⊕ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by
apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂)
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
case hfgC R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ RingHom.comp (RingHom.comp (sumToIter R S₁ S₂) (iterToSum R S₁ S₂)) C = C
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) ·
refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX)
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) ·
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
case hC R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ RingHom.comp (RingHom.comp (RingHom.comp (sumToIter R S₁ S₂) (iterToSum R S₁ S₂)) C) C = RingHom.comp C C case hX R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ ∀ (n : S₂), (RingHom.comp (RingHom.comp (sumToIter R S₁ S₂) (iterToSum R S₁ S₂)) C) (X n) = C (X n)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX)
case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C]
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX)
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ RingHom.comp (RingHom.comp (RingHom.comp (sumToIter R S₁ S₂) (iterToSum R S₁ S₂)) C) C = RingHom.comp C C
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX)
case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C]
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX)
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ RingHom.comp (RingHom.comp (RingHom.comp (sumToIter R S₁ S₂) (iterToSum R S₁ S₂)) C) C = RingHom.comp C C
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC =>
ext1
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC =>
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
case a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R x✝ : R ⊢ (RingHom.comp (RingHom.comp (RingHom.comp (sumToIter R S₁ S₂) (iterToSum R S₁ S₂)) C) C) x✝ = (RingHom.comp C C) x✝
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1;
simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C]
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1;
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
case hX R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ ∀ (n : S₂), (RingHom.comp (RingHom.comp (sumToIter R S₁ S₂) (iterToSum R S₁ S₂)) C) (X n) = C (X n)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C]
case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr]
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C]
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ ∀ (n : S₂), (RingHom.comp (RingHom.comp (sumToIter R S₁ S₂) (iterToSum R S₁ S₂)) C) (X n) = C (X n)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C]
case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr]
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C]
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ ∀ (n : S₂), (RingHom.comp (RingHom.comp (sumToIter R S₁ S₂) (iterToSum R S₁ S₂)) C) (X n) = C (X n)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX =>
intro
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX =>
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n✝ : S₂ ⊢ (RingHom.comp (RingHom.comp (sumToIter R S₁ S₂) (iterToSum R S₁ S₂)) C) (X n✝) = C (X n✝)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro;
simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr]
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro;
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
case hfgX R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ ∀ (n : S₁), (sumToIter R S₁ S₂) ((iterToSum R S₁ S₂) (X n)) = X n
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] ·
simp [iterToSum_X, sumToIter_Xl]
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] ·
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
case hgfC R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ RingHom.comp (RingHom.comp (iterToSum R S₁ S₂) (sumToIter R S₁ S₂)) C = C
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] ·
ext1
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] ·
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
case hgfC.a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R x✝ : R ⊢ (RingHom.comp (RingHom.comp (iterToSum R S₁ S₂) (sumToIter R S₁ S₂)) C) x✝ = C x✝
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1;
simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C]
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1;
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
case hgfX R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ ∀ (n : S₁ ⊕ S₂), (iterToSum R S₁ S₂) ((sumToIter R S₁ S₂) (X n)) = X n
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] ·
rintro ⟨⟩
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] ·
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
case hgfX.inl R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R val✝ : S₁ ⊢ (iterToSum R S₁ S₂) ((sumToIter R S₁ S₂) (X (Sum.inl val✝))) = X (Sum.inl val✝)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;>
simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X]
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;>
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
case hgfX.inr R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R val✝ : S₂ ⊢ (iterToSum R S₁ S₂) ((sumToIter R S₁ S₂) (X (Sum.inr val✝))) = X (Sum.inr val✝)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;>
simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X]
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;>
Mathlib.Data.MvPolynomial.Equiv.247_0.88gPfxLltQQTcHM
/-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R src✝ : MvPolynomial (S₁ ⊕ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := sumRingEquiv R S₁ S₂ ⊢ ∀ (r : R), Equiv.toFun src✝.toEquiv ((algebraMap R (MvPolynomial (S₁ ⊕ S₂) R)) r) = (algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R))) r
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by
intro r
/-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by
Mathlib.Data.MvPolynomial.Equiv.261_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R src✝ : MvPolynomial (S₁ ⊕ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := sumRingEquiv R S₁ S₂ r : R ⊢ Equiv.toFun src✝.toEquiv ((algebraMap R (MvPolynomial (S₁ ⊕ S₂) R)) r) = (algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R))) r
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r
have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl
/-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r
Mathlib.Data.MvPolynomial.Equiv.261_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R src✝ : MvPolynomial (S₁ ⊕ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := sumRingEquiv R S₁ S₂ r : R A : (algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R))) r = C (C r) ⊢ Equiv.toFun src✝.toEquiv ((algebraMap R (MvPolynomial (S₁ ⊕ S₂) R)) r) = (algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R))) r
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl
have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl
/-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl
Mathlib.Data.MvPolynomial.Equiv.261_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R src✝ : MvPolynomial (S₁ ⊕ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := sumRingEquiv R S₁ S₂ r : R A : (algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R))) r = C (C r) B : (algebraMap R (MvPolynomial (S₁ ⊕ S₂) R)) r = C r ⊢ Equiv.toFun src✝.toEquiv ((algebraMap R (MvPolynomial (S₁ ⊕ S₂) R)) r) = (algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R))) r
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl
simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A]
/-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl
Mathlib.Data.MvPolynomial.Equiv.261_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ AlgHom.comp (aeval fun o => Option.elim o Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (rename Option.some) (X none)) = AlgHom.id R (MvPolynomial S₁ R)[X]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by
ext : 2
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by
Mathlib.Data.MvPolynomial.Equiv.280_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R)
Mathlib_Data_MvPolynomial_Equiv
case hC.hf R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R i✝ : S₁ ⊢ (AlgHom.comp (AlgHom.comp (aeval fun o => Option.elim o Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (rename Option.some) (X none))) CAlgHom) (X i✝) = (AlgHom.comp (AlgHom.id R (MvPolynomial S₁ R)[X]) CAlgHom) (X i✝)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;>
simp [← Polynomial.C_eq_algebraMap]
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;>
Mathlib.Data.MvPolynomial.Equiv.280_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R)
Mathlib_Data_MvPolynomial_Equiv
case hX.a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n✝ : ℕ ⊢ Polynomial.coeff ((AlgHom.comp (aeval fun o => Option.elim o Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (rename Option.some) (X none))) Polynomial.X) n✝ = Polynomial.coeff ((AlgHom.id R (MvPolynomial S₁ R)[X]) Polynomial.X) n✝
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;>
simp [← Polynomial.C_eq_algebraMap]
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;>
Mathlib.Data.MvPolynomial.Equiv.280_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ AlgHom.comp (Polynomial.aevalTower (rename Option.some) (X none)) (aeval fun o => Option.elim o Polynomial.X fun s => Polynomial.C (X s)) = AlgHom.id R (MvPolynomial (Option S₁) R)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by
ext i : 2
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by
Mathlib.Data.MvPolynomial.Equiv.280_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R)
Mathlib_Data_MvPolynomial_Equiv
case hf.a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R i : Option S₁ m✝ : Option S₁ →₀ ℕ ⊢ coeff m✝ ((AlgHom.comp (Polynomial.aevalTower (rename Option.some) (X none)) (aeval fun o => Option.elim o Polynomial.X fun s => Polynomial.C (X s))) (X i)) = coeff m✝ ((AlgHom.id R (MvPolynomial (Option S₁) R)) (X i))
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2;
cases i
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2;
Mathlib.Data.MvPolynomial.Equiv.280_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R)
Mathlib_Data_MvPolynomial_Equiv
case hf.a.none R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R m✝ : Option S₁ →₀ ℕ ⊢ coeff m✝ ((AlgHom.comp (Polynomial.aevalTower (rename Option.some) (X none)) (aeval fun o => Option.elim o Polynomial.X fun s => Polynomial.C (X s))) (X none)) = coeff m✝ ((AlgHom.id R (MvPolynomial (Option S₁) R)) (X none))
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;>
simp
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;>
Mathlib.Data.MvPolynomial.Equiv.280_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R)
Mathlib_Data_MvPolynomial_Equiv
case hf.a.some R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R m✝ : Option S₁ →₀ ℕ val✝ : S₁ ⊢ coeff m✝ ((AlgHom.comp (Polynomial.aevalTower (rename Option.some) (X none)) (aeval fun o => Option.elim o Polynomial.X fun s => Polynomial.C (X s))) (X (Option.some val✝))) = coeff m✝ ((AlgHom.id R (MvPolynomial (Option S₁) R)) (X (Option.some val✝)))
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;>
simp
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;>
Mathlib.Data.MvPolynomial.Equiv.280_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ AlgHom.comp (aeval fun o => Option.elim o (C Polynomial.X) X) (aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) = AlgHom.id R (MvPolynomial S₁ R[X])
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by
ext : 2
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by
Mathlib.Data.MvPolynomial.Equiv.292_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X]
Mathlib_Data_MvPolynomial_Equiv
case h₁.hX R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ (AlgHom.comp (AlgHom.comp (aeval fun o => Option.elim o (C Polynomial.X) X) (aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i))) (IsScalarTower.toAlgHom R R[X] (MvPolynomial S₁ R[X]))) Polynomial.X = (AlgHom.comp (AlgHom.id R (MvPolynomial S₁ R[X])) (IsScalarTower.toAlgHom R R[X] (MvPolynomial S₁ R[X]))) Polynomial.X
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;>
simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;>
Mathlib.Data.MvPolynomial.Equiv.292_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X]
Mathlib_Data_MvPolynomial_Equiv
case h₂.a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R i✝ : S₁ m✝ : S₁ →₀ ℕ ⊢ coeff m✝ ((AlgHom.comp (aeval fun o => Option.elim o (C Polynomial.X) X) (aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i))) (X i✝)) = coeff m✝ ((AlgHom.id R (MvPolynomial S₁ R[X])) (X i✝))
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;>
simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;>
Mathlib.Data.MvPolynomial.Equiv.292_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X]
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R ⊢ AlgHom.comp (aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (aeval fun o => Option.elim o (C Polynomial.X) X) = AlgHom.id R (MvPolynomial (Option S₁) R)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by
ext ⟨i⟩ : 2
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by
Mathlib.Data.MvPolynomial.Equiv.292_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X]
Mathlib_Data_MvPolynomial_Equiv
case hf.none.a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R m✝ : Option S₁ →₀ ℕ ⊢ coeff m✝ ((AlgHom.comp (aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (aeval fun o => Option.elim o (C Polynomial.X) X)) (X none)) = coeff m✝ ((AlgHom.id R (MvPolynomial (Option S₁) R)) (X none))
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;>
simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;>
Mathlib.Data.MvPolynomial.Equiv.292_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X]
Mathlib_Data_MvPolynomial_Equiv
case hf.some.a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R val✝ : S₁ m✝ : Option S₁ →₀ ℕ ⊢ coeff m✝ ((AlgHom.comp (aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (aeval fun o => Option.elim o (C Polynomial.X) X)) (X (Option.some val✝))) = coeff m✝ ((AlgHom.id R (MvPolynomial (Option S₁) R)) (X (Option.some val✝)))
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;>
simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;>
Mathlib.Data.MvPolynomial.Equiv.292_0.88gPfxLltQQTcHM
/-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X]
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ ⊢ ↑(finSuccEquiv R n) = eval₂Hom (RingHom.comp Polynomial.C C) fun i => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by
ext i : 2
theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by
Mathlib.Data.MvPolynomial.Equiv.318_0.88gPfxLltQQTcHM
theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i
Mathlib_Data_MvPolynomial_Equiv
case hC.a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ i : R ⊢ (RingHom.comp (↑(finSuccEquiv R n)) C) i = (RingHom.comp (eval₂Hom (RingHom.comp Polynomial.C C) fun i => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) C) i
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 ·
simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C]
theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 ·
Mathlib.Data.MvPolynomial.Equiv.318_0.88gPfxLltQQTcHM
theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i
Mathlib_Data_MvPolynomial_Equiv
case hC.a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ i : R ⊢ (algebraMap R (MvPolynomial (Fin n) R)[X]) i = Polynomial.C (C i)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C]
rfl
theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C]
Mathlib.Data.MvPolynomial.Equiv.318_0.88gPfxLltQQTcHM
theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i
Mathlib_Data_MvPolynomial_Equiv
case hX.a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ i : Fin (n + 1) n✝ : ℕ ⊢ Polynomial.coeff (↑(finSuccEquiv R n) (X i)) n✝ = Polynomial.coeff ((eval₂Hom (RingHom.comp Polynomial.C C) fun i => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) (X i)) n✝
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl ·
refine' Fin.cases _ _ i
theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl ·
Mathlib.Data.MvPolynomial.Equiv.318_0.88gPfxLltQQTcHM
theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i
Mathlib_Data_MvPolynomial_Equiv
case hX.a.refine'_1 R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ i : Fin (n + 1) n✝ : ℕ ⊢ Polynomial.coeff (↑(finSuccEquiv R n) (X 0)) n✝ = Polynomial.coeff ((eval₂Hom (RingHom.comp Polynomial.C C) fun i => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) (X 0)) n✝
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;>
simp [finSuccEquiv]
theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;>
Mathlib.Data.MvPolynomial.Equiv.318_0.88gPfxLltQQTcHM
theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i
Mathlib_Data_MvPolynomial_Equiv
case hX.a.refine'_2 R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ i : Fin (n + 1) n✝ : ℕ ⊢ ∀ (i : Fin n), Polynomial.coeff (↑(finSuccEquiv R n) (X (Fin.succ i))) n✝ = Polynomial.coeff ((eval₂Hom (RingHom.comp Polynomial.C C) fun i => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) (X (Fin.succ i))) n✝
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;>
simp [finSuccEquiv]
theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;>
Mathlib.Data.MvPolynomial.Equiv.318_0.88gPfxLltQQTcHM
theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ p : MvPolynomial (Fin (n + 1)) R ⊢ (finSuccEquiv R n) p = (eval₂Hom (RingHom.comp Polynomial.C C) fun i => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by
rw [← finSuccEquiv_eq, RingHom.coe_coe]
@[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by
Mathlib.Data.MvPolynomial.Equiv.329_0.88gPfxLltQQTcHM
@[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p
Mathlib_Data_MvPolynomial_Equiv
R✝ : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R✝ e : ℕ s : σ →₀ ℕ inst✝¹ : CommSemiring R✝ n✝ : ℕ R : Type u inst✝ : CommSemiring R n : ℕ ⊢ RingHom.comp (↑(AlgEquiv.symm (finSuccEquiv R n))) (RingHom.comp Polynomial.C C) = C
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by
refine' RingHom.ext fun x => _
theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by
Mathlib.Data.MvPolynomial.Equiv.337_0.88gPfxLltQQTcHM
theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R)
Mathlib_Data_MvPolynomial_Equiv
R✝ : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R✝ e : ℕ s : σ →₀ ℕ inst✝¹ : CommSemiring R✝ n✝ : ℕ R : Type u inst✝ : CommSemiring R n : ℕ x : R ⊢ (RingHom.comp (↑(AlgEquiv.symm (finSuccEquiv R n))) (RingHom.comp Polynomial.C C)) x = C x
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _
rw [RingHom.comp_apply]
theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _
Mathlib.Data.MvPolynomial.Equiv.337_0.88gPfxLltQQTcHM
theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R)
Mathlib_Data_MvPolynomial_Equiv
R✝ : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R✝ e : ℕ s : σ →₀ ℕ inst✝¹ : CommSemiring R✝ n✝ : ℕ R : Type u inst✝ : CommSemiring R n : ℕ x : R ⊢ ↑(AlgEquiv.symm (finSuccEquiv R n)) ((RingHom.comp Polynomial.C C) x) = C x
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply]
refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _)
theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply]
Mathlib.Data.MvPolynomial.Equiv.337_0.88gPfxLltQQTcHM
theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R)
Mathlib_Data_MvPolynomial_Equiv
R✝ : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R✝ e : ℕ s : σ →₀ ℕ inst✝¹ : CommSemiring R✝ n✝ : ℕ R : Type u inst✝ : CommSemiring R n : ℕ x : R ⊢ (RingHom.comp Polynomial.C C) x = (finSuccEquiv R n) (C x)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _)
simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C]
theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _)
Mathlib.Data.MvPolynomial.Equiv.337_0.88gPfxLltQQTcHM
theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ ⊢ (finSuccEquiv R n) (X 0) = Polynomial.X
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by
simp
theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by
Mathlib.Data.MvPolynomial.Equiv.352_0.88gPfxLltQQTcHM
theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin n ⊢ (finSuccEquiv R n) (X (Fin.succ j)) = Polynomial.C (X j)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by
simp
theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by
Mathlib.Data.MvPolynomial.Equiv.356_0.88gPfxLltQQTcHM
theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j)
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ m : Fin n →₀ ℕ f : MvPolynomial (Fin (n + 1)) R i : ℕ ⊢ coeff m (Polynomial.coeff ((finSuccEquiv R n) f) i) = coeff (cons i m) f
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by
induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
case h1 R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin (n + 1) →₀ ℕ r : R m : Fin n →₀ ℕ i : ℕ ⊢ coeff m (Polynomial.coeff ((finSuccEquiv R n) ((monomial j) r)) i) = coeff (cons i m) ((monomial j) r) case h2 R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ p q : MvPolynomial (Fin (n + 1)) R hp : ∀ (m : Fin n →₀ ℕ) (i : ℕ), coeff m (Polynomial.coeff ((finSuccEquiv R n) p) i) = coeff (cons i m) p hq : ∀ (m : Fin n →₀ ℕ) (i : ℕ), coeff m (Polynomial.coeff ((finSuccEquiv R n) q) i) = coeff (cons i m) q m : Fin n →₀ ℕ i : ℕ ⊢ coeff m (Polynomial.coeff ((finSuccEquiv R n) (p + q)) i) = coeff (cons i m) (p + q)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m
swap
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
case h2 R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ p q : MvPolynomial (Fin (n + 1)) R hp : ∀ (m : Fin n →₀ ℕ) (i : ℕ), coeff m (Polynomial.coeff ((finSuccEquiv R n) p) i) = coeff (cons i m) p hq : ∀ (m : Fin n →₀ ℕ) (i : ℕ), coeff m (Polynomial.coeff ((finSuccEquiv R n) q) i) = coeff (cons i m) q m : Fin n →₀ ℕ i : ℕ ⊢ coeff m (Polynomial.coeff ((finSuccEquiv R n) (p + q)) i) = coeff (cons i m) (p + q)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap ·
simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq]
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap ·
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
case h1 R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin (n + 1) →₀ ℕ r : R m : Fin n →₀ ℕ i : ℕ ⊢ coeff m (Polynomial.coeff ((finSuccEquiv R n) ((monomial j) r)) i) = coeff (cons i m) ((monomial j) r)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq]
simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply]
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq]
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
case h1 R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin (n + 1) →₀ ℕ r : R m : Fin n →₀ ℕ i : ℕ ⊢ r * coeff m (Polynomial.coeff (Polynomial.X ^ j 0 * Polynomial.C (∏ x : Fin n, X x ^ j (Fin.succ x))) i) = if j = cons i m then r else 0
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply]
rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply]
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
case h1 R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin (n + 1) →₀ ℕ r : R m : Fin n →₀ ℕ i : ℕ ⊢ r * coeff m (if i = j 0 then ∏ x : Fin n, X x ^ j (Fin.succ x) else 0) = r * if j = cons i m then 1 else 0
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow];
congr 1
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow];
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
case h1.e_a R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin (n + 1) →₀ ℕ r : R m : Fin n →₀ ℕ i : ℕ ⊢ coeff m (if i = j 0 then ∏ x : Fin n, X x ^ j (Fin.succ x) else 0) = if j = cons i m then 1 else 0
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1
obtain rfl | hjmi := eq_or_ne j (m.cons i)
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
case h1.e_a.inl R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ r : R m : Fin n →₀ ℕ i : ℕ ⊢ coeff m (if i = (cons i m) 0 then ∏ x : Fin n, X x ^ (cons i m) (Fin.succ x) else 0) = if cons i m = cons i m then 1 else 0
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) ·
simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R)
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) ·
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
case h1.e_a.inr R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin (n + 1) →₀ ℕ r : R m : Fin n →₀ ℕ i : ℕ hjmi : j ≠ cons i m ⊢ coeff m (if i = j 0 then ∏ x : Fin n, X x ^ j (Fin.succ x) else 0) = if j = cons i m then 1 else 0
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) ·
simp only [hjmi, if_false]
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) ·
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
case h1.e_a.inr R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin (n + 1) →₀ ℕ r : R m : Fin n →₀ ℕ i : ℕ hjmi : j ≠ cons i m ⊢ coeff m (if i = j 0 then ∏ x : Fin n, X x ^ j (Fin.succ x) else 0) = 0
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false]
obtain hij | rfl := ne_or_eq i (j 0)
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false]
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
case h1.e_a.inr.inl R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin (n + 1) →₀ ℕ r : R m : Fin n →₀ ℕ i : ℕ hjmi : j ≠ cons i m hij : i ≠ j 0 ⊢ coeff m (if i = j 0 then ∏ x : Fin n, X x ^ j (Fin.succ x) else 0) = 0
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) ·
simp only [hij, if_false, coeff_zero]
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) ·
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
case h1.e_a.inr.inr R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin (n + 1) →₀ ℕ r : R m : Fin n →₀ ℕ hjmi : j ≠ cons (j 0) m ⊢ coeff m (if j 0 = j 0 then ∏ x : Fin n, X x ^ j (Fin.succ x) else 0) = 0
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) · simp only [hij, if_false, coeff_zero]
simp only [eq_self_iff_true, if_true]
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) · simp only [hij, if_false, coeff_zero]
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
case h1.e_a.inr.inr R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin (n + 1) →₀ ℕ r : R m : Fin n →₀ ℕ hjmi : j ≠ cons (j 0) m ⊢ coeff m (∏ x : Fin n, X x ^ j (Fin.succ x)) = 0
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) · simp only [hij, if_false, coeff_zero] simp only [eq_self_iff_true, if_true]
have hmj : m ≠ j.tail := by rintro rfl rw [cons_tail] at hjmi contradiction
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) · simp only [hij, if_false, coeff_zero] simp only [eq_self_iff_true, if_true]
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin (n + 1) →₀ ℕ r : R m : Fin n →₀ ℕ hjmi : j ≠ cons (j 0) m ⊢ m ≠ tail j
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) · simp only [hij, if_false, coeff_zero] simp only [eq_self_iff_true, if_true] have hmj : m ≠ j.tail := by
rintro rfl
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) · simp only [hij, if_false, coeff_zero] simp only [eq_self_iff_true, if_true] have hmj : m ≠ j.tail := by
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin (n + 1) →₀ ℕ r : R hjmi : j ≠ cons (j 0) (tail j) ⊢ False
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) · simp only [hij, if_false, coeff_zero] simp only [eq_self_iff_true, if_true] have hmj : m ≠ j.tail := by rintro rfl
rw [cons_tail] at hjmi
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) · simp only [hij, if_false, coeff_zero] simp only [eq_self_iff_true, if_true] have hmj : m ≠ j.tail := by rintro rfl
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin (n + 1) →₀ ℕ r : R hjmi : j ≠ j ⊢ False
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) · simp only [hij, if_false, coeff_zero] simp only [eq_self_iff_true, if_true] have hmj : m ≠ j.tail := by rintro rfl rw [cons_tail] at hjmi
contradiction
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) · simp only [hij, if_false, coeff_zero] simp only [eq_self_iff_true, if_true] have hmj : m ≠ j.tail := by rintro rfl rw [cons_tail] at hjmi
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv
case h1.e_a.inr.inr R : Type u S₁ : Type v S₂ : Type w S₃ : Type x σ : Type u_1 a a' a₁ a₂ : R e : ℕ s : σ →₀ ℕ inst✝ : CommSemiring R n : ℕ j : Fin (n + 1) →₀ ℕ r : R m : Fin n →₀ ℕ hjmi : j ≠ cons (j 0) m hmj : m ≠ tail j ⊢ coeff m (∏ x : Fin n, X x ^ j (Fin.succ x)) = 0
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.MvPolynomial.Rename import Mathlib.Data.Polynomial.AlgebraMap import Mathlib.Data.MvPolynomial.Variables import Mathlib.Data.Finsupp.Fin import Mathlib.Logic.Equiv.Fin import Mathlib.Algebra.BigOperators.Fin #align_import data.mv_polynomial.equiv from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Equivalences between polynomial rings This file establishes a number of equivalences between polynomial rings, based on equivalences between the underlying types. ## Notation As in other polynomial files, we typically use the notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ## Tags equivalence, isomorphism, morphism, ring hom, hom -/ noncomputable section open BigOperators Polynomial Set Function Finsupp AddMonoidAlgebra universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} namespace MvPolynomial variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {s : σ →₀ ℕ} section Equiv variable (R) [CommSemiring R] /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ @[simps] def pUnitAlgEquiv : MvPolynomial PUnit R ≃ₐ[R] R[X] where toFun := eval₂ Polynomial.C fun _ => Polynomial.X invFun := Polynomial.eval₂ MvPolynomial.C (X PUnit.unit) left_inv := by let f : R[X] →+* MvPolynomial PUnit R := Polynomial.eval₂RingHom MvPolynomial.C (X PUnit.unit) let g : MvPolynomial PUnit R →+* R[X] := eval₂Hom Polynomial.C fun _ => Polynomial.X show ∀ p, f.comp g p = p apply is_id · ext a dsimp rw [eval₂_C, Polynomial.eval₂_C] · rintro ⟨⟩ dsimp rw [eval₂_X, Polynomial.eval₂_X] right_inv p := Polynomial.induction_on p (fun a => by rw [Polynomial.eval₂_C, MvPolynomial.eval₂_C]) (fun p q hp hq => by rw [Polynomial.eval₂_add, MvPolynomial.eval₂_add, hp, hq]) fun p n _ => by rw [Polynomial.eval₂_mul, Polynomial.eval₂_pow, Polynomial.eval₂_X, Polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X] map_mul' _ _ := eval₂_mul _ _ map_add' _ _ := eval₂_add _ _ commutes' _ := eval₂_C _ _ _ #align mv_polynomial.punit_alg_equiv MvPolynomial.pUnitAlgEquiv section Map variable {R} (σ) /-- If `e : A ≃+* B` is an isomorphism of rings, then so is `map e`. -/ @[simps apply] def mapEquiv [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : MvPolynomial σ S₁ ≃+* MvPolynomial σ S₂ := { map (e : S₁ →+* S₂) with toFun := map (e : S₁ →+* S₂) invFun := map (e.symm : S₂ →+* S₁) left_inv := map_leftInverse e.left_inv right_inv := map_rightInverse e.right_inv } #align mv_polynomial.map_equiv MvPolynomial.mapEquiv @[simp] theorem mapEquiv_refl : mapEquiv σ (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.ext map_id #align mv_polynomial.map_equiv_refl MvPolynomial.mapEquiv_refl @[simp] theorem mapEquiv_symm [CommSemiring S₁] [CommSemiring S₂] (e : S₁ ≃+* S₂) : (mapEquiv σ e).symm = mapEquiv σ e.symm := rfl #align mv_polynomial.map_equiv_symm MvPolynomial.mapEquiv_symm @[simp] theorem mapEquiv_trans [CommSemiring S₁] [CommSemiring S₂] [CommSemiring S₃] (e : S₁ ≃+* S₂) (f : S₂ ≃+* S₃) : (mapEquiv σ e).trans (mapEquiv σ f) = mapEquiv σ (e.trans f) := RingEquiv.ext fun p => by simp only [RingEquiv.coe_trans, comp_apply, mapEquiv_apply, RingEquiv.coe_ringHom_trans, map_map] #align mv_polynomial.map_equiv_trans MvPolynomial.mapEquiv_trans variable {A₁ A₂ A₃ : Type*} [CommSemiring A₁] [CommSemiring A₂] [CommSemiring A₃] variable [Algebra R A₁] [Algebra R A₂] [Algebra R A₃] /-- If `e : A ≃ₐ[R] B` is an isomorphism of `R`-algebras, then so is `map e`. -/ @[simps apply] def mapAlgEquiv (e : A₁ ≃ₐ[R] A₂) : MvPolynomial σ A₁ ≃ₐ[R] MvPolynomial σ A₂ := { mapAlgHom (e : A₁ →ₐ[R] A₂), mapEquiv σ (e : A₁ ≃+* A₂) with toFun := map (e : A₁ →+* A₂) } #align mv_polynomial.map_alg_equiv MvPolynomial.mapAlgEquiv @[simp] theorem mapAlgEquiv_refl : mapAlgEquiv σ (AlgEquiv.refl : A₁ ≃ₐ[R] A₁) = AlgEquiv.refl := AlgEquiv.ext map_id #align mv_polynomial.map_alg_equiv_refl MvPolynomial.mapAlgEquiv_refl @[simp] theorem mapAlgEquiv_symm (e : A₁ ≃ₐ[R] A₂) : (mapAlgEquiv σ e).symm = mapAlgEquiv σ e.symm := rfl #align mv_polynomial.map_alg_equiv_symm MvPolynomial.mapAlgEquiv_symm @[simp] theorem mapAlgEquiv_trans (e : A₁ ≃ₐ[R] A₂) (f : A₂ ≃ₐ[R] A₃) : (mapAlgEquiv σ e).trans (mapAlgEquiv σ f) = mapAlgEquiv σ (e.trans f) := by ext simp only [AlgEquiv.trans_apply, mapAlgEquiv_apply, map_map] rfl #align mv_polynomial.map_alg_equiv_trans MvPolynomial.mapAlgEquiv_trans end Map section variable (S₁ S₂ S₃) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. See `sumRingEquiv` for the ring isomorphism. -/ def sumToIter : MvPolynomial (Sum S₁ S₂) R →+* MvPolynomial S₁ (MvPolynomial S₂ R) := eval₂Hom (C.comp C) fun bc => Sum.recOn bc X (C ∘ X) #align mv_polynomial.sum_to_iter MvPolynomial.sumToIter @[simp] theorem sumToIter_C (a : R) : sumToIter R S₁ S₂ (C a) = C (C a) := eval₂_C _ _ a set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_C MvPolynomial.sumToIter_C @[simp] theorem sumToIter_Xl (b : S₁) : sumToIter R S₁ S₂ (X (Sum.inl b)) = X b := eval₂_X _ _ (Sum.inl b) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xl MvPolynomial.sumToIter_Xl @[simp] theorem sumToIter_Xr (c : S₂) : sumToIter R S₁ S₂ (X (Sum.inr c)) = C (X c) := eval₂_X _ _ (Sum.inr c) set_option linter.uppercaseLean3 false in #align mv_polynomial.sum_to_iter_Xr MvPolynomial.sumToIter_Xr /-- The function from multivariable polynomials in one type, with coefficients in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sumRingEquiv` for the ring isomorphism. -/ def iterToSum : MvPolynomial S₁ (MvPolynomial S₂ R) →+* MvPolynomial (Sum S₁ S₂) R := eval₂Hom (eval₂Hom C (X ∘ Sum.inr)) (X ∘ Sum.inl) #align mv_polynomial.iter_to_sum MvPolynomial.iterToSum theorem iterToSum_C_C (a : R) : iterToSum R S₁ S₂ (C (C a)) = C a := Eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_C MvPolynomial.iterToSum_C_C theorem iterToSum_X (b : S₁) : iterToSum R S₁ S₂ (X b) = X (Sum.inl b) := eval₂_X _ _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_X MvPolynomial.iterToSum_X theorem iterToSum_C_X (c : S₂) : iterToSum R S₁ S₂ (C (X c)) = X (Sum.inr c) := Eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.iter_to_sum_C_X MvPolynomial.iterToSum_C_X variable (σ) /-- The algebra isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyAlgEquiv [he : IsEmpty σ] : MvPolynomial σ R ≃ₐ[R] R := AlgEquiv.ofAlgHom (aeval (IsEmpty.elim he)) (Algebra.ofId _ _) (by ext) (by ext i m exact IsEmpty.elim' he i) #align mv_polynomial.is_empty_alg_equiv MvPolynomial.isEmptyAlgEquiv /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ @[simps!] def isEmptyRingEquiv [IsEmpty σ] : MvPolynomial σ R ≃+* R := (isEmptyAlgEquiv R σ).toRingEquiv #align mv_polynomial.is_empty_ring_equiv MvPolynomial.isEmptyRingEquiv variable {σ} /-- A helper function for `sumRingEquiv`. -/ @[simps] def mvPolynomialEquivMvPolynomial [CommSemiring S₃] (f : MvPolynomial S₁ R →+* MvPolynomial S₂ S₃) (g : MvPolynomial S₂ S₃ →+* MvPolynomial S₁ R) (hfgC : (f.comp g).comp C = C) (hfgX : ∀ n, f (g (X n)) = X n) (hgfC : (g.comp f).comp C = C) (hgfX : ∀ n, g (f (X n)) = X n) : MvPolynomial S₁ R ≃+* MvPolynomial S₂ S₃ where toFun := f invFun := g left_inv := is_id (RingHom.comp _ _) hgfC hgfX right_inv := is_id (RingHom.comp _ _) hfgC hfgX map_mul' := f.map_mul map_add' := f.map_add #align mv_polynomial.mv_polynomial_equiv_mv_polynomial MvPolynomial.mvPolynomialEquivMvPolynomial /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumRingEquiv : MvPolynomial (Sum S₁ S₂) R ≃+* MvPolynomial S₁ (MvPolynomial S₂ R) := by apply mvPolynomialEquivMvPolynomial R (Sum S₁ S₂) _ _ (sumToIter R S₁ S₂) (iterToSum R S₁ S₂) · refine RingHom.ext (hom_eq_hom _ _ ?hC ?hX) case hC => ext1; simp only [RingHom.comp_apply, iterToSum_C_C, sumToIter_C] case hX => intro; simp only [RingHom.comp_apply, iterToSum_C_X, sumToIter_Xr] · simp [iterToSum_X, sumToIter_Xl] · ext1; simp only [RingHom.comp_apply, sumToIter_C, iterToSum_C_C] · rintro ⟨⟩ <;> simp only [sumToIter_Xl, iterToSum_X, sumToIter_Xr, iterToSum_C_X] #align mv_polynomial.sum_ring_equiv MvPolynomial.sumRingEquiv /-- The algebra isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficients in multivariable polynomials in the other type. -/ def sumAlgEquiv : MvPolynomial (Sum S₁ S₂) R ≃ₐ[R] MvPolynomial S₁ (MvPolynomial S₂ R) := { sumRingEquiv R S₁ S₂ with commutes' := by intro r have A : algebraMap R (MvPolynomial S₁ (MvPolynomial S₂ R)) r = (C (C r) : _) := rfl have B : algebraMap R (MvPolynomial (Sum S₁ S₂) R) r = C r := rfl simp only [sumRingEquiv, mvPolynomialEquivMvPolynomial, Equiv.toFun_as_coe, Equiv.coe_fn_mk, B, sumToIter_C, A] } #align mv_polynomial.sum_alg_equiv MvPolynomial.sumAlgEquiv section -- this speeds up typeclass search in the lemma below attribute [local instance] IsScalarTower.right /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and polynomials with coefficients in `MvPolynomial S₁ R`. -/ @[simps!] def optionEquivLeft : MvPolynomial (Option S₁) R ≃ₐ[R] Polynomial (MvPolynomial S₁ R) := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim Polynomial.X fun s => Polynomial.C (X s)) (Polynomial.aevalTower (MvPolynomial.rename some) (X none)) (by ext : 2 <;> simp [← Polynomial.C_eq_algebraMap]) (by ext i : 2; cases i <;> simp) #align mv_polynomial.option_equiv_left MvPolynomial.optionEquivLeft end /-- The algebra isomorphism between multivariable polynomials in `Option S₁` and multivariable polynomials with coefficients in polynomials. -/ def optionEquivRight : MvPolynomial (Option S₁) R ≃ₐ[R] MvPolynomial S₁ R[X] := AlgEquiv.ofAlgHom (MvPolynomial.aeval fun o => o.elim (C Polynomial.X) X) (MvPolynomial.aevalTower (Polynomial.aeval (X none)) fun i => X (Option.some i)) (by ext : 2 <;> simp only [MvPolynomial.algebraMap_eq, Option.elim, AlgHom.coe_comp, AlgHom.id_comp, IsScalarTower.coe_toAlgHom', comp_apply, aevalTower_C, Polynomial.aeval_X, aeval_X, Option.elim', aevalTower_X, AlgHom.coe_id, id.def, eq_self_iff_true, imp_true_iff]) (by ext ⟨i⟩ : 2 <;> simp only [Option.elim, AlgHom.coe_comp, comp_apply, aeval_X, aevalTower_C, Polynomial.aeval_X, AlgHom.coe_id, id.def, aevalTower_X]) #align mv_polynomial.option_equiv_right MvPolynomial.optionEquivRight variable (n : ℕ) /-- The algebra isomorphism between multivariable polynomials in `Fin (n + 1)` and polynomials over multivariable polynomials in `Fin n`. -/ def finSuccEquiv : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] Polynomial (MvPolynomial (Fin n) R) := (renameEquiv R (_root_.finSuccEquiv n)).trans (optionEquivLeft R (Fin n)) #align mv_polynomial.fin_succ_equiv MvPolynomial.finSuccEquiv theorem finSuccEquiv_eq : (finSuccEquiv R n : MvPolynomial (Fin (n + 1)) R →+* Polynomial (MvPolynomial (Fin n) R)) = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i := by ext i : 2 · simp only [finSuccEquiv, optionEquivLeft_apply, aeval_C, AlgEquiv.coe_trans, RingHom.coe_coe, coe_eval₂Hom, comp_apply, renameEquiv_apply, eval₂_C, RingHom.coe_comp, rename_C] rfl · refine' Fin.cases _ _ i <;> simp [finSuccEquiv] #align mv_polynomial.fin_succ_equiv_eq MvPolynomial.finSuccEquiv_eq @[simp] theorem finSuccEquiv_apply (p : MvPolynomial (Fin (n + 1)) R) : finSuccEquiv R n p = eval₂Hom (Polynomial.C.comp (C : R →+* MvPolynomial (Fin n) R)) (fun i : Fin (n + 1) => Fin.cases Polynomial.X (fun k => Polynomial.C (X k)) i) p := by rw [← finSuccEquiv_eq, RingHom.coe_coe] #align mv_polynomial.fin_succ_equiv_apply MvPolynomial.finSuccEquiv_apply theorem finSuccEquiv_comp_C_eq_C {R : Type u} [CommSemiring R] (n : ℕ) : (↑(MvPolynomial.finSuccEquiv R n).symm : Polynomial (MvPolynomial (Fin n) R) →+* _).comp (Polynomial.C.comp MvPolynomial.C) = (MvPolynomial.C : R →+* MvPolynomial (Fin n.succ) R) := by refine' RingHom.ext fun x => _ rw [RingHom.comp_apply] refine' (MvPolynomial.finSuccEquiv R n).injective (Trans.trans ((MvPolynomial.finSuccEquiv R n).apply_symm_apply _) _) simp only [MvPolynomial.finSuccEquiv_apply, MvPolynomial.eval₂Hom_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_comp_C_eq_C MvPolynomial.finSuccEquiv_comp_C_eq_C variable {n} {R} theorem finSuccEquiv_X_zero : finSuccEquiv R n (X 0) = Polynomial.X := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_zero MvPolynomial.finSuccEquiv_X_zero theorem finSuccEquiv_X_succ {j : Fin n} : finSuccEquiv R n (X j.succ) = Polynomial.C (X j) := by simp set_option linter.uppercaseLean3 false in #align mv_polynomial.fin_succ_equiv_X_succ MvPolynomial.finSuccEquiv_X_succ /-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) · simp only [hij, if_false, coeff_zero] simp only [eq_self_iff_true, if_true] have hmj : m ≠ j.tail := by rintro rfl rw [cons_tail] at hjmi contradiction
simpa only [monomial_eq, C_1, one_mul, prod_pow, Finsupp.tail_apply, if_neg hmj.symm] using coeff_monomial m j.tail (1 : R)
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f := by induction' f using MvPolynomial.induction_on' with j r p q hp hq generalizing i m swap · simp only [(finSuccEquiv R n).map_add, Polynomial.coeff_add, coeff_add, hp, hq] simp only [finSuccEquiv_apply, coe_eval₂Hom, eval₂_monomial, RingHom.coe_comp, prod_pow, Polynomial.coeff_C_mul, coeff_C_mul, coeff_monomial, Fin.prod_univ_succ, Fin.cases_zero, Fin.cases_succ, ← map_prod, ← RingHom.map_pow, Function.comp_apply] rw [← mul_boole, mul_comm (Polynomial.X ^ j 0), Polynomial.coeff_C_mul_X_pow]; congr 1 obtain rfl | hjmi := eq_or_ne j (m.cons i) · simpa only [cons_zero, cons_succ, if_pos rfl, monomial_eq, C_1, one_mul, prod_pow] using coeff_monomial m m (1 : R) · simp only [hjmi, if_false] obtain hij | rfl := ne_or_eq i (j 0) · simp only [hij, if_false, coeff_zero] simp only [eq_self_iff_true, if_true] have hmj : m ≠ j.tail := by rintro rfl rw [cons_tail] at hjmi contradiction
Mathlib.Data.MvPolynomial.Equiv.361_0.88gPfxLltQQTcHM
/-- The coefficient of `m` in the `i`-th coefficient of `finSuccEquiv R n f` equals the coefficient of `Finsupp.cons i m` in `f`. -/ theorem finSuccEquiv_coeff_coeff (m : Fin n →₀ ℕ) (f : MvPolynomial (Fin (n + 1)) R) (i : ℕ) : coeff m (Polynomial.coeff (finSuccEquiv R n f) i) = coeff (m.cons i) f
Mathlib_Data_MvPolynomial_Equiv