By now you should have:
NOTE: The Recursive Definition tool takes a little while to start up the first time you use it, as it needs to search the HOL system for potential primitive recursive datatypes.
This tool has four components:
Figure: Defining Size using Primitive Recursion
Now select btree from the list of types on the right. The cases of the binary tree datatype should be filled in in the Full Specification box.
Now In the Template entry type:
Size (_:'a btree)and press Return or the Apply Template button. This indicates we are defining a new constant Size ranging over polymorphic binary trees. We have to specify the 'a type constraint here, otherwise HOL will complain about a type variable being unconstrained. The Full Specification box will be adjusted to match the new template, and should look like:
(Size ((LEAF x):'a btree) = ...) /\ (Size ((NODE b1 b2):'a btree) = ...)Now edit the specification so it reads:
(Size ((LEAF x):'a btree) = 1) /\ (Size ((NODE b1 b2):'a btree) = 1 + Size b1 + Size b2)Now press the Execute button. The definition should now be entered in to the HOL system and into the theory. As before, TkHol will ask you if you want the operation added to the script file it is developing. You should press the Yes button here.
We now want to make a second recursive definition. Edit the template to show
PasteLeft (_:'a btree) btree2and press Return or the Apply Template button. Now edit the specification so it reads:
(PasteLeft ((LEAF x):'a btree) b = NODE b (LEAF x)) /\ (PasteLeft ((NODE b1 b2):'a btree) b = NODE (PasteLeft b1 b) b2)Now press the Execute button as before.