Zulip Chat Archive

Stream: lean4

Topic: induction in conv mode


Tomas Skrivan (Feb 17 2024 at 19:09):

I would like to inductively rewrite terms in conv mode. My application would be to compute derivatives of recursively defined functions.

I have a buggy prototype that can do induction over natural numbers. You can rewrite: n+n to Nat.recOn n 0 fun n' xₙ => xₙ + 2 using conv command induction n (simp) (rw[thm1,eq]).

Here is the full code:

code

Unfortunately it produces an error (kernel) declaration has free variables '_example'. What did I do wrong?

Also compiler can't work with Nat.recOn, what should I do to produce executable code? How can I generalize this to any inductive type?

Kyle Miller (Feb 17 2024 at 19:12):

Check out compile_inductive% in mathlib. It's used to autogenerate compiled definitions for recursors, and for example there's compile_inductive% Nat already in Mathlib.Util.CompileInductive

Tomas Skrivan (Feb 17 2024 at 19:17):

This is very nice! I just include that file and I can eval #eval (Nat.recOn (motive:=fun _ => Nat) 10 0 fun n' xₙ => xₙ + 2)

Tomas Skrivan (Feb 17 2024 at 20:17):

I found the mistake, instead of replaceFVars #[xₙ',eqₙ''] there should be replaceFVars #[xₙ',eqₙ'] and the kernel error is gone.


Last updated: May 02 2025 at 03:31 UTC