bool Scalar::CollectTerms( SumOfTerms& sumOfTerms ) { SumOfTerms::Node* node = sumOfTerms.Head(); while( node ) { Term* term = node->data; term->CombineFactors(); term->productOfFactors.Sort( Term::ProductOfFactors::SORT_ASCENDING ); node = node->Next(); } SumOfTerms::Node* nodeA = sumOfTerms.Head(); while( nodeA ) { Term* termA = nodeA->data; SumOfTerms::Node* nodeB = nodeA->Next(); while( nodeB ) { Term* termB = nodeB->data; SumOfTerms::Node* nextNodeB = nodeB->Next(); if( termA->CombineWith( termB, false, false ) ) sumOfTerms.Remove( nodeB ); nodeB = nextNodeB; } } nodeA = sumOfTerms.Head(); while( nodeA ) { Term* termA = nodeA->data; SumOfTerms::Node* nextNodeA = nodeA->Next(); if( termA->IsZero() ) sumOfTerms.Remove( nodeA ); nodeA = nextNodeA; } return true; }
bool Scalar::Scale( double number ) { if( IsZero() ) return true; for( SumOfTerms::Node* node = sumOfTermsNumerator.Head(); node; node = node->Next() ) { Term* term = node->data; if( term->IsZero() ) continue; NumericalFactor* numericalFactor = ( NumericalFactor* )term->FindTermOfFactorType( Factor::NUMERICAL ); if( !numericalFactor ) { numericalFactor = new NumericalFactor( 1.0 ); term->productOfFactors.InsertBefore()->data = numericalFactor; } numericalFactor->number *= number; } return true; }