| 1 | #***************************************************************************** |
|---|
| 2 | # Copyright (C) 2005 William Stein <wstein@gmail.com> |
|---|
| 3 | # |
|---|
| 4 | # Distributed under the terms of the GNU General Public License (GPL) |
|---|
| 5 | # |
|---|
| 6 | # This code is distributed in the hope that it will be useful, |
|---|
| 7 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 8 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 9 | # General Public License for more details. |
|---|
| 10 | # |
|---|
| 11 | # The full text of the GPL is available at: |
|---|
| 12 | # |
|---|
| 13 | # http://www.gnu.org/licenses/ |
|---|
| 14 | #***************************************************************************** |
|---|
| 15 | |
|---|
| 16 | include "../../ext/interrupt.pxi" |
|---|
| 17 | include "../../ext/stdsage.pxi" |
|---|
| 18 | include 'misc.pxi' |
|---|
| 19 | include 'decl.pxi' |
|---|
| 20 | |
|---|
| 21 | ############################################################################## |
|---|
| 22 | # |
|---|
| 23 | # ntl_GF2EX: Polynomials over GF(2) via NTL |
|---|
| 24 | # |
|---|
| 25 | # AUTHORS: |
|---|
| 26 | # - Martin Albrecht <malb@informatik.uni-bremen.de> 2006-01: initial version |
|---|
| 27 | # |
|---|
| 28 | ############################################################################## |
|---|
| 29 | |
|---|
| 30 | cdef class ntl_GF2EX: |
|---|
| 31 | r""" |
|---|
| 32 | """ |
|---|
| 33 | def __init__(self, x=[]): |
|---|
| 34 | """ |
|---|
| 35 | EXAMPLES: |
|---|
| 36 | sage: ntl.set_modulus(ntl.ZZ(3)) |
|---|
| 37 | sage: m=ntl.GF2E_modulus(ntl.GF2X([1,1,0,1,1,0,0,0,1])) |
|---|
| 38 | sage: ntl.GF2EX('[[1 0] [2 1]]') |
|---|
| 39 | [[1] [0 1]] |
|---|
| 40 | """ |
|---|
| 41 | s = str(x) |
|---|
| 42 | _sig_on |
|---|
| 43 | GF2EX_from_str(&self.x, s) |
|---|
| 44 | _sig_off |
|---|
| 45 | |
|---|
| 46 | def __new__(self, x=[]): |
|---|
| 47 | GF2EX_construct(&self.x) |
|---|
| 48 | |
|---|
| 49 | def __dealloc__(self): |
|---|
| 50 | GF2EX_destruct(&self.x) |
|---|
| 51 | |
|---|
| 52 | def __reduce__(self): |
|---|
| 53 | raise NotImplementedError |
|---|
| 54 | |
|---|
| 55 | def __repr__(self): |
|---|
| 56 | _sig_on |
|---|
| 57 | return string_delete(GF2EX_to_str(&self.x)) |
|---|
| 58 | |
|---|
| 59 | def __mul__(ntl_GF2EX self, other): |
|---|
| 60 | cdef ntl_GF2EX y |
|---|
| 61 | cdef ntl_GF2EX r = ntl_GF2EX() |
|---|
| 62 | if not isinstance(other, ntl_GF2EX): |
|---|
| 63 | other = ntl_GF2EX(other) |
|---|
| 64 | y = other |
|---|
| 65 | _sig_on |
|---|
| 66 | GF2EX_mul(r.x, self.x, y.x) |
|---|
| 67 | _sig_off |
|---|
| 68 | return r |
|---|
| 69 | |
|---|
| 70 | def __sub__(ntl_GF2EX self, other): |
|---|
| 71 | cdef ntl_GF2EX y |
|---|
| 72 | cdef ntl_GF2EX r = ntl_GF2EX() |
|---|
| 73 | if not isinstance(other, ntl_GF2EX): |
|---|
| 74 | other = ntl_GF2EX(other) |
|---|
| 75 | y = other |
|---|
| 76 | _sig_on |
|---|
| 77 | GF2EX_sub(r.x, self.x, y.x) |
|---|
| 78 | _sig_off |
|---|
| 79 | return r |
|---|
| 80 | |
|---|
| 81 | def __add__(ntl_GF2EX self, other): |
|---|
| 82 | cdef ntl_GF2EX y |
|---|
| 83 | cdef ntl_GF2EX r = ntl_GF2EX() |
|---|
| 84 | if not isinstance(other, ntl_GF2EX): |
|---|
| 85 | other = ntl_GF2EX(other) |
|---|
| 86 | y = other |
|---|
| 87 | _sig_on |
|---|
| 88 | GF2EX_add(r.x, self.x, y.x) |
|---|
| 89 | _sig_off |
|---|
| 90 | return r |
|---|
| 91 | |
|---|
| 92 | def __neg__(ntl_GF2EX self): |
|---|
| 93 | cdef ntl_GF2EX r = ntl_GF2EX() |
|---|
| 94 | _sig_on |
|---|
| 95 | GF2EX_negate(r.x, self.x) |
|---|
| 96 | _sig_off |
|---|
| 97 | return r |
|---|
| 98 | |
|---|
| 99 | def __pow__(ntl_GF2EX self, long e, ignored): |
|---|
| 100 | cdef ntl_GF2EX r = ntl_GF2EX() |
|---|
| 101 | _sig_on |
|---|
| 102 | GF2EX_power(r.x, self.x, e) |
|---|
| 103 | _sig_off |
|---|
| 104 | return r |
|---|