1 #ifndef realroot_tensor_eenvops_hpp
2 #define realroot_tensor_eenvops_hpp
19 template <
class R,
class C,
class eenv,
class P >
20 void levalm (R & result,
const C * data,
const eenv & env,
const P & p)
22 typedef R result_type;
26 const int esz = env.
sz ();
27 const int nvr = env.
nvr ();
28 const int *szs = env.
szs ();
29 const int *str = env.
str ();
32 result_type* tmp =
new result_type[env.
sz()];
35 for (
int v = nvr - 1; v >= 0; v--)
36 for (
int i = 0; i < esz; i += str[v - 1]) {
44 template <
class R,
class C,
class eenv,
class P >
45 void hevalm (R & result,
const C * data,
const eenv & env,
const P & p)
47 typedef R result_type;
51 const int esz = env.
sz ();
52 const int nvr = env.
nvr ();
53 const int *szs = env.
szs ();
54 const int *str = env.
str ();
57 result_type* tmp=
new result_type[env.
sz ()], r;
59 for (
int v = nvr - 1; v >= 0; v--)
60 for (
int i = 0; i < esz; i += str[v - 1]) {
69 template<
typename real_t,
typename value_t>
70 void decasteljau( real_t * r,
unsigned sz,
const value_t& t,
int str = 1 )
73 for ( er = r + (sz-1)*str; er != r; er -= str )
74 for ( p = r; p != er; p += str )
75 *p = real_t(value_t(1)-t)* *p+t**(p+str);
79 template <
class R,
class C,
class eenv,
class P >
80 void levalb (R & result,
const C * data,
const eenv & env,
const P & p)
85 int szTemp = env.
sz();
89 const int esz (env.
sz ());
90 const int nvr (env.
nvr ());
91 const int *szs (env.
szs ());
92 const int *str (env.
str ());
96 for (
int v = nvr - 1; v >= 0; v--)
97 for (
int i = 0; i < esz; i += str[v - 1])
105 template <
class OutputIterator,
class C,
class eenv >
106 void maxs (OutputIterator _maxs_,
const C * data,
const eenv & env,
int v)
108 const int *eszs = env.
szs ();
109 const int *estr = env.
str ();
112 for ( k = 0; k < eszs[v]; k++, data += estr[v], _maxs_++)
115 for (i = 0; i < estr[-1]; i += estr[v - 1])
116 for (
const C * edata = data + i; edata < data + i + estr[v]; edata++)
117 if (*edata > *_maxs_)
122 template <
class OutputIterator,
class C,
class eenv >
123 void mins (OutputIterator _mins_,
const C * data,
const eenv & env,
int v)
125 const int *eszs = env.
szs ();
126 const int *estr = env.
str ();
129 for (p = 0, k = 0; k < eszs[v]; k++, p += estr[v], _mins_++)
132 for (i = 0; i < estr[-1]; i += estr[v - 1])
133 for (j = i; j < i + estr[v]; j++)
134 if (data[j + p] < *_mins_)
135 *_mins_ = data[j + p];
141 template <
class C,
class eenv >
142 void vswap(
C * data,
const eenv & env,
int *perm,
int *supp = 0,
int nsupp = 0 )
144 const int *szs = env.
szs ();
145 const int *str = env.
str ();
146 int ostr[env.
nvr ()];
148 for (i = env.
nvr () - 2, str[env.
nvr () - 1] = 1; i >= -1;
149 ostr[i] = szs[perm[i + 1]] * str[i + 1], i--) ;
153 for (i = 0; i < env.esz (); i++)
155 for (a = i, v = env.
nvr () - 1; a; a /= szs[v], v--)
156 o += (a % szs[v]) * ostr[perm[v]];
163 for (i = 0; i < nsupp; supp[i++] = o)
165 for (a = supp[i], v = env.
nvr () - 1; a; a /= szs[v], v--)
166 o += (a % szs[v]) * ostr[perm[v]];
174 template <
class C,
class eenv >
177 const int *estr = env.
str ();
178 const int *eszs = env.
szs ();
179 const int envr = env.
nvr ();
180 const int esz = env.
sz ();
181 const C *bins = binms[eszs[envr - 1] - 1];
182 for (
C * pdata = data; pdata < data + esz; pdata += estr[envr - 2])
184 for (
int v = 0; v < envr - 1; v++)
186 bins = binms[eszs[v] - 1];
188 for (
int i = 0; i < esz; i += estr[v - 1])
189 for (
int j = 0; j < estr[v]; j++)
190 vct::pmul (data + i + j, bins, eszs[v], estr[v], 1);
202 template <
class C,
class eenv >
205 const int *estr = env.
str ();
206 const int *eszs = env.
szs ();
207 const int envr = env.
nvr ();
208 const int esz = env.
sz ();
209 const C * bins = binoms[eszs[envr - 1] - 1];
211 for (
C * pdata = data; pdata < data + esz;
vct::pmul (pdata, bins, eszs[envr - 1]), pdata += estr[envr - 2]) ;
213 for (
int v = 0; v < envr - 1; v++)
215 bins = binoms[eszs[v] - 1];
217 for (
int i = 0; i < esz; i += estr[v - 1])
218 for (
int j = 0; j < estr[v]; j++)
219 vct::pmul (data + i + j, bins, eszs[v], estr[v], 1);
224 template <
class C,
class eenv >
227 const int *estr = env.
str ();
228 const int *eszs = env.
szs ();
229 const int envr = env.
nvr ();
230 const int esz = env.
sz ();
231 const C *bins = binoms[eszs[envr - 1] - 1];
232 for (
C * pdata = data; pdata < data + esz; pdata += estr[envr - 2])
234 for (
int v = 0; v < envr - 1; v++)
236 bins = binoms[eszs[v] - 1];
238 for (
int i = 0; i < esz; i += estr[v - 1])
239 for (
int j = 0; j < estr[v]; j++)
240 vct::pdiv (data + i + j, bins, eszs[v], estr[v], 1);
244 template<
class C>
inline
247 for ( i = st; i != st*int(sz); i += st )
248 for ( k = (sz-1)*st; k != i-st; k -= st )
254 template<
class C>
inline
260 for ( p = 0, i = 0; i < sz; i++, p += st )
261 { tmp[i] = bzc[p]; bzc[p] =
C(0); };
262 for ( p = 0, i = 0; i < sz; i++, p += st )
263 for ( bin = binoms[sz-i-1], l = p, k = 0; k < sz-i; k++, l += st )
264 bzc[l] += tmp[i]*bin[k];
266 for ( i = 0, l = 0; i < sz; i ++, l += st )
273 template <
class C,
class eenv >
276 const int *esz = e.
szs ();
277 const int *est = e.
str ();
279 for (i = 0; i < e.
sz (); i += est[v - 1])
280 for (j = i; j < i + est[v];
convertm2b (data + j, esz[v], est[v], bins), j++) ;
284 template <
class C,
class eenv >
287 for (
int v = 0; v < env.
nvr ();
convertm2b (data, env, bins, v++)) ;
293 template <
class C,
class eenv >
296 const int *esz = e.
szs ();
297 const int *est = e.
str ();
299 for (i = 0; i < e.
sz (); i += est[v - 1])
300 for (j = i; j < i + est[v];
301 convertb2m (data + j, esz[v], est[v], bins), j++) ;
305 template <
class C,
class eenv >
308 for (
int v = 0; v < env.
nvr ();
convertb2m (data, env, bins, v++)) ;
315 template<
typename C>
inline
316 void diff(
C *
b,
const C * a,
unsigned sz,
int sb,
int sa )
319 for (
unsigned i = 1; i < sz; i ++ ) { b[(i-1)*sb] = i*a[i]; };
323 template<
typename C>
inline
327 for ( i = 1, a += s; b != e; *b = *a*i++, b += s, a += s ) ;
330 template<
typename C>
inline
333 for (
int i = 1; b != e; *b++ = *(++a)*i++ ) ;
342 for ( sz_t i = 0; i < o.
sz(); i += o.
st(v-1), is += a.
st(v-1) )
343 for ( sz_t j = 0; j < a.
st(v); j ++ )
344 diff(op+i+j, ap+is+j,a.
sz(v), o.
st(v), a.
st(v)) ;
350 const int ssz = esrc.
sz ();
352 const int * sstr = esrc.
str();
353 int rst = sstr[v-1]-sstr[v];
357 for ( ed = dst, es = src; es < src+ssz; ed += rst, es += sstr[v-1] )
358 for ( i = 1, fd = ed, fs = es+sstr[v]; fs != es+sstr[v-1]; fd += sstr[v], fs += sstr[v], i ++ )
365 static void bdiff(
C * dst,
const eenv& a,
C const *
const src,
int v )
367 const int ssz = a.sz ();
368 const int * sszs = a.szs();
369 const int * sstr = a.str();
370 int rst = sstr[v-1]-sstr[v];
372 C * ed;
const C * es;
373 for ( ed = dst, es = src; es < src+ssz; ed += rst, es += sstr[v-1] )
375 C * fd;
const C * fs;
376 for ( fs = es, fd = ed; fs < es + sstr[v]; fs++, fd ++ )
379 for ( p = fs, dp = fd; p < fs+rst; p += sstr[v], dp += sstr[v] )
380 *dp = (*(p+sstr[v])-*p)*(sszs[v]-1);
385 template<
class C,
class T>
inline
389 for ( er = rlast - st ; er != r; er -= st, l += st )
392 for ( p = r; p != er; p += st )
393 *p = (1.0-t)**p+t**(p+st);
398 template <
class C,
class eenv,
class T>
inline
402 const int *sstr = env.
str ();
405 for ( el = l, er = r; el != l + sstr[-1]; el += sstr[v-1], er += sstr[v-1] )
408 for ( fl = el, fr = er; fl != el + sstr[v]; fl++, fr++ )
414 template<
class C>
inline
418 for ( er = rlast - st ; er != r; er -= st, l += st )
421 for ( p = r; p != er; p += st )
422 *p = (*p+*(p+st))/
C(2);
427 template <
class C,
class eenv >
431 const int *sstr = env.
str ();
433 for ( el = l, er = r; el != l + sstr[-1]; el += sstr[v-1], er += sstr[v-1] )
436 for ( fl = el, fr = er; fl != el + sstr[v]; fl++, fr++ )
442 template<
class C,
class T>
inline
446 for ( er = rlast - st ; er != r; er -= st )
447 for ( p = r; p != er; p += st )
448 *p = (a**p+b**(p+st));
453 template<
class C,
class T>
inline
459 const int *sstr = env.
str ();
461 for (
C * es = s; es != s + sstr[-1]; es += sstr[v-1] )
462 for (
C * fs = es; fs != es + sstr[v]; fs ++ )
469 template<
class C,
class T>
inline
478 const int *sstr = env.
str ();
480 for (
C * es = s; es != s + sstr[-1]; es += sstr[v-1] )
481 for (
C * fs = es; fs != es + sstr[v]; fs ++ )
488 template<
class C,
class eenv,
class T >
inline
491 brestrictLR ( src, env, v, T(1-a), a, T((b-a)/(T(1)-a)), T((T(1)-b)/(T(1)-a)) );
498 const int ssz = a.
sz ();
500 const int * sstr = a.
str();
502 C * ed;
const C * es;
504 for ( ed = dst, es = src; es < src+ssz; es += sstr[v-1] )
505 for ( fs = es; fs < es + sstr[v]; *ed++ = *fs++ ) ;
511 const int ssz = a.
sz ();
513 const int * sstr = a.
str();
515 C * ed;
const C * es;
517 es = src + sstr[v-1]-sstr[v];
518 for ( ed = dst; es < src+ssz; es += sstr[v-1] )
520 for ( fs = es; fs < es + sstr[v]; *ed++ = *fs++ ) ;
527 const int ssz = a.
sz ();
528 const int * sstr = a.
str();
530 C * ed;
const C * es;
532 es = src + sstr[v-1]-sstr[v];
533 for ( ed = dst; es < src+ssz; es += sstr[v-1] )
536 for ( fs = es; fs < es + sstr[v]; *ed++ = *fs++ ) ;
540 template<
class C,
class X,
class O,
class eenv >
541 void mpolfill(
C * data,
const sparse::monomial_seq<X,O>& mpol,
const eenv& env )
543 const int *vr = env.
vrs ();
544 const int *st = env.
str ();
545 const int nvr = env.
nvr();
546 typename sparse::monomial_seq<X,O>::const_iterator it;
548 for (it =mpol.begin (); it != mpol.end (); it++)
551 for (
int v = 0; v < nvr; a += (*it)[vr[v]] * st[v], v++) ;
void inverses(A *a, A *ea)
Definition: tensor_vctops.hpp:476
void hevalm(R &result, const C *data, const eenv &env, const P &p)
Definition: tensor_eenv_loops.hpp:45
void hhorner(O &o, C const *const c, unsigned n, const I &i, const I &i0, int s=1)
Definition: tensor_vctops.hpp:436
void brestrictRL(C *s, const eenv &env, int v, const T &a, const T &b, const T &c, const T &d)
Definition: tensor_eenv_loops.hpp:470
void bsplit2(C *l, C *r, const eenv &env, int v)
Definition: tensor_eenv_loops.hpp:428
void bsplit(C *l, C *r, const eenv &env, const T &t, int v)
Definition: tensor_eenv_loops.hpp:399
void uscale(bernstein< C > &mpl)
Definition: tensor_bernstein_fcts.hpp:20
const C & b
Definition: Interval_glue.hpp:25
int * szs()
Definition: tensor_eenv_fcts.hpp:12
MP swap(const MP &P, int var_i, int var_j)
Definition: sparse_monomials.hpp:988
void m_diff(C *op, const eenv &o, C const *ap, const eenv &a, int v)
Definition: tensor_eenv_loops.hpp:338
void ibinoms(C *data, const eenv &env, binomials< C > &binms)
Definition: tensor_eenv_loops.hpp:195
void copy(A *a, const B *b, unsigned n)
Definition: tensor_vctops.hpp:140
int * vrs()
Definition: tensor_eenv_fcts.hpp:18
void vswap(C *data, const eenv &env, int *perm, int *supp=0, int nsupp=0)
Definition: tensor_eenv_loops.hpp:142
int * str()
Definition: tensor_eenv_fcts.hpp:21
void slice(C *dst, const eenv &a, const C *src, int v, int n)
Definition: tensor_eenv_loops.hpp:525
Definition: tensor_eenv.hpp:9
void mdiff(C *dst, const eenv &a, C const *const src, const eenv &esrc, int v)
Definition: tensor_eenv_loops.hpp:348
tensor::eenv eenv
Definition: tensor_convert.hpp:12
int nvr() const
number of variables
Definition: tensor_eenv_fcts.hpp:9
TMPL void copy(Polynomial &r, const Polynomial &a)
Copy of a in r.
Definition: sparse_monomials.hpp:613
void pmul(A *a, const B *b, int sz, int sta=1, int stb=1)
Definition: tensor_vctops.hpp:38
void brestrict(C *src, const eenv &env, int v, const T &a, const T &b)
Definition: tensor_eenv_loops.hpp:489
void binoms(bernstein< C > &mpl)
Definition: tensor_bernstein_fcts.hpp:9
Definition: polynomial.hpp:37
int sz() const
return the total number of coefficients of the dense representation
Definition: tensor_eenv_fcts.hpp:16
void bsplit_uloop(C *r, C *rlast, C *l, const T &t, int st)
Definition: tensor_eenv_loops.hpp:386
void maxs(OutputIterator _maxs_, const C *data, const eenv &env, int v)
Definition: tensor_eenv_loops.hpp:106
void levalm(R &result, const C *data, const eenv &env, const P &p)
Definition: tensor_eenv_loops.hpp:20
TMPL Polynomial diff(const Polynomial &p, int v)
Definition: tensor_bernstein.hpp:79
void decasteljau(real_t *r, unsigned sz, const value_t &t, int str=1)
Definition: tensor_eenv_loops.hpp:70
Definition: binomials.hpp:68
void mpolfill(C *data, const sparse::monomial_seq< X, O > &mpol, const eenv &env)
Definition: tensor_eenv_loops.hpp:541
const C & c
Definition: Interval_glue.hpp:45
double C
Definition: solver_mv_fatarcs.cpp:16
void convertm2b(bernstein< C > &mpl)
Definition: tensor_bernstein_fcts.hpp:31
void pdiv(A *a, const B *b, unsigned sz, int sta=1, int stb=1)
Definition: tensor_vctops.hpp:50
int st(int v) const
return the stride for variable v
Definition: tensor_eenv_fcts.hpp:24
void brestrict_uloop(C *r, C *rlast, int st, const T &a, const T &b)
Definition: tensor_eenv_loops.hpp:443
void lface(bernstein< C > &f, const bernstein< C > &src, int v)
Definition: tensor_bernstein_fcts.hpp:354
void bsplit2_uloop(C *r, C *rlast, C *l, int st)
Definition: tensor_eenv_loops.hpp:415
void assign(A &a, const B &b)
Generic definition of the assignement function.
Definition: assign.hpp:97
void convertb2m(monomials< C > &mpl)
Definition: tensor_bernstein_fcts.hpp:26
void levalb(R &result, const C *data, const eenv &env, const P &p)
Definition: tensor_eenv_loops.hpp:80
void scale(bernstein< C > &mpl)
Definition: tensor_bernstein_fcts.hpp:14
void horner(O &o, C const *const c, unsigned n, const I &i, int s=1)
Definition: tensor_vctops.hpp:420
void rface(bernstein< C > &f, const bernstein< C > &src, int v)
Definition: tensor_bernstein_fcts.hpp:361
void scmul(A *a, const B &b, unsigned n, int s=1)
Definition: tensor_vctops.hpp:98
void mins(OutputIterator _mins_, const C *data, const eenv &env, int v)
Definition: tensor_eenv_loops.hpp:123
void brestrictLR(C *s, const eenv &env, int v, const T &a, const T &b, const T &c, const T &d)
Definition: tensor_eenv_loops.hpp:454
#define assert(expr, msg)
Definition: shared_object.hpp:57