Skip to content

Commit

Permalink
Fuzz test: fixing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
axkr committed Feb 24, 2020
1 parent 7c39f25 commit 00654cf
Show file tree
Hide file tree
Showing 28 changed files with 25,649 additions and 308 deletions.
25,056 changes: 25,056 additions & 0 deletions symja_android_library/data/harvest.sym

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.matheclipse.core.eval.EvalEngine;
import org.matheclipse.core.eval.exception.ArgumentTypeException;
import org.matheclipse.core.eval.exception.Validate;
import org.matheclipse.core.eval.exception.ValidateException;
import org.matheclipse.core.eval.interfaces.AbstractEvaluator;
import org.matheclipse.core.eval.interfaces.AbstractFunctionEvaluator;
import org.matheclipse.core.eval.util.IntRangeSpec;
Expand Down Expand Up @@ -1503,8 +1504,9 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
}

return result;
} catch (ArgumentTypeException ate) {
// see LevelSpecification
} catch (final ValidateException ve) {
// see level specification
return engine.printMessage(ve.getMessage(ast.topHead()));
}
}
return F.NIL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ public int[] expectedArgSize() {
"sym", "Argument `1` at position `2` is expected to be a symbol.", //
"tag", "Rule for `1` can only be attached to `2`.", //
"take", "Cannot take positions `1` through `2` in `3`.", //
"usraw", "Cannot unset object `1`.", //
"vpow2", "Argument `1` is restricted to vectors with a length of power of 2.", //
"vrule", "Cannot set `1` to `2`, which is not a valid list of replacement rules.", //
"write", "Tag `1` in `2` is Protected.", //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2685,25 +2685,26 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
boolean togetherMode = engine.isTogetherMode();
try {
engine.setTogetherMode(true);
final IAST list = (IAST) ast.arg1();
matrix = Convert.list2Matrix(list);
if (matrix != null) {
final FieldLUDecomposition<IExpr> lu = new FieldLUDecomposition<IExpr>(matrix);
final FieldMatrix<IExpr> lMatrix = lu.getL();
final FieldMatrix<IExpr> uMatrix = lu.getU();
final int[] iArr = lu.getPivot();
// final int permutationCount = lu.getPermutationCount();
int size = iArr.length;
final IASTAppendable iList = F.ListAlloc(size);
// +1 because in Symja the offset is +1 compared to java arrays
iList.appendArgs(0, size, i -> F.ZZ(iArr[i] + 1));
// for (int i = 0; i < size; i++) {
// // +1 because in Symja the offset is +1 compared to java arrays
// iList.append(F.integer(iArr[i] + 1));
// }
return F.List(Convert.matrix2List(lMatrix), Convert.matrix2List(uMatrix), iList);
if (ast.arg1().isList()) {
final IAST list = (IAST) ast.arg1();
matrix = Convert.list2Matrix(list);
if (matrix != null) {
final FieldLUDecomposition<IExpr> lu = new FieldLUDecomposition<IExpr>(matrix);
final FieldMatrix<IExpr> lMatrix = lu.getL();
final FieldMatrix<IExpr> uMatrix = lu.getU();
final int[] iArr = lu.getPivot();
// final int permutationCount = lu.getPermutationCount();
int size = iArr.length;
final IASTAppendable iList = F.ListAlloc(size);
// +1 because in Symja the offset is +1 compared to java arrays
iList.appendArgs(0, size, i -> F.ZZ(iArr[i] + 1));
// for (int i = 0; i < size; i++) {
// // +1 because in Symja the offset is +1 compared to java arrays
// iList.append(F.integer(iArr[i] + 1));
// }
return F.List(Convert.matrix2List(lMatrix), Convert.matrix2List(uMatrix), iList);
}
}

} catch (final ClassCastException e) {
if (Config.SHOW_STACKTRACE) {
e.printStackTrace();
Expand Down Expand Up @@ -2906,56 +2907,59 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
boolean togetherMode = engine.isTogetherMode();
try {
engine.setTogetherMode(true);
matrix = Convert.list2Matrix((IAST) ast.arg1());
if (matrix == null) {
return F.NIL;
}
int p = ast.arg2().toIntDefault(Integer.MIN_VALUE);
if (p == Integer.MIN_VALUE) {
return F.NIL;
}
if (p == 1) {
((IAST) ast.arg1()).addEvalFlags(IAST.IS_MATRIX);
return ast.arg1();
}
if (p == 0) {
resultMatrix = new BlockFieldMatrix<IExpr>(ExprField.CONST, matrix.getRowDimension(),
matrix.getColumnDimension());
int min = matrix.getRowDimension();
if (min > matrix.getColumnDimension()) {
min = matrix.getColumnDimension();
if (ast.arg1().isList()) {
matrix = Convert.list2Matrix((IAST) ast.arg1());
if (matrix == null) {
return F.NIL;
}
int p = ast.arg2().toIntDefault(Integer.MIN_VALUE);
if (p == Integer.MIN_VALUE) {
return F.NIL;
}
for (int i = 0; i < min; i++) {
resultMatrix.setEntry(i, i, F.C1);
if (p == 1) {
((IAST) ast.arg1()).addEvalFlags(IAST.IS_MATRIX);
return ast.arg1();
}
if (p == 0) {
resultMatrix = new BlockFieldMatrix<IExpr>(ExprField.CONST, matrix.getRowDimension(),
matrix.getColumnDimension());
int min = matrix.getRowDimension();
if (min > matrix.getColumnDimension()) {
min = matrix.getColumnDimension();
}
for (int i = 0; i < min; i++) {
resultMatrix.setEntry(i, i, F.C1);
}

return Convert.matrix2List(resultMatrix);
}
if (p < 0) {
resultMatrix = Inverse.inverseMatrix(matrix);
matrix = resultMatrix;
p *= (-1);
} else {
resultMatrix = matrix;
}
for (int i = 1; i < p; i++) {
resultMatrix = resultMatrix.multiply(matrix);
}
return Convert.matrix2List(resultMatrix);
}
if (p < 0) {
resultMatrix = Inverse.inverseMatrix(matrix);
matrix = resultMatrix;
p *= (-1);
} else {
resultMatrix = matrix;
}
for (int i = 1; i < p; i++) {
resultMatrix = resultMatrix.multiply(matrix);
}
return Convert.matrix2List(resultMatrix);

// } catch (final ClassCastException e) {
// if (Config.SHOW_STACKTRACE) {
// e.printStackTrace();
// }
// } catch (final ArithmeticException e) {
// if (Config.SHOW_STACKTRACE) {
// e.printStackTrace();
// }
// throw new NonNegativeIntegerExpected(ast, 2);
// } catch (final IndexOutOfBoundsException e) {
// if (Config.SHOW_STACKTRACE) {
// e.printStackTrace();
// }
// } catch (final ClassCastException e) {
// if (Config.SHOW_STACKTRACE) {
// e.printStackTrace();
// }
// } catch (final ArithmeticException e) {
// if (Config.SHOW_STACKTRACE) {
// e.printStackTrace();
// }
// throw new NonNegativeIntegerExpected(ast, 2);
// } catch (final IndexOutOfBoundsException e) {
// if (Config.SHOW_STACKTRACE) {
// e.printStackTrace();
// }
}
return F.NIL;
} catch (final RuntimeException e) {
if (Config.SHOW_STACKTRACE) {
e.printStackTrace();
Expand Down Expand Up @@ -3299,20 +3303,21 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
boolean togetherMode = engine.isTogetherMode();
try {
engine.setTogetherMode(true);
if (ast.arg1().isList()) {
final IAST list = (IAST) ast.arg1();
matrix = Convert.list2Matrix(list);
if (matrix != null) {
FieldReducedRowEchelonForm fmw = new FieldReducedRowEchelonForm(matrix);
FieldMatrix<IExpr> nullspace = fmw.getNullSpace(F.CN1);
if (nullspace == null) {
return F.List();
}

final IAST list = (IAST) ast.arg1();
matrix = Convert.list2Matrix(list);
if (matrix != null) {
FieldReducedRowEchelonForm fmw = new FieldReducedRowEchelonForm(matrix);
FieldMatrix<IExpr> nullspace = fmw.getNullSpace(F.CN1);
if (nullspace == null) {
return F.List();
IASTMutable list2 = Convert.matrix2List(nullspace);
// rows in descending orders
EvalAttributes.sort(list2, ExprReverseComparator.CONS);
return list2;
}

IASTMutable list2 = Convert.matrix2List(nullspace);
// rows in descending orders
EvalAttributes.sort(list2, ExprReverseComparator.CONS);
return list2;
}
} catch (final ClassCastException e) {
if (Config.SHOW_STACKTRACE) {
Expand Down Expand Up @@ -3651,14 +3656,14 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
boolean togetherMode = engine.isTogetherMode();
try {
engine.setTogetherMode(true);

final IAST list = (IAST) ast.arg1();
matrix = Convert.list2Matrix(list);
if (matrix != null) {
FieldReducedRowEchelonForm fmw = new FieldReducedRowEchelonForm(matrix);
return Convert.matrix2List(fmw.getRowReducedMatrix());
if (ast.arg1().isList()) {
final IAST list = (IAST) ast.arg1();
matrix = Convert.list2Matrix(list);
if (matrix != null) {
FieldReducedRowEchelonForm fmw = new FieldReducedRowEchelonForm(matrix);
return Convert.matrix2List(fmw.getRowReducedMatrix());
}
}

} catch (final ClassCastException e) {
if (Config.SHOW_STACKTRACE) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1127,8 +1127,9 @@ public IExpr evaluate(IAST ast, EvalEngine engine) {
VisitorLevelSpecification level = new VisitorLevelSpecification(crf, arg3, false,
engine);
arg1.accept(level);
} catch (ArgumentTypeException ate) {
return F.NIL;
} catch (final ValidateException ve) {
// see level specification
return engine.printMessage(ve.getMessage(F.Cases));
} catch (StopException se) {
// reached maximum number of results
}
Expand All @@ -1142,8 +1143,9 @@ public IExpr evaluate(IAST ast, EvalEngine engine) {
VisitorLevelSpecification level = new VisitorLevelSpecification(cpmf, arg3, false,
engine);
arg1.accept(level);
} catch (ArgumentTypeException ate) {
return F.NIL;
} catch (final ValidateException ve) {
// see level specification
return engine.printMessage(ve.getMessage(ast.topHead()));
} catch (StopException se) {
// reached maximum number of results
}
Expand Down Expand Up @@ -1629,9 +1631,10 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
}
arg1.accept(level);
return F.ZZ(mf.getCounter());
} catch (ArgumentTypeException ate) {
} catch (final ValidateException ve) {
// see level specification
return engine.printMessage(ve.getMessage(ast.topHead()));
}
return F.NIL;
}

@Override
Expand Down Expand Up @@ -1840,12 +1843,17 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
if (ast.isAST3() || ast.size() == 5) {
final IExpr arg3 = engine.evaluate(ast.arg3());
int maximumRemoveOperations = -1;
if (ast.size() == 5) {
maximumRemoveOperations = Validate.checkIntType(ast, 4);
}
IASTAppendable arg1RemoveClone = ((IAST) arg1).copyAppendable();

try {
if (ast.size() == 5) {
if (ast.arg4().isInfinity()) {
maximumRemoveOperations = Integer.MAX_VALUE;
} else {
maximumRemoveOperations = Validate.checkIntType(ast, 4);
}
}


DeleteCasesPatternMatcherFunctor cpmf = new DeleteCasesPatternMatcherFunctor(matcher);
VisitorRemoveLevelSpecification level = new VisitorRemoveLevelSpecification(cpmf, arg3,
maximumRemoveOperations, false, engine);
Expand All @@ -1856,14 +1864,12 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
return arg1RemoveClone;
} catch (VisitorRemoveLevelSpecification.StopException se) {
// reached maximum number of results
} catch (final ArgumentTypeException ate) {
return F.NIL;
// } catch (final RuntimeException rex) {
// // ArgumentTypeException from VisitorLevelSpecification level specification checks
// return engine.printMessage("DeleteCases: " + rex.getMessage());
} catch (final ValidateException ve) {
// see level specification
return engine.printMessage(ve.getMessage(ast.topHead()));
}

return arg1RemoveClone;
return arg1RemoveClone;
} else {
return deleteCases((IAST) arg1, matcher);
}
Expand Down Expand Up @@ -2150,7 +2156,7 @@ public IExpr evaluate(IAST ast, EvalEngine engine) {
return F.NIL;
}
}
if (indx <= list.size()) {
if (indx < list.size()) {
return list.get(indx);
}
} else if (ast.arg2().isList()) {
Expand Down Expand Up @@ -3102,8 +3108,9 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
return resultList;
}
return F.List();
} catch (ArgumentTypeException ate) {
return F.NIL;
} catch (final ValidateException ve) {
// see level specification
return engine.printMessage(ve.getMessage(ast.topHead()));
}
}

Expand Down Expand Up @@ -3730,8 +3737,9 @@ public IExpr evaluate(IAST ast, EvalEngine engine) {
final IExpr arg3 = engine.evaluate(ast.arg3());
final LevelSpec level = new LevelSpecification(arg3, true);
return position((IAST) arg1, arg2, level, maxResults, engine);
} catch (ArgumentTypeException ate) {
// see LevelSpecification
} catch (final ValidateException ve) {
// see level specification
return engine.printMessage(ve.getMessage(ast.topHead()));
}
}
}
Expand Down Expand Up @@ -5419,7 +5427,13 @@ protected static IExpr evaluateTable(final IAST ast, final IAST resultList, IExp
new TableFunction(engine, ast.arg1()), defaultValue);
return generator.table();
}
} catch (final ArgumentTypeException e) {
} catch (final ArrayIndexOutOfBoundsException e) {
if (Config.SHOW_STACKTRACE) {
e.printStackTrace();
}
} catch (final ValidateException ve) {
// see iterator specification
return engine.printMessage(ve.getMessage(ast.topHead()));
} catch (final NoEvalException e) {
} catch (final ClassCastException e) {
// the iterators are generated only from IASTs
Expand All @@ -5445,7 +5459,9 @@ protected static IExpr evaluateTableThrow(final IAST ast, final IAST resultList,
new TableFunction(engine, ast.arg1()), defaultValue);
return generator.tableThrow();
}
} catch (final ArgumentTypeException e) {
} catch (final ValidateException ve) {
// see iterator specification
return engine.printMessage(ve.getMessage(ast.topHead()));
} catch (final NoEvalException e) {
} catch (final ClassCastException e) {
// the iterators are generated only from IASTs
Expand Down Expand Up @@ -6013,8 +6029,9 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
}
}
}
} catch (ArgumentTypeException ate) {
return F.NIL;
} catch (final ValidateException ve) {
// see level specification
return engine.printMessage(ve.getMessage(ast.topHead()));
// } catch (final RuntimeException rex) {
// // ArgumentTypeException from VisitorLevelSpecification level specification checks
// return engine.printMessage("Total: " + rex.getMessage());
Expand Down
Loading

0 comments on commit 00654cf

Please sign in to comment.