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