From 7bfc2809c8f5c1dcb803ec7656da819512c29f4f Mon Sep 17 00:00:00 2001
From: Edouard Paris <mail@edouard.paris>
Date: Wed, 11 May 2016 12:21:24 +0200
Subject: [PATCH] methods add, equal of polynome

---
 main.ml     |  7 ++++++-
 polynome.ml | 50 +++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/main.ml b/main.ml
index 3bfe56e..d94cb8a 100644
--- a/main.ml
+++ b/main.ml
@@ -1,2 +1,7 @@
 (*projet AP Edouard Paris 2016*)
-open Polynome;;
+
+open Polynome
+open Simplepolynome;;
+
+
+  
diff --git a/polynome.ml b/polynome.ml
index d4d47eb..a532e01 100644
--- a/polynome.ml
+++ b/polynome.ml
@@ -5,21 +5,29 @@ open Big_int;;
 module type Coefficient =
   sig
     type coeff
-    val print_coeff: coeff -> string
+    val print: coeff -> string
+    val is_null: coeff -> bool
+    val add: coeff -> coeff -> coeff
+    val equal: coeff -> coeff -> bool
   end
 ;;
   
 module type Degree =
   sig
     type degree
-    val print_degree: degree -> string
+    val print: degree -> string
+    val add: degree -> degree -> degree
+    val equal: degree -> degree -> bool
+    val is_bigger: degree -> degree -> bool
   end
 ;;
   
 module type Polynomes =
   sig
     type polynome
-    val print_pol: polynome -> string
+    val print: polynome -> string
+    val equal: polynome -> polynome -> bool
+    val add: polynome -> polynome -> polynome
   end
 ;;
 
@@ -28,9 +36,41 @@ module Polynome (C : Coefficient) (D : Degree) =
     type polynome =
       |Null
       |NotNull of C.coeff*D.degree*polynome
-    let rec print_pol p = match p with
+    let rec print p = match p with
       |Null -> "0"
       |NotNull (cc, dd, pp)->
-	(C.print_coeff cc)^"X^"^(D.print_degree dd)^"+"^(print_pol 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)
+      |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)
+    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)
+	)
   end
 ;;
-- 
GitLab