Zulip Chat Archive

Stream: mathlib4

Topic: efficiently dealing with / vs .div


Jonathan Protzenko (Sep 18 2023 at 22:35):

my goal contains this term: -↑R * x / ↑R * ↑R , and I also have ↑R ∣ -↑R in my context, so I'm trying to do rw [ Int.mul_div_assoc (-↑R: Int) ] to put this expression in a form that can be further simplified, but the lemma relies on .div while my goal uses / -- how can I reconcile the two? this seems to be an instance of a general pattern where I've previously had to deal with notations (e.g. writing lemmas of the form (↑R)⁻¹ = ZMod.inv q (↑ R) just to "evaluate away" the notation...) perhaps there is a good way to deal with these discrepancies?

FYI I get:

tactic 'rewrite' failed, did not find instance of the pattern in the target expression
  Int.div (-↑R * ?m.27345) ?m.27346

Eric Wieser (Sep 18 2023 at 22:36):

docs#Int.mul_ediv_assoc is what you want

Eric Wieser (Sep 18 2023 at 22:37):

.div and / are different operations (they round differently)

Jonathan Protzenko (Sep 18 2023 at 22:38):

ah that explains it. thanks!

Eric Wieser (Sep 18 2023 at 22:38):

It's a little confusing, because lemmas in Std about / are generally named ediv, while lemmas in mathlib use div in the name

Eric Wieser (Sep 18 2023 at 22:39):

I think there's a proposal to rename .div to .tdiv such that ediv can be called div and the confusion is gone

Jonathan Protzenko (Sep 18 2023 at 22:39):

thanks Eric! and I'd be remiss if I didn't ask: is there an efficient tactic in mathlib that might help simplify this expression? (just trying to remove the R / R part...)

Jonathan Protzenko (Sep 18 2023 at 22:40):

the proposal sounds good, but now that I now there's a confusing notation, I'll pay more attention to which one of the two I'm dealing with, thanks

Eric Wieser (Sep 18 2023 at 22:40):

I'm afraid that's not really answerable without a #mwe

Jonathan Protzenko (Sep 18 2023 at 22:41):

no problem, let me work a little more on that, thanks

Jonathan Protzenko (Sep 18 2023 at 22:55):

this is the original thing I was setting out to prove when I ran into / vs .div:

import Mathlib.Data.Int.ModEq

example (a: Int) (x: Int) (r: Int) (q: Int) (h_R: 0 < R) (h: a  -R * x / R * R [ZMOD q]): a  - x * R [ZMOD q] := by
  sorry

Kevin Buzzard (Sep 18 2023 at 23:15):

Can you make it a #mwe ? (read the link)

Jonathan Protzenko (Sep 18 2023 at 23:49):

ah yes thanks I didn't realize #mwe was clickable and I needed all of the imports... should be good now. I mean I did manage to prove that, but I'm wondering if there's a tactic that will do it in one step rather than my own painful 10 lines that involve proving divisibility and then re-arranging the terms rather tediously by hand

Jireh Loreaux (Sep 18 2023 at 23:56):

docs#Int.ediv_mul_cancel should get you there almost instantly.

Jireh Loreaux (Sep 18 2023 at 23:57):

As for automation, no, we don't really have any for that because integer division isn't well-behaved.

Jonathan Protzenko (Sep 19 2023 at 03:31):

yeah that's basically what I ended up doing

Jonathan Protzenko (Sep 19 2023 at 03:31):

good to know that there isn't anything more principled

Jonathan Protzenko (Sep 19 2023 at 03:31):

thanks!


Last updated: Dec 20 2023 at 11:08 UTC