Semantics of Imp arithmetic expressions.
This is formalized via an evaluation function that maps an arithmetic expression and an envionment to an integer. The integer is the value of the expression given the environment.
The (recursive) evaluation of Imp's arithmetic expressions always terminates.
This evaluation function is executable.
Function:
(defun aeval (exp env) (declare (xargs :guard (and (aexpp exp) (envp env)))) (aexp-case exp :const exp.value :var (read-var exp.name env) :add (+ (aeval exp.left env) (aeval exp.right env)) :mul (* (aeval exp.left env) (aeval exp.right env))))
Theorem:
(defthm integerp-of-aeval (b* ((int (aeval exp env))) (integerp int)) :rule-classes :rewrite)
Theorem:
(defthm aeval-of-aexp-fix-exp (equal (aeval (aexp-fix exp) env) (aeval exp env)))
Theorem:
(defthm aeval-aexp-equiv-congruence-on-exp (implies (aexp-equiv exp exp-equiv) (equal (aeval exp env) (aeval exp-equiv env))) :rule-classes :congruence)
Theorem:
(defthm aeval-of-env-fix-env (equal (aeval exp (env-fix env)) (aeval exp env)))
Theorem:
(defthm aeval-env-equiv-congruence-on-env (implies (env-equiv env env-equiv) (equal (aeval exp env) (aeval exp env-equiv))) :rule-classes :congruence)