Added a new exponent rule
This commit is contained in:
parent
a920b2eee0
commit
36de6ab02a
Binary file not shown.
@ -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
|
||||
|
@ -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)) {
|
||||
|
@ -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)) {
|
||||
|
@ -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<br>
|
||||
* <b>a√x=x^1/a</b>
|
||||
* <b>(a ^ b) * (a ^ c) = a ^ (b + c)</b>
|
||||
*
|
||||
* @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<Function> 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;
|
||||
}
|
||||
|
||||
|
48
src/org/warp/picalculator/math/rules/ExponentRule17.java
Normal file
48
src/org/warp/picalculator/math/rules/ExponentRule17.java
Normal file
@ -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<br>
|
||||
* <b>a√x=x^1/a</b>
|
||||
*
|
||||
* @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<Function> execute(Function f) throws Error {
|
||||
final Calculator root = f.getRoot();
|
||||
final ArrayList<Function> 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;
|
||||
}
|
||||
|
||||
}
|
40
src/org/warp/picalculator/math/rules/ExponentRule9.java
Normal file
40
src/org/warp/picalculator/math/rules/ExponentRule9.java
Normal file
@ -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<br>
|
||||
* <b>(a ^ b) ^ c = a ^ (b * c)</b>
|
||||
*
|
||||
* @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<Function> execute(Function f) throws Error {
|
||||
final Calculator root = f.getRoot();
|
||||
final ArrayList<Function> 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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user