42 Expression * Logarithm::simpleShallowReduce(Context & context, AngleUnit angleUnit) {
69 Expression * Logarithm::shallowReduce(Context& context, AngleUnit angleUnit) {
70 Expression * e = Expression::shallowReduce(context, angleUnit);
75 #if MATRIX_EXACT_REDUCING 77 return SimplificationEngine::map(
this, context, angleUnit);
83 Expression * f = simpleShallowReduce(context, angleUnit);
90 bool letLogAtRoot = parentIsAPowerOfSameBase();
98 Expression * newLog = shallowReduce(context, angleUnit);
99 newLog = newLog->replaceWith(
new Multiplication(y, newLog->clone(),
false),
true);
100 return newLog->shallowReduce(context, angleUnit);
105 for (
int i = 0; i<op->numberOfOperands()-1; i++) {
110 newLog->replaceOperand(newLog->editableOperand(0), factor,
true);
111 a->addOperand(newLog);
112 newLog->shallowReduce(context, angleUnit);
115 if (a->numberOfOperands() > 0) {
116 op->shallowReduce(context, angleUnit);
117 Expression * reducedLastLog = shallowReduce(context, angleUnit);
118 reducedLastLog->replaceWith(a,
false);
119 a->addOperand(reducedLastLog);
120 return a->shallowReduce(context, angleUnit);
128 Expression * n = splitInteger(r->numerator(),
false, context, angleUnit);
129 Expression * d = splitInteger(r->denominator(),
true, context, angleUnit);
132 return a->shallowReduce(context, angleUnit);
137 bool Logarithm::parentIsAPowerOfSameBase()
const {
140 bool thisIsPowerExponent = parentExpression->type() ==
Type::Power ? parentExpression->operand(1) == this :
false;
142 const Expression * parentParentExpression = parentExpression->parent();
143 if (parentExpression ==
nullptr) {
146 thisIsPowerExponent = parentParentExpression->type() ==
Type::Power ? parentParentExpression->operand(1) == parentExpression :
false;
147 parentExpression = parentParentExpression;
149 if (thisIsPowerExponent) {
150 const Expression * powerOperand0 = parentExpression->operand(0);
157 if (powerOperand0->isIdenticalTo(
operand(1))){
165 Expression * Logarithm::splitInteger(Integer i,
bool isDenominator, Context & context, AngleUnit angleUnit) {
175 if (coefficients[0].isMinusOne()) {
179 e->replaceOperand(e->operand(0),
new Rational(i),
true);
180 if (!isDenominator) {
190 coefficients[index].setNegative(
true);
193 e->replaceOperand(e->operand(0),
new Rational(factors[index]),
true);
195 static_cast<Logarithm *
>(e)->simpleShallowReduce(context, angleUnit);
197 m->shallowReduce(context, angleUnit);
203 Expression * Logarithm::shallowBeautify(Context & context, AngleUnit angleUnit) {
216 Expression * Logarithm::templatedApproximate(Context& context, AngleUnit angleUnit)
const {
224 Complex<T> * xc =
static_cast<Complex<T> *
>(x);
225 Complex<T> * nc =
static_cast<Complex<T> *
>(n);
226 result = Division::compute<T>(computeOnComplex(*xc, angleUnit), computeOnComplex(*nc, angleUnit));
230 return new Complex<T>(result);
233 ExpressionLayout * Logarithm::privateCreateLayout(
PrintFloat::Mode floatDisplayMode, ComplexFormat complexFormat)
const {
239 ExpressionLayout * childrenLayouts[2];
241 childrenLayouts[1] =
new ParenthesisLayout(
operand(0)->
createLayout(floatDisplayMode, complexFormat));
242 return new HorizontalLayout(childrenLayouts, 2);
Expression * parent() const
Expression * replaceWith(Expression *newOperand, bool deleteAfterReplace=true)
Expression * approximate(Context &context, AngleUnit angleUnit=AngleUnit::Default) const
const Expression *const * operands() const override
Type type() const override
Expression * editableOperand(int i)
size_t strlen(const char *s)
friend class NaperianLogarithm
bool isIdenticalTo(const Expression *e) const
static void PrimeFactorization(const Integer *i, Integer *outputFactors, Integer *outputCoefficients, int outputLength)
friend class Multiplication
static constexpr int k_maxNumberOfPrimeFactors
static ExpressionLayout * createPrefixLayout(const Expression *expression, PrintFloat::Mode floatDisplayMode, Expression::ComplexFormat complexFormat, const char *operatorName)
ExpressionLayout * createLayout(PrintFloat::Mode floatDisplayMode=PrintFloat::Mode::Default, ComplexFormat complexFormat=ComplexFormat::Default) const
static Complex< T > Float(T x)
Expression * clone() const override
virtual Sign sign() const
void detachOperand(const Expression *e)
const Expression * operand(int i) const
virtual Type type() const =0
int numberOfOperands() const override
void replaceOperand(const Expression *oldOperand, Expression *newOperand, bool deleteOldOperand=true)
static Expression * map(const Expression *expression, Context &context, Expression::AngleUnit angleUnit, ComplexCompute< T > compute)