Operator* Power::Simplified( Context* nctx, TypeCorrespondanceTable& table ) { Operator* sf = mySubOps[0]->Simplified(nctx, table); Operator* ss = mySubOps[1]->Simplified(nctx, table); if( sf->IsConstant() && ss->IsConstant() ) { Constant* csf = reinterpret_cast<Constant*>(sf); Constant* css = reinterpret_cast<Constant*>(ss); return new Constant( nctx, std::pow(csf->GetValue(), css->GetValue() ) ); } else if( ss->IsNull() ) return new Constant( nctx, 1.0 ); else if( ss->IsOne() ) return sf; else return new Power( nctx, sf, ss ); }
Operator* Division::Simplified( Context* nctx, TypeCorrespondanceTable& table ) { Operator* fp = mySubOps[0]->Simplified(nctx, table); Operator* fs = mySubOps[1]->Simplified(nctx, table); if( fp->IsNull() ) return new Constant( nctx, 0.0, table[GetType()] ); else if( fp->IsOne() ) return new Inverse( nctx, fs ); else if( fp->IsConstant() && fs->IsConstant() ) { Constant* cfp = reinterpret_cast<Constant*>(fp); Constant* cfs = reinterpret_cast<Constant*>(fs); return new Constant( nctx, cfp->GetValue() / cfs->GetValue(), table[GetType()] ); } else return new Division( nctx, fp, fs ); }
Operator* Substraction::Simplified( Context* nctx, TypeCorrespondanceTable& table ) { Operator* sf = mySubOps[0]->Simplified(nctx, table); Operator* ss = mySubOps[1]->Simplified(nctx, table); if( sf->IsConstant() && ss->IsConstant() ) { Constant* csf = reinterpret_cast<Constant*>(sf); Constant* css = reinterpret_cast<Constant*>(ss); double v = csf->GetValue() - css->GetValue(); return new Constant( nctx, v ); } else if( sf->IsNull() ) return new Negate( nctx, ss ); else if( ss->IsNull() ) return sf; else return new Substraction( nctx, sf, ss ); }