Circuits that compute on numbers: Algebra

- 1.1 Algebra
- 1.2 Arithmetic circuits
- 1.3 Single-assignment programs

Circuits are ``programs'' that are constructed from
AND, OR, NOT operations and compute on the value set, ` {t,f}`.
We use equations to name the wires within the circuit,
and we saw how to deduce properties of the circuit
even when we did not know the exact values of the circuit's inputs.
This is critical for circuit design and analysis.

We can also make
``circuits'' from the arithmetic
operations, ` +, -, *, /`, that compute on
numbers ---
numbers travel along the wires.
We apply the principles of

In this chapter, we review principles of algebra and apply them to equationally defined systems (circuits).

===================================================(By the way, this set of laws defines a(a + b) + c = a + (b + c) law assoc+ a + b = b + a law comm+ a + 0 = a law unit+ (a * b) * c = a * (b * c) law assoc* a * b = b * a law comm* a * 1 = a law unit* a * (b + c) = (a * b) + (a * c) law dist===================================================

Say
we use the numbers, ` 0`,

===================================================1 + 1 = 2 2 + 1 = 3 3 + 1 = 4 and so on, and also 0 * 0 = 0===================================================

We use the operators and arguments to write *expressions*,
like ` (3 * 2) + 1`.
We use the equational laws to calculate the expression's answer, its output,
its

Here's *why* ` 3 * 2 = 6`:

===================================================So,3 * 2 = 3 * (1 + 1) because 1 + 1 = 2 = (3 * 1) + (3 * 1) because dist = 3 + 3 because unit* (twice) = 3 + (2 + 1) because 2 + 1 = 3 = 3 + (1 + 2) because comm+ = (3 + 1) + 2 because assoc+ = 4 + 2 because 3 + 1 = 4 = ... = 6 (you do the remaining steps)===================================================

So,
let's pretend we have hardware gates for the operations, ` +, -, *`.
Now, we have circuits where

===================================================In the 1970's, this form of circuit, called a===================================================

Here is the equational system for the above circuit, where each internal wire is labelled with its own name:

This equation set uses one operation in each equation. It is calleda = x + y b = 2 * a c = y + 1 d = b - c

Let's repeat the exercises at the end of the previous chapter for
this equational system.
First, say that ` x = 3` and

===================================================Algebra calculates the numerical values for all ofpremises: x = 3, y = 2 a = x + y therefore, x = 3, y = 2, a = x + y therefore, x = 3, y = 2, a = 5 (by application of the previously viewed algebra laws) b = 2 * a therefore, x = 3, y = 2, a = 5, b = 10 c = y + 1 therefore, x = 3, y = 2, a = 5, b = 10, c = 3 d = b - c therefore, x = 3, y = 2, a = 5, b = 10, c = 3, d = 7===================================================

Next, say that we know that the circuit will be plugged into an
assembly that supplies input ` 1` to

===================================================This reasoning is similar to what we use when we write assignment commands in a programming language.premise: x = 1 a = x + y therefore, a = x + y, x = 1 a = 1 + y by substitution b = 2 * a therefore, b = 2 * a, a = 1 + y b = 2 * (1 + y) by substitution b = (2 * y) + 2 by algebra c = y + 1 therefore, c = y + 1, b = (2 * y) + 2 d = b - c therefore, d = b - c, c = y + 1, b = (2 * y) + 2 d = (2 * y) + 2 - (y + 1) by substitution d = y + 1 by algebra===================================================

Let's do one more exercise. Say we have this equation set/circuit/program:

a = x - y b = 2 * a c = b + 1

Pretend that the algebra
equations define
a real-time controller for the rudder of an airplane, and inputs ` x` and

Say that we want to validate, to *prove*,
that the value of the output, ` c`,
is greater than one, that is,

We construct the proof with
algebra. Along the way, we will prove that ` a` and

===================================================So, we have proved that when the inputs satisfy thepremises: x > y, x > 0 a = x - y since x > y, then x - y > y - y then x - y > 0 by algebra since a = x - y, then a > 0 by substitution b = 2 * a since a > 0, then 2 * a > 0 by algebra then b > 0 by substitution c = b + 1 since b > 0 then b + 1 > 0 + 1 then b + 1 > 1 by algebra then c > 1 by substitution===================================================

This style of reasoning is critical to developing correct code for embedded, real-time systems.

Like an electronics engineer, who analyzes a circuit for voltage and resistance levels, we have analyzed the program and calculated in advance of execution its behavioral properties.

If we violate either property, our analysis breaks down. Consider this "equation set":

A naive application of algebra lets us deduce a falsehood:x = 0 y = x x = x + 1

===================================================The assignment command we use in programming is different from an algebraic equality.x = 0 therefore, x == 0 y = x therefore, y == x and x == 0 x = x + 1 therefore, y == x (not any more!) x == 0 (not any more!) and also x == x + 1 (impossible!) and also 0 == 0 + 1 (impossible!)===================================================

We must distinguish between
the ``old'' value of ` x` prior to the assignment,

By the way, the first "high level" programming language, Fortran,
was designed in the 1950s by John Backus for IBM's engineers, who wanted to write and
solve equation sets. Backus knew that computer hardware used storage cells
for variables and that the cells' values could be updated. So, he
introduced the equational version of assignment to Fortran, which wrecks the
correspondence between algebra equations and program code.
Since then, there are many modern languages, the *functional programming languages*,
which prohibit Fortran-style assignment and restore the connection between
algebra and program code. Backus himself, in his Turing Award Lecture of 1977,
disavowed assignment as a fundamental programming notion.