Zulip Chat Archive

Stream: lean4

Topic: isDefEq thing I dont understand


Henrik Böving (Feb 06 2023 at 18:42):

Someone gave me the following code:

import Lean
open Lean Elab Meta
elab "#isDefEq " t₁:term "===" t₂:term : command => do
  Command.liftTermElabM do
    let e₁ <- Lean.Elab.Term.elabTerm t₁ none
    let e₂ <- Lean.Elab.Term.elabTerm t₂ none
    let isEq <- Lean.Meta.isDefEq e₁ e₂
    logInfo s!"{isEq}"

set_option trace.Meta.isDefEq true in
#isDefEq 0 + 0 === 0

and to my surprise it prints false? However when I run it like this:

import Lean
open Lean Elab Meta
elab "#isDefEq " t₁:term "===" t₂:term : command => do
  Command.liftTermElabM do
    let e₁ <- Lean.Elab.Term.elabTerm t₁ none
    let e₂ <- Lean.Elab.Term.elabTerm t₂ none
    let isEq <- Lean.Meta.isDefEq e₁ e₂
    logInfo s!"{isEq}"

set_option trace.Meta.isDefEq true in
#isDefEq 0 + (0 : Nat) === (0 : Nat)

I get true? Why is the Nat annotation relevant here? In my understanding it should pick the OfNat Nat default instance and just know that it is natural numbers getting thrown around here and the behavior should not change if I add these annotations? So what am I misunderstanding?

Gabriel Ebner (Feb 06 2023 at 19:08):

I think you're missing a synthesizeSyntheticMVarsUsingDefault here.

Gabriel Ebner (Feb 06 2023 at 19:08):

In the first example, Lean hasn't decided yet that 0 is a natural number.

Gabriel Ebner (Feb 06 2023 at 19:09):

It could be a type with weird ops where 0 + 0 = 1 (and 0 ≠ 1).

Kyle Miller (Feb 06 2023 at 19:13):

open Lean Elab Meta
elab "#isDefEq " t₁:term "===" t₂:term : command => do
  Command.liftTermElabM do
    let e₁ <- Lean.Elab.Term.elabTerm t₁ none
    let e₂ <- Lean.Elab.Term.elabTerm t₂ none
    Term.synthesizeSyntheticMVarsUsingDefault
    let isEq <- Lean.Meta.isDefEq e₁ e₂
    logInfo s!"{isEq}"

#isDefEq 0 + 0 === 0
-- true
#isDefEq 1 === 1 + 0
-- true

Last updated: Dec 20 2023 at 11:08 UTC