Zulip Chat Archive

Stream: new members

Topic: norm_num question


Michael Stoll (Mar 17 2022 at 18:15):

Why does the following not work?

example : (3 : zmod 8)^2 = 1 := by norm_num

gives

tactic failed, there are unsolved goals
state:
 9 = 1

If norm_num cannot do it, how can numerical calculations then be done in ℤ/nℤ?

Mario Carneiro (Mar 17 2022 at 18:21):

norm_fin does this kind of thing but I think it doesn't work on zmod. You can also prove 9 % 8 = 1 % 8 using norm_num and apply a theorem to deduce the zmod fact

Heather Macbeth (Mar 17 2022 at 18:21):

I think dec_trivial works on this kind of thing.

Heather Macbeth (Mar 17 2022 at 18:21):

import data.zmod.basic

example : (3 : zmod 8)^2 = 1 := by dec_trivial

Michael Stoll (Mar 17 2022 at 18:30):

@Heather Macbeth Hm, I think I tried that (perhaps in a slightly more complicated situation).

This also gives

example (a : zmod 17) : a^4  2 := by { fin_cases a; dec_trivial }

But I guess that trying the same with (say)

example (a b c : zmod 8) : a^2 + b^2 + c^2  7

will be too much for Lean.

Michael Stoll (Mar 17 2022 at 18:33):

My original question still stands: Is there a (good) reason why this is not part of what norm_num does?

Yakov Pechersky (Mar 17 2022 at 18:37):

Just because the norm_fin extension hasn't been expanded to support zmod (n + 1). An easy way would be to transfer through the fin (n + 1) \~-+* zmod (n + 1) ring equiv (which is just refl)

Johan Commelin (Mar 17 2022 at 18:38):

Michael Stoll said:

This also gives

example (a : zmod 17) : a^4  2 := by { fin_cases a; dec_trivial }

This should work with dec_trivial! (note the !).

Michael Stoll (Mar 17 2022 at 18:43):

I was thinking of the 8^3 = 512 cases the naive approach would generate.

Michael Stoll (Mar 17 2022 at 18:46):

(Previous version had a wrong statement.)
The simpler version:

example (a b : zmod 4) : a^2 + b^2  3 := begin fin_cases a; { fin_cases b; dec_trivial, } end

works without the ! and also with it.

Rob Lewis (Mar 17 2022 at 18:49):

The 512 cases aren't instant, but aren't horribly slow. For the "simpler" version, luckily dec_trivial can only prove true statements :smile:

Michael Stoll (Mar 17 2022 at 18:49):

I had just realized that and was editing my message...

Michael Stoll (Mar 17 2022 at 18:51):

On my machine, I get a deterministic timeout from the 512 cases (with dec_trivial!).

Michael Stoll (Mar 17 2022 at 18:51):

... and also with dec_trivial.

Rob Lewis (Mar 17 2022 at 18:53):

Are you using fin_cases first? This isn't necessary. Lean knows that universal quantifiers over a finite type are decidable.

example (a b c : zmod 8) : a^2 + b^2 + c^2  7 :=
by dec_trivial!

Michael Stoll (Mar 17 2022 at 18:55):

OK; I didn't know that. In fact, I have no really good idea what dec_trivial[!] is and is not capable of doing.
Still trying to feel my way in...

Johan Commelin (Mar 17 2022 at 18:58):

The difference between dec_trivial and dec_trivial! is quite small. The version with ! will try to revert some assumptions, but otherwise it's just the same as dec_trivial.

Johan Commelin (Mar 17 2022 at 18:59):

And dec_trivial tells Lean: hey all definitions involved are computable. You should be able to use them to run a finite algorithm and decide the truth of this claim.

Johan Commelin (Mar 17 2022 at 19:00):

But the efficiency of that algorithm can of course be horrible, depending on those definitions and the size of the objects involved.

Michael Stoll (Mar 17 2022 at 19:30):

I expected the following to work, but it doesn't.

lemma l1 (a : zmod 8) : a^2 = 0  a^2 = 1  a^2 = 4 := by dec_trivial!

example (a : zmod 8) (h : a^2 = 6) : false :=
begin
  have l := l1 a,
  rw h at l,
  dec_trivial, -- gives error, also with dec_trivial!
end

It does, however, after inserting revert l before dec_trivial. Why does this make a difference?

Kyle Miller (Mar 17 2022 at 19:34):

Michael Stoll said:

My original question still stands: Is there a (good) reason why this is not part of what norm_num does?

I'm wondering this, too. Is it out of scope for norm_num to be able to reduce zmod numerals?

Yakov Pechersky (Mar 17 2022 at 20:03):

It can be a norm_num extensions, probably within the extension provided by norm_fin


Last updated: Dec 20 2023 at 11:08 UTC