bit-flipping

This commit is contained in:
2026-05-10 13:30:23 +02:00
parent 504527269a
commit 296331096c
3 changed files with 9055 additions and 5468 deletions

View File

@ -1741,3 +1741,685 @@
content((0, -1.2), text(size: 0.8em, fill: green, weight: "bold")[Distance maximale], anchor: "north")
})
}
// --- VRAIES MATRICES GÉNÉRÉES ---
#let _h_pts = (
(10, 0),
(14, 0),
(15, 0),
(16, 0),
(17, 0),
(2, 1),
(5, 1),
(7, 1),
(13, 1),
(16, 1),
(18, 1),
(21, 1),
(28, 1),
(4, 2),
(9, 2),
(15, 2),
(17, 2),
(18, 2),
(3, 3),
(13, 3),
(17, 3),
(25, 3),
(29, 3),
(1, 4),
(2, 4),
(9, 4),
(29, 4),
(5, 5),
(7, 5),
(11, 5),
(14, 5),
(16, 5),
(22, 5),
(27, 5),
(6, 6),
(14, 6),
(22, 6),
(28, 6),
(1, 7),
(11, 7),
(12, 7),
(21, 7),
(23, 7),
(0, 8),
(5, 8),
(23, 8),
(26, 8),
(27, 8),
(1, 9),
(3, 9),
(4, 9),
(6, 9),
(7, 9),
(8, 9),
(11, 9),
(19, 9),
(21, 9),
(26, 9),
(12, 10),
(15, 10),
(20, 10),
(29, 10),
(2, 11),
(12, 11),
(20, 11),
(24, 11),
(28, 11),
(0, 12),
(3, 12),
(8, 12),
(10, 12),
(18, 12),
(19, 12),
(24, 12),
(25, 12),
(4, 13),
(8, 13),
(20, 13),
(22, 13),
(23, 13),
(26, 13),
(0, 14),
(6, 14),
(9, 14),
(10, 14),
(13, 14),
(19, 14),
(24, 14),
(25, 14),
(27, 14),
)
#let _p_pts = (
(0, 0),
(1, 0),
(3, 0),
(4, 0),
(7, 0),
(8, 0),
(10, 0),
(13, 0),
(14, 0),
(2, 1),
(3, 1),
(9, 1),
(10, 1),
(11, 1),
(12, 1),
(13, 1),
(0, 2),
(1, 2),
(2, 2),
(4, 2),
(7, 2),
(8, 2),
(9, 2),
(10, 2),
(11, 2),
(12, 2),
(2, 3),
(3, 3),
(4, 3),
(11, 3),
(12, 3),
(13, 3),
(14, 3),
(0, 4),
(2, 4),
(3, 4),
(5, 4),
(7, 4),
(9, 4),
(11, 4),
(14, 4),
(0, 5),
(2, 5),
(3, 5),
(4, 5),
(7, 5),
(8, 5),
(9, 5),
(10, 5),
(12, 5),
(13, 5),
(14, 5),
(2, 6),
(3, 6),
(8, 6),
(9, 6),
(11, 6),
(3, 7),
(4, 7),
(5, 7),
(6, 7),
(7, 7),
(8, 7),
(10, 7),
(11, 7),
(13, 7),
(1, 8),
(2, 8),
(3, 8),
(8, 8),
(9, 8),
(12, 8),
(0, 9),
(5, 9),
(9, 9),
(11, 9),
(0, 10),
(3, 10),
(4, 10),
(7, 10),
(8, 10),
(10, 10),
(11, 10),
(12, 10),
(13, 10),
(0, 11),
(1, 11),
(3, 11),
(4, 11),
(5, 11),
(6, 11),
(11, 11),
(14, 11),
(2, 12),
(4, 12),
(6, 12),
(8, 12),
(9, 12),
(11, 12),
(12, 12),
(14, 12),
(3, 13),
(4, 13),
(5, 13),
(7, 13),
(8, 13),
(10, 13),
(11, 13),
(13, 13),
(14, 13),
(1, 14),
(2, 14),
(9, 14),
)
// --- Composant d'illustration des vraies densités ---
#let paradoxe_densite_reel() = {
cetz.canvas(length: 0.18cm, {
// Réglage de l'échelle pour que ça tienne
import cetz.draw: *
// Fonction pour dessiner une matrice à partir de ses points
let draw_real_matrix(offset_x, cols, rows, pts, title, col, dens_text) = {
// Cadre
rect((offset_x, 0), (offset_x + cols, -rows), stroke: 1.5pt + black)
// Titre au dessus
content((offset_x + cols / 2, 2.5), text(weight: "bold", size: 0.8em)[#title])
// Densité en dessous
content((offset_x + cols / 2, -rows - 2.2), text(
fill: gray,
weight: "bold",
size: 0.65em,
)[_Densité_ : #dens_text])
// Dessin des vrais points (les '1')
for (x, y) in pts {
circle((offset_x + x + 0.5, -y - 0.5), radius: 0.35, fill: col, stroke: none)
}
}
// --- 1. Dessin de la matrice H (0 à 30) ---
// draw_real_matrix(0, 30, 15, _h_pts, "H (Clairsemée)", orange, "20%")
draw_real_matrix(0, 30, 15, _h_pts, "H", orange, "20%")
// --- 2. Zone centrale élargie pour le Pivot de Gauss ---
let arrow_start = 32
let arrow_end = 50
let center_x = (arrow_start + arrow_end) / 2
line((arrow_start, -7.5), (arrow_end, -7.5), mark: (end: "stealth", fill: black), stroke: 1.5pt + black)
content((center_x, -5), text(size: 0.70em, style: "italic", weight: "bold")[Pivot de Gauss])
// --- 3. Dessin de la matrice P décalée ---
// On commence P à 52 (au lieu de 41)
// draw_real_matrix(52, 15, 15, _p_pts, "Bloc P (Dense)", blue, "50%")
draw_real_matrix(52, 15, 15, _p_pts, "Bloc P", blue, "50%")
})
}
#let schema_systematique() = {
cetz.canvas(length: 1cm, {
import cetz.draw: *
let w_p = 2.2
let w_i = 2.4
let h = 1.5
// --- MATRICE H = [P^T | I] ---
group({
translate((-w_p - w_i - 1.5, 0))
content((-0.2, h / 2), $bold(H) =$, anchor: "east")
// 1. Les fonds colorés (sans bordure)
rect((0, 0), (w_p, h), fill: blue.lighten(80%), stroke: none)
rect((w_p, 0), (w_p + w_i, h), fill: gray.lighten(90%), stroke: none)
// 2. Les lignes (une seule par intersection)
rect((0, 0), (w_p + w_i, h), stroke: 1.5pt + black) // Contour global
line((w_p, 0), (w_p, h), stroke: 1pt + black) // Séparation propre
content((w_p / 2, h / 2), $bold(P)^top$, text: (fill: blue.darken(20%), weight: "bold"))
content((w_p + w_i / 2, h / 2), $bold(I)_(n-k)$)
})
// Flèche centrale
line((-1.0, h / 2), (0.7, h / 2), mark: (end: "stealth", fill: black), stroke: 1.5pt + black)
// --- MATRICE G = [I | P] ---
group({
translate((2.5, 0))
content((-0.2, h / 2), $bold(G) =$, anchor: "east")
// 1. Les fonds colorés (sans bordure)
rect((0, 0), (w_i, h), fill: gray.lighten(90%), stroke: none)
rect((w_i, 0), (w_i + w_p, h), fill: blue.lighten(80%), stroke: none)
// 2. Les lignes
rect((0, 0), (w_i + w_p, h), stroke: 1.5pt + black) // Contour global
line((w_i, 0), (w_i, h), stroke: 1pt + black) // Séparation propre
content((w_i / 2, h / 2), $bold(I)_k$)
content((w_i + w_p / 2, h / 2), $bold(P)$, text: (fill: blue.darken(20%), weight: "bold"))
})
})
}
#let dessiner_matrice(nom, blocs, hauteur: 1.5) = {
cetz.canvas(length: 1cm, {
import cetz.draw: *
group({
// 1. Nom de la matrice à gauche (ex: "H =")
if nom != none {
content((-0.2, hauteur / 2), nom, anchor: "east")
}
let x = 0 // Curseur pour avancer de gauche à droite
// 2. Étape des fonds et du texte (sans aucune bordure)
for bloc in blocs {
let w = bloc.at("largeur", default: 2)
let bg = bloc.at("fond", default: none)
let txt = bloc.at("texte", default: none)
// Dessine le fond coloré
rect((x, 0), (x + w, hauteur), fill: bg, stroke: none)
// Place le texte exactement au milieu du bloc
content((x + w / 2, hauteur / 2), txt)
x += w // On décale le curseur pour le prochain bloc
}
let largeur_totale = x
// 3. Étape des lignes (pour des intersections parfaites)
x = 0
for i in range(blocs.len() - 1) {
x += blocs.at(i).at("largeur", default: 2)
// Lignes de séparation internes (plus fines)
line((x, 0), (x, hauteur), stroke: 1pt + black)
}
// 4. Contour global par-dessus tout (plus épais)
rect((0, 0), (largeur_totale, hauteur), stroke: 1.5pt + black, fill: none)
})
})
}
//Comp 1
#let vvals = (1, 0, 1, 0)
#let edges = ((0, 0), (1, 0), (3, 0), (0, 1), (2, 1), (3, 1), (1, 2), (2, 2))
#let graph_layout(step: 1) = {
cetz.canvas(length: 0.85cm, {
import cetz.draw: *
let (vy, cy) = (4.5, 0.0) // vy = Top (Variable Nodes), cy = Bottom (Check Nodes)
let vxs = (0.0, 2.5, 5.0, 7.5)
let cxs = (1.25, 3.75, 6.25)
let r_v = 0.45
let s_c = 0.4
// --- 1. LES ARÊTES AVEC DIRECTIONALITÉ ---
for (k, (vi, ci)) in edges.enumerate() {
let v_pos = (vxs.at(vi), vy)
let c_pos = (cxs.at(ci), cy)
if step == 1 {
// VN -> CN : On part du haut vers le bas
line(
v_pos,
c_pos,
shorten-start: r_v,
shorten-end: s_c,
mark: (end: ">", fill: blue, size: 0.3),
stroke: 2pt + blue,
)
} else if step == 2 {
// CN -> VN : On part du bas vers le haut
let is_err = (ci == 0 or ci == 2)
let col = if is_err { red } else { green.darken(20%) }
line(
c_pos,
v_pos,
shorten-start: s_c,
shorten-end: r_v,
mark: (end: ">", fill: col, size: 0.3),
stroke: 2pt + col,
)
} else {
// Étape 3 : Passif
line(v_pos, c_pos, shorten-start: r_v, shorten-end: s_c, stroke: 1pt + gray.lighten(70%))
}
}
// --- 2. LES VARIABLE NODES (VN) ---
for i in range(4) {
let pos = (vxs.at(i), vy)
let is_flip = (step == 3 and i == 1)
let col = if is_flip { red } else { blue }
let bg = if is_flip { red.lighten(92%) } else { blue.lighten(90%) }
let val = if is_flip { "1" } else { str(vvals.at(i)) }
circle(pos, radius: r_v, fill: bg, stroke: (if is_flip { 2.5pt } else { 1.5pt }) + col)
content(pos, text(weight: "bold", fill: col, size: 1.1em)[#val])
content((pos.at(0), pos.at(1) + 0.8), text(size: 0.8em, fill: col.darken(0%))[$v_#i$])
if is_flip {
content((pos.at(0) + 0.1, pos.at(1) + 1.3), text(fill: red, weight: "bold", size: 0.7em)[FLIP !])
}
}
// --- 3. LES CHECK NODES (CN) ---
for j in range(3) {
let pos = (cxs.at(j), cy)
let val = if j == 1 { 0 } else { 1 }
let col = orange
let bg = orange.lighten(90%)
if step >= 2 {
let is_ok = (val == 0)
col = if is_ok { green.darken(20%) } else { red }
bg = col.lighten(92%)
}
rect((pos.at(0) - s_c, pos.at(1) - s_c), (pos.at(0) + s_c, pos.at(1) + s_c), fill: bg, stroke: 1.8pt + col)
content(pos, text(weight: "bold", fill: col, size: 1.1em)[#str(val)])
content((pos.at(0), pos.at(1) - 0.8), text(size: 0.8em, fill: col.darken(0%))[$c_#j$])
}
})
}
#let bf_step1_sending() = graph_layout(step: 1)
#let bf_step2_verdict() = graph_layout(step: 2)
#let bf_step3_flip() = graph_layout(step: 3)
#let schema_vote_majoritaire(n_erreurs: 3, flipped: true) = {
cetz.canvas(length: 1.0cm, {
import cetz.draw: *
// Positions des CN autour du VN central
let v_pos = (0.0, 0.0)
let c_positions = (
(-2.2, 1.8),
(0.0, 2.2),
(2.2, 1.8),
(-2.2, -1.8),
)
// Statuts des CN (1=Erreur)
let states = (1, 1, 1, 0)
let col_err = red
let col_ok = green.darken(10%)
// Arêtes avec flèche CN→VN
for (i, p) in c_positions.enumerate() {
let col = if states.at(i) == 1 { col_err } else { col_ok }
// VN→CN (bleu)
line(
v_pos,
p,
mark: (end: "stealth", fill: blue.lighten(20%), size: 0.16),
stroke: 1.2pt + blue.lighten(30%),
)
// CN→VN (coloré)
line(
p,
(v_pos.at(0) + 0.06, v_pos.at(1) + 0.06),
mark: (end: "stealth", fill: col, size: 0.18),
stroke: 1.8pt + col,
)
// Badge message
let mx = (v_pos.at(0) + p.at(0)) / 2
let my = (v_pos.at(1) + p.at(1)) / 2
content(
(mx, my),
box(
fill: if states.at(i) == 1 { red.lighten(88%) } else { green.lighten(88%) },
stroke: 0.5pt + col,
radius: 2pt,
inset: (x: 3pt, y: 1.5pt),
)[#text(size: 0.52em, fill: col, weight: "bold")[#if states.at(i) == 1 { [✗] } else { [✓] }]],
)
}
// CN (carrés)
for (i, p) in c_positions.enumerate() {
let col = if states.at(i) == 1 { col_err } else { col_ok }
let sz = 0.35
rect(
(p.at(0) - sz, p.at(1) - sz),
(p.at(0) + sz, p.at(1) + sz),
fill: col.lighten(90%),
stroke: 1.8pt + col,
)
content(p, text(size: 0.72em, fill: col, weight: "bold")[#states.at(i)])
}
// VN central
let r_vn = 0.52
let col_vn = if flipped { red } else { blue }
circle(
v_pos,
radius: r_vn,
fill: col_vn.lighten(82%),
stroke: 2.5pt + col_vn,
)
let val_txt = if flipped { [0] } else { [1] }
content(v_pos, text(size: 0.95em, fill: col_vn, weight: "bold")[#val_txt])
// Décision sous le nœud
if flipped {
content(
(0, -1.0),
box(
fill: red.lighten(88%),
stroke: 1.2pt + red,
radius: 4pt,
inset: (x: 7pt, y: 4pt),
)[#text(fill: red, weight: "bold", size: 0.78em)[FLIP : 1 → 0]],
)
} else {
content(
(0, -1.0),
box(
fill: rgb("#f8f9fa"),
stroke: 0.8pt + gray,
radius: 4pt,
inset: (x: 7pt, y: 4pt),
)[#text(fill: gray.darken(40%), size: 0.72em, style: "italic")[Majorité = 3/4 ✗]],
)
}
})
}
// --- Définitions de style globales ---
#let iterative_decoder_colors = (
top: rgb("000000"), // Noir
cn_update: rgb("ff9933"), // Orange
vn_update: rgb("3366cc"), // Bleu
success: rgb("339900"), // Vert
failure: rgb("cc3333"), // Rouge
edge: black,
)
// Définir des styles de nœuds avec de grands insets pour un espacement généreux
#let node_style = (
cn_update: (
stroke: iterative_decoder_colors.cn_update,
fill: iterative_decoder_colors.cn_update.lighten(90%),
radius: 4pt,
inset: (x: 20pt, y: 15pt), // Grand inset horizontal et vertical
label: (align: center, gutter: 8pt, size: 1em),
),
vn_update: (
stroke: iterative_decoder_colors.vn_update,
fill: iterative_decoder_colors.vn_update.lighten(90%),
radius: 4pt,
inset: (x: 20pt, y: 15pt),
label: (align: center, gutter: 8pt, size: 1em),
),
diamond_node: (
radius: 1pt, // Coins légèrement arrondis pour le diamant
label: (align: center, size: 1em, gutter: 0pt), // Font légèrement plus petit pour la lisibilité
),
output_node: (
radius: 4pt,
inset: (x: 10pt, y: 8pt), // Espacement légèrement plus compact pour les sorties
label: (align: center, size: 1em, gutter: 4pt),
),
)
// Style d'arête
#let edge_style = (
stroke: iterative_decoder_colors.edge,
mark: (end: ">"),
)
#let schema_boucle_bf() = {
cetz.canvas(length: 0.9cm, {
import cetz.draw: *
let s_fleche = (stroke: 1.5pt + black, mark: (end: "stealth", fill: black, size: 0.22))
let col_1 = orange
let col_2 = blue
let col_3 = green.darken(10%)
let col_stop = red
// --- 1. PARAMÈTRES ---
let w_boite = 9.2
let h_boite = 3.2
let espacement_titre = 8pt // Un peu réduit pour l'équilibre
let y_init = 12.0
let y_cn = 8.0
let y_vn = 3.5
let y_check = -1.0
let y_fail = -5.5
let w_l = 2.4
let h_l = 1.3
// --- 2. ANCRES (Rectangles invisibles) ---
rect((-2.5, y_init - 0.6), (2.5, y_init + 0.6), stroke: none, name: "init")
rect((-w_boite / 2, y_cn - h_boite / 2), (w_boite / 2, y_cn + h_boite / 2), stroke: none, name: "cn")
rect((-w_boite / 2, y_vn - h_boite / 2), (w_boite / 2, y_vn + h_boite / 2), stroke: none, name: "vn")
rect((-w_l, y_check - h_l), (w_l, y_check + h_l), stroke: none, name: "check")
// Bloc succès bien large
rect((5.8, y_check - 1.0), (12.5, y_check + 1.0), stroke: none, name: "ok")
rect((-w_boite / 2, y_fail - 0.7), (w_boite / 2, y_fail + 0.7), stroke: none, name: "fail")
// --- 3. DESSIN DES FLÈCHES ---
line("init.south", "cn.north", ..s_fleche)
line("cn.south", "vn.north", ..s_fleche)
line("vn.south", "check.north", ..s_fleche)
line("check.south", "fail.north", ..s_fleche)
line("check.east", "ok.west", ..s_fleche)
line("check.west", (-6.5, y_check), (-6.5, y_cn), "cn.west", ..s_fleche)
// --- 4. DESSIN VISUEL ---
// Mot reçu
rect("init.north-west", "init.south-east", fill: black, radius: 25pt)
content("init", text(white, weight: "bold", size: 1.1em)[Mot reçu $bold(r)$])
// ① CN Update - Correction de l'équilibre
rect("cn.north-west", "cn.south-east", fill: col_1.lighten(97%), stroke: 2.2pt + col_1, radius: 5pt)
content("cn")[
#set align(center + horizon)
#block(breakable: false)[
#set align(left)
#stack(dir: ttb, spacing: espacement_titre, text(1.1em, fill: col_1, weight: "bold")[① CN Update], text(
0.85em,
)[Calcul du syndrome $bold(s) = bold(H)bold(r)^T$ \ Chaque $c_i$ évalue sa parité])
]
]
// ② VN Update - Correction de l'équilibre
rect("vn.north-west", "vn.south-east", fill: col_2.lighten(97%), stroke: 2.2pt + col_2, radius: 5pt)
content("vn")[
#set align(center + horizon)
#block(breakable: false)[
#set align(left)
#stack(dir: ttb, spacing: espacement_titre, text(1.1em, fill: col_2, weight: "bold")[② VN Update], text(
0.85em,
)[Chaque $v_j$ compte ses erreurs\ Si majorité → FLIP])
]
]
// Losange
line(
"check.north",
"check.east",
"check.south",
"check.west",
close: true,
fill: green.lighten(97%),
stroke: 2.2pt + col_3,
)
content("check", text(1.1em, weight: "bold")[$bold(s) = bold(0)$])
// Succès : Largeur corrigée et texte sur une ligne
rect("ok.north-west", "ok.south-east", fill: col_3.lighten(97%), stroke: 2.2pt + col_3, radius: 5pt)
content("ok", text(col_3, weight: "bold", size: 1.1em)[Succès : $hat(bold(c))=bold(r)$])
// Échec - Correction de l'équilibre
rect("fail.north-west", "fail.south-east", fill: col_stop.lighten(97%), stroke: 2.2pt + col_stop, radius: 5pt)
content("fail")[
#set align(center + horizon)
#text(col_stop, weight: "bold", size: 1.1em)[iter $>$ M $arrow.r$ Échec]
]
// --- 5. ÉTIQUETTES ---
// Oui centré sur sa flèche
content((4.1, y_check + 0.6), text(col_3, weight: "bold", size: 1.1em)[Oui])
content((1.2, (y_check + y_fail) / 2), text(col_stop, weight: "bold", size: 1.1em)[Non])
content((-7.3, (y_cn + y_check) / 2), angle: 90deg, text(size: 1.1em, style: "italic", weight: "bold")[iter $+1$])
})
}