Zulip Chat Archive

Stream: mathlib4

Topic: Double-casting


Sorrachai Yingchareonthawornchai (Sep 23 2024 at 14:14):

I encounter a double-casting situation. How do I close this goal? Here, a is in Z, and ↑a⁺ is Fin n, and ↑↑a⁺ is Nat
a : ℤ
hha : a ≤ 0
↑↑a⁺ = 0

simp [hha, posPart_eq_zero] does not work

Julian Berman (Sep 23 2024 at 14:15):

It's a bit easier to help if you include a #mwe.

Sorrachai Yingchareonthawornchai (Sep 23 2024 at 14:26):

Sure, here it is:

import Mathlib

theorem extracted_1 (n : ) [inst : NeZero n] (a : ) (ha : 1  n + a) (hb : a  n - 1) (hha : a  0) :
  ↑↑a = 0 := sorry

Yury G. Kudryashov (Sep 23 2024 at 14:33):

This is not an #mwe that I can copy+paste, then try to prove. You need to add explicit type annotations to make sure it parses correctly.

Yury G. Kudryashov (Sep 23 2024 at 14:34):

Someting like (((a⁺ : Int) : Fin n) : Nat) = 0

Yury G. Kudryashov (Sep 23 2024 at 14:37):

You can start with

  rw [ Fin.val_zero' n, Fin.val_inj, Fin.natCast_eq_zero]

Yury G. Kudryashov (Sep 23 2024 at 14:37):

This way you'll no longer have Fin n.

Yury G. Kudryashov (Sep 23 2024 at 14:38):

Wait, you have a ≤ 0, so posPart a = 0, right?

Sorrachai Yingchareonthawornchai (Sep 23 2024 at 14:39):

yes

Yury G. Kudryashov (Sep 23 2024 at 14:39):

  simp [posPart_eq_zero.2 hha]

should work (not tested)

Sorrachai Yingchareonthawornchai (Sep 23 2024 at 14:40):

that works thanks. (What is posPart_eq_zero.2?)

Yury G. Kudryashov (Sep 23 2024 at 14:40):

It selects the right-to-left implication from posPart_eq_zero.

Yury G. Kudryashov (Sep 23 2024 at 14:41):

A more readable version:

  have : a = 0 := by rwa [posPart_eq_zero]
  simp [this]

Sorrachai Yingchareonthawornchai (Sep 23 2024 at 14:43):

Thanks a lot

Sorrachai Yingchareonthawornchai (Sep 23 2024 at 17:05):

x1 : ℤ
x2 : ℤ
hfxn : ↑x1 = ↑x2
x1 = x2

In hfxn, the integers are casted to Fin n (i.e., @Int.cast (Fin n) AddGroupWithOne.toIntCast x1 : Fin n)
How to remove the cast at hfxn?

Edward van de Meent (Sep 23 2024 at 17:07):

i don't think this is true? for example, consider what might happen when x1=0 and x2=n?

Sorrachai Yingchareonthawornchai (Sep 23 2024 at 17:27):

Thanks. The context is :

s : Finset ℤ := Icc (-↑n + 1) (↑n - 1)
x1 : ℤ
hx1 : x1 ∈ s
x2 : ℤ
hx2 : x2 ∈ s
x1le0 : x1 ≤ 0
x2le0 : x2 ≤ 0
hfxn : ↑x1 = ↑x2
 x1 = x2

Edward van de Meent (Sep 23 2024 at 17:32):

rather than copy-pasting the context, please provide a #mwe

Sorrachai Yingchareonthawornchai (Sep 23 2024 at 17:42):

Is this one okay?

import Mathlib

example  (n :  )[NeZero n] :=
  let s : Finset  := Finset.Icc (-n + 1) (n - 1)
  let f :    Fin n × Fin n  := fun (i)  ( (i) , (i))
  have f_inj : Set.InjOn f s := by
    simp  [Set.InjOn]
    intro x1 hx1 x2 hx2 hfx
    simp [f] at hfx
    obtain hfxp, hfxn := hfx
    obtain x1le0 | x1g0 := le_total x1 0
    obtain x2le0 | x2g0 := le_total x2 0
    have t1: x1 = 0 := by rwa [posPart_eq_zero]
    have t2: x2 = 0 := by rwa [posPart_eq_zero]
    have t1n: x1  = -x1 := by rwa [negPart_eq_neg]
    have t2n: x2  = -x2 := by rwa [negPart_eq_neg]
    rw [t1n,t2n] at hfxn
    simp at hfxn
    sorry

Yaël Dillies (Sep 23 2024 at 18:39):

@Sorrachai Yingchareonthawornchai, using #17061 and #17063, you can do

import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Order.Group.PosPart
import Mathlib.Data.ZMod.Defs

open Set

example (n : ) [NeZero n] :
    InjOn (fun z :   (((z), (z)) : Fin n × Fin n)) (Ioo (-n) n) :=
  ((CharP.intCast_injOn_Ico _ n).prodMap (CharP.intCast_injOn_Ico _ n)).comp
    posPart_negPart_injective.injOn fun z hz 
    ⟨⟨posPart_nonneg _, by simpa [NeZero.pos] using hz.2,
      negPart_nonneg _, by simpa [NeZero.pos] using hz.1⟩⟩

Sorrachai Yingchareonthawornchai (Sep 23 2024 at 19:48):

Thanks. Should I wait for the new update from #17061 and #17063 ?

Yaël Dillies (Sep 23 2024 at 20:20):

Maybe someone will get them merged quickly? :wink:

Yury G. Kudryashov (Sep 23 2024 at 20:29):

Merged, delegated


Last updated: May 02 2025 at 03:31 UTC