From 91d3a9ef606abf0a5490659f1fef73bdb66a3fbe Mon Sep 17 00:00:00 2001 From: Mysaa Date: Thu, 11 Mar 2021 16:25:36 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Tentatives=20de=20modularisation=20des=20cl?= =?UTF-8?q?asses,=20y=20a=20encore=20deux=20trois=20probl=C3=A8mes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Codes.ml => Code.ml | 9 ++++++--- Makefile | 13 ++++++++++++- Maths.ml => Math.ml | 0 Maths.mli | 1 - Test.ml | 8 ++++++-- 6 files changed, 25 insertions(+), 7 deletions(-) rename Codes.ml => Code.ml (97%) rename Maths.ml => Math.ml (100%) delete mode 100644 Maths.mli diff --git a/.gitignore b/.gitignore index 141d355..6c0bf2e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.cmi *.cmx +*.cmo *.o *.a *.ascii.txt diff --git a/Codes.ml b/Code.ml similarity index 97% rename from Codes.ml rename to Code.ml index 9e7336a..f754ac6 100644 --- a/Codes.ml +++ b/Code.ml @@ -24,10 +24,13 @@ *) -#cd "/home/mysaa/Documents/Arbeiten/TIPE2021";; -#use "Maths.ml";; +#cd "/home/mysaa/Documents/Arbeiten/TIPE2021/";; +#load "Math.cmo";; + +open Math;; + (* La bonne structure *) -type code_lineaire = {klin : int; nlin : int; g : matrice; h : matrice};; +type code_lineaire = {klin : int; nlin : int; g : matrice; h : Math.matrice};; (* La super stucture *) type code_cyclique = {kcyc : int; ncyc: int; pol: polynome};; diff --git a/Makefile b/Makefile index 47c2a45..02d022d 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,17 @@ ascii: $(shell find textes/ -type f -iname "*.txt" ! -iname "*.ascii.txt" | sed %.cmx: %.ml ocamlopt -c $< + +%.cmo: %.ml + ocamlc -c $< + + +Code.cmo: Code.ml Math.cmo + mkdir tmp + cat Code.ml | sed '/^#/d' > tmp/Code.ml + ocamlc -c tmp/Code.ml Math.cmo + mv tmp/Code.cmo Code.cmo + rm -r tmp tipe: tipe.cmx ocamlopt -o tipe str.cmxa tipe.cmx @@ -16,4 +27,4 @@ tipe: tipe.cmx runall: $(shell find textes/ -type f -iname "*.txt" ! -iname "*.ascii.txt" | sed "s/\.txt/\.txt\.test/") clean: - rm -rf tipe *.cmx *.cmi *.o textes/*.ascii.txt + rm -rf tipe *.cmx *.cmi *.cmo *.o textes/*.ascii.txt *.ntl.ml diff --git a/Maths.ml b/Math.ml similarity index 100% rename from Maths.ml rename to Math.ml diff --git a/Maths.mli b/Maths.mli deleted file mode 100644 index 8d1c8b6..0000000 --- a/Maths.mli +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Test.ml b/Test.ml index 69e421d..8656e08 100644 --- a/Test.ml +++ b/Test.ml @@ -1,10 +1,14 @@ #cd "/home/mysaa/Documents/Arbeiten/TIPE2021";; -#use "Codes.ml";; +Sys.command "make Math.cmo Code.cmo";; +#load "Math.cmo";; +#load "Code.cmo";; +open Math;; +open Code;; (* Test du produit de matrice *) let matest = [0b01110; 0b00101; 0b10111];; print_matrice 5 matest;; -produit matest 0b110;; (* -> 0b10010 = 8*) +produit matest 0b110;; (* -> 0b10010 = 8 *) (* Tests des polynomes *) let pol1 = 13 and pol2 = 67;; From 929150577c1e8dc29eafcc9172e6c445bb7a16f4 Mon Sep 17 00:00:00 2001 From: Mysaa Date: Thu, 11 Mar 2021 22:49:00 +0100 Subject: [PATCH 2/3] =?UTF-8?q?Ajout=20de=20jolies=20d=C3=A9finitions=20ml?= =?UTF-8?q?i=20pour=20les=20modules=20Modification=20du=20Makefile=20qui?= =?UTF-8?q?=20d=C3=A9tecte=20tout=20seul=20la=20pr=C3=A9sence=20d'un=20mli?= =?UTF-8?q?.=20Rangement=20des=20pdfs=20dans=20un=20sous-dossier=20"Docume?= =?UTF-8?q?nts"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Code.ml | 128 ++++++++++++------ Code.mli | 27 ++++ AlgCodeCycl.pdf => Documents/AlgCodeCycl.pdf | Bin .../Cours_Pierre_Abbrugiati.pdf | Bin m89lm1ea.pdf => Documents/m89lm1ea.pdf | Bin Makefile | 15 +- Math.mli | 20 +++ Test.ml | 26 ++-- 8 files changed, 148 insertions(+), 68 deletions(-) create mode 100644 Code.mli rename AlgCodeCycl.pdf => Documents/AlgCodeCycl.pdf (100%) rename Cours_Pierre_Abbrugiati.pdf => Documents/Cours_Pierre_Abbrugiati.pdf (100%) rename m89lm1ea.pdf => Documents/m89lm1ea.pdf (100%) create mode 100644 Math.mli diff --git a/Code.ml b/Code.ml index f754ac6..66e4583 100644 --- a/Code.ml +++ b/Code.ml @@ -23,24 +23,29 @@ * on représente une matrice par un liste d'entier, il s'agit de la liste de ses colonnes (qui sont donc des vecteurs) *) - +(* #cd "/home/mysaa/Documents/Arbeiten/TIPE2021/";; #load "Math.cmo";; +*) open Math;; -(* La bonne structure *) -type code_lineaire = {klin : int; nlin : int; g : matrice; h : Math.matrice};; +(*************************************************************) +(************************Module CLineaire*********************) +(*************************************************************) -(* La super stucture *) -type code_cyclique = {kcyc : int; ncyc: int; pol: polynome};; +module CLineaire = +struct + +(* La bonne structure *) +type t = {k : int; n : int; g : Math.matrice; h : Math.matrice};; +type code_lineaire = t;; (* Le type du module *) (* Calcule Y = GX *) let encoder code x = produit code.g x ;; -(* Le nom de cette fonction n'est pas assez explicite *) -let construire_code_lineaire_systematique k n redondance = +let systematiqueFromRedondance k n redondance = let g = let decalage = deux_puissance k in let rec iteredon ajout = function @@ -50,36 +55,9 @@ let construire_code_lineaire_systematique k n redondance = c :: (iteredon (ajout * 2) queue) in iteredon 1 redondance and h = redondance @ (identite (n-k)) in - {klin = k; nlin = n; g = g; h = h} + {k = k; n = n; g = g; h = h} ;; -(* Construit le code linéaire associé au code cyclique *) -let cycliqueVersLineaire code = - let k=code.kcyc and n=code.ncyc and pol=code.pol in - let g = - let rec itdecal i l = - if i<0 - then l - else itdecal (i-1) ((pol lsl i)::l) - in itdecal (k-1) [] - and h = - let polh = poldiv ((deux_puissance n) + 1) pol in - print_polynome polh; - let filtre = (deux_puissance (n-k+1))-1 in - let rec sub i l = - if i<(-k) - then l - else sub (i-1) (((decagauche polh i) land filtre)::l) - in sub (n-k-1) [] - in {klin = k; nlin = n; g = g; h = h} -;; - - -let lineaireVersCyclique code = - (*TODO*)1 -;; - - (* Etant donnés tous les vecteurs de poids p dans un espace de dimension d, retourne touts ceux de poids p+1 dans ce même espace *) let suivants d vecteurs = let contraintes = ref [] in @@ -103,6 +81,7 @@ let suivants d vecteurs = ;; + (* Renvoit le plus petit mot (au sens de Hamming) dans F_2^d vérifiant 'propriete' et de poids inférieur à poids_max. Renvoie le couple (-1, 0) si aucun mot n'a été trouvé *) let plus_petit_verifiant propriete poids_max d = let rec chercher p vecteurs = @@ -115,20 +94,12 @@ let plus_petit_verifiant propriete poids_max d = in chercher 0 [0] ;; -let appartenir code v = produit code.h v = 0;; - -(* Calcul la distance minimale d'un code *) -let distance_minimale code = - let n = code.nlin in - let propriete = fun v -> (0 < v) && (appartenir code v) in - let (p, _) = plus_petit_verifiant propriete n n in p -;; exception PasDansLeCodeException;; (* Calcul de façons à ouf l'antécédent de 'y' pour le code 'code' *) let antecedent code y = - let mot_max = (deux_puissance code.klin) - 1 in + let mot_max = (deux_puissance code.k) - 1 in let rec iterer = function | x when x = mot_max -> raise PasDansLeCodeException | x -> @@ -139,10 +110,20 @@ let antecedent code y = exception IndecodableException;; + +let appartenir code v = produit code.h v = 0;; + +(* Calcul la distance minimale d'un code *) +let distance_minimale code = + let n = code.n in + let propriete = fun v -> (0 < v) && (appartenir code v) in + let (p, _) = plus_petit_verifiant propriete n n in p +;; + (* Applique notre algorithme préféré *) let decoder code z = let d_min = distance_minimale code in - let e_c = (d_min - 1) / 2 and n = code.nlin in + let e_c = (d_min - 1) / 2 and n = code.n in let propriete = fun v -> appartenir code ((lxor) z v) in match plus_petit_verifiant propriete e_c n with | (-1, 0) -> raise IndecodableException @@ -150,4 +131,61 @@ let decoder code z = ;; +end;; + +(*************************************************************) +(************************Module CCyclique*********************) +(*************************************************************) + +module CCyclique = +struct +;; +(* La super stucture *) +type t = {k : int; n: int; pol: polynome};; +type code_cyclique = t;; + +let get k n pol = {k=k;n=n;pol=pol};; + + +end;; + +(*************************************************************) +(*****************************Suite***************************) +(*************************************************************) + +open CLineaire;; +open CCyclique;; + +(* Construit le code linéaire associé au code cyclique *) +let cycliqueVersLineaire code = + let k=code.k and n=code.n and pol=code.pol in + let g = + let rec itdecal i l = + if i<0 + then l + else itdecal (i-1) ((pol lsl i)::l) + in itdecal (k-1) [] + and h = + let polh = poldiv ((deux_puissance n) + 1) pol in + print_polynome polh; + let filtre = (deux_puissance (n-k+1))-1 in + let rec sub i l = + if i<(-k) + then l + else sub (i-1) (((decagauche polh i) land filtre)::l) + in sub (n-k-1) [] + in {k = k; n = n; g = g; h = h} +;; + + +let lineaireVersCyclique code = + (*TODO*)1 +;; + + + + + + + (* Voilà *) \ No newline at end of file diff --git a/Code.mli b/Code.mli new file mode 100644 index 0000000..4f845ee --- /dev/null +++ b/Code.mli @@ -0,0 +1,27 @@ +module CLineaire : +sig +type t = { + k : int; + n : int; + g : Math.matrice; + h : Math.matrice; } +type code_lineaire = t + +val encoder : code_lineaire -> Math.vecteur -> Math.vecteur +val systematiqueFromRedondance : int -> int -> int list -> code_lineaire +val distance_minimale : code_lineaire -> int +val decoder : code_lineaire -> int -> Math.vecteur +val appartenir : code_lineaire -> Math.vecteur -> bool +end + +module CCyclique : +sig + type t = { + k : int; + n : int; + pol : Math.polynome; } + + val get : int -> int -> Math.polynome -> t +end + +val cycliqueVersLineaire : CCyclique.t -> CLineaire.t diff --git a/AlgCodeCycl.pdf b/Documents/AlgCodeCycl.pdf similarity index 100% rename from AlgCodeCycl.pdf rename to Documents/AlgCodeCycl.pdf diff --git a/Cours_Pierre_Abbrugiati.pdf b/Documents/Cours_Pierre_Abbrugiati.pdf similarity index 100% rename from Cours_Pierre_Abbrugiati.pdf rename to Documents/Cours_Pierre_Abbrugiati.pdf diff --git a/m89lm1ea.pdf b/Documents/m89lm1ea.pdf similarity index 100% rename from m89lm1ea.pdf rename to Documents/m89lm1ea.pdf diff --git a/Makefile b/Makefile index 02d022d..6108f82 100644 --- a/Makefile +++ b/Makefile @@ -7,16 +7,13 @@ ascii: $(shell find textes/ -type f -iname "*.txt" ! -iname "*.ascii.txt" | sed %.cmx: %.ml ocamlopt -c $< -%.cmo: %.ml +Code.cmo: Math.cmo + +%.cmi: %.mli + ocamlc -c $< +%.cmo: %.ml + if [ -f $*".mli" ]; then ocamlc -c $*".mli" ; fi ocamlc -c $< - - -Code.cmo: Code.ml Math.cmo - mkdir tmp - cat Code.ml | sed '/^#/d' > tmp/Code.ml - ocamlc -c tmp/Code.ml Math.cmo - mv tmp/Code.cmo Code.cmo - rm -r tmp tipe: tipe.cmx ocamlopt -o tipe str.cmxa tipe.cmx diff --git a/Math.mli b/Math.mli new file mode 100644 index 0000000..48f67f9 --- /dev/null +++ b/Math.mli @@ -0,0 +1,20 @@ +type vecteur = int +type matrice = int list +type polynome = int +val nthOfBinarint : int -> int -> string +val print_matrice : int -> matrice -> unit +val print_vecteur : int -> vecteur -> unit +val print_polynome : polynome -> unit +val produit : matrice -> vecteur -> vecteur +val deux_puissance : int -> int +val orderize : 'a -> 'a -> 'a * 'a +val identite : int -> int list +val changer_bit : int -> int -> int +val decagauche : int -> int -> int +val respecter : int -> int list -> bool +val matriceAuPif : int -> int -> matrice +val polmul : polynome -> polynome -> polynome +val degre : polynome -> int +val poldiveuc : polynome -> polynome -> polynome * polynome +val poldiv : polynome -> polynome -> polynome +val polrst : polynome -> polynome -> polynome diff --git a/Test.ml b/Test.ml index 8656e08..439b43b 100644 --- a/Test.ml +++ b/Test.ml @@ -2,6 +2,7 @@ Sys.command "make Math.cmo Code.cmo";; #load "Math.cmo";; #load "Code.cmo";; + open Math;; open Code;; @@ -39,10 +40,10 @@ respecter 7 [3];; -> les 3 dernières lignes : H *) let code_hamming = - construire_code_lineaire_systematique 4 7 [7; 3; 5; 6] + CLineaire.systematiqueFromRedondance 4 7 [7; 3; 5; 6] ;; -distance_minimale code_hamming;; +CLineaire.distance_minimale code_hamming;; @@ -52,25 +53,22 @@ for i=0 to 20 do Random.self_init (); let matPapa = matriceAuPif 9 12 in - let code_paparfait = construire_code_lineaire_systematique 12 21 matPapa in - let dst = distance_minimale code_paparfait in + let code_paparfait = CLineaire.systematiqueFromRedondance 12 21 matPapa in + let dst = CLineaire.distance_minimale code_paparfait in if dst>1 then raise (GTROUVE matPapa) done;; -print_vecteur 21 (encoder code_paparfait 0b011011011001);; +print_vecteur 21 (CLineaire.encoder code_paparfait 0b011011011001);; - -print_matrice 3 (suivants 3 (suivants 3 (suivants 3 (suivants 3 [0b000]))));; - -print_vecteur 7 (encoder code_hamming 0b0100);; -decoder code_hamming 0b1010100;; -decoder code_hamming 0b0010100;; -decoder code_hamming 0b1110000;; +print_vecteur 7 (CLineaire.encoder code_hamming 0b0100);; +CLineaire.decoder code_hamming 0b1010100;; +CLineaire.decoder code_hamming 0b0010100;; +CLineaire.decoder code_hamming 0b1110000;; print_vecteur 7 21;; (* Tests des codes cycliques *) -let cocycl = {ncyc=7;kcyc=4;pol=13};; +let cocycl = CCyclique.get 7 4 13;; print_polynome cocycl.pol;; poldiveuc ((deux_puissance 7) +1) cocycl.pol;; print_polynome ((deux_puissance 7) +1);; @@ -78,4 +76,4 @@ print_polynome (poldiv ((deux_puissance 7) +1) cocycl.pol);; let cocylined = cycliqueVersLineaire cocycl;; print_matrice 7 cocylined.g;; print_matrice 4 cocylined.h;; -distance_minimale cocylined;; +CLineaire.distance_minimale cocylined;; From 9c7e31e5e8fe8bec9ca17c54950d1a4147f254e5 Mon Sep 17 00:00:00 2001 From: Mysaa Date: Wed, 24 Mar 2021 19:50:00 +0100 Subject: [PATCH 3/3] Ajout d'un petit double point-virgule trop mignon --- Code.ml | 1 + Test.ml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Code.ml b/Code.ml index 66e4583..c40f407 100644 --- a/Code.ml +++ b/Code.ml @@ -36,6 +36,7 @@ open Math;; module CLineaire = struct +;; (* La bonne structure *) type t = {k : int; n : int; g : Math.matrice; h : Math.matrice};; diff --git a/Test.ml b/Test.ml index 439b43b..8afcf66 100644 --- a/Test.ml +++ b/Test.ml @@ -76,4 +76,4 @@ print_polynome (poldiv ((deux_puissance 7) +1) cocycl.pol);; let cocylined = cycliqueVersLineaire cocycl;; print_matrice 7 cocylined.g;; print_matrice 4 cocylined.h;; -CLineaire.distance_minimale cocylined;; +CLineaire.distance_minimale cocylined;; \ No newline at end of file