Mathematics for Computer Science
MIT 6.042J/18.062J
State Machines:
Derived Variables
Albert R Meyer, March 5, 2009
lec 5R.1
Derived Variables
A derived variable, v, is a
function giving a “value” to each
state:
v: States Values
If Vals =
, say v is “
-valued”
or “nonnegative-integer-valued”
Albert R Meyer, March 5, 2009
lec 5R.2
Derived Variables
Robot on the grid example:
2
States =
Define the
sum-value, , of a state:
an
(x,y) ::= x+y
-valued derived variable
Albert R Meyer, March 5, 2009
lec 5R.3
Derived Variables
Called derived to distinguish
from actual variables that
appear in a program.
For robot Actual: x, y
Derived:
Albert R Meyer, March 5, 2009
lec 5R.4
Derived Variables
Another derived variable:
::= (mod 2)
is {0,1}-valued
Albert R Meyer, March 5, 2009
lec 5R.5
Derived Variables
For GCD, have (actual)
variables x, y.
Proof of GCD termination:
y is strictly decreasing &
natural number-valued
Albert R Meyer, March 5, 2009
lec 5R.6
Derived Variables
Termination followed by
Well Ordering Principle:
y must take a least value.
then the algorithm is stuck
Albert R Meyer, March 5, 2009
lec 5R.7
Strictly Decreasing Variable
16
Goes down at
every step
12
8
4
0
Q0
Q1
Q2
Q3
Q4
Q5
Q6
Albert R Meyer, March 5, 2009
Q7
Q8
State
lec 5R.8
Weakly Decreasing Variable
Down or constant
after each step
16
12
8
4
0
Q0
Q1
Q2
Q3
Q4
Q5
Q6
Albert R Meyer, March 5, 2009
Q7
Q8
State
lec 5R.9
, for the Diagonal Robot
: up & down all over the
place; neither increasing nor
decreasing
: is constant; both increasing
& decreasing (weakly)
Albert R Meyer, March 5, 2009
lec 5R.10
The Down-East Robot
Robot on the
2
grid can move
West 1: (x+1,y) (x,y)
can simultaneously move
South 1 & East any amount z
(x,y+1) (x + z ,y)
Albert R Meyer, March 5, 2009
lec 5R.13
The Down-East Robot
•
•
•
•
•
(7,5)
• •
•
(2,4)
• • •
•
•
•
•
•
•
•
•
•
•
•
(0,3) •
•
•
•
•
•
•
(7,3)
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
(0,1) •
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
(15,0)
•
•
•
•
•
•
•
•
•
•
(0,0)
Albert R Meyer, March 5, 2009
L7-3.14
The Down-East Robot
Robot must eventually get
stuck at the origin, (0,0), no
matter where it starts.
Obvious?
sort of.
Albert R Meyer, March 5, 2009
lec 5R.15
The Down-East Robot
y: weakly decreasing
x: all over the place
…some derived -valued
strictly decreasing variable??
NO!
Albert R Meyer, March 5, 2009
lec 5R.16
The Down-East Robot
a state with value n will get stuck
after at most n steps. What value
to assign to state (0,1)?
no n
works
robot might go:
(0,1)(n,0)(n1,0)(0,0)
n+1 steps
Albert R Meyer, March 5, 2009
lec 5R.17
Proving Termination
using Well-founded
Partial Orders
Albert R Meyer, March 5, 2009
lec 5R.18
Partial-order valued variables
Defs of increasing/decreasing
variables extend to variables
with partially ordered values.
We’ll use values in certain
well-founded partial orders to
prove termination.
Albert R Meyer, March 5, 2009
lec 5R.19
The Down-East Robot
(x,y) (x',y') implies
(y,x) lex (y',x')
( (x,y) ) ::= (y,x)
is strictly ≺lex-decreasing
Albert R Meyer, March 5, 2009
lec 5R.28
strictly ≺lex-decreasing variable
Corollary. Down-East
Robot always terminates
…can’t move forever
Albert R Meyer, March 5, 2009
lec 5R.29
Team Problems
Problems
1&2
Albert R Meyer, March 5, 2009
lec 5R.30
© Copyright 2026 Paperzz