Zulip Chat Archive
Stream: lean4
Topic: Unable to Apply List Lemma?
David Pearce (May 22 2024 at 22:35):
I am confused why the fails (Lean 4.7.0
):
-- A set of zero or more bytes upto a given size.
structure FinVec {n:Nat} (T) where
data : List T
isLt : data.length <= n
def slice32(l:List Nat) : (FinVec (n:=32) Nat) :=
let bytes := (l.take 32)
-- Prove bytes has at most 32 elements.
have q : bytes.length ≤ 32 := by rw [List.length_take]
-- Construct FinVec
{data:=bytes, isLt:=q}
Specifically, the error is that it List.length_take_le
is an unknown constant
. But, this is a real lemma I'm trying apply. I figure an import is required, but could not get the right incantation.
I should add, that I thought I understood that the standard library (now batteries) was included by default. So, I expected something like this to do it:
import Std.Data.List.Lemmas
Thoughts?
David Pearce (May 22 2024 at 22:39):
(deleted)
David Pearce (May 22 2024 at 22:41):
(deleted)
David Pearce (May 22 2024 at 22:48):
(deleted)
Kim Morrison (May 22 2024 at 23:22):
Seems to work fine with import Batteries.Data.List.Lemmas
.
Kim Morrison (May 22 2024 at 23:23):
You may need to upgrade from v4.7.0 to v4.8.0-rc2, but I suspect it should work fine in v4.7.0
Kim Morrison (May 22 2024 at 23:24):
Batteries is not included by default, so you need to have a
[[require]]
name = "batteries"
git = "https://github.com/leanprover-community/batteries"
rev = "main"
in your lakefile.toml (or equivalent in lakefile.lean).
David Pearce (May 22 2024 at 23:30):
I managed to get this to work with 4.8.0-rc2
:
import Batteries
-- A set of zero or more bytes upto a given size.
structure FinVec {n:Nat} (T) where
data : List T
isLt : data.length <= n
def slice32(l:List Nat) : (FinVec (n:=32) Nat) :=
let bytes := (l.take 32)
-- Prove bytes has at most 32 elements.
have q : bytes.length ≤ 32 := by apply List.length_take_le
-- Construct FinVec
{data:=bytes, isLt:=q}
David Pearce (May 22 2024 at 23:30):
I thought import Std
was a thing? It definitely worked for me at some point.
Kim Morrison (May 22 2024 at 23:31):
Std
was renamed to Batteries
. Sorry for the confusion!
David Pearce (May 22 2024 at 23:41):
So did you still need to require
it when it was Std
?
David Pearce (May 22 2024 at 23:44):
Yeah, so the release notes for 4.7.0
say this:
Lean 4.7.0 has been released! While this release includes the usual collection of quality-of-life improvements and bug fixes, the most noticable change is that a large part of
Std
, the external standard library, is included with Lean.
Kim Morrison (May 23 2024 at 00:37):
Yes, it's true that many lemmas don't require any imports any more, but this was not a wholesale ingestion of Std. ("large part", not "all")
David Pearce (May 23 2024 at 00:41):
So how are you supposed to import stuff that is now included automatically with Lean? Or is it just automatically available?
Kim Morrison (May 23 2024 at 00:41):
It is just automatic.
Last updated: May 02 2025 at 03:31 UTC