Zum Inhalt springen

Datei:GCD through successive subtractions.svg

Aus MOOCsWiki Staging
Originaldatei (SVG-Datei, Basisgröße: 660 × 825 Pixel, Dateigröße: 5 KB)

Diese Datei stammt aus Wikimedia Commons und kann von anderen Projekten verwendet werden. Die Beschreibung von deren Dateibeschreibungsseite wird unten angezeigt.

Beschreibung

Beschreibung
English: The set of common divisors of two given natural numbers is the set of divisors of one and only one natural number, called the “greatest common divisor” of the initial pair. To prove its existence, it is sufficient to exhibit we can always calculate it, from any pair of natural numbers. How to understand “greatest”? The order in question is divisibility: a partial order on set ℕ of natural numbers. For example, 2 is a common divisor that can be written: We will soon calculate the greatest common divisor Zero is multiple of any natural number, in other words, zero is the greatest element of ℕ for divisibility. is not the greatest natural number for the usual order relation, of which the symbol The least element of ℕ for divisibility is 1.

the set of common divisors are multiples of any element is also a multiple Conversely, every common divisor is also a divisor In other words, also the set of common divisors

Under the algorithm of the image, is replaced and then by repeating the process replaced And then replaced Finally the step‑by‑step process replaces the initial pair goes out of the loop of subtractions, and affirms:

Instead of replacing with the four successive pairs: we could get directly the last pair by the Euclidean division It does not matter there are 4 successive subtractions of 6, we can ignore 4: the quotient value of this Euclidean division. Actually, every sequence of subtractions of a same number can be replaced with an Euclidean division by this number. Thus we discover the more known algorithm of GCD through successive Euclidean divisions, by improving the present algorithm of subtractions.

A novice in coding can copy and paste in a window dedicated to JavaScript one of the following comparisons, and then command the execution: 30 < 24; or 6 == 0; or 6 < 24. Within the image, six symbols look like assignments in OCaml. Here is an example of assignment in JavaScript: r = 30; commanding to store into the object of type Number and value 30. Everyone can download Firefox, and then open a Firefox window dedicated to JavaScript code. In this special window, we can copy and paste the following translation from the flow chart into JavaScript.

/* To open a Firefox window
 dedicated to JavaScript code:  Shift + F4  */

d = r = k = 182; p = 238;  // example of input values,
// that we can replace with two other natural numbers
if( s = p){  // if the common value of s and p is not zero
while(r){  // while the value of r is not zero
if(r < s){  // in this case, reverse the values of r and s
d = s; s = r; r = d }
r = r-s }  // end of the loop 'while(r)'
d = s }  // end of the block that begins with 'if( s = p)'
"   GCD("+ k +", "+ p +") = "+ d;  // output: a String object

// Keyboard shortcut in Firefox to execute the code:  Ctrl + L

On the image top,  means that  of natural numbers. The previous JavaScript code works only if the two input values are natural numbers. Here is an improvement of the previous code, where the input values assigned are verified.

try{ //  in case of error in this block,
//  execution failure of this code block, go to 'catch'
d = r = k = 408; p = 255;  // example of input values
var b;  // global scope declaration
s = function(n){
// to test the value of parameter n: is it a natural number?
b = n.constructor == Number; // Boolean value
if( !b // first incorrect case
  || n < 0 || n != Math.floor(n)  // other incorrect cases
) throw n
//  in one of the previous cases, n is thrown as error
};  // end of assignment to variable s
s(k); s(p);  // verifications
if( s = p){  // if the common value of s and p is not zero
while(r){
if(r < s){d = s; s = r; r = d} r = r-s } d = s }
"  GCD("+ k +", "+ p +") = "+ d
}catch(e){  // in case of error (if e is thrown)
"  "+( b ? e +"  is not a natural number.":
"  Incorrect code.")
}
The GCD operation is classically used to simplify a fraction. is the irreducible form Two natural numbers of which the GCD is 1 are called coprime integers.
 
Français : Voir la version en français…
Datum
Quelle Eigenes Werk
Urheber Arthur Baelde
Andere Versionen
SVG‑Erstellung
InfoField
 Der SVG-Code ist valide.
 Diese Vektorgrafik wurde mit einem Texteditor erstellt.

Lizenz

Arthur Baelde, der Nutzungsrechtsinhaber dieses Werkes, veröffentlicht es hiermit unter der folgenden Lizenz:
w:de:Creative Commons
Namensnennung Weitergabe unter gleichen Bedingungen
Namensnennung:
Dieses Werk darf von dir
  • verbreitet werden – vervielfältigt, verbreitet und öffentlich zugänglich gemacht werden
  • neu zusammengestellt werden – abgewandelt und bearbeitet werden
Zu den folgenden Bedingungen:
  • Namensnennung – Du musst angemessene Urheber- und Rechteangaben machen, einen Link zur Lizenz beifügen und angeben, ob Änderungen vorgenommen wurden. Diese Angaben dürfen in jeder angemessenen Art und Weise gemacht werden, allerdings nicht so, dass der Eindruck entsteht, der Lizenzgeber unterstütze gerade dich oder deine Nutzung besonders.
  • Weitergabe unter gleichen Bedingungen – Wenn du das Material wiedermischst, transformierst oder darauf aufbaust, musst du deine Beiträge unter der gleichen oder einer kompatiblen Lizenz wie das Original verbreiten.

Kurzbeschreibungen

Ergänze eine einzeilige Erklärung, was diese Datei darstellt.
The algorith transforms any pair of positive integers into another having the same common divisors, and including a decisive 0,  through a process able to interchange two integers, or remplace the greatest with the positive difference of the two.

In dieser Datei abgebildete Objekte

Motiv

5.165 Byte

825 Pixel

660 Pixel

image/svg+xml

c583b794c4f66ad732df5117f364c8bb8e54de72

Dateiversionen

Klicke auf einen Zeitpunkt, um diese Version zu laden.

Version vomVorschaubildMaßeBenutzerKommentar
aktuell14:18, 9. Feb. 2025Vorschaubild der Version vom 14:18, 9. Feb. 2025660 × 825 (5 KB)wikimediacommons>Arthur Baelde the  latest  version  is  the  best  one 

Metadaten