Skip to content
Extraits de code Groupes Projets
Valider 15933da2 rédigé par EdouardParis's avatar EdouardParis
Parcourir les fichiers

change indentation and finish naive_mul

parent f25aa29a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -7,8 +7,9 @@ module type Coefficient =
type coeff
val print: coeff -> string
val is_null: coeff -> bool
val add: coeff -> coeff -> coeff
val equal: coeff -> coeff -> bool
val add: coeff -> coeff -> coeff
val mul: coeff -> coeff -> coeff
end
;;
......@@ -40,50 +41,57 @@ module Polynome (C : Coefficient) (D : Degree) =
let rec print p = match p with
|Null -> "0"
|NotNull (cc, dd, pp)->
(C.print cc)^"X^"^(D.print dd)^"+"^(print pp)
(C.print cc)^"X^"^(D.print dd)^"+"^(print pp)
let rec equal x y = match x with
|Null ->
(match y with
|Null -> true
|NotNull (_, _, _)-> false)
|Null -> (match y with
|Null -> true
|NotNull (_, _, _)-> false)
|NotNull (cx, dx, xx)->
(match y with
|Null -> false
|NotNull (cy, dy, yy) ->
if D.equal dx dy
then
if C.equal cx cy
then equal xx yy
else false
else false)
(match y with
|Null -> false
|NotNull (cy, dy, yy) ->
if D.equal dx dy
then
if C.equal cx cy
then equal xx yy
else false
else false
)
let rec add x y = match x with
|Null -> y
|NotNull (cx, dx, xx)->
(match y with
|Null -> x
|NotNull (cy, dy, yy)->
if D.is_bigger dy dx
then NotNull (cy, dy, add x yy)
else
if D.is_bigger dx dy
then NotNull (cx, dx, add xx yy)
else
let m = C.add cx cy in
if C.is_null m
then add xx yy
else NotNull (m, dx, add xx yy)
)
(*let rec naive_mul x y = match x with
(match y with
|Null -> x
|NotNull (cy, dy, yy)->
if D.is_bigger dy dx
then NotNull (cy, dy, add x yy)
else
if D.is_bigger dx dy
then NotNull (cx, dx, add xx yy)
else
let m = C.add cx cy in
if C.is_null m
then add xx yy
else NotNull (m, dx, add xx yy)
)
(*private function for incrementing the degree of a polynome*)
let rec increment_degree d x = match x with
|Null -> Null
|NotNull (cx, dx, xx)-> NotNull (cx, (D.add d dx), (increment_degree d xx))
(*private function in order to multiply all the coeffs of a pol*)
let rec multiply_coeffs c x = match x with
|Null -> Null
|NotNull (cx, dx, xx) ->
if C.is_null c then Null
else NotNull ((C.mul c cx), dx, (multiply_coeffs c xx))
(*Naive multiplication of two polynomes*)
let rec naive_mul x y = match x with
|Null -> Null
|NotNull -> (cx, dx, xx)->
(match y with
|Null -> Null
|NotNull (cy, dy, yy)->
match xx with
|Null
|NotNull
)
*)
|NotNull (cx, dx, xx) ->
(match y with
|Null -> Null
|NotNull (_, _, _)->
add (increment_degree dx (multiply_coeffs cx y))(naive_mul xx y)
)
end
;;
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter