lean4-htt/tests/lean/funind_errors.lean
Kim Morrison 3a408e0e54
feat: change Array.get to take a Nat and a proof (#6032)
This PR changes the signature of `Array.get` to take a Nat and a proof,
rather than a `Fin`, for consistency with the rest of the (planned)
Array API. Note that because of bootstrapping issues we can't provide
`get_elem_tactic` as an autoparameter for the proof. As users will
mostly use the `xs[i]` notation provided by `GetElem`, this hopefully
isn't a problem.

We may restore `Fin` based versions, either here or downstream, as
needed, but they won't be the "main" functions.

---------

Co-authored-by: David Thrane Christiansen <david@davidchristiansen.dk>
2024-11-12 03:30:46 +00:00

45 lines
1.2 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Some of these tests made more sense when we had a
-- derive_functional_induction command.
#check doesNotExist.induct
def takeWhile (p : α → Bool) (as : Array α) : Array α :=
foo 0 #[]
where
foo (i : Nat) (r : Array α) : Array α :=
if h : i < as.size then
let a := as.get i h
if p a then
foo (i+1) (r.push a)
else
r
else
r
termination_by as.size - i
-- Checks the error message when the users tries to access the induct rule for the wrong function
-- (before we used reserved names for this feature we did give a more helpful error message here)
#check takeWhile.induct
#check takeWhile.foo.induct
-- this tests the error we get when trying to access the induct rules for
-- a function that recurses over an inductive *predicate* (not yet supported)
inductive Even : Nat → Prop where
| zero : Even 0
| plus2 : Even n → Even (n + 2)
def idEven : Even n → Even n
| .zero => .zero
| .plus2 p => .plus2 (idEven p)
#check idEven.induct
-- this tests the error we get when trying to access the induct rules for
-- a function that recurses over `Acc`
def idAcc : Acc p x → Acc p x
| Acc.intro x f => Acc.intro x (fun y h => idAcc (f y h))
#check idAcc.induct