//========================================================================================= /*virtual*/ Evaluator* Environment::CreateBinaryOperator( const char* operatorName, Evaluator* leftOperand, Evaluator* rightOperand, bool& isBinaryOperationEvaluator ) { // Here we implement exponentiation in terms of Tayler series. // This works for any type of number, because the Tyler series // function only uses the arithmetic operations of the number interface. // We re-write x^y as exp(y*ln x). The Tayler series are centered at zero. // If the user does not want it centered at zero, they must call the // Tyler series functions themselves. Environment derivatives, of course, // can override this function to give the "^" operator a different meaning. if( 0 == strcmp( operatorName, "^" ) ) { Number* zero = CreateNumber(); zero->AssignAdditiveIdentity( *this ); FunctionArgumentEvaluator* argumentEvaluator = new FunctionArgumentEvaluator(); argumentEvaluator->Argument( leftOperand ); TaylorSeriesFunctionEvaluator* lnEvaluator = new TaylorSeriesFunctionEvaluator(); lnEvaluator->Center( zero, *this ); lnEvaluator->TaylorSeries( TaylorSeriesFunctionEvaluator::TAYLOR_SERIES_LN ); lnEvaluator->AddArgument( argumentEvaluator, FunctionEvaluator::APPEND_TO_LIST_OF_ARGS ); BinaryArithmeticOperationEvaluator* mulEvaluator = new BinaryArithmeticOperationEvaluator( BinaryArithmeticOperationEvaluator::ARITHMETIC_OPERATION_MULTIPLY ); mulEvaluator->LeftOperand( rightOperand ); mulEvaluator->RightOperand( lnEvaluator ); argumentEvaluator = new FunctionArgumentEvaluator(); argumentEvaluator->Argument( mulEvaluator ); TaylorSeriesFunctionEvaluator* expEvaluator = new TaylorSeriesFunctionEvaluator(); expEvaluator->Center( zero, *this ); expEvaluator->TaylorSeries( TaylorSeriesFunctionEvaluator::TAYLOR_SERIES_EXP ); expEvaluator->AddArgument( argumentEvaluator, FunctionEvaluator::APPEND_TO_LIST_OF_ARGS ); // We're not actually returning a binary operation evaluator. isBinaryOperationEvaluator = false; delete zero; return expEvaluator; } return 0; }
//========================================================================================= /*virtual*/ bool EnvironmentInformationFunctionEvaluator::EvaluateResult( Number& result, Environment& environment ) { result.AssignAdditiveIdentity( environment ); environment.PrintEnvironmentInfo(); return true; }