Chore(math-translation-FR-fr): a pack of translations for the math section (#558)

* chore(factorial): translation fr-FR

* feat(math-translation-fr-FR): fast powering

* feat(math-translation-fr-FR): fibonacci numbers

* chore(math-translation-fr-FR): bits

* chore(math-translation-fr-FR): complex number

* chore(math-translation-fr-FR): euclidean algorithm

* chore(math-translation-fr-FR): fibonacci number

* chore(math-translation-fr-FR): fourier transform

* chore(math-translation-fr-FR): fourier transform WIP

* chore(math-translation-fr-FR): fourier transform done

* chore(math-translation-fr-FR): fourier transform in menu
This commit is contained in:
Loïc TRUCHOT
2020-10-05 21:13:47 +02:00
committed by GitHub
parent 07bc4a4b97
commit d6b8dd394a
15 changed files with 1200 additions and 328 deletions

View File

@@ -0,0 +1,73 @@
# Algorithme d'exponentiation rapide
_Read this in other languages:_
[english](README.md).
En algèbre, une **puissance** d'un nombre est le résultat de la multiplication répétée de ce nombre avec lui-même.
Elle est souvent notée en assortissant le nombre d'un entier, typographié en exposant, qui indique le nombre de fois qu'apparaît le nombre comme facteur dans cette multiplication.
![Power](https://www.mathsisfun.com/algebra/images/exponent-8-2.svg)
## Implémentation « naïve »
Comment trouver `a` élevé à la puissance `b` ?
On multiplie `a` avec lui-même, `b` nombre de fois.
Ainsi, `a^b = a * a * a * ... * a` (`b` occurrences de `a`).
Cette opération aura un complexité linéaire, notée `O(n)`,
car la multiplication aura lieu exactement `n` fois.
## Algorithme d'exponentiation rapide
Peut-on faire mieux que cette implémentation naïve?
Oui, on peut réduire le nombre de puissance à un complexité de `O(log(n))`.
Cet algorithme utilise l'approche « diviser pour mieux régner »
pour calculer cette puissance.
En l'état, cet algorithme fonctionne pour deux entiers positifs `X` et `Y`.
L'idée derrière cet algorithme est basée sur l'observation suivante.
Lorsque `Y` est **pair**:
```text
X^Y = X^(Y/2) * X^(Y/2)
```
Lorsque `Y` est **impair**:
```text
X^Y = X^(Y//2) * X^(Y//2) * X
où Y//2 est le résultat de la division entière de Y par 2.
```
**Par exemple**
```text
2^4 = (2 * 2) * (2 * 2) = (2^2) * (2^2)
```
```text
2^5 = (2 * 2) * (2 * 2) * 2 = (2^2) * (2^2) * (2)
```
Ainsi, puisqu'à chaque étape on doits calculer
deux fois la même puissance `X ^ (Y / 2)`,
on peut optimiser en l'enregistrant dans une variable intermédiaire
pour éviter son calcul en double.
**Complexité en temps**
Comme à chaque itération nous réduisons la puissance de moitié,
nous appelons récursivement la fonction `log(n)` fois. Le complexité de temps de cet algorithme est donc réduite à:
```text
O(log(n))
```
## Références
- [YouTube](https://www.youtube.com/watch?v=LUWavfN9zEo&index=80&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8&t=0s)
- [Wikipedia](https://fr.wikipedia.org/wiki/Exponentiation_rapide)

View File

@@ -1,6 +1,9 @@
# Fast Powering Algorithm
**The power of a number** says how many times to use the number in a
_Read this in other languages:_
[français](README.fr-FR.md).
**The power of a number** says how many times to use the number in a
multiplication.
It is written as a small number to the right and above the base number.
@@ -11,7 +14,7 @@ It is written as a small number to the right and above the base number.
How to find `a` raised to the power `b`?
We multiply `a` to itself, `b` times. That
We multiply `a` to itself, `b` times. That
is, `a^b = a * a * a * ... * a` (`b` occurrences of `a`).
This operation will take `O(n)` time since we need to do multiplication operation
@@ -20,9 +23,9 @@ exactly `n` times.
## Fast Power Algorithm
Can we do better than naive algorithm does? Yes we may solve the task of
powering in `O(log(n))` time.
powering in `O(log(n))` time.
The algorithm uses divide and conquer approach to compute power. Currently the
The algorithm uses divide and conquer approach to compute power. Currently the
algorithm work for two positive integers `X` and `Y`.
The idea behind the algorithm is based on the fact that:
@@ -30,7 +33,7 @@ The idea behind the algorithm is based on the fact that:
For **even** `Y`:
```text
X^Y = X^(Y/2) * X^(Y/2)
X^Y = X^(Y/2) * X^(Y/2)
```
For **odd** `Y`:
@@ -50,17 +53,17 @@ where Y//2 is result of division of Y by 2 without reminder.
2^5 = (2 * 2) * (2 * 2) * 2 = (2^2) * (2^2) * (2)
```
Now, since on each step we need to compute the same `X^(Y/2)` power twice we may optimise
it by saving it to some intermediate variable to avoid its duplicate calculation.
Now, since on each step we need to compute the same `X^(Y/2)` power twice we may optimise
it by saving it to some intermediate variable to avoid its duplicate calculation.
**Time Complexity**
Since each iteration we split the power by half then we will call function
Since each iteration we split the power by half then we will call function
recursively `log(n)` times. This the time complexity of the algorithm is reduced to:
```text
O(log(n))
```
```
## References