Zulip Chat Archive

Stream: new members

Topic: Why tactic `decide` cannot solve IsSquare 9 ?


ptrl (Dec 04 2024 at 16:33):

My code:

def nine_is_square : IsSquare 9 := by
  decide

screenshot2024-12-05 00.33.25.png

Eric Wieser (Dec 04 2024 at 16:35):

unseal Nat.sqrt.iter in
def nine_is_square : IsSquare 9 := by
  decide

fixes it

Eric Wieser (Dec 04 2024 at 16:35):

cc @Joachim Breitner, it would be great to have some documentation in the decide tactic about the interaction with well-founded recursion

Daniel Weber (Dec 04 2024 at 17:09):

I recall some talk about being allowed to unfold well-founded recursion on ground terms, which could also solve this

ptrl (Dec 05 2024 at 02:17):

@Eric Wieser May I ask a more further question?
How to solve this by decide? \sqrt 7 will be solved, but \sqrt 7 + 1 not work

unseal Nat.sqrt.iter in
example : Irrational (7 + 1) := by
  decide

Eric Wieser (Dec 05 2024 at 02:21):

You can use

#synth Decidable (Irrational 7)

to see that docs#instDecidableIrrationalSqrtOfNatReal is being used, which only applies when there is no addition

ptrl (Dec 05 2024 at 02:32):

Eric Wieser said:

You can use

#synth Decidable (Irrational 7)

to see that docs#instDecidableIrrationalSqrtOfNatReal is being used, which only applies when there is no addition

Hi, @Eric Wieser
If I want to solve Irrational (√7 + 1), what should I do? I want to use Irrational.rat_add, but 1 is not a rational, it is \R.
And what about Irrational (√7 - 1)? I think it is more difficult

Matt Diamond (Dec 05 2024 at 02:35):

this works, though I would hope there's a way to do this without the Nat.cast_one rewrite:

import Mathlib

unseal Nat.sqrt.iter in
example : Irrational (7 + 1) := by
  rw [ Nat.cast_one, irrational_add_nat_iff]
  decide

Matt Diamond (Dec 05 2024 at 02:38):

and then you can do the same for - 1 using irrational_sub_nat_iff

Eric Wieser (Dec 05 2024 at 02:51):

We should add an ofNat version of that lemma, and rename that one to natCast

Mario Carneiro (Dec 05 2024 at 10:50):

Daniel Weber said:

I recall some talk about being allowed to unfold well-founded recursion on ground terms, which could also solve this

Probably decide +kernel, since the kernel doesn't care about irreducibility

ptrl (Dec 05 2024 at 15:00):

Why \sqrt 4 = 2 cannot be solved by decide? :sob:

unseal Nat.sqrt.iter in
def sqrt4eq2 : (4 : ) = 2 := by
  decide

Mario Carneiro (Dec 05 2024 at 15:01):

does decide +kernel work?

Daniel Weber (Dec 05 2024 at 15:01):

That's not docs#Nat.sqrt, that's docs#Real.sqrt (and reals are noncomputable)

Mario Carneiro (Dec 05 2024 at 15:03):

theorem sqrt4eq2 : (4 : ) = 2 := by
  rw [Real.sqrt_eq_iff_eq_sq] <;> norm_num

works

Mario Carneiro (Dec 05 2024 at 15:05):

perhaps norm_num should have a module for Real.sqrt that does this, although it's obviously limited to rational squares

Ruben Van de Velde (Dec 05 2024 at 15:36):

I agree


Last updated: May 02 2025 at 03:31 UTC