include/it/poly.h

Go to the documentation of this file.
00001 /*
00002    libit - Library for basic source and channel coding functions
00003    Copyright (C) 2005-2008 Francois Cayre, Vivien Chappelier, Herve Jegou
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 /*
00021   Polynomial functions
00022   Copyright (C) 2005-2007 Vivien Chappelier
00023 */
00024 
00025 #ifndef __it_poly_h
00026 #define __it_poly_h
00027 
00028 #include <it/types.h>
00029 #include <it/vec.h>
00030 #include <it/mat.h>
00031 
00032 /*---------------------------------------------------------------------------*/
00033 /*! \defgroup poly Polynomial functions                                      */
00034 /* @{                                                                        */
00035 /*---------------------------------------------------------------------------*/
00036 
00037 /* matrix of polynomials */
00038 typedef vec **pmat;
00039 
00040 static inline pmat pmat_new (int W, int H) {
00041   return ((pmat) Mat_new (vec, W, H));
00042 }
00043 static inline void pmat_delete (pmat m) {
00044   Mat_delete ((Mat) m);
00045 }
00046 
00047 /* vector of polynomials */
00048 typedef vec *pvec;
00049 
00050 static inline pvec pvec_new (int N) {
00051   return ((pvec) Vec_new (vec, N));
00052 }
00053 static inline void pvec_delete (pvec v) {
00054   Vec_delete ((Vec) v);
00055 }
00056 
00057 /* polynomial function */
00058 it_function_args (itf_polynomial) {
00059   vec  poly;
00060 };
00061 extern it_function_t itf_polynomial;
00062 
00063 /* the degree of a polynomial */
00064 #define poly_deg(p) (vec_length(p) - 1)
00065 
00066 /* remove null factors from the polynomial */
00067 void poly_normalize (vec v);
00068 
00069 /* check if the polynomial is null. */
00070 int  poly_is_null (vec v);
00071 
00072 /* evaluate the polynomial in 'x' */
00073 static inline double poly_eval (vec v, double x) {
00074   it_function_args (itf_polynomial) itf_polynomial_args;
00075   itf_polynomial_args.poly = v;
00076   return (itf_polynomial (x, &itf_polynomial_args));
00077 }
00078 
00079 /*-----------------------------------------------------------------*/
00080 /* Arithmetic operations                                           */
00081 /*-----------------------------------------------------------------*/
00082 
00083 void poly_shift (vec v, int shift);
00084 
00085 /* polynomial addition */
00086 vec  poly_add (vec a, vec b);
00087 
00088 /* polynomial subtraction */
00089 vec  poly_sub (vec a, vec b);
00090 
00091 /* polynomial multiplication */
00092 static inline vec poly_mul (vec a, vec b) {
00093   return (vec_conv (a, b));
00094 }
00095 
00096 /* Laurent polynomial Euclidean division of a by b */
00097 /* This finds Q and R such that A = B Q + R X^deg_x */
00098 /* for classical polynomial division, deg_x = 0. */
00099 vec  lpoly_ediv (vec _a, vec _b, int deg_x, vec * _q);
00100 
00101 /* polynomial Euclidean division */
00102 #define poly_ediv(a, b, _q) lpoly_ediv(a, b, 0, _q)
00103 
00104 /* returns the quotient of the Euclidean division of a by b */
00105 static inline vec poly_div (vec a, vec b) {
00106   vec  q, r;
00107   r = poly_ediv (a, b, &q);
00108   vec_delete (r);
00109   return (q);
00110 }
00111 
00112 /* returns the remainder of the Euclidean division of a by b */
00113 static inline vec poly_mod (vec a, vec b) {
00114   vec  q, r;
00115   r = poly_ediv (a, b, &q);
00116   vec_delete (q);
00117   return (r);
00118 }
00119 
00120 /* returns the greatest common divider of a and b */
00121 vec  poly_gcd (vec a, vec b);
00122 
00123 /* @} */
00124 
00125 
00126 #endif

Hosted by
Copyright (C) 2005-2006 Hervé Jégou
Vivien Chappelier
Francois Cayre
libit logo courtesy of Jonathan Delhumeau