0

Im brand new to Isabelle, and HOL programming in general. One of the exercises in a text book is to:

Define a recursive function double :: nat ⇒ nat and prove double m = add m m.

Im Still trying to define it but i can't figure it out., Here is what i have done so far.

fun double :: "nat => nat"  where
"double 0 = 0" |  //my base case
"double (n) =  //I don't know what to do here

I have a function add defined as follows.

fun add :: "nat ⇒ nat ⇒ nat" where
"add 0 n = n" |
"add (Suc m) n = Suc(add m n)"

but i don't think I'm meant to use add in the definition of double. Also an explanation with the answer would be greatly appreciated. Thank you, Rainy

Eridanis
  • 410
  • 1
  • 6
  • 19

1 Answers1

1

Try to figure out how to express double (Suc n) in terms of double n and Suc. That willl give you a recursive definition.

Manuel Eberl
  • 7,858
  • 15
  • 24
  • Would this be correct: fun double :: "nat => nat" where "double 0 = 0" | "double (Suc n) = double n + Suc(Suc(0))" – Eridanis Jul 15 '14 at 14:14
  • 1
    In principle yes, but it is somehow cheating to use the built-in addition `op +` when the exercise is about `double` and `add`. Maybe you can express the same equation by just using `Suc`s without `op +` (or `add` for that matter)? – chris Jul 15 '14 at 15:04
  • 1
    I changed it to "double (Suc n) = Suc(Suc(double n))" and i get no errors, is this correct then? – Eridanis Jul 15 '14 at 15:37
  • Yes. That was the intended result. – Manuel Eberl Jul 15 '14 at 15:49