Monday, 8 January 2018

divisibility - Extended Euclidean Algorithm problem



I'm confused about how to do the extended algorithm. For example, here's the gcd part

gcd(8000,7001)



8000=70011+9997001=9997+8999=8124+78=71+17=17+0gcd



Now, the extended algorithm




\begin{align}1 &= 8 - 1\cdot7\\ &= 8 - 1\cdot(999 - 8\cdot124)\\ &= -1\cdot999 + 8\cdot125\end{align}



How do you get this 8*125 from the previous line?


Answer



\begin{eqnarray}\!\text{By the distributive law}\ \ && \,8\:\!\ \overbrace{ -\, 1\cdot(999\,-\,8\cdot 124)}^{\textstyle -1\,(a\!-\!b) = -a\! +\! b\ }\\ &=&\ 8\cdot\color{#c00}1\, -\, 999\, +\, 8\cdot\color{#c00}{124}\\ &=&\ 8\cdot\color{#0a0}{ 125} - 999\ \ \,{\rm by}\ \ \color{#c00}{124 + 1} = \color{#0a0}{125}\end{eqnarray}




This "back-substitution method" for the extended gcd is notoriously error-prone. Simpler to compute and easier to remember is the method described here., where we keep track of each remainder's expression as a linear combination of the gcd arguments. Executing that algorithm yields



\begin{array}{rrr} 8000 & 1 & 0\\ 7001 & 0 & 1\\ 999 & 1 & -1\\ 8 & -7& 8\\ -1 & \!\!\color{#c00}{876} & \!\!\!\color{#0a0}{-1001}\end{array}



where each line \,\ a\ \ b\ \ c\ \, means that \ a = 8000\, b + 7001\, c.\ Therefore




1 = -\color{#c00}{876}\cdot 8000 + \color{#0a0}{1001}\cdot 7001



The linked post described the algorithm in great detail, in a way that is easy to remember.



Here is another example computing \rm\ gcd(141,19),\, with the equations written explicitly



\rm\begin{eqnarray} [\![1]\!]\ \ \ \, \color{#C00}{141}\!\ &=&\,\ \ 1&\cdot& 141\, +\ 0&\cdot& 19 \\ [\![2]\!]\quad\ \color{#C00}{19}\ &=&\,\ \ 0&\cdot& 141\, +\ 1&\cdot& 19 \\ \color{#940}{[\![1]\!]-7\,[\![2]\!]}\, \rightarrow\, [\![3]\!]\quad\ \ \ \color{#C00}{ 8}\ &=&\,\ \ 1&\cdot& 141\, -\ 7&\cdot& 19 \\ \color{#940}{[\![2]\!]-2\,[\![3]\!]}\,\rightarrow\,[\![4]\!]\quad\ \ \ \color{#C00}{3}\ &=& {-}2&\cdot& 141\, + 15&\cdot& 19 \\ \color{#940}{[\![3]\!]-3\,[\![4]\!]}\,\rightarrow\,[\![5]\!]\quad \color{#C00}{{-}1}\ &=&\,\ \ 7&\cdot& 141\, -\color{#0A0}{ 52}&\cdot& \color{#0A0}{19} \end{eqnarray}\qquad\qquad\qquad\quad


No comments:

Post a Comment

real analysis - How to find lim_{hrightarrow 0}frac{sin(ha)}{h}

How to find \lim_{h\rightarrow 0}\frac{\sin(ha)}{h} without lhopital rule? I know when I use lhopital I easy get $$ \lim_{h\rightarrow 0}...