![]() |
rssoft
0.0.0
Reed-Solomon codes library with soft decision decoding
|
00001 /* 00002 Copyright 2013 Edouard Griffiths <f4exb at free dot fr> 00003 00004 This file is part of RSSoft. A Reed-Solomon Soft Decoding library 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301 USA 00019 00020 Original from Arash Partow (see original copytight notice). 00021 Extensively modified augmented with a few methods and included in 00022 RSSoft in gf sub-namespace. 00023 00024 Univariate polynomials with coefficients in GF(2^m) class hence 00025 members of GF(2^m)[X] 00026 00027 */ 00028 /* 00029 ********************************************************************* 00030 * * 00031 * Galois Field Arithmetic Library (version 0.0.1) * 00032 * * 00033 * Class: Galois Field Polynomial * 00034 * Version: 0.0.1 * 00035 * Author: Arash Partow - 2000 * 00036 * URL: http://www.partow.net/projects/galois/index.html * 00037 * * 00038 * Copyright Notice: * 00039 * Free use of this library is permitted under the guidelines and * 00040 * in accordance with the most current version of the Common Public * 00041 * License. * 00042 * http://www.opensource.org/licenses/cpl.php * 00043 * * 00044 ********************************************************************* 00045 */ 00046 00047 #ifndef __GFQ_POLYNOMIAL_H__ 00048 #define __GFQ_POLYNOMIAL_H__ 00049 00050 #include <iostream> 00051 #include <vector> 00052 #include <utility> 00053 #include <algorithm> 00054 #include <assert.h> 00055 #include "GFq.h" 00056 #include "GFq_Element.h" 00057 00058 namespace rssoft 00059 { 00060 namespace gf 00061 { 00062 00066 class GFq_Polynomial 00067 { 00068 00069 public: 00070 00075 GFq_Polynomial(const GFq& _gf); 00076 00083 GFq_Polynomial(const GFq& _gf, const unsigned int size, GFq_Element* gfe = NULL); 00084 00090 GFq_Polynomial(const GFq& _gf, const std::vector<GFq_Element>& gfe); 00091 00096 GFq_Polynomial(const GFq_Polynomial& polynomial); 00097 00102 GFq_Polynomial(const GFq_Element& gfe); 00103 00107 ~GFq_Polynomial() 00108 { 00109 } 00110 ; 00111 00115 void init(const std::vector<GFq_Element>& _poly); 00116 00120 bool is_valid() const; 00121 00125 bool is_zero() const; 00126 00130 bool is_one() const; 00131 00135 unsigned int deg() const; 00136 00140 const GFq& field() const; 00141 00145 const std::vector<GFq_Element>& get_poly() const; 00146 00150 std::vector<GFq_Element>& get_poly_for_update(); 00151 00155 void get_poly_symbols(std::vector<GFq_Symbol>& symbols, unsigned int size=0) const 00156 { 00157 symbols.resize((size == 0 ? poly.size() : size)); 00158 std::transform(poly.begin(), poly.end(), symbols.begin(), gfq_element_to_symbol); 00159 } 00160 00165 void set_degree(const unsigned int& x); 00166 00167 GFq_Polynomial& operator =(const GFq_Polynomial& polynomial); 00168 GFq_Polynomial& operator =(const GFq_Element& gfe); 00169 GFq_Polynomial& operator+=(const GFq_Polynomial& polynomial); 00170 GFq_Polynomial& operator+=(const GFq_Element& gfe); 00171 GFq_Polynomial& operator-=(const GFq_Polynomial& polynomial); 00172 GFq_Polynomial& operator-=(const GFq_Element& gfe); 00173 GFq_Polynomial& operator*=(const GFq_Polynomial& polynomial); 00174 GFq_Polynomial& operator*=(const GFq_Element& gfe); 00175 GFq_Polynomial& operator/=(const GFq_Polynomial& divisor); 00176 GFq_Polynomial& operator/=(const GFq_Element& gfe); 00177 GFq_Polynomial& operator%=(const GFq_Polynomial& divisor); 00178 GFq_Polynomial& operator%=(const unsigned int& power); 00179 GFq_Polynomial& operator^=(const int& n); 00180 GFq_Polynomial& operator<<=(const unsigned int& n); 00181 GFq_Polynomial& operator>>=(const unsigned int& n); 00182 00183 GFq_Element& operator[](const unsigned int& term); 00184 GFq_Element operator()(const GFq_Element& value); 00185 GFq_Element operator()(GFq_Symbol value); 00186 00187 const GFq_Element& operator[](const unsigned int& term) const; 00188 const GFq_Element operator()(const GFq_Element& value) const; 00189 const GFq_Element operator()(GFq_Symbol value) const; 00190 00191 bool operator==(const GFq_Polynomial& polynomial) const; 00192 bool operator!=(const GFq_Polynomial& polynomial) const; 00193 00197 GFq_Polynomial derivative(); 00198 00203 GFq_Element make_monic(); 00204 00212 void rootChien(std::vector<GFq_Element>& roots); 00213 00218 void set_alpha_format(bool _alpha_format) 00219 { 00220 alpha_format = _alpha_format; 00221 } 00222 00226 friend std::ostream& operator <<(std::ostream& os, const GFq_Polynomial& polynomial); 00227 00228 protected: 00229 const GFq& gf; 00230 std::vector<GFq_Element> poly; 00231 bool alpha_format; // true: power of alpha representation, false: binary representation of printed coefficients 00232 }; 00233 00234 void simplify(GFq_Polynomial& polynomial); 00235 GFq_Polynomial operator +(const GFq_Polynomial& a, const GFq_Polynomial& b); 00236 GFq_Polynomial operator +(const GFq_Polynomial& a, const GFq_Element& b); 00237 GFq_Polynomial operator +(const GFq_Element& a, const GFq_Polynomial& b); 00238 GFq_Polynomial operator +(const GFq_Polynomial& a, const GFq_Symbol& b); 00239 GFq_Polynomial operator +(const GFq_Symbol& a, const GFq_Polynomial& b); 00240 GFq_Polynomial operator -(const GFq_Polynomial& a, const GFq_Polynomial& b); 00241 GFq_Polynomial operator -(const GFq_Polynomial& a, const GFq_Element& b); 00242 GFq_Polynomial operator -(const GFq_Element& a, const GFq_Polynomial& b); 00243 GFq_Polynomial operator -(const GFq_Polynomial& a, const GFq_Symbol& b); 00244 GFq_Polynomial operator -(const GFq_Symbol& a, const GFq_Polynomial& b); 00245 GFq_Polynomial operator *(const GFq_Polynomial& a, const GFq_Polynomial& b); 00246 GFq_Polynomial operator *(const GFq_Element& a, const GFq_Polynomial& b); 00247 GFq_Polynomial operator *(const GFq_Polynomial& a, const GFq_Element& b); 00248 GFq_Polynomial operator /(const GFq_Polynomial& a, const GFq_Polynomial& b); 00249 GFq_Polynomial operator /(const GFq_Polynomial& a, const GFq_Element& b); 00250 GFq_Polynomial operator %(const GFq_Polynomial& a, const GFq_Polynomial& b); 00251 GFq_Polynomial operator %(const GFq_Polynomial& a, const unsigned int& power); 00252 GFq_Polynomial operator ^(const GFq_Polynomial& a, const int& n); 00253 00257 GFq_Polynomial operator <<(const GFq_Polynomial& a, const unsigned int& n); 00258 00263 GFq_Polynomial operator >>(const GFq_Polynomial& a, const unsigned int& n); 00264 00273 GFq_Polynomial gcd(const GFq_Polynomial& a, const GFq_Polynomial& b); 00274 00279 std::pair<GFq_Polynomial, GFq_Polynomial> div(const GFq_Polynomial& a, 00280 const GFq_Polynomial& b); 00281 00287 std::vector<GFq_Element> rootex_nz(const GFq_Polynomial& a); 00288 00294 std::vector<GFq_Element> rootex(const GFq_Polynomial& a); 00295 00302 GFq_Polynomial get_monic(const GFq_Polynomial& a, GFq_Element& lead_poly); 00303 00310 std::vector<GFq_Polynomial> square_free_decomposition(const GFq_Polynomial& a); 00311 00312 } // namespace gf 00313 } // namespace rssoft 00314 00315 #endif // __GFQ_POLYNOMIAL_H__