new_list_rec_definition : ((string # term) -> thm)
|- !x f. ?! fn. (fn[] = x) /\ (!h t. fn(CONS h t) = f(fn t)h t)Evaluating
new_list_rec_definition
(`fun_DEF`,
"(fun x_1 ... [] ... x_i = f_1[x_1, ..., x_i]) /\
(fun x_1 ... (CONS h t) ... x_i =
f_2[fun t_1 ... t ... t_i, x_1, ..., h, t, ..., x_i])");;
where all the free variables in the terms t_1, ..., t_i are
contained in {h,t,x_1,...,x_i}, automatically proves the theorem:
|- ?fun. !x_1 ... x_i. fun x_1 ... [] ... x_i = f_1[x_1, ..., x_i] /\
!x_1 ... x_i. fun (CONS h t) x_1 ... x_i =
f_2[fun t_1 ... t ... t_i, x_1, ..., h, t, ...,x_i]
and then declares a new constant fun with this property as its
specification. This constant specification is returned as a theorem by
new_list_rec_definition and is saved with name fun_DEF in the
current theory segment.
The ML function new_list_rec_definition also allows the user to partially specify the value of a function defined (possibly recursively) on lists by giving its value for only one of [] or CONS h t. See the examples below.
new_list_rec_definition
(`LENGTH`,
"(LENGTH NIL = 0) /\
(!h:*. !t. LENGTH (CONS h t) = SUC (LENGTH t))")
When this ML expression is evaluated, HOL uses list_Axiom
to prove existence of a function that satisfies the given primitive
recursive definition, introduces a constant to name this function
using a constant specification, and stores the resulting theorem:
LENGTH |- (LENGTH[] = 0) /\ (!h t. LENGTH(CONS h t) = SUC(LENGTH t))
in the current theory segment (in this case, the theory list).
Using new_list_rec_definition, the predicate NULL and the
selectors HD and TL are defined
in the theory list by the
specifications:
NULL |- NULL[] /\ (!h t. ~NULL(CONS h t))
HD |- !(h:*) t. HD(CONS h t) = h
TL |- !(h:*) t. TL(CONS h t) = t