Zulip Chat Archive

Stream: new members

Topic: WithTop ℤ casting not working.


Giulio Caflisch (Oct 01 2024 at 18:06):

Please can someone explain to me why, for integers, the casting from integers to upwards extended integers is not working?

import Mathlib

open Nat

variable (p : ) [hp : Fact (Nat.Prime p)]

theorem Padic.norm_lt_iff_addValuation_gt (x : ℚ_[p]) (m : ) :
    x < (p : )^(-(m : ))  Padic.addValuation x > m := by
  by_cases hx : x = 0
  · repeat rw [hx]
    rw [Padic.addValuation.map_zero]
    simp only [norm_zero, WithTop.natCast_lt_top, iff_true, zpow_neg, zpow_natCast, inv_pos]
    apply pow_pos
    rw [cast_pos]
    exact hp.out.pos
  · rw [ ne_eq] at hx
    rw [Padic.norm_eq_pow_val]
    rw [Padic.addValuation.apply]
      -- have hx' ::= solve ↑p ^ (-x.valuation) < ↑p ^ (-↑m) for x.valuation
      -- exact hx'
    rw [gt_iff_lt]
    nth_rewrite 2 [cast_lt] -- why isn't this working?
    nth_rewrite 2 [ neg_lt_neg_iff]
    apply Real.pow_lt_pow_iff_right
    · exact hx
    · exact hx

Edward van de Meent (Oct 01 2024 at 18:10):

it seems the issue is that the right argument you're trying to rewrite isn't Nat.cast but rather WithTop.some

Etienne Marion (Oct 01 2024 at 18:14):

Does this help?

rw [gt_iff_lt,  WithTop.coe_natCast, WithTop.coe_lt_coe]

Giulio Caflisch (Oct 01 2024 at 18:31):

It works, thanks to both

Giulio Caflisch (Oct 01 2024 at 20:04):

Sorry to disturb again.

import Mathlib

open Nat

variable (p : ) [hp : Fact (Nat.Prime p)]

theorem Padic.norm_lt_iff_addValuation_gt (x : ℚ_[p]) (m : ) :
    x < (p : )^(-(m : ))  Padic.addValuation x > m := by
  by_cases hx : x = 0
  · repeat rw [hx]
    rw [Padic.addValuation.map_zero]
    simp only [norm_zero, WithTop.natCast_lt_top, iff_true, zpow_neg, zpow_natCast, inv_pos]
    apply pow_pos
    rw [cast_pos]
    exact hp.out.pos
  · rw [ ne_eq] at hx
    have hp' : 1 < p := by
      apply Nat.Prime.one_lt hp.out
    rw [Padic.norm_eq_pow_val]
    rw [Padic.addValuation.apply]
      -- have hx' ::= solution_with_proof ↑p ^ (-x.valuation) < ↑p ^ (-↑m) for x.valuation
      -- exact hx'
    rw [gt_iff_lt]
    rw [ WithTop.coe_natCast, WithTop.coe_lt_coe]
    nth_rewrite 2 [ neg_lt_neg_iff]
    repeat rw [ Real.rpow_intCast]
    rw [Real.rpow_lt_rpow_left_iff]
    simp only [Int.cast_neg]
    simp only [neg_lt_neg_iff]
    sorry -- rw [Real.intCast_lt]
    · simp only [one_lt_cast]
      exact hp'
    · exact hx
    · exact hx

I need one last line to finish the proof.
In mathlib there is the theorem

Real.ratCast_lt

but I need the exact same thing byt of the form Real.intCast_lt but this doesn't exist as far as I looked in Mathlib

Etienne Marion (Oct 01 2024 at 20:12):

You want docs#Int.cast_lt

Etienne Marion (Oct 01 2024 at 20:12):

I found it by typing Int.cast, _ < _ in #loogle

Giulio Caflisch (Oct 01 2024 at 20:34):

Thanks a lot. I also used #loogle and somehow, searching

↑?a < ↑?b  ?a < ?b

nothing useful came out.

Etienne Marion (Oct 01 2024 at 20:38):

I think loogle does not really know how to interpret the arrows because they can mean any coercion, so it just ignores it, thus your request is the same as _ < _ ↔ _ < _, which is too general.

David Loeffler (Oct 02 2024 at 11:10):

Hi Giulio! One very useful trick I find when searching for an unknown lemma is to write it down carefully as a self-contained example and then use exact?. In situations like this one, when your goal has things like ↑a involved whose meaning is context-dependent, exact? works best if you add explicit type annotations to make sure that all the types have been elaborated correctly before searching.

E.g. if you type

example (a b : ) : (a : WithTop ) < (b : WithTop )  a < b := by exact?

in to a lean file in VSCode, it will think for a few seconds and respond Try this: exact WithTop.coe_lt_coe.


Last updated: May 02 2025 at 03:31 UTC