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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations