3

I apologize if this is a duplicate question (believe me, I've searched). This question is a part of an ungraded class warm-up exercise.

Question:
Using induction, prove that for all positive integers $x$ and $y$, that $g(x,y)$ computes the GCD of $x$ and $y$:

$$g(x,y) = \left\{\matrix{x & \text{ if }~~~x=y\\g(x-y,y) & \text{ if }~~~ x>y\\g(x,y-x) & \text{ if }~~~x<y}\right.$$

Edit:
Since this is a piecewise function, the base case confuses me. Am I supposed to do three separate base cases here? Also, the fact that this is recursive is not helping.
The first thing I would do is the base case where x and y equals 1, so: gcd(1,1) = 1 since x=y.
From there I don't really know where to go.

Apparently, knowing how to do this problem is a prerequisite for the class, which is stressing me out because I have never encountered an induction proof like this, and I really don't want to drop the class if I don't have to.

  • 1
    Welcome to math.SE: since you are new, I wanted to let you know a few things about the site. In order to get the best possible answers, it is helpful if you say in what context you encountered the problem, and what your thoughts on it are; this will prevent people from telling you things you already know, and help them give their answers at the right level. – Winther Oct 04 '15 at 00:46
  • Certainly. I appreciate your help, and for reformatting the function. I have edited my original question with some more context/thoughts. – original_jared Oct 04 '15 at 01:03
  • Here is one possible approach. Assume for induction that the formula holds for all $(x,y)$ with $x,y\leq n$ for some integer $n$. We now want to prove it for all $(x,y)$ with $x,y\leq n+1$. This means proving $g(n+1,y) = \gcd(n+1,y)$ for all $y=1,2,\ldots,n+1$ (the case $g(x,n+1)$ follows by symmetry). The case $y=n+1$ is simple: $g(n+1,n+1)=n+1$ and $\gcd(n+1,n+1)=n+1$. Further we have $g(n+1,y) = g(n+1-y,y)$ and you already know that $g(n+1-y,y) = \gcd(n+1-y,y)$ by the induction hypotesis so to compute the induction step you need to prove that $\gcd(n+1,y) = \gcd(n+1-y,y)$. – Winther Oct 04 '15 at 01:11
  • In general, with problems like this, any case that gives you a definite answer (e.g. the first one) is a base case of the induction. Any case that is recursive is part of the inductive step (so cases 2 and 3 here). I think you will need to use strong induction to prove the claim, noting that the recursion always results in a reduction in the sum of the two arguments of the function, e.g. $x+y \mapsto x$ or $x+y \mapsto y$. – Marconius Oct 04 '15 at 01:15
  • 1
    I would try induction on $|x-y|$ with my hypothesis being that the algorithm works for all $|x-y| \le n$. You will need to verify that $\gcd(x,y) = \gcd(x, x-y)$. – Steven Alexis Gregory Oct 04 '15 at 19:46
  • See here for a detalied explanation of the intuition and induction (this is for a proof of the gcd Bezout identity, but the same method works here). – Bill Dubuque Mar 20 '23 at 23:37

2 Answers2

1

Make an initial WLOG assumption in your solution that $x\geq y$, and try to solve the problem using strong induction on $x$.

So your Base Case can be $x=1$ (and also $y=1$). After proving the Base Case, you need strong induction.

Strong induction is basically where we assume that the Base Case holds for all values uptill some $k$, and prove it for $k+1$. So, if the claim holds for all values of $x$ till $k$, then let $x=k+1$.

In your inductive step, you will have to take both cases $x=y=k+1$ and $x=k+1>y$. In the first case, you are done because $g(x,y)=k+1=\gcd(x,y)$. In the second case, you will have to use the Strong Induction assumption. The third case doesn't matter because we have established before that $x\geq y$.

Hope this helps. Let me know if you have a question. Here's the solution;

WLOG, we will let $x\geq y$ for this problem. We want to show that given any positive integer $x$, for each positive integer $y\leq x$, we have $g(x,y)=\gcd(x,y)$. We will prove this by strong induction on $x$. For $x=1$, we have $x=y=1$ and $$g(x,y)=1=\gcd(1,1).$$So the Base Case holds. Now, suppose that for each $x\in\{1,2,\dots,k\}$ our claim holds. Then we will show that for $x=k+1$ the claim holds. Let $x=k+1$, then $y=k+1$ or $y\in\{1,2,\dots,k\}$. If $y=k+1$, then $x=y=k+1$, and $$g(x,y)=k+1=\gcd(x,y).$$If $y\in\{1,2,\dots,k\}$, then we have $$g(x,y)=g(x-y,y).$$By the inductive hypothesis,$$g(x-y,y)=\gcd(x-y,y)=\gcd(x,y).$$So $g(x,y)=\gcd(x,y)$ in all cases, and we're done.

MathMinded
  • 1,318
0

What have you tried so far? What are you planning to use as your base case/cases and induction step?

Edit: Your idea of 1,1 is on the right track, but think of the base case as being more general. The base case can be any case where the answer is easy to test, and where you can't induct any lower. Basically these are the endpoint/edge cases,

For example, take 10 and 6. g(10,6)=g(4,6)=g(4,2)=g(2,2)=2. Another example: 15 and 5. g(15,5)=g(10,5)=g(5,5)=5.

We seem to be stopping at the g(x,y), x=y step. Which is great because that is easy to check -- of course gcd(x,x)=x.

The fact that there are three parts just means you have 3 induction steps, depending on xy, x=y. However once you get one, the other two should be easy.

Nate 8
  • 514
  • Since this is a piecewise function, the base case confuses me. Am I supposed to do three separate base cases here? Also, the fact that this is recursive is really throwing me off.

    The first thing I would do is the base case where x and y equals 1, so:

    gcd(1,1) = 1 since x=y. From there I don't really know where to go.

    – original_jared Oct 03 '15 at 23:58
  • Unfortunately I was told I didn't have enough reputation to do so. – Nate 8 Oct 04 '15 at 00:43