// Note that we accumulate into this multivector and fail unless every term of the given multivector is a geometric product. // Every accumulated term will be a geometric product. bool Multivector::GeometricProductMultiply( const Vector& vectorA, const Multivector& multivectorB ) { for( const SumOfTerms::Node* node = multivectorB.sumOfTerms.Head(); node; node = node->Next() ) { const Term* term = node->data; if( term->productType != Term::GEOMETRIC_PRODUCT ) return false; Term* newTerm = term->Clone(); newTerm->productOfVectors.InsertBefore()->data = vectorA.Clone(); } return false; }
bool Multivector::Term::InnerProductMultiply( const Vector& vector, Multivector& multivector, bool vectorRight ) const { if( productType != OUTER_PRODUCT ) return false; if( productOfVectors.Count() == 0 ) { Term* newTerm = new Term( OUTER_PRODUCT ); newTerm->coeficient->Assign( *coeficient ); newTerm->productOfVectors.InsertAfter()->data = vector.Clone(); multivector.sumOfTerms.InsertAfter()->data = newTerm; return true; } bool negateNewTerms = false; if( vectorRight && productOfVectors.Count() % 2 == 0 ) negateNewTerms = true; ProductOfVectors::Node* node = const_cast< ProductOfVectors* >( &productOfVectors )->Head(); do { ProductOfVectors::Node* nextNode = node->Next(); const_cast< ProductOfVectors* >( &productOfVectors )->Remove( node ); Term* newTerm = Clone(); multivector.sumOfTerms.InsertAfter()->data = newTerm; Scalar* innerProductScalar = theBilinearForm->InnerProduct( vector.name, node->data->name ); if( !newTerm->coeficient->AssignProduct( *newTerm->coeficient, *innerProductScalar ) ) return false; if( negateNewTerms ) newTerm->coeficient->Negate(); if( nextNode ) const_cast< ProductOfVectors* >( &productOfVectors )->InsertBefore( nextNode, node ); else const_cast< ProductOfVectors* >( &productOfVectors )->InsertAfter( 0, node ); node = nextNode; } while( node ); return true; }
// Note that we accumulate into this multivector and fail unless every term of the given multivector is an outer product. // Every accumulated term will be an outer product. bool Multivector::OuterProductMultiply( const Vector& vectorA, const Multivector& multivectorB ) { for( const SumOfTerms::Node* node = multivectorB.sumOfTerms.Head(); node; node = node->Next() ) { const Term* term = node->data; if( term->productType != Term::OUTER_PRODUCT ) return false; if( term->FindVectorWithName( vectorA.name ) ) continue; Term* newTerm = term->Clone(); newTerm->productOfVectors.InsertBefore()->data = vectorA.Clone(); } return true; }