From 58d77a941849fb6cf997b0a015e4f5624228e766 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 25 Sep 2023 13:35:25 +0200 Subject: [PATCH] vault backup: 2023-09-25 13:35:25 --- Algo/Séminaire/Exercices seminaire.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Algo/Séminaire/Exercices seminaire.md b/Algo/Séminaire/Exercices seminaire.md index 590c52c..64985f0 100644 --- a/Algo/Séminaire/Exercices seminaire.md +++ b/Algo/Séminaire/Exercices seminaire.md @@ -383,7 +383,7 @@ let rec puissance_better x n = else let pb_odd = puissance_better x (n/2) * n in pb_odd*pb_odd;; -(*Correction*) +(*Correction v1*) let power x n = match n with | 0 -> (match x with | 0. -> failwith "power 0^0 impossible" @@ -395,5 +395,19 @@ let power x n = match n with | _ -> (let rec p = function | 0 -> 1. | n -> x*.p(n-1) in p n) - ;; +;; + +(*Correction v2*) +let power x n = match n with + | 0 -> (match x with + | 0. -> failwith "power 0^0 impossible" + | _ -> 1.) + | _ -> (match x with + | 1. -> 1. + | 0. -> 0. + | -1. -> if n mod 2 = 0 then 1. else -1.) + | _ -> (let rec p = function + | 0 -> 1. + | n -> x*.p(n-1) in p n) +;; ``` \ No newline at end of file