diff --git a/Algebra Cheat Sheet.rtf b/Algebra Cheat Sheet.rtf index 4d9f00d3..dd0df088 100644 Binary files a/Algebra Cheat Sheet.rtf and b/Algebra Cheat Sheet.rtf differ diff --git a/src/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java b/src/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java index 7c002011..cb71e2a4 100644 --- a/src/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java +++ b/src/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java @@ -130,7 +130,7 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi if (!available) { System.err.println(GLProfile.glAvailabilityToString()); } - return false; + return available; } @Override diff --git a/src/org/warp/picalculator/math/functions/Multiplication.java b/src/org/warp/picalculator/math/functions/Multiplication.java index 1356cd88..38dcefa3 100644 --- a/src/org/warp/picalculator/math/functions/Multiplication.java +++ b/src/org/warp/picalculator/math/functions/Multiplication.java @@ -6,6 +6,7 @@ import org.warp.picalculator.Error; import org.warp.picalculator.math.Calculator; import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.ExponentRule15; +import org.warp.picalculator.math.rules.ExponentRule16; import org.warp.picalculator.math.rules.FractionsRule14; import org.warp.picalculator.math.rules.NumberRule1; import org.warp.picalculator.math.rules.NumberRule2; @@ -53,6 +54,9 @@ public class Multiplication extends FunctionTwoValues { if (ExponentRule15.compare(this)) { return true; } + if (ExponentRule16.compare(this)) { + return true; + } if (FractionsRule14.compare(this)) { return true; } @@ -75,6 +79,8 @@ public class Multiplication extends FunctionTwoValues { result = NumberRule6.execute(this); } else if (ExponentRule15.compare(this)) { result = ExponentRule15.execute(this); + } else if (ExponentRule16.compare(this)) { + result = ExponentRule16.execute(this); } else if (FractionsRule14.compare(this)) { result = FractionsRule14.execute(this); } else if (MultiplicationMethod1.compare(this)) { diff --git a/src/org/warp/picalculator/math/functions/Power.java b/src/org/warp/picalculator/math/functions/Power.java index ddec0efa..19938e70 100644 --- a/src/org/warp/picalculator/math/functions/Power.java +++ b/src/org/warp/picalculator/math/functions/Power.java @@ -9,6 +9,7 @@ import org.warp.picalculator.math.rules.ExponentRule1; import org.warp.picalculator.math.rules.ExponentRule2; import org.warp.picalculator.math.rules.ExponentRule3; import org.warp.picalculator.math.rules.ExponentRule4; +import org.warp.picalculator.math.rules.ExponentRule9; import org.warp.picalculator.math.rules.FractionsRule4; import org.warp.picalculator.math.rules.FractionsRule5; import org.warp.picalculator.math.rules.UndefinedRule1; @@ -49,6 +50,9 @@ public class Power extends FunctionTwoValues { if (ExponentRule4.compare(this)) { return true; } + if (ExponentRule9.compare(this)) { + return true; + } if (FractionsRule4.compare(this)) { return true; } @@ -84,6 +88,8 @@ public class Power extends FunctionTwoValues { result.addAll(ExponentRule3.execute(this)); } else if (ExponentRule4.compare(this)) { result.addAll(ExponentRule4.execute(this)); + } else if (ExponentRule9.compare(this)) { + result.addAll(ExponentRule9.execute(this)); } else if (FractionsRule4.compare(this)) { result.addAll(FractionsRule4.execute(this)); } else if (FractionsRule5.compare(this)) { diff --git a/src/org/warp/picalculator/math/rules/ExponentRule16.java b/src/org/warp/picalculator/math/rules/ExponentRule16.java index 3ddaa7ad..4bede1c6 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule16.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule16.java @@ -9,11 +9,11 @@ import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Power; -import org.warp.picalculator.math.functions.Root; +import org.warp.picalculator.math.functions.Sum; /** * Exponent rule
- * a√x=x^1/a + * (a ^ b) * (a ^ c) = a ^ (b + c) * * @author Andrea Cavalli * @@ -21,11 +21,13 @@ import org.warp.picalculator.math.functions.Root; public class ExponentRule16 { public static boolean compare(Function f) { - if (f instanceof Root) { - final Root fnc = (Root) f; - if (fnc.getVariable1().equals(fnc.getVariable2())) { - return true; - } + final Multiplication fnc = (Multiplication) f; + if (fnc.getVariable1() instanceof Power && fnc.getVariable2() instanceof Power) { + return ((Power)fnc.getVariable1()).getVariable1().equals(((Power)fnc.getVariable2()).getVariable1()); + } else if (fnc.getVariable1() instanceof Power) { + return ((Power)fnc.getVariable1()).getVariable1().equals(fnc.getVariable2()); + } else if (fnc.getVariable2() instanceof Power) { + return ((Power)fnc.getVariable2()).getVariable1().equals(fnc.getVariable1()); } return false; } @@ -34,14 +36,13 @@ public class ExponentRule16 { final Calculator root = f.getRoot(); final ArrayList result = new ArrayList<>(); final Multiplication fnc = (Multiplication) f; - final Power p = new Power(fnc.getRoot(), null, null); - final Expression expr = new Expression(root); - final Function a = fnc.getVariable1(); - expr.addFunctionToEnd(a); - final Number two = new Number(root, 2); - p.setVariable1(expr); - p.setVariable2(two); - result.add(p); + if (fnc.getVariable1() instanceof Power && fnc.getVariable2() 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())))); + } else if (fnc.getVariable1() 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)))); + } else if (fnc.getVariable2() 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())))); + } return result; } diff --git a/src/org/warp/picalculator/math/rules/ExponentRule17.java b/src/org/warp/picalculator/math/rules/ExponentRule17.java new file mode 100644 index 00000000..b10086fd --- /dev/null +++ b/src/org/warp/picalculator/math/rules/ExponentRule17.java @@ -0,0 +1,48 @@ +package org.warp.picalculator.math.rules; + +import java.util.ArrayList; + +import org.warp.picalculator.Error; +import org.warp.picalculator.math.Calculator; +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.Number; +import org.warp.picalculator.math.functions.Power; +import org.warp.picalculator.math.functions.Root; + +/** + * Exponent rule
+ * a√x=x^1/a + * + * @author Andrea Cavalli + * + */ +public class ExponentRule17 { + + public static boolean compare(Function f) { + if (f instanceof Root) { + final Root fnc = (Root) f; + if (fnc.getVariable1().equals(fnc.getVariable2())) { + return true; + } + } + return false; + } + + public static ArrayList execute(Function f) throws Error { + final Calculator root = f.getRoot(); + final ArrayList result = new ArrayList<>(); + final Multiplication fnc = (Multiplication) f; + final Power p = new Power(fnc.getRoot(), null, null); + final Expression expr = new Expression(root); + final Function a = fnc.getVariable1(); + expr.addFunctionToEnd(a); + final Number two = new Number(root, 2); + p.setVariable1(expr); + p.setVariable2(two); + result.add(p); + return result; + } + +} diff --git a/src/org/warp/picalculator/math/rules/ExponentRule9.java b/src/org/warp/picalculator/math/rules/ExponentRule9.java new file mode 100644 index 00000000..f27a907c --- /dev/null +++ b/src/org/warp/picalculator/math/rules/ExponentRule9.java @@ -0,0 +1,40 @@ +package org.warp.picalculator.math.rules; + +import java.util.ArrayList; + +import org.warp.picalculator.Error; +import org.warp.picalculator.math.Calculator; +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.Number; +import org.warp.picalculator.math.functions.Power; + +/** + * Exponent rule
+ * (a ^ b) ^ c = a ^ (b * c) + * + * @author Andrea Cavalli + * + */ +public class ExponentRule9 { + + public static boolean compare(Function f) { + final Power fnc = (Power) f; + if (fnc.getVariable1() instanceof Power) { + return true; + } + return false; + } + + public static ArrayList execute(Function f) throws Error { + final Calculator root = f.getRoot(); + final ArrayList result = new ArrayList<>(); + final Power powC = (Power) f; + final Power powB = (Power) powC.getVariable1(); + final Power p = new Power(root, powB.getVariable1(), new Multiplication(root, new Expression(root, powB.getVariable2()), new Expression(root, powC.getVariable2()))); + result.add(p); + return result; + } + +}