@@ -62,14 +62,6 @@ section Ring
6262
6363variable [Ring R] (v : Valuation R Γ₀)
6464
65- instance : Ring (WithVal v) := fast_instance% Equiv.ring { toFun := ofVal, invFun := toVal v }
66- instance : Inhabited (WithVal v) := ⟨0 ⟩
67- instance : Preorder (WithVal v) := .lift (v ∘ ofVal)
68-
69- theorem le_def {v : Valuation R Γ₀} {a b : WithVal v} : a ≤ b ↔ v a.ofVal ≤ v b.ofVal := .rfl
70-
71- theorem lt_def {v : Valuation R Γ₀} {a b : WithVal v} : a < b ↔ v a.ofVal < v b.ofVal := .rfl
72-
7365lemma ofVal_toVal (x : R) : ofVal (toVal v x) = x := rfl
7466@[simp] lemma toVal_ofVal (x : WithVal v) : toVal v (ofVal x) = x := rfl
7567
@@ -91,6 +83,18 @@ lemma ofVal_bijective : Function.Bijective (ofVal (v := v)) :=
9183lemma toVal_bijective : Function.Bijective (toVal v) :=
9284 ⟨toVal_injective v, toVal_surjective v⟩
9385
86+
87+ instance : Zero (WithVal v) where zero := toVal _ 0
88+ instance : One (WithVal v) where one := toVal _ 1
89+ instance : Add (WithVal v) where add x y := toVal _ (x.ofVal + y.ofVal)
90+ instance : Sub (WithVal v) where sub x y := toVal _ (x.ofVal - y.ofVal)
91+ instance : Neg (WithVal v) where neg x := toVal _ (-x.ofVal)
92+ instance : Mul (WithVal v) where mul x y := toVal _ (x.ofVal * y.ofVal)
93+ instance {S} [SMul S R] : SMul S (WithVal v) where smul s x := toVal _ (s • x.ofVal)
94+ instance : Pow (WithVal v) ℕ where pow x n := toVal _ (x.ofVal ^ n)
95+ instance : NatCast (WithVal v) where natCast n := toVal _ n
96+ instance : IntCast (WithVal v) where intCast z := toVal _ z
97+
9498@[simp] lemma toVal_zero : toVal v 0 = 0 := rfl
9599
96100@[simp] lemma ofVal_zero : ofVal (0 : WithVal v) = 0 := rfl
@@ -119,6 +123,11 @@ lemma toVal_bijective : Function.Bijective (toVal v) :=
119123
120124@[simp] lemma ofVal_pow (x : WithVal v) (n : ℕ) : ofVal (x ^ n) = (ofVal x) ^ n := rfl
121125
126+ @[simp] theorem toVal_smul {S} [SMul S R] (s : S) (r : R) : toVal v (s • r) = s • toVal v r := rfl
127+
128+ @[simp] theorem ofVal_smul {S} [SMul S R] (s : S) (x : WithVal v) : ofVal (s • x) = s • ofVal x :=
129+ rfl
130+
122131@[simp] lemma toVal_natCast (n : ℕ) : toVal v n = n := rfl
123132
124133@[simp] lemma ofVal_natCast (n : ℕ) : ofVal (n : WithVal v) = n := rfl
@@ -127,9 +136,16 @@ lemma toVal_bijective : Function.Bijective (toVal v) :=
127136
128137@[simp] lemma ofVal_intCast (z : ℤ) : ofVal (z : WithVal v) = z := rfl
129138
130- @[simp] lemma toVal_ofNat (n : ℕ) [n.AtLeastTwo] : toVal v ofNat(n) = ofNat(n) := rfl
139+ instance : Ring (WithVal v) := fast_instance% ofVal_injective v |>.ring _
140+ (ofVal_zero _) (ofVal_one _) (ofVal_add _) (ofVal_mul _) (ofVal_neg _) (ofVal_sub _)
141+ (ofVal_smul _) (ofVal_smul _) (ofVal_pow _) (ofVal_natCast _) (ofVal_intCast _)
142+
143+ instance : Inhabited (WithVal v) := ⟨0 ⟩
144+ instance : Preorder (WithVal v) := .lift (v ∘ ofVal)
131145
132- @[simp] lemma ofVal_ofNat (n : ℕ) [n.AtLeastTwo] : ofVal (ofNat(n) : WithVal v) = ofNat(n) := rfl
146+ theorem le_def {v : Valuation R Γ₀} {a b : WithVal v} : a ≤ b ↔ v a.ofVal ≤ v b.ofVal := .rfl
147+
148+ theorem lt_def {v : Valuation R Γ₀} {a b : WithVal v} : a < b ↔ v a.ofVal < v b.ofVal := .rfl
133149
134150@[simp] lemma toVal_eq_zero (x : R) : toVal v x = 0 ↔ x = 0 := (toVal_injective v).eq_iff
135151
@@ -220,8 +236,6 @@ theorem smul_left_def [SMul R S] (x : WithVal v) (s : S) : x • s = ofVal x •
220236instance [SMul R S] [FaithfulSMul R S] : FaithfulSMul (WithVal v) S where
221237 eq_of_smul_eq_smul h := ofVal_injective v <| FaithfulSMul.eq_of_smul_eq_smul h
222238
223- instance [SMul S R] : SMul S (WithVal v) := (equiv v).smul S
224-
225239theorem smul_right_def [SMul S R] (s : S) (x : WithVal v) : s • x = toVal v (s • ofVal x) := rfl
226240
227241instance [SMul S R] [FaithfulSMul S R] : FaithfulSMul S (WithVal v) where
@@ -239,7 +253,7 @@ instance {P : Type*} [Ring S] [SMul P S] [SMul R S] [SMul P R]
239253
240254instance {P : Type*} [Ring S] [SMul P R] [SMul S R] [SMul P S]
241255 [IsScalarTower P S R] (v : Valuation S Γ₀) : IsScalarTower P (WithVal v) R where
242- smul_assoc := by simp [smul_right_def, smul_left_def]
256+ smul_assoc := by simp [smul_right_def, smul_left_def, - toVal_smul ]
243257
244258instance [AddCommMonoid S] [Module R S] : Module (WithVal v) S :=
245259 .compHom S (equiv v).toRingHom
@@ -251,10 +265,6 @@ instance [AddCommMonoid S] [Module R S] [Module.Finite R S] :
251265instance [Semiring S] [Module S R] : Module S (WithVal v) :=
252266 fast_instance% (equiv v).module S
253267
254- @[simp] theorem toVal_smul [SMul S R] (s : S) (r : R) : toVal v (s • r) = s • toVal v r := rfl
255-
256- @[simp] theorem ofVal_smul [SMul S R] (s : S) (x : WithVal v) : ofVal (s • x) = s • ofVal x := rfl
257-
258268variable [Ring S] [Module R S] (v : Valuation S Γ₀)
259269
260270variable (R) in
@@ -327,9 +337,11 @@ section Field
327337
328338variable [Field R] (v : Valuation R Γ₀)
329339
330- instance : Field (WithVal v) := fast_instance% (equiv v).field
331-
332- instance [NumberField R] : NumberField (WithVal v) where
340+ instance : Div (WithVal v) where div x y := toVal _ (x.ofVal / y.ofVal)
341+ instance : Inv (WithVal v) where inv x := toVal _ x.ofVal⁻¹
342+ instance : Pow (WithVal v) ℤ where pow x z := toVal _ (x.ofVal ^ z)
343+ instance : NNRatCast (WithVal v) where nnratCast q := toVal _ q
344+ instance : RatCast (WithVal v) where ratCast q := toVal _ q
333345
334346@[simp] lemma toVal_div (x y : R) : toVal v (x / y) = toVal v x / toVal v y := rfl
335347
@@ -351,6 +363,14 @@ instance [NumberField R] : NumberField (WithVal v) where
351363
352364@[simp] lemma ofVal_ratCast (q : ℚ) : ofVal (q : WithVal v) = q := rfl
353365
366+ instance : Field (WithVal v) := fast_instance% ofVal_injective v |>.field _
367+ (ofVal_zero _) (ofVal_one _) (ofVal_add _) (ofVal_mul _) (ofVal_neg _) (ofVal_sub _)
368+ (ofVal_inv _) (ofVal_div _)
369+ (ofVal_smul _) (ofVal_smul _) (ofVal_smul _) (ofVal_smul _) (ofVal_pow _) (ofVal_zpow _)
370+ (ofVal_natCast _) (ofVal_intCast _) (ofVal_nnratCast _) (ofVal_ratCast _)
371+
372+ instance [NumberField R] : NumberField (WithVal v) where
373+
354374end Field
355375
356376section Ring
0 commit comments