Check if a sum test expression is statically well-formed.
(check-sum-test-expression target target-result alternative expr ctxt) → result
The type of the target expression must be (a subtype of) a sum type. The alternative must be one of that sum type. The type of the whole expression is boolean.
Function:
(defun check-sum-test-expression (target target-result alternative expr ctxt) (declare (xargs :guard (and (expressionp target) (type-resultp target-result) (identifierp alternative) (expressionp expr) (contextp ctxt)))) (declare (ignorable expr)) (let ((__function__ 'check-sum-test-expression)) (declare (ignorable __function__)) (type-result-case target-result :err (type-result-err target-result.info) :ok (b* ((type (ensure-single-type target-result.types)) ((when (not type)) (type-result-err (list :multi-valued-sum-test-target (expression-fix target) target-result.types))) (type (max-supertype type (context->tops ctxt))) ((when (not type)) (type-result-err (list :no-max-supertype type))) (tsum (get-type-sum type (context->tops ctxt))) ((when (not tsum)) (type-result-err (list :sum-test-type-mismatch type))) (product (get-alternative-product alternative (type-sum->alternatives tsum))) ((when (not product)) (type-result-err (list :sum-test-no-alternative tsum (identifier-fix alternative))))) (make-type-result-ok :types (list (type-boolean)) :obligations target-result.obligations)))))
Theorem:
(defthm type-resultp-of-check-sum-test-expression (b* ((result (check-sum-test-expression target target-result alternative expr ctxt))) (type-resultp result)) :rule-classes :rewrite)
Theorem:
(defthm check-sum-test-expression-of-expression-fix-target (equal (check-sum-test-expression (expression-fix target) target-result alternative expr ctxt) (check-sum-test-expression target target-result alternative expr ctxt)))
Theorem:
(defthm check-sum-test-expression-expression-equiv-congruence-on-target (implies (expression-equiv target target-equiv) (equal (check-sum-test-expression target target-result alternative expr ctxt) (check-sum-test-expression target-equiv target-result alternative expr ctxt))) :rule-classes :congruence)
Theorem:
(defthm check-sum-test-expression-of-type-result-fix-target-result (equal (check-sum-test-expression target (type-result-fix target-result) alternative expr ctxt) (check-sum-test-expression target target-result alternative expr ctxt)))
Theorem:
(defthm check-sum-test-expression-type-result-equiv-congruence-on-target-result (implies (type-result-equiv target-result target-result-equiv) (equal (check-sum-test-expression target target-result alternative expr ctxt) (check-sum-test-expression target target-result-equiv alternative expr ctxt))) :rule-classes :congruence)
Theorem:
(defthm check-sum-test-expression-of-identifier-fix-alternative (equal (check-sum-test-expression target target-result (identifier-fix alternative) expr ctxt) (check-sum-test-expression target target-result alternative expr ctxt)))
Theorem:
(defthm check-sum-test-expression-identifier-equiv-congruence-on-alternative (implies (identifier-equiv alternative alternative-equiv) (equal (check-sum-test-expression target target-result alternative expr ctxt) (check-sum-test-expression target target-result alternative-equiv expr ctxt))) :rule-classes :congruence)
Theorem:
(defthm check-sum-test-expression-of-expression-fix-expr (equal (check-sum-test-expression target target-result alternative (expression-fix expr) ctxt) (check-sum-test-expression target target-result alternative expr ctxt)))
Theorem:
(defthm check-sum-test-expression-expression-equiv-congruence-on-expr (implies (expression-equiv expr expr-equiv) (equal (check-sum-test-expression target target-result alternative expr ctxt) (check-sum-test-expression target target-result alternative expr-equiv ctxt))) :rule-classes :congruence)
Theorem:
(defthm check-sum-test-expression-of-context-fix-ctxt (equal (check-sum-test-expression target target-result alternative expr (context-fix ctxt)) (check-sum-test-expression target target-result alternative expr ctxt)))
Theorem:
(defthm check-sum-test-expression-context-equiv-congruence-on-ctxt (implies (context-equiv ctxt ctxt-equiv) (equal (check-sum-test-expression target target-result alternative expr ctxt) (check-sum-test-expression target target-result alternative expr ctxt-equiv))) :rule-classes :congruence)