Encoders_Decoders
system:sage


<h1>Basic encoding and decoding</h1>

<p><span style="font-size: large;">Warning: if you do not have a copy of our bitbucket repository, these examples will not work!</span></p>

{{{id=1|
F = GF(23)
n, k = 15, 7
C = GeneralizedReedSolomonCode(F.list()[:n], k)
C
///
}}}

<p>We want to encode an element of the message space</p>

{{{id=32|
V = VectorSpace(F, k)
m = V.random_element()
print m
///
}}}

{{{id=2|
c = C.encode(m)
print c
///
}}}

{{{id=33|
print c in C
///
}}}

<p>Now we can decode it</p>

{{{id=40|
y = copy(c)
y[5] += 1
y[7] += 1
y[11] += 1
print y in C
///
}}}

{{{id=34|
c_dec = C.decode_to_code(y)
print c_dec == c
///
}}}

<p>And we can even get back to the original message</p>

{{{id=6|
m_dec = C.decode_to_message(y)
print m_dec == m
///
}}}

<h1>Advanced encoding and decoding</h1>

<p>I want to select a specific encoder</p>

{{{id=39|
C.encoders_available()
///
}}}

{{{id=13|
Enc_vect = C.encoder('EvaluationVector')
print Enc_vect
///
}}}

{{{id=35|
Enc_poly = C.encoder('EvaluationPolynomial')
print Enc_poly
///
}}}

<p>Encoders are cached</p>

{{{id=14|
C._cached_encoders
///
}}}

<p>Encoding and recovery</p>

{{{id=18|
c = Enc_vect.encode(m)
print c
///
}}}

{{{id=41|
c in C
///
}}}

{{{id=19|
p = Enc_poly.unencode(c)
print p
///
}}}

{{{id=20|
Enc_poly.encode(p)
///
}}}

{{{id=21|
print Enc_poly.message_space()
///
}}}

{{{id=36|
print Enc_vect.message_space()
///
}}}

<p>Decode from a code, or decode from a decoder?</p>

{{{id=22|
C.decoders_available()
///
}}}

{{{id=24|
Gao = C.decoder('Gao')
Gao
///
}}}

{{{id=25|
print y
print y in C
///
}}}

{{{id=26|
print Gao.connected_encoder()
///
}}}

{{{id=38|
print Gao.message_space()
///
}}}

{{{id=28|
Gao.decode_to_message(y)
///
}}}

{{{id=29|
C.decode_to_message(y)
///
}}}

{{{id=30|
C.decoder()
///
}}}

{{{id=42|

///
}}}