new_list_rec_definition : ((string # term) -> thm)

SYNOPSIS
Defines a primitive recursive function over the type of lists.

DESCRIBE
The function new_list_rec_definition provides the facility for defining primitive recursive functions on the type of lists. It takes a pair argument, consisting of the name under which the resulting definition will be saved in the current theory segment, and a term giving the desired definition. The value returned by new_list_rec_definition is a theorem which states the definition requested by the user. This theorem is derived by formal proof from an instance of the theorem list_Axiom:
   |- !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.

FAILURE
Failure occurs if HOL cannot prove there is a function satisfying the specification (ie. if the term supplied to mlnew_list_rec_definition is not a well-formed primitive recursive definition), or if any other condition for making a constant specification is violated (see the failure conditions for new_specification).

EXAMPLE
The HOL system defines a length function, LENGTH, on lists by the primitive recursive definition on lists shown 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

SEEALSO  new_definition,   new_infix_definition,   new_infix_list_rec_definition,   new_infix_prim_rec_definition,   new_prim_rec_definition,   new_recursive_definition,   new_type_definition,   new_specification,   list_Axiom

HOL  Kananaskis 0