0

From Eric Lehman et al.'s Mathematics for Computer Science [PDF]:

Problem 9.13. $\,$ Define the Pulverizer state machine to have: $$ \begin{align*} \text{states} ::=& \mathbb{N}^6&\\ \text{start state} ::=& (a, b, 0, 1, 1, 0)&(\text{where }a \ge b > 0)\\ \text{transitions} ::=& (x, y, s, t, u, v) \longrightarrow\\ &(y, \text{rem}(x, y), u-sq, v-tq, s, t )& (\text{for }q=\text{qcnt}(x, y), y > 0). \end{align*} $$ (a) Show that the following properties are preserved invariants of the Pulverizer machine: $$ \begin{align*} \gcd(x, y) &= \gcd(a, b), &(\text{Inv1})\\ sa + t b &= y, \text{and} &(\text{Inv2})\\ ua + vb &= x. &(\text{Inv3})\\ \end{align*} $$ (b) Conclude that the Pulverizer machine is partially correct.

(c) Explain why the machine terminates after at most the same number of transi- tions as the Euclidean algorithm.

where the Pulverizer state machine is defined as follows

Today, the Pulverizer is more commonly known as the “Extended Euclidean Gcd Algorithm,” because it is so close to Euclid’s algorithm.

some notation definition:

We use the notation $\text{qcnt}(n, d )$ for the quotient and $\text{rem}(n, d )$ for the remainder.

I can prove (a).

$\text{rem}(x,y)\ge 0$ and it is strictly decreasing when the machine runs. Does (b) says that we need to let $\text{rem}(x,y)= 0$ as the termination condition which is same as the Euclidean algorithm? This is different from the implicit condition $y=0$ implied by $y>0$.

But if so, then it will cause these 2 algorithms have the same number in (c). If not, it should take more number but not at most. Then (c) is still not as the problem expected.

Implied by wikipedia, the above process adding 2 sequences based on the standard Euclidean algorithm should have "correct" for (b) and "same number" for (c). Then what does the book mean for the above statements?

Could you offer one answer or some hints for (b)? And I will try to understand (c) based on that since someone told me it is not one good habit to ask multiple questions in one post.

Bill Dubuque
  • 282,220
An5Drama
  • 436

1 Answers1

2

For (b): The machine performs the transition $$(x,y,s,t,u,v) \mapsto (x',y',s',t',u',v') = (y, \mathrm{rem}(x,y), u-sq, v-tq, s, t) $$ if $y > 0$; otherwise, we need to understand that no transition takes place, i.e., the machine halts and 'produces a result', namely (the relevant part of) the end state $(x,y,s,t,u,v)$.

The notion of partial correctness is explained as follows on p.182 in your reference: "Partial correctness means that when there is a result, it is correct, but the process might not always produce a result, perhaps because it gets stuck in a loop."

So question (b) amounts to proving: whenever the initial state $(a,b,0,1,1,0)$ is such that the machine halts, the end result is correct. Here, using Part (a), this can be taken to mean (I leave you the task to justify this) that whenever the machine reaches an end state $(x_f,y_f = 0,s_f,t_f,u_f,v_f)$, this state satisfies $$\mathrm{gcd}(a,b) = x_f = u_f a + v_f b$$ so that the machine correctly computed $\mathrm{gcd}(a,b)$, but also correctly expresses $\mathrm{gcd}(a,b)$ as a linear integer combination of $a$ and $b$ (as claimed in Theorem 9.2.2).

For (c): Now, we need to prove that the machine always halts (for the allowed initial states) and, moreover, that it does so in no more than the number of steps used in the standard Euclidean algorithm. Hint: It may help to compare this machine with the machine defined by Equation (9.18) in Problem 9.14.

Jordan Payette
  • 6,219
  • 1
  • 13
  • 20
  • Thanks for your clarification and hints. I thought the key part is how to interpret "partial correctness". I have understood (b) if using your highlighted book definition (chapter 6 is read some time ago, I didn't pay much attention to partial correctness at that time. Sorry for that). 1. For (c), after comparison, as I have said in the question, it seems that "Extended" is only done by adding adding 2 sequences which doesn't influence termination. Then why does the problem highlight no more than? – An5Drama May 03 '24 at 01:13
  • (I will give some ideas about (c) here. If that will be long, then I will open one new post. Do you think this is fine?) 2. Then we can say "correct" based on (b,c) – An5Drama May 05 '24 at 02:17
  • 1
    @An5Drama I think your comment from two days ago already solves (c). In my opinion, the 'no more than' serves to make you think a bit: one observes the Pulverizer machine extends the Euclid machine, and from this observation alone, we know Pulverizer will terminate when (or before) the Euclid terminates (and we know Euclid terminates). This suffices to solve (c). Without further inspection of the extension, it is possible that the Pulverizer machine halts before the Euclid machine; however, closer inspection reveals no other termination condition here. – Jordan Payette May 05 '24 at 12:09