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