Search in sources :

Example 1 with OpenIntToIExprHashMap

use of org.matheclipse.core.eval.util.OpenIntToIExprHashMap in project symja_android_library by axkr.

the class Arithmetic method rationalPower.

/**
 * (p1Numer/p1Denom)^(p1Exp)
 *
 * @return {@link F#NIL} if evaluation wasn't possible
 */
public static IExpr rationalPower(IInteger p1Numer, IInteger p1Denom, IRational p1Exp) {
    boolean[] evaled = new boolean[] { false };
    OpenIntToIExprHashMap<IExpr> fn1Map = new OpenIntToIExprHashMap<IExpr>();
    IInteger fn1Rest = Primality.countPrimes1021(p1Numer, p1Exp, fn1Map, true, evaled);
    IInteger fd1Rest = Primality.countPrimes1021(p1Denom, p1Exp.negate(), fn1Map, true, evaled);
    if (evaled[0]) {
        IASTAppendable times1 = F.TimesAlloc(fn1Map.size() + 4);
        if (!fn1Rest.isOne()) {
            times1.append(F.Power(fn1Rest, p1Exp));
        }
        if (!fd1Rest.isOne()) {
            times1.append(F.Power(fd1Rest, p1Exp.negate()));
        }
        OpenIntToIExprHashMap<IExpr>.Iterator iter = fn1Map.iterator();
        while (iter.hasNext()) {
            iter.advance();
            int base = iter.key();
            IExpr exponent = iter.value();
            if (base != 1) {
                times1.append(F.Power(F.ZZ(base), exponent));
            }
        }
        return times1;
    }
    return F.NIL;
}
Also used : OpenIntToIExprHashMap(org.matheclipse.core.eval.util.OpenIntToIExprHashMap) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IInteger(org.matheclipse.core.interfaces.IInteger) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 2 with OpenIntToIExprHashMap

use of org.matheclipse.core.eval.util.OpenIntToIExprHashMap in project symja_android_library by axkr.

the class Arithmetic method timesPowerPower.

/**
 * (p1Numer/p1Denom)^(p1Exp) * (p2Numer1/p2Denom1)^(p2Exp)
 *
 * @return {@link F#NIL} if evaluation wasn't possible
 */
private static IExpr timesPowerPower(IInteger p1Numer, IInteger p1Denom, IExpr p1Exp, IInteger p2Numer, IInteger p2Denom, IExpr p2Exp, boolean setEvaled) {
    boolean[] evaled = new boolean[] { false };
    OpenIntToIExprHashMap<IExpr> fn1Map = new OpenIntToIExprHashMap<IExpr>();
    IInteger fn1Rest = Primality.countPrimes1021(p1Numer, p1Exp, fn1Map, setEvaled, evaled);
    IInteger fd2Rest = Primality.countPrimes1021(p2Denom, p2Exp.negate(), fn1Map, setEvaled, evaled);
    OpenIntToIExprHashMap<IExpr> fn2Map = new OpenIntToIExprHashMap<IExpr>();
    IInteger fn2Rest = Primality.countPrimes1021(p2Numer, p2Exp, fn2Map, setEvaled, evaled);
    IInteger fd1Rest = Primality.countPrimes1021(p1Denom, p1Exp.negate(), fn2Map, setEvaled, evaled);
    if (!evaled[0] && fn2Map.size() > 0) {
        OpenIntToIExprHashMap<IExpr>.Iterator iter = fn2Map.iterator();
        while (iter.hasNext()) {
            iter.advance();
            int base = iter.key();
            IExpr exp1 = fn1Map.get(base);
            if (exp1 != null) {
                if (exp1.isAST()) {
                    evaled[0] = true;
                    break;
                }
                IExpr exp2 = fn2Map.get(base);
                if (exp2.isAST()) {
                    evaled[0] = true;
                    break;
                }
                if ((exp1.isInteger() && exp2.isInteger())) {
                    evaled[0] = true;
                    break;
                }
            }
        }
    }
    if (evaled[0]) {
        if (fn2Map.size() > 0) {
            OpenIntToIExprHashMap<IExpr>.Iterator iter = fn2Map.iterator();
            while (iter.hasNext()) {
                iter.advance();
                int base = iter.key();
                IExpr exponent = iter.value();
                IExpr exp = fn1Map.get(base);
                if (exp == null) {
                    fn1Map.put(base, exponent);
                } else {
                    fn1Map.put(base, exp.add(exponent));
                }
            }
        }
        IASTAppendable times1 = F.TimesAlloc(fn1Map.size() + 4);
        if (!fn1Rest.isOne()) {
            times1.append(F.Power(fn1Rest, p1Exp));
        }
        if (!fd2Rest.isOne()) {
            times1.append(F.Power(fd2Rest, p2Exp.negate()));
        }
        if (!fn2Rest.isOne()) {
            times1.append(F.Power(fn2Rest, p2Exp));
        }
        if (!fd1Rest.isOne()) {
            times1.append(F.Power(fd1Rest, p1Exp.negate()));
        }
        if (fn1Map.size() > 0) {
            OpenIntToIExprHashMap<IExpr>.Iterator iter = fn1Map.iterator();
            while (iter.hasNext()) {
                iter.advance();
                int base = iter.key();
                IExpr exponent = iter.value();
                if (base != 1) {
                    times1.append(F.Power(F.ZZ(base), F.evalExpand(exponent)));
                }
            }
        }
        return times1;
    }
    return F.NIL;
}
Also used : OpenIntToIExprHashMap(org.matheclipse.core.eval.util.OpenIntToIExprHashMap) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IInteger(org.matheclipse.core.interfaces.IInteger) IExpr(org.matheclipse.core.interfaces.IExpr)

Aggregations

OpenIntToIExprHashMap (org.matheclipse.core.eval.util.OpenIntToIExprHashMap)2 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)2 IExpr (org.matheclipse.core.interfaces.IExpr)2 IInteger (org.matheclipse.core.interfaces.IInteger)2