Back to index

texmacs  1.0.7.15
Classes | Defines | Functions
polynomial.hpp File Reference
#include "vector.hpp"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  polynomial_rep
class  polynomial
class  unary_properties< polynomial< T > >
class  binary_properties< polynomial< T >, polynomial< U > >
class  binary_properties< T, polynomial< U > >
class  binary_properties< polynomial< T >, U >

Defines

#define TMPL   template<typename T>
#define BINARY_TMPL   template<typename T, typename U>
#define R   typename unary_properties<T>::norm_type
#define M   typename binary_properties<T,U>::product_type

Functions

TMPL int N (polynomial< T > a)
TMPL TA (polynomial< T > a)
 CONCRETE_TEMPLATE_CODE (polynomial, typename, T)
TMPL int degree (polynomial< T > p)
TMPL tree as_tree (polynomial< T > p)
TMPL tm_ostreamoperator<< (tm_ostream &out, polynomial< T > p)
template<typename T , typename Op >
polynomial< Tunary (polynomial< T > p)
TMPL polynomial< Tcopy (polynomial< T > v)
TMPL polynomial< Toperator- (polynomial< T > v)
template<typename T , typename Op >
polynomial< Tbinary (polynomial< T > p1, polynomial< T > p2)
TMPL polynomial< Toperator+ (polynomial< T > p1, polynomial< T > p2)
TMPL polynomial< Toperator- (polynomial< T > p1, polynomial< T > p2)
TMPL polynomial< Tderive (polynomial< T > p)
TMPL polynomial< Toperator* (polynomial< T > p1, polynomial< T > p2)
TMPL polynomial< Toperator* (T c, polynomial< T > p)
TMPL vector< polynomial< T > > operator* (T c, vector< polynomial< T > > v)
TMPL vector< polynomial< T > > operator* (array< T > c, polynomial< T > p)
TMPL array< Textract (vector< polynomial< T > > v, int i)

Define Documentation

#define BINARY_TMPL   template<typename T, typename U>

Definition at line 16 of file polynomial.hpp.

#define M   typename binary_properties<T,U>::product_type

Definition at line 18 of file polynomial.hpp.

#define R   typename unary_properties<T>::norm_type

Definition at line 17 of file polynomial.hpp.

#define TMPL   template<typename T>

Definition at line 15 of file polynomial.hpp.


Function Documentation

TMPL T * A ( polynomial< T a) [inline]

Definition at line 102 of file polynomial.hpp.

{ return p->a; }

Definition at line 132 of file polynomial.hpp.

                          {
  int i, n= N(p);
  if (n == 0) return "0";
  tree sum= as_tree (p[0]);
  for (i=1; i<n; i++)
    sum= add (sum, mul (as_tree (p[i]), pow (tree ("x"), as_tree (i))));
  return sum;
}

Here is the call graph for this function:

template<typename T , typename Op >
polynomial<T> binary ( polynomial< T p1,
polynomial< T p2 
)

Definition at line 169 of file polynomial.hpp.

                                            {
  int i, n1= N(p1), n2=N(p2), m= min (n1, n2), n= max (n1, n2);
  T* a= A(p1);
  T* b= A(p2);
  T* r= tm_new_array<T> (n);
  for (i=0; i<m; i++)
    r[i]= Op::eval (a[i], b[i]);
  if (n1 < n2)
    for (; i<n; i++)
      r[i]= Op::eval (T(0), b[i]);
  else
    for (; i<n; i++)
      r[i]= Op::eval (a[i], T(0));
  return polynomial<T> (r, n);
}

Here is the call graph for this function:

CONCRETE_TEMPLATE_CODE ( polynomial  ,
typename  ,
T   
)
TMPL polynomial<T> copy ( polynomial< T v) [inline]

Definition at line 161 of file polynomial.hpp.

                       {
  return unary<T,copy_op> (v); }
TMPL int degree ( polynomial< T p) [inline]

Definition at line 103 of file polynomial.hpp.

{ return N(p)-1; }

Here is the call graph for this function:

TMPL polynomial<T> derive ( polynomial< T p) [inline]

Definition at line 194 of file polynomial.hpp.

                         {
  if (N(p) <= 1) return 0;
  int i, n= N(p);
  T* a= A(p);
  T* r= tm_new_array<T> (n-1);
  for (i=1; i<n; i++)
    r[i-1]= T(i) * a[i];
  return polynomial<T> (r, n-1);
}

Here is the call graph for this function:

TMPL array<T> extract ( vector< polynomial< T > >  v,
int  i 
)

Definition at line 258 of file polynomial.hpp.

                                          {
  // NOTE: replace array by vector as soon as "points" are vectors
  int j, n= N(v);
  array<T> r (n);
  // vector<T> r (T(0), n);
  for (j=0; j<n; j++)
    r[j]= v[j][i];
  return r;
}

Here is the call graph for this function:

TMPL int N ( polynomial< T a) [inline]

Definition at line 101 of file polynomial.hpp.

{ return p->n; }
TMPL polynomial<T> operator* ( polynomial< T p1,
polynomial< T p2 
)

Definition at line 209 of file polynomial.hpp.

                                                {
  int i, j, n1= N(p1), n2=N(p2), n= n1+n2;
  T* a= A(p1);
  T* b= A(p2);
  T* r= tm_new_array<T> (n);
  for (i=0; i<n; i++) r[i]= 0;
  for (i=0; i<n1; i++)
    for (j=0; j<n2; j++)
      r[i+j] += a[i] * b[j];
  return polynomial<T> (r, n);
}

Here is the call graph for this function:

TMPL polynomial<T> operator* ( T  c,
polynomial< T p 
)

Definition at line 222 of file polynomial.hpp.

                                  {
  int i, n= N(p);
  T* a= A(p);
  T* r= tm_new_array<T> (n);
  for (i=0; i<n; i++)
    r[i]= c * a[i];
  return polynomial<T> (r, n);
}

Here is the call graph for this function:

TMPL vector<polynomial<T> > operator* ( T  c,
vector< polynomial< T > >  v 
)

Definition at line 236 of file polynomial.hpp.

                                           {
  // TODO: superfluous after more general asymmetric vector multiplication
  int i, n= N(v);
  polynomial<T>* a= A(v);
  polynomial<T>* r= tm_new_array<polynomial<T> > (n);
  for (i=0; i<n; i++)
    r[i]= c * v[i];
  return vector<polynomial<T> > (r, n);
}

Here is the call graph for this function:

TMPL vector<polynomial<T> > operator* ( array< T c,
polynomial< T p 
)

Definition at line 247 of file polynomial.hpp.

                                         {
  // NOTE: replace array by vector as soon as "points" are vectors
  int i, n= N(c);
  T* a= A(c);
  polynomial<T>* r= tm_new_array<polynomial<T> > (n);
  for (i=0; i<n; i++)
    r[i]= a[i] * p;
  return vector<polynomial<T> > (r, n);
}

Here is the call graph for this function:

TMPL polynomial<T> operator+ ( polynomial< T p1,
polynomial< T p2 
) [inline]

Definition at line 186 of file polynomial.hpp.

                                                {
  return binary<T,add_op> (p1, p2); }
TMPL polynomial<T> operator- ( polynomial< T v) [inline]

Definition at line 165 of file polynomial.hpp.

                             {
  return unary<T,neg_op> (v); }
TMPL polynomial<T> operator- ( polynomial< T p1,
polynomial< T p2 
) [inline]

Definition at line 190 of file polynomial.hpp.

                                                {
  return binary<T,sub_op> (p1, p2); }
TMPL tm_ostream& operator<< ( tm_ostream out,
polynomial< T p 
) [inline]

Definition at line 142 of file polynomial.hpp.

                                               {
  return out << as_math_string (as_tree (p));
}

Here is the call graph for this function:

template<typename T , typename Op >
polynomial<T> unary ( polynomial< T p)

Definition at line 151 of file polynomial.hpp.

                        {
  int i, n= N(p);
  T* a= A(p);
  T* r= tm_new_array<T> (n);
  for (i=0; i<n; i++)
    r[i]= Op::eval (a[i]);
  return polynomial<T> (r, n);
}

Here is the call graph for this function: