A list of puns related to "Euclidean algorithm"
I was playing around with GATs today and decided to challenge myself to implement the Euclidean Algorithm using only the type system. Also, to make it even harder, I used GATs wherever possible, including for implementing comparisons, addition, squaring, and multiplication on the natural numbers.
Surprisingly the most difficult part was implementing the absolute difference operation (|x-y|
). I had to create a "-1"-ish type which I'm not thrilled about :/
I tried to provide at least a little documentation of my thought process, but some of the implementation (mostly floor division) is a bit messy.
Let me know what you think, this is my first time posting here and my first finished Rust project that I'm really proud of!
So about the Extended Euclidean algorithm, the algorithm that finds, a
, b
, and d
in the equation am+bn=d
, where m
and n
are two positive integers, d
is their GCD, and a
and b
are two integers (not necessarily positive)
So the book I am following has the following instructions for implementing this algorithm:
E1. [Initialize.] Set aβ² β b β 1, a β bβ² β 0, c β m, d β n.
E2. [Divide.] Let q and r be the quotient and remainder, respectively, of c divided by d. (We have c = qd + r and 0 β€ r < d.)
E3. [Remainder zero?] If r = 0, the algorithm terminates; we have in this case am + bn = d as desired.
E4. [Recycle.] Set c β d, d β r, t β aβ², aβ² β a, a β t β qa, t β bβ², bβ² β b, b β t β qb, and go back to E2.
My problem is that I don't particularly understand all the math around this algorithm, I understand the normal Euclidean algorithm well enough, so I understand half of the extended one as well. What I don't understand is the need for a'
and b'
as well t
(I get that t
is a temporary variable but I don't get the a = t - qa
and b = t - qb
part). That as well as the initialization of the variables a
, a'
, b
, and b'
as well as the swapping of the values between them on each iteration. Can anybody help me bridge these gaps in my understanding of this algorithm?
As the title says, a program to run the Euclidean algorithm on the fx-991EX: https://imgur.com/a/L3MC2dD
It's a little technical, a little long ( ... ), but for a first ever ( because I can say with some confidence that no one sufficiently versed with calculator logic programs on a non-programmable calculator ) attempt I made in a physics lesson I don't think it's so bad ( there are a few bits here and there I'm able to condense, but for reasons of convenience I don't think I will ).
Now, as for actually running the 'program':
We start with the initialisation of the variables:
Set A to be the larger of the two values, B to be the smaller, and everything else as 0.
Make sure the calculator is operating with radians as the angle measure, degrees will not work with what I've done here. ( If you're unsure of how this is changed, just type in [ SHIFT, SETUP, 2, 2 ] ) ).
Next, input: [ A . STO x ]
If entered correctly, this should trigger a syntax error ( all intended, don't worry! ).
( note: it's important that the decimal point is not deleted until after the program is entered in full, so keep it there even as we're typing in the rest )
Press on the D-PAD Left button three times to move to the end of the expression and continue to write the program till we're finished and it's all on screen.
Remove the decimal point and start the program by pressing enter. From here on you'll need to manually push equals for every step forward.
Done! There's nothing more that requires any direct input, so just keep it going and if all goes well itβll finish with the very last value of B as the HCF of our initial inputs A & B.
If anyone has any thoughts / queries, feel free to share, Iβm quite interested to see if thereβre actually any meaningful applications to this. Happy calculating!
n >= 3.
The greatest common divisor is:
(F_n, F_n+1).
so be it:
aF_n + bF_{n+1}.
What general assumption could you make about a and b? Prove it.
This is our task and we are completly lost about how to deal with that.
I know this is probably one of the simpler parts of the problem, but how (in this example) are they getting 5 * 675 - 16 *210 from 5 * (675 - 3 * 210) - 210? I understand all the mod calculations and plugging in steps, just that last jump is getting me.
https://preview.redd.it/89la6ngpx6u51.png?width=637&format=png&auto=webp&s=69ce6e371970ded844ec77488b9958d191fdec48
While solving some of the problems below #100, I stumbled across those topics and for a long time I had no idea they were related. I superficially understand those concepts separately, but I don't get how they relate to each other. Where can I find some good material about them? I have a little knowledge on number theory, but as you can see I'm not really good at it. I'm hoping PE helps me improve.
Anyone able to help with these questions? Thank you so much in advance!!
So, again: For which n (n e N) is the value of the grestest common divisor maximal?
The numbers given are for example 13n-7 and 2n+1.
I gave it a go by using the Euclidean algorithm and this is how it went:
https://ibb.co/T0P8KLR
The red text is the right answer and as you can see my answers are almost right but not quite (the first one is correct but I did the same thing with the other examples??). So please, if you have an idea of what Iβm doing wrong, it would be very very appreciated!
Also, I am not sure how this is the answer to the question βmake the common divisor maximalβ, other than the fact that we are finding a greatest common divisor that is bigger than 1. I mean, isnβt the value of the gcd supposed to be maximal anyway?
Thank you!
Found GCD(561, 442) to be 17
561 = 1*442 +119
412 = 3*119 +85
119 = 1*85 + 34
85 = 2*34 + 17
34 = 2*17 + 0
Rewritten
561 - 1*442 =119
412 - 3*119 =85
119 - 1*85 = 34
85 -2*34 = 17
34 -2*17 = 0
Then what do I do? I think I need to substitute somehow, but I cannot figure that out
I understand how it works, but I was wondering why it changes both numbers in the recursive step.
In the algorithm, we start with two positive integers n and m, assuming n > m. If the remainder n mod m is nonzero, then we know that the GCD (let's call it d) must evenly divide n, m, and the remainder (n mod m). This fact allows us to reduce the problem such that d = gcd(m, n mod m).
But isn't it also true that d = gcd(n, n mod m)? This would also reach the same result. Why does euclid's algorithm use the first method and not the second?
Here is a picture of the example I'm looking at. I tried to work through it myself.
https://imgur.com/a/aMmAHZW
I do not understand how in this example 2 is congruent to 18 is congruent to 3(mod15).
I do understand why 18 is congruent to 3(mod15), but I don't understand why also
2 is congruent to 18 is congruent to 3(mod15) as the example in my book states.
3=33m+27n
6=33-1*27
3=27-4*6
3=27-4*(33-1*27) = (-4)*33+5*27
m = -4, n=5
How did they get from 3=27-4(33-1*27)
to
3= -4*33+5*27... Where did the +5 come from? How does that term 3=27-4(33-1*27) become -4*33+5*27
Thanks!
Hi, im fairly new to using python i have been doing bits of it for my course work however its come to it to write a program to get the gcd value for a euclidean algorithm i believe i've got the correct code but i keep getting an error that says Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
euclidian(93,219)
NameError: name 'euclidian' is not defined
however my code is as follows:
from math import *
def euclidlian(x,y, verbose=True):
if x < y:
return euclidian(y, x, verbose)
print ()
while y != 0:
if verbose: print('%s = %s * %s + %s' % (x, floor(x/y),y, x % y))
(x, y) = (y,x % y)
if verbose: print('gcd is %s' % x)
return x
euclidian(93,219)
any help would be greatly appreciated thanks in advance.
Hi, I feel like this must be a really silly question compared to the other questions I have seen on this subreddit.
But pretty much I'm a little stuck on how to do the Euclidean's algorithm.
I think the part I don't understand is when you simplify the groups.
How did they get from this to the end result
31 = ( 527 - 341 x 1 ) x 2 - 341
31 = 527 x 2 - 341 x 2 - 341
31 = 527 x 2 - 341 x 3
I understand how they got to the first equation by expanding but I'm a little confused about the simplification process.
also please keep in mind this is not a homework question but I just want to learn the Euclidean's algorithm the question I'm talking about can be found here.
Animating the Euclidean Algorithm and its application to computer science encryption (extended Euclidean Algorithm - BΓ©zout's identity) would be really cool. Computers stay secured by an algorithm derived 3000 years ago.
https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm
Iβm looking to implement the Hershberger and Suri's Wave Algorithm for shortest path finding in c++, research paper is https://pdfs.semanticscholar.org/4c1f/2cc5262541db0f1047dab0f0789968f8975d.pdf. Does anyone have experience with this algorithm?
Hello,
I understand how to use euclidean algorithm to find a^(-1) for situation like:
a^(-1) Γ a = 1 mod n
because that's basically just following instruction, but i don't really get why this algorithm is applied here and why does it work.
Can anybody help me understand?
So here we go, βpaperβ #6 from BIO-Complexity (pdf).
This paper is all about a genetic algorithm used to solve for a Steiner Tree. A bit of background before we get into it: A Steiner tree is a network of lines and nodes where they meet (interchanges in this paper) connecting pre-specified coordinate points via the shortest possible path. Back in 2006, the authors over at The Pandaβs Thumb issued a challenge (read that, youβll see some names familiar to r/debateevolution) that involved Steiner trees: Solve the problem with an algorithm, and also have people do math to solve it, then have creationists identify which answers where which.
Of course, none of them could tell the designed (i.e. solved by people) solutions from the evolved (i.e. generated by the algorithm), so they (Dembski specifically) responding by arguing that the information to solve the problem was βfront-loadedβ into the algorithm.
This charge takes two forms. The first is that the answer is specifically and explicitly present in the code. This was absurd on its face, so they fell back to the second form of the argument, that the structure of the code itself dictates that a specific results must occur. So even if the solution isnβt explicitly stated in the code, it is still βdesignedβ when it is generated due to the programmer designing the code in such a way that a specific outcome is predetermined.
This paper is an attempt to elaborate on that second form of the objection, specifically with regard to Dave Thomasβ algorithm (Thomas is the author of the Pandaβs Thumb piece linked above).
So letβs get into it.
The specific challenge issued to Dembski et al. is to identify the specific part of code that provides the solution. In other words, specifically identify the βfront-loadingβ. The authors identify two specific pieces.
The first ensures that there are at least two interchanges in the network connecting the points. The second specifies that no mutations cause tne number of interchanges to go below two.
The claim is that these two pieces of the code contain all of the information necessary to solve the problem.
But thatβs wrong, and the data in this paper show that thatβs wrong, because they generate lots of different potential solutions, some better and many worse than others.
All that th
... keep reading on reddit β‘It's what I was taught in school maybe 10 or more years ago. I'm helping my cousin, who is in 8th grade, with his schoolwork since he is out sick, some of his work is about finding the GCD, but apparently what he was taught and what his textbook says is that the way to find the GCD is to find the LCM by prime factorization and then solve with the formula GCD = a * b/LCM [a,b]. This seems backwards to me, prime factorization is a silly way to go about this at all, and I was taught that to find the LCM you'd solve a * b/GCD, so if you're going to use prime factorization you'd use it find the GCD and then use that to find the LCM. Is there any good reason why they'd choose to teach backwards, and to solve using prime factorization rather than Euclid's Algorithm?
How can I intuitively understand the Euclidean algorithm? Iβve looked up the proof, but I feel like I am mindlessly following the steps without really understanding why it is true. Any help? And any tips to keep in mind when browsing future theorems and lemmas?
Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.