A measure for recurring over expressions.
(vl-expr-count x) → *
This measure has a few nice properties. It respects all of the equivalences for expressions and avoids having a function for vl-maybe-expr-p.
Note that we don't count the attributes of an atom. Normally there's not any reason to descend into their attributes, so this doesn't really matter. We might some day extend this function to also count atom attributes.
Theorem:
(defthm vl-exprlist-count-of-cons (equal (vl-exprlist-count (cons a x)) (+ 1 (vl-expr-count a) (vl-exprlist-count x))))
Theorem:
(defthm vl-expr-count-of-car-weak (<= (vl-expr-count (car x)) (vl-exprlist-count x)) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm vl-expr-count-of-car-strong (implies (consp x) (< (vl-expr-count (car x)) (vl-exprlist-count x))) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm vl-expr-kind-when-vl-expr-count-is-1-fwd (implies (equal (vl-expr-count x) 1) (equal (vl-expr-kind x) :atom)) :rule-classes ((:forward-chaining)))
Theorem:
(defthm vl-exprlist-count-of-cdr-weak (<= (vl-exprlist-count (cdr x)) (vl-exprlist-count x)) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm vl-exprlist-count-of-cdr-strong (implies (consp x) (< (vl-exprlist-count (cdr x)) (vl-exprlist-count x))) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm vl-atts-count-when-atom (implies (atom x) (equal (vl-atts-count x) 1)))
Theorem:
(defthm vl-atts-count-of-cons (equal (vl-atts-count (cons a x)) (if (atom a) (vl-atts-count x) (+ 1 (if (cdr a) (vl-expr-count (cdr a)) 0) (vl-atts-count x)))))
Theorem:
(defthm vl-atts-count-of-cdr-weak (<= (vl-atts-count (cdr x)) (vl-atts-count x)) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm vl-atts-count-of-cdr-strong (implies (and (consp x) (consp (car x))) (< (vl-atts-count (cdr x)) (vl-atts-count x))) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm vl-expr-count-of-cdar-when-vl-atts-p (implies (and (vl-atts-p x) x) (< (vl-expr-count (cdar x)) (vl-atts-count x))) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm vl-exprlist-count-of-vl-nonatom->args-strong (implies (equal (vl-expr-kind x) :nonatom) (< (vl-exprlist-count (vl-nonatom->args x)) (vl-expr-count x))) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm vl-exprlist-count-of-vl-nonatom->atts-strong (implies (equal (vl-expr-kind x) :nonatom) (< (vl-atts-count (vl-nonatom->atts x)) (vl-expr-count x))) :rule-classes ((:rewrite) (:linear)))
Theorem:
(defthm vl-expr-count-of-vl-expr-fix-x (equal (vl-expr-count (vl-expr-fix x)) (vl-expr-count x)))
Theorem:
(defthm vl-atts-count-of-vl-atts-fix-x (equal (vl-atts-count (vl-atts-fix x)) (vl-atts-count x)))
Theorem:
(defthm vl-exprlist-count-of-vl-exprlist-fix-x (equal (vl-exprlist-count (vl-exprlist-fix x)) (vl-exprlist-count x)))
Theorem:
(defthm vl-expr-count-vl-expr-equiv-congruence-on-x (implies (vl-expr-equiv x x-equiv) (equal (vl-expr-count x) (vl-expr-count x-equiv))) :rule-classes :congruence)
Theorem:
(defthm vl-atts-count-vl-atts-equiv-congruence-on-x (implies (vl-atts-equiv x x-equiv) (equal (vl-atts-count x) (vl-atts-count x-equiv))) :rule-classes :congruence)
Theorem:
(defthm vl-exprlist-count-vl-exprlist-equiv-congruence-on-x (implies (vl-exprlist-equiv x x-equiv) (equal (vl-exprlist-count x) (vl-exprlist-count x-equiv))) :rule-classes :congruence)