Add comments to incorrect rules and partially fix ExpandRule1
This commit is contained in:
parent
df5de92931
commit
6b814b84b6
@ -50,33 +50,33 @@ public class ExpandRule1 implements Rule {
|
||||
if (fnc.getParameter1().equals(new Number(fnc.getMathContext(), -1))) {
|
||||
final Function expr = fnc.getParameter2();
|
||||
if (expr instanceof Sum)
|
||||
isExecutable = true;
|
||||
isExecutable = true; // -1 * (a + b)
|
||||
else if (expr instanceof Subtraction)
|
||||
isExecutable = true;
|
||||
isExecutable = true; // -1 * (a - b)
|
||||
else if (expr instanceof SumSubtraction)
|
||||
isExecutable = true;
|
||||
isExecutable = true; // -1 * (a +- b)
|
||||
}
|
||||
} else if (f instanceof Subtraction || f instanceof SumSubtraction) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
final Function expr = fnc.getParameter2();
|
||||
if (expr instanceof Sum)
|
||||
isExecutable = true;
|
||||
isExecutable = true; // x [- +-] (a + b)
|
||||
else if (expr instanceof Subtraction)
|
||||
isExecutable = true;
|
||||
isExecutable = true; // x [- +-] (a - b)
|
||||
else if (expr instanceof SumSubtraction)
|
||||
isExecutable = true;
|
||||
isExecutable = true; // x [- +-] (a +- b)
|
||||
}
|
||||
if (isExecutable) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final MathContext root = f.getMathContext();
|
||||
|
||||
Function expr = null;
|
||||
int fromSubtraction = 0;
|
||||
Function expr = null; // f.getParameter1() [* - +-] expr
|
||||
int fromSubtraction = 0; // 0: (*), 1: (-), 2: (+-)
|
||||
FunctionOperator subtraction = null;
|
||||
if (f instanceof Multiplication)
|
||||
expr = ((Multiplication) f).getParameter2();
|
||||
else if (f instanceof Subtraction || f instanceof SumSubtraction) {
|
||||
expr = ((Multiplication) f).getParameter2();
|
||||
expr = ((FunctionOperator) f).getParameter2();
|
||||
if (f instanceof Subtraction)
|
||||
fromSubtraction = 1;
|
||||
else
|
||||
@ -93,31 +93,37 @@ public class ExpandRule1 implements Rule {
|
||||
final Function b = ((Sum) fnc).getParameter2();
|
||||
final Function fnc2 = new Subtraction(root, new Multiplication(root, new Number(root, -1), a), b);
|
||||
if (fromSubtraction > 0) {
|
||||
subtraction = new Subtraction(root, ((FunctionOperator) f).getParameter1(), fnc2);
|
||||
result.add(subtraction);
|
||||
// FIXME SumSubtraction treated as just Subtraction
|
||||
subtraction = new Sum(root, ((FunctionOperator) f).getParameter1(), fnc2);
|
||||
result.add(subtraction); // x [- +-] (a + b) -> x + (-1*a - b)
|
||||
} else
|
||||
result.add(fnc2);
|
||||
result.add(fnc2); // -1 * (a + b) -> -1*a - b
|
||||
} else if (fnc instanceof Subtraction) {
|
||||
final Function a = ((Subtraction) fnc).getParameter1();
|
||||
final Function b = ((Subtraction) fnc).getParameter2();
|
||||
final Function fnc2 = new Sum(root, new Multiplication(root, new Number(root, -1), a), b);
|
||||
if (fromSubtraction > 0) {
|
||||
subtraction = new Subtraction(root, ((FunctionOperator) f).getParameter1(), fnc2);
|
||||
result.add(subtraction);
|
||||
// FIXME SumSubtraction treated as just Subtraction
|
||||
subtraction = new Sum(root, ((FunctionOperator) f).getParameter1(), fnc2);
|
||||
result.add(subtraction); // x [- +-] (a - b) -> x + (-1*a + b)
|
||||
} else
|
||||
result.add(fnc2);
|
||||
} else if (fnc instanceof SumSubtraction) {
|
||||
result.add(fnc2); // -1 * (a - b) -> -1*a + b
|
||||
} else if (fnc instanceof SumSubtraction) { // FIXME Subtraction and SumSubtraction confusion
|
||||
final Function a = ((SumSubtraction) fnc).getParameter1();
|
||||
final Function b = ((SumSubtraction) fnc).getParameter2();
|
||||
final Function fnc2 = new Sum(root, new Multiplication(root, new Number(root, -1), a), b);
|
||||
final Function fnc3 = new Subtraction(root, new Multiplication(root, new Number(root, -1), a), b);
|
||||
final Function fnc2 = new Sum(root, new Multiplication(root, new Number(root, -1), a), b); // -1*a + b
|
||||
final Function fnc3 = new Subtraction(root, new Multiplication(root, new Number(root, -1), a), b); // -1*a - b
|
||||
if (fromSubtraction > 0) {
|
||||
// x [- +-] (a +- b) -> [x +- (-1*a + b), x +- (-1*a - b), x +- (-1*a - b)]
|
||||
subtraction = new SumSubtraction(root, ((FunctionOperator) f).getParameter1(), fnc2);
|
||||
result.add(subtraction);
|
||||
subtraction = new SumSubtraction(root, ((FunctionOperator) f).getParameter1(), fnc3);
|
||||
// FIXME same result twice
|
||||
result.add(subtraction);
|
||||
result.add(subtraction);
|
||||
} else {
|
||||
// -1 * (a +- b) -> [-1*a + b, -1*a + b]
|
||||
// FIXME same result twice
|
||||
result.add(fnc2);
|
||||
result.add(fnc2);
|
||||
}
|
||||
|
@ -41,12 +41,12 @@ public class ExponentRule17 implements Rule {
|
||||
*/
|
||||
|
||||
@Override
|
||||
public ObjectArrayList<Function> execute(final Function f) {
|
||||
public ObjectArrayList<Function> execute(final Function f) { // FIXME incorrect rule
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Root) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter1().equals(fnc.getParameter2()))
|
||||
isExecutable = true;
|
||||
isExecutable = true; // root(a, a)
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
@ -57,7 +57,7 @@ public class ExponentRule17 implements Rule {
|
||||
final Function two = new Number(root, 2);
|
||||
final Function p = new Power(root, a, two);
|
||||
result.add(p);
|
||||
return result;
|
||||
return result; // root(a, a) -> a^2
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user