Compat.new_prim_rec_definition : (string * term) -> thm
|- !e f. ?! fn. (fn 0 = e) /\ (!n. fn(SUC n) = f(fn n)n)Evaluating
new_prim_rec_definition ("fun_DEF", --`(fun x_1 ... 0 ... x_i = f_1[x_1, ..., x_i]) /\ (fun x_1 ... (SUC n) ... x_i = f_2[fun t_1 ... n ... t_i, x_1, ..., n, ..., x_i])`--);where all the free variables in the terms t_1, ..., t_i are contained in {n, x_1, ..., x_i}, automatically proves the theorem:
|- ?fun. !x_1 ... x_i. fun x_1 ... 0 ... x_i = f_1[x_1, ..., x_i] /\ !x_1 ... x_i. fun (SUC n) x_1 ... x_i = f_2[fun t_1 ... n ... t_i, x_1, ..., n, ...,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_prim_rec_definition and is saved with name fun_DEF in the current theory segment.
The ML function new_prim_rec_definition also allows the user to partially specify the value of a function defined (possibly recursively) on the natural numbers by giving its value for only one of 0 or SUC n. See the example below.
- val PLUS = new_prim_rec_definition = (`PLUS`, = (--`(plus 0 n = n) /\ = (plus (SUC m) n = SUC(plus m n))`--)); PLUS = |- (!n. plus 0 n = n) /\ (!m n. plus(SUC m)n = SUC(plus m n))or by primitive recursion on its second argument:
- val PLUS = new_prim_rec_definition = (`PLUS`, = (--`(plus m 0 = m) /\ = (plus m (SUC n) = SUC(plus m n))`--)); PLUS = |- (!m. plus m 0 = m) /\ (!m n. plus m(SUC n) = SUC(plus m n))A decrement function DEC, whose value is specified for only positive natural numbers, can be defined using new_prim_rec_definition as follows
- val DEC = new_prim_rec_definition = (`DEC`, (--`DEC (SUC n) = n`--)); DEC = |- !n. DEC(SUC n) = nThis definition specifies the value of the function DEC only for positive natural numbers. In particular, the value of DEC 0 is left unspecified, and the only non-trivial property that can be proved to hold of the constant DEC is the property stated by the theorem returned by the call to new_prim_rec_definition shown in the session above.