Remove all the dead if bramches in a term.
(remove-dead-if-branches term) → new-term
Each
Function:
(defun remove-dead-if-branches (term) (declare (xargs :guard (pseudo-termp term))) (let ((__function__ 'remove-dead-if-branches)) (declare (ignorable __function__)) (b* (((when (variablep term)) term) ((when (fquotep term)) term) (fn (ffn-symb term)) ((when (and (eq fn 'if) (= (len (fargs term)) 3))) (cond ((member-equal (fargn term 1) (list *t* (fcons-term 'not (list *nil*)))) (remove-dead-if-branches (fargn term 2))) ((member-equal (fargn term 1) (list *nil* (fcons-term 'not (list *t*)))) (remove-dead-if-branches (fargn term 3))) (t (cons 'if (cons (remove-dead-if-branches (fargn term 1)) (cons (remove-dead-if-branches (fargn term 2)) (cons (remove-dead-if-branches (fargn term 3)) 'nil))))))) (new-args (remove-dead-if-branches-lst (fargs term))) ((when (symbolp fn)) (fcons-term fn new-args))) (fcons-term (make-lambda (lambda-formals fn) (remove-dead-if-branches (lambda-body fn))) new-args))))
Function:
(defun remove-dead-if-branches-lst (terms) (declare (xargs :guard (pseudo-term-listp terms))) (let ((__function__ 'remove-dead-if-branches-lst)) (declare (ignorable __function__)) (b* (((when (endp terms)) nil) (new-term (remove-dead-if-branches (car terms))) (new-terms (remove-dead-if-branches-lst (cdr terms)))) (cons new-term new-terms))))
Theorem:
(defthm return-type-of-remove-dead-if-branches.new-term (implies (and (pseudo-termp term)) (b* ((?new-term (remove-dead-if-branches term))) (pseudo-termp new-term))) :rule-classes :rewrite)
Theorem:
(defthm return-type-of-remove-dead-if-branches-lst.new-terms (implies (and (pseudo-term-listp terms)) (b* ((?new-terms (remove-dead-if-branches-lst terms))) (and (pseudo-term-listp new-terms) (equal (len new-terms) (len terms))))) :rule-classes :rewrite)