Simplify exp(y + log(x))

Issue #136 resolved
Martin Mauch created an issue

Hi Axel,

I would have expected Symja to be able to simplify an expression like

exp(y + log(x))

to something like

x * exp(y)

but the term is left as it is.

I've tried both the web ui and a Java example like this

new EvalEngine().evaluate(F.Simplify(F.Exp(F.Plus(F.Log(F.x), F.y))))

Is this a simplification that still needs to be implemented, or am I doing something wrong? If the former, I can try to make a pull request if you can give me some pointers on where to start.

Nice holidays!

Comments (6)

  1. Axel Kramer repo owner

    This is a simplification that still needs to be implemented.

    The input

    exp(y + log(x))
    

    will be transformed internally to

    E^(y+Log(x))
    

    which is in FullForm:

    Power(E, Plus(y, Log(x)))
    

    Use commmit 8d7dc24 (org.matheclipse.core.reflection.system.Power.java) as a starting point:to implement your changes:

            if (arg1.isE() && arg2.isPlus()) {
                IAST plus = (IAST)arg2; 
                // simplify E^(y+Log(x)) here
            }
    

    Define a JUnit testcase in LowercaseTestCase.java to test your implementation:

        public void testPower() {
            check("Exp(y + Log(x))", "x+E^y");
        }
    
  2. Martin Mauch reporter

    I've found another case where the simplifications are not used:

    check("E^(2*(y+Log(x)))", "E^(2*y)*x^2");
    

    I could manually check for the exponent including a Times, but I think it would be more appropriate to run the simplifications on a fully expanded / multiplied-out version. Is there a function that I can call to do this?

  3. Axel Kramer repo owner

    In commit 8b71d00 I added F.evalExpand(arg2):

            if (arg1.isE() && (arg2.isPlusTimesPower())) {
                IExpr expandedFunction = F.evalExpand(arg2);
                if (expandedFunction.isPlus()) {
                    return powerEPlus((IAST) expandedFunction);
                }
            }
    
  4. Log in to comment