Zulip Chat Archive

Stream: general

Topic: Offloading decidable equality checks


Sky Wilshaw (Nov 15 2023 at 12:35):

Is there a way to offload decidable equality to the VM? If not, is ther a better way to write tests of my functions in this way?

import Lean.Data.Parsec

open Lean Parsec

def beginEnv (environment : String) : Parsec Unit := skipString s!"\\begin\{{environment}}"
def endEnv (environment : String) : Parsec Unit := skipString s!"\\end\{{environment}}"

def env (environment : String) (inner : Parsec α) : Parsec α :=
  beginEnv environment *> inner <* endEnv environment

deriving instance DecidableEq for Except

#eval (env "foo" (pstring "test")).run "\\begin{foo}test\\end{foo}" -- .ok "test"

theorem envTest :
    (env "foo" (pstring "test")).run "\\begin{foo}test\\end{foo}" = .ok "test" :=
  by decide -- timeout

Sky Wilshaw (Nov 15 2023 at 12:37):

Alternatively, are there simp lemmas for things in parsec?

Alex J. Best (Nov 15 2023 at 13:09):

You can use native_decide in place of decide I believe

Shreyas Srinivas (Nov 15 2023 at 13:10):

At the price of trusting the compiler

Sky Wilshaw (Nov 15 2023 at 13:13):

Ah great, that worked! I knew something like that had to exist.

Eric Wieser (Nov 15 2023 at 13:13):

rfl works there too

Sky Wilshaw (Nov 15 2023 at 13:16):

It takes too long to elaborate rfl unfortunately.

Eric Wieser (Nov 15 2023 at 13:48):

Weird, it works instantly for me

Sky Wilshaw (Nov 15 2023 at 13:49):

Interestingly enough by rfl is fast but rfl is slow. What's the difference?

Eric Wieser (Nov 15 2023 at 13:53):

Is this on the example above, or a much bigger example?

Eric Wieser (Nov 15 2023 at 13:53):

If the former, maybe you're on an older lean.

Mauricio Collares (Nov 15 2023 at 13:53):

There is a difference, but it was much more pronounced in earlier versions of Lean. Are you using an older Lean version?

Sky Wilshaw (Nov 15 2023 at 13:54):

It's just the example above. by rfl is instant, and rfl times out. I'm on leanprover/lean4:nightly-2023-05-09 .

Eric Wieser (Nov 15 2023 at 13:55):

That's 6 months old

Eric Wieser (Nov 15 2023 at 13:56):

I think it predates the first official release, and probably the FRO?

Sky Wilshaw (Nov 15 2023 at 13:56):

Ah, right. lake update wasn't doing anything so I just assumed I was already on a relatively recent one.

Sky Wilshaw (Nov 15 2023 at 13:56):

Does lake update even update the toolchain?

Sky Wilshaw (Nov 15 2023 at 13:57):

Just updated to 4.3.0-rc1 and now rfl is fast. Thanks for the help!

Eric Wieser (Nov 15 2023 at 14:00):

Sky Wilshaw said:

Does lake update even update the toolchain?

Only if you're using mathlib (!)

Scott Morrison (Nov 15 2023 at 22:31):

(Mathlib provides a post update hook that does this.)


Last updated: Dec 20 2023 at 11:08 UTC