Search in sources :

Example 26 with ISignedNumber

use of org.matheclipse.core.interfaces.ISignedNumber in project symja_android_library by axkr.

the class AbstractAST method toDoubleVector.

/** {@inheritDoc} */
@Override
public double[] toDoubleVector() {
    double[] result = new double[size() - 1];
    ISignedNumber signedNumber;
    for (int i = 1; i < size(); i++) {
        signedNumber = get(i).evalSignedNumber();
        if (signedNumber != null) {
            result[i - 1] = signedNumber.doubleValue();
        } else {
            return null;
        }
    }
    return result;
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber)

Example 27 with ISignedNumber

use of org.matheclipse.core.interfaces.ISignedNumber in project symja_android_library by axkr.

the class AbstractAST method toDoubleMatrix.

/** {@inheritDoc} */
@Override
public double[][] toDoubleMatrix() {
    int[] dim = isMatrix();
    if (dim == null) {
        return null;
    }
    double[][] result = new double[dim[0]][dim[1]];
    ISignedNumber signedNumber;
    for (int i = 1; i <= dim[0]; i++) {
        IAST row = (IAST) get(i);
        for (int j = 1; j <= dim[1]; j++) {
            signedNumber = row.get(j).evalSignedNumber();
            if (signedNumber != null) {
                result[i - 1][j - 1] = signedNumber.doubleValue();
            } else {
                return null;
            }
        }
    }
    return result;
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) IAST(org.matheclipse.core.interfaces.IAST)

Example 28 with ISignedNumber

use of org.matheclipse.core.interfaces.ISignedNumber in project symja_android_library by axkr.

the class Assumptions method isNegative.

@Override
public boolean isNegative(IExpr expr) {
    ISignedNumber num;
    SignedNumberRelations gla = valueMap.get(expr);
    if (gla != null) {
        boolean result = false;
        num = gla.getLess();
        if (num != null) {
            if (!num.isZero()) {
                if (!num.isLessThan(F.C0)) {
                    return false;
                }
            }
            result = true;
        }
        if (!result) {
            num = gla.getLessEqual();
            if (num != null) {
                if (!num.isLessThan(F.C0)) {
                    return false;
                }
                result = true;
            }
        }
        return result;
    }
    return false;
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber)

Example 29 with ISignedNumber

use of org.matheclipse.core.interfaces.ISignedNumber in project symja_android_library by axkr.

the class Assumptions method isNonNegative.

@Override
public boolean isNonNegative(IExpr expr) {
    ISignedNumber num;
    SignedNumberRelations gla = valueMap.get(expr);
    if (gla != null) {
        boolean result = false;
        num = gla.getGreater();
        if (num != null) {
            if (num.isZero()) {
                result = true;
            }
        }
        if (!result) {
            num = gla.getGreaterEqual();
            if (num != null) {
                if (num.isZero()) {
                    result = true;
                }
            }
        }
        if (result) {
            return true;
        }
        return isPositive(expr);
    }
    return false;
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber)

Example 30 with ISignedNumber

use of org.matheclipse.core.interfaces.ISignedNumber in project symja_android_library by axkr.

the class Assumptions method addLessEqual.

private static boolean addLessEqual(IAST lessEqualAST, Assumptions assumptions) {
    if (lessEqualAST.isAST3()) {
        // arg1 <= arg2 <= arg3
        IExpr arg1 = lessEqualAST.arg1();
        IExpr arg2 = lessEqualAST.arg2();
        IExpr arg3 = lessEqualAST.arg3();
        if (arg1.isSignedNumber() && arg3.isSignedNumber() && !arg2.isNumber()) {
            if (!((ISignedNumber) arg1).isGreaterThan(((ISignedNumber) arg3))) {
                ISignedNumber num1 = (ISignedNumber) arg1;
                ISignedNumber num3 = (ISignedNumber) arg3;
                IExpr key = arg2;
                SignedNumberRelations gla = assumptions.valueMap.get(key);
                if (gla == null) {
                    gla = new SignedNumberRelations();
                }
                gla.addGreaterEqual(num1);
                gla.addLessEqual(num3);
                assumptions.valueMap.put(key, gla);
                return true;
            }
        }
        return false;
    }
    // arg1 <= arg2;
    if (lessEqualAST.arg2().isSignedNumber()) {
        SignedNumberRelations gla = assumptions.valueMap.get(lessEqualAST.arg1());
        if (gla == null) {
            gla = new SignedNumberRelations();
        }
        gla.addLessEqual((ISignedNumber) lessEqualAST.arg2());
        assumptions.valueMap.put(lessEqualAST.arg1(), gla);
        return true;
    }
    if (lessEqualAST.arg1().isSignedNumber()) {
        ISignedNumber num = (ISignedNumber) lessEqualAST.arg1();
        IExpr key = lessEqualAST.arg2();
        SignedNumberRelations gla = assumptions.valueMap.get(key);
        if (gla == null) {
            gla = new SignedNumberRelations();
        }
        gla.addGreaterEqual(num);
        assumptions.valueMap.put(key, gla);
        return true;
    }
    return false;
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) IExpr(org.matheclipse.core.interfaces.IExpr)

Aggregations

ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)49 IExpr (org.matheclipse.core.interfaces.IExpr)31 IAST (org.matheclipse.core.interfaces.IAST)22 ISymbol (org.matheclipse.core.interfaces.ISymbol)10 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)7 LinearConstraint (org.hipparchus.optim.linear.LinearConstraint)3 Num (org.matheclipse.core.expression.Num)3 IInteger (org.matheclipse.core.interfaces.IInteger)3 IntegerDistribution (org.hipparchus.distribution.IntegerDistribution)2 RealDistribution (org.hipparchus.distribution.RealDistribution)2 MathIllegalStateException (org.hipparchus.exception.MathIllegalStateException)2 LinearObjectiveFunction (org.hipparchus.optim.linear.LinearObjectiveFunction)2 WrappedException (org.matheclipse.core.eval.exception.WrappedException)2 Options (org.matheclipse.core.eval.util.Options)2 ComplexNum (org.matheclipse.core.expression.ComplexNum)2 IComplex (org.matheclipse.core.interfaces.IComplex)2 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)2 INum (org.matheclipse.core.interfaces.INum)2 IRational (org.matheclipse.core.interfaces.IRational)2 ArrayList (java.util.ArrayList)1