Séance du 4 mars
On a ajouté les codes cycliques et les polynomes
This commit is contained in:
parent
1a2398444c
commit
3a5c532475
BIN
AlgCodeCycl.pdf
BIN
AlgCodeCycl.pdf
Binary file not shown.
38
Codes.ml
38
Codes.ml
@ -27,7 +27,10 @@
|
||||
#cd "/home/mysaa/Documents/Arbeiten/TIPE2021";;
|
||||
#use "Maths.ml";;
|
||||
(* La bonne structure *)
|
||||
type code_lineaire = {k : int; n : int; g : matrice; h : matrice};;
|
||||
type code_lineaire = {klin : int; nlin : int; g : matrice; h : matrice};;
|
||||
|
||||
(* La super stucture *)
|
||||
type code_cyclique = {kcyc : int; ncyc: int; pol: polynome};;
|
||||
|
||||
(* Calcule Y = GX *)
|
||||
let encoder code x = produit code.g x ;;
|
||||
@ -44,9 +47,34 @@ let construire_code_lineaire_systematique k n redondance =
|
||||
c :: (iteredon (ajout * 2) queue)
|
||||
in iteredon 1 redondance
|
||||
and h = redondance @ (identite (n-k)) in
|
||||
{k = k; n = n; g = g; h = h}
|
||||
{klin = k; nlin = 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 *)
|
||||
@ -88,7 +116,7 @@ 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 n = code.nlin in
|
||||
let propriete = fun v -> (0 < v) && (appartenir code v) in
|
||||
let (p, _) = plus_petit_verifiant propriete n n in p
|
||||
;;
|
||||
@ -97,7 +125,7 @@ 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.k) - 1 in
|
||||
let mot_max = (deux_puissance code.klin) - 1 in
|
||||
let rec iterer = function
|
||||
| x when x = mot_max -> raise PasDansLeCodeException
|
||||
| x ->
|
||||
@ -111,7 +139,7 @@ exception IndecodableException;;
|
||||
(* 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.n in
|
||||
let e_c = (d_min - 1) / 2 and n = code.nlin in
|
||||
let propriete = fun v -> appartenir code ((lxor) z v) in
|
||||
match plus_petit_verifiant propriete e_c n with
|
||||
| (-1, 0) -> raise IndecodableException
|
||||
|
||||
6
CompteRendu/.gitignore
vendored
Normal file
6
CompteRendu/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
*.aux
|
||||
*.log
|
||||
*.pdf
|
||||
*.sh
|
||||
*.synctex.gz
|
||||
*.toc
|
||||
49
CompteRendu/CompteRendu.tex
Normal file
49
CompteRendu/CompteRendu.tex
Normal file
@ -0,0 +1,49 @@
|
||||
% !TeX encoding = UTF-8
|
||||
\documentclass[10pt,a4paper]{article}
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage[margin=0.5in]{geometry}
|
||||
\usepackage[french]{babel}
|
||||
\usepackage{tabularx}
|
||||
\usepackage{theorem}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amssymb}
|
||||
\usepackage{calrsfs}
|
||||
\usepackage{setspace}
|
||||
|
||||
\usepackage{bashful}
|
||||
|
||||
|
||||
\theorembodyfont{\upshape}
|
||||
|
||||
% Assure que les nouvelles parties commencent toujours sur une nouvelle page.
|
||||
\let\oldpart\part
|
||||
\renewcommand\part{\clearpage\oldpart}
|
||||
|
||||
% Un peu plus d'interligne, c'est plus lisible
|
||||
\doublespacing
|
||||
|
||||
% Fait une jolie barre horizontale
|
||||
\newcommand{\hsep}{\centerline{\rule{0.8\linewidth}{.05pt}}}
|
||||
|
||||
\author{Samy AVRILLON, Victor BELLOT, Dylan THEVENET}
|
||||
\title{Études des codes cycliques}
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
\hsep
|
||||
|
||||
\tableofcontents
|
||||
|
||||
\pagebreak
|
||||
|
||||
\part{Mathématique}
|
||||
|
||||
|
||||
|
||||
\part{Algorithmie}
|
||||
\section{Structures de données crées}
|
||||
\section{Liste des fonctions}
|
||||
|
||||
|
||||
\end{document}
|
||||
80
Maths.ml
80
Maths.ml
@ -1,6 +1,9 @@
|
||||
type vecteur = int;;
|
||||
type matrice = int list;;
|
||||
type polynome = int;;
|
||||
|
||||
|
||||
(***************** AFFICHAGE *****************)
|
||||
(* Zolie fonction d'affichage (h=nombre de lignes) *)
|
||||
(* L'algorithme est moche, mais y a pas trop d'autre solution que de arrayiser la liste, c'est stoqué dans le mauvais sens *)
|
||||
let nthOfBinarint i n = if ((0b1 lsl n) land i)=0 then "0" else "1";;
|
||||
@ -26,6 +29,22 @@ let print_matrice h (matl:matrice) :unit =
|
||||
print_endline "┘";;
|
||||
let print_vecteur h x = print_matrice h [x];;
|
||||
|
||||
let print_polynome pol =
|
||||
let rec aux pol i preums = match pol with
|
||||
| 0 -> print_endline ""
|
||||
| pol when pol mod 2 = 0 -> aux (pol lsr 1) (i+1) preums
|
||||
| _ -> begin
|
||||
begin
|
||||
match (preums,i) with
|
||||
| true,0 -> print_string "1"
|
||||
| true,_ -> (print_string "X^";print_int i)
|
||||
| false,_ -> (print_string " + X^";print_int i)
|
||||
end;aux (pol lsr 1) (i+1) false
|
||||
end
|
||||
in aux pol 0 true;;
|
||||
|
||||
(***************** MATRICES *****************)
|
||||
|
||||
(* Effectue le produit matriciel 'matrice' . 'vecteur' *)
|
||||
let produit (matrice:matrice) (vecteur:vecteur) :vecteur =
|
||||
let rec auxiliaire resultat_partiel masque = function
|
||||
@ -35,13 +54,17 @@ let produit (matrice:matrice) (vecteur:vecteur) :vecteur =
|
||||
if masque mod 2 = 1
|
||||
then (lxor) colonne resultat_partiel
|
||||
else resultat_partiel
|
||||
in auxiliaire resultat (masque / 2) reste
|
||||
in auxiliaire resultat (masque lsr 1) reste
|
||||
in auxiliaire 0 vecteur matrice
|
||||
;;
|
||||
|
||||
(* Ne calcul papy *)
|
||||
let deux_puissance = (lsl) 1;;
|
||||
|
||||
let orderize p q =
|
||||
if (p<q)
|
||||
then (p,q)
|
||||
else (q,p);;
|
||||
|
||||
(* Construit la matrice identité de taille d.d *)
|
||||
let identite d =
|
||||
@ -55,13 +78,15 @@ let identite d =
|
||||
(* Change l'état du 'i'-eme bit *)
|
||||
let changer_bit i = (lxor) (deux_puissance i);;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(* Décalage gauche avec entier relatif *)
|
||||
let rec decagauche x = function
|
||||
| n when n < 0 -> x lsr (-n)
|
||||
| n when n > 0 -> x lsl n
|
||||
| n -> x
|
||||
;;
|
||||
|
||||
(* Vérifie que 'y' respecte toutes les contraintes de 'cs' *)
|
||||
(* Est-ce que pour tout P dans cs, P(cs) ? *)
|
||||
(* Est-ce que pour tout P dans cs, P(y) ? *)
|
||||
let respecter y cs =
|
||||
let ny = (lnot) y in
|
||||
List.fold_right (fun c b -> b && (land) c ny > 0) cs true
|
||||
@ -74,3 +99,46 @@ let matriceAuPif l h =
|
||||
| 0 -> tmp
|
||||
| l -> aux (l-1) h (((Random.bits ()) land filtre)::tmp)
|
||||
in aux l h [];;
|
||||
|
||||
(***************** POLYNOMES *****************)
|
||||
|
||||
let polmul (p_in:polynome) (q_in:polynome) : polynome =
|
||||
let (p,q) = orderize p_in q_in in
|
||||
let rec sub pa qa somme =
|
||||
if pa=0 then somme else
|
||||
sub (pa lsr 1) (qa lsl 1) (if (pa mod 2=0) then somme else (somme lxor qa))
|
||||
in sub p q 0 ;;
|
||||
|
||||
let degre (p:polynome) :int =
|
||||
let rec aux p d =
|
||||
match p with
|
||||
| 0 -> -1
|
||||
| 1 -> d
|
||||
| _ -> aux (p lsr 1) (d+1)
|
||||
in aux p 0;;
|
||||
|
||||
let poldiveuc (p:polynome) (q:polynome) : (polynome * polynome) =
|
||||
let dq = degre q in
|
||||
let rec sub quotient reste =
|
||||
let dr = degre reste in
|
||||
let d = dr - dq in
|
||||
if d >= 0
|
||||
then sub (quotient lxor (deux_puissance d)) (reste lxor (q lsl d))
|
||||
else (quotient, reste)
|
||||
in sub 0 p;;
|
||||
|
||||
let poldiv (p:polynome) (q:polynome) : polynome = fst (poldiveuc p q);;
|
||||
let polrst (p:polynome) (q:polynome) : polynome = snd (poldiveuc p q);;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
28
Test.ml
28
Test.ml
@ -6,6 +6,15 @@ let matest = [0b01110; 0b00101; 0b10111];;
|
||||
print_matrice 5 matest;;
|
||||
produit matest 0b110;; (* -> 0b10010 = 8*)
|
||||
|
||||
(* Tests des polynomes *)
|
||||
let pol1 = 13 and pol2 = 67;;
|
||||
print_polynome pol1;;
|
||||
print_polynome pol2;;
|
||||
print_polynome (polmul pol1 pol2);;
|
||||
let qt,rst=(poldiveuc pol2 pol1) in
|
||||
print_polynome qt;
|
||||
print_polynome rst;;
|
||||
|
||||
(* Test des fonctions de base *)
|
||||
deux_puissance 11;;
|
||||
identite 3;;
|
||||
@ -29,11 +38,13 @@ let code_hamming =
|
||||
construire_code_lineaire_systematique 4 7 [7; 3; 5; 6]
|
||||
;;
|
||||
|
||||
distance_minimale code_paparfait;;
|
||||
distance_minimale code_hamming;;
|
||||
|
||||
|
||||
|
||||
exception GTROUVE of matrice;;
|
||||
|
||||
for i=0 to 200000
|
||||
for i=0 to 20
|
||||
do
|
||||
Random.self_init ();
|
||||
let matPapa = matriceAuPif 9 12 in
|
||||
@ -48,10 +59,19 @@ print_vecteur 21 (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 21;;
|
||||
|
||||
(* Tests des codes cycliques *)
|
||||
let cocycl = {ncyc=7;kcyc=4;pol=13};;
|
||||
print_polynome cocycl.pol;;
|
||||
poldiveuc ((deux_puissance 7) +1) cocycl.pol;;
|
||||
print_polynome ((deux_puissance 7) +1);;
|
||||
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;;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user