CBV_CONV : compset -> conv
The simplification sets are mutable objects, this means they are extended by side-effect. The function new_compset will create a new set containing reflexivity (REFL_CLAUSE), plus the supplied rewrites. Theorems can be added to an existing compset with the function add_thms.
It is also possible to add conversions to a simplification set with add_conv. The only restriction is that a constant (c) and an arity (n) must be provided. The conversion will be called only on terms in which c is applied to n arguments.
Two theorem “preprocessors” are provided to control the strictness of the arguments of a constant. lazyfy_thm has pattern variables on the left hand side turned into abstractions on the right hand side. This transformation is applied on every conjunct, and removes prenex universal quantifications. A typical example is COND_CLAUSES:
(COND T a b = a) /\ (COND F a b = b)
(COND T = \a b. a) /\ (COND F = \a b. b)
Conversely, strictify_thm does the reverse transformation. This is particularly relevant for LET_DEF:
LET = \f x. f x --> LET f x = f x
It is necessary to provide rules for all the constants appearing in the expression to reduce (all also for those that appear in the right hand side of a rule), unless the given constant is considered as a constructor of the representation chosen. As an example, reduceLib.num_compset creates a new simplification set with all the rules needed for basic boolean and arithmetical calculations built in.
- val rws = new_compset [lazyfy_thm COND_CLAUSES]; > val rws = <compset> : compset - CBV_CONV rws (--`(\x.x) ((\x.x) if T then 0+0 else 10)`--); > val it = |- (\x. x) ((\x. x) (if T then 0 + 0 else 10)) = 0 + 0 : thm - CBV_CONV (reduceLib.num_compset()) (--`if 100 - 5 * 5 < 80 then 2 EXP 16 else 3`--); > val it = |- (if 100 - 5 * 5 < 80 then 2 ** 16 else 3) = 65536 : thm
val eqn = bossLib.Define `exp n p = if p=0 then 1 else n * (exp n (p-1))`; val _ = add_thms [eqn] computeLib.the_compset; - CBV_CONV rws (--`exp 2 n`--); > Interrupted. - set_skip rws "COND" (SOME 1); > val it = () : unit - CBV_CONV rws (--`exp 2 n`--); > val it = |- exp 2 n = (if n = 0 then 1 else 2 * exp 2 (n - 1)) : thm
exp 2 n if n = 0 then 1 else 2 * exp 2 (n-1) if n = 0 then 1 else 2 * if (n-1) = 0 then 1 else 2 * exp 2 (n-1-1) ...
- val th = ASSUME (--`0 = x`--); - val tm = Term`\(x:num). x = 0`; - val rws = from_list [th]; - CBV_CONV rws tm;