vault backup: 2023-09-05 15:07:54

This commit is contained in:
2023-09-05 15:07:54 +02:00
parent 4c95cef899
commit 6dfa2cb3bc
4 changed files with 24 additions and 25 deletions

View File

@ -1,7 +1,7 @@
## 2.2 (Power)
```Ocaml
(*First version*)
(*First version ; 6 multiplications*)
# let power28(x) =
let x2 = x + x in
let x4 = x2*x2 in
@ -9,16 +9,16 @@
let x16 = x8*x8 in
x16*x8*x4 ;;
(*Second version*)
(*Second version ; 27 multiplications*)
# let power28(x) = x*x*x*x*x*x...*x ;;
(*Third version*)
(*Third version ; 11 multiplications*)
# let power28(x) =
let sq(x) = x+x in
let sq(x) = x*x in
let pow4(x) = sq(sq(x)) in
pow4(pow4(x))*sq(pow4(x))*pow4(x);;
(*Fourth version*)
(*Fourth version ; 7 multiplications*)
# let power28(x)=
let sq(x) = x+x in
let p4=sq(sq(x)) in