0

This is one following question based on one question I asked before

In spring18 mcs.pdf, it has 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 transitions as the Euclidean algorithm.

definition of the Pulverizer State machine:

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

The state machine for the Euclidean algorithm is defined in Problem 9.14.

The Euclidean state machine is defined by the rule $$ (x, y)\longrightarrow (y,\text{rem}(x,y)), \tag{9.18} $$ for y > 0.

As wikipedia says, "Extended" is by adding 2 sequences parallelly based on the standard Euclidean algorithm.

Does Problem 9.13 say "at most" for (c) due to not caring about the specific number but only that the machine will halt? Are there some trivial cases omitted where the “Extended Euclidean Gcd Algorithm” needs less transitions than the standard one?

An5Drama
  • 436

1 Answers1

1

This is just an attempted outline (I have not actually got to the bottom of the exercise, so I do not even guarantee the correctness of what I have written below):

By definition of the Pulverizer, we have the following recurrence, where $k \in \mathbb{N}$ is the step index:

$ \begin{align*} x_0 & = a \\ y_0 & = b \\ s_0 & = 0 \\ t_0 & = 1 \\ u_0 & = 1 \\ v_0 & = 0 \\ x_{k+1} & = y_k \\ y_{k+1} & = \operatorname{rem}(x_k,y_k) \\ s_{k+1} & = u_k - s_k q_k \\ t_{k+1} & = v_k - t_k q_k \\ u_{k+1} & = s_k \\ v_{k+1} & = t_k \\ \end{align*} $

(Notice that I am not taking into account that there is a termination state, which means there is a $k$ such that the state does not change from that point on: I don't think we need this below, so I'll keep it simple.)

(a) Show that the following properties are preserved invariants of the Pulverizer machine:

$\gcd(x,y) = \gcd(a,b) \quad \text{(Inv1)}$

By induction on $k$.

  • Case $k = 0$ : prove $\gcd(x_0,y_0) = \gcd(a,b)$.

    Trivial, by unfolding the definitions of $x_0$ and $y_0$.

  • Case $k \ge 0$ : prove $\forall x_k,y_k$ :
    $\gcd(x_k,y_k) = \gcd(a,b) \to \gcd(x_{k+1},y_{k+1}) = \gcd(a,b)$.

    By transitivity of equality, we can just prove $\gcd(x_{k+1},y_{k+1}) = \gcd(x_k,y_k)$.

    By unfolding $x_{k+1}$ and $y_{k+1}$, then using properties of $\gcd$ and $\operatorname{rem}$ ...

$sa + tb = y \quad \text{(Inv2)}$

Again, by induction on $k$.

  • Case $k = 0$ : prove $s_0 a + t_0 b = y_0$.

    Trivial, by unfolding definitions.

  • Case $k \ge 0$ : prove $\forall y_k,s_k,t_k$ :
    $s_k a + t_k b = y_k \to s_{k+1} a + t_{k+1} b = y_{k+1}$.

    ...

$ua + vb = x \quad \text{(Inv3)}$

Again, by induction on $k$ ...

(b) Conclude that the Pulverizer machine is partially correct.

That is, prove that, if the Pulverizer terminates in the state $(x,y,s,t,u,v)$, then $x = \gcd(a,b)$ ...

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

By definition of the Euclidean algorithm, we have the following recurrence, where $k \in \mathbb{N}$ is the step index:

$ \begin{align*} x_0 & = a \\ y_0 & = b \\ x_{k+1} & = y_k \\ y_{k+1} & = \operatorname{rem}(x_k,y_k) \\ \end{align*} $

(Again, notice that I am not taking into account that there is a termination state, which means there is a $k$ such that the state does not change from that point on: I don't think we need this either, though a rigorous approach would have it.)

But, looking back at the recurrence for the Pulverizer, we observe that $x$ and $y$ in the Pulverizer only depend on each other and on no other component of the state. Further, the recurrence for the Pulverizer restricted to just $x$ and $y$ is exactly equivalent to the one here for the Euclidean algorithm, also considering that the condition for termination is $y=0$ for both.

So, the two definitions are exactly equivalent over the $x$ and $y$ components (for a to be precisely stated notion of equivalence). Hence, the Pulverizer cannot but stop after exactly as many steps as the Euclidean algorithm. Whence, a fortiori (i.e., all the more so), the conclusion follows.

That much for an informal sketch: a rigorous approach I suppose would have to be in the form of some bisimulation.

  • Maybe I had some ambiguity in my question (I made one small modification to my question just now after viewing your answer). Thanks for your whole solutions for the problem. But I only had questions about "no more than" in (c). Could you say more about the relation in "bisimulation" where "less than" may happen or show they must be equal? IMHO it seems like one bijection so that they have the same number, one special case of "not greater than". Is that right? (I haven't learnt about bisimulation before. Hope my understanding is right.) – An5Drama May 05 '24 at 11:12
  • As my question says, is it ok to say "equal" based on "adding 2 sequences parallelly"? If not could you give the specific bisimulation for the above 2 machines? wikipedia doesn't give one example and some lectures http://www.cse.unsw.edu.au/~cs3153/20T1/Week%2004/1Tue/Slides%20Condensed.pdf also don't give much. – An5Drama May 05 '24 at 12:00
  • "adding 2 sequences" is the verbatim rephrase of what wikipedia says. You can read there. That is clear if knowing what the extended Euclidean algorithm is. 2. FYI, my reference QA answerer replied to me saying (c) answer can be thought as "equal".
  • – An5Drama May 05 '24 at 12:23