### Evaluating Arithmetic Expressions

Order of Operations

 × ÷ + −

### Circles of Evaluation

Another way to show order of operations uses circles. 4
2
4 − 2

#### Circle Rules

1. Each circle must have one function, which goes at the top.
2. The numbers are written below the function, in order from left to right. ×
8
3
8 × 3 ×
7
4
1
7 × (4 − 1) ×
+
6
9
4
1
(6 + 9) × (4 − 1)

#### Legal Expressions in Scheme 4
2
(− 4 2)

#### Rules for Legal Expressions

1. Any value is a legal expression.
2. Each open parenthesis is followed by one function, then by one or more legal expressions, and finally by a closing parenthesis. ×
8
3
(× 8 3) ×
7
4
1
(× 7 (− 4 1)) ×
+
6
9
4
1
(× (+ 6 9) (− 4 1))

#### Functions, Names and Arguments

1. Each function has an opening and closing parenthesis.
2. Each function has a name.
3. All the expressions that follow the function name are called arguments to the function.

Example:

For the expression (+ 4 3), the name of the function is +, and the arguments are 4 and 3.

#### Writing a Math Expression as a Scheme Legal Expression

1. Draw a circle of evaluation for the math expression.
2. Write the legal expression for the circle of evaluation.

Example:

Given the math expression 17 + (4 − 3)

The circle of evaluation is: +
17
4
3

The legal expression is: (+ 17 (− 4 3))

#### Final Footnote - Three Ways of Writing Expressions

 infix 4 + 2 Used in math class prefix + 4 2 Used in Scheme postfix 4 2 + Used in other programming
Computer Programming Unit 1.4 - How to Construct Legal Statements in the Scheme Programming Language