Read a variable's value from the environment.
It is convenient to regard every possible variable to be explicitly or implicitly present in the environment, by regarding the value associated to a variable not explicitly present as 0, as if the variable were explicitly present and had value 0. This way, this reading function is total: it always yields an integer value for each variable and environment.
Function:
(defun read-var (var env) (declare (xargs :guard (and (stringp var) (envp env)))) (b* ((var-val (omap::assoc (str-fix var) (env-fix env)))) (if (null var-val) 0 (cdr var-val))))
Theorem:
(defthm integerp-of-read-var (b* ((val (read-var var env))) (integerp val)) :rule-classes :rewrite)
Theorem:
(defthm read-var-of-str-fix-var (equal (read-var (str-fix var) env) (read-var var env)))
Theorem:
(defthm read-var-streqv-congruence-on-var (implies (acl2::streqv var var-equiv) (equal (read-var var env) (read-var var-equiv env))) :rule-classes :congruence)
Theorem:
(defthm read-var-of-env-fix-env (equal (read-var var (env-fix env)) (read-var var env)))
Theorem:
(defthm read-var-env-equiv-congruence-on-env (implies (env-equiv env env-equiv) (equal (read-var var env) (read-var var env-equiv))) :rule-classes :congruence)