Course contentsShow
← Computer Science
Lesson 2020 of 2,87245. Type Systems and SemanticsFree lesson

Operational Semantics of Arithmetic Expressions

Defining evaluation rules for simple arithmetic expressions with constants and binary operators.

Operational Semantics of Arithmetic Expressions

What you'll learn: How to formally define the evaluation rules for simple arithmetic expressions step-by-step.

The Core Idea

Now that you understand semantic rules and judgments, let's apply them to something concrete: arithmetic expressions. We need precise rules that describe how expressions like 3 + 5 or (2 * 4) - 1 evaluate to their final values.

Think of it like a calculator's instruction manual written in mathematical notation. Instead of vague descriptions like "add the numbers together," we write formal rules that say exactly what happens at each evaluation step.

Defining the Rules

For simple arithmetic expressions with constants and binary operators, we define evaluation rules as judgments:

Constants: A number evaluates to itself immediately.

  • Rule: n ⇓ n (where n is any numeric constant)

Binary Operations: An expression with an operator evaluates by first evaluating its left operand, then its right operand, then applying the operation.

  • Rule for addition: If e₁ ⇓ v₁ and e₂ ⇓ v₂, then e₁ + e₂ ⇓ v₁ + v₂
  • Similar rules exist for -, *, /

Example in Action

To evaluate (2 + 3) * 4:

  1. Evaluate 2 + 3: First 2 ⇓ 2, then 3 ⇓ 3, so 2 + 3 ⇓ 5
  2. Evaluate 4: Simply 4 ⇓ 4
  3. Apply multiplication: 5 * 4 ⇓ 20

These rules are compositional—complex expressions are evaluated by combining the results of simpler sub-expressions according to fixed patterns.

Key Takeaway: Operational semantics of arithmetic expressions uses formal evaluation rules that specify how constants evaluate to themselves and how binary operations combine the evaluated results of their operands.