Zulip Chat Archive

Stream: mathlib4

Topic: Conversion from ℤ → UInt64 → ℤ


Geoffrey Irving (Feb 01 2024 at 17:20):

It feels like this should be very easy to prove, but I am stuck. Not sure how to unpack the various definitions. The conversion is happening via the fact that Fin n is a commutative ring, so one conceptual proof is induction on the presentation of , but I don't know how to express that.

import Mathlib.Data.UInt

@[simp] lemma UInt64.toInt_intCast (n : ) : ((n : UInt64).toNat : ) = n % 2^64 := by
  sorry

Eric Rodriguez (Feb 01 2024 at 17:30):

the Nat version is easy:

@[simp] lemma UInt64.toInt_intCast (n : ) : ((n : UInt64).toNat) = n % 2^64 := Fin.coe_ofNat_eq_mod _ _

and I assume you need it for this. Some way of doing this is just saying that n+N264n + N * 2^64 is positive for some large enough $N$ and then use the natural number result I guess? but not sure how much API is there

Geoffrey Irving (Feb 01 2024 at 17:30):

I already have the Nat version. Now I need the Int version.

Geoffrey Irving (Feb 01 2024 at 17:31):

(I need to do a bit of signed 128-bit arithmetic, and this is a necessary lemma for proving things about that.)

Geoffrey Irving (Feb 01 2024 at 17:31):

True, adding a big multiple should do it. Thanks!

Geoffrey Irving (Feb 01 2024 at 17:39):

Though the APIs are super different: the Nat one is more native since Fin wraps Nat, and doesn’t use general rings.

Geoffrey Irving (Feb 02 2024 at 09:11):

Resolved: rewriting as Nat or -Nat makes it straightforward, via

theorem Int.induction_overlap {p :   Prop} (hi :  n : , p n) (lo :  n : , p (-n)) :
     n : , p n := by intro n; induction' n with n; exact hi n; exact lo (_ + 1)

Eric Wieser (Feb 03 2024 at 19:18):

Arguably that should replace docs#Int.eq_nat_or_neg (swapping obtain ⟨n, rfl, rfl⟩ := z.eq_nat_or_neg for induction x using that_lemma)


Last updated: May 02 2025 at 03:31 UTC