Finished rewriting calculus engine.
Finished rewriting calculus engine and affected classes: functions and rules.
This commit is contained in:
parent
36de6ab02a
commit
50e6837eda
28
src/org/warp/picalculator/TestCalcBenchmark.java
Normal file
28
src/org/warp/picalculator/TestCalcBenchmark.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package org.warp.picalculator;
|
||||||
|
|
||||||
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
|
|
||||||
|
public class TestCalcBenchmark {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Error {
|
||||||
|
Utils.debugOn = true;
|
||||||
|
int times = 1;
|
||||||
|
|
||||||
|
MathContext mc = new MathContext();
|
||||||
|
long time1 = System.nanoTime();
|
||||||
|
mc.parseInputString("5WABCDEFGHIWABCDEFGHIWABCDEFGHIWABCDEFGHIWABCDEFGHIWABCDEFGHI");
|
||||||
|
long time2 = System.nanoTime();
|
||||||
|
for (int i = 0; i < times; i++) {
|
||||||
|
if (i == 1) {
|
||||||
|
Utils.debugOn = false;
|
||||||
|
}
|
||||||
|
mc.f2 = mc.solveExpression(mc.f);
|
||||||
|
}
|
||||||
|
long time3 = System.nanoTime();
|
||||||
|
// System.out.println(mc.f2.get(0).toString());
|
||||||
|
System.out.println("PARSING\t"+((time2-time1) / 1000000d / ((double) times)) + " milliseconds");
|
||||||
|
System.out.println("WORK\t"+((time3-time2) / 1000000d / ((double) times)) + " milliseconds");
|
||||||
|
System.out.println("TOTAL\t"+((time3-time1) / 1000000d / ((double) times)) + " milliseconds");
|
||||||
|
}
|
||||||
|
}
|
@ -22,11 +22,11 @@ import org.nevec.rjm.BigDecimalMath;
|
|||||||
import org.nevec.rjm.Rational;
|
import org.nevec.rjm.Rational;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionSingle;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.functions.Division;
|
import org.warp.picalculator.math.functions.Division;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Negative;
|
import org.warp.picalculator.math.functions.Negative;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
@ -127,12 +127,12 @@ public class Utils {
|
|||||||
public static boolean areThereOnlySettedUpFunctionsSumsEquationsAndSystems(ArrayList<Function> fl) {
|
public static boolean areThereOnlySettedUpFunctionsSumsEquationsAndSystems(ArrayList<Function> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
||||||
if (fl.get(i) instanceof AnteriorFunction) {
|
if (fl.get(i) instanceof FunctionSingle) {
|
||||||
if (((AnteriorFunction) fl.get(i)).getVariable() == null) {
|
if (((FunctionSingle) fl.get(i)).getParameter() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (fl.get(i) instanceof FunctionTwoValues) {
|
} else if (fl.get(i) instanceof FunctionOperator) {
|
||||||
if (((FunctionTwoValues) fl.get(i)).getVariable1() == null || ((FunctionTwoValues) fl.get(i)).getVariable2() == null) {
|
if (((FunctionOperator) fl.get(i)).getParameter1() == null || ((FunctionOperator) fl.get(i)).getParameter2() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -146,12 +146,12 @@ public class Utils {
|
|||||||
public static boolean areThereOnlySettedUpFunctionsSumsMultiplicationsEquationsAndSystems(ArrayList<Function> fl) {
|
public static boolean areThereOnlySettedUpFunctionsSumsMultiplicationsEquationsAndSystems(ArrayList<Function> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Multiplication || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Multiplication || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
||||||
if (fl.get(i) instanceof AnteriorFunction) {
|
if (fl.get(i) instanceof FunctionSingle) {
|
||||||
if (((AnteriorFunction) fl.get(i)).getVariable() == null) {
|
if (((FunctionSingle) fl.get(i)).getParameter() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (fl.get(i) instanceof FunctionTwoValues) {
|
} else if (fl.get(i) instanceof FunctionOperator) {
|
||||||
if (((FunctionTwoValues) fl.get(i)).getVariable1() == null || ((FunctionTwoValues) fl.get(i)).getVariable2() == null) {
|
if (((FunctionOperator) fl.get(i)).getParameter1() == null || ((FunctionOperator) fl.get(i)).getParameter2() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -165,12 +165,12 @@ public class Utils {
|
|||||||
public static boolean areThereOnlySettedUpFunctionsEquationsAndSystems(ArrayList<Function> fl) {
|
public static boolean areThereOnlySettedUpFunctionsEquationsAndSystems(ArrayList<Function> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
||||||
if (fl.get(i) instanceof AnteriorFunction) {
|
if (fl.get(i) instanceof FunctionSingle) {
|
||||||
if (((AnteriorFunction) fl.get(i)).getVariable() == null) {
|
if (((FunctionSingle) fl.get(i)).getParameter() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (fl.get(i) instanceof FunctionTwoValues) {
|
} else if (fl.get(i) instanceof FunctionOperator) {
|
||||||
if (((FunctionTwoValues) fl.get(i)).getVariable1() == null || ((FunctionTwoValues) fl.get(i)).getVariable2() == null) {
|
if (((FunctionOperator) fl.get(i)).getParameter1() == null || ((FunctionOperator) fl.get(i)).getParameter2() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -184,12 +184,12 @@ public class Utils {
|
|||||||
public static boolean areThereOnlySettedUpFunctionsAndSystems(ArrayList<Function> fl) {
|
public static boolean areThereOnlySettedUpFunctionsAndSystems(ArrayList<Function> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
||||||
if (fl.get(i) instanceof AnteriorFunction) {
|
if (fl.get(i) instanceof FunctionSingle) {
|
||||||
if (((AnteriorFunction) fl.get(i)).getVariable() == null) {
|
if (((FunctionSingle) fl.get(i)).getParameter() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (fl.get(i) instanceof FunctionTwoValues) {
|
} else if (fl.get(i) instanceof FunctionOperator) {
|
||||||
if (((FunctionTwoValues) fl.get(i)).getVariable1() == null || ((FunctionTwoValues) fl.get(i)).getVariable2() == null) {
|
if (((FunctionOperator) fl.get(i)).getParameter1() == null || ((FunctionOperator) fl.get(i)).getParameter2() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -202,8 +202,8 @@ public class Utils {
|
|||||||
|
|
||||||
public static boolean areThereOnlyEmptySNFunctions(ArrayList<Function> fl) {
|
public static boolean areThereOnlyEmptySNFunctions(ArrayList<Function> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (fl.get(i) instanceof AnteriorFunction) {
|
if (fl.get(i) instanceof FunctionSingle) {
|
||||||
if (((AnteriorFunction) fl.get(i)).getVariable() == null) {
|
if (((FunctionSingle) fl.get(i)).getParameter() == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,8 +213,8 @@ public class Utils {
|
|||||||
|
|
||||||
public static boolean areThereOnlyEmptyNSNFunctions(ArrayList<Function> fl) {
|
public static boolean areThereOnlyEmptyNSNFunctions(ArrayList<Function> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (fl.get(i) instanceof FunctionTwoValues && !(fl.get(i) instanceof Sum) && !(fl.get(i) instanceof SumSubtraction) && !(fl.get(i) instanceof Subtraction) && !(fl.get(i) instanceof Multiplication) && !(fl.get(i) instanceof Division)) {
|
if (fl.get(i) instanceof FunctionOperator && !(fl.get(i) instanceof Sum) && !(fl.get(i) instanceof SumSubtraction) && !(fl.get(i) instanceof Subtraction) && !(fl.get(i) instanceof Multiplication) && !(fl.get(i) instanceof Division)) {
|
||||||
if (((FunctionTwoValues) fl.get(i)).getVariable1() == null && ((FunctionTwoValues) fl.get(i)).getVariable2() == null) {
|
if (((FunctionOperator) fl.get(i)).getParameter1() == null && ((FunctionOperator) fl.get(i)).getParameter2() == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,7 +225,7 @@ public class Utils {
|
|||||||
public static boolean areThereEmptyMultiplications(ArrayList<Function> fl) {
|
public static boolean areThereEmptyMultiplications(ArrayList<Function> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (fl.get(i) instanceof Multiplication || fl.get(i) instanceof Division) {
|
if (fl.get(i) instanceof Multiplication || fl.get(i) instanceof Division) {
|
||||||
if (((FunctionTwoValues) fl.get(i)).getVariable1() == null && ((FunctionTwoValues) fl.get(i)).getVariable2() == null) {
|
if (((FunctionOperator) fl.get(i)).getParameter1() == null && ((FunctionOperator) fl.get(i)).getParameter2() == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ public class Utils {
|
|||||||
public static boolean areThereEmptySums(ArrayList<Function> fl) {
|
public static boolean areThereEmptySums(ArrayList<Function> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction) {
|
if (fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction) {
|
||||||
if (((FunctionTwoValues) fl.get(i)).getVariable1() == null && ((FunctionTwoValues) fl.get(i)).getVariable2() == null) {
|
if (((FunctionOperator) fl.get(i)).getParameter1() == null && ((FunctionOperator) fl.get(i)).getParameter2() == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,7 +247,7 @@ public class Utils {
|
|||||||
public static boolean areThereEmptySystems(ArrayList<Function> fl) {
|
public static boolean areThereEmptySystems(ArrayList<Function> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (fl.get(i) instanceof EquationsSystemPart) {
|
if (fl.get(i) instanceof EquationsSystemPart) {
|
||||||
if (((EquationsSystemPart) fl.get(i)).getVariable() == null) {
|
if (((EquationsSystemPart) fl.get(i)).getParameter() == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,13 +257,13 @@ public class Utils {
|
|||||||
|
|
||||||
public static boolean areThereOtherSettedUpFunctions(ArrayList<Function> fl) {
|
public static boolean areThereOtherSettedUpFunctions(ArrayList<Function> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Expression || fl.get(i) instanceof AnteriorFunction || fl.get(i) instanceof Multiplication || fl.get(i) instanceof Division)) {
|
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Expression || fl.get(i) instanceof FunctionSingle || fl.get(i) instanceof Multiplication || fl.get(i) instanceof Division)) {
|
||||||
if (fl.get(i) instanceof AnteriorFunction) {
|
if (fl.get(i) instanceof FunctionSingle) {
|
||||||
if (((AnteriorFunction) fl.get(i)).getVariable() == null) {
|
if (((FunctionSingle) fl.get(i)).getParameter() == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (fl.get(i) instanceof FunctionTwoValues) {
|
} else if (fl.get(i) instanceof FunctionOperator) {
|
||||||
if (((FunctionTwoValues) fl.get(i)).getVariable1() == null || ((FunctionTwoValues) fl.get(i)).getVariable2() == null) {
|
if (((FunctionOperator) fl.get(i)).getParameter1() == null || ((FunctionOperator) fl.get(i)).getParameter2() == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -358,7 +358,7 @@ public class Utils {
|
|||||||
final int wsegno = 5;
|
final int wsegno = 5;
|
||||||
final int hsegno = h1 + 2;
|
final int hsegno = h1 + 2;
|
||||||
|
|
||||||
var.draw(x + wsegno, y + (hsegno - h1));
|
var.draw(x + wsegno, y + (hsegno - h1), null, null);
|
||||||
|
|
||||||
DisplayManager.renderer.glDrawLine(x + 1, y + hsegno - 3, x + 1, y + hsegno - 3);
|
DisplayManager.renderer.glDrawLine(x + 1, y + hsegno - 3, x + 1, y + hsegno - 3);
|
||||||
DisplayManager.renderer.glDrawLine(x + 2, y + hsegno - 2, x + 2, y + hsegno - 2);
|
DisplayManager.renderer.glDrawLine(x + 2, y + hsegno - 2, x + 2, y + hsegno - 2);
|
||||||
@ -449,7 +449,7 @@ public class Utils {
|
|||||||
|
|
||||||
public static boolean allSolved(List<Function> expressions) throws Error {
|
public static boolean allSolved(List<Function> expressions) throws Error {
|
||||||
for (final Function itm : expressions) {
|
for (final Function itm : expressions) {
|
||||||
if (itm.isSolved() == false) {
|
if (itm.isSimplified() == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -461,7 +461,7 @@ public class Utils {
|
|||||||
final int size2 = l2.size();
|
final int size2 = l2.size();
|
||||||
int cur1 = 0;
|
int cur1 = 0;
|
||||||
int cur2 = 0;
|
int cur2 = 0;
|
||||||
final int total = l1.size() * l2.size();
|
final int total = size1 * size2;
|
||||||
final Function[][] results = new Function[total][2];
|
final Function[][] results = new Function[total][2];
|
||||||
for (int i = 0; i < total; i++) {
|
for (int i = 0; i < total; i++) {
|
||||||
results[i] = new Function[] { l1.get(cur1), l2.get(cur2) };
|
results[i] = new Function[] { l1.get(cur1), l2.get(cur2) };
|
||||||
@ -481,6 +481,45 @@ public class Utils {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Function[][] joinFunctionsResults(ArrayList<ArrayList<Function>> ln) {
|
||||||
|
final int[] sizes = new int[ln.size()];
|
||||||
|
for (int i = 0; i < ln.size(); i++) {
|
||||||
|
sizes[i] = ln.get(i).size();
|
||||||
|
}
|
||||||
|
int[] curs = new int[sizes.length];
|
||||||
|
int total = 0;
|
||||||
|
for (int i = 0; i < ln.size(); i++) {
|
||||||
|
if (i == 0) {
|
||||||
|
total = sizes[i];
|
||||||
|
} else {
|
||||||
|
total *= sizes[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final Function[][] results = new Function[total][sizes.length];
|
||||||
|
for (int i = 0; i < total; i++) {
|
||||||
|
results[i] = new Function[sizes.length];
|
||||||
|
for (int j = 0; j < sizes.length; j++) {
|
||||||
|
results[i][j] = ln.get(j).get(curs[j]);
|
||||||
|
}
|
||||||
|
for (int k = 0; k < sizes.length; k++) {
|
||||||
|
if (i % sizes[k] == 0) {
|
||||||
|
for (int l = 0; l < sizes.length; l++) {
|
||||||
|
if (l != k) {
|
||||||
|
curs[l] += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int k = 0; k < sizes.length; k++) {
|
||||||
|
if (curs[k] >= sizes[k]) {
|
||||||
|
curs[k] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isNegative(Function b) {
|
public static boolean isNegative(Function b) {
|
||||||
if (b instanceof Negative) {
|
if (b instanceof Negative) {
|
||||||
return true;
|
return true;
|
||||||
|
11
src/org/warp/picalculator/gui/math/Block.java
Normal file
11
src/org/warp/picalculator/gui/math/Block.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package org.warp.picalculator.gui.math;
|
||||||
|
|
||||||
|
public abstract class Block {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param x Position relative to the window.
|
||||||
|
* @param y Position relative to the window.
|
||||||
|
* @param c Parent container.
|
||||||
|
*/
|
||||||
|
public abstract void draw(int x, int y, Container c);
|
||||||
|
}
|
112
src/org/warp/picalculator/gui/math/Container.java
Normal file
112
src/org/warp/picalculator/gui/math/Container.java
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
package org.warp.picalculator.gui.math;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.warp.picalculator.device.graphicengine.Display;
|
||||||
|
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||||
|
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||||
|
|
||||||
|
public class Container implements GraphicalElement {
|
||||||
|
|
||||||
|
private final int minWidth;
|
||||||
|
private final int minHeight;
|
||||||
|
private final ArrayList<Block> content;
|
||||||
|
private int width;
|
||||||
|
private int height;
|
||||||
|
private int line;
|
||||||
|
|
||||||
|
public Container(int minWidth, int minHeight) {
|
||||||
|
this.minWidth = minWidth;
|
||||||
|
this.minHeight = minHeight;
|
||||||
|
this.content = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Container(int minWidth, int minHeight, ArrayList<Block> content) {
|
||||||
|
this.minWidth = minWidth;
|
||||||
|
this.minHeight = minHeight;
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addBlock(Block b) {
|
||||||
|
content.add(b);
|
||||||
|
recomputeDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeBlock(Block b) {
|
||||||
|
content.remove(b);
|
||||||
|
recomputeDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAt(int i) {
|
||||||
|
content.remove(i);
|
||||||
|
recomputeDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block getBlockAt(int i) {
|
||||||
|
return content.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
content.clear();
|
||||||
|
recomputeDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param x Position relative to the window.
|
||||||
|
* @param y Position relative to the window.
|
||||||
|
* @param small size of the element.
|
||||||
|
* @param caretPos remaining positions of the caret.
|
||||||
|
* @return <code>caretPos - currentElementLength</code>
|
||||||
|
*/
|
||||||
|
public int draw(GraphicEngine g, int x, int y, boolean small, int caretPos) {
|
||||||
|
Renderer r = g.getRenderer();
|
||||||
|
return caretPos;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void recomputeDimensions() {
|
||||||
|
int w = 0;
|
||||||
|
int h = 0;
|
||||||
|
int l = 0;
|
||||||
|
|
||||||
|
for (Block b : content) {
|
||||||
|
w += b.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (w > minWidth) {
|
||||||
|
width = w;
|
||||||
|
} else {
|
||||||
|
width = minWidth;
|
||||||
|
}
|
||||||
|
if (h > minHeight) {
|
||||||
|
height = h;
|
||||||
|
} else {
|
||||||
|
height = minHeight;
|
||||||
|
}
|
||||||
|
line = l;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLine() {
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLength() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
33
src/org/warp/picalculator/gui/math/GraphicalElement.java
Normal file
33
src/org/warp/picalculator/gui/math/GraphicalElement.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package org.warp.picalculator.gui.math;
|
||||||
|
|
||||||
|
public interface GraphicalElement {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recompute element's dimension parameters, like <strong>width</strong>, <strong>height</strong>, <strong>line</strong> or <strong>length</strong>.
|
||||||
|
*/
|
||||||
|
public void recomputeDimensions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Width of the element.
|
||||||
|
*/
|
||||||
|
public int getWidth();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Height of the element.
|
||||||
|
*/
|
||||||
|
public int getHeight();
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Position of the vertical alignment line of the element, relative to itself.
|
||||||
|
*/
|
||||||
|
public int getLine();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to compute the position of the caret.
|
||||||
|
* @return Length (in characters) of the element.
|
||||||
|
*/
|
||||||
|
public int getLength();
|
||||||
|
}
|
@ -4,7 +4,7 @@ import org.warp.picalculator.Main;
|
|||||||
import org.warp.picalculator.Utils;
|
import org.warp.picalculator.Utils;
|
||||||
import org.warp.picalculator.device.Keyboard.Key;
|
import org.warp.picalculator.device.Keyboard.Key;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Variable.VariableValue;
|
import org.warp.picalculator.math.functions.Variable.VariableValue;
|
||||||
|
|
||||||
public class ChooseVariableValueScreen extends Screen {
|
public class ChooseVariableValueScreen extends Screen {
|
||||||
|
@ -19,12 +19,12 @@ import org.warp.picalculator.gui.DisplayManager;
|
|||||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||||
import org.warp.picalculator.math.AngleMode;
|
import org.warp.picalculator.math.AngleMode;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionDynamic;
|
||||||
|
import org.warp.picalculator.math.FunctionSingle;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.FunctionMultipleValues;
|
|
||||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
|
||||||
import org.warp.picalculator.math.functions.Variable;
|
import org.warp.picalculator.math.functions.Variable;
|
||||||
import org.warp.picalculator.math.functions.Variable.VariableValue;
|
import org.warp.picalculator.math.functions.Variable.VariableValue;
|
||||||
import org.warp.picalculator.math.functions.equations.Equation;
|
import org.warp.picalculator.math.functions.equations.Equation;
|
||||||
@ -37,7 +37,7 @@ public class MathInputScreen extends Screen {
|
|||||||
public volatile int caretPos = 0;
|
public volatile int caretPos = 0;
|
||||||
public volatile boolean showCaret = true;
|
public volatile boolean showCaret = true;
|
||||||
public volatile float showCaretDelta = 0f;
|
public volatile float showCaretDelta = 0f;
|
||||||
public Calculator calc;
|
public MathContext calc;
|
||||||
public boolean autoscroll;
|
public boolean autoscroll;
|
||||||
public int scrollX = 0;
|
public int scrollX = 0;
|
||||||
public int errorLevel = 0; // 0 = nessuno, 1 = risultato, 2 = tutto
|
public int errorLevel = 0; // 0 = nessuno, 1 = risultato, 2 = tutto
|
||||||
@ -48,7 +48,7 @@ public class MathInputScreen extends Screen {
|
|||||||
super();
|
super();
|
||||||
canBeInHistory = true;
|
canBeInHistory = true;
|
||||||
|
|
||||||
calc = new Calculator();
|
calc = new MathContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -204,7 +204,7 @@ public class MathInputScreen extends Screen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
final int y = padding + 20 + padding + fontBig.getCharacterHeight() + 1 + topSpacing;
|
final int y = padding + 20 + padding + fontBig.getCharacterHeight() + 1 + topSpacing;
|
||||||
fnc.draw(padding + scrollA, y);
|
fnc.draw(padding + scrollA, y, null, null);
|
||||||
if (tooLong) {
|
if (tooLong) {
|
||||||
DisplayManager.renderer.glColor(DisplayManager.renderer.glGetClearColor());
|
DisplayManager.renderer.glColor(DisplayManager.renderer.glGetClearColor());
|
||||||
DisplayManager.renderer.glFillColor(Main.screenSize[0] - 16 - 2, y, fnc.getHeight(), Main.screenSize[0]);
|
DisplayManager.renderer.glFillColor(Main.screenSize[0] - 16 - 2, y, fnc.getHeight(), Main.screenSize[0]);
|
||||||
@ -221,7 +221,7 @@ public class MathInputScreen extends Screen {
|
|||||||
int bottomSpacing = 0;
|
int bottomSpacing = 0;
|
||||||
for (final Function f : calc.f2) {
|
for (final Function f : calc.f2) {
|
||||||
bottomSpacing += f.getHeight() + 2;
|
bottomSpacing += f.getHeight() + 2;
|
||||||
f.draw(DisplayManager.engine.getWidth() - 2 - f.getWidth(), DisplayManager.engine.getHeight() - bottomSpacing);
|
f.draw(DisplayManager.engine.getWidth() - 2 - f.getWidth(), DisplayManager.engine.getHeight() - bottomSpacing, null, null);
|
||||||
}
|
}
|
||||||
if (calc.resultsCount > 1 && calc.resultsCount != calc.f2.size()) {
|
if (calc.resultsCount > 1 && calc.resultsCount != calc.f2.size()) {
|
||||||
final String resultsCountText = calc.resultsCount + " total results".toUpperCase();
|
final String resultsCountText = calc.resultsCount + " total results".toUpperCase();
|
||||||
@ -558,8 +558,8 @@ public class MathInputScreen extends Screen {
|
|||||||
} else {
|
} else {
|
||||||
results.add(f);
|
results.add(f);
|
||||||
for (final Function itm : results) {
|
for (final Function itm : results) {
|
||||||
if (itm.isSolved() == false) {
|
if (itm.isSimplified() == false) {
|
||||||
final List<Function> dt = itm.solveOneStep();
|
final List<Function> dt = itm.simplify();
|
||||||
partialResults.addAll(dt);
|
partialResults.addAll(dt);
|
||||||
} else {
|
} else {
|
||||||
partialResults.add(itm);
|
partialResults.add(itm);
|
||||||
@ -582,7 +582,7 @@ public class MathInputScreen extends Screen {
|
|||||||
results.addAll(hs);
|
results.addAll(hs);
|
||||||
calc.f2 = results;
|
calc.f2 = results;
|
||||||
for (final Function rf : calc.f2) {
|
for (final Function rf : calc.f2) {
|
||||||
rf.generateGraphics();
|
rf.recomputeDimensions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Utils.debug.println(calc.f2.toString());
|
Utils.debug.println(calc.f2.toString());
|
||||||
@ -625,7 +625,7 @@ public class MathInputScreen extends Screen {
|
|||||||
results.addAll(hs);
|
results.addAll(hs);
|
||||||
calc.f2 = results;
|
calc.f2 = results;
|
||||||
for (final Function rf : calc.f2) {
|
for (final Function rf : calc.f2) {
|
||||||
rf.generateGraphics();
|
rf.recomputeDimensions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
@ -730,12 +730,12 @@ public class MathInputScreen extends Screen {
|
|||||||
private ArrayList<Function> getKnownVariables(Function[] fncs) {
|
private ArrayList<Function> getKnownVariables(Function[] fncs) {
|
||||||
final ArrayList<Function> res = new ArrayList<>();
|
final ArrayList<Function> res = new ArrayList<>();
|
||||||
for (final Function f : fncs) {
|
for (final Function f : fncs) {
|
||||||
if (f instanceof FunctionTwoValues) {
|
if (f instanceof FunctionOperator) {
|
||||||
res.addAll(getKnownVariables(new Function[] { ((FunctionTwoValues) f).getVariable1(), ((FunctionTwoValues) f).getVariable2() }));
|
res.addAll(getKnownVariables(new Function[] { ((FunctionOperator) f).getParameter1(), ((FunctionOperator) f).getParameter2() }));
|
||||||
} else if (f instanceof FunctionMultipleValues) {
|
} else if (f instanceof FunctionDynamic) {
|
||||||
res.addAll(getKnownVariables(((FunctionMultipleValues) f).getVariables()));
|
res.addAll(getKnownVariables(((FunctionDynamic) f).getParameters()));
|
||||||
} else if (f instanceof AnteriorFunction) {
|
} else if (f instanceof FunctionSingle) {
|
||||||
res.addAll(getKnownVariables(new Function[] { ((AnteriorFunction) f).getVariable() }));
|
res.addAll(getKnownVariables(new Function[] { ((FunctionSingle) f).getParameter() }));
|
||||||
} else if (f instanceof Variable) {
|
} else if (f instanceof Variable) {
|
||||||
if (((Variable)f).getType() == Variable.V_TYPE.KNOWN) {
|
if (((Variable)f).getType() == Variable.V_TYPE.KNOWN) {
|
||||||
if (!res.contains(f)) {
|
if (!res.contains(f)) {
|
||||||
|
@ -4,7 +4,7 @@ import org.warp.picalculator.Error;
|
|||||||
import org.warp.picalculator.Main;
|
import org.warp.picalculator.Main;
|
||||||
import org.warp.picalculator.device.Keyboard.Key;
|
import org.warp.picalculator.device.Keyboard.Key;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
|
||||||
public class SolveEquationScreen extends Screen {
|
public class SolveEquationScreen extends Screen {
|
||||||
|
|
||||||
|
56
src/org/warp/picalculator/math/Function.java
Normal file
56
src/org/warp/picalculator/math/Function.java
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package org.warp.picalculator.math;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.warp.picalculator.Error;
|
||||||
|
|
||||||
|
public interface Function {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns this function and its children in a string form.
|
||||||
|
* @return This function and its children in a string form.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deep clone this function.
|
||||||
|
* @return A clone of this function.
|
||||||
|
*/
|
||||||
|
public Function clone();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic method to change a parameter in a known position.
|
||||||
|
* @param index parameter index.
|
||||||
|
* @param var parameter.
|
||||||
|
* @return A new instance of this function.
|
||||||
|
*/
|
||||||
|
public Function setParameter(int index, Function var) throws IndexOutOfBoundsException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic method to retrieve a parameter in a known position.
|
||||||
|
* @param index parameter index.
|
||||||
|
* @return The requested parameter.
|
||||||
|
*/
|
||||||
|
public Function getParameter(int index) throws IndexOutOfBoundsException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the current Math Context used by this function
|
||||||
|
* @return Calculator mathContext
|
||||||
|
*/
|
||||||
|
public MathContext getMathContext();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simplify the current function or it's children
|
||||||
|
*/
|
||||||
|
public List<Function> simplify() throws Error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current simplification status of this function and it's childrens
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean isSimplified();
|
||||||
|
}
|
165
src/org/warp/picalculator/math/FunctionDynamic.java
Normal file
165
src/org/warp/picalculator/math/FunctionDynamic.java
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
package org.warp.picalculator.math;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.warp.picalculator.Error;
|
||||||
|
import org.warp.picalculator.Utils;
|
||||||
|
|
||||||
|
import com.rits.cloning.Cloner;
|
||||||
|
|
||||||
|
public abstract class FunctionDynamic implements Function {
|
||||||
|
public FunctionDynamic(MathContext root) {
|
||||||
|
this.root = root;
|
||||||
|
functions = new Function[] {};
|
||||||
|
}
|
||||||
|
|
||||||
|
public FunctionDynamic(Function[] values) {
|
||||||
|
if (values.length > 0) {
|
||||||
|
root = values[0].getMathContext();
|
||||||
|
} else {
|
||||||
|
throw new NullPointerException("Nessun elemento nell'array. Impossibile ricavare il nodo root");
|
||||||
|
}
|
||||||
|
functions = values;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FunctionDynamic(MathContext root, Function[] values) {
|
||||||
|
this.root = root;
|
||||||
|
functions = values;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final MathContext root;
|
||||||
|
protected Function[] functions;
|
||||||
|
|
||||||
|
public Function[] getParameters() {
|
||||||
|
return Arrays.copyOf(functions, functions.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FunctionDynamic setParameters(final List<Function> value) {
|
||||||
|
FunctionDynamic f = this.clone();
|
||||||
|
final int vsize = value.size();
|
||||||
|
final Function[] tmp = new Function[vsize];
|
||||||
|
for (int i = 0; i < vsize; i++) {
|
||||||
|
tmp[i] = value.get(i);
|
||||||
|
}
|
||||||
|
f.functions = tmp;
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FunctionDynamic setParameters(final Function[] value) {
|
||||||
|
FunctionDynamic f = this.clone();
|
||||||
|
f.functions = value;
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Function getParameter(int index) {
|
||||||
|
return functions[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FunctionDynamic setParameter(int index, Function value) {
|
||||||
|
FunctionDynamic f = this.clone();
|
||||||
|
f.functions[index] = value;
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FunctionDynamic appendParameter(Function value) {
|
||||||
|
FunctionDynamic f = this.clone();
|
||||||
|
f.functions = Arrays.copyOf(f.functions, f.functions.length + 1);
|
||||||
|
f.functions[f.functions.length - 1] = value;
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the current number of parameters.
|
||||||
|
* @return The number of parameters.
|
||||||
|
*/
|
||||||
|
public int getParametersLength() {
|
||||||
|
return functions.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FunctionDynamic setParametersLength(int length) {
|
||||||
|
FunctionDynamic f = this.clone();
|
||||||
|
f.functions = Arrays.copyOf(functions, length);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSimplified() {
|
||||||
|
for (final Function variable : functions) {
|
||||||
|
if (variable.isSimplified() == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !isSolvable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current simplification status of this function, assuming that its children are already simplified.
|
||||||
|
* @return <strong>true</strong> if this function can be solved, otherwise <strong>false</strong>.
|
||||||
|
*/
|
||||||
|
protected abstract boolean isSolvable();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final ArrayList<Function> simplify() throws Error {
|
||||||
|
boolean solved = true;
|
||||||
|
Function[] fncs = getParameters();
|
||||||
|
for (Function f : fncs) {
|
||||||
|
if (f.isSimplified() == false) {
|
||||||
|
solved = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ArrayList<Function> result = solved ? solve() : null;
|
||||||
|
|
||||||
|
if (result == null || result.isEmpty()) {
|
||||||
|
result = new ArrayList<>();
|
||||||
|
|
||||||
|
final ArrayList<ArrayList<Function>> ln = new ArrayList<>();
|
||||||
|
for (int i = 0; i < fncs.length; i++) {
|
||||||
|
ArrayList<Function> l = new ArrayList<>();
|
||||||
|
if (fncs[i].isSimplified()) {
|
||||||
|
l.add(fncs[i]);
|
||||||
|
} else {
|
||||||
|
l.addAll(fncs[i].simplify());
|
||||||
|
}
|
||||||
|
ln.add(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Function[][] results = Utils.joinFunctionsResults(ln);
|
||||||
|
|
||||||
|
for (final Function[] f : results) {
|
||||||
|
result.add(this.setParameters(f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Solves only this function, assuming that its children are already simplified and it can be solved.
|
||||||
|
* @return The solved function.
|
||||||
|
* @throws Error Errors during computation, like a/0 or similar.
|
||||||
|
*/
|
||||||
|
protected abstract ArrayList<Function> solve() throws Error;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MathContext getMathContext() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract FunctionDynamic clone();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return functions.hashCode() + 883 * super.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
164
src/org/warp/picalculator/math/FunctionOperator.java
Normal file
164
src/org/warp/picalculator/math/FunctionOperator.java
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
package org.warp.picalculator.math;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.warp.picalculator.Error;
|
||||||
|
import org.warp.picalculator.Utils;
|
||||||
|
|
||||||
|
public abstract class FunctionOperator implements Function {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance of FunctionOperator. The Math Context will be the same of <strong>value1</strong>'s.
|
||||||
|
* @throws NullPointerException when value1 is null.
|
||||||
|
* @param value1 The parameter of this function.
|
||||||
|
* @param value2 The parameter of this function.
|
||||||
|
*/
|
||||||
|
public FunctionOperator(Function value1, Function value2) throws NullPointerException {
|
||||||
|
this.mathContext = value1.getMathContext();
|
||||||
|
parameter1 = value1;
|
||||||
|
parameter2 = value2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance of FunctionOperator.
|
||||||
|
* @param value1 The parameter of this function.
|
||||||
|
* @param value2 The parameter of this function.
|
||||||
|
*/
|
||||||
|
public FunctionOperator(MathContext mc, Function value1, Function value2) {
|
||||||
|
this.mathContext = mc;
|
||||||
|
parameter1 = value1;
|
||||||
|
parameter2 = value2;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final MathContext mathContext;
|
||||||
|
|
||||||
|
protected Function parameter1 = null;
|
||||||
|
protected Function parameter2 = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return First parameter.
|
||||||
|
*/
|
||||||
|
public Function getParameter1() {
|
||||||
|
return parameter1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Second parameter.
|
||||||
|
*/
|
||||||
|
public Function getParameter2() {
|
||||||
|
return parameter2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param var First parameter.
|
||||||
|
* @return A new instance of this function.
|
||||||
|
*/
|
||||||
|
public FunctionOperator setParameter1(Function var) {
|
||||||
|
FunctionOperator s = this.clone();
|
||||||
|
s.parameter1 = var;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param var Second parameter.
|
||||||
|
* @return A new instance of this function.
|
||||||
|
*/
|
||||||
|
public FunctionOperator setParameter2(Function var) {
|
||||||
|
FunctionOperator s = this.clone();
|
||||||
|
s.parameter2 = var;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FunctionOperator setParameter(int index, Function var) throws IndexOutOfBoundsException {
|
||||||
|
switch(index) {
|
||||||
|
case 0:
|
||||||
|
return this.setParameter1(var);
|
||||||
|
case 1:
|
||||||
|
return this.setParameter2(var);
|
||||||
|
default:
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Function getParameter(int index) throws IndexOutOfBoundsException {
|
||||||
|
switch(index) {
|
||||||
|
case 0:
|
||||||
|
return this.getParameter1();
|
||||||
|
case 1:
|
||||||
|
return this.getParameter2();
|
||||||
|
default:
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MathContext getMathContext() {
|
||||||
|
return mathContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSimplified() {
|
||||||
|
return (parameter1.isSimplified() & parameter2.isSimplified()) ? !isSolvable() : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current simplification status of this function, assuming that its children are already simplified.
|
||||||
|
* @return <strong>true</strong> if this function can be solved, otherwise <strong>false</strong>.
|
||||||
|
*/
|
||||||
|
protected abstract boolean isSolvable();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final ArrayList<Function> simplify() throws Error {
|
||||||
|
final boolean solved = parameter1.isSimplified() & parameter2.isSimplified();
|
||||||
|
ArrayList<Function> result = solved ? solve() : null;;
|
||||||
|
|
||||||
|
if (result == null || result.isEmpty()) {
|
||||||
|
result = new ArrayList<>();
|
||||||
|
|
||||||
|
final ArrayList<Function> l1 = new ArrayList<>();
|
||||||
|
final ArrayList<Function> l2 = new ArrayList<>();
|
||||||
|
if (parameter1.isSimplified()) {
|
||||||
|
l1.add(parameter1);
|
||||||
|
} else {
|
||||||
|
l1.addAll(parameter1.simplify());
|
||||||
|
}
|
||||||
|
if (parameter2.isSimplified()) {
|
||||||
|
l2.add(parameter2);
|
||||||
|
} else {
|
||||||
|
l2.addAll(parameter2.simplify());
|
||||||
|
}
|
||||||
|
|
||||||
|
final Function[][] results = Utils.joinFunctionsResults(l1, l2);
|
||||||
|
|
||||||
|
for (final Function[] f : results) {
|
||||||
|
result.add(this.setParameter1(f[0]).setParameter2(f[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Solves only this function, assuming that its children are already simplified and it can be solved.
|
||||||
|
* @return The solved function.
|
||||||
|
* @throws Error Errors during computation, like a/0 or similar.
|
||||||
|
*/
|
||||||
|
protected abstract ArrayList<Function> solve() throws Error;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract FunctionOperator clone();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return parameter1.hashCode() + 7 * parameter2.hashCode() + 883 * super.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract boolean equals(Object o);
|
||||||
|
}
|
130
src/org/warp/picalculator/math/FunctionSingle.java
Normal file
130
src/org/warp/picalculator/math/FunctionSingle.java
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
package org.warp.picalculator.math;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.warp.picalculator.Error;
|
||||||
|
|
||||||
|
public abstract class FunctionSingle implements Function {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance of FunctionSingle. The Math Context will be the same of <strong>value</strong>'s.
|
||||||
|
* @throws NullPointerException when value is null.
|
||||||
|
* @param value The parameter of this function.
|
||||||
|
*/
|
||||||
|
public FunctionSingle(Function value) throws NullPointerException {
|
||||||
|
mathContext = value.getMathContext();
|
||||||
|
parameter = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance of FunctionSingle.
|
||||||
|
* @param mathContext Math Context
|
||||||
|
* @param value The parameter of this function.
|
||||||
|
*/
|
||||||
|
public FunctionSingle(MathContext mathContext, Function value) {
|
||||||
|
this.mathContext = mathContext;
|
||||||
|
parameter = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final MathContext mathContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function parameter.<br>
|
||||||
|
* <u>MUST NOT BE MODIFIED IF ALREADY SET UP.</u>
|
||||||
|
*/
|
||||||
|
protected Function parameter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Parameter.
|
||||||
|
*/
|
||||||
|
public Function getParameter() {
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param var Parameter.
|
||||||
|
* @return A new instance of this function.
|
||||||
|
*/
|
||||||
|
public FunctionSingle setParameter(Function value) {
|
||||||
|
FunctionSingle s = this.clone();
|
||||||
|
s.parameter = value;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FunctionSingle setParameter(int index, Function var) throws IndexOutOfBoundsException {
|
||||||
|
if (index == 0) {
|
||||||
|
return this.setParameter(var);
|
||||||
|
} else {
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Function getParameter(int index) throws IndexOutOfBoundsException {
|
||||||
|
if (index == 0) {
|
||||||
|
return this.getParameter();
|
||||||
|
} else {
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MathContext getMathContext() {
|
||||||
|
return mathContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final ArrayList<Function> simplify() throws Error {
|
||||||
|
final boolean simplified = parameter.isSimplified();
|
||||||
|
ArrayList<Function> result = simplified ? solve() : null;
|
||||||
|
|
||||||
|
if (result == null || result.isEmpty()) {
|
||||||
|
result = new ArrayList<>();
|
||||||
|
|
||||||
|
final ArrayList<Function> l1 = new ArrayList<>();
|
||||||
|
if (parameter.isSimplified()) {
|
||||||
|
l1.add(parameter);
|
||||||
|
} else {
|
||||||
|
l1.addAll(parameter.simplify());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final Function f : l1) {
|
||||||
|
result.add(this.setParameter(f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Solves only this function, assuming that its children are already simplified and it can be solved.
|
||||||
|
* @return The solved function.
|
||||||
|
* @throws Error Errors during computation, like a/0 or similar.
|
||||||
|
*/
|
||||||
|
protected abstract ArrayList<Function> solve() throws Error;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSimplified() {
|
||||||
|
return parameter.isSimplified() ? !isSolvable() : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current simplification status of this function, assuming that its children are already simplified.
|
||||||
|
* @return <strong>true</strong> if this function can be solved, otherwise <strong>false</strong>.
|
||||||
|
*/
|
||||||
|
protected abstract boolean isSolvable();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract FunctionSingle clone();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return parameter.hashCode() + 883 * super.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract boolean equals(Object o);
|
||||||
|
}
|
@ -7,13 +7,12 @@ import org.warp.picalculator.Error;
|
|||||||
import org.warp.picalculator.Errors;
|
import org.warp.picalculator.Errors;
|
||||||
import org.warp.picalculator.Utils;
|
import org.warp.picalculator.Utils;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Variable.VariableValue;
|
import org.warp.picalculator.math.functions.Variable.VariableValue;
|
||||||
import org.warp.picalculator.math.functions.equations.Equation;
|
import org.warp.picalculator.math.functions.equations.Equation;
|
||||||
import org.warp.picalculator.math.functions.equations.EquationsSystem;
|
import org.warp.picalculator.math.functions.equations.EquationsSystem;
|
||||||
|
|
||||||
public class Calculator {
|
public class MathContext {
|
||||||
|
|
||||||
public AngleMode angleMode = AngleMode.DEG;
|
public AngleMode angleMode = AngleMode.DEG;
|
||||||
public boolean exactMode = false;
|
public boolean exactMode = false;
|
||||||
@ -22,7 +21,7 @@ public class Calculator {
|
|||||||
public ArrayList<VariableValue> variablesValues;
|
public ArrayList<VariableValue> variablesValues;
|
||||||
public int resultsCount;
|
public int resultsCount;
|
||||||
|
|
||||||
public Calculator() {
|
public MathContext() {
|
||||||
f = new ArrayList<>();
|
f = new ArrayList<>();
|
||||||
f2 = new ArrayList<>();
|
f2 = new ArrayList<>();
|
||||||
variablesValues = new ArrayList<>();
|
variablesValues = new ArrayList<>();
|
||||||
@ -37,7 +36,7 @@ public class Calculator {
|
|||||||
final String[] parts = string.substring(1).split("\\{");
|
final String[] parts = string.substring(1).split("\\{");
|
||||||
final EquationsSystem s = new EquationsSystem(this);
|
final EquationsSystem s = new EquationsSystem(this);
|
||||||
for (final String part : parts) {
|
for (final String part : parts) {
|
||||||
s.addFunctionToEnd(parseEquationString(part));
|
s.appendParameter(parseEquationString(part));
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
} else if (string.contains("=")) {
|
} else if (string.contains("=")) {
|
||||||
@ -50,15 +49,9 @@ public class Calculator {
|
|||||||
public Function parseEquationString(String string) throws Error {
|
public Function parseEquationString(String string) throws Error {
|
||||||
final String[] parts = string.split("=");
|
final String[] parts = string.split("=");
|
||||||
if (parts.length == 1) {
|
if (parts.length == 1) {
|
||||||
final Equation e = new Equation(this, null, null);
|
return new Equation(this, new Expression(this, parts[0]), new Number(this, BigInteger.ZERO));
|
||||||
e.setVariable1(new Expression(this, parts[0]));
|
|
||||||
e.setVariable2(new Number(this, BigInteger.ZERO));
|
|
||||||
return e;
|
|
||||||
} else if (parts.length == 2) {
|
} else if (parts.length == 2) {
|
||||||
final Equation e = new Equation(this, null, null);
|
return new Equation(this, new Expression(this, parts[0]), new Expression(this, parts[1]));
|
||||||
e.setVariable1(new Expression(this, parts[0]));
|
|
||||||
e.setVariable2(new Expression(this, parts[1]));
|
|
||||||
return e;
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error(Errors.SYNTAX_ERROR);
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
}
|
}
|
||||||
@ -74,11 +67,11 @@ public class Calculator {
|
|||||||
results.add(f);
|
results.add(f);
|
||||||
while (Utils.allSolved(results) == false) {
|
while (Utils.allSolved(results) == false) {
|
||||||
for (final Function itm : results) {
|
for (final Function itm : results) {
|
||||||
if (itm.isSolved() == false) {
|
if (itm.isSimplified() == false) {
|
||||||
final long t1 = System.currentTimeMillis();
|
final long t1 = System.currentTimeMillis();
|
||||||
final List<Function> dt = itm.solveOneStep();
|
final List<Function> dt = itm.simplify();
|
||||||
final long t2 = System.currentTimeMillis();
|
final long t2 = System.currentTimeMillis();
|
||||||
if (t2 - t1 >= 3000) {
|
if (!Utils.debugOn & (t2 - t1 >= 3000)) {
|
||||||
throw new Error(Errors.TIMEOUT);
|
throw new Error(Errors.TIMEOUT);
|
||||||
}
|
}
|
||||||
partialResults.addAll(dt);
|
partialResults.addAll(dt);
|
||||||
@ -117,13 +110,6 @@ public class Calculator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
f = fncs;
|
f = fncs;
|
||||||
for (final Function f : f) {
|
|
||||||
try {
|
|
||||||
f.generateGraphics();
|
|
||||||
} catch (final NullPointerException ex) {
|
|
||||||
throw new Error(Errors.SYNTAX_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public void solve(EquationScreen equationScreen, char letter) throws Error {
|
/*public void solve(EquationScreen equationScreen, char letter) throws Error {
|
@ -1,150 +0,0 @@
|
|||||||
package org.warp.picalculator.math.functions;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
|
||||||
import org.warp.picalculator.Utils;
|
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
|
||||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
|
||||||
import org.warp.picalculator.math.Calculator;
|
|
||||||
|
|
||||||
import com.rits.cloning.Cloner;
|
|
||||||
|
|
||||||
public abstract class AnteriorFunction implements Function {
|
|
||||||
public AnteriorFunction(Function value) {
|
|
||||||
root = value.getRoot();
|
|
||||||
variable = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnteriorFunction(Calculator root, Function value) {
|
|
||||||
this.root = root;
|
|
||||||
variable = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract Function NewInstance(Calculator root, Function value);
|
|
||||||
|
|
||||||
protected final Calculator root;
|
|
||||||
protected Function variable;
|
|
||||||
protected int width;
|
|
||||||
protected int height;
|
|
||||||
protected int line;
|
|
||||||
protected boolean small;
|
|
||||||
|
|
||||||
public Function getVariable() {
|
|
||||||
return variable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVariable(Function value) {
|
|
||||||
variable = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Calculator getRoot() {
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract String getSymbol();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final ArrayList<Function> solveOneStep() throws Error {
|
|
||||||
final boolean solved = variable.isSolved();
|
|
||||||
ArrayList<Function> result = solved ? solve() : null;
|
|
||||||
|
|
||||||
if (result == null || result.isEmpty()) {
|
|
||||||
result = new ArrayList<>();
|
|
||||||
|
|
||||||
final ArrayList<Function> l1 = new ArrayList<>();
|
|
||||||
if (variable.isSolved()) {
|
|
||||||
l1.add(variable);
|
|
||||||
} else {
|
|
||||||
l1.addAll(variable.solveOneStep());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final Function f : l1) {
|
|
||||||
result.add(NewInstance(root, f));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract ArrayList<Function> solve() throws Error;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSolved() {
|
|
||||||
return variable.isSolved() ? !isSolvable() : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract boolean isSolvable();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateGraphics() {
|
|
||||||
variable.setSmall(small);
|
|
||||||
variable.generateGraphics();
|
|
||||||
|
|
||||||
width = Utils.getFont(small).getStringWidth(getSymbol()) + 1 + getVariable().getWidth();
|
|
||||||
height = variable.getHeight();
|
|
||||||
line = variable.getLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(int x, int y) {
|
|
||||||
final float h1 = getVariable().getHeight();
|
|
||||||
final int wsegno = Utils.getFont(small).getStringWidth(getSymbol());
|
|
||||||
final float hsegno = Utils.getFontHeight(small);
|
|
||||||
final float maxh = getHeight();
|
|
||||||
Utils.getFont(small).use(DisplayManager.engine);
|
|
||||||
|
|
||||||
DisplayManager.renderer.glDrawStringLeft(x, (int) Math.floor(y + (maxh - hsegno) / 2), getSymbol());
|
|
||||||
getVariable().draw(x + wsegno + 1, (int) Math.floor(y + (maxh - h1) / 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth() {
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHeight() {
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLine() {
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
// try {
|
|
||||||
// return solve().toString();
|
|
||||||
String val1 = "null";
|
|
||||||
if (variable != null) {
|
|
||||||
val1 = variable.toString();
|
|
||||||
}
|
|
||||||
return getSymbol() + val1;
|
|
||||||
// } catch (Error e) {
|
|
||||||
// return e.id.toString();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AnteriorFunction clone() {
|
|
||||||
final Cloner cloner = new Cloner();
|
|
||||||
return cloner.deepClone(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSmall(boolean small) {
|
|
||||||
this.small = small;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return variable.hashCode() + 883 * getSymbol().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract boolean equals(Object o);
|
|
||||||
}
|
|
@ -6,7 +6,10 @@ import org.warp.picalculator.Error;
|
|||||||
import org.warp.picalculator.Utils;
|
import org.warp.picalculator.Utils;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.gui.math.GraphicalElement;
|
||||||
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.rules.FractionsRule1;
|
import org.warp.picalculator.math.rules.FractionsRule1;
|
||||||
import org.warp.picalculator.math.rules.FractionsRule11;
|
import org.warp.picalculator.math.rules.FractionsRule11;
|
||||||
@ -15,24 +18,16 @@ import org.warp.picalculator.math.rules.FractionsRule2;
|
|||||||
import org.warp.picalculator.math.rules.FractionsRule3;
|
import org.warp.picalculator.math.rules.FractionsRule3;
|
||||||
import org.warp.picalculator.math.rules.UndefinedRule2;
|
import org.warp.picalculator.math.rules.UndefinedRule2;
|
||||||
|
|
||||||
public class Division extends FunctionTwoValues {
|
public class Division extends FunctionOperator {
|
||||||
|
|
||||||
public Division(Calculator root, Function value1, Function value2) {
|
public Division(MathContext root, Function value1, Function value2) {
|
||||||
super(root, value1, value2);
|
super(root, value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
|
||||||
return new Division(root, value1, value2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSymbol() {
|
|
||||||
return MathematicalSymbols.DIVISION;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isSolvable() {
|
protected boolean isSolvable() {
|
||||||
|
Function variable1 = getParameter1();
|
||||||
|
Function variable2 = getParameter2();
|
||||||
if (FractionsRule1.compare(this)) {
|
if (FractionsRule1.compare(this)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -52,7 +47,7 @@ public class Division extends FunctionTwoValues {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (variable1 instanceof Number && variable2 instanceof Number) {
|
if (variable1 instanceof Number && variable2 instanceof Number) {
|
||||||
if (root.exactMode) {
|
if (getMathContext().exactMode) {
|
||||||
try {
|
try {
|
||||||
return ((Number)variable1).divide((Number)variable2).isInteger();
|
return ((Number)variable1).divide((Number)variable2).isInteger();
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
@ -67,6 +62,8 @@ public class Division extends FunctionTwoValues {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<Function> solve() throws Error {
|
public ArrayList<Function> solve() throws Error {
|
||||||
|
Function variable1 = getParameter1();
|
||||||
|
Function variable2 = getParameter2();
|
||||||
ArrayList<Function> result = new ArrayList<>();
|
ArrayList<Function> result = new ArrayList<>();
|
||||||
if (FractionsRule1.compare(this)) {
|
if (FractionsRule1.compare(this)) {
|
||||||
result = FractionsRule1.execute(this);
|
result = FractionsRule1.execute(this);
|
||||||
@ -86,147 +83,17 @@ public class Division extends FunctionTwoValues {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMinus() {
|
|
||||||
final String numerator = variable1.toString();
|
|
||||||
if (numerator.startsWith("-")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void draw(int x, int y, boolean small, boolean drawMinus) {
|
|
||||||
final boolean beforedrawminus = this.drawMinus;
|
|
||||||
this.drawMinus = drawMinus;
|
|
||||||
draw(x, y);
|
|
||||||
this.drawMinus = beforedrawminus;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean drawMinus = true;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateGraphics() {
|
|
||||||
variable1.generateGraphics();
|
|
||||||
|
|
||||||
variable2.generateGraphics();
|
|
||||||
|
|
||||||
width = calcWidth();
|
|
||||||
height = calcHeight();
|
|
||||||
line = variable1.getHeight() + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(int x, int y) {
|
|
||||||
// glColor3f(255, 127-50+new Random().nextInt(50), 0);
|
|
||||||
// glFillRect(x,y,width,height);
|
|
||||||
// glColor3f(0, 0, 0);
|
|
||||||
|
|
||||||
final Object var1 = variable1;
|
|
||||||
final Object var2 = variable2;
|
|
||||||
boolean minus = false;
|
|
||||||
int minusw = 0;
|
|
||||||
int minush = 0;
|
|
||||||
String numerator = ((Function) var1).toString();
|
|
||||||
if (numerator.startsWith("-") && ((Function) var1) instanceof Number) {
|
|
||||||
minus = true;
|
|
||||||
numerator = numerator.substring(1);
|
|
||||||
}
|
|
||||||
int w1 = 0;
|
|
||||||
int h1 = 0;
|
|
||||||
Utils.getFont(small).use(DisplayManager.engine);
|
|
||||||
if (minus) {
|
|
||||||
w1 = Utils.getFont(small).getStringWidth(numerator);
|
|
||||||
h1 = Utils.getFont(small).getCharacterHeight();
|
|
||||||
} else {
|
|
||||||
w1 = ((Function) var1).getWidth();
|
|
||||||
h1 = ((Function) var1).getHeight();
|
|
||||||
}
|
|
||||||
final int w2 = ((Function) var2).getWidth();
|
|
||||||
int maxw;
|
|
||||||
if (w1 > w2) {
|
|
||||||
maxw = 1 + w1;
|
|
||||||
} else {
|
|
||||||
maxw = 1 + w2;
|
|
||||||
}
|
|
||||||
if (minus && drawMinus) {
|
|
||||||
minusw = Utils.getFont(small).getCharacterWidth() /* Width of minus */ + 1;
|
|
||||||
minush = Utils.getFont(small).getCharacterHeight();
|
|
||||||
DisplayManager.renderer.glDrawStringLeft(x + 1, y + h1 + 1 + 1 - (minush / 2), "-");
|
|
||||||
DisplayManager.renderer.glDrawStringLeft((int) (x + 1 + minusw + 1 + (maxw - w1) / 2d), y, numerator);
|
|
||||||
} else {
|
|
||||||
((Function) var1).draw((int) (x + 1 + minusw + (maxw - w1) / 2d), y);
|
|
||||||
}
|
|
||||||
((Function) var2).draw((int) (x + 1 + minusw + (maxw - w2) / 2d), y + h1 + 1 + 1 + 1);
|
|
||||||
DisplayManager.renderer.glFillColor(x + 1 + minusw, y + h1 + 1, maxw, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHeight() {
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int calcHeight() {
|
|
||||||
|
|
||||||
boolean minus = false;
|
|
||||||
String numerator = variable1.toString();
|
|
||||||
if (numerator.startsWith("-") && variable1 instanceof Number) {
|
|
||||||
minus = true;
|
|
||||||
numerator = numerator.substring(1);
|
|
||||||
}
|
|
||||||
int h1 = 0;
|
|
||||||
if (minus) {
|
|
||||||
h1 = Utils.getFontHeight(small);
|
|
||||||
} else {
|
|
||||||
h1 = variable1.getHeight();
|
|
||||||
}
|
|
||||||
final int h2 = variable2.getHeight();
|
|
||||||
return h1 + 3 + h2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLine() {
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth() {
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int calcWidth() {
|
|
||||||
boolean minus = false;
|
|
||||||
String numerator = variable1.toString();
|
|
||||||
if (numerator.startsWith("-") && variable1 instanceof Number) {
|
|
||||||
minus = true;
|
|
||||||
numerator = numerator.substring(1);
|
|
||||||
}
|
|
||||||
int w1 = 0;
|
|
||||||
if (minus) {
|
|
||||||
w1 = Utils.getFont(small).getStringWidth(numerator);
|
|
||||||
} else {
|
|
||||||
w1 = variable1.getWidth();
|
|
||||||
}
|
|
||||||
final int w2 = variable2.getWidth();
|
|
||||||
int maxw = 0;
|
|
||||||
if (w1 > w2) {
|
|
||||||
maxw = w1 + 1;
|
|
||||||
} else {
|
|
||||||
maxw = w2 + 1;
|
|
||||||
}
|
|
||||||
if (minus && drawMinus) {
|
|
||||||
return 1 + Utils.getFont(small).getCharacterWidth() /* Width of minus */ + 1 + maxw;
|
|
||||||
} else {
|
|
||||||
return 1 + maxw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof Division) {
|
if (o instanceof Division) {
|
||||||
final FunctionTwoValues f = (FunctionTwoValues) o;
|
final FunctionOperator f = (FunctionOperator) o;
|
||||||
return variable1.equals(f.variable1) && variable2.equals(f.variable2);
|
return getParameter1().equals(f.getParameter1()) && getParameter2().equals(f.getParameter2());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FunctionOperator clone() {
|
||||||
|
return new Division(this.getMathContext(), this.getParameter1(), this.getParameter2());
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,76 +1,58 @@
|
|||||||
package org.warp.picalculator.math.functions;
|
package org.warp.picalculator.math.functions;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.Utils;
|
import org.warp.picalculator.Utils;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
|
||||||
public class EmptyNumber implements Function {
|
public class EmptyNumber implements Function {
|
||||||
|
|
||||||
public EmptyNumber(Calculator root) {
|
public EmptyNumber(MathContext root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Calculator root;
|
private final MathContext root;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSymbol() {
|
public ArrayList<Function> simplify() throws Error {
|
||||||
return " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Function> solveOneStep() throws Error {
|
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSolved() {
|
public boolean isSimplified() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateGraphics() {
|
public MathContext getMathContext() {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(int x, int y) {
|
|
||||||
DisplayManager.renderer.glDrawStringLeft(x, y, "␀");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth() {
|
|
||||||
return Utils.getFont(small).getStringWidth("␀");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHeight() {
|
|
||||||
return Utils.getFont(small).getCharacterHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLine() {
|
|
||||||
return Utils.getFont(small).getCharacterHeight() / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Calculator getRoot() {
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean small = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSmall(boolean small) {
|
|
||||||
this.small = small;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
return o instanceof EmptyNumber;
|
return o instanceof EmptyNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Function clone() {
|
||||||
|
return new EmptyNumber(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Function setParameter(int index, Function var) throws IndexOutOfBoundsException {
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Function getParameter(int index) throws IndexOutOfBoundsException {
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,11 @@ import org.warp.picalculator.Error;
|
|||||||
import org.warp.picalculator.Errors;
|
import org.warp.picalculator.Errors;
|
||||||
import org.warp.picalculator.Utils;
|
import org.warp.picalculator.Utils;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionDynamic;
|
||||||
|
import org.warp.picalculator.math.FunctionSingle;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.functions.trigonometry.ArcCosine;
|
import org.warp.picalculator.math.functions.trigonometry.ArcCosine;
|
||||||
import org.warp.picalculator.math.functions.trigonometry.ArcSine;
|
import org.warp.picalculator.math.functions.trigonometry.ArcSine;
|
||||||
@ -22,27 +26,27 @@ import org.warp.picalculator.math.functions.trigonometry.Cosine;
|
|||||||
import org.warp.picalculator.math.functions.trigonometry.Sine;
|
import org.warp.picalculator.math.functions.trigonometry.Sine;
|
||||||
import org.warp.picalculator.math.functions.trigonometry.Tangent;
|
import org.warp.picalculator.math.functions.trigonometry.Tangent;
|
||||||
|
|
||||||
public class Expression extends FunctionMultipleValues {
|
public class Expression extends FunctionDynamic {
|
||||||
|
|
||||||
public Expression(Calculator root) {
|
public Expression(MathContext root) {
|
||||||
super(root);
|
super(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Expression(Calculator root, Function[] values) {
|
public Expression(MathContext root, Function[] values) {
|
||||||
super(root, values);
|
super(root, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Expression(Calculator root, Function value) {
|
public Expression(MathContext root, Function value) {
|
||||||
super(root, new Function[]{value});
|
super(root, new Function[]{value});
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean initialParenthesis = false;
|
private boolean initialParenthesis = false;
|
||||||
|
|
||||||
public Expression(Calculator root, String string) throws Error {
|
public Expression(MathContext root, String string) throws Error {
|
||||||
this(root, string, "", true);
|
this(root, string, "", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Expression(Calculator root, String string, String debugSpaces, boolean initialParenthesis) throws Error {
|
public Expression(MathContext root, String string, String debugSpaces, boolean initialParenthesis) throws Error {
|
||||||
super(root);
|
super(root);
|
||||||
this.initialParenthesis = initialParenthesis;
|
this.initialParenthesis = initialParenthesis;
|
||||||
boolean isNumber = false;
|
boolean isNumber = false;
|
||||||
@ -65,7 +69,7 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
// If the expression is already a number:
|
// If the expression is already a number:
|
||||||
// Se l'espressione è già un numero:
|
// Se l'espressione è già un numero:
|
||||||
final Number t = new Number(root, string);
|
final Number t = new Number(root, string);
|
||||||
setVariables(new Function[] { t });
|
functions = new Function[] { t };
|
||||||
Utils.debug.println(debugSpaces + "•Result:" + t.toString());
|
Utils.debug.println(debugSpaces + "•Result:" + t.toString());
|
||||||
} else {
|
} else {
|
||||||
// Else prepare the expression:
|
// Else prepare the expression:
|
||||||
@ -215,8 +219,8 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
debugSpaces += " ";
|
debugSpaces += " ";
|
||||||
|
|
||||||
// Convert the expression to a list of objects
|
// Convert the expression to a list of objects
|
||||||
final Expression imputRawParenthesis = new Expression(root);
|
Expression imputRawParenthesis = new Expression(root);
|
||||||
imputRawParenthesis.setVariables(new Function[] {});
|
imputRawParenthesis = (Expression) imputRawParenthesis.setParameters(new Function[] {});
|
||||||
String tmp = "";
|
String tmp = "";
|
||||||
final String[] functions = concat(concat(concat(concat(MathematicalSymbols.functions(), MathematicalSymbols.parentheses()), MathematicalSymbols.signums(true)), MathematicalSymbols.variables()), MathematicalSymbols.genericSyntax());
|
final String[] functions = concat(concat(concat(concat(MathematicalSymbols.functions(), MathematicalSymbols.parentheses()), MathematicalSymbols.signums(true)), MathematicalSymbols.variables()), MathematicalSymbols.genericSyntax());
|
||||||
for (int i = 0; i < processExpression.length(); i++) {
|
for (int i = 0; i < processExpression.length(); i++) {
|
||||||
@ -322,30 +326,30 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
if (f instanceof Expression) {
|
if (f instanceof Expression) {
|
||||||
tmp = "";
|
tmp = "";
|
||||||
} else if (f instanceof Variable) {
|
} else if (f instanceof Variable) {
|
||||||
if (imputRawParenthesis.getVariablesLength() == 0) {
|
if (imputRawParenthesis.getParametersLength() == 0) {
|
||||||
if (tmp.length() > 0) {
|
if (tmp.length() > 0) {
|
||||||
imputRawParenthesis.addFunctionToEnd(new Number(root, tmp));
|
imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Number(root, tmp));
|
||||||
Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp);
|
Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp);
|
||||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(root, null, null));
|
imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Multiplication(root, null, null));
|
||||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getSymbol());
|
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final Function precedentFunction = imputRawParenthesis.getVariable(imputRawParenthesis.getVariablesLength() - 1);
|
final Function precedentFunction = imputRawParenthesis.getParameter(imputRawParenthesis.getParametersLength() - 1);
|
||||||
if (tmp.length() > 0) {
|
if (tmp.length() > 0) {
|
||||||
if (precedentFunction instanceof Number || precedentFunction instanceof Variable) {
|
if (precedentFunction instanceof Number || precedentFunction instanceof Variable) {
|
||||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(root, null, null));
|
imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Multiplication(root, null, null));
|
||||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getSymbol());
|
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
if (tmp.equals("-")) {
|
if (tmp.equals("-")) {
|
||||||
imputRawParenthesis.addFunctionToEnd(new Subtraction(root, null, null));
|
imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Subtraction(root, null, null));
|
||||||
} else {
|
} else {
|
||||||
imputRawParenthesis.addFunctionToEnd(new Number(root, tmp));
|
imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Number(root, tmp));
|
||||||
Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp);
|
Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tmp.length() > 0 || (precedentFunction instanceof Number || precedentFunction instanceof Variable)) {
|
if (tmp.length() > 0 || (precedentFunction instanceof Number || precedentFunction instanceof Variable)) {
|
||||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(root, null, null));
|
imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Multiplication(root, null, null));
|
||||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getSymbol());
|
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -355,12 +359,12 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
tmp = "-1";
|
tmp = "-1";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
imputRawParenthesis.addFunctionToEnd(new Number(root, tmp));
|
imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Number(root, tmp));
|
||||||
Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp);
|
Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
imputRawParenthesis.addFunctionToEnd(f);
|
imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(f);
|
||||||
Utils.debug.println(debugSpaces + "•Added variable to expression:" + f.getSymbol() + (f instanceof Number ? " (number)" : " (variable)"));
|
Utils.debug.println(debugSpaces + "•Added variable to expression:" + f.getClass().getSimpleName() + (f instanceof Number ? " (number)" : " (variable)"));
|
||||||
tmp = "";
|
tmp = "";
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@ -378,7 +382,7 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
if (tmp.length() > 0) {
|
if (tmp.length() > 0) {
|
||||||
Utils.debug.println(debugSpaces + "•Added variable to expression:" + tmp);
|
Utils.debug.println(debugSpaces + "•Added variable to expression:" + tmp);
|
||||||
try {
|
try {
|
||||||
imputRawParenthesis.addFunctionToEnd(new Number(root, tmp));
|
imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Number(root, tmp));
|
||||||
} catch (final NumberFormatException ex) {
|
} catch (final NumberFormatException ex) {
|
||||||
throw new Error(Errors.SYNTAX_ERROR);
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
}
|
}
|
||||||
@ -394,13 +398,13 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
// Fine suddivisione di insieme
|
// Fine suddivisione di insieme
|
||||||
|
|
||||||
Utils.debug.println(debugSpaces + "•Removing useless parentheses");
|
Utils.debug.println(debugSpaces + "•Removing useless parentheses");
|
||||||
for (int i = 0; i < imputRawParenthesis.functions.length; i++) {
|
for (int i = 0; i < imputRawParenthesis.getParametersLength(); i++) {
|
||||||
if (imputRawParenthesis.functions[i] instanceof Expression) {
|
if (imputRawParenthesis.getParameter(i) instanceof Expression) {
|
||||||
final Expression par = (Expression) imputRawParenthesis.functions[i];
|
final Expression par = (Expression) imputRawParenthesis.getParameter(i);
|
||||||
if (par.functions.length == 1) {
|
if (par.getParametersLength() == 1) {
|
||||||
final Function subFunz = par.functions[0];
|
final Function subFunz = par.getParameter(0);
|
||||||
if (subFunz instanceof Expression || subFunz instanceof Number || subFunz instanceof Variable) {
|
if (subFunz instanceof Expression || subFunz instanceof Number || subFunz instanceof Variable) {
|
||||||
imputRawParenthesis.functions[i] = subFunz;
|
imputRawParenthesis = (Expression) imputRawParenthesis.setParameter(i, subFunz);
|
||||||
Utils.debug.println(debugSpaces + " •Useless parentheses removed");
|
Utils.debug.println(debugSpaces + " •Useless parentheses removed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -410,7 +414,7 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
// Inizia l'affinazione dell'espressione
|
// Inizia l'affinazione dell'espressione
|
||||||
Utils.debug.println(debugSpaces + "•Pushing classes...");
|
Utils.debug.println(debugSpaces + "•Pushing classes...");
|
||||||
|
|
||||||
final Function[] oldFunctionsArray = imputRawParenthesis.getVariables();
|
final Function[] oldFunctionsArray = imputRawParenthesis.getParameters();
|
||||||
final ArrayList<Function> oldFunctionsList = new ArrayList<>();
|
final ArrayList<Function> oldFunctionsList = new ArrayList<>();
|
||||||
for (int i = 0; i < oldFunctionsArray.length; i++) {
|
for (int i = 0; i < oldFunctionsArray.length; i++) {
|
||||||
Function funzione = oldFunctionsArray[i];
|
Function funzione = oldFunctionsArray[i];
|
||||||
@ -458,15 +462,15 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
}
|
}
|
||||||
Utils.debug.println(debugSpaces + " •Phase: " + step);
|
Utils.debug.println(debugSpaces + " •Phase: " + step);
|
||||||
while (i < oldFunctionsList.size() && change == false && oldFunctionsList.size() > 1) {
|
while (i < oldFunctionsList.size() && change == false && oldFunctionsList.size() > 1) {
|
||||||
final Function funzioneTMP = oldFunctionsList.get(i);
|
Function funzioneTMP = oldFunctionsList.get(i);
|
||||||
if (funzioneTMP instanceof FunctionTwoValues) {
|
if (funzioneTMP instanceof FunctionOperator) {
|
||||||
if (step != "SN Functions") {
|
if (step != "SN Functions") {
|
||||||
if ((step == "sums" && (funzioneTMP instanceof Sum || funzioneTMP instanceof SumSubtraction || funzioneTMP instanceof Subtraction) == true && ((funzioneTMP instanceof AnteriorFunction && ((AnteriorFunction) funzioneTMP).variable == null) || (funzioneTMP instanceof FunctionTwoValues && ((FunctionTwoValues) funzioneTMP).variable1 == null && ((FunctionTwoValues) funzioneTMP).variable2 == null) || (!(funzioneTMP instanceof AnteriorFunction) && !(funzioneTMP instanceof FunctionTwoValues)))) || (step.equals("multiplications") && ((funzioneTMP instanceof Multiplication) || (funzioneTMP instanceof Division)) && ((FunctionTwoValues) funzioneTMP).variable1 == null && ((FunctionTwoValues) funzioneTMP).variable2 == null) || (step == "NSN Functions" && (funzioneTMP instanceof Sum) == false && (funzioneTMP instanceof SumSubtraction) == false && (funzioneTMP instanceof Subtraction) == false && (funzioneTMP instanceof Multiplication) == false && (funzioneTMP instanceof Division) == false && ((funzioneTMP instanceof AnteriorFunction && ((AnteriorFunction) funzioneTMP).variable == null) || (funzioneTMP instanceof FunctionTwoValues && ((FunctionTwoValues) funzioneTMP).variable1 == null && ((FunctionTwoValues) funzioneTMP).variable2 == null) || (!(funzioneTMP instanceof AnteriorFunction) && !(funzioneTMP instanceof FunctionTwoValues))))) {
|
if ((step == "sums" && (funzioneTMP instanceof Sum || funzioneTMP instanceof SumSubtraction || funzioneTMP instanceof Subtraction) == true && ((funzioneTMP instanceof FunctionSingle && ((FunctionSingle) funzioneTMP).getParameter() == null) || (funzioneTMP instanceof FunctionOperator && ((FunctionOperator) funzioneTMP).getParameter1() == null && ((FunctionOperator) funzioneTMP).getParameter2() == null) || (!(funzioneTMP instanceof FunctionSingle) && !(funzioneTMP instanceof FunctionOperator)))) || (step.equals("multiplications") && ((funzioneTMP instanceof Multiplication) || (funzioneTMP instanceof Division)) && ((FunctionOperator) funzioneTMP).getParameter1() == null && ((FunctionOperator) funzioneTMP).getParameter2() == null) || (step == "NSN Functions" && (funzioneTMP instanceof Sum) == false && (funzioneTMP instanceof SumSubtraction) == false && (funzioneTMP instanceof Subtraction) == false && (funzioneTMP instanceof Multiplication) == false && (funzioneTMP instanceof Division) == false && ((funzioneTMP instanceof FunctionSingle && ((FunctionSingle) funzioneTMP).getParameter() == null) || (funzioneTMP instanceof FunctionOperator && ((FunctionOperator) funzioneTMP).getParameter1() == null && ((FunctionOperator) funzioneTMP).getParameter2() == null) || (!(funzioneTMP instanceof FunctionSingle) && !(funzioneTMP instanceof FunctionOperator))))) {
|
||||||
change = true;
|
change = true;
|
||||||
|
|
||||||
if (i + 1 < oldFunctionsList.size() && i - 1 >= 0) {
|
if (i + 1 < oldFunctionsList.size() && i - 1 >= 0) {
|
||||||
((FunctionTwoValues) funzioneTMP).setVariable1(oldFunctionsList.get(i - 1));
|
funzioneTMP = ((FunctionOperator) funzioneTMP).setParameter1(oldFunctionsList.get(i - 1));
|
||||||
((FunctionTwoValues) funzioneTMP).setVariable2(oldFunctionsList.get(i + 1));
|
funzioneTMP = ((FunctionOperator) funzioneTMP).setParameter2(oldFunctionsList.get(i + 1));
|
||||||
oldFunctionsList.set(i, funzioneTMP);
|
oldFunctionsList.set(i, funzioneTMP);
|
||||||
|
|
||||||
// è importante togliere prima gli elementi
|
// è importante togliere prima gli elementi
|
||||||
@ -475,15 +479,15 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
oldFunctionsList.remove(i + 1);
|
oldFunctionsList.remove(i + 1);
|
||||||
oldFunctionsList.remove(i - 1);
|
oldFunctionsList.remove(i - 1);
|
||||||
|
|
||||||
Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.getSymbol());
|
Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.getClass().getSimpleName());
|
||||||
try {
|
try {
|
||||||
Utils.debug.println(debugSpaces + " " + "var1=" + ((FunctionTwoValues) funzioneTMP).getVariable1().toString());
|
Utils.debug.println(debugSpaces + " " + "var1=" + ((FunctionOperator) funzioneTMP).getParameter1().toString());
|
||||||
} catch (final NullPointerException ex2) {}
|
} catch (final NullPointerException ex2) {}
|
||||||
try {
|
try {
|
||||||
Utils.debug.println(debugSpaces + " " + "var2=" + ((FunctionTwoValues) funzioneTMP).getVariable2().toString());
|
Utils.debug.println(debugSpaces + " " + "var2=" + ((FunctionOperator) funzioneTMP).getParameter2().toString());
|
||||||
} catch (final NullPointerException ex2) {}
|
} catch (final NullPointerException ex2) {}
|
||||||
try {
|
try {
|
||||||
Utils.debug.println(debugSpaces + " " + "(result)=" + ((FunctionTwoValues) funzioneTMP).toString());
|
Utils.debug.println(debugSpaces + " " + "(result)=" + ((FunctionOperator) funzioneTMP).toString());
|
||||||
} catch (final NullPointerException ex2) {}
|
} catch (final NullPointerException ex2) {}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -491,15 +495,15 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (funzioneTMP instanceof AnteriorFunction) {
|
} else if (funzioneTMP instanceof FunctionSingle) {
|
||||||
if ((step == "SN Functions" && ((AnteriorFunction) funzioneTMP).variable == null)) {
|
if ((step == "SN Functions" && ((FunctionSingle) funzioneTMP).getParameter() == null)) {
|
||||||
if (i + 1 < oldFunctionsList.size()) {
|
if (i + 1 < oldFunctionsList.size()) {
|
||||||
final Function nextFunc = oldFunctionsList.get(i + 1);
|
final Function nextFunc = oldFunctionsList.get(i + 1);
|
||||||
if (nextFunc instanceof AnteriorFunction && ((AnteriorFunction) nextFunc).variable == null) {
|
if (nextFunc instanceof FunctionSingle && ((FunctionSingle) nextFunc).getParameter() == null) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
change = true;
|
change = true;
|
||||||
((AnteriorFunction) funzioneTMP).setVariable(nextFunc);
|
funzioneTMP = ((FunctionSingle) funzioneTMP).setParameter(nextFunc);
|
||||||
oldFunctionsList.set(i, funzioneTMP);
|
oldFunctionsList.set(i, funzioneTMP);
|
||||||
|
|
||||||
// è importante togliere prima gli elementi in
|
// è importante togliere prima gli elementi in
|
||||||
@ -507,8 +511,8 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
// scalano da destra a sinistra.
|
// scalano da destra a sinistra.
|
||||||
oldFunctionsList.remove(i + 1);
|
oldFunctionsList.remove(i + 1);
|
||||||
|
|
||||||
Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.getSymbol());
|
Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.getClass().getSimpleName());
|
||||||
final Function var = ((AnteriorFunction) funzioneTMP).getVariable();
|
final Function var = ((FunctionSingle) funzioneTMP).getParameter();
|
||||||
if (var == null) {
|
if (var == null) {
|
||||||
Utils.debug.println(debugSpaces + " " + "var=null");
|
Utils.debug.println(debugSpaces + " " + "var=null");
|
||||||
} else {
|
} else {
|
||||||
@ -533,9 +537,9 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
} while (((oldFunctionsList.size() != before || step != "sums") && oldFunctionsList.size() > 1));
|
} while (((oldFunctionsList.size() != before || step != "sums") && oldFunctionsList.size() > 1));
|
||||||
}
|
}
|
||||||
if (oldFunctionsList.isEmpty()) {
|
if (oldFunctionsList.isEmpty()) {
|
||||||
setVariables(new Function[] { new Number(root, 0) });
|
super.functions = new Function[] { new Number(root, 0) };
|
||||||
} else {
|
} else {
|
||||||
setVariables(oldFunctionsList);
|
super.functions = oldFunctionsList.toArray(new Function[oldFunctionsList.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
dsl = debugSpaces.length();
|
dsl = debugSpaces.length();
|
||||||
@ -550,18 +554,13 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSymbol() {
|
|
||||||
return "Parentesi";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isSolvable() {
|
protected boolean isSolvable() {
|
||||||
if (functions.length > 1) {
|
if (getParametersLength() > 1) {
|
||||||
return true;
|
return true;
|
||||||
} else if (functions.length == 1) {
|
} else if (getParametersLength() == 1) {
|
||||||
final Function f = functions[0];
|
final Function f = getParameter(0);
|
||||||
if (f.isSolved() == false) {
|
if (f.isSimplified() == false) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return !parenthesisNeeded();
|
return !parenthesisNeeded();
|
||||||
@ -571,14 +570,14 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Function> solveOneStep() throws Error {
|
public ArrayList<Function> solve() throws Error {
|
||||||
final List<Function> ret = new ArrayList<>();
|
final ArrayList<Function> ret = new ArrayList<>();
|
||||||
if (functions.length == 1) {
|
if (getParametersLength() == 1) {
|
||||||
if (functions[0].isSolved() || !parenthesisNeeded()) {
|
if (getParameter(0).isSimplified() || !parenthesisNeeded()) {
|
||||||
ret.add(functions[0]);
|
ret.add(getParameter(0));
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
final List<Function> l = functions[0].solveOneStep();
|
final List<Function> l = getParameter(0).simplify();
|
||||||
for (final Function f : l) {
|
for (final Function f : l) {
|
||||||
if (f instanceof Number || f instanceof Variable) {
|
if (f instanceof Number || f instanceof Variable) {
|
||||||
ret.add(f);
|
ret.add(f);
|
||||||
@ -589,9 +588,9 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (final Function f : functions) {
|
for (final Function f : getParameters()) {
|
||||||
if (f.isSolved() == false) {
|
if (f.isSimplified() == false) {
|
||||||
final List<Function> partial = f.solveOneStep();
|
final List<Function> partial = f.simplify();
|
||||||
for (final Function fnc : partial) {
|
for (final Function fnc : partial) {
|
||||||
ret.add(new Expression(root, new Function[] { fnc }));
|
ret.add(new Expression(root, new Function[] { fnc }));
|
||||||
}
|
}
|
||||||
@ -601,34 +600,22 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateGraphics() {
|
|
||||||
for (final Function var : functions) {
|
|
||||||
var.setSmall(small);
|
|
||||||
var.generateGraphics();
|
|
||||||
}
|
|
||||||
|
|
||||||
width = calcWidth();
|
|
||||||
height = calcHeight();
|
|
||||||
line = calcLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean parenthesisNeeded() {
|
public boolean parenthesisNeeded() {
|
||||||
boolean parenthesisneeded = true;
|
boolean parenthesisneeded = true;
|
||||||
if (initialParenthesis) {
|
if (initialParenthesis) {
|
||||||
parenthesisneeded = false;
|
parenthesisneeded = false;
|
||||||
} else {
|
} else {
|
||||||
if (functions.length == 1) {
|
if (getParametersLength() == 1) {
|
||||||
final Function f = functions[0];
|
final Function f = getParameter(0);
|
||||||
if (f instanceof Number || f instanceof Variable || f instanceof Expression || f instanceof Division || f instanceof Joke || f instanceof Undefined || f instanceof Power || f instanceof Sine || f instanceof Cosine || f instanceof Tangent || f instanceof ArcSine || f instanceof ArcCosine || f instanceof ArcTangent || f instanceof RootSquare) {
|
if (f instanceof Number || f instanceof Variable || f instanceof Expression || f instanceof Division || f instanceof Joke || f instanceof Undefined || f instanceof Power || f instanceof Sine || f instanceof Cosine || f instanceof Tangent || f instanceof ArcSine || f instanceof ArcCosine || f instanceof ArcTangent || f instanceof RootSquare) {
|
||||||
parenthesisneeded = false;
|
parenthesisneeded = false;
|
||||||
}
|
}
|
||||||
if (f instanceof Multiplication) {
|
if (f instanceof Multiplication) {
|
||||||
if (((Multiplication) f).getVariable1() instanceof Number) {
|
if (((Multiplication) f).getParameter1() instanceof Number) {
|
||||||
parenthesisneeded = !(((Multiplication) f).getVariable2() instanceof Variable);
|
parenthesisneeded = !(((Multiplication) f).getParameter2() instanceof Variable);
|
||||||
} else if (((Multiplication) f).getVariable2() instanceof Number) {
|
} else if (((Multiplication) f).getParameter2() instanceof Number) {
|
||||||
parenthesisneeded = !(((Multiplication) f).getVariable1() instanceof Variable);
|
parenthesisneeded = !(((Multiplication) f).getParameter1() instanceof Variable);
|
||||||
} else if (((Multiplication) f).getVariable1() instanceof Variable || ((Multiplication) f).getVariable2() instanceof Variable) {
|
} else if (((Multiplication) f).getParameter1() instanceof Variable || ((Multiplication) f).getParameter2() instanceof Variable) {
|
||||||
parenthesisneeded = false;
|
parenthesisneeded = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -637,136 +624,25 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
return parenthesisneeded;
|
return parenthesisneeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(int x, int y) {
|
|
||||||
if (parenthesisNeeded() == false) {
|
|
||||||
functions[0].draw(x, y);
|
|
||||||
} else {
|
|
||||||
final float miny = y;
|
|
||||||
final float maxy = y + getHeight();
|
|
||||||
final int h = getHeight();
|
|
||||||
x += 1;
|
|
||||||
DisplayManager.renderer.glDrawLine(x, y + 2, x, y + 2);
|
|
||||||
DisplayManager.renderer.glDrawLine( x + 1, y + 1, x + 1, y + 1);
|
|
||||||
DisplayManager.renderer.glDrawLine( x + 2, y, x + 2, y);
|
|
||||||
|
|
||||||
DisplayManager.renderer.glDrawLine(x, y + 2, x, y + h - 3);
|
|
||||||
|
|
||||||
DisplayManager.renderer.glDrawLine(x, y + h - 3, x, y + h - 3);
|
|
||||||
DisplayManager.renderer.glDrawLine(x + 1, y + h - 2, x + 1, y + h - 2);
|
|
||||||
DisplayManager.renderer.glDrawLine(x + 2, y + h - 1, x + 2, y + h - 1);
|
|
||||||
x += 4;
|
|
||||||
for (final Function f : functions) {
|
|
||||||
final float fheight = f.getHeight();
|
|
||||||
final float y2 = miny + ((maxy - miny) / 2 - fheight / 2);
|
|
||||||
f.draw(x, (int) y2);
|
|
||||||
x += f.getWidth();
|
|
||||||
}
|
|
||||||
x += 2;
|
|
||||||
DisplayManager.renderer.glDrawLine(x, y, x, y);
|
|
||||||
DisplayManager.renderer.glDrawLine(x + 1, y + 1, x + 1, y + 1);
|
|
||||||
DisplayManager.renderer.glDrawLine(x + 2, y + 2, x + 2, y + 2);
|
|
||||||
|
|
||||||
DisplayManager.renderer.glDrawLine(x + 2, y + 2, x + 2, y + h - 3);
|
|
||||||
|
|
||||||
DisplayManager.renderer.glDrawLine(x, y + h - 1, x, y + h - 1);
|
|
||||||
DisplayManager.renderer.glDrawLine(x + 1, y + h - 2, x + 1, y + h - 2);
|
|
||||||
DisplayManager.renderer.glDrawLine(x + 2, y + h - 3, x + 2, y + h - 3);
|
|
||||||
x += 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth() {
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int calcWidth() {
|
|
||||||
if (parenthesisNeeded() == false) {
|
|
||||||
return functions[0].getWidth();
|
|
||||||
} else {
|
|
||||||
int w = 0;
|
|
||||||
for (final Function f : functions) {
|
|
||||||
w += f.getWidth();
|
|
||||||
}
|
|
||||||
return 1 + 4 + w + 2 + 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHeight() {
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int calcHeight() {
|
|
||||||
if (initialParenthesis || functions.length == 1) {
|
|
||||||
return functions[0].getHeight();
|
|
||||||
} else {
|
|
||||||
Function tmin = null;
|
|
||||||
Function tmax = null;
|
|
||||||
for (final Function t : functions) {
|
|
||||||
if (tmin == null || t.getLine() >= tmin.getLine()) {
|
|
||||||
tmin = t;
|
|
||||||
}
|
|
||||||
if (tmax == null || t.getHeight() - t.getLine() >= tmax.getHeight() - tmax.getLine()) {
|
|
||||||
tmax = t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tmin == null) {
|
|
||||||
return Utils.getFontHeight(small);
|
|
||||||
}
|
|
||||||
return tmin.getLine() + tmax.getHeight() - tmax.getLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLine() {
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int calcLine() {
|
|
||||||
if (initialParenthesis || functions.length == 1) {
|
|
||||||
return functions[0].getLine();
|
|
||||||
} else {
|
|
||||||
Function tl = null;
|
|
||||||
for (final Function t : functions) {
|
|
||||||
if (tl == null || t.getLine() >= tl.getLine()) {
|
|
||||||
tl = t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tl == null) {
|
|
||||||
return Utils.getFontHeight(small) / 2;
|
|
||||||
}
|
|
||||||
return tl.getLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String vars = "null";
|
String s = "(";
|
||||||
if (functions != null && functions.length > 0) {
|
if (functions.length > 0) {
|
||||||
if (functions.length == 1) {
|
for (Function f : functions) {
|
||||||
if (functions[0] != null) {
|
s+=f.toString()+",";
|
||||||
vars = functions[0].toString();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (final Function variable : functions) {
|
|
||||||
if (variable != null) {
|
|
||||||
vars += ", " + variable.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vars = vars.substring(2);
|
|
||||||
}
|
}
|
||||||
|
s = s.substring(0, s.length()-1);
|
||||||
}
|
}
|
||||||
return "(" + vars + ")";
|
s+=")";
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof Expression) {
|
if (o instanceof Expression) {
|
||||||
final Expression f = (Expression) o;
|
final Expression f = (Expression) o;
|
||||||
final Function[] exprFuncs1 = functions;
|
final Function[] exprFuncs1 = getParameters();
|
||||||
final Function[] exprFuncs2 = f.functions;
|
final Function[] exprFuncs2 = f.getParameters();
|
||||||
if (exprFuncs1.length == exprFuncs2.length) {
|
if (exprFuncs1.length == exprFuncs2.length) {
|
||||||
for (int i = 0; i < exprFuncs1.length; i++) {
|
for (int i = 0; i < exprFuncs1.length; i++) {
|
||||||
if (exprFuncs1[i].equals(exprFuncs2[i]) == false) {
|
if (exprFuncs1[i].equals(exprFuncs2[i]) == false) {
|
||||||
@ -775,13 +651,18 @@ public class Expression extends FunctionMultipleValues {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (o != null & getVariablesLength() == 1) {
|
} else if (o != null & getParametersLength() == 1) {
|
||||||
final Function f = (Function) o;
|
final Function f = (Function) o;
|
||||||
return (functions[0].equals(f));
|
return (getParameter(0).equals(f));
|
||||||
} else if (o == null & getVariablesLength() == 0) {
|
} else if (o == null & getParametersLength() == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Expression clone() {
|
||||||
|
return new Expression(root, functions);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package org.warp.picalculator.math.functions;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
|
||||||
import org.warp.picalculator.math.Calculator;
|
|
||||||
|
|
||||||
public interface Function {
|
|
||||||
public String getSymbol();
|
|
||||||
|
|
||||||
public List<Function> solveOneStep() throws Error;
|
|
||||||
|
|
||||||
public boolean isSolved();
|
|
||||||
|
|
||||||
public void generateGraphics() throws NullPointerException;
|
|
||||||
|
|
||||||
public void draw(int x, int y);
|
|
||||||
|
|
||||||
public int getWidth();
|
|
||||||
|
|
||||||
public int getHeight();
|
|
||||||
|
|
||||||
public int getLine();
|
|
||||||
|
|
||||||
public Calculator getRoot();
|
|
||||||
|
|
||||||
public void setSmall(boolean small);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o);
|
|
||||||
}
|
|
@ -1,129 +0,0 @@
|
|||||||
package org.warp.picalculator.math.functions;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.warp.picalculator.math.Calculator;
|
|
||||||
|
|
||||||
import com.rits.cloning.Cloner;
|
|
||||||
|
|
||||||
public abstract class FunctionMultipleValues implements Function {
|
|
||||||
public FunctionMultipleValues(Calculator root) {
|
|
||||||
this.root = root;
|
|
||||||
functions = new Function[] {};
|
|
||||||
}
|
|
||||||
|
|
||||||
public FunctionMultipleValues(Function[] values) {
|
|
||||||
if (values.length > 0) {
|
|
||||||
root = values[0].getRoot();
|
|
||||||
} else {
|
|
||||||
throw new NullPointerException("Nessun elemento nell'array. Impossibile ricavare il nodo root");
|
|
||||||
}
|
|
||||||
functions = values;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FunctionMultipleValues(Calculator root, Function[] values) {
|
|
||||||
this.root = root;
|
|
||||||
functions = values;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final Calculator root;
|
|
||||||
protected Function[] functions;
|
|
||||||
protected int width;
|
|
||||||
protected int height;
|
|
||||||
protected int line;
|
|
||||||
protected boolean small;
|
|
||||||
|
|
||||||
public Function[] getVariables() {
|
|
||||||
return functions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVariables(final List<Function> value) {
|
|
||||||
final int vsize = value.size();
|
|
||||||
final Function[] tmp = new Function[vsize];
|
|
||||||
for (int i = 0; i < vsize; i++) {
|
|
||||||
tmp[i] = value.get(i);
|
|
||||||
}
|
|
||||||
functions = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVariables(final Function[] value) {
|
|
||||||
functions = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Function getVariable(int index) {
|
|
||||||
return functions[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVariable(int index, Function value) {
|
|
||||||
functions[index] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addFunctionToEnd(Function value) {
|
|
||||||
final int index = functions.length;
|
|
||||||
setVariablesLength(index + 1);
|
|
||||||
functions[index] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getVariablesLength() {
|
|
||||||
return functions.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVariablesLength(int length) {
|
|
||||||
functions = Arrays.copyOf(functions, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract String getSymbol();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSolved() {
|
|
||||||
for (final Function variable : functions) {
|
|
||||||
if (!variable.isSolved()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return !isSolvable();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract boolean isSolvable();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Calculator getRoot() {
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract void generateGraphics();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
// try {
|
|
||||||
// return solve().toString();
|
|
||||||
return "TODO: fare una nuova alternativa a solve().toString()";
|
|
||||||
// } catch (Error e) {
|
|
||||||
// return e.id.toString();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Function clone() {
|
|
||||||
final Cloner cloner = new Cloner();
|
|
||||||
return cloner.deepClone(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSmall(boolean small) {
|
|
||||||
this.small = small;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return functions.hashCode() + 883 * getSymbol().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,197 +0,0 @@
|
|||||||
package org.warp.picalculator.math.functions;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
|
||||||
import org.warp.picalculator.Utils;
|
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
|
||||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
|
||||||
import org.warp.picalculator.math.Calculator;
|
|
||||||
|
|
||||||
import com.rits.cloning.Cloner;
|
|
||||||
|
|
||||||
public abstract class FunctionTwoValues implements Function {
|
|
||||||
public FunctionTwoValues(Calculator root, Function value1, Function value2) {
|
|
||||||
this.root = root;
|
|
||||||
variable1 = value1;
|
|
||||||
variable2 = value2;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract Function NewInstance(Calculator root, Function value1, Function value2);
|
|
||||||
|
|
||||||
protected final Calculator root;
|
|
||||||
|
|
||||||
protected Function variable1 = null;
|
|
||||||
protected Function variable2 = null;
|
|
||||||
protected int width;
|
|
||||||
protected int height;
|
|
||||||
protected int line;
|
|
||||||
protected boolean small;
|
|
||||||
|
|
||||||
public Function getVariable1() {
|
|
||||||
return variable1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVariable1(Function value) {
|
|
||||||
variable1 = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Calculator getRoot() {
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Function getVariable2() {
|
|
||||||
return variable2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVariable2(Function value) {
|
|
||||||
variable2 = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract String getSymbol();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSolved() {
|
|
||||||
return (variable1.isSolved() & variable2.isSolved()) ? !isSolvable() : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract boolean isSolvable();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final ArrayList<Function> solveOneStep() throws Error {
|
|
||||||
final boolean solved = variable1.isSolved() & variable2.isSolved();
|
|
||||||
ArrayList<Function> result = solved ? solve() : null;;
|
|
||||||
|
|
||||||
if (result == null || result.isEmpty()) {
|
|
||||||
result = new ArrayList<>();
|
|
||||||
|
|
||||||
final ArrayList<Function> l1 = new ArrayList<>();
|
|
||||||
final ArrayList<Function> l2 = new ArrayList<>();
|
|
||||||
if (variable1.isSolved()) {
|
|
||||||
l1.add(variable1);
|
|
||||||
} else {
|
|
||||||
l1.addAll(variable1.solveOneStep());
|
|
||||||
}
|
|
||||||
if (variable2.isSolved()) {
|
|
||||||
l2.add(variable2);
|
|
||||||
} else {
|
|
||||||
l2.addAll(variable2.solveOneStep());
|
|
||||||
}
|
|
||||||
|
|
||||||
final Function[][] results = Utils.joinFunctionsResults(l1, l2);
|
|
||||||
|
|
||||||
for (final Function[] f : results) {
|
|
||||||
result.add(NewInstance(root, f[0], f[1]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract ArrayList<Function> solve() throws Error;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateGraphics() {
|
|
||||||
variable1.setSmall(small);
|
|
||||||
variable1.generateGraphics();
|
|
||||||
|
|
||||||
variable2.setSmall(small);
|
|
||||||
variable2.generateGraphics();
|
|
||||||
|
|
||||||
width = calcWidth();
|
|
||||||
height = calcHeight();
|
|
||||||
line = calcLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(int x, int y) {
|
|
||||||
final int ln = getLine();
|
|
||||||
int dx = 0;
|
|
||||||
variable1.draw(dx + x, ln - variable1.getLine() + y);
|
|
||||||
dx += 1 + variable1.getWidth();
|
|
||||||
if (drawSignum()) {
|
|
||||||
Utils.getFont(small).use(DisplayManager.engine);
|
|
||||||
DisplayManager.renderer.glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol());
|
|
||||||
dx += Utils.getFont(small).getStringWidth(getSymbol());
|
|
||||||
}
|
|
||||||
variable2.draw(dx + x, ln - variable2.getLine() + y);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth() {
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHeight() {
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLine() {
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String val1 = "null";
|
|
||||||
String val2 = "null";
|
|
||||||
if (variable1 != null) {
|
|
||||||
val1 = variable1.toString();
|
|
||||||
}
|
|
||||||
if (variable2 != null) {
|
|
||||||
val2 = variable2.toString();
|
|
||||||
}
|
|
||||||
return val1 + getSymbol() + val2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FunctionTwoValues clone() {
|
|
||||||
final Cloner cloner = new Cloner();
|
|
||||||
return cloner.deepClone(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean drawSignum() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSmall(boolean small) {
|
|
||||||
this.small = small;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int calcWidth() {
|
|
||||||
return variable1.getWidth() + 1 + (drawSignum() ? Utils.getFont(small).getStringWidth(getSymbol()) : 0) + variable2.getWidth();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int calcHeight() {
|
|
||||||
|
|
||||||
Function tmin = variable1;
|
|
||||||
Function tmax = variable1;
|
|
||||||
if (tmin == null || variable2.getLine() >= tmin.getLine()) {
|
|
||||||
tmin = variable2;
|
|
||||||
}
|
|
||||||
if (tmax == null || variable2.getHeight() - variable2.getLine() >= tmax.getHeight() - tmax.getLine()) {
|
|
||||||
tmax = variable2;
|
|
||||||
}
|
|
||||||
return tmin.getLine() + tmax.getHeight() - tmax.getLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int calcLine() {
|
|
||||||
Function tl = variable1;
|
|
||||||
if (tl == null || variable2.getLine() >= tl.getLine()) {
|
|
||||||
tl = variable2;
|
|
||||||
}
|
|
||||||
return tl.getLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return variable1.hashCode() + 7 * variable2.hashCode() + 883 * getSymbol().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract boolean equals(Object o);
|
|
||||||
}
|
|
@ -1,5 +1,6 @@
|
|||||||
package org.warp.picalculator.math.functions;
|
package org.warp.picalculator.math.functions;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
@ -7,7 +8,8 @@ import org.warp.picalculator.Utils;
|
|||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
|
||||||
public class Joke implements Function {
|
public class Joke implements Function {
|
||||||
|
|
||||||
@ -17,78 +19,41 @@ public class Joke implements Function {
|
|||||||
private static final String[] jokes = new String[] { "♓", "TORNADO", "SHARKNADO" };
|
private static final String[] jokes = new String[] { "♓", "TORNADO", "SHARKNADO" };
|
||||||
private static final int[] jokesFont = new int[] { 4, -1, -1 };
|
private static final int[] jokesFont = new int[] { 4, -1, -1 };
|
||||||
private final byte joke;
|
private final byte joke;
|
||||||
private final Calculator root;
|
private final MathContext root;
|
||||||
|
|
||||||
public Joke(Calculator root, byte joke) {
|
public Joke(MathContext root, byte joke) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
this.joke = joke;
|
this.joke = joke;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSymbol() {
|
public ArrayList<Function> simplify() throws Error {
|
||||||
return "joke";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Function> solveOneStep() throws Error {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSolved() {
|
public boolean isSimplified() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateGraphics() {
|
public MathContext getMathContext() {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(int x, int y) {
|
|
||||||
final BinaryFont rf = DisplayManager.renderer.getCurrentFont();
|
|
||||||
if (jokesFont[joke] >= 0) {
|
|
||||||
DisplayManager.fonts[jokesFont[joke]].use(DisplayManager.engine);
|
|
||||||
}
|
|
||||||
DisplayManager.renderer.glDrawStringLeft(x, y, jokes[joke]);
|
|
||||||
if (jokesFont[joke] >= 0) {
|
|
||||||
rf.use(DisplayManager.engine);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth() {
|
|
||||||
if (jokesFont[joke] >= 0) {
|
|
||||||
return DisplayManager.fonts[jokesFont[joke]].getStringWidth(jokes[joke]);
|
|
||||||
} else {
|
|
||||||
return Utils.getFont(small).getStringWidth(jokes[joke]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHeight() {
|
|
||||||
if (jokesFont[joke] >= 0) {
|
|
||||||
return DisplayManager.fonts[jokesFont[joke]].getCharacterHeight();
|
|
||||||
} else {
|
|
||||||
return Utils.getFont(small).getCharacterHeight();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLine() {
|
|
||||||
return getHeight() / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Calculator getRoot() {
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean small = false;
|
@Override
|
||||||
|
public Function clone() {
|
||||||
|
return new Joke(root, joke);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSmall(boolean small) {
|
public Function setParameter(int index, Function var) throws IndexOutOfBoundsException {
|
||||||
this.small = small;
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Function getParameter(int index) throws IndexOutOfBoundsException {
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,10 @@ package org.warp.picalculator.math.functions;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionSingle;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.rules.ExponentRule15;
|
import org.warp.picalculator.math.rules.ExponentRule15;
|
||||||
import org.warp.picalculator.math.rules.ExponentRule16;
|
import org.warp.picalculator.math.rules.ExponentRule16;
|
||||||
@ -14,28 +17,20 @@ import org.warp.picalculator.math.rules.NumberRule6;
|
|||||||
import org.warp.picalculator.math.rules.SyntaxRule1;
|
import org.warp.picalculator.math.rules.SyntaxRule1;
|
||||||
import org.warp.picalculator.math.rules.methods.MultiplicationMethod1;
|
import org.warp.picalculator.math.rules.methods.MultiplicationMethod1;
|
||||||
|
|
||||||
public class Multiplication extends FunctionTwoValues {
|
public class Multiplication extends FunctionOperator {
|
||||||
|
|
||||||
public Multiplication(Calculator root, Function value1, Function value2) {
|
public Multiplication(MathContext root, Function value1, Function value2) {
|
||||||
super(root, value1, value2);
|
super(root, value1, value2);
|
||||||
if (value1 instanceof Variable && value2 instanceof Variable == false) {
|
if (value1 instanceof Variable && value2 instanceof Variable == false) {
|
||||||
variable1 = value2;
|
parameter1 = value2;
|
||||||
variable2 = value1;
|
parameter2 = value1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
|
||||||
return new Multiplication(root, value1, value2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSymbol() {
|
|
||||||
return MathematicalSymbols.MULTIPLICATION;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isSolvable() {
|
protected boolean isSolvable() {
|
||||||
|
Function variable1 = getParameter1();
|
||||||
|
Function variable2 = getParameter2();
|
||||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -85,92 +80,36 @@ public class Multiplication extends FunctionTwoValues {
|
|||||||
result = FractionsRule14.execute(this);
|
result = FractionsRule14.execute(this);
|
||||||
} else if (MultiplicationMethod1.compare(this)) {
|
} else if (MultiplicationMethod1.compare(this)) {
|
||||||
result = MultiplicationMethod1.execute(this);
|
result = MultiplicationMethod1.execute(this);
|
||||||
} else if (variable1.isSolved() & variable2.isSolved()) {
|
} else if (parameter1.isSimplified() & parameter2.isSimplified()) {
|
||||||
result.add(((Number) variable1).multiply((Number) variable2));
|
result.add(((Number) parameter1).multiply((Number) parameter2));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean drawSignum() {
|
|
||||||
final Function[] tmpVar = new Function[] { variable1, variable2 };
|
|
||||||
final boolean[] ok = new boolean[] { false, false };
|
|
||||||
for (int val = 0; val < 2; val++) {
|
|
||||||
while (!ok[val]) {
|
|
||||||
if (tmpVar[val] instanceof Division) {
|
|
||||||
ok[0] = true;
|
|
||||||
ok[1] = true;
|
|
||||||
} else if (tmpVar[val] instanceof Variable) {
|
|
||||||
ok[val] = true;
|
|
||||||
} else if (tmpVar[val] instanceof Number) {
|
|
||||||
if (val == 0) {
|
|
||||||
ok[val] = true;
|
|
||||||
} else {
|
|
||||||
if (!(tmpVar[0] instanceof Number)) {
|
|
||||||
ok[val] = true;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (tmpVar[val] instanceof Power) {
|
|
||||||
tmpVar[val] = ((Power) tmpVar[val]).variable1;
|
|
||||||
} else if (tmpVar[val] instanceof Root) {
|
|
||||||
if (val == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ok[val] = true;
|
|
||||||
} else if (tmpVar[val] instanceof RootSquare) {
|
|
||||||
if (val == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ok[val] = true;
|
|
||||||
} else if (tmpVar[val] instanceof Undefined) {
|
|
||||||
break;
|
|
||||||
} else if (tmpVar[val] instanceof Joke) {
|
|
||||||
break;
|
|
||||||
} else if (tmpVar[val] instanceof Negative) {
|
|
||||||
if (val == 1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ok[val] = true;
|
|
||||||
} else if (tmpVar[val] instanceof Expression) {
|
|
||||||
if (((Expression)tmpVar[val]).parenthesisNeeded() == true) {
|
|
||||||
ok[0] = true;
|
|
||||||
ok[1] = true;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (tmpVar[val] instanceof FunctionTwoValues) {
|
|
||||||
if (val == 0) {
|
|
||||||
tmpVar[val] = ((FunctionTwoValues) tmpVar[val]).variable2;
|
|
||||||
} else {
|
|
||||||
tmpVar[val] = ((FunctionTwoValues) tmpVar[val]).variable1;
|
|
||||||
}
|
|
||||||
} else if (tmpVar[val] instanceof AnteriorFunction) {
|
|
||||||
tmpVar[val] = ((AnteriorFunction) tmpVar[val]).variable;
|
|
||||||
} else {
|
|
||||||
ok[val] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ok[0] == true && ok[1] == true) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof Multiplication) {
|
if (o instanceof Multiplication) {
|
||||||
final FunctionTwoValues f = (FunctionTwoValues) o;
|
final FunctionOperator f = (FunctionOperator) o;
|
||||||
if (variable1.equals(f.variable1) && variable2.equals(f.variable2)) {
|
if (parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2())) {
|
||||||
return true;
|
return true;
|
||||||
} else if (variable1.equals(f.variable2) && variable2.equals(f.variable1)) {
|
} else if (parameter1.equals(f.getParameter2()) && parameter2.equals(f.getParameter1())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Multiplication clone() {
|
||||||
|
return new Multiplication(mathContext, parameter1, parameter2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if (parameter1 != null && parameter2 != null) {
|
||||||
|
return parameter1.toString()+"*"+parameter2.toString();
|
||||||
|
} else {
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -7,19 +7,21 @@ import org.warp.picalculator.Errors;
|
|||||||
import org.warp.picalculator.Utils;
|
import org.warp.picalculator.Utils;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionSingle;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||||
import org.warp.picalculator.math.rules.ExpandRule5;
|
import org.warp.picalculator.math.rules.ExpandRule5;
|
||||||
|
|
||||||
public class Negative extends AnteriorFunction {
|
public class Negative extends FunctionSingle {
|
||||||
|
|
||||||
public Negative(Calculator root, Function value) {
|
public Negative(MathContext root, Function value) {
|
||||||
super(root, value);
|
super(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Function NewInstance(Calculator root, Function value) {
|
public Function NewInstance(MathContext root, Function value) {
|
||||||
return new Negative(root, value);
|
return new Negative(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,13 +31,13 @@ public class Negative extends AnteriorFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateGraphics() {
|
public void recomputeDimensions() {
|
||||||
variable.setSmall(small);
|
variable.setSmall(small);
|
||||||
variable.generateGraphics();
|
variable.recomputeDimensions();
|
||||||
|
|
||||||
height = getVariable().getHeight();
|
height = getParameter().getHeight();
|
||||||
width = Utils.getFont(small).getCharacterWidth() /* Width of - */ + getVariable().getWidth();
|
width = Utils.getFont(small).getCharacterWidth() /* Width of - */ + getParameter().getWidth();
|
||||||
line = getVariable().getLine();
|
line = getParameter().getLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -62,10 +64,10 @@ public class Negative extends AnteriorFunction {
|
|||||||
result = ExpandRule1.execute(this);
|
result = ExpandRule1.execute(this);
|
||||||
} else if (ExpandRule5.compare(this)) {
|
} else if (ExpandRule5.compare(this)) {
|
||||||
result = ExpandRule5.execute(this);
|
result = ExpandRule5.execute(this);
|
||||||
} else if (variable.isSolved()) {
|
} else if (variable.isSimplified()) {
|
||||||
try {
|
try {
|
||||||
final Number var = (Number) getVariable();
|
final Number var = (Number) getParameter();
|
||||||
result.add(var.multiply(new Number(root, "-1")));
|
result.add(var.multiply(new Number(mathContext, "-1")));
|
||||||
} catch (final NullPointerException ex) {
|
} catch (final NullPointerException ex) {
|
||||||
throw new Error(Errors.ERROR);
|
throw new Error(Errors.ERROR);
|
||||||
} catch (final NumberFormatException ex) {
|
} catch (final NumberFormatException ex) {
|
||||||
@ -75,14 +77,14 @@ public class Negative extends AnteriorFunction {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final ArrayList<Function> l1 = new ArrayList<>();
|
final ArrayList<Function> l1 = new ArrayList<>();
|
||||||
if (variable.isSolved()) {
|
if (variable.isSimplified()) {
|
||||||
l1.add(variable);
|
l1.add(variable);
|
||||||
} else {
|
} else {
|
||||||
l1.addAll(variable.solveOneStep());
|
l1.addAll(variable.simplify());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final Function f : l1) {
|
for (final Function f : l1) {
|
||||||
result.add(new Negative(root, f));
|
result.add(new Negative(mathContext, f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -12,42 +12,39 @@ import org.warp.picalculator.Error;
|
|||||||
import org.warp.picalculator.Utils;
|
import org.warp.picalculator.Utils;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
|
||||||
import com.rits.cloning.Cloner;
|
import com.rits.cloning.Cloner;
|
||||||
|
|
||||||
public class Number implements Function {
|
public class Number implements Function {
|
||||||
|
|
||||||
private final Calculator root;
|
private final MathContext root;
|
||||||
protected BigDecimal term;
|
protected BigDecimal term;
|
||||||
protected int width;
|
|
||||||
protected int height;
|
|
||||||
protected int line;
|
|
||||||
protected boolean small;
|
|
||||||
|
|
||||||
public Number(Calculator root, BigInteger val) {
|
public Number(MathContext root, BigInteger val) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
term = new BigDecimal(val).setScale(Utils.scale, Utils.scaleMode2);
|
term = new BigDecimal(val).setScale(Utils.scale, Utils.scaleMode2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Number(Calculator root, BigDecimal val) {
|
public Number(MathContext root, BigDecimal val) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
term = val.setScale(Utils.scale, Utils.scaleMode2);
|
term = val.setScale(Utils.scale, Utils.scaleMode2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Number(Calculator root, String s) throws Error {
|
public Number(MathContext root, String s) throws Error {
|
||||||
this(root, new BigDecimal(s).setScale(Utils.scale, Utils.scaleMode2));
|
this(root, new BigDecimal(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Number(Calculator root, int s) {
|
public Number(MathContext root, int s) {
|
||||||
this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Number(Calculator root, float s) {
|
public Number(MathContext root, float s) {
|
||||||
this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Number(Calculator root, double s) {
|
public Number(MathContext root, double s) {
|
||||||
this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,18 +56,6 @@ public class Number implements Function {
|
|||||||
term = val.setScale(Utils.scale, Utils.scaleMode2);
|
term = val.setScale(Utils.scale, Utils.scaleMode2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateGraphics() {
|
|
||||||
line = calcLine(); //TODO pp
|
|
||||||
height = calcHeight();
|
|
||||||
width = calcWidth();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSymbol() {
|
|
||||||
return toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Number add(Number f) {
|
public Number add(Number f) {
|
||||||
final Number ret = new Number(root, getTerm().add(f.getTerm()));
|
final Number ret = new Number(root, getTerm().add(f.getTerm()));
|
||||||
return ret;
|
return ret;
|
||||||
@ -120,115 +105,13 @@ public class Number implements Function {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void draw(int x, int y, PIDisplay g, boolean small, boolean drawMinus) {
|
|
||||||
// boolean beforedrawminus = this.drawMinus;
|
|
||||||
// this.drawMinus = drawMinus;
|
|
||||||
// draw(x, y, small);
|
|
||||||
// this.drawMinus = beforedrawminus;
|
|
||||||
// }
|
|
||||||
|
|
||||||
private boolean drawMinus = true;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(int x, int y) {
|
|
||||||
Utils.getFont(small).use(DisplayManager.engine);
|
|
||||||
String t = toString();
|
|
||||||
|
|
||||||
if (t.startsWith("-")) {
|
|
||||||
if (drawMinus) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
t = t.substring(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (t.contains("ℯ℮")) {
|
|
||||||
final BinaryFont defaultf = Utils.getFont(small);
|
|
||||||
final BinaryFont smallf = Utils.getFont(true);
|
|
||||||
final String s = t.substring(0, t.indexOf("ℯ℮") + 2);
|
|
||||||
final int sw = defaultf.getStringWidth(s);
|
|
||||||
DisplayManager.renderer.glDrawStringLeft(x + 1, y + smallf.getCharacterHeight() - 2, s);
|
|
||||||
smallf.use(DisplayManager.engine);
|
|
||||||
DisplayManager.renderer.glDrawStringLeft(x + 1 + sw - 3, y, t.substring(t.indexOf("ℯ℮") + 2));
|
|
||||||
} else {
|
|
||||||
DisplayManager.renderer.glDrawStringLeft(x + 1, y, t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHeight(boolean drawMinus) {
|
|
||||||
final boolean beforedrawminus = this.drawMinus;
|
|
||||||
this.drawMinus = drawMinus;
|
|
||||||
final int h = getHeight();
|
|
||||||
this.drawMinus = beforedrawminus;
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHeight() {
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int calcHeight() {
|
|
||||||
final String t = toString();
|
|
||||||
if (t.contains("ℯ℮")) {
|
|
||||||
return Utils.getFontHeight(small) - 2 + Utils.getFontHeight(true);
|
|
||||||
} else {
|
|
||||||
final int h1 = Utils.getFontHeight(small);
|
|
||||||
return h1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth() {
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int calcWidth() {
|
|
||||||
String t = toString();
|
|
||||||
if (t.startsWith("-")) {
|
|
||||||
if (drawMinus) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
t = t.substring(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (t.contains("ℯ℮")) {
|
|
||||||
final BinaryFont defaultf = Utils.getFont(small);
|
|
||||||
final BinaryFont smallf = Utils.getFont(true);
|
|
||||||
final String s = t.substring(0, t.indexOf("ℯ℮") + 2);
|
|
||||||
final int sw = defaultf.getStringWidth(s);
|
|
||||||
return 1 + sw - 3 + smallf.getStringWidth(t.substring(t.indexOf("ℯ℮") + 2));
|
|
||||||
} else {
|
|
||||||
return Utils.getFont(small).getStringWidth(t) + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLine() {
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int calcLine() {
|
|
||||||
final String t = toString();
|
|
||||||
if (t.contains("ℯ℮")) {
|
|
||||||
return (Utils.getFontHeight(small) / 2) - 2 + Utils.getFontHeight(true);
|
|
||||||
} else {
|
|
||||||
return Utils.getFontHeight(small) / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number clone() {
|
public Number clone() {
|
||||||
final Cloner cloner = new Cloner();
|
return new Number(root, term);
|
||||||
return cloner.deepClone(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSmall(boolean small) {
|
public boolean isSimplified() {
|
||||||
this.small = small;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSolved() {
|
|
||||||
if (root.exactMode) {
|
if (root.exactMode) {
|
||||||
return isInteger();
|
return isInteger();
|
||||||
} else {
|
} else {
|
||||||
@ -237,7 +120,7 @@ public class Number implements Function {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Function> solveOneStep() throws Error {
|
public List<Function> simplify() throws Error {
|
||||||
final List<Function> result = new ArrayList<>();
|
final List<Function> result = new ArrayList<>();
|
||||||
if (root.exactMode) {
|
if (root.exactMode) {
|
||||||
Number divisor = new Number(root, BigInteger.TEN.pow(getNumberOfDecimalPlaces()));
|
Number divisor = new Number(root, BigInteger.TEN.pow(getNumberOfDecimalPlaces()));
|
||||||
@ -284,7 +167,7 @@ public class Number implements Function {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Calculator getRoot() {
|
public MathContext getMathContext() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,4 +223,14 @@ public class Number implements Function {
|
|||||||
|
|
||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Function setParameter(int index, Function var) throws IndexOutOfBoundsException {
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Function getParameter(int index) throws IndexOutOfBoundsException {
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@ package org.warp.picalculator.math.functions;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.rules.ExponentRule1;
|
import org.warp.picalculator.math.rules.ExponentRule1;
|
||||||
import org.warp.picalculator.math.rules.ExponentRule2;
|
import org.warp.picalculator.math.rules.ExponentRule2;
|
||||||
@ -14,25 +16,15 @@ import org.warp.picalculator.math.rules.FractionsRule4;
|
|||||||
import org.warp.picalculator.math.rules.FractionsRule5;
|
import org.warp.picalculator.math.rules.FractionsRule5;
|
||||||
import org.warp.picalculator.math.rules.UndefinedRule1;
|
import org.warp.picalculator.math.rules.UndefinedRule1;
|
||||||
|
|
||||||
public class Power extends FunctionTwoValues {
|
public class Power extends FunctionOperator {
|
||||||
|
|
||||||
public Power(Calculator root, Function value1, Function value2) {
|
public Power(MathContext root, Function value1, Function value2) {
|
||||||
super(root, value1, value2);
|
super(root, value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
|
||||||
return new Power(root, value1, value2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSymbol() {
|
|
||||||
return MathematicalSymbols.POWER;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isSolvable() {
|
protected boolean isSolvable() {
|
||||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
if (parameter1 instanceof Number & parameter2 instanceof Number) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (UndefinedRule1.compare(this)) {
|
if (UndefinedRule1.compare(this)) {
|
||||||
@ -62,19 +54,6 @@ public class Power extends FunctionTwoValues {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateGraphics() {
|
|
||||||
variable1.setSmall(small);
|
|
||||||
variable1.generateGraphics();
|
|
||||||
|
|
||||||
variable2.setSmall(true);
|
|
||||||
variable2.generateGraphics();
|
|
||||||
|
|
||||||
height = variable1.getHeight() + variable2.getHeight() - 4;
|
|
||||||
line = variable2.getHeight() - 4 + variable1.getLine();
|
|
||||||
width = getVariable1().getWidth() + getVariable2().getWidth() + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<Function> solve() throws Error {
|
public ArrayList<Function> solve() throws Error {
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
@ -94,45 +73,23 @@ public class Power extends FunctionTwoValues {
|
|||||||
result.addAll(FractionsRule4.execute(this));
|
result.addAll(FractionsRule4.execute(this));
|
||||||
} else if (FractionsRule5.compare(this)) {
|
} else if (FractionsRule5.compare(this)) {
|
||||||
result.addAll(FractionsRule5.execute(this));
|
result.addAll(FractionsRule5.execute(this));
|
||||||
} else if (variable1 instanceof Number & variable2 instanceof Number) {
|
} else if (parameter1 instanceof Number & parameter2 instanceof Number) {
|
||||||
result.add(((Number) variable1).pow((Number) variable2));
|
result.add(((Number) parameter1).pow((Number) parameter2));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(int x, int y) {
|
|
||||||
// glColor3f(0, 127-50+new Random().nextInt(50), 0);
|
|
||||||
// glFillRect(x,y,width,height);
|
|
||||||
// glColor3f(0, 0, 0);
|
|
||||||
|
|
||||||
int dx = 0;
|
|
||||||
variable1.draw(dx + x, getHeight() - variable1.getHeight() + y);
|
|
||||||
dx += variable1.getWidth();
|
|
||||||
variable2.draw(dx + x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHeight() {
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLine() {
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth() {
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof Power) {
|
if (o instanceof Power) {
|
||||||
final FunctionTwoValues f = (FunctionTwoValues) o;
|
final FunctionOperator f = (FunctionOperator) o;
|
||||||
return variable1.equals(f.variable1) && variable2.equals(f.variable2);
|
return parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Power clone() {
|
||||||
|
return new Power(mathContext, parameter1, parameter2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,17 +6,19 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
|
|
||||||
public class Root extends FunctionTwoValues {
|
public class Root extends FunctionOperator {
|
||||||
|
|
||||||
public Root(Calculator root, Function value1, Function value2) {
|
public Root(MathContext root, Function value1, Function value2) {
|
||||||
super(root, value1, value2);
|
super(root, value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
protected Function NewInstance(MathContext root, Function value1, Function value2) {
|
||||||
return new Root(root, value1, value2);
|
return new Root(root, value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,36 +29,36 @@ public class Root extends FunctionTwoValues {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateGraphics() {
|
public void generateGraphics() {
|
||||||
variable1.setSmall(true);
|
parameter1.setSmall(true);
|
||||||
variable1.generateGraphics();
|
parameter1.recomputeDimensions();
|
||||||
|
|
||||||
variable2.setSmall(small);
|
parameter2.setSmall(small);
|
||||||
variable2.generateGraphics();
|
parameter2.recomputeDimensions();
|
||||||
|
|
||||||
width = 1 + variable1.getWidth() + 2 + variable2.getWidth() + 2;
|
width = 1 + parameter1.getWidth() + 2 + parameter2.getWidth() + 2;
|
||||||
height = variable1.getHeight() + variable2.getHeight() - 2;
|
height = parameter1.getHeight() + parameter2.getHeight() - 2;
|
||||||
line = variable1.getHeight() + variable2.getLine() - 2;
|
line = parameter1.getHeight() + parameter2.getLine() - 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isSolvable() {
|
protected boolean isSolvable() {
|
||||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
if (parameter1 instanceof Number & parameter2 instanceof Number) {
|
||||||
if (root.exactMode == false) {
|
if (mathContext.exactMode == false) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Number exponent = new Number(root, BigDecimal.ONE);
|
Number exponent = new Number(mathContext, BigDecimal.ONE);
|
||||||
exponent = exponent.divide((Number) variable1);
|
exponent = exponent.divide((Number) parameter1);
|
||||||
final Number resultVal = ((Number) variable2).pow(exponent);
|
final Number resultVal = ((Number) parameter2).pow(exponent);
|
||||||
final Number originalVariable = resultVal.pow(new Number(root, 2));
|
final Number originalVariable = resultVal.pow(new Number(mathContext, 2));
|
||||||
if (originalVariable.equals(variable2)) {
|
if (originalVariable.equals(parameter2)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception | Error ex) {
|
} catch (Exception | Error ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (variable1 instanceof Number && ((Number) variable1).equals(new Number(root, 2))) {
|
if (parameter1 instanceof Number && ((Number) parameter1).equals(new Number(mathContext, 2))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -65,38 +67,38 @@ public class Root extends FunctionTwoValues {
|
|||||||
@Override
|
@Override
|
||||||
public ArrayList<Function> solve() throws Error {
|
public ArrayList<Function> solve() throws Error {
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
if (root.exactMode) {
|
if (mathContext.exactMode) {
|
||||||
if (variable1 instanceof Number && ((Number) variable1).equals(new Number(root, 2))) {
|
if (parameter1 instanceof Number && ((Number) parameter1).equals(new Number(mathContext, 2))) {
|
||||||
result.add(new RootSquare(root, variable2));
|
result.add(new RootSquare(mathContext, parameter2));
|
||||||
} else {
|
} else {
|
||||||
Number exponent = new Number(root, BigInteger.ONE);
|
Number exponent = new Number(mathContext, BigInteger.ONE);
|
||||||
exponent = exponent.divide((Number) variable1);
|
exponent = exponent.divide((Number) parameter1);
|
||||||
result.add(((Number) variable2).pow(exponent));
|
result.add(((Number) parameter2).pow(exponent));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final Number exp = (Number) variable1;
|
final Number exp = (Number) parameter1;
|
||||||
final Number numb = (Number) variable2;
|
final Number numb = (Number) parameter2;
|
||||||
|
|
||||||
result.add(numb.pow(new Number(root, 1).divide(exp)));
|
result.add(numb.pow(new Number(mathContext, 1).divide(exp)));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(int x, int y) {
|
public void draw(int x, int y, boolean small, int caretPos) {
|
||||||
// glColor3f(0, 255, 0);
|
// glColor3f(0, 255, 0);
|
||||||
// glFillRect(x,y,width,height);
|
// glFillRect(x,y,width,height);
|
||||||
// glColor3f(0, 0, 0);
|
// glColor3f(0, 0, 0);
|
||||||
|
|
||||||
final int w1 = getVariable2().getWidth();
|
final int w1 = getVariable2().getWidth();
|
||||||
final int h1 = getVariable2().getHeight();
|
final int h1 = getVariable2().getHeight();
|
||||||
final int w2 = getVariable1().getWidth();
|
final int w2 = getParameter1().getWidth();
|
||||||
final int h2 = getVariable1().getHeight();
|
final int h2 = getParameter1().getHeight();
|
||||||
final int height = getHeight();
|
final int height = getHeight();
|
||||||
final int hh = (int) Math.ceil((double) h1 / 2);
|
final int hh = (int) Math.ceil((double) h1 / 2);
|
||||||
|
|
||||||
getVariable1().draw(x + 1, y);
|
getParameter1().draw(x + 1, y, null, null);
|
||||||
getVariable2().draw(x + 1 + w2 + 2, y + h2 - 2);
|
getVariable2().draw(x + 1 + w2 + 2, y + h2 - 2, null, null);
|
||||||
|
|
||||||
DisplayManager.renderer.glDrawLine(x + 1 + w2 - 2, y + height - 2, x + 1 + w2 - 2, y + height - 2);
|
DisplayManager.renderer.glDrawLine(x + 1 + w2 - 2, y + height - 2, x + 1 + w2 - 2, y + height - 2);
|
||||||
DisplayManager.renderer.glDrawLine(x + 1 + w2 - 1, y + height - 1, x + 1 + w2 - 1, y + height - 1);
|
DisplayManager.renderer.glDrawLine(x + 1 + w2 - 1, y + height - 1, x + 1 + w2 - 1, y + height - 1);
|
||||||
@ -124,8 +126,8 @@ public class Root extends FunctionTwoValues {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof Root) {
|
if (o instanceof Root) {
|
||||||
final FunctionTwoValues f = (FunctionTwoValues) o;
|
final FunctionOperator f = (FunctionOperator) o;
|
||||||
return variable1.equals(f.variable1) && variable2.equals(f.variable2);
|
return parameter1.equals(f.parameter1) && parameter2.equals(f.parameter2);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,19 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.Utils;
|
import org.warp.picalculator.Utils;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionSingle;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
|
|
||||||
public class RootSquare extends AnteriorFunction {
|
public class RootSquare extends FunctionSingle {
|
||||||
|
|
||||||
public RootSquare(Calculator root, Function value) {
|
public RootSquare(MathContext root, Function value) {
|
||||||
super(root, value);
|
super(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Function NewInstance(Calculator root, Function value) {
|
public Function NewInstance(MathContext root, Function value) {
|
||||||
return new RootSquare(root, value);
|
return new RootSquare(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,26 +27,26 @@ public class RootSquare extends AnteriorFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateGraphics() {
|
public void recomputeDimensions() {
|
||||||
variable.setSmall(small);
|
variable.setSmall(small);
|
||||||
variable.generateGraphics();
|
variable.recomputeDimensions();
|
||||||
|
|
||||||
height = getVariable().getHeight() + 2;
|
height = getParameter().getHeight() + 2;
|
||||||
width = 1 + 4 + getVariable().getWidth() + 1;
|
width = 1 + 4 + getParameter().getWidth() + 1;
|
||||||
line = getVariable().getLine() + 2;
|
line = getParameter().getLine() + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isSolvable() {
|
protected boolean isSolvable() {
|
||||||
if (variable instanceof Number) {
|
if (variable instanceof Number) {
|
||||||
if (root.exactMode == false) {
|
if (mathContext.exactMode == false) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Number exponent = new Number(root, BigInteger.ONE);
|
Number exponent = new Number(mathContext, BigInteger.ONE);
|
||||||
exponent = exponent.divide(new Number(root, 2));
|
exponent = exponent.divide(new Number(mathContext, 2));
|
||||||
final Number resultVal = ((Number) variable).pow(exponent);
|
final Number resultVal = ((Number) variable).pow(exponent);
|
||||||
final Number originalVariable = resultVal.pow(new Number(root, 2));
|
final Number originalVariable = resultVal.pow(new Number(mathContext, 2));
|
||||||
if (originalVariable.equals(variable)) {
|
if (originalVariable.equals(variable)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -58,26 +60,26 @@ public class RootSquare extends AnteriorFunction {
|
|||||||
@Override
|
@Override
|
||||||
public ArrayList<Function> solve() throws Error {
|
public ArrayList<Function> solve() throws Error {
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
if (root.exactMode) {
|
if (mathContext.exactMode) {
|
||||||
Number exponent = new Number(root, BigInteger.ONE);
|
Number exponent = new Number(mathContext, BigInteger.ONE);
|
||||||
exponent = exponent.divide(new Number(root, 2));
|
exponent = exponent.divide(new Number(mathContext, 2));
|
||||||
result.add(((Number) variable).pow(exponent));
|
result.add(((Number) variable).pow(exponent));
|
||||||
} else {
|
} else {
|
||||||
final Number exp = new Number(root, 2);
|
final Number exp = new Number(mathContext, 2);
|
||||||
final Number numb = (Number) variable;
|
final Number numb = (Number) variable;
|
||||||
|
|
||||||
result.add(numb.pow(new Number(root, 1).divide(exp)));
|
result.add(numb.pow(new Number(mathContext, 1).divide(exp)));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(int x, int y) {
|
public int draw(int x, int y, boolean small, int caretPos) {
|
||||||
// glColor3f(0, 255, 0);
|
// glColor3f(0, 255, 0);
|
||||||
// glFillRect(x,y,width,height);
|
// glFillRect(x,y,width,height);
|
||||||
// glColor3f(0, 0, 0);
|
// glColor3f(0, 0, 0);
|
||||||
|
|
||||||
Utils.writeSquareRoot(getVariable(), x, y, small);
|
Utils.writeSquareRoot(getParameter(), x, y, small);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,7 +3,9 @@ package org.warp.picalculator.math.functions;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||||
import org.warp.picalculator.math.rules.ExpandRule5;
|
import org.warp.picalculator.math.rules.ExpandRule5;
|
||||||
@ -14,14 +16,14 @@ import org.warp.picalculator.math.rules.VariableRule2;
|
|||||||
import org.warp.picalculator.math.rules.VariableRule3;
|
import org.warp.picalculator.math.rules.VariableRule3;
|
||||||
import org.warp.picalculator.math.rules.methods.SumMethod1;
|
import org.warp.picalculator.math.rules.methods.SumMethod1;
|
||||||
|
|
||||||
public class Subtraction extends FunctionTwoValues {
|
public class Subtraction extends FunctionOperator {
|
||||||
|
|
||||||
public Subtraction(Calculator root, Function value1, Function value2) {
|
public Subtraction(MathContext root, Function value1, Function value2) {
|
||||||
super(root, value1, value2);
|
super(root, value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
protected Function NewInstance(MathContext root, Function value1, Function value2) {
|
||||||
return new Subtraction(root, value1, value2);
|
return new Subtraction(root, value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +34,7 @@ public class Subtraction extends FunctionTwoValues {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isSolvable() {
|
protected boolean isSolvable() {
|
||||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
if (parameter1 instanceof Number & parameter2 instanceof Number) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (VariableRule1.compare(this)) {
|
if (VariableRule1.compare(this)) {
|
||||||
@ -81,8 +83,8 @@ public class Subtraction extends FunctionTwoValues {
|
|||||||
result = NumberRule5.execute(this);
|
result = NumberRule5.execute(this);
|
||||||
} else if (SumMethod1.compare(this)) {
|
} else if (SumMethod1.compare(this)) {
|
||||||
result = SumMethod1.execute(this);
|
result = SumMethod1.execute(this);
|
||||||
} else if (variable1.isSolved() & variable2.isSolved()) {
|
} else if (parameter1.isSimplified() & parameter2.isSimplified()) {
|
||||||
result.add(((Number) variable1).add(((Number) variable2).multiply(new Number(root, "-1"))));
|
result.add(((Number) parameter1).add(((Number) parameter2).multiply(new Number(mathContext, "-1"))));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -90,8 +92,8 @@ public class Subtraction extends FunctionTwoValues {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof Subtraction) {
|
if (o instanceof Subtraction) {
|
||||||
final FunctionTwoValues f = (FunctionTwoValues) o;
|
final FunctionOperator f = (FunctionOperator) o;
|
||||||
return variable1.equals(f.variable1) && variable2.equals(f.variable2);
|
return parameter1.equals(f.parameter1) && parameter2.equals(f.parameter2);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,9 @@ import org.warp.picalculator.Error;
|
|||||||
import org.warp.picalculator.Errors;
|
import org.warp.picalculator.Errors;
|
||||||
import org.warp.picalculator.Utils;
|
import org.warp.picalculator.Utils;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.rules.NumberRule3;
|
import org.warp.picalculator.math.rules.NumberRule3;
|
||||||
import org.warp.picalculator.math.rules.NumberRule5;
|
import org.warp.picalculator.math.rules.NumberRule5;
|
||||||
@ -18,25 +20,15 @@ import org.warp.picalculator.math.rules.VariableRule2;
|
|||||||
import org.warp.picalculator.math.rules.VariableRule3;
|
import org.warp.picalculator.math.rules.VariableRule3;
|
||||||
import org.warp.picalculator.math.rules.methods.SumMethod1;
|
import org.warp.picalculator.math.rules.methods.SumMethod1;
|
||||||
|
|
||||||
public class Sum extends FunctionTwoValues {
|
public class Sum extends FunctionOperator {
|
||||||
|
|
||||||
public Sum(Calculator root, Function value1, Function value2) {
|
public Sum(MathContext root, Function value1, Function value2) {
|
||||||
super(root, value1, value2);
|
super(root, value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
|
||||||
return new Sum(root, value1, value2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSymbol() {
|
|
||||||
return MathematicalSymbols.SUM;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isSolvable() {
|
protected boolean isSolvable() {
|
||||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
if (parameter1 instanceof Number & parameter2 instanceof Number) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (SyntaxRule2.compare(this)) {
|
if (SyntaxRule2.compare(this)) {
|
||||||
@ -68,7 +60,7 @@ public class Sum extends FunctionTwoValues {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<Function> solve() throws Error {
|
public ArrayList<Function> solve() throws Error {
|
||||||
if (variable1 == null || variable2 == null) {
|
if (parameter1 == null || parameter2 == null) {
|
||||||
throw new Error(Errors.SYNTAX_ERROR);
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
}
|
}
|
||||||
ArrayList<Function> result = new ArrayList<>();
|
ArrayList<Function> result = new ArrayList<>();
|
||||||
@ -88,61 +80,40 @@ public class Sum extends FunctionTwoValues {
|
|||||||
result = NumberRule7.execute(this);
|
result = NumberRule7.execute(this);
|
||||||
} else if (SumMethod1.compare(this)) {
|
} else if (SumMethod1.compare(this)) {
|
||||||
result = SumMethod1.execute(this);
|
result = SumMethod1.execute(this);
|
||||||
} else if (variable1.isSolved() & variable2.isSolved()) {
|
} else if (parameter1.isSimplified() & parameter2.isSimplified()) {
|
||||||
if ((root.getChild().equals(this))) {
|
if ((mathContext.getChild().equals(this))) {
|
||||||
if (((Number) variable1).term.compareTo(new BigDecimal(2)) == 0 && ((Number) variable2).term.compareTo(new BigDecimal(2)) == 0) {
|
if (((Number) parameter1).term.compareTo(new BigDecimal(2)) == 0 && ((Number) parameter2).term.compareTo(new BigDecimal(2)) == 0) {
|
||||||
result.add(new Joke(root, Joke.FISH));
|
result.add(new Joke(mathContext, Joke.FISH));
|
||||||
return result;
|
return result;
|
||||||
} else if (((Number) variable1).term.compareTo(new BigDecimal(20)) == 0 && ((Number) variable2).term.compareTo(new BigDecimal(20)) == 0) {
|
} else if (((Number) parameter1).term.compareTo(new BigDecimal(20)) == 0 && ((Number) parameter2).term.compareTo(new BigDecimal(20)) == 0) {
|
||||||
result.add(new Joke(root, Joke.TORNADO));
|
result.add(new Joke(mathContext, Joke.TORNADO));
|
||||||
return result;
|
return result;
|
||||||
} else if (((Number) variable1).term.compareTo(new BigDecimal(29)) == 0 && ((Number) variable2).term.compareTo(new BigDecimal(29)) == 0) {
|
} else if (((Number) parameter1).term.compareTo(new BigDecimal(29)) == 0 && ((Number) parameter2).term.compareTo(new BigDecimal(29)) == 0) {
|
||||||
result.add(new Joke(root, Joke.SHARKNADO));
|
result.add(new Joke(mathContext, Joke.SHARKNADO));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.add(((Number) variable1).add((Number) variable2));
|
result.add(((Number) parameter1).add((Number) parameter2));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateGraphics() {
|
|
||||||
variable1.setSmall(small);
|
|
||||||
variable1.generateGraphics();
|
|
||||||
|
|
||||||
variable2.setSmall(small);
|
|
||||||
variable2.generateGraphics();
|
|
||||||
|
|
||||||
width = calcWidth();
|
|
||||||
height = calcHeight();
|
|
||||||
line = calcLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth() {
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int calcWidth() {
|
|
||||||
int dx = 0;
|
|
||||||
dx += variable1.getWidth();
|
|
||||||
dx += 1;
|
|
||||||
dx += Utils.getFont(small).getStringWidth(getSymbol());
|
|
||||||
return dx += variable2.getWidth();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof Sum) {
|
if (o instanceof Sum) {
|
||||||
final FunctionTwoValues f = (FunctionTwoValues) o;
|
final FunctionOperator f = (FunctionOperator) o;
|
||||||
if (variable1.equals(f.variable1) && variable2.equals(f.variable2)) {
|
if (parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2())) {
|
||||||
return true;
|
return true;
|
||||||
} else if (variable1.equals(f.variable2) && variable2.equals(f.variable1)) {
|
} else if (parameter1.equals(f.getParameter2()) && parameter2.equals(f.getParameter1())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Sum clone() {
|
||||||
|
return new Sum(mathContext, parameter1, parameter2);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,21 +7,23 @@ import org.warp.picalculator.Errors;
|
|||||||
import org.warp.picalculator.Utils;
|
import org.warp.picalculator.Utils;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||||
import org.warp.picalculator.math.rules.NumberRule3;
|
import org.warp.picalculator.math.rules.NumberRule3;
|
||||||
import org.warp.picalculator.math.rules.NumberRule4;
|
import org.warp.picalculator.math.rules.NumberRule4;
|
||||||
import org.warp.picalculator.math.rules.NumberRule5;
|
import org.warp.picalculator.math.rules.NumberRule5;
|
||||||
|
|
||||||
public class SumSubtraction extends FunctionTwoValues {
|
public class SumSubtraction extends FunctionOperator {
|
||||||
|
|
||||||
public SumSubtraction(Calculator root, Function value1, Function value2) {
|
public SumSubtraction(MathContext root, Function value1, Function value2) {
|
||||||
super(root, value1, value2);
|
super(root, value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
protected Function NewInstance(MathContext root, Function value1, Function value2) {
|
||||||
return new SumSubtraction(root, value1, value2);
|
return new SumSubtraction(root, value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +34,7 @@ public class SumSubtraction extends FunctionTwoValues {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isSolvable() {
|
protected boolean isSolvable() {
|
||||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
if (parameter1 instanceof Number & parameter2 instanceof Number) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (NumberRule3.compare(this)) {
|
if (NumberRule3.compare(this)) {
|
||||||
@ -52,7 +54,7 @@ public class SumSubtraction extends FunctionTwoValues {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<Function> solve() throws Error {
|
public ArrayList<Function> solve() throws Error {
|
||||||
if (variable1 == null || variable2 == null) {
|
if (parameter1 == null || parameter2 == null) {
|
||||||
throw new Error(Errors.SYNTAX_ERROR);
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
}
|
}
|
||||||
ArrayList<Function> result = new ArrayList<>();
|
ArrayList<Function> result = new ArrayList<>();
|
||||||
@ -64,20 +66,20 @@ public class SumSubtraction extends FunctionTwoValues {
|
|||||||
result = NumberRule4.execute(this);
|
result = NumberRule4.execute(this);
|
||||||
} else if (NumberRule5.compare(this)) {
|
} else if (NumberRule5.compare(this)) {
|
||||||
result = NumberRule5.execute(this);
|
result = NumberRule5.execute(this);
|
||||||
} else if (variable1.isSolved() & variable2.isSolved()) {
|
} else if (parameter1.isSimplified() & parameter2.isSimplified()) {
|
||||||
result.add(((Number) variable1).add((Number) variable2));
|
result.add(((Number) parameter1).add((Number) parameter2));
|
||||||
result.add(((Number) variable1).add(((Number) variable2).multiply(new Number(root, "-1"))));
|
result.add(((Number) parameter1).add(((Number) parameter2).multiply(new Number(mathContext, "-1"))));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateGraphics() {
|
public void generateGraphics() {
|
||||||
variable1.setSmall(small);
|
parameter1.setSmall(small);
|
||||||
variable1.generateGraphics();
|
parameter1.recomputeDimensions();
|
||||||
|
|
||||||
variable2.setSmall(small);
|
parameter2.setSmall(small);
|
||||||
variable2.generateGraphics();
|
parameter2.recomputeDimensions();
|
||||||
|
|
||||||
width = calcWidth();
|
width = calcWidth();
|
||||||
height = calcHeight();
|
height = calcHeight();
|
||||||
@ -85,20 +87,20 @@ public class SumSubtraction extends FunctionTwoValues {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(int x, int y) {
|
public void draw(int x, int y, boolean small, int caretPos) {
|
||||||
// glColor3f(127, 127-50+new Random().nextInt(50), 255);
|
// glColor3f(127, 127-50+new Random().nextInt(50), 255);
|
||||||
// glFillRect(x,y,width,height);
|
// glFillRect(x,y,width,height);
|
||||||
// glColor3f(0, 0, 0);
|
// glColor3f(0, 0, 0);
|
||||||
|
|
||||||
final int ln = getLine();
|
final int ln = getLine();
|
||||||
int dx = 0;
|
int dx = 0;
|
||||||
variable1.draw(dx + x, ln - variable1.getLine() + y);
|
parameter1.draw(dx + x, ln - parameter1.getLine() + y, null, null);
|
||||||
dx += variable1.getWidth();
|
dx += parameter1.getWidth();
|
||||||
Utils.getFont(small).use(DisplayManager.engine);
|
Utils.getFont(small).use(DisplayManager.engine);
|
||||||
dx += 1;
|
dx += 1;
|
||||||
DisplayManager.renderer.glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol());
|
DisplayManager.renderer.glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol());
|
||||||
dx += Utils.getFont(small).getStringWidth(getSymbol());
|
dx += Utils.getFont(small).getStringWidth(getSymbol());
|
||||||
variable2.draw(dx + x, ln - variable2.getLine() + y);
|
parameter2.draw(dx + x, ln - parameter2.getLine() + y, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -109,17 +111,17 @@ public class SumSubtraction extends FunctionTwoValues {
|
|||||||
@Override
|
@Override
|
||||||
protected int calcWidth() {
|
protected int calcWidth() {
|
||||||
int dx = 0;
|
int dx = 0;
|
||||||
dx += variable1.getWidth();
|
dx += parameter1.getWidth();
|
||||||
dx += 1;
|
dx += 1;
|
||||||
dx += Utils.getFont(small).getStringWidth(getSymbol());
|
dx += Utils.getFont(small).getStringWidth(getSymbol());
|
||||||
return dx += variable2.getWidth();
|
return dx += parameter2.getWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof SumSubtraction) {
|
if (o instanceof SumSubtraction) {
|
||||||
final FunctionTwoValues f = (FunctionTwoValues) o;
|
final FunctionOperator f = (FunctionOperator) o;
|
||||||
return variable1.equals(f.variable1) && variable2.equals(f.variable2);
|
return parameter1.equals(f.parameter1) && parameter2.equals(f.parameter2);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,14 @@ import org.warp.picalculator.Error;
|
|||||||
import org.warp.picalculator.Utils;
|
import org.warp.picalculator.Utils;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
|
||||||
public class Undefined implements Function {
|
public class Undefined implements Function {
|
||||||
|
|
||||||
protected final Calculator root;
|
protected final MathContext root;
|
||||||
|
|
||||||
public Undefined(Calculator root) {
|
public Undefined(MathContext root) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ public class Undefined implements Function {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Calculator getRoot() {
|
public MathContext getRoot() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,28 +6,24 @@ import java.util.List;
|
|||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.Utils;
|
import org.warp.picalculator.Utils;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
|
||||||
import com.rits.cloning.Cloner;
|
import com.rits.cloning.Cloner;
|
||||||
|
|
||||||
public class Variable implements Function {
|
public class Variable implements Function {
|
||||||
|
|
||||||
protected char var;
|
protected char var;
|
||||||
protected int width;
|
protected final MathContext root;
|
||||||
protected int height;
|
|
||||||
protected int line;
|
|
||||||
protected int[] varColor;
|
|
||||||
protected boolean small;
|
|
||||||
protected final Calculator root;
|
|
||||||
protected V_TYPE type = V_TYPE.KNOWN;
|
protected V_TYPE type = V_TYPE.KNOWN;
|
||||||
|
|
||||||
public Variable(Calculator root, char val, V_TYPE type) {
|
public Variable(MathContext root, char val, V_TYPE type) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
var = val;
|
var = val;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Variable(Calculator root, String s, V_TYPE type) throws Error {
|
public Variable(MathContext root, String s, V_TYPE type) throws Error {
|
||||||
this(root, s.charAt(0), type);
|
this(root, s.charAt(0), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,84 +43,11 @@ public class Variable implements Function {
|
|||||||
return new Variable(root, var, typ);
|
return new Variable(root, var, typ);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateGraphics() {
|
|
||||||
line = calcLine();
|
|
||||||
height = calcHeight();
|
|
||||||
width = calcWidth();
|
|
||||||
varColor = new int[3];
|
|
||||||
switch (type) {
|
|
||||||
case KNOWN:
|
|
||||||
varColor[0] = 0;
|
|
||||||
varColor[1] = 200;
|
|
||||||
varColor[2] = 0;
|
|
||||||
break;
|
|
||||||
case UNKNOWN:
|
|
||||||
varColor[0] = 200;
|
|
||||||
varColor[1] = 0;
|
|
||||||
varColor[2] = 0;
|
|
||||||
break;
|
|
||||||
case SOLUTION:
|
|
||||||
varColor[0] = 0;
|
|
||||||
varColor[1] = 0;
|
|
||||||
varColor[2] = 200;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSymbol() {
|
|
||||||
return toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "" + getChar();
|
return "" + getChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void draw(int x, int y, PIDisplay g, boolean small, boolean drawMinus) {
|
|
||||||
// boolean beforedrawminus = this.drawMinus;
|
|
||||||
// this.drawMinus = drawMinus;
|
|
||||||
// draw(x, y, small);
|
|
||||||
// this.drawMinus = beforedrawminus;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(int x, int y) {
|
|
||||||
Utils.getFont(small).use(DisplayManager.engine);
|
|
||||||
DisplayManager.renderer.glColor3i(varColor[0], varColor[1], varColor[2]);
|
|
||||||
DisplayManager.renderer.glDrawStringLeft(x + 1, y, toString());
|
|
||||||
DisplayManager.renderer.glColor3i(0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHeight() {
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int calcHeight() {
|
|
||||||
final int h1 = Utils.getFontHeight(small);
|
|
||||||
return h1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth() {
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int calcWidth() {
|
|
||||||
return Utils.getFont(small).getStringWidth(toString()) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLine() {
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int calcLine() {
|
|
||||||
return Utils.getFontHeight(small) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class VariableValue {
|
public static class VariableValue {
|
||||||
public final Variable v;
|
public final Variable v;
|
||||||
public final Number n;
|
public final Number n;
|
||||||
@ -136,23 +59,12 @@ public class Variable implements Function {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Variable clone() {
|
public boolean isSimplified() {
|
||||||
final Cloner cloner = new Cloner();
|
|
||||||
return cloner.deepClone(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSmall(boolean small) {
|
|
||||||
this.small = small;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSolved() {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Function> solveOneStep() throws Error {
|
public List<Function> simplify() throws Error {
|
||||||
final List<Function> result = new ArrayList<>();
|
final List<Function> result = new ArrayList<>();
|
||||||
result.add(this);
|
result.add(this);
|
||||||
return result;
|
return result;
|
||||||
@ -172,13 +84,28 @@ public class Variable implements Function {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Calculator getRoot() {
|
public MathContext getMathContext() {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Variable clone() {
|
||||||
|
return new Variable(root, var, type);
|
||||||
|
}
|
||||||
|
|
||||||
public static enum V_TYPE {
|
public static enum V_TYPE {
|
||||||
KNOWN,
|
KNOWN,
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
SOLUTION
|
SOLUTION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Function setParameter(int index, Function var) throws IndexOutOfBoundsException {
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Function getParameter(int index) throws IndexOutOfBoundsException {
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,24 +8,24 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.Errors;
|
import org.warp.picalculator.Errors;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.SolveMethod;
|
import org.warp.picalculator.math.SolveMethod;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Subtraction;
|
import org.warp.picalculator.math.functions.Subtraction;
|
||||||
|
|
||||||
import com.rits.cloning.Cloner;
|
import com.rits.cloning.Cloner;
|
||||||
|
|
||||||
public class Equation extends FunctionTwoValues {
|
public class Equation extends FunctionOperator {
|
||||||
|
|
||||||
public Equation(Calculator root, Function value1, Function value2) {
|
public Equation(MathContext root, Function value1, Function value2) {
|
||||||
super(root, value1, value2);
|
super(root, value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
protected Function NewInstance(MathContext root, Function value1, Function value2) {
|
||||||
return new Equation(root, value1, value2);
|
return new Equation(root, value1, value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ public class Equation extends FunctionTwoValues {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isSolvable() {
|
protected boolean isSolvable() {
|
||||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
if (parameter1 instanceof Number & parameter2 instanceof Number) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -44,17 +44,17 @@ public class Equation extends FunctionTwoValues {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<Function> solve() throws Error {
|
public ArrayList<Function> solve() throws Error {
|
||||||
if (variable1 == null || variable2 == null) {
|
if (parameter1 == null || parameter2 == null) {
|
||||||
throw new Error(Errors.SYNTAX_ERROR);
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
}
|
}
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
if (variable1.isSolved() & variable2.isSolved()) {
|
if (parameter1.isSimplified() & parameter2.isSimplified()) {
|
||||||
if (((Number) variable2).getTerm().compareTo(new BigDecimal(0)) == 0) {
|
if (((Number) parameter2).getTerm().compareTo(new BigDecimal(0)) == 0) {
|
||||||
result.add(this);
|
result.add(this);
|
||||||
} else {
|
} else {
|
||||||
final Equation e = new Equation(root, null, null);
|
final Equation e = new Equation(mathContext, null, null);
|
||||||
e.setVariable1(new Subtraction(root, variable1, variable2));
|
e.setParameter1(new Subtraction(mathContext, parameter1, parameter2));
|
||||||
e.setVariable2(new Number(root, "0"));
|
e.setParameter2(new Number(mathContext, "0"));
|
||||||
result.add(e);
|
result.add(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,24 +5,24 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionDynamic;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.FunctionMultipleValues;
|
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
|
|
||||||
public class EquationsSystem extends FunctionMultipleValues {
|
public class EquationsSystem extends FunctionDynamic {
|
||||||
static final int spacing = 2;
|
static final int spacing = 2;
|
||||||
|
|
||||||
public EquationsSystem(Calculator root) {
|
public EquationsSystem(MathContext root) {
|
||||||
super(root);
|
super(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EquationsSystem(Calculator root, Function value) {
|
public EquationsSystem(MathContext root, Function value) {
|
||||||
super(root, new Function[] { value });
|
super(root, new Function[] { value });
|
||||||
}
|
}
|
||||||
|
|
||||||
public EquationsSystem(Calculator root, Function[] value) {
|
public EquationsSystem(MathContext root, Function[] value) {
|
||||||
super(root, value);
|
super(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,11 +43,11 @@ public class EquationsSystem extends FunctionMultipleValues {
|
|||||||
public List<Function> solveOneStep() throws Error {
|
public List<Function> solveOneStep() throws Error {
|
||||||
final List<Function> ret = new ArrayList<>();
|
final List<Function> ret = new ArrayList<>();
|
||||||
if (functions.length == 1) {
|
if (functions.length == 1) {
|
||||||
if (functions[0].isSolved()) {
|
if (functions[0].isSimplified()) {
|
||||||
ret.add(functions[0]);
|
ret.add(functions[0]);
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
final List<Function> l = functions[0].solveOneStep();
|
final List<Function> l = functions[0].simplify();
|
||||||
for (final Function f : l) {
|
for (final Function f : l) {
|
||||||
if (f instanceof Number) {
|
if (f instanceof Number) {
|
||||||
ret.add(f);
|
ret.add(f);
|
||||||
@ -59,8 +59,8 @@ public class EquationsSystem extends FunctionMultipleValues {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (final Function f : functions) {
|
for (final Function f : functions) {
|
||||||
if (f.isSolved() == false) {
|
if (f.isSimplified() == false) {
|
||||||
final List<Function> partial = f.solveOneStep();
|
final List<Function> partial = f.simplify();
|
||||||
for (final Function fnc : partial) {
|
for (final Function fnc : partial) {
|
||||||
ret.add(new Expression(root, new Function[] { fnc }));
|
ret.add(new Expression(root, new Function[] { fnc }));
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ public class EquationsSystem extends FunctionMultipleValues {
|
|||||||
public void generateGraphics() {
|
public void generateGraphics() {
|
||||||
for (final Function f : functions) {
|
for (final Function f : functions) {
|
||||||
f.setSmall(false);
|
f.setSmall(false);
|
||||||
f.generateGraphics();
|
f.recomputeDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
width = 0;
|
width = 0;
|
||||||
@ -103,7 +103,7 @@ public class EquationsSystem extends FunctionMultipleValues {
|
|||||||
final int spazioSopra = h - marginBottom;
|
final int spazioSopra = h - marginBottom;
|
||||||
int dy = marginTop;
|
int dy = marginTop;
|
||||||
for (final Function f : functions) {
|
for (final Function f : functions) {
|
||||||
f.draw(x + 5, y + dy);
|
f.draw(x + 5, y + dy, null, null);
|
||||||
dy += f.getHeight() + spacing;
|
dy += f.getHeight() + spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,19 +5,19 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionSingle;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
|
|
||||||
public class EquationsSystemPart extends AnteriorFunction {
|
public class EquationsSystemPart extends FunctionSingle {
|
||||||
|
|
||||||
public EquationsSystemPart(Calculator root, Equation equazione) {
|
public EquationsSystemPart(MathContext root, Equation equazione) {
|
||||||
super(root, equazione);
|
super(root, equazione);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Function NewInstance(Calculator root, Function value) {
|
protected Function NewInstance(MathContext root, Function value) {
|
||||||
return new EquationsSystemPart(root, (Equation) value);
|
return new EquationsSystemPart(root, (Equation) value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,22 +27,22 @@ public class EquationsSystemPart extends AnteriorFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateGraphics() {
|
public void recomputeDimensions() {
|
||||||
variable.setSmall(false);
|
variable.setSmall(false);
|
||||||
variable.generateGraphics();
|
variable.recomputeDimensions();
|
||||||
|
|
||||||
width = 5 + getVariable().getWidth();
|
width = 5 + getParameter().getWidth();
|
||||||
height = 3 + getVariable().getHeight() + 2;
|
height = 3 + getParameter().getHeight() + 2;
|
||||||
line = 3 + getVariable().getLine();
|
line = 3 + getParameter().getLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(int x, int y) {
|
public int draw(int x, int y, boolean small, int caretPos) {
|
||||||
final int h = getHeight() - 1;
|
final int h = getHeight() - 1;
|
||||||
final int paddingTop = 3;
|
final int paddingTop = 3;
|
||||||
final int spazioSotto = (h - 3 - 2) / 2 + paddingTop;
|
final int spazioSotto = (h - 3 - 2) / 2 + paddingTop;
|
||||||
final int spazioSopra = h - spazioSotto;
|
final int spazioSopra = h - spazioSotto;
|
||||||
variable.draw(x + 5, y + paddingTop);
|
variable.draw(x + 5, y + paddingTop, null, null);
|
||||||
DisplayManager.renderer.glDrawLine(x + 2, y + 0, x + 3, y + 0);
|
DisplayManager.renderer.glDrawLine(x + 2, y + 0, x + 3, y + 0);
|
||||||
DisplayManager.renderer.glDrawLine(x + 1, y + 1, x + 1, y + spazioSotto / 2);
|
DisplayManager.renderer.glDrawLine(x + 1, y + 1, x + 1, y + spazioSotto / 2);
|
||||||
DisplayManager.renderer.glDrawLine(x + 2, y + spazioSotto / 2 + 1, x + 2, y + spazioSotto - 1);
|
DisplayManager.renderer.glDrawLine(x + 2, y + spazioSotto / 2 + 1, x + 2, y + spazioSotto - 1);
|
||||||
|
@ -3,19 +3,19 @@ package org.warp.picalculator.math.functions.trigonometry;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionSingle;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
|
|
||||||
public class ArcCosine extends AnteriorFunction {
|
public class ArcCosine extends FunctionSingle {
|
||||||
|
|
||||||
public ArcCosine(Calculator root, Function value) {
|
public ArcCosine(MathContext root, Function value) {
|
||||||
super(root, value);
|
super(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Function NewInstance(Calculator root, Function value) {
|
public Function NewInstance(MathContext root, Function value) {
|
||||||
return new ArcCosine(root, value);
|
return new ArcCosine(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,19 +3,19 @@ package org.warp.picalculator.math.functions.trigonometry;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionSingle;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
|
|
||||||
public class ArcSine extends AnteriorFunction {
|
public class ArcSine extends FunctionSingle {
|
||||||
|
|
||||||
public ArcSine(Calculator root, Function value) {
|
public ArcSine(MathContext root, Function value) {
|
||||||
super(root, value);
|
super(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Function NewInstance(Calculator root, Function value) {
|
public Function NewInstance(MathContext root, Function value) {
|
||||||
return new ArcSine(root, value);
|
return new ArcSine(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,19 +3,19 @@ package org.warp.picalculator.math.functions.trigonometry;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionSingle;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
|
|
||||||
public class ArcTangent extends AnteriorFunction {
|
public class ArcTangent extends FunctionSingle {
|
||||||
|
|
||||||
public ArcTangent(Calculator root, Function value) {
|
public ArcTangent(MathContext root, Function value) {
|
||||||
super(root, value);
|
super(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Function NewInstance(Calculator root, Function value) {
|
public Function NewInstance(MathContext root, Function value) {
|
||||||
return new ArcTangent(root, value);
|
return new ArcTangent(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,19 +3,19 @@ package org.warp.picalculator.math.functions.trigonometry;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionSingle;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
|
|
||||||
public class Cosine extends AnteriorFunction {
|
public class Cosine extends FunctionSingle {
|
||||||
|
|
||||||
public Cosine(Calculator root, Function value) {
|
public Cosine(MathContext root, Function value) {
|
||||||
super(root, value);
|
super(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Function NewInstance(Calculator root, Function value) {
|
public Function NewInstance(MathContext root, Function value) {
|
||||||
return new Cosine(root, value);
|
return new Cosine(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,20 +5,20 @@ import java.util.ArrayList;
|
|||||||
import org.nevec.rjm.BigDecimalMath;
|
import org.nevec.rjm.BigDecimalMath;
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.AngleMode;
|
import org.warp.picalculator.math.AngleMode;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionSingle;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
|
|
||||||
public class Sine extends AnteriorFunction {
|
public class Sine extends FunctionSingle {
|
||||||
|
|
||||||
public Sine(Calculator root, Function value) {
|
public Sine(MathContext root, Function value) {
|
||||||
super(root, value);
|
super(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Function NewInstance(Calculator root, Function value) {
|
public Function NewInstance(MathContext root, Function value) {
|
||||||
return new Sine(root, value);
|
return new Sine(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,12 +30,12 @@ public class Sine extends AnteriorFunction {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean isSolvable() {
|
protected boolean isSolvable() {
|
||||||
if (variable instanceof Number) {
|
if (variable instanceof Number) {
|
||||||
if (root.exactMode == false) {
|
if (mathContext.exactMode == false) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (root.angleMode == AngleMode.DEG) {
|
if (mathContext.angleMode == AngleMode.DEG) {
|
||||||
final Function[] solvableValues = new Function[] { new Number(root, 0), new Number(root, 30), new Number(root, 90), };
|
final Function[] solvableValues = new Function[] { new Number(mathContext, 0), new Number(mathContext, 30), new Number(mathContext, 90), };
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -44,8 +44,8 @@ public class Sine extends AnteriorFunction {
|
|||||||
public ArrayList<Function> solve() throws Error {
|
public ArrayList<Function> solve() throws Error {
|
||||||
final ArrayList<Function> results = new ArrayList<>();
|
final ArrayList<Function> results = new ArrayList<>();
|
||||||
if (variable instanceof Number) {
|
if (variable instanceof Number) {
|
||||||
if (root.exactMode == false) {
|
if (mathContext.exactMode == false) {
|
||||||
results.add(new Number(root, BigDecimalMath.sin(((Number) variable).getTerm())));
|
results.add(new Number(mathContext, BigDecimalMath.sin(((Number) variable).getTerm())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
@ -54,8 +54,8 @@ public class Sine extends AnteriorFunction {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof Sine) {
|
if (o instanceof Sine) {
|
||||||
final AnteriorFunction f = (AnteriorFunction) o;
|
final FunctionSingle f = (FunctionSingle) o;
|
||||||
if (variable.equals(f.getVariable())) {
|
if (variable.equals(f.getParameter())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,19 @@ package org.warp.picalculator.math.functions.trigonometry;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionSingle;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
|
|
||||||
public class Tangent extends AnteriorFunction {
|
public class Tangent extends FunctionSingle {
|
||||||
|
|
||||||
public Tangent(Calculator root, Function value) {
|
public Tangent(MathContext root, Function value) {
|
||||||
super(root, value);
|
super(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Function NewInstance(Calculator root, Function value) {
|
public Function NewInstance(MathContext root, Function value) {
|
||||||
return new Tangent(root, value);
|
return new Tangent(root, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,10 +3,10 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
|
||||||
import org.warp.picalculator.math.functions.Negative;
|
import org.warp.picalculator.math.functions.Negative;
|
||||||
import org.warp.picalculator.math.functions.Subtraction;
|
import org.warp.picalculator.math.functions.Subtraction;
|
||||||
import org.warp.picalculator.math.functions.Sum;
|
import org.warp.picalculator.math.functions.Sum;
|
||||||
@ -25,28 +25,28 @@ public class ExpandRule1 {
|
|||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
if (f instanceof Negative) {
|
if (f instanceof Negative) {
|
||||||
final Negative fnc = (Negative) f;
|
final Negative fnc = (Negative) f;
|
||||||
if (fnc.getVariable() instanceof Expression) {
|
if (fnc.getParameter() instanceof Expression) {
|
||||||
final Expression expr = (Expression) fnc.getVariable();
|
final Expression expr = (Expression) fnc.getParameter();
|
||||||
if (expr.getVariablesLength() == 1) {
|
if (expr.getParametersLength() == 1) {
|
||||||
if (expr.getVariable(0) instanceof Sum) {
|
if (expr.getParameter(0) instanceof Sum) {
|
||||||
return true;
|
return true;
|
||||||
} else if (expr.getVariable(0) instanceof Subtraction) {
|
} else if (expr.getParameter(0) instanceof Subtraction) {
|
||||||
return true;
|
return true;
|
||||||
} else if (expr.getVariable(0) instanceof SumSubtraction) {
|
} else if (expr.getParameter(0) instanceof SumSubtraction) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (f instanceof Subtraction || f instanceof SumSubtraction) {
|
} else if (f instanceof Subtraction || f instanceof SumSubtraction) {
|
||||||
final FunctionTwoValues fnc = (FunctionTwoValues) f;
|
final FunctionOperator fnc = (FunctionOperator) f;
|
||||||
if (fnc.getVariable2() instanceof Expression) {
|
if (fnc.getParameter2() instanceof Expression) {
|
||||||
final Expression expr = (Expression) fnc.getVariable2();
|
final Expression expr = (Expression) fnc.getParameter2();
|
||||||
if (expr.getVariablesLength() == 1) {
|
if (expr.getParametersLength() == 1) {
|
||||||
if (expr.getVariable(0) instanceof Sum) {
|
if (expr.getParameter(0) instanceof Sum) {
|
||||||
return true;
|
return true;
|
||||||
} else if (expr.getVariable(0) instanceof Subtraction) {
|
} else if (expr.getParameter(0) instanceof Subtraction) {
|
||||||
return true;
|
return true;
|
||||||
} else if (expr.getVariable(0) instanceof SumSubtraction) {
|
} else if (expr.getParameter(0) instanceof SumSubtraction) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,15 +57,15 @@ public class ExpandRule1 {
|
|||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
|
|
||||||
Expression expr = null;
|
Expression expr = null;
|
||||||
int fromSubtraction = 0;
|
int fromSubtraction = 0;
|
||||||
FunctionTwoValues subtraction = null;
|
FunctionOperator subtraction = null;
|
||||||
if (f instanceof Negative) {
|
if (f instanceof Negative) {
|
||||||
expr = ((Expression) ((Negative) f).getVariable());
|
expr = ((Expression) ((Negative) f).getParameter());
|
||||||
} else if (f instanceof Subtraction || f instanceof SumSubtraction) {
|
} else if (f instanceof Subtraction || f instanceof SumSubtraction) {
|
||||||
expr = ((Expression) ((FunctionTwoValues) f).getVariable2());
|
expr = ((Expression) ((FunctionOperator) f).getParameter2());
|
||||||
if (f instanceof Subtraction) {
|
if (f instanceof Subtraction) {
|
||||||
fromSubtraction = 1;
|
fromSubtraction = 1;
|
||||||
} else {
|
} else {
|
||||||
@ -77,48 +77,36 @@ public class ExpandRule1 {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final Function fnc = expr.getVariable(0);
|
final Function fnc = expr.getParameter(0);
|
||||||
if (fnc instanceof Sum) {
|
if (fnc instanceof Sum) {
|
||||||
final Function a = ((Sum) fnc).getVariable1();
|
final Function a = ((Sum) fnc).getParameter1();
|
||||||
final Function b = ((Sum) fnc).getVariable2();
|
final Function b = ((Sum) fnc).getParameter2();
|
||||||
final Subtraction fnc2 = new Subtraction(root, null, b);
|
final Subtraction fnc2 = new Subtraction(root, new Negative(root, a), b);
|
||||||
fnc2.setVariable1(new Negative(root, a));
|
|
||||||
if (fromSubtraction > 0) {
|
if (fromSubtraction > 0) {
|
||||||
subtraction = new Subtraction(root, null, null);
|
subtraction = new Subtraction(root, ((FunctionOperator) f).getParameter1(), fnc2);
|
||||||
subtraction.setVariable1(((FunctionTwoValues) f).getVariable1());
|
|
||||||
subtraction.setVariable2(fnc2);
|
|
||||||
result.add(subtraction);
|
result.add(subtraction);
|
||||||
} else {
|
} else {
|
||||||
result.add(fnc2);
|
result.add(fnc2);
|
||||||
}
|
}
|
||||||
} else if (fnc instanceof Subtraction) {
|
} else if (fnc instanceof Subtraction) {
|
||||||
final Function a = ((Subtraction) fnc).getVariable1();
|
final Function a = ((Subtraction) fnc).getParameter1();
|
||||||
final Function b = ((Subtraction) fnc).getVariable2();
|
final Function b = ((Subtraction) fnc).getParameter2();
|
||||||
final Sum fnc2 = new Sum(root, null, b);
|
final Sum fnc2 = new Sum(root, new Negative(root, a), b);
|
||||||
fnc2.setVariable1(new Negative(root, a));
|
|
||||||
if (fromSubtraction > 0) {
|
if (fromSubtraction > 0) {
|
||||||
subtraction = new Subtraction(root, null, null);
|
subtraction = new Subtraction(root, ((FunctionOperator) f).getParameter1(), fnc2);
|
||||||
subtraction.setVariable1(((FunctionTwoValues) f).getVariable1());
|
|
||||||
subtraction.setVariable2(fnc2);
|
|
||||||
result.add(subtraction);
|
result.add(subtraction);
|
||||||
} else {
|
} else {
|
||||||
result.add(fnc2);
|
result.add(fnc2);
|
||||||
}
|
}
|
||||||
} else if (fnc instanceof SumSubtraction) {
|
} else if (fnc instanceof SumSubtraction) {
|
||||||
final Function a = ((SumSubtraction) fnc).getVariable1();
|
final Function a = ((SumSubtraction) fnc).getParameter1();
|
||||||
final Function b = ((SumSubtraction) fnc).getVariable2();
|
final Function b = ((SumSubtraction) fnc).getParameter2();
|
||||||
final Sum fnc2 = new Sum(root, null, b);
|
final Sum fnc2 = new Sum(root, new Negative(root, a), b);
|
||||||
fnc2.setVariable1(new Negative(root, a));
|
final Subtraction fnc3 = new Subtraction(root, new Negative(root, a), b);
|
||||||
final Subtraction fnc3 = new Subtraction(root, null, b);
|
|
||||||
fnc3.setVariable1(new Negative(root, a));
|
|
||||||
if (fromSubtraction > 0) {
|
if (fromSubtraction > 0) {
|
||||||
subtraction = new SumSubtraction(root, null, null);
|
subtraction = new SumSubtraction(root, ((FunctionOperator) f).getParameter1(), fnc2);
|
||||||
subtraction.setVariable1(((FunctionTwoValues) f).getVariable1());
|
|
||||||
subtraction.setVariable2(fnc2);
|
|
||||||
result.add(subtraction);
|
result.add(subtraction);
|
||||||
subtraction = new SumSubtraction(root, null, null);
|
subtraction = new SumSubtraction(root, ((FunctionOperator) f).getParameter1(), fnc3);
|
||||||
subtraction.setVariable1(((FunctionTwoValues) f).getVariable1());
|
|
||||||
subtraction.setVariable2(fnc3);
|
|
||||||
result.add(subtraction);
|
result.add(subtraction);
|
||||||
result.add(subtraction);
|
result.add(subtraction);
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Negative;
|
import org.warp.picalculator.math.functions.Negative;
|
||||||
import org.warp.picalculator.math.functions.Subtraction;
|
import org.warp.picalculator.math.functions.Subtraction;
|
||||||
|
|
||||||
@ -20,15 +20,15 @@ public class ExpandRule5 {
|
|||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
if (f instanceof Negative) {
|
if (f instanceof Negative) {
|
||||||
final Negative fnc = (Negative) f;
|
final Negative fnc = (Negative) f;
|
||||||
if (fnc.getVariable() instanceof Expression) {
|
if (fnc.getParameter() instanceof Expression) {
|
||||||
final Expression e = (Expression) fnc.getVariable();
|
final Expression e = (Expression) fnc.getParameter();
|
||||||
return e.getVariablesLength() == 1 && e.getVariable(0) instanceof Negative;
|
return e.getParametersLength() == 1 && e.getParameter(0) instanceof Negative;
|
||||||
}
|
}
|
||||||
} else if (f instanceof Subtraction) {
|
} else if (f instanceof Subtraction) {
|
||||||
final Subtraction fnc = (Subtraction) f;
|
final Subtraction fnc = (Subtraction) f;
|
||||||
if (fnc.getVariable2() instanceof Expression) {
|
if (fnc.getParameter2() instanceof Expression) {
|
||||||
final Expression e = (Expression) fnc.getVariable2();
|
final Expression e = (Expression) fnc.getParameter2();
|
||||||
return e.getVariablesLength() == 1 && e.getVariable(0) instanceof Negative;
|
return e.getParametersLength() == 1 && e.getParameter(0) instanceof Negative;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -40,10 +40,10 @@ public class ExpandRule5 {
|
|||||||
|
|
||||||
if (f instanceof Negative) {
|
if (f instanceof Negative) {
|
||||||
final Negative fnc = (Negative) f;
|
final Negative fnc = (Negative) f;
|
||||||
result.add(((Negative) ((Expression) fnc.getVariable()).getVariable(0)).getVariable());
|
result.add(((Negative) ((Expression) fnc.getParameter()).getParameter(0)).getParameter());
|
||||||
} else if (f instanceof Subtraction) {
|
} else if (f instanceof Subtraction) {
|
||||||
final Subtraction fnc = (Subtraction) f;
|
final Subtraction fnc = (Subtraction) f;
|
||||||
result.add(((Negative) ((Expression) fnc.getVariable2()).getVariable(0)).getVariable());
|
result.add(((Negative) ((Expression) fnc.getParameter2()).getParameter(0)).getParameter());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Power;
|
import org.warp.picalculator.math.functions.Power;
|
||||||
|
|
||||||
@ -19,15 +19,15 @@ public class ExponentRule1 {
|
|||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Power fnc = (Power) f;
|
final Power fnc = (Power) f;
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
if (fnc.getVariable1().equals(new Number(root, 1))) {
|
if (fnc.getParameter1().equals(new Number(root, 1))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
result.add(new Number(root, 1));
|
result.add(new Number(root, 1));
|
||||||
return result;
|
return result;
|
||||||
|
@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Power;
|
import org.warp.picalculator.math.functions.Power;
|
||||||
@ -21,23 +21,20 @@ public class ExponentRule15 {
|
|||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Multiplication fnc = (Multiplication) f;
|
final Multiplication fnc = (Multiplication) f;
|
||||||
if (fnc.getVariable1().equals(fnc.getVariable2())) {
|
if (fnc.getParameter1().equals(fnc.getParameter2())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final Multiplication fnc = (Multiplication) f;
|
final Multiplication fnc = (Multiplication) f;
|
||||||
final Power p = new Power(root, null, null);
|
final Function a = fnc.getParameter1();
|
||||||
final Expression expr = new Expression(root);
|
final Expression expr = new Expression(root, a);
|
||||||
final Function a = fnc.getVariable1();
|
|
||||||
expr.addFunctionToEnd(a);
|
|
||||||
final Number two = new Number(root, 2);
|
final Number two = new Number(root, 2);
|
||||||
p.setVariable1(expr);
|
final Power p = new Power(root, expr, two);
|
||||||
p.setVariable2(two);
|
|
||||||
result.add(p);
|
result.add(p);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Power;
|
import org.warp.picalculator.math.functions.Power;
|
||||||
@ -22,26 +22,26 @@ public class ExponentRule16 {
|
|||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Multiplication fnc = (Multiplication) f;
|
final Multiplication fnc = (Multiplication) f;
|
||||||
if (fnc.getVariable1() instanceof Power && fnc.getVariable2() instanceof Power) {
|
if (fnc.getParameter1() instanceof Power && fnc.getParameter2() instanceof Power) {
|
||||||
return ((Power)fnc.getVariable1()).getVariable1().equals(((Power)fnc.getVariable2()).getVariable1());
|
return ((Power)fnc.getParameter1()).getParameter1().equals(((Power)fnc.getParameter2()).getParameter1());
|
||||||
} else if (fnc.getVariable1() instanceof Power) {
|
} else if (fnc.getParameter1() instanceof Power) {
|
||||||
return ((Power)fnc.getVariable1()).getVariable1().equals(fnc.getVariable2());
|
return ((Power)fnc.getParameter1()).getParameter1().equals(fnc.getParameter2());
|
||||||
} else if (fnc.getVariable2() instanceof Power) {
|
} else if (fnc.getParameter2() instanceof Power) {
|
||||||
return ((Power)fnc.getVariable2()).getVariable1().equals(fnc.getVariable1());
|
return ((Power)fnc.getParameter2()).getParameter1().equals(fnc.getParameter1());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final Multiplication fnc = (Multiplication) f;
|
final Multiplication fnc = (Multiplication) f;
|
||||||
if (fnc.getVariable1() instanceof Power && fnc.getVariable2() instanceof Power) {
|
if (fnc.getParameter1() instanceof Power && fnc.getParameter2() instanceof Power) {
|
||||||
result.add(new Power(root, ((Power)fnc.getVariable1()).getVariable1(), new Sum(root, new Expression(root, ((Power)fnc.getVariable1()).getVariable2()), new Expression(root, ((Power)fnc.getVariable2()).getVariable2()))));
|
result.add(new Power(root, ((Power)fnc.getParameter1()).getParameter1(), new Sum(root, new Expression(root, ((Power)fnc.getParameter1()).getParameter2()), new Expression(root, ((Power)fnc.getParameter2()).getParameter2()))));
|
||||||
} else if (fnc.getVariable1() instanceof Power) {
|
} else if (fnc.getParameter1() instanceof Power) {
|
||||||
result.add(new Power(root, ((Power)fnc.getVariable1()).getVariable1(), new Sum(root, new Expression(root, ((Power)fnc.getVariable1()).getVariable2()), new Number(root, 1))));
|
result.add(new Power(root, ((Power)fnc.getParameter1()).getParameter1(), new Sum(root, new Expression(root, ((Power)fnc.getParameter1()).getParameter2()), new Number(root, 1))));
|
||||||
} else if (fnc.getVariable2() instanceof Power) {
|
} else if (fnc.getParameter2() instanceof Power) {
|
||||||
result.add(new Power(root, ((Power)fnc.getVariable1()).getVariable1(), new Sum(root, new Number(root, 1), new Expression(root, ((Power)fnc.getVariable2()).getVariable2()))));
|
result.add(new Power(root, ((Power)fnc.getParameter1()).getParameter1(), new Sum(root, new Number(root, 1), new Expression(root, ((Power)fnc.getParameter2()).getParameter2()))));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Power;
|
import org.warp.picalculator.math.functions.Power;
|
||||||
@ -23,7 +23,7 @@ public class ExponentRule17 {
|
|||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
if (f instanceof Root) {
|
if (f instanceof Root) {
|
||||||
final Root fnc = (Root) f;
|
final Root fnc = (Root) f;
|
||||||
if (fnc.getVariable1().equals(fnc.getVariable2())) {
|
if (fnc.getParameter1().equals(fnc.getParameter2())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,16 +31,13 @@ public class ExponentRule17 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final Multiplication fnc = (Multiplication) f;
|
final Multiplication fnc = (Multiplication) f;
|
||||||
final Power p = new Power(fnc.getRoot(), null, null);
|
final Function a = fnc.getParameter1();
|
||||||
final Expression expr = new Expression(root);
|
final Expression expr = new Expression(root, a);
|
||||||
final Function a = fnc.getVariable1();
|
|
||||||
expr.addFunctionToEnd(a);
|
|
||||||
final Number two = new Number(root, 2);
|
final Number two = new Number(root, 2);
|
||||||
p.setVariable1(expr);
|
final Power p = new Power(fnc.getMathContext(), expr, two);
|
||||||
p.setVariable2(two);
|
|
||||||
result.add(p);
|
result.add(p);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Power;
|
import org.warp.picalculator.math.functions.Power;
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ public class ExponentRule2 {
|
|||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Power fnc = (Power) f;
|
final Power fnc = (Power) f;
|
||||||
if (fnc.getVariable2().equals(new Number(f.getRoot(), 1))) {
|
if (fnc.getParameter2().equals(new Number(f.getMathContext(), 1))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -26,7 +26,7 @@ public class ExponentRule2 {
|
|||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
result.add(((Power) f).getVariable1());
|
result.add(((Power) f).getParameter1());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Power;
|
import org.warp.picalculator.math.functions.Power;
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ public class ExponentRule3 {
|
|||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Power fnc = (Power) f;
|
final Power fnc = (Power) f;
|
||||||
if (fnc.getVariable2().equals(new Number(f.getRoot(), 0))) {
|
if (fnc.getParameter2().equals(new Number(f.getMathContext(), 0))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -26,7 +26,7 @@ public class ExponentRule3 {
|
|||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
result.add(new Number(f.getRoot(), 1));
|
result.add(new Number(f.getMathContext(), 1));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Power;
|
import org.warp.picalculator.math.functions.Power;
|
||||||
@ -21,34 +21,26 @@ public class ExponentRule4 {
|
|||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Power fnc = (Power) f;
|
final Power fnc = (Power) f;
|
||||||
if (fnc.getVariable1() instanceof Expression && ((Expression) fnc.getVariable1()).getVariablesLength() == 1 && ((Expression) fnc.getVariable1()).getVariable(0) instanceof Multiplication && fnc.getVariable2() instanceof Number) {
|
if (fnc.getParameter1() instanceof Expression && ((Expression) fnc.getParameter1()).getParametersLength() == 1 && ((Expression) fnc.getParameter1()).getParameter(0) instanceof Multiplication && fnc.getParameter2() instanceof Number) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final Power fnc = (Power) f;
|
final Power fnc = (Power) f;
|
||||||
final Expression expr = (Expression) fnc.getVariable1();
|
final Expression expr = (Expression) fnc.getParameter1();
|
||||||
final Multiplication mult = (Multiplication) expr.getVariable(0);
|
final Multiplication mult = (Multiplication) expr.getParameter(0);
|
||||||
final Function a = mult.getVariable1();
|
final Function a = mult.getParameter1();
|
||||||
final Function b = mult.getVariable2();
|
final Function b = mult.getParameter2();
|
||||||
final Number n = (Number) fnc.getVariable2();
|
final Number n = (Number) fnc.getParameter2();
|
||||||
final Multiplication retMult = new Multiplication(root, null, null);
|
final Expression e1 = new Expression(root, a);
|
||||||
final Power p1 = new Power(root, null, null);
|
final Power p1 = new Power(root, e1, n);
|
||||||
final Expression e1 = new Expression(root);
|
final Expression e2 = new Expression(root, b);
|
||||||
e1.addFunctionToEnd(a);
|
final Power p2 = new Power(root, e2, n);
|
||||||
p1.setVariable1(e1);
|
final Multiplication retMult = new Multiplication(root, p1, p2);
|
||||||
p1.setVariable2(n);
|
|
||||||
final Power p2 = new Power(root, null, null);
|
|
||||||
final Expression e2 = new Expression(root);
|
|
||||||
e2.addFunctionToEnd(b);
|
|
||||||
p2.setVariable1(e2);
|
|
||||||
p2.setVariable2(n);
|
|
||||||
retMult.setVariable1(p1);
|
|
||||||
retMult.setVariable2(p2);
|
|
||||||
result.add(retMult);
|
result.add(retMult);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Power;
|
import org.warp.picalculator.math.functions.Power;
|
||||||
@ -21,18 +21,18 @@ public class ExponentRule9 {
|
|||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Power fnc = (Power) f;
|
final Power fnc = (Power) f;
|
||||||
if (fnc.getVariable1() instanceof Power) {
|
if (fnc.getParameter1() instanceof Power) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final Power powC = (Power) f;
|
final Power powC = (Power) f;
|
||||||
final Power powB = (Power) powC.getVariable1();
|
final Power powB = (Power) powC.getParameter1();
|
||||||
final Power p = new Power(root, powB.getVariable1(), new Multiplication(root, new Expression(root, powB.getVariable2()), new Expression(root, powC.getVariable2())));
|
final Power p = new Power(root, powB.getParameter1(), new Multiplication(root, new Expression(root, powB.getParameter2()), new Expression(root, powC.getParameter2())));
|
||||||
result.add(p);
|
result.add(p);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Division;
|
import org.warp.picalculator.math.functions.Division;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,13 +18,13 @@ import org.warp.picalculator.math.functions.Number;
|
|||||||
public class FractionsRule1 {
|
public class FractionsRule1 {
|
||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final Division fnc = (Division) f;
|
final Division fnc = (Division) f;
|
||||||
if (fnc.getVariable1() instanceof Number) {
|
if (fnc.getParameter1() instanceof Number) {
|
||||||
final Number numb1 = (Number) fnc.getVariable1();
|
final Number numb1 = (Number) fnc.getParameter1();
|
||||||
if (numb1.equals(new Number(root, 0))) {
|
if (numb1.equals(new Number(root, 0))) {
|
||||||
if (fnc.getVariable2() instanceof Number) {
|
if (fnc.getParameter2() instanceof Number) {
|
||||||
final Number numb2 = (Number) fnc.getVariable2();
|
final Number numb2 = (Number) fnc.getParameter2();
|
||||||
if (numb2.equals(new Number(root, 0))) {
|
if (numb2.equals(new Number(root, 0))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ public class FractionsRule1 {
|
|||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
result.add(new Number(f.getRoot(), 0));
|
result.add(new Number(f.getMathContext(), 0));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Division;
|
import org.warp.picalculator.math.functions.Division;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,14 +22,14 @@ public class FractionsRule11 {
|
|||||||
Function a;
|
Function a;
|
||||||
Function c;
|
Function c;
|
||||||
Division div2;
|
Division div2;
|
||||||
if (fnc.getVariable2() instanceof Division) {
|
if (fnc.getParameter2() instanceof Division) {
|
||||||
div2 = (Division) fnc.getVariable2();
|
div2 = (Division) fnc.getParameter2();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
a = fnc.getVariable1();
|
a = fnc.getParameter1();
|
||||||
c = div2.getVariable2();
|
c = div2.getParameter2();
|
||||||
return new Multiplication(fnc.getRoot(), a, c).isSolved() == false;
|
return new Multiplication(fnc.getMathContext(), a, c).isSimplified() == false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
@ -39,12 +39,12 @@ public class FractionsRule11 {
|
|||||||
Function b;
|
Function b;
|
||||||
Function c;
|
Function c;
|
||||||
|
|
||||||
Division div2 = (Division) fnc.getVariable2();
|
Division div2 = (Division) fnc.getParameter2();
|
||||||
|
|
||||||
a = fnc.getVariable1();
|
a = fnc.getParameter1();
|
||||||
b = div2.getVariable1();
|
b = div2.getParameter1();
|
||||||
c = div2.getVariable2();
|
c = div2.getParameter2();
|
||||||
result.add(new Division(fnc.getRoot(), new Multiplication(fnc.getRoot(), new Expression(fnc.getRoot(), a), new Expression(fnc.getRoot(), c)), b));
|
result.add(new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), new Expression(fnc.getMathContext(), a), new Expression(fnc.getMathContext(), c)), b));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Division;
|
import org.warp.picalculator.math.functions.Division;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,11 +21,11 @@ public class FractionsRule12 {
|
|||||||
final Division fnc = (Division) f;
|
final Division fnc = (Division) f;
|
||||||
Function a;
|
Function a;
|
||||||
Function c;
|
Function c;
|
||||||
if (fnc.getVariable1() instanceof Division) {
|
if (fnc.getParameter1() instanceof Division) {
|
||||||
final Division div2 = (Division) fnc.getVariable1();
|
final Division div2 = (Division) fnc.getParameter1();
|
||||||
a = fnc.getVariable1();
|
a = fnc.getParameter1();
|
||||||
c = div2.getVariable2();
|
c = div2.getParameter2();
|
||||||
return new Multiplication(fnc.getRoot(), a, c).isSolved() == false;
|
return new Multiplication(fnc.getMathContext(), a, c).isSimplified() == false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -37,11 +37,11 @@ public class FractionsRule12 {
|
|||||||
Function b;
|
Function b;
|
||||||
Function c;
|
Function c;
|
||||||
|
|
||||||
final Division div2 = (Division) fnc.getVariable1();
|
final Division div2 = (Division) fnc.getParameter1();
|
||||||
a = fnc.getVariable2();
|
a = fnc.getParameter2();
|
||||||
b = div2.getVariable1();
|
b = div2.getParameter1();
|
||||||
c = div2.getVariable2();
|
c = div2.getParameter2();
|
||||||
result.add(new Division(fnc.getRoot(), new Multiplication(fnc.getRoot(), new Expression(fnc.getRoot(), a), new Expression(fnc.getRoot(), c)), b));
|
result.add(new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), new Expression(fnc.getMathContext(), a), new Expression(fnc.getMathContext(), c)), b));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Division;
|
import org.warp.picalculator.math.functions.Division;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,26 +23,26 @@ public class FractionsRule14 {
|
|||||||
Function b;
|
Function b;
|
||||||
Function c;
|
Function c;
|
||||||
Function d;
|
Function d;
|
||||||
if (fnc.getVariable1() instanceof Division && fnc.getVariable2() instanceof Division) {
|
if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Division) {
|
||||||
final Division div1 = (Division) fnc.getVariable1();
|
final Division div1 = (Division) fnc.getParameter1();
|
||||||
final Division div2 = (Division) fnc.getVariable2();
|
final Division div2 = (Division) fnc.getParameter2();
|
||||||
a = div1.getVariable1();
|
a = div1.getParameter1();
|
||||||
b = div1.getVariable2();
|
b = div1.getParameter2();
|
||||||
c = div2.getVariable1();
|
c = div2.getParameter1();
|
||||||
d = div2.getVariable2();
|
d = div2.getParameter2();
|
||||||
return new Multiplication(f.getRoot(), a, c).isSolved() == false || new Multiplication(f.getRoot(), b, d).isSolved() == false;
|
return new Multiplication(f.getMathContext(), a, c).isSimplified() == false || new Multiplication(f.getMathContext(), b, d).isSimplified() == false;
|
||||||
} else if (fnc.getVariable1() instanceof Division) {
|
} else if (fnc.getParameter1() instanceof Division) {
|
||||||
final Division div1 = (Division) fnc.getVariable1();
|
final Division div1 = (Division) fnc.getParameter1();
|
||||||
a = div1.getVariable1();
|
a = div1.getParameter1();
|
||||||
b = div1.getVariable2();
|
b = div1.getParameter2();
|
||||||
c = fnc.getVariable2();
|
c = fnc.getParameter2();
|
||||||
return new Multiplication(f.getRoot(), a, c).isSolved() == false;
|
return new Multiplication(f.getMathContext(), a, c).isSimplified() == false;
|
||||||
} else if (fnc.getVariable2() instanceof Division) {
|
} else if (fnc.getParameter2() instanceof Division) {
|
||||||
final Division div2 = (Division) fnc.getVariable2();
|
final Division div2 = (Division) fnc.getParameter2();
|
||||||
a = fnc.getVariable1();
|
a = fnc.getParameter1();
|
||||||
c = div2.getVariable1();
|
c = div2.getParameter1();
|
||||||
d = div2.getVariable2();
|
d = div2.getParameter2();
|
||||||
return new Multiplication(f.getRoot(), a, c).isSolved() == false;
|
return new Multiplication(f.getMathContext(), a, c).isSimplified() == false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -55,28 +55,28 @@ public class FractionsRule14 {
|
|||||||
Function c;
|
Function c;
|
||||||
Function d;
|
Function d;
|
||||||
|
|
||||||
if (fnc.getVariable1() instanceof Division && fnc.getVariable2() instanceof Division) {
|
if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Division) {
|
||||||
final Division div1 = (Division) fnc.getVariable1();
|
final Division div1 = (Division) fnc.getParameter1();
|
||||||
final Division div2 = (Division) fnc.getVariable2();
|
final Division div2 = (Division) fnc.getParameter2();
|
||||||
a = div1.getVariable1();
|
a = div1.getParameter1();
|
||||||
b = div1.getVariable2();
|
b = div1.getParameter2();
|
||||||
c = div2.getVariable1();
|
c = div2.getParameter1();
|
||||||
d = div2.getVariable2();
|
d = div2.getParameter2();
|
||||||
final Division div = new Division(fnc.getRoot(), new Multiplication(fnc.getRoot(), new Expression(fnc.getRoot(), a), new Expression(fnc.getRoot(), c)), new Multiplication(fnc.getRoot(), new Expression(fnc.getRoot(), b), new Expression(fnc.getRoot(), d)));
|
final Division div = new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), new Expression(fnc.getMathContext(), a), new Expression(fnc.getMathContext(), c)), new Multiplication(fnc.getMathContext(), new Expression(fnc.getMathContext(), b), new Expression(fnc.getMathContext(), d)));
|
||||||
result.add(div);
|
result.add(div);
|
||||||
} else if (fnc.getVariable1() instanceof Division) {
|
} else if (fnc.getParameter1() instanceof Division) {
|
||||||
final Division div1 = (Division) fnc.getVariable1();
|
final Division div1 = (Division) fnc.getParameter1();
|
||||||
a = div1.getVariable1();
|
a = div1.getParameter1();
|
||||||
b = div1.getVariable2();
|
b = div1.getParameter2();
|
||||||
c = fnc.getVariable2();
|
c = fnc.getParameter2();
|
||||||
final Division div = new Division(fnc.getRoot(), new Multiplication(fnc.getRoot(), new Expression(fnc.getRoot(), a), new Expression(fnc.getRoot(), c)), b);
|
final Division div = new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), new Expression(fnc.getMathContext(), a), new Expression(fnc.getMathContext(), c)), b);
|
||||||
result.add(div);
|
result.add(div);
|
||||||
} else if (fnc.getVariable2() instanceof Division) {
|
} else if (fnc.getParameter2() instanceof Division) {
|
||||||
final Division div2 = (Division) fnc.getVariable2();
|
final Division div2 = (Division) fnc.getParameter2();
|
||||||
a = fnc.getVariable1();
|
a = fnc.getParameter1();
|
||||||
c = div2.getVariable1();
|
c = div2.getParameter1();
|
||||||
d = div2.getVariable2();
|
d = div2.getParameter2();
|
||||||
final Division div = new Division(fnc.getRoot(), new Multiplication(fnc.getRoot(), new Expression(fnc.getRoot(), a), new Expression(fnc.getRoot(), c)), d);
|
final Division div = new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), new Expression(fnc.getMathContext(), a), new Expression(fnc.getMathContext(), c)), d);
|
||||||
result.add(div);
|
result.add(div);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Division;
|
import org.warp.picalculator.math.functions.Division;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,9 +18,9 @@ public class FractionsRule2 {
|
|||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Division fnc = (Division) f;
|
final Division fnc = (Division) f;
|
||||||
if (fnc.getVariable2() instanceof Number) {
|
if (fnc.getParameter2() instanceof Number) {
|
||||||
final Number numb = (Number) fnc.getVariable2();
|
final Number numb = (Number) fnc.getParameter2();
|
||||||
if (numb.equals(new Number(f.getRoot(), 1))) {
|
if (numb.equals(new Number(f.getMathContext(), 1))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ public class FractionsRule2 {
|
|||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final Division fnc = (Division) f;
|
final Division fnc = (Division) f;
|
||||||
result.add(fnc.getVariable1());
|
result.add(fnc.getParameter1());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Division;
|
import org.warp.picalculator.math.functions.Division;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,7 +18,7 @@ public class FractionsRule3 {
|
|||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Division fnc = (Division) f;
|
final Division fnc = (Division) f;
|
||||||
if (fnc.getVariable1().equals(fnc.getVariable2())) {
|
if (fnc.getParameter1().equals(fnc.getParameter2())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -26,7 +26,7 @@ public class FractionsRule3 {
|
|||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
result.add(new Number(f.getRoot(), 1));
|
result.add(new Number(f.getMathContext(), 1));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Division;
|
import org.warp.picalculator.math.functions.Division;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Power;
|
import org.warp.picalculator.math.functions.Power;
|
||||||
|
|
||||||
@ -19,9 +19,9 @@ public class FractionsRule4 {
|
|||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Power fnc = (Power) f;
|
final Power fnc = (Power) f;
|
||||||
if (fnc.getVariable1() instanceof Division && fnc.getVariable2() instanceof Number) {
|
if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Number) {
|
||||||
final Number n2 = (Number) fnc.getVariable2();
|
final Number n2 = (Number) fnc.getParameter2();
|
||||||
if (n2.equals(new Number(f.getRoot(), -1))) {
|
if (n2.equals(new Number(f.getMathContext(), -1))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,9 +31,9 @@ public class FractionsRule4 {
|
|||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final Power fnc = (Power) f;
|
final Power fnc = (Power) f;
|
||||||
final Function a = ((Division) fnc.getVariable1()).getVariable1();
|
final Function a = ((Division) fnc.getParameter1()).getParameter1();
|
||||||
final Function b = ((Division) fnc.getVariable1()).getVariable2();
|
final Function b = ((Division) fnc.getParameter1()).getParameter2();
|
||||||
final Division res = new Division(f.getRoot(), b, a);
|
final Division res = new Division(f.getMathContext(), b, a);
|
||||||
result.add(res);
|
result.add(res);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,9 @@ import java.math.BigDecimal;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Division;
|
import org.warp.picalculator.math.functions.Division;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Power;
|
import org.warp.picalculator.math.functions.Power;
|
||||||
|
|
||||||
@ -21,8 +21,8 @@ public class FractionsRule5 {
|
|||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Power fnc = (Power) f;
|
final Power fnc = (Power) f;
|
||||||
if (fnc.getVariable1() instanceof Division && fnc.getVariable2() instanceof Number) {
|
if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Number) {
|
||||||
final Number n2 = (Number) fnc.getVariable2();
|
final Number n2 = (Number) fnc.getParameter2();
|
||||||
if (n2.getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
if (n2.getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -31,12 +31,12 @@ public class FractionsRule5 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final Power fnc = (Power) f;
|
final Power fnc = (Power) f;
|
||||||
final Function a = ((Division) fnc.getVariable1()).getVariable1();
|
final Function a = ((Division) fnc.getParameter1()).getParameter1();
|
||||||
final Function b = ((Division) fnc.getVariable1()).getVariable2();
|
final Function b = ((Division) fnc.getParameter1()).getParameter2();
|
||||||
final Function c = ((Number) fnc.getVariable2()).multiply(new Number(root, "-1"));
|
final Function c = ((Number) fnc.getParameter2()).multiply(new Number(root, "-1"));
|
||||||
final Division dv = new Division(root, b, a);
|
final Division dv = new Division(root, b, a);
|
||||||
final Power pow = new Power(root, dv, c);
|
final Power pow = new Power(root, dv, c);
|
||||||
result.add(pow);
|
result.add(pow);
|
||||||
|
@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
|
|
||||||
@ -18,16 +18,16 @@ import org.warp.picalculator.math.functions.Number;
|
|||||||
public class NumberRule1 {
|
public class NumberRule1 {
|
||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final Multiplication mult = (Multiplication) f;
|
final Multiplication mult = (Multiplication) f;
|
||||||
if (mult.getVariable1() instanceof Number) {
|
if (mult.getParameter1() instanceof Number) {
|
||||||
final Number numb = (Number) mult.getVariable1();
|
final Number numb = (Number) mult.getParameter1();
|
||||||
if (numb.equals(new Number(root, 0))) {
|
if (numb.equals(new Number(root, 0))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mult.getVariable2() instanceof Number) {
|
if (mult.getParameter2() instanceof Number) {
|
||||||
final Number numb = (Number) mult.getVariable2();
|
final Number numb = (Number) mult.getParameter2();
|
||||||
if (numb.equals(new Number(root, 0))) {
|
if (numb.equals(new Number(root, 0))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ public class NumberRule1 {
|
|||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
result.add(new Number(f.getRoot(), "0"));
|
result.add(new Number(f.getMathContext(), "0"));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
|
|
||||||
@ -18,16 +18,16 @@ import org.warp.picalculator.math.functions.Number;
|
|||||||
public class NumberRule2 {
|
public class NumberRule2 {
|
||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final Multiplication mult = (Multiplication) f;
|
final Multiplication mult = (Multiplication) f;
|
||||||
if (mult.getVariable1() instanceof Number) {
|
if (mult.getParameter1() instanceof Number) {
|
||||||
final Number numb = (Number) mult.getVariable1();
|
final Number numb = (Number) mult.getParameter1();
|
||||||
if (numb.equals(new Number(root, 1))) {
|
if (numb.equals(new Number(root, 1))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mult.getVariable2() instanceof Number) {
|
if (mult.getParameter2() instanceof Number) {
|
||||||
final Number numb = (Number) mult.getVariable2();
|
final Number numb = (Number) mult.getParameter2();
|
||||||
if (numb.equals(new Number(root, 1))) {
|
if (numb.equals(new Number(root, 1))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -36,22 +36,22 @@ public class NumberRule2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
Function a = null;
|
Function a = null;
|
||||||
boolean aFound = false;
|
boolean aFound = false;
|
||||||
final Multiplication mult = (Multiplication) f;
|
final Multiplication mult = (Multiplication) f;
|
||||||
if (aFound == false & mult.getVariable1() instanceof Number) {
|
if (aFound == false & mult.getParameter1() instanceof Number) {
|
||||||
final Number numb = (Number) mult.getVariable1();
|
final Number numb = (Number) mult.getParameter1();
|
||||||
if (numb.equals(new Number(root, 1))) {
|
if (numb.equals(new Number(root, 1))) {
|
||||||
a = mult.getVariable2();
|
a = mult.getParameter2();
|
||||||
aFound = true;
|
aFound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (aFound == false && mult.getVariable2() instanceof Number) {
|
if (aFound == false && mult.getParameter2() instanceof Number) {
|
||||||
final Number numb = (Number) mult.getVariable2();
|
final Number numb = (Number) mult.getParameter2();
|
||||||
if (numb.equals(new Number(root, 1))) {
|
if (numb.equals(new Number(root, 1))) {
|
||||||
a = mult.getVariable1();
|
a = mult.getParameter1();
|
||||||
aFound = true;
|
aFound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Negative;
|
import org.warp.picalculator.math.functions.Negative;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
@ -26,20 +26,20 @@ public class NumberRule3 {
|
|||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
if (f instanceof Subtraction) {
|
if (f instanceof Subtraction) {
|
||||||
final Subtraction sub = (Subtraction) f;
|
final Subtraction sub = (Subtraction) f;
|
||||||
if (sub.getVariable1().equals(sub.getVariable2())) {
|
if (sub.getParameter1().equals(sub.getParameter2())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (f instanceof Sum) {
|
} else if (f instanceof Sum) {
|
||||||
final Sum sub = (Sum) f;
|
final Sum sub = (Sum) f;
|
||||||
if (sub.getVariable1() instanceof Negative) {
|
if (sub.getParameter1() instanceof Negative) {
|
||||||
final Negative neg = (Negative) sub.getVariable1();
|
final Negative neg = (Negative) sub.getParameter1();
|
||||||
if (neg.getVariable().equals(sub.getVariable2())) {
|
if (neg.getParameter().equals(sub.getParameter2())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (f instanceof SumSubtraction) {
|
} else if (f instanceof SumSubtraction) {
|
||||||
final SumSubtraction sub = (SumSubtraction) f;
|
final SumSubtraction sub = (SumSubtraction) f;
|
||||||
if (sub.getVariable1().equals(sub.getVariable2())) {
|
if (sub.getParameter1().equals(sub.getParameter2())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,12 +47,10 @@ public class NumberRule3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
if (f instanceof SumSubtraction) {
|
if (f instanceof SumSubtraction) {
|
||||||
final Multiplication mul = new Multiplication(root, null, null);
|
final Multiplication mul = new Multiplication(root, new Number(root, 2), f);
|
||||||
mul.setVariable1(new Number(root, 2));
|
|
||||||
mul.setVariable2(f);
|
|
||||||
result.add(mul);
|
result.add(mul);
|
||||||
}
|
}
|
||||||
result.add(new Number(root, 0));
|
result.add(new Number(root, 0));
|
||||||
|
@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Subtraction;
|
import org.warp.picalculator.math.functions.Subtraction;
|
||||||
import org.warp.picalculator.math.functions.Sum;
|
import org.warp.picalculator.math.functions.Sum;
|
||||||
import org.warp.picalculator.math.functions.SumSubtraction;
|
import org.warp.picalculator.math.functions.SumSubtraction;
|
||||||
@ -26,11 +26,11 @@ public class NumberRule4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final SumSubtraction ss = (SumSubtraction) f;
|
final SumSubtraction ss = (SumSubtraction) f;
|
||||||
result.add(new Sum(root, ss.getVariable1(), ss.getVariable2()));
|
result.add(new Sum(root, ss.getParameter1(), ss.getParameter2()));
|
||||||
result.add(new Subtraction(root, ss.getVariable1(), ss.getVariable2()));
|
result.add(new Subtraction(root, ss.getParameter1(), ss.getParameter2()));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,21 +23,21 @@ import org.warp.picalculator.math.functions.Number;
|
|||||||
public class NumberRule5 {
|
public class NumberRule5 {
|
||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final FunctionTwoValues fnc = (FunctionTwoValues) f;
|
final FunctionOperator fnc = (FunctionOperator) f;
|
||||||
if (fnc.getVariable1().equals(new Number(root, 0)) || fnc.getVariable2().equals(new Number(root, 0))) {
|
if (fnc.getParameter1().equals(new Number(root, 0)) || fnc.getParameter2().equals(new Number(root, 0))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final FunctionTwoValues fnc = (FunctionTwoValues) f;
|
final FunctionOperator fnc = (FunctionOperator) f;
|
||||||
Function a = fnc.getVariable1();
|
Function a = fnc.getParameter1();
|
||||||
if (a.equals(new Number(root, 0))) {
|
if (a.equals(new Number(root, 0))) {
|
||||||
a = fnc.getVariable2();
|
a = fnc.getParameter2();
|
||||||
}
|
}
|
||||||
result.add(a);
|
result.add(a);
|
||||||
return result;
|
return result;
|
||||||
|
@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Negative;
|
import org.warp.picalculator.math.functions.Negative;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
@ -19,16 +19,16 @@ import org.warp.picalculator.math.functions.Number;
|
|||||||
public class NumberRule6 {
|
public class NumberRule6 {
|
||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final Multiplication mult = (Multiplication) f;
|
final Multiplication mult = (Multiplication) f;
|
||||||
if (mult.getVariable1() instanceof Number) {
|
if (mult.getParameter1() instanceof Number) {
|
||||||
final Number numb = (Number) mult.getVariable1();
|
final Number numb = (Number) mult.getParameter1();
|
||||||
if (numb.equals(new Number(root, -1))) {
|
if (numb.equals(new Number(root, -1))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mult.getVariable2() instanceof Number) {
|
if (mult.getParameter2() instanceof Number) {
|
||||||
final Number numb = (Number) mult.getVariable2();
|
final Number numb = (Number) mult.getParameter2();
|
||||||
if (numb.equals(new Number(root, -1))) {
|
if (numb.equals(new Number(root, -1))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -37,28 +37,27 @@ public class NumberRule6 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
Function a = null;
|
Function a = null;
|
||||||
boolean aFound = false;
|
boolean aFound = false;
|
||||||
final Multiplication mult = (Multiplication) f;
|
final Multiplication mult = (Multiplication) f;
|
||||||
if (aFound == false & mult.getVariable1() instanceof Number) {
|
if (aFound == false & mult.getParameter1() instanceof Number) {
|
||||||
final Number numb = (Number) mult.getVariable1();
|
final Number numb = (Number) mult.getParameter1();
|
||||||
if (numb.equals(new Number(root, -1))) {
|
if (numb.equals(new Number(root, -1))) {
|
||||||
a = mult.getVariable2();
|
a = mult.getParameter2();
|
||||||
aFound = true;
|
aFound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (aFound == false && mult.getVariable2() instanceof Number) {
|
if (aFound == false && mult.getParameter2() instanceof Number) {
|
||||||
final Number numb = (Number) mult.getVariable2();
|
final Number numb = (Number) mult.getParameter2();
|
||||||
if (numb.equals(new Number(root, -1))) {
|
if (numb.equals(new Number(root, -1))) {
|
||||||
a = mult.getVariable1();
|
a = mult.getParameter1();
|
||||||
aFound = true;
|
aFound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Negative minus = new Negative(root, null);
|
final Negative minus = new Negative(root, a);
|
||||||
minus.setVariable(a);
|
|
||||||
|
|
||||||
result.add(minus);
|
result.add(minus);
|
||||||
return result;
|
return result;
|
||||||
|
@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Sum;
|
import org.warp.picalculator.math.functions.Sum;
|
||||||
@ -19,15 +19,13 @@ import org.warp.picalculator.math.functions.Sum;
|
|||||||
public class NumberRule7 {
|
public class NumberRule7 {
|
||||||
|
|
||||||
public static boolean compare(Sum f) {
|
public static boolean compare(Sum f) {
|
||||||
return f.getVariable1().equals(f.getVariable2());
|
return f.getParameter1().equals(f.getParameter2());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Sum f) throws Error {
|
public static ArrayList<Function> execute(Sum f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final Multiplication mult = new Multiplication(root, null, null);
|
final Multiplication mult = new Multiplication(root, new Number(root, 2), f.getParameter1());
|
||||||
mult.setVariable1(new Number(root, 2));
|
|
||||||
mult.setVariable2(f.getVariable1());
|
|
||||||
result.add(mult);
|
result.add(mult);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Sum;
|
import org.warp.picalculator.math.functions.Sum;
|
||||||
|
|
||||||
@ -19,32 +19,30 @@ import org.warp.picalculator.math.functions.Sum;
|
|||||||
public class SyntaxRule1 {
|
public class SyntaxRule1 {
|
||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final FunctionTwoValues m = (FunctionTwoValues) f;
|
final FunctionOperator m = (FunctionOperator) f;
|
||||||
if (m instanceof Multiplication & m.getVariable1() instanceof Multiplication) {
|
if (m instanceof Multiplication & m.getParameter1() instanceof Multiplication) {
|
||||||
return true;
|
return true;
|
||||||
} else if (m instanceof Sum & m.getVariable1() instanceof Sum) {
|
} else if (m instanceof Sum & m.getParameter1() instanceof Sum) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final FunctionTwoValues mOut = (FunctionTwoValues) f;
|
FunctionOperator mOut = (FunctionOperator) f;
|
||||||
final Function a = ((FunctionTwoValues) mOut.getVariable1()).getVariable1();
|
final Function a = ((FunctionOperator) mOut.getParameter1()).getParameter1();
|
||||||
final Function b = ((FunctionTwoValues) mOut.getVariable1()).getVariable2();
|
final Function b = ((FunctionOperator) mOut.getParameter1()).getParameter2();
|
||||||
final Function c = mOut.getVariable2();
|
final Function c = mOut.getParameter2();
|
||||||
FunctionTwoValues mIn;
|
FunctionOperator mIn;
|
||||||
if (f instanceof Multiplication) {
|
if (f instanceof Multiplication) {
|
||||||
mIn = new Multiplication(root, null, null);
|
mIn = new Multiplication(root, b, c);
|
||||||
} else {
|
} else {
|
||||||
mIn = new Sum(root, null, null);
|
mIn = new Sum(root, b, c);
|
||||||
}
|
}
|
||||||
mOut.setVariable1(a);
|
mOut = mOut.setParameter1(a);
|
||||||
mIn.setVariable1(b);
|
mOut = mOut.setParameter2(mIn);
|
||||||
mIn.setVariable2(c);
|
|
||||||
mOut.setVariable2(mIn);
|
|
||||||
result.add(mOut);
|
result.add(mOut);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Sum;
|
import org.warp.picalculator.math.functions.Sum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,12 +18,12 @@ import org.warp.picalculator.math.functions.Sum;
|
|||||||
public class SyntaxRule2 {
|
public class SyntaxRule2 {
|
||||||
|
|
||||||
public static boolean compare(Sum f) {
|
public static boolean compare(Sum f) {
|
||||||
if (f.getVariable2() instanceof Sum) {
|
if (f.getParameter2() instanceof Sum) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (f.getVariable2() instanceof Expression) {
|
if (f.getParameter2() instanceof Expression) {
|
||||||
final Expression e = (Expression) f.getVariable2();
|
final Expression e = (Expression) f.getParameter2();
|
||||||
if (e.getVariablesLength() == 1 && e.getVariable(0) instanceof Sum) {
|
if (e.getParametersLength() == 1 && e.getParameter(0) instanceof Sum) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,22 +31,20 @@ public class SyntaxRule2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Sum f) throws Error {
|
public static ArrayList<Function> execute(Sum f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final Function a = f.getVariable1();
|
final Function a = f.getParameter1();
|
||||||
Function b, c;
|
Function b, c;
|
||||||
if (f.getVariable2() instanceof Sum) {
|
if (f.getParameter2() instanceof Sum) {
|
||||||
b = ((Sum) f.getVariable2()).getVariable1();
|
b = ((Sum) f.getParameter2()).getParameter1();
|
||||||
c = ((Sum) f.getVariable2()).getVariable2();
|
c = ((Sum) f.getParameter2()).getParameter2();
|
||||||
} else {
|
} else {
|
||||||
b = ((Sum) ((Expression) f.getVariable2()).getVariable(0)).getVariable1();
|
b = ((Sum) ((Expression) f.getParameter2()).getParameter(0)).getParameter1();
|
||||||
c = ((Sum) ((Expression) f.getVariable2()).getVariable(0)).getVariable2();
|
c = ((Sum) ((Expression) f.getParameter2()).getParameter(0)).getParameter2();
|
||||||
}
|
}
|
||||||
final Sum mIn = new Sum(root, null, null);
|
final Sum mIn = new Sum(root, a, b);
|
||||||
f.setVariable1(mIn);
|
f.setParameter1(mIn);
|
||||||
mIn.setVariable1(a);
|
f.setParameter2(c);
|
||||||
mIn.setVariable2(b);
|
|
||||||
f.setVariable2(c);
|
|
||||||
result.add(f);
|
result.add(f);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Power;
|
import org.warp.picalculator.math.functions.Power;
|
||||||
import org.warp.picalculator.math.functions.Undefined;
|
import org.warp.picalculator.math.functions.Undefined;
|
||||||
@ -19,16 +19,16 @@ import org.warp.picalculator.math.functions.Undefined;
|
|||||||
public class UndefinedRule1 {
|
public class UndefinedRule1 {
|
||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final Power fnc = (Power) f;
|
final Power fnc = (Power) f;
|
||||||
if (fnc.getVariable1().equals(new Number(root, 0)) && fnc.getVariable2().equals(new Number(root, 0))) {
|
if (fnc.getParameter1().equals(new Number(root, 0)) && fnc.getParameter2().equals(new Number(root, 0))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
result.add(new Undefined(root));
|
result.add(new Undefined(root));
|
||||||
return result;
|
return result;
|
||||||
|
@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Division;
|
import org.warp.picalculator.math.functions.Division;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Undefined;
|
import org.warp.picalculator.math.functions.Undefined;
|
||||||
|
|
||||||
@ -19,10 +19,10 @@ import org.warp.picalculator.math.functions.Undefined;
|
|||||||
public class UndefinedRule2 {
|
public class UndefinedRule2 {
|
||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final Division fnc = (Division) f;
|
final Division fnc = (Division) f;
|
||||||
if (fnc.getVariable2() instanceof Number) {
|
if (fnc.getParameter2() instanceof Number) {
|
||||||
final Number numb = (Number) fnc.getVariable2();
|
final Number numb = (Number) fnc.getParameter2();
|
||||||
if (numb.equals(new Number(root, 0))) {
|
if (numb.equals(new Number(root, 0))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ public class UndefinedRule2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
result.add(new Undefined(root));
|
result.add(new Undefined(root));
|
||||||
return result;
|
return result;
|
||||||
|
@ -3,10 +3,10 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Subtraction;
|
import org.warp.picalculator.math.functions.Subtraction;
|
||||||
import org.warp.picalculator.math.functions.Sum;
|
import org.warp.picalculator.math.functions.Sum;
|
||||||
@ -20,39 +20,34 @@ import org.warp.picalculator.math.functions.Sum;
|
|||||||
*/
|
*/
|
||||||
public class VariableRule1 {
|
public class VariableRule1 {
|
||||||
|
|
||||||
public static boolean compare(FunctionTwoValues fnc) {
|
public static boolean compare(FunctionOperator fnc) {
|
||||||
if (fnc.getVariable1() instanceof Multiplication & fnc.getVariable2() instanceof Multiplication) {
|
if (fnc.getParameter1() instanceof Multiplication & fnc.getParameter2() instanceof Multiplication) {
|
||||||
final Multiplication m1 = (Multiplication) fnc.getVariable1();
|
final Multiplication m1 = (Multiplication) fnc.getParameter1();
|
||||||
final Multiplication m2 = (Multiplication) fnc.getVariable2();
|
final Multiplication m2 = (Multiplication) fnc.getParameter2();
|
||||||
if (m1.getVariable2().equals(m2.getVariable2())) {
|
if (m1.getParameter2().equals(m2.getParameter2())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(FunctionTwoValues fnc) throws Error {
|
public static ArrayList<Function> execute(FunctionOperator fnc) throws Error {
|
||||||
final Calculator root = fnc.getRoot();
|
final MathContext root = fnc.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final Multiplication m1 = (Multiplication) fnc.getVariable1();
|
final Multiplication m1 = (Multiplication) fnc.getParameter1();
|
||||||
final Multiplication m2 = (Multiplication) fnc.getVariable2();
|
final Multiplication m2 = (Multiplication) fnc.getParameter2();
|
||||||
final Function a = m1.getVariable1();
|
final Function a = m1.getParameter1();
|
||||||
final Function b = m2.getVariable1();
|
final Function b = m2.getParameter1();
|
||||||
final Function x = m1.getVariable2();
|
final Function x = m1.getParameter2();
|
||||||
|
|
||||||
final Multiplication retm = new Multiplication(root, null, null);
|
FunctionOperator rets;
|
||||||
final Expression rete = new Expression(root);
|
|
||||||
FunctionTwoValues rets;
|
|
||||||
if (fnc instanceof Sum) {
|
if (fnc instanceof Sum) {
|
||||||
rets = new Sum(root, null, null);
|
rets = new Sum(root, a, b);
|
||||||
} else {
|
} else {
|
||||||
rets = new Subtraction(root, null, null);
|
rets = new Subtraction(root, a, b);
|
||||||
}
|
}
|
||||||
rets.setVariable1(a);
|
final Expression rete = new Expression(root, rets);
|
||||||
rets.setVariable2(b);
|
final Multiplication retm = new Multiplication(root, rete, x);
|
||||||
rete.addFunctionToEnd(rets);
|
|
||||||
retm.setVariable1(rete);
|
|
||||||
retm.setVariable2(x);
|
|
||||||
result.add(retm);
|
result.add(retm);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Subtraction;
|
import org.warp.picalculator.math.functions.Subtraction;
|
||||||
@ -21,37 +21,32 @@ import org.warp.picalculator.math.functions.Sum;
|
|||||||
*/
|
*/
|
||||||
public class VariableRule2 {
|
public class VariableRule2 {
|
||||||
|
|
||||||
public static boolean compare(FunctionTwoValues fnc) {
|
public static boolean compare(FunctionOperator fnc) {
|
||||||
if (fnc.getVariable1() instanceof Multiplication) {
|
if (fnc.getParameter1() instanceof Multiplication) {
|
||||||
final Multiplication m1 = (Multiplication) fnc.getVariable1();
|
final Multiplication m1 = (Multiplication) fnc.getParameter1();
|
||||||
if (m1.getVariable2().equals(fnc.getVariable2())) {
|
if (m1.getParameter2().equals(fnc.getParameter2())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(FunctionTwoValues fnc) throws Error {
|
public static ArrayList<Function> execute(FunctionOperator fnc) throws Error {
|
||||||
final Calculator root = fnc.getRoot();
|
final MathContext root = fnc.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final Multiplication m1 = (Multiplication) fnc.getVariable1();
|
final Multiplication m1 = (Multiplication) fnc.getParameter1();
|
||||||
final Function a = m1.getVariable1();
|
final Function a = m1.getParameter1();
|
||||||
final Function x = fnc.getVariable2();
|
final Function x = fnc.getParameter2();
|
||||||
|
|
||||||
final Multiplication retm = new Multiplication(root, null, null);
|
|
||||||
final Expression rete = new Expression(root);
|
|
||||||
|
|
||||||
FunctionTwoValues rets;
|
FunctionOperator rets;
|
||||||
if (fnc instanceof Sum) {
|
if (fnc instanceof Sum) {
|
||||||
rets = new Sum(root, null, null);
|
rets = new Sum(root, a, new Number(root, 1));
|
||||||
} else {
|
} else {
|
||||||
rets = new Subtraction(root, null, null);
|
rets = new Subtraction(root, a, new Number(root, 1));
|
||||||
}
|
}
|
||||||
rets.setVariable1(a);
|
final Expression rete = new Expression(root, rets);
|
||||||
rets.setVariable2(new Number(root, 1));
|
final Multiplication retm = new Multiplication(root, rete, x);
|
||||||
rete.addFunctionToEnd(rets);
|
|
||||||
retm.setVariable1(rete);
|
|
||||||
retm.setVariable2(x);
|
|
||||||
result.add(retm);
|
result.add(retm);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ package org.warp.picalculator.math.rules;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Subtraction;
|
import org.warp.picalculator.math.functions.Subtraction;
|
||||||
@ -21,37 +21,32 @@ import org.warp.picalculator.math.functions.Sum;
|
|||||||
*/
|
*/
|
||||||
public class VariableRule3 {
|
public class VariableRule3 {
|
||||||
|
|
||||||
public static boolean compare(FunctionTwoValues fnc) {
|
public static boolean compare(FunctionOperator fnc) {
|
||||||
if (fnc.getVariable2() instanceof Multiplication) {
|
if (fnc.getParameter2() instanceof Multiplication) {
|
||||||
final Multiplication m2 = (Multiplication) fnc.getVariable2();
|
final Multiplication m2 = (Multiplication) fnc.getParameter2();
|
||||||
if (m2.getVariable2().equals(fnc.getVariable1())) {
|
if (m2.getParameter2().equals(fnc.getParameter1())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(FunctionTwoValues fnc) throws Error {
|
public static ArrayList<Function> execute(FunctionOperator fnc) throws Error {
|
||||||
final Calculator root = fnc.getRoot();
|
final MathContext root = fnc.getMathContext();
|
||||||
final ArrayList<Function> result = new ArrayList<>();
|
final ArrayList<Function> result = new ArrayList<>();
|
||||||
final Multiplication m2 = (Multiplication) fnc.getVariable2();
|
final Multiplication m2 = (Multiplication) fnc.getParameter2();
|
||||||
final Function a = m2.getVariable1();
|
final Function a = m2.getParameter1();
|
||||||
final Function x = fnc.getVariable1();
|
final Function x = fnc.getParameter1();
|
||||||
|
|
||||||
final Multiplication retm = new Multiplication(root, null, null);
|
FunctionOperator rets;
|
||||||
final Expression rete = new Expression(root);
|
|
||||||
FunctionTwoValues rets;
|
|
||||||
if (fnc instanceof Sum) {
|
if (fnc instanceof Sum) {
|
||||||
rets = new Sum(root, null, null);
|
rets = new Sum(root, new Number(root, 1), a);
|
||||||
} else {
|
} else {
|
||||||
rets = new Subtraction(root, null, null);
|
rets = new Subtraction(root, new Number(root, 1), a);
|
||||||
}
|
}
|
||||||
|
|
||||||
rets.setVariable1(new Number(root, 1));
|
final Expression rete = new Expression(root, rets);
|
||||||
rets.setVariable2(a);
|
final Multiplication retm = new Multiplication(root, rete, x);
|
||||||
rete.addFunctionToEnd(rets);
|
|
||||||
retm.setVariable1(rete);
|
|
||||||
retm.setVariable2(x);
|
|
||||||
result.add(retm);
|
result.add(retm);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules.methods;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Division;
|
import org.warp.picalculator.math.functions.Division;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
|
|
||||||
@ -19,11 +19,11 @@ import org.warp.picalculator.math.functions.Number;
|
|||||||
public class DivisionRule1 {
|
public class DivisionRule1 {
|
||||||
|
|
||||||
public static boolean compare(Division f) {
|
public static boolean compare(Division f) {
|
||||||
return f.getVariable1().isSolved() && f.getVariable2().isSolved() && !(f.getVariable1() instanceof Number && f.getVariable2() instanceof Number) && getFirstWorkingDivisionCouple(getDivisionElements(f)) != null;
|
return f.getParameter1().isSimplified() && f.getParameter2().isSimplified() && !(f.getParameter1() instanceof Number && f.getParameter2() instanceof Number) && getFirstWorkingDivisionCouple(getDivisionElements(f)) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Division f) throws Error {
|
public static ArrayList<Function> execute(Division f) throws Error {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
Function result;
|
Function result;
|
||||||
final ArrayList<Function> elements = getDivisionElements(f);
|
final ArrayList<Function> elements = getDivisionElements(f);
|
||||||
final int[] workingElementCouple = getFirstWorkingDivisionCouple(elements);
|
final int[] workingElementCouple = getFirstWorkingDivisionCouple(elements);
|
||||||
@ -49,18 +49,18 @@ public class DivisionRule1 {
|
|||||||
|
|
||||||
private static ArrayList<Function> getDivisionElements(Division division) {
|
private static ArrayList<Function> getDivisionElements(Division division) {
|
||||||
final ArrayList<Function> elementsNumerator = new ArrayList<>();
|
final ArrayList<Function> elementsNumerator = new ArrayList<>();
|
||||||
Function numMult = division.getVariable1();
|
Function numMult = division.getParameter1();
|
||||||
while (numMult instanceof Multiplication) {
|
while (numMult instanceof Multiplication) {
|
||||||
elementsNumerator.add(((Multiplication) numMult).getVariable1());
|
elementsNumerator.add(((Multiplication) numMult).getParameter1());
|
||||||
numMult = ((Multiplication) numMult).getVariable2();
|
numMult = ((Multiplication) numMult).getParameter2();
|
||||||
}
|
}
|
||||||
elementsNumerator.add(numMult);
|
elementsNumerator.add(numMult);
|
||||||
|
|
||||||
final ArrayList<Function> elementsDenominator = new ArrayList<>();
|
final ArrayList<Function> elementsDenominator = new ArrayList<>();
|
||||||
Function denomMult = division.getVariable1();
|
Function denomMult = division.getParameter1();
|
||||||
while (denomMult instanceof Multiplication) {
|
while (denomMult instanceof Multiplication) {
|
||||||
elementsDenominator.add(((Multiplication) denomMult).getVariable1());
|
elementsDenominator.add(((Multiplication) denomMult).getParameter1());
|
||||||
denomMult = ((Multiplication) denomMult).getVariable2();
|
denomMult = ((Multiplication) denomMult).getParameter2();
|
||||||
}
|
}
|
||||||
elementsDenominator.add(denomMult);
|
elementsDenominator.add(denomMult);
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ public class DivisionRule1 {
|
|||||||
if (i != j) {
|
if (i != j) {
|
||||||
Function testFunc;
|
Function testFunc;
|
||||||
testFunc = new Multiplication(root, a, b);
|
testFunc = new Multiplication(root, a, b);
|
||||||
if (!testFunc.isSolved()) {
|
if (!testFunc.isSimplified()) {
|
||||||
return new int[] { i, j };
|
return new int[] { i, j };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules.methods;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.Multiplication;
|
import org.warp.picalculator.math.functions.Multiplication;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
|
|
||||||
@ -18,12 +18,12 @@ import org.warp.picalculator.math.functions.Number;
|
|||||||
public class MultiplicationMethod1 {
|
public class MultiplicationMethod1 {
|
||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
return ((Multiplication) f).getVariable1().isSolved() && ((Multiplication) f).getVariable2().isSolved() && !(((Multiplication) f).getVariable1() instanceof Number && ((Multiplication) f).getVariable2() instanceof Number) && getFirstWorkingMultiplicationCouple(getMultiplicationElements(f)) != null;
|
return ((Multiplication) f).getParameter1().isSimplified() && ((Multiplication) f).getParameter2().isSimplified() && !(((Multiplication) f).getParameter1() instanceof Number && ((Multiplication) f).getParameter2() instanceof Number) && getFirstWorkingMultiplicationCouple(getMultiplicationElements(f)) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
Function result;
|
Function result;
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> elements = getMultiplicationElements(f);
|
final ArrayList<Function> elements = getMultiplicationElements(f);
|
||||||
final int[] workingElementCouple = getFirstWorkingMultiplicationCouple(elements);
|
final int[] workingElementCouple = getFirstWorkingMultiplicationCouple(elements);
|
||||||
final Function elem1 = elements.get(workingElementCouple[0]);
|
final Function elem1 = elements.get(workingElementCouple[0]);
|
||||||
@ -49,8 +49,8 @@ public class MultiplicationMethod1 {
|
|||||||
private static ArrayList<Function> getMultiplicationElements(Function mult) {
|
private static ArrayList<Function> getMultiplicationElements(Function mult) {
|
||||||
final ArrayList<Function> elements = new ArrayList<>();
|
final ArrayList<Function> elements = new ArrayList<>();
|
||||||
while (mult instanceof Multiplication) {
|
while (mult instanceof Multiplication) {
|
||||||
elements.add(((Multiplication) mult).getVariable1());
|
elements.add(((Multiplication) mult).getParameter1());
|
||||||
mult = ((Multiplication) mult).getVariable2();
|
mult = ((Multiplication) mult).getParameter2();
|
||||||
}
|
}
|
||||||
elements.add(mult);
|
elements.add(mult);
|
||||||
return elements;
|
return elements;
|
||||||
@ -66,7 +66,7 @@ public class MultiplicationMethod1 {
|
|||||||
if (elements.size() == 2) {
|
if (elements.size() == 2) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Calculator root = elements.get(0).getRoot();
|
final MathContext root = elements.get(0).getMathContext();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
a = elements.get(i);
|
a = elements.get(i);
|
||||||
for (int j = 0; j < size; j++) {
|
for (int j = 0; j < size; j++) {
|
||||||
@ -74,7 +74,7 @@ public class MultiplicationMethod1 {
|
|||||||
if (i != j) {
|
if (i != j) {
|
||||||
Function testFunc;
|
Function testFunc;
|
||||||
testFunc = new Multiplication(root, a, b);
|
testFunc = new Multiplication(root, a, b);
|
||||||
if (!testFunc.isSolved()) {
|
if (!testFunc.isSimplified()) {
|
||||||
return new int[] { i, j };
|
return new int[] { i, j };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,9 @@ import java.math.BigDecimal;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.math.Calculator;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.functions.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
import org.warp.picalculator.math.FunctionOperator;
|
||||||
import org.warp.picalculator.math.functions.Negative;
|
import org.warp.picalculator.math.functions.Negative;
|
||||||
import org.warp.picalculator.math.functions.Number;
|
import org.warp.picalculator.math.functions.Number;
|
||||||
import org.warp.picalculator.math.functions.Subtraction;
|
import org.warp.picalculator.math.functions.Subtraction;
|
||||||
@ -22,13 +22,13 @@ import org.warp.picalculator.math.functions.Sum;
|
|||||||
public class SumMethod1 {
|
public class SumMethod1 {
|
||||||
|
|
||||||
public static boolean compare(Function f) {
|
public static boolean compare(Function f) {
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
return (f instanceof Sum || f instanceof Subtraction) && ((FunctionTwoValues) f).getVariable1().isSolved() && ((FunctionTwoValues) f).getVariable2().isSolved() && !(((FunctionTwoValues) f).getVariable1() instanceof Number && ((FunctionTwoValues) f).getVariable2() instanceof Number) && getFirstWorkingSumCouple(root, getSumElements(f)) != null;
|
return (f instanceof Sum || f instanceof Subtraction) && ((FunctionOperator) f).getParameter1().isSimplified() && ((FunctionOperator) f).getParameter2().isSimplified() && !(((FunctionOperator) f).getParameter1() instanceof Number && ((FunctionOperator) f).getParameter2() instanceof Number) && getFirstWorkingSumCouple(root, getSumElements(f)) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Function> execute(Function f) throws Error {
|
public static ArrayList<Function> execute(Function f) throws Error {
|
||||||
Function result;
|
Function result;
|
||||||
final Calculator root = f.getRoot();
|
final MathContext root = f.getMathContext();
|
||||||
final ArrayList<Function> elements = getSumElements(f);
|
final ArrayList<Function> elements = getSumElements(f);
|
||||||
final int[] workingElementCouple = getFirstWorkingSumCouple(root, elements);
|
final int[] workingElementCouple = getFirstWorkingSumCouple(root, elements);
|
||||||
final Function elem1 = elements.get(workingElementCouple[0]);
|
final Function elem1 = elements.get(workingElementCouple[0]);
|
||||||
@ -41,11 +41,11 @@ public class SumMethod1 {
|
|||||||
final Function a = prec;
|
final Function a = prec;
|
||||||
final Function b = elements.get(i);
|
final Function b = elements.get(i);
|
||||||
if (b instanceof Negative) {
|
if (b instanceof Negative) {
|
||||||
prec = new Subtraction(root, a, ((Negative) b).getVariable());
|
prec = new Subtraction(root, a, ((Negative) b).getParameter());
|
||||||
((FunctionTwoValues) prec).getVariable2();
|
((FunctionOperator) prec).getParameter2();
|
||||||
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
||||||
prec = new Subtraction(root, a, ((Number) b).multiply(new Number(root, -1)));
|
prec = new Subtraction(root, a, ((Number) b).multiply(new Number(root, -1)));
|
||||||
((FunctionTwoValues) prec).getVariable2();
|
((FunctionOperator) prec).getParameter2();
|
||||||
} else {
|
} else {
|
||||||
prec = new Sum(root, a, b);
|
prec = new Sum(root, a, b);
|
||||||
}
|
}
|
||||||
@ -60,21 +60,21 @@ public class SumMethod1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static ArrayList<Function> getSumElements(Function sum) {
|
private static ArrayList<Function> getSumElements(Function sum) {
|
||||||
final Calculator root = sum.getRoot();
|
final MathContext root = sum.getMathContext();
|
||||||
final ArrayList<Function> elements = new ArrayList<>();
|
final ArrayList<Function> elements = new ArrayList<>();
|
||||||
while (sum instanceof Sum || sum instanceof Subtraction) {
|
while (sum instanceof Sum || sum instanceof Subtraction) {
|
||||||
if (sum instanceof Sum) {
|
if (sum instanceof Sum) {
|
||||||
elements.add(((FunctionTwoValues) sum).getVariable2());
|
elements.add(((FunctionOperator) sum).getParameter2());
|
||||||
} else {
|
} else {
|
||||||
elements.add(new Negative(root, ((FunctionTwoValues) sum).getVariable2()));
|
elements.add(new Negative(root, ((FunctionOperator) sum).getParameter2()));
|
||||||
}
|
}
|
||||||
sum = ((FunctionTwoValues) sum).getVariable1();
|
sum = ((FunctionOperator) sum).getParameter1();
|
||||||
}
|
}
|
||||||
elements.add(sum);
|
elements.add(sum);
|
||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int[] getFirstWorkingSumCouple(Calculator root, ArrayList<Function> elements) {
|
private static int[] getFirstWorkingSumCouple(MathContext root, ArrayList<Function> elements) {
|
||||||
final int size = elements.size();
|
final int size = elements.size();
|
||||||
Function a;
|
Function a;
|
||||||
Function b;
|
Function b;
|
||||||
@ -88,17 +88,17 @@ public class SumMethod1 {
|
|||||||
if (i != j) {
|
if (i != j) {
|
||||||
Function testFunc;
|
Function testFunc;
|
||||||
if (b instanceof Negative) {
|
if (b instanceof Negative) {
|
||||||
testFunc = new Subtraction(root, a, ((Negative) b).getVariable());
|
testFunc = new Subtraction(root, a, ((Negative) b).getParameter());
|
||||||
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
||||||
testFunc = new Subtraction(root, a, ((Number) b).multiply(new Number(root, -1)));
|
testFunc = new Subtraction(root, a, ((Number) b).multiply(new Number(root, -1)));
|
||||||
} else if (a instanceof Negative) {
|
} else if (a instanceof Negative) {
|
||||||
testFunc = new Subtraction(root, b, ((Negative) a).getVariable());
|
testFunc = new Subtraction(root, b, ((Negative) a).getParameter());
|
||||||
} else if (a instanceof Number && ((Number) a).getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
} else if (a instanceof Number && ((Number) a).getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
||||||
testFunc = new Subtraction(root, b, ((Number) a).multiply(new Number(root, -1)));
|
testFunc = new Subtraction(root, b, ((Number) a).multiply(new Number(root, -1)));
|
||||||
} else {
|
} else {
|
||||||
testFunc = new Sum(root, a, b);
|
testFunc = new Sum(root, a, b);
|
||||||
}
|
}
|
||||||
if (!testFunc.isSolved()) {
|
if (!testFunc.isSimplified()) {
|
||||||
return new int[] { i, j };
|
return new int[] { i, j };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user