Write a variable's value to the environment.
We add/overwrite a/the pair for the variable in the omap. We do this even if the value is 0; in this case, we could instead just remove the pair, since read-var treats an absent variable the same way as one with value 0. But we prefer to always add/overwrite the pair, avoiding any ``normalization'' of the environment (i.e. avoiding insisting that no variable in the environment has value 0). Treating an absent variable as one with value 0 is a mere convenience for having a total read-var.
Function:
(defun write-var (var val env) (declare (xargs :guard (and (stringp var) (integerp val) (envp env)))) (omap::update (str-fix var) (ifix val) (env-fix env)))
Theorem:
(defthm envp-of-write-var (b* ((new-env (write-var var val env))) (envp new-env)) :rule-classes :rewrite)
Theorem:
(defthm write-var-of-str-fix-var (equal (write-var (str-fix var) val env) (write-var var val env)))
Theorem:
(defthm write-var-streqv-congruence-on-var (implies (acl2::streqv var var-equiv) (equal (write-var var val env) (write-var var-equiv val env))) :rule-classes :congruence)
Theorem:
(defthm write-var-of-ifix-val (equal (write-var var (ifix val) env) (write-var var val env)))
Theorem:
(defthm write-var-int-equiv-congruence-on-val (implies (acl2::int-equiv val val-equiv) (equal (write-var var val env) (write-var var val-equiv env))) :rule-classes :congruence)
Theorem:
(defthm write-var-of-env-fix-env (equal (write-var var val (env-fix env)) (write-var var val env)))
Theorem:
(defthm write-var-env-equiv-congruence-on-env (implies (env-equiv env env-equiv) (equal (write-var var val env) (write-var var val env-equiv))) :rule-classes :congruence)