Generate the combination for the fields of a product type or a case of a sum type.
(deffoldred-gen-prod-combination
type fields kind kind-fn suffix targets
extra-args default combine fty-table)
→
(mv fn-term thm-term field-names thm-events)The
We generate two combination terms: one for the fold function, and one for an associated theorem. We also return the list of names of the fields, in order.
The
The
We go through the fields,
and we return a right-associated nest of the
Function:
(defun deffoldred-gen-prod-combination (type fields kind kind-fn suffix targets extra-args default combine fty-table) (declare (xargs :guard (and (symbolp type) (flexprod-field-listp fields) (symbolp kind) (symbolp kind-fn) (symbolp suffix) (symbol-listp targets) (true-listp extra-args) (symbolp combine) (alistp fty-table)))) (let ((__function__ 'deffoldred-gen-prod-combination)) (declare (ignorable __function__)) (b* (((when (endp fields)) (mv default default nil nil)) (field (car fields)) (name (flexprod-field->name field)) ((unless (symbolp name)) (raise "Internal error: malformed field name ~x0." name) (mv nil nil nil nil)) (recog (flexprod-field->type field)) ((unless (symbolp recog)) (raise "Internal error: malformed field recognizer ~x0." recog) (mv nil nil nil nil)) (info (flextype-with-recognizer recog fty-table)) (field-type (and info (flextype->name info))) ((unless (and field-type (member-eq field-type targets))) (b* (((mv fn-term thm-term rest-names thm-events) (deffoldred-gen-prod-combination type (cdr fields) kind kind-fn suffix targets extra-args default combine fty-table))) (mv fn-term thm-term (cons name rest-names) thm-events))) (accessor (flexprod-field->acc-name field)) ((unless (symbolp accessor)) (raise "Internal error: malformed field accessor ~x0." accessor) (mv nil nil nil nil)) (type-suffix (deffoldred-gen-fold-name type suffix)) (field-type-suffix (deffoldred-gen-fold-name field-type suffix)) (extra-args-names (deffoldred-extra-args-to-names extra-args)) (fn-term (cons field-type-suffix (cons (cons accessor (cons type 'nil)) extra-args-names))) (thm-term (cons field-type-suffix (cons name extra-args-names))) (field-type-suffix-of-accessor (acl2::packn-pos (list field-type suffix '-of- accessor) suffix)) (thm-events (and (eq combine 'and) (eq default t) (cons (cons 'defruled (cons field-type-suffix-of-accessor (cons (cons 'implies (cons (if kind (cons 'and (cons (cons type-suffix (cons type extra-args-names)) (cons (cons 'equal (cons (cons kind-fn (cons type 'nil)) (cons kind 'nil))) 'nil))) (cons type-suffix (cons type extra-args-names))) (cons (cons field-type-suffix (cons (cons accessor (cons type 'nil)) extra-args-names)) 'nil))) (cons ':expand (cons (cons type-suffix (cons type extra-args-names)) 'nil))))) (cons (cons 'add-to-ruleset (cons (deffoldred-gen-ruleset-name suffix) (cons (cons 'quote (cons (cons field-type-suffix-of-accessor 'nil) 'nil)) 'nil))) 'nil)))) ((mv rest-fn-term rest-thm-term rest-names more-thm-events) (deffoldred-gen-prod-combination type (cdr fields) kind kind-fn suffix targets extra-args default combine fty-table)) (names (cons name rest-names)) (all-thm-events (append thm-events more-thm-events)) ((when (equal rest-fn-term default)) (mv fn-term thm-term names all-thm-events))) (mv (cons combine (cons fn-term (cons rest-fn-term 'nil))) (cons combine (cons thm-term (cons rest-thm-term 'nil))) names all-thm-events))))
Theorem:
(defthm symbol-listp-of-deffoldred-gen-prod-combination.field-names (b* (((mv ?fn-term ?thm-term ?field-names ?thm-events) (deffoldred-gen-prod-combination type fields kind kind-fn suffix targets extra-args default combine fty-table))) (symbol-listp field-names)) :rule-classes :rewrite)
Theorem:
(defthm pseudo-event-form-listp-of-deffoldred-gen-prod-combination.thm-events (b* (((mv ?fn-term ?thm-term ?field-names ?thm-events) (deffoldred-gen-prod-combination type fields kind kind-fn suffix targets extra-args default combine fty-table))) (acl2::pseudo-event-form-listp thm-events)) :rule-classes :rewrite)