|
| 1 | +/- |
| 2 | +Copyright (c) 2024 Salvatore Mercuri. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Salvatore Mercuri |
| 5 | +-/ |
| 6 | +import Mathlib.Algebra.Group.Basic |
| 7 | +import Mathlib.Algebra.Order.AbsoluteValue |
| 8 | +import Mathlib.Analysis.Normed.Field.Basic |
| 9 | + |
| 10 | +/-! |
| 11 | +# WithAbs |
| 12 | +
|
| 13 | +`WithAbs v` is a type synonym for a semiring `R` which depends on an absolute value. The point of |
| 14 | +this is to allow the type class inference system to handle multiple sources of instances that |
| 15 | +arise from absolute values. See `NumberTheory.NumberField.Completion` for an example of this |
| 16 | +being used to define Archimedean completions of a number field. |
| 17 | +
|
| 18 | +## Main definitions |
| 19 | + - `WithAbs` : type synonym for a semiring which depends on an absolute value. This is |
| 20 | + a function that takes an absolute value on a semiring and returns the semiring. This can be used |
| 21 | + to assign and infer instances on a semiring that depend on absolute values. |
| 22 | + - `WithAbs.equiv v` : the canonical (type) equivalence between `WithAbs v` and `R`. |
| 23 | + - `WithAbs.ringEquiv v` : The canonical ring equivalence between `WithAbs v` and `R`. |
| 24 | +-/ |
| 25 | +noncomputable section |
| 26 | + |
| 27 | +variable {R S K : Type*} [Semiring R] [OrderedSemiring S] [Field K] |
| 28 | + |
| 29 | +/-- Type synonym for a semiring which depends on an absolute value. This is a function that takes |
| 30 | +an absolute value on a semiring and returns the semiring. We use this to assign and infer instances |
| 31 | +on a semiring that depend on absolute values. -/ |
| 32 | +@[nolint unusedArguments] |
| 33 | +def WithAbs : AbsoluteValue R S → Type _ := fun _ => R |
| 34 | + |
| 35 | +namespace WithAbs |
| 36 | + |
| 37 | +variable (v : AbsoluteValue R ℝ) |
| 38 | + |
| 39 | +/-- Canonical equivalence between `WithAbs v` and `R`. -/ |
| 40 | +def equiv : WithAbs v ≃ R := Equiv.refl (WithAbs v) |
| 41 | + |
| 42 | +instance instNonTrivial [Nontrivial R] : Nontrivial (WithAbs v) := inferInstanceAs (Nontrivial R) |
| 43 | + |
| 44 | +instance instUnique [Unique R] : Unique (WithAbs v) := inferInstanceAs (Unique R) |
| 45 | + |
| 46 | +instance instSemiring : Semiring (WithAbs v) := inferInstanceAs (Semiring R) |
| 47 | + |
| 48 | +instance instRing [Ring R] : Ring (WithAbs v) := inferInstanceAs (Ring R) |
| 49 | + |
| 50 | +instance instInhabited : Inhabited (WithAbs v) := ⟨0⟩ |
| 51 | + |
| 52 | +instance normedRing {R : Type*} [Ring R] (v : AbsoluteValue R ℝ) : NormedRing (WithAbs v) := |
| 53 | + v.toNormedRing |
| 54 | + |
| 55 | +instance normedField (v : AbsoluteValue K ℝ) : NormedField (WithAbs v) := |
| 56 | + v.toNormedField |
| 57 | + |
| 58 | +/-! `WithAbs.equiv` preserves the ring structure. -/ |
| 59 | + |
| 60 | +variable (x y : WithAbs v) (r s : R) |
| 61 | +@[simp] |
| 62 | +theorem equiv_zero : WithAbs.equiv v 0 = 0 := rfl |
| 63 | + |
| 64 | +@[simp] |
| 65 | +theorem equiv_symm_zero : (WithAbs.equiv v).symm 0 = 0 := rfl |
| 66 | + |
| 67 | +@[simp] |
| 68 | +theorem equiv_add : WithAbs.equiv v (x + y) = WithAbs.equiv v x + WithAbs.equiv v y := rfl |
| 69 | + |
| 70 | +@[simp] |
| 71 | +theorem equiv_symm_add : |
| 72 | + (WithAbs.equiv v).symm (r + s) = (WithAbs.equiv v).symm r + (WithAbs.equiv v).symm s := |
| 73 | + rfl |
| 74 | + |
| 75 | +@[simp] |
| 76 | +theorem equiv_sub [Ring R] : WithAbs.equiv v (x - y) = WithAbs.equiv v x - WithAbs.equiv v y := rfl |
| 77 | + |
| 78 | +@[simp] |
| 79 | +theorem equiv_symm_sub [Ring R] : |
| 80 | + (WithAbs.equiv v).symm (r - s) = (WithAbs.equiv v).symm r - (WithAbs.equiv v).symm s := |
| 81 | + rfl |
| 82 | + |
| 83 | +@[simp] |
| 84 | +theorem equiv_neg [Ring R] : WithAbs.equiv v (-x) = - WithAbs.equiv v x := rfl |
| 85 | + |
| 86 | +@[simp] |
| 87 | +theorem equiv_symm_neg [Ring R] : (WithAbs.equiv v).symm (-r) = - (WithAbs.equiv v).symm r := rfl |
| 88 | + |
| 89 | +@[simp] |
| 90 | +theorem equiv_mul : WithAbs.equiv v (x * y) = WithAbs.equiv v x * WithAbs.equiv v y := rfl |
| 91 | + |
| 92 | +@[simp] |
| 93 | +theorem equiv_symm_mul : |
| 94 | + (WithAbs.equiv v).symm (x * y) = (WithAbs.equiv v).symm x * (WithAbs.equiv v).symm y := |
| 95 | + rfl |
| 96 | + |
| 97 | +/-- `WithAbs.equiv` as a ring equivalence. -/ |
| 98 | +def ringEquiv : WithAbs v ≃+* R := RingEquiv.refl _ |
| 99 | + |
| 100 | +end WithAbs |
0 commit comments