Zulip Chat Archive

Stream: new members

Topic: Division in `ZMod p`?


Quang Dao (Jul 18 2025 at 22:39):

Is there a tactic besides native_decide that help me prove computations in ZMod p that involves division?

example : (1 : ZMod 29) / 2 = 15 := by sorry

I tried decide, norm_num, reduce_mod_char, grind, simp +arith +decide, ring, etc, but none of them work. Why is that?

Ruben Van de Velde (Jul 18 2025 at 22:40):

What does it mean to divide in ZMod p?

Quang Dao (Jul 18 2025 at 22:46):

It is defined as a * b⁻¹. So this reduces to why can't we easily compute inverse. And note that ZMod.inv is defined by way of extended GCD, i.e. Nat.xgcd

Aaron Liu (Jul 18 2025 at 22:48):

I'm worried

import Mathlib

/-
failed to synthesize
  HDiv (ZMod 29) (ZMod 29) ?m.1006

Hint: Additional diagnostic information may be available using the `set_option diagnostics true` command.
-/
example : ((1 : ZMod 29) / (2 : ZMod 29) : ZMod 29) = (15 : ZMod 29) := by decide +kernel

that shouldn't happen, right? (on the web server)

Quang Dao (Jul 18 2025 at 22:49):

You need to first prove [Fact (Nat.Prime 29)], via decide for instance

Quang Dao (Jul 18 2025 at 22:50):

Here's what happens for decide:

tactic 'decide' failed for proposition
  1 / 2 = 15
since its 'Decidable' instance
  ZMod.decidableEq 29 (1 / 2) 15
did not reduce to 'isTrue' or 'isFalse'.

Reduction got stuck at the 'Decidable' instance
  match h : ((1 / 2)).beq 15 with
  | true => isTrue 
  | false => isFalse 

Ruben Van de Velde (Jul 18 2025 at 22:52):

import Mathlib
example : (1 : ZMod 29) * 2⁻¹ = 15 := by
  norm_num
  apply ZMod.inv_eq_of_mul_eq_one
  norm_num
  rfl

Looks like there's room for impovement

Aaron Liu (Jul 18 2025 at 22:56):

Did they get rid of the inv when p is not prime?

Quang Dao (Jul 18 2025 at 22:58):

No, there is always ZMod.inv and it gives junk values when (i : ZMod p) is not coprime to p. It's just that you can't access division or inversion notation when p is not prime

Ruben Van de Velde (Jul 18 2025 at 23:01):

Inv and the inversion notation are always defined

Quang Dao (Jul 18 2025 at 23:03):

Sorry, yes, only division notation is disallowed

Quang Dao (Jul 18 2025 at 23:04):

What would it take to extend current tactics to cover this example?


Last updated: Dec 20 2025 at 21:32 UTC