I have the following isabelle code snippet:
type_synonym vname = string
datatype aexp = N int | V vname | Plus aexp aexp
fun full_plus :: "aexp ⇒ aexp ⇒ aexp" where
"full_plus (N n⇩1) (N n⇩2) = N (n⇩1+n⇩2)" |
"full_plus (N n⇩1) (Plus (N n⇩2) a) = (Plus (N (n⇩1+n⇩2)) a)" |
"full_plus (N n⇩1) (Plus a (N n⇩2)) = (Plus (N (n⇩1+n⇩2)) a)" |
"full_plus (Plus (N n⇩1) a) (N n⇩2) = (Plus (N (n⇩1+n⇩2)) a)" |
"full_plus (Plus a (N n⇩1)) (N n⇩2) = (Plus (N (n⇩1+n⇩2)) a)" |
"full_plus (Plus a⇩1 (N n⇩1)) (Plus a⇩2 (N n⇩2)) = (Plus (N (n⇩1+n⇩2)) (Plus a⇩1 a⇩2))" |
"full_plus (Plus a⇩1 (N n⇩1)) (Plus (N n⇩2) a⇩2) = (Plus (N (n⇩1+n⇩2)) (Plus a⇩1 a⇩2))" |
"full_plus (Plus (N n⇩1) a⇩1) (Plus a⇩2 (N n⇩2)) = (Plus (N (n⇩1+n⇩2)) (Plus a⇩1 a⇩2))" |
"full_plus (Plus (N n⇩1) a⇩1) (Plus (N n⇩2) a⇩2) = (Plus (N (n⇩1+n⇩2)) (Plus a⇩1 a⇩2))" |
"full_plus a⇩1 a⇩2 = Plus a⇩1 a⇩2"
However, the function definition turns purple in jEdit. I've seen this happen when I mark a recursive lemma as [simp]
so I'm assuming this means the backend freezes or falls into an infinite loop, but never with functions. To me it seems that full_plus
does not recurse...? I've added declare [[simp_trace]]
to the program, but that just produces a long and (to me, a beginner) unintelligeble trace. I can post it here if someone wants to see it, but it's quite long.
For reference, this is for exercise 3.2 from the free online concrete semantics book. Hope someone can help me out!
I ran your function definition on my computer and it eventually finishes.
The function package which provides fun
rewrites your function definitions to equations which can be used in Isabelle proofs. For that it has to check if your definitions and the patterns on the left hand side are non-overlapping. If there are overlapping (which is the case here) it has to rewrite the definitions to non-overlapping ones1. Given your complicated definitions it needs a long time to do that.
In a nutshell, the patterns on the left hand side of your definitions are too complicated and overlap quite a bit. Try to simplify them.
1See also Manuel Eberl's comment below.