1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | |
---|
3 | |
---|
4 | #include "config.h" |
---|
5 | |
---|
6 | |
---|
7 | #include "cf_assert.h" |
---|
8 | |
---|
9 | #include "cf_defs.h" |
---|
10 | #include "cf_eval.h" |
---|
11 | |
---|
12 | static CanonicalForm evalCF ( const CanonicalForm & f, const CFArray & a, int m, int n ); |
---|
13 | |
---|
14 | |
---|
15 | Evaluation& Evaluation::operator= ( const Evaluation & e ) |
---|
16 | { |
---|
17 | if ( this != &e ) { |
---|
18 | values = e.values; |
---|
19 | } |
---|
20 | return *this; |
---|
21 | } |
---|
22 | |
---|
23 | CanonicalForm |
---|
24 | Evaluation::operator() ( const CanonicalForm & f ) const |
---|
25 | { |
---|
26 | if ( f.inCoeffDomain() || f.level() < values.min() ) |
---|
27 | return f; |
---|
28 | else if ( f.level() < values.max() ) |
---|
29 | return evalCF( f, values, values.min(), f.level() ); |
---|
30 | else |
---|
31 | return evalCF( f, values, values.min(), values.max() ); |
---|
32 | } |
---|
33 | |
---|
34 | CanonicalForm |
---|
35 | Evaluation::operator() ( const CanonicalForm & f, int i, int j ) const |
---|
36 | { |
---|
37 | if ( i > j ) |
---|
38 | return f; |
---|
39 | return evalCF( f, values, i, j ); |
---|
40 | } |
---|
41 | |
---|
42 | void |
---|
43 | Evaluation::nextpoint() |
---|
44 | { |
---|
45 | int n = values.max(); |
---|
46 | for ( int i = values.min(); i <= n; i++ ) |
---|
47 | values[i] += 1; |
---|
48 | } |
---|
49 | |
---|
50 | void |
---|
51 | Evaluation::setValue(int i, const CanonicalForm& f) |
---|
52 | { |
---|
53 | if (i < values.min() || i > values.max()) |
---|
54 | return; |
---|
55 | values[i]= f; |
---|
56 | } |
---|
57 | |
---|
58 | #ifndef NOSTREAMIO |
---|
59 | OSTREAM& |
---|
60 | operator<< ( OSTREAM& s, const Evaluation &e ) |
---|
61 | { |
---|
62 | e.values.print(s); |
---|
63 | return s; |
---|
64 | } |
---|
65 | #endif /* NOSTREAMIO */ |
---|
66 | |
---|
67 | CanonicalForm |
---|
68 | evalCF ( const CanonicalForm & f, const CFArray & a, int m, int n ) |
---|
69 | { |
---|
70 | if ( m > n ) |
---|
71 | return f; |
---|
72 | else { |
---|
73 | CanonicalForm result = f; |
---|
74 | while ( n >= m ) { |
---|
75 | result = result( a[n], Variable( n ) ); |
---|
76 | n--; |
---|
77 | } |
---|
78 | return result; |
---|
79 | } |
---|
80 | // iterated method turned out to be faster than |
---|
81 | // return evalCF( f( a[n], Variable( n ) ), a, m, n-1 ); |
---|
82 | } |
---|