vault backup: 2023-09-25 14:21:29

This commit is contained in:
Louis Gallet 2023-09-25 14:21:29 +02:00
parent 743c2e517b
commit 7f3dd95837
Signed by: lgallet
SSH Key Fingerprint: SHA256:qnW7pk4EoMRR0UftZLZQKSMUImbEFsiruLC7jbCHJAY

View File

@ -427,4 +427,31 @@ let power x n = match n with
| n -> p (x*x) (n/2) *. (if n mod 2 = 1 then x else 1.)
in p x n)
;;
```
```
Complexity :
$$
x^0 -> 1 \ | \
x^1 -> (x^0)^2 -> 2 \ | \
x^2 -> x^1 -> 3 \ | \
x^4 -> x^2 -> 4 \ | \
x^8 -> x^4 -> 5 \ | \
x^16 -> x^8 -> 6 \ | \
x^(2^k) -> x^(2^k-1) -> k+2 \approx{k} \ | \
n = 2^k -> K*log(n) \ | \
log(n) = log(2^k) = k
$$
$$
= O(log(n))
$$
## 4.12 - Prime number
```Ocaml
let prime n =
if n < 1 then
invalid_args "n should not be inferior to zero"
else
let rec p n =
if n = 0 then
1
else