\( % Latex Preamble definitions here (mostly usepackage) \usepackage% %[dvipsnames] {xcolor} % make sure this is before the loading font packages \newcommand\hmmax{0} \newcommand\bmmax{0} \usepackage{amssymb} \usepackage{amsmath} \usepackage{mathtools} \usepackage %[dvipsnames] {graphicx} \usepackage{float} %\usepackage[numbers]{natbib} \usepackage[document]{ragged2e} % % enumitem doesn't seem to work with beamer %\usepackage[inline]{enumitem} \usepackage{wrapfig} \usepackage{stackrel} % extensible arrows \usepackage{extpfeil} % \usepackage{trfrac} \usepackage{amsthm} \usepackage{tikz} \usepackage{tikz-cd} \usepackage{tikz} \usepackage{tikz-qtree} \usetikzlibrary{automata, positioning, arrows, shapes.geometric} \usepackage{turnstile} \usepackage{comment} %https://tex.stackexchange.com/questions/21334/is-there-a-package-that-has-the-clockwise-gapped-circle-arrow-in-it % \usepackage{mathbx} \usepackage{datetime} \usepackage{datetime2} %% Also See %% http://u.cs.biu.ac.il/~tsaban/Pdf/LaTeXCommonErrs.pdf %% for general tips \usepackage{listings} \usepackage{subfigure} \usepackage{bm} \usepackage{amsfonts} %% - also included by amssymb \usepackage{mathpazo} %% - because the OP uses mathpazo, optional %\usepackage{tufte-latex} \usepackage{comment} \usepackage{mathtools} \usepackage{bussproofs} \usepackage{hyperref} %\usepackage{cleveref} \)
\( %% Your math definitions here % \newcommand{\alphaequiv}{{\underset{\raise 0.7em\alpha}{=}}} \newcommand{\yields}{\Rightarrow} \newcommand{\derives}{\overset{*}{\yields}} \newcommand{\alphaequiv}{=_{\alpha}} \newcommand{\tto}[2]{{\overset{#1}{\underset{#2}{\longrightarrow}}}} \newcommand{\transitsto}[2]{{\overset{#1}{\underset{#2}{\longrightarrow}}}} \newcommand{\xtransitsto}[2]{{\underset{#2}{\xrightarrow{#1}}}} \newcommand{\xtransitsfrom}[2]{{\underset{#2}{\xleftarrow{#1}}}} \newcommand{\xto}[2]{{\xtransitsto{#1}{#2}}} \newcommand{\xfrom}[2]{{\xtransitsfrom{#1}{#2}}} \newcommand{\xreaches}[2]{{\underset{#2}{\xtwoheadrightarrow{#1}}}} \newcommand{\reaches}[2]{{\underset{#2}{\xtwoheadrightarrow{#1}}}} %\newcommand{\reaches}[2]{{\overset{#1}{\underset{#2}{\twoheadrightarrow}}}} %\newcommand{\goesto}[2]{\transitsto{#1}{#2}} %\newcommand{\betareducesto}{{\underset{\beta}{\rightarrow}}} \newcommand{\betareducesto}{\rightarrow_{\beta}} %\newcommand{\etareducesto}{{\underset{\eta}{\rightarrow}}} \newcommand{\etareducesto}{\rightarrow_{\eta}} %\newcommand{\betaetareducesto}{{\underset{\beta\ \eta}{\rightarrow}}} \newcommand{\betaetareducesto}{\rightarrow_{\beta\eta}} \newcommand{\preducesto}{\rhd} \newcommand{\psimplifiesto}{\stackrel{\scriptstyle{*}}{\rhd}} \newcommand{\lreducesto}{\rightsquigarrow} \newcommand{\lsimplifiesto}{\stackrel{\scriptstyle{*}}{\lreducesto}} \newcommand{\rewritesto}{\hookrightarrow} \newcommand{\goesto}[1]{\stackrel{#1}{\rightarrow}} \newcommand{\xgoesto}[1]{\xrightarrow{#1}} \newcommand{\reducesto}{\stackrel{}{\rightarrow}} \newcommand{\simplifiesto}{\stackrel{\scriptstyle{*}}{\rightarrow}} \newcommand{\connected}[1]{\stackrel{#1}{\leftrightarrow}} \newcommand{\joins}{\downarrow} \newcommand{\evaluatesto}{\Longrightarrow} %\newcommand{\lit}[1]{\hbox{\sf{#1}}} \newcommand{\lit}[1]{{\sf{#1}}} \newcommand{\true}{\lit{true}} \newcommand{\false}{\lit{false}} \def\Z{\mbox{${\mathbb Z}$}} \def\N{\mbox{${\mathbb N}$}} \def\P{\mbox{${\mathbb P}$}} \def\R{\mbox{${\mathbb R}$}} \def\T{\mbox{${\mathbb T}$}} \newcommand{\Rp}{{\mathbb{R}}^+} \def\Bool{\mbox{${\mathbb B}$}} \def\Q{\mbox{${\mathbb Q}$}} \def\sA{\mbox{${\cal A}$}} \def\sB{\mbox{${\cal B}$}} \def\sC{\mbox{${\cal C}$}} \def\sD{\mbox{${\cal D}$}} \def\sF{\mbox{${\cal F}$}} \def\sG{\mbox{${\cal G}$}} \def\sL{\mbox{${\cal L}$}} \def\sP{\mbox{${\cal P}$}} \def\sM{\mbox{${\cal M}$}} \def\sN{\mbox{${\cal N}$}} \def\sR{\mbox{${\cal R}$}} \def\sS{\mbox{${\cal S}$}} \def\sO{\mbox{${\cal O}$}} \def\sT{\mbox{${\cal T}$}} \def\sU{\mbox{${\cal U}$}} \def\th{\mbox{$\widetilde{h}$}} \def\tg{\mbox{$\widetilde{g}$}} \def\tP{\mbox{$\widetilde{P}$}} \def\norm{\mbox{$\parallel$}} \def\osum{${{\bigcirc}}\!\!\!\!{\rm s}~$} \def\pf{\noindent {\bf Proof}~~} \def\exec{\mathit{exec}} \def\Act{\mathit{A\!ct}} \def\Traces{\mathit{Traces}} \def\Spec{\mathit{Spec}} \def\uns{\mathit{unless}} \def\ens{\mathit{ensures}} \def\lto{\mathit{leads\!\!-\!\!to}} \def\a{\alpha} \def\b{\beta} \def\c{\gamma} \def\d{\delta} \def\sP{\mbox{${\cal P}$}} \def\sM{\mbox{${\cal M}$}} \def\sA{\mbox{${\cal A}$}} \def\sB{\mbox{${\cal B}$}} \def\sC{\mbox{${\cal C}$}} \def\sI{\mbox{${\cal I}$}} \def\sS{\mbox{${\cal S}$}} \def\sD{\mbox{${\cal D}$}} \def\sF{\mbox{${\cal F}$}} \def\sG{\mbox{${\cal G}$}} \def\sR{\mbox{${\cal R}$}} \def\tg{\mbox{$\widetilde{g}$}} \def\ta{\mbox{$\widetilde{a}$}} \def\tb{\mbox{$\widetilde{b}$}} \def\tc{\mbox{$\widetilde{c}$}} \def\tx{\mbox{$\widetilde{x}$}} \def\ty{\mbox{$\widetilde{y}$}} \def\tz{\mbox{$\widetilde{z}$}} \def\tI{\mbox{$\widetilde{I}$}} \def\norm{\mbox{$\parallel$}} \def\sL{\mbox{${\cal L}$}} \def\sM{\mbox{${\cal M}$}} \def\sN{\mbox{${\cal N}$}} \def\th{\mbox{$\widetilde{h}$}} \def\tg{\mbox{$\widetilde{g}$}} \def\tP{\mbox{$\widetilde{P}$}} \def\norm{\mbox{$\parallel$}} \def\to{\rightarrow} \def\ov{\overline} \def\gets{\leftarrow} \def\too{\longrightarrow} \def\To{\Rightarrow} %\def\points{\mapsto} %\def\yields{\mapsto^{*}} \def\un{\underline} \def\vep{$\varepsilon$} \def\ep{$\epsilon$} \def\tri{$\bigtriangleup$} \def\Fi{$F^{\infty}$} \def\Di{\Delta^{\infty}} \def\ebox\Box \def\emp{\emptyset} \def\leadsto{\rightharpoondown^{*}} \newcommand{\benum}{\begin{enumerate}} \newcommand{\eenum}{\end{enumerate}} \newcommand{\bdes}{\begin{description}} \newcommand{\edes}{\end{description}} \newcommand{\bt}{\begin{theorem}} \newcommand{\et}{\end{theorem}} \newcommand{\bl}{\begin{lemma}} \newcommand{\el}{\end{lemma}} % \newcommand{\bp}{\begin{prop}} % \newcommand{\ep}{\end{prop}} \newcommand{\bd}{\begin{defn}} \newcommand{\ed}{\end{defn}} \newcommand{\brem}{\begin{remark}} \newcommand{\erem}{\end{remark}} \newcommand{\bxr}{\begin{exercise}} \newcommand{\exr}{\end{exercise}} \newcommand{\bxm}{\begin{example}} \newcommand{\exm}{\end{example}} \newcommand{\beqa}{\begin{eqnarray*}} \newcommand{\eeqa}{\end{eqnarray*}} \newcommand{\bc}{\begin{center}} \newcommand{\ec}{\end{center}} \newcommand{\bcent}{\begin{center}} \newcommand{\ecent}{\end{center}} % \newcommand{\la}{\langle} % \newcommand{\ra}{\rangle} \newcommand{\bcor}{\begin{corollary}} \newcommand{\ecor}{\end{corollary}} \newcommand{\bds}{\begin{defns}} \newcommand{\eds}{\end{defns}} \newcommand{\brems}{\begin{remarks}} \newcommand{\erems}{\end{remarks}} \newcommand{\bxrs}{\begin{exercises}} \newcommand{\exrs}{\end{exercises}} \newcommand{\bxms}{\begin{examples}} \newcommand{\exms}{\end{examples}} \newcommand{\bfig}{\begin{figure}} \newcommand{\efig}{\end{figure}} \newcommand{\set}[1]{\{#1\}} \newcommand{\pair}[1]{\langle #1\rangle} \newcommand{\tuple}[1]{\langle #1\rangle} \newcommand{\size}[1]{| #1 |} \newcommand{\union}{\cup} \newcommand{\Union}{\bigcup} \newcommand{\intersection}{\cap} \newcommand{\Intersection}{\bigcap} \newcommand{\B}{\textbf{B}} %\newcommand{\be}[2]{\begin{equation} \label{#1} \tag{#2} \end{equation}} \newcommand{\abs}[1]{{\lvert}#1{\rvert}} \newcommand{\id}[1]{\mathit{#1}} \newcommand{\pfun}{\rightharpoonup} \newcommand{\ra}[1]{\kern-1.5ex\xrightarrow{\ \ #1\ \ }\phantom{}\kern-1.5ex} \newcommand{\ras}[1]{\kern-1.5ex\xrightarrow{\ \ \smash{#1}\ \ }\phantom{}\kern-1.5ex} \newcommand{\da}[1]{\bigg\downarrow\raise.5ex\rlap{\scriptstyle#1}} \newcommand{\ua}[1]{\bigg\uparrow\raise.5ex\rlap{\scriptstyle#1}} % \newcommand{\lift}[1]{#1_{\bot}} \newcommand{\signal}[1]{\tilde{#1}} \newcommand{\ida}{\stackrel{{\sf def}}{=}} \newcommand{\eqn}{\doteq} \newcommand{\deduce}[1]{\sststile{#1}{}} %% These don't sit very well with MathJax %% so we don't plan to use theorem like environments %% in org documents. %% instead we plan to use headings with %% 1. property drawers with a CLASS property identifying %% the environment %% 2. A tag with the same name as the CLASS property %% In LaTeX export, these turn into (sub)sections. %% See http://u.cs.biu.ac.il/~tsaban/Pdf/LaTeXCommonErrs.pdf %% \newtheorem{prop}[thm]{Proposition} %% \theoremstyle{plain}%default %% \newtheorem{theorem}{Theorem}[section] %% \newtheorem{lemma}{Lemma}[section] %% \newtheorem{corollary}{Corollary}[section] %% \newtheorem{definition}{Definition}[section] %% \newtheorem{remark}{Remark}[section] %% \newtheorem{example}{Example}[section] %% \newtheorem{exercise}{Exercise}[section] \newcommand{\less}[1]{#1_{<}} \newcommand{\pfn}{\rightharpoonup} \newcommand{\ffn}{\stackrel{{\sf fin}}{\rightharpoonup}} \newcommand{\stkout}[1]{\ifmmode\text{\sout{\ensuremath{#1}}}\else\sout{#1}\fi} % Caution: Not supported by MathJax! % ---------------------------------- % \DeclareMathSymbol{\shortminus}{\mathbin}{AMSa}{"39} % \usepackage{amsfonts} %% <- also included by amssymb % \DeclareMathSymbol{\shortminus}{\mathbin}{AMSa}{"39} \usepackage{mathpazo} %% <- because the OP uses mathpazo, optional \newcommand{\mbf}[1]{\mathbf{#1}} \newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor} \newcommand{\ceil}[1]{\left\lceil #1 \right\rceil} \newcommand{\rel}{\twoheadrightarrow} \newcommand{\map}{\rightarrow} %\newcommand{\fixed}{\boldsymbol{\circlearrowleft}} \newcommand{\terminal}{\not\xto{}{}} \newcommand{\fixed}{\bm\circlearrowleft} \newcommand{\imp}{\rightarrow} \newcommand{\dimp}{\leftrightarrow} % double implication \newcommand{\lequiv}{\Longleftrightarrow} % logical equivalence \newcommand{\limplies}{\Rightarrow} \newcommand{\lxor}{\veebar} \)
UP | HOME

Lecture notes on the ADDITION Language: Operational Semantics

Table of Contents

1 Introduction

We define a small language called ADDITION, the language of arithmetic expressions over numbers and the addition operator. While the language itself is perhaps trivial, it is still a useful test bed to introduce the two essential elements of the design and analysis of programming languages: syntax and semantics. Syntax defines what constitute expressions in a language. Semantics is concerned with their meaning. Meaning is arrived as the culmination of the execution of abstract machine(s) that manipulate expressions. This process, called evaluation, is the process by which meaning is invested into expressions of a language. The semantic approach we employ is called operational semantics, to distinguish from other types of semantic approaches (denotational, axiomatic). It consists of essentially six key components, each of which is defined as a relation involving syntax:

  • 1. Equational identities
  • 2. Rewriting (reading the equations left to write)
  • 3. Reduction (applying a rewrite rule to a subexpression)
  • 4. Simplification (a sequence of reductions)
  • 5. Evaluation (simplification to a value)
  • 6. Implementation (reduction strategies)

1.1 Motivating example

Intuitively, the approach of operational semantics is not very different from how we do algebra in high school. We evaluate algebraic expressions by the process of simplification. Each simplification step consists of a reduction that transforms an expression to another expression. Each reduction is driven by the instantiation of a rewrite rule, an equation driven in a particular direction. For example the equation \(x/x = 1\) (provided \(x\neq 0\)) could be used to drive the rewrite rule \(x/x \rewritesto 1\) (read `rewrites to').

Algebraic identities
These come from our knowledge of the underlying domain. E.g., variables in the identities represent real numbers, and the operations * and / represent division and multiplication in a field.
\begin{align*} x/x &= 1 & \quad x\neq 0\\ 1*x &= x\\ x*1 &= x \end{align*}
Rewrite Rules
These are obtained by orienting the algebraic identities in a particular direction (from left to right):
\begin{align*} x/x &\rewritesto 1 & \quad \mbox{$x\neq 0$} \quad \mbox{INV}\\ 1*x &\rewritesto x & \quad \qquad \id{ID}_\id{LEFT}\\ x*1 &\rewritesto x & \quad \qquad \id{ID}_\id{RIGHT}\\ \end{align*}

Consider the expression \((3/3)*(y/y)\), where \(y\neq 0\). This expression reduces to 1*y/y by the application of a rewrite rule. The subexpression that matches the left side of the rewrite rule is called a redex. A sequence of reductions constitute a simplification. Answers are numbers; numbers are already in the simplest possible form: they can not be reduced further. A simplification that results in an answer is called an evaluation.

Reduction, Simplification to an answer
Here is an example of an evaluation.
\begin{align*} (3/3)*(y/y) &\reducesto & \quad \mbox{using INV with $x\mapsto 3$ in the redex $3/3$}\\ 1*(y/y) &\reducesto & \quad \mbox{using INV with $x\mapsto y$ in the redex $y/y$}\\ 1*1 &\reducesto & \quad \mbox{using ID_RIGHT with $x\mapsto 1$ in the redex $1*1$}\\ 1 \end{align*}

We might say that the meaning of \((3/3)*(y/y)\) when \(y\neq 0\) is \(1\) because this expression evaluates to 1.

2 Semantic Engineering

Numerous questions arise: Does every expression simplify to an answer? Could the simplification yield multiple answers? What if the simplification process never finishes? What if multiple rewrite rules are applicable for reduction? Which one do we choose? Does it matter which one we choose first? In terms of efficiency? In terms of correctness? What does `correctness' mean anyway? What other machinery is needed to carry out simplification besides the expressions themselves, et cetera.

A semantic engineer tasked with designing a programming language is concerned with such questions, many of which have subtleties that miss the casual eye. The answer involves comparing multiple choices in the design space, with competing requirements inevitably yielding to some compromises, not uncommon in engineering design.

3 ADDITION Syntax

\begin{align*} e ::= & & \scriptstyle{EXP} & \qquad \mbox{Addition Expression}\\ & \overline{n} & \scriptstyle{NUMCONST} & \qquad \mbox{Number Literal}\\ & e + e & \scriptstyle{PLUSEXP} & \qquad \mbox{Plus Expression}\\ \\ n ::= & & \scriptstyle{NUM} & \qquad \mbox{Number} \end{align*}

4 ADDITION Rewrite (redex) rules

\[\rewritesto \subseteq \id{EXP}\times \id{EXP}\]

\begin{align*} \overline{n_1}+\overline{n_2} \rewritesto \overline{n_1+n_2}\quad \scriptstyle{PLUS} \\ \\ \\ \end{align*}

The understanding is that the above rule defines an (infinite) family of rules, one for each pair of numbers.

5 Reduction (small step semantics)

\[\reducesto \subseteq \id{EXP}\times \id{EXP}\]

\begin{align*} \frac{e \hookrightarrow e'}{e\reducesto e'}\quad \scriptstyle{REWRITE} \\ \\ \\ \frac{e_1\rightarrow e_1'}{e_1+e_2 \reducesto e_1'+e_2}\quad \scriptstyle{LEFT} \\ \\ \\ \frac{e_2\reducesto e_2'}{e_1+e_2 \reducesto e_1+e'_2}\quad \scriptstyle{RIGHT} \\ \end{align*}

\(e\) is reducible, written \(e\reducesto\), if there exists an \(e'\) such that \(e\reducesto e'\). \(e\) is irreducible if \(e\) is not reducible.

6 Simplification (reflexive-transitive closure of reduction)

\[\simplifiesto \subseteq \id{EXP}\times \id{EXP}\]

\begin{align*} \frac{}{e \simplifiesto e}\quad \scriptstyle{REFLEX} \\ \\ \\ \frac{e \reducesto e'}{e\simplifiesto e'}\quad \scriptstyle{REDUCE} \\ \\ \\ \frac{e_1\reducesto e_2\quad e_2\simplifiesto e_3}{e_1\simplifiesto e_3}\quad \scriptstyle{TRANS} \\ \\ \\ \end{align*}

7 Theorem (Simplification compatible closure)

[L1]

  • 1. If \(p \simplifiesto r\) then \(p+q\simplifiesto r+q\).
  • 2. If \(q \simplifiesto s\) then \(p+r\simplifiesto p+s\).

7.1 Proof

7.1.1 Part 1

By induction on the derivation of \(p\simplifiesto r\).

  • 1. \(\cfrac{}{p\simplifiesto r}\quad\scriptstyle{REFLEX}\): In this case \(p=r\). Therefore, we have \[\frac{}{p+q\simplifiesto r+q}\quad{\scriptstyle{REFLEX}}\]
  • 2. \(\cfrac{p\reducesto r}{p\simplifiesto r}\quad{REDUCE}\): The desired derivation of the simplification is obtained as

\[\cfrac{\cfrac{p\reducesto r}{p+q\reducesto r+q}\quad{LEFT}}{p+q\simplifiesto r+q}\quad{\scriptstyle{REDUCE}}\]

  • 3. \(\cfrac{{p\reducesto s}\quad {s\simplifiesto r}}{p\simplifiesto r}\quad{TRANS}\):

    Since \(s\simplifiesto r\), by the induction hypothesis \(s+q\simplifiesto r+q\).

    Thus we have the following derivation of simplification:

\[ \cfrac{\cfrac{\cfrac{p\reducesto s} {p+q\reducesto s+q}\quad LEFT} {p+q\simplifiesto s+q}\quad{REDUCE} \qquad{s+q\simplifiesto r+q \quad (IH)}} {p+q\simplifiesto r+q}\quad{TRANS} \]

7.1.2 Part 2

The proof is very similar to that of Part1 and is omitted.

7.2 Derived Rules

From the above, we have

\begin{align*} \frac{p\simplifiesto r}{p+q\simplifiesto r+q}\quad {LEFT*}\\ \\ \frac{q\simplifiesto s}{p+q\simplifiesto p+s}\quad {RIGHT*} \end{align*}

8 Values

We identify a set of values and a subset of expressions that represent those values. In the ADDITION language, values are numbers.

\begin{align*} v ::= & & \scriptstyle{VAL} & \qquad \mbox{Value}\\ & n & \scriptstyle{NUM} & \qquad \mbox{Number}\\ \end{align*}

8.1 Values represented by literals

Certain expressions, the literals of the form \(\overline{n}\) represent values. More precisely, a literal \(\overline{n}\) represents the value \(n\).

Note that literals are irreducible.

9 Semantic Properties of the ADDITION language

9.1 Theorem (Normal forms under \(\reducesto\) are literals)

9.1.1 Statement

\(e\) is irreducible iff \(e\) is a literal \(\overline{n}\) for some number \(n\).

9.1.2 Proof

The 'if' part follows immediately since there is no reduction for a number literal.

For the `only if' we show that \(e\) is not a literal implies \(e\) is reducible. The proof is by induction on the structure of \(e\).

If \(e\) is not a literal, then it is an addition expression, say \(e_1+e_2\). Either both \(e_1\) and \(e_2\) are literals \(\overline{n_1}\) and \(\overline{n_2}\) respectively, or one or more of \(e_1\) and \(e_2\) are not. In the first case, \(e\) reduces to \(\overline{n_1+n_2}\). In the second case, assume \(e_1\) is not a literal. By the induction hypothesis, \(e_1\) is reducible. By the LEFT rule \(e\) is reducible. The case assuming \(e_2\) is not a literal is similar and omitted.

The only if condition, viz, ``if \(e\) is not a literal implies \(e\) is reducible'' is called the progress condition. It's possible in other languages, and we will see several later, that the progress condition may be violated.

9.2 Theorem (Termination)

9.2.1 Statement

For every \(e\), there is no infinite chain of reductions \[e\reducesto e_1 \reducesto e_2 \ldots\]

9.2.2 Proof

The proof is by structural induction on \(e\). Note that the size of the expression reduces in each reduction. If \(e\reducesto e'\), then \(|e'| < |e|\).

9.3 Theorem (Normalizing)

9.3.1 Statement

\(\reducesto\) is normalizing. Every expression \(e\) has a normal form.

9.3.2 Proof

Follows from Termination.

9.4 Theorem (Local Confluence)

9.4.1 Statement

If an expression reduces to two different expressions, then those two expressions simplify to a common third expression. If \(e\reducesto e_1\) and \(e\reducesto e_2\), there there exists \(e_3\) such that \(e_1\simplifiesto e_3\) and \(e_2 \simplifiesto e_3\).

9.4.2 Proof

The proof is based on well-founded induction on the \(\reducesto\) relation over expressions. Notice that our induction scheme is based on the inductive structure of the derivations of the reduction relation \(\reducesto\), not the structure of expressions (syntax).

Assume \(e\reducesto e_1\) and \(e\reducesto e_2\). Then we have the following cases:

  • 1. \(e \reducesto e_1\) using REWRITE: Then \(e=\overline{n_1}+\overline{n_2}\). It follows that \(e_1\) and \(e_2\) are each \(\overline{n_1+n_2}\) and then \(e_1 = e_2 = e_3\), and hence \(e_1\simplifiesto e_3\) and \(e_2\simplifiesto e_3\).
  • 2. \(e \reducesto e_1\) using LEFT: Then we have \(e = p+q\) and \(e_1=p'+q\) such that \(p\reducesto p'\). Then there are two possibilities for \(e\reducesto e_2\):
    • 2.1. \(e\reducesto e_2\) using LEFT: We have \(e=p+q\) (from the parent assumption) and \(e_2=p''+ q\) such that \(p\reducesto p''\).

      From the induction hypothesis, since \(p\reducesto p'\) and \(p\reducesto p''\), both \(p'\) and \(p''\) reduce to a common expression \(r\). Using LEFT*, \(p'+q\simplifiesto r+q\) and \(p''+q\simplifiesto r+q\). Thus both \(e_1\) and \(e_2\) simplify to a common expression.

    • 2.2. \(e\reducesto e_2\) using RIGHT: We have \(e=p+q\) (from the parent assumption) and \(e_2=p+q'\) such that \(q\reducesto q'\). Then \(p'+q\) and \(p+q'\) simplify to the common expression \(p'+q'\) with the application of a LEFT and RIGHT rule, respectively.

The other cases are similar and left as an exercise.

9.5 Theorem (Confluence)

9.5.1 Statement

\(\reducesto\) is confluent.

9.5.2 Proof

Follows from termination and local confluence (see notes on Abstract Reduction systems).

9.6 Theorem (Convergence to a value)

9.6.1 Statement

Every expression simplifies to a unique literal.

9.6.2 Proof

Confluence and termination means convergence. Termination implies at least every expression simplifies to at least one normal form. Confluence implies at most one. From this it follows that every ADDITION expression reduces to a unique normal form. Since all normal forms in the ADDITION are literals, the result follows.

10 Valuation (Big step) Semantics

We define the value of an expression to be the number of the number literal to which the expression simplifies.

We write this as \(e\evaluatesto v\). The EOPL text also writes this as \(v = \id{valueof}(e)\). Notice that for ADDITION, it makes sense to say ``the'' value because the number literal to which an expression simplifies to is unique (from the above theorem).

10.1 Evaluation Rules

\[\evaluatesto \subseteq \id{EXP}\times \id{NUM}\]

\begin{align*} \frac{}{\overline{n}\evaluatesto n}\quad \scriptstyle{NUM} \\ \\ \\ \frac{{e_1\evaluatesto n_1}\qquad {e_2\evaluatesto n_2}}{e_1+e_2 \evaluatesto n_1+n_2}\quad \scriptstyle{PLUS} \\ \\ \\ \end{align*}

11 Theorem (Consistency between small-step and valuation semantics)

11.0.1 Statement

\[e\simplifiesto \overline{n}\] iff \[e\evaluatesto n\]

11.0.2 Proof

Left as an exercise.

12 Implementations (Reduction Strategies)

Notice the non-determinism inherent in the reduction relation \(\reducesto\). Either the left or the right side of a compound expression may be reduced first. The deduction system doesn't specify which one. Implementations sometimes stipulate a specific order for the evaluation of the subexpressions. This may be necessary in the presence of side effects, for example.

The strategy we employ reduces the left subexpression first to a value. Only then does it reduce the right subexpression. (using the same strategy). We call this reduction strategy left-order.

12.1 Implementation via left-order reduction

\[\xto{}{L} \subseteq \id{EXP}\times \id{EXP}\]

\begin{align*} \frac{}{\overline{n}+\overline{n_2}\xto{}{L}\ \overline{n_1+n_2}}\quad \scriptstyle{REWRITE} \\ \\ \\ \frac{e_1\ \xto{}{L}\ {e'_1}}{e_1+e_2\ \xto{}{L}\ {e'_1}+e_2}\quad \scriptstyle{LEFT} \\ \\ \\ \frac{e_2\ \xto{}{L}\ {e'_2}}{\overline{n_1}+e_2\ \xto{}{L}\ \overline{n_1}+{e'_2}}\quad \scriptstyle{RIGHT} \\ \\ \\ \end{align*}

13 Theorem (Relating reduction, evaluation and implementation)

13.0.1 Statement

\(e\simplifiesto \overline{n}\) \(\qquad\) iff \(\qquad\) \(e\xto{*}{L} \overline{n}\) \(\qquad\) iff \(\qquad\) \(e\evaluatesto n\).

13.0.2 Proof

Exercise.

Author: Venkatesh Choppella

Created: 2023-11-25 Sat 09:14

Validate