Finished converting js rules to java rules

This commit is contained in:
Andrea Cavalli 2018-03-25 12:36:22 +02:00
parent 01925526a1
commit b1aabe899f
55 changed files with 823 additions and 515 deletions

View File

@ -11,7 +11,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<classpathentry excluding="**|rules/|rules/" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>

View File

@ -4,7 +4,7 @@ import org.warp.picalculator.gui.screens.KeyboardDebugScreen;
public class KeyboardTest {
public static void main(String[] args) throws InterruptedException {
public static void main(String[] args) throws InterruptedException, Error {
new Main(new KeyboardDebugScreen(), args);
}
}

View File

@ -14,11 +14,11 @@ import com.pi4j.wiringpi.Gpio;
public class Main {
public static Main instance;
public static String[] args;
public Main(String[] args) throws InterruptedException {
public Main(String[] args) throws InterruptedException, Error {
this(new LoadingScreen(), args);
}
public Main(Screen screen, String[] args) {
public Main(Screen screen, String[] args) throws InterruptedException, Error {
System.out.println("WarpPI Calculator");
instance = this;
Main.args = args;
@ -94,7 +94,7 @@ public class Main {
Keyboard.startKeyboard();
}
public void afterStart() {
public void afterStart() throws InterruptedException, Error {
DisplayManager.INSTANCE.setBrightness(0.2f);
RulesManager.initialize();
RulesManager.warmUp();
@ -104,7 +104,7 @@ public class Main {
Keyboard.stopKeyboard();
}
public static void main(String[] args) throws InterruptedException {
public static void main(String[] args) throws InterruptedException, Error {
/*
* TEST: Comparing BigIntegerMath.divisors() vs programmingpraxis' Number.getFactors() function
*

View File

@ -17,7 +17,7 @@ public class EmptyNumber implements Function {
private final MathContext root;
@Override
public ObjectArrayList<Function> simplify(Rule rule) throws Error {
public ObjectArrayList<Function> simplify(Rule rule) throws Error, InterruptedException {
return rule.execute(this);
}

View File

@ -27,7 +27,7 @@ public class Joke implements Function {
}
@Override
public ObjectArrayList<Function> simplify(Rule rule) throws Error {
public ObjectArrayList<Function> simplify(Rule rule) throws Error, InterruptedException {
return rule.execute(this);
}

View File

@ -117,7 +117,7 @@ public class Number implements Function {
}
@Override
public ObjectArrayList<Function> simplify(Rule rule) throws Error {
public ObjectArrayList<Function> simplify(Rule rule) throws Error, InterruptedException {
return rule.execute(this);
}

View File

@ -23,7 +23,7 @@ public class Undefined implements Function {
}
@Override
public ObjectArrayList<Function> simplify(Rule rule) throws Error {
public ObjectArrayList<Function> simplify(Rule rule) throws Error, InterruptedException {
return rule.execute(this);
}

View File

@ -57,7 +57,7 @@ public class Variable implements Function {
}
@Override
public ObjectArrayList<Function> simplify(Rule rule) throws Error {
public ObjectArrayList<Function> simplify(Rule rule) throws Error, InterruptedException {
return rule.execute(this);
}

View File

@ -2,6 +2,7 @@ package org.warp.picalculator.math.rules;
import java.io.Serializable;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -12,7 +13,7 @@ import jdk.nashorn.internal.objects.annotations.SpecializedFunction;
* @author Andrea Cavalli
*
*/
public interface Rule extends Serializable {
public interface Rule {
/**
* Get rule name
* @return
@ -32,6 +33,7 @@ public interface Rule extends Serializable {
*
* @param func
* @return <ul><li><code>null</code> if it's not executable on the function <b>func</b></li><li>An <code>ObjectArrayList&lt;Function&gt;</code> if it did something</li></ul>
* @throws Error
*/
public ObjectArrayList<Function> execute(Function func);
public ObjectArrayList<Function> execute(Function func) throws Error, InterruptedException;
}

View File

@ -85,7 +85,7 @@ public class RulesManager {
tDir.toFile().delete();
}
Utils.unzip(cacheFilePath.toString(), tDir.getParent().toString(), "");
useCache = !StaticVars.debugOn;
useCache = true;//!StaticVars.debugOn;
cacheFilePath.toFile().delete();
} catch (Exception ex) {
ex.printStackTrace();
@ -144,15 +144,16 @@ public class RulesManager {
InputStream resource = Utils.getResourceStream(scriptFile);
String text = Utils.read(resource);
String[] textArray = text.split("\\n", 5);
System.err.println(text);
String javaClassName = textArray[2].substring(6);
String javaClassNameAndPath = new StringBuilder("org.warp.picalculator.math.rules.").append(javaClassName).toString();
final int extIndex = javaClassNameAndPath.lastIndexOf('.');
String javaClassDeclaration = textArray[2].substring(6);
int extIndex = javaClassDeclaration.lastIndexOf('.');
String javaClassNameOnly = javaClassDeclaration.substring(extIndex + 1, javaClassDeclaration.length());
String javaClassNameAndPath = new StringBuilder("org.warp.picalculator.math.rules.").append(javaClassDeclaration).toString();
extIndex = javaClassNameAndPath.lastIndexOf('.');
String javaCode = new StringBuilder("package ").append(javaClassNameAndPath.substring(0, extIndex >= 0 ? extIndex : javaClassNameAndPath.length())).append(";\n")
.append(textArray[4]).toString();
Path tDirPath = tDir.resolve(javaClassNameAndPath.replace('.', File.separatorChar)).getParent();
Path tFileJava = tDirPath.resolve(javaClassName + ".java");
Path tFileClass = tDirPath.resolve(javaClassName + ".class");
Path tFileJava = tDirPath.resolve(javaClassNameOnly + ".java");
Path tFileClass = tDirPath.resolve(javaClassNameOnly + ".class");
if (!tDirPath.toFile().exists()) {
Files.createDirectories(tDirPath);
}
@ -192,7 +193,7 @@ public class RulesManager {
return (Rule) aClass.newInstance();
}
public static void warmUp() {
public static void warmUp() throws Error, InterruptedException {
ObjectArrayList<Function> uselessResult = null;
boolean uselessVariable = false;
for (RuleType val : RuleType.values()) {

View File

@ -1,17 +1,17 @@
Rule file
functions/Division
functions/EmptyNumber
functions/Expression
functions/Joke
functions/Multiplication
functions/Negative
functions/Number
functions/Power
functions/Root
functions/Subtraction
functions/Sum
functions/SumSubtraction
functions/Variable
functions/DivisionRule
functions/EmptyNumberRule
functions/ExpressionRule
functions/JokeRule
functions/MultiplicationRule
functions/NegativeRule
functions/NumberRule
functions/PowerRule
functions/RootRule
functions/SubtractionRule
functions/SumRule
functions/SumSubtractionRule
functions/VariableRule
ExpandRule1
ExpandRule2
ExpandRule5

1 Rule file
2 functions/Division functions/DivisionRule
3 functions/EmptyNumber functions/EmptyNumberRule
4 functions/Expression functions/ExpressionRule
5 functions/Joke functions/JokeRule
6 functions/Multiplication functions/MultiplicationRule
7 functions/Negative functions/NegativeRule
8 functions/Number functions/NumberRule
9 functions/Power functions/PowerRule
10 functions/Root functions/RootRule
11 functions/Subtraction functions/SubtractionRule
12 functions/Sum functions/SumRule
13 functions/SumSubtraction functions/SumSubtractionRule
14 functions/Variable functions/VariableRule
15 ExpandRule1
16 ExpandRule2
17 ExpandRule5

View File

@ -1,19 +1,15 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=ExpandRule2
*/
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.FunctionOperator;
import org.warp.picalculator.math.FunctionDynamic;
import org.warp.picalculator.math.FunctionSingle;
import org.warp.picalculator.math.MathContext;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.warp.picalculator.ScriptUtils;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import org.warp.picalculator.math.rules.RulesManager;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.functions.Subtraction;
@ -27,7 +23,7 @@ import org.warp.picalculator.math.functions.Number;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class ExpandRule2 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -49,9 +45,9 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Multiplication) {
Function fnc = f;
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1().equals(new Number(fnc.getMathContext(), -1))) {
var expr = fnc.getParameter2();
Function expr = fnc.getParameter2();
if (expr instanceof Sum) {
isExecutable = true;
} else if (expr instanceof Subtraction) {
@ -61,8 +57,8 @@ public class __INSERT_CLASS_NAME__ implements Rule {
}
}
} else if (f instanceof Subtraction || f instanceof SumSubtraction) {
Function fnc = f;
var expr = fnc.getParameter2();
FunctionOperator fnc = (FunctionOperator) f;
Function expr = fnc.getParameter2();
if (expr instanceof Sum) {
isExecutable = true;
} else if (expr instanceof Subtraction) {
@ -73,15 +69,15 @@ public class __INSERT_CLASS_NAME__ implements Rule {
}
if (isExecutable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var root = f.getMathContext();
MathContext root = f.getMathContext();
var expr = null;
var fromSubtraction = 0;
var subtraction = null;
Function expr = null;
int fromSubtraction = 0;
Function subtraction = null;
if (f instanceof Multiplication) {
expr = f.getParameter2();
expr = ((FunctionOperator) f).getParameter2();
} else if (f instanceof Subtraction || f instanceof SumSubtraction) {
expr = f.getParameter2();
expr = ((FunctionOperator) f).getParameter2();
if (f instanceof Subtraction) {
fromSubtraction = 1;
} else {
@ -93,36 +89,36 @@ public class __INSERT_CLASS_NAME__ implements Rule {
}
Function fnc = expr;
FunctionOperator fnc = (FunctionOperator) expr;
if (fnc instanceof Sum) {
var a = fnc.getParameter1();
var b = fnc.getParameter2();
var fnc2 = new Subtraction(root, new Multiplication(root, new Number(root, -1), a), b);
Function a = fnc.getParameter1();
Function b = fnc.getParameter2();
Function fnc2 = new Subtraction(root, new Multiplication(root, new Number(root, -1), a), b);
if (fromSubtraction > 0) {
subtraction = new Subtraction(root, f.getParameter1(), fnc2);
subtraction = new Subtraction(root, ((FunctionOperator)f).getParameter1(), fnc2);
result.add(subtraction);
} else {
result.add(fnc2);
}
} else if (fnc instanceof Subtraction) {
var a = fnc.getParameter1();
var b = fnc.getParameter2();
var fnc2 = new Sum(root, new Multiplication(root, new Number(root, -1), a), b);
Function a = fnc.getParameter1();
Function b = fnc.getParameter2();
Function fnc2 = new Sum(root, new Multiplication(root, new Number(root, -1), a), b);
if (fromSubtraction > 0) {
subtraction = new Subtraction(root, f.getParameter1(), fnc2);
subtraction = new Subtraction(root, ((FunctionOperator)f).getParameter1(), fnc2);
result.add(subtraction);
} else {
result.add(fnc2);
}
} else if (fnc instanceof SumSubtraction) {
var a = fnc.getParameter1();
var b = fnc.getParameter2();
var fnc2 = new Sum(root, new Multiplication(root, new Number(root, -1), a), b);
var fnc3 = new Subtraction(root, new Multiplication(root, new Number(root, -1), a), b);
Function a = fnc.getParameter1();
Function b = fnc.getParameter2();
Function fnc2 = new Sum(root, new Multiplication(root, new Number(root, -1), a), b);
Function fnc3 = new Subtraction(root, new Multiplication(root, new Number(root, -1), a), b);
if (fromSubtraction > 0) {
subtraction = new SumSubtraction(root, f.getParameter1(), fnc2);
subtraction = new SumSubtraction(root, ((FunctionOperator)f).getParameter1(), fnc2);
result.add(subtraction);
subtraction = new SumSubtraction(root, f.getParameter1(), fnc3);
subtraction = new SumSubtraction(root, ((FunctionOperator)f).getParameter1(), fnc3);
result.add(subtraction);
result.add(subtraction);
} else {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=ExpandRule5
*/
import org.warp.picalculator.math.Function;
@ -10,10 +10,13 @@ import org.warp.picalculator.math.FunctionSingle;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Negative;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -24,7 +27,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class ExpandRule5 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -46,10 +49,10 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Negative) {
isExecutable = f.getParameter() instanceof Negative;
isExecutable = ((FunctionSingle)f).getParameter() instanceof Negative;
} else if (f instanceof Multiplication) {
if (f.getParameter1().equals(new Number(f.getMathContext(), -1)) && f.getParameter2() instanceof Multiplication) {
isExecutable = f.getParameter2().getParameter1().equals(f.getParameter1());
if (((FunctionOperator)f).getParameter1().equals(new Number(f.getMathContext(), -1)) && ((FunctionOperator)f).getParameter2() instanceof Multiplication) {
isExecutable = ((FunctionOperator)((FunctionOperator)f).getParameter2()).getParameter1().equals(((FunctionOperator)f).getParameter1());
}
}
@ -57,11 +60,11 @@ public class __INSERT_CLASS_NAME__ implements Rule {
ObjectArrayList<Function> result = new ObjectArrayList<>();
if (f instanceof Negative) {
Function fnc = f;
result.add(((fnc.getParameter()).getParameter()).getParameter());
Negative fnc = (Negative) f;
result.add(((FunctionSingle)((FunctionSingle)fnc.getParameter()).getParameter()).getParameter());
} else if (f instanceof Multiplication) {
Function fnc = f;
result.add(fnc.getParameter2().getParameter2());
FunctionOperator fnc = (FunctionOperator) f;
result.add(((FunctionOperator)fnc.getParameter2()).getParameter2());
}
return result;
} else {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=ExponentRule1
*/
import org.warp.picalculator.math.Function;
@ -16,6 +16,8 @@ import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -26,7 +28,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class ExponentRule1 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -47,15 +49,14 @@ public class __INSERT_CLASS_NAME__ implements Rule {
@Override
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
var root = f.getMathContext();
MathContext root = f.getMathContext();
if (f instanceof Power) {
if (f.getParameter1().equals(new Number(root, 1))) {
if (((Power)f).getParameter1().equals(new Number(root, 1))) {
isExecutable = true;
}
}
if (isExecutable) {
var root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add(new Number(root, 1));
return result;

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=ExponentRule15
*/
import org.warp.picalculator.math.Function;
@ -17,6 +17,8 @@ import org.warp.picalculator.math.MathContext;
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.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -27,7 +29,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class ExponentRule15 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -50,19 +52,19 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Multiplication) {
Function fnc = f;
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1().equals(fnc.getParameter2())) {
isExecutable = true;
}
}
if (isExecutable) {
var root = f.getMathContext();
MathContext root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
Function fnc = f;
var a = fnc.getParameter1();
var two = new Number(root, 2);
var p = new Power(root, a, two);
FunctionOperator fnc = (FunctionOperator) f;
Function a = fnc.getParameter1();
Function two = new Number(root, 2);
Function p = new Power(root, a, two);
result.add(p);
return result;
} else {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=ExponentRule16
*/
import org.warp.picalculator.math.Function;
@ -18,6 +18,8 @@ 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.Sum;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -28,7 +30,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class ExponentRule16 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -51,26 +53,26 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Multiplication) {
Function fnc = f;
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1() instanceof Power && fnc.getParameter2() instanceof Power) {
isExecutable = (fnc.getParameter1()).getParameter1().equals((fnc.getParameter2()).getParameter1());
isExecutable = ((FunctionOperator)fnc.getParameter1()).getParameter1().equals(((FunctionOperator)fnc.getParameter2()).getParameter1());
} else if (fnc.getParameter1() instanceof Power) {
isExecutable = (fnc.getParameter1()).getParameter1().equals(fnc.getParameter2());
isExecutable = ((FunctionOperator)fnc.getParameter1()).getParameter1().equals(fnc.getParameter2());
} else if (fnc.getParameter2() instanceof Power) {
isExecutable = (fnc.getParameter2()).getParameter1().equals(fnc.getParameter1());
isExecutable = ((FunctionOperator)fnc.getParameter2()).getParameter1().equals(fnc.getParameter1());
}
}
if (isExecutable) {
var root = f.getMathContext();
MathContext root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
Function fnc = f;
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1() instanceof Power && fnc.getParameter2() instanceof Power) {
result.add(new Power(root, (fnc.getParameter1()).getParameter1(), new Sum(root, fnc.getParameter1().getParameter2(), fnc.getParameter2().getParameter2())));
result.add(new Power(root, ((FunctionOperator)fnc.getParameter1()).getParameter1(), new Sum(root, ((FunctionOperator)fnc.getParameter1()).getParameter2(), ((FunctionOperator)fnc.getParameter2()).getParameter2())));
} else if (fnc.getParameter1() instanceof Power) {
result.add(new Power(root, fnc.getParameter2(), new Sum(root, fnc.getParameter1().getParameter2(), new Number(root, 1))));
result.add(new Power(root, fnc.getParameter2(), new Sum(root, ((FunctionOperator)fnc.getParameter1()).getParameter2(), new Number(root, 1))));
} else if (fnc.getParameter2() instanceof Power) {
result.add(new Power(root, fnc.getParameter1(), new Sum(root, new Number(root, 1), fnc.getParameter2().getParameter2())));
result.add(new Power(root, fnc.getParameter1(), new Sum(root, new Number(root, 1), ((FunctionOperator)fnc.getParameter2()).getParameter2())));
}
return result;
} else {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=ExponentRule17
*/
import org.warp.picalculator.math.Function;
@ -18,6 +18,8 @@ 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.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -28,7 +30,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class ExponentRule17 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -51,19 +53,19 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Root) {
Function fnc = f;
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1().equals(fnc.getParameter2())) {
isExecutable = true;
}
}
if (isExecutable) {
var root = f.getMathContext();
MathContext root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
Function fnc = f;
var a = fnc.getParameter1();
var two = new Number(root, 2);
var p = new Power(fnc.getMathContext(), a, two);
FunctionOperator fnc = (FunctionOperator) f;
Function a = fnc.getParameter1();
Function two = new Number(root, 2);
Function p = new Power(root, a, two);
result.add(p);
return result;
} else {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=ExponentRule2
*/
import org.warp.picalculator.math.Function;
@ -15,6 +15,8 @@ import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -25,7 +27,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class ExponentRule2 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -48,16 +50,16 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Power) {
Function fnc = f;
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter2().equals(new Number(f.getMathContext(), 1))) {
isExecutable = true;
}
}
if (isExecutable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add((f).getParameter1());
return result;
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add(((FunctionOperator)f).getParameter1());
return result;
} else {
return null;
}

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=ExponentRule3
*/
import org.warp.picalculator.math.Function;
@ -15,6 +15,8 @@ import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -25,7 +27,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class ExponentRule3 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -48,16 +50,16 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Power) {
Function fnc = f;
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter2().equals(new Number(f.getMathContext(), 0))) {
isExecutable = true;
}
}
if (isExecutable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add(new Number(f.getMathContext(), 1));
return result;
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add(new Number(f.getMathContext(), 1));
return result;
} else {
return null;
}

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=ExponentRule4
*/
import org.warp.picalculator.math.Function;
@ -18,6 +18,8 @@ import org.warp.picalculator.math.functions.Expression;
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.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -28,7 +30,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class ExponentRule4 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -51,25 +53,25 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Power) {
Function fnc = f;
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1() instanceof Multiplication && fnc.getParameter2() instanceof Number) {
isExecutable = true;
}
}
if (isExecutable) {
var root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
Function fnc = f;
var mult = fnc.getParameter1();
var a = mult.getParameter1();
var b = mult.getParameter2();
var n = fnc.getParameter2();
var p1 = new Power(root, a, n);
var p2 = new Power(root, b, n);
var retMult = new Multiplication(root, p1, p2);
result.add(retMult);
return result;
MathContext root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
FunctionOperator fnc = (FunctionOperator) f;
FunctionOperator mult = (FunctionOperator) fnc.getParameter1();
Function a = mult.getParameter1();
Function b = mult.getParameter2();
Function n = fnc.getParameter2();
Function p1 = new Power(root, a, n);
Function p2 = new Power(root, b, n);
Function retMult = new Multiplication(root, p1, p2);
result.add(retMult);
return result;
} else {
return null;
}

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=ExponentRule9
*/
import org.warp.picalculator.math.Function;
@ -16,6 +16,8 @@ import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -26,7 +28,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class ExponentRule9 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -49,20 +51,20 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Power) {
Function fnc = f;
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1() instanceof Power) {
isExecutable = true;
}
}
if (isExecutable) {
var root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
var powC = f;
var powB = powC.getParameter1();
var p = new Power(root, powB.getParameter1(), new Multiplication(root, powB.getParameter2(), powC.getParameter2()));
result.add(p);
return result;
MathContext root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
FunctionOperator powC = (FunctionOperator) f;
FunctionOperator powB = (FunctionOperator) powC.getParameter1();
Function p = new Power(root, powB.getParameter1(), new Multiplication(root, powB.getParameter2(), powC.getParameter2()));
result.add(p);
return result;
} else {
return null;
}

View File

@ -1,40 +1,17 @@
/*
SETTINGS: (please don't move this part)
PATH=FractionsRule2
PATH=FractionsRule1
*/
//Imports
import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Fractions rule
* a / 1 = a/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
*/
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.FunctionOperator;
import org.warp.picalculator.math.FunctionDynamic;
import org.warp.picalculator.math.FunctionSingle;
import org.warp.picalculator.math.MathContext;
//Imports
import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Number;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Fractions rule
@ -43,7 +20,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class FractionsRule1 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -65,14 +42,14 @@ public class __INSERT_CLASS_NAME__ implements Rule {
@Override
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
var root = f.getMathContext();
MathContext root = f.getMathContext();
if (f instanceof Division) {
Function fnc = f;
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1() instanceof Number) {
var numb1 = fnc.getParameter1();
Function numb1 = fnc.getParameter1();
if (numb1.equals(new Number(root, 0))) {
if (fnc.getParameter2() instanceof Number) {
var numb2 = fnc.getParameter2();
Function numb2 = fnc.getParameter2();
if (numb2.equals(new Number(root, 0)) == false) {
isExecutable = true;
}
@ -91,51 +68,4 @@ public class __INSERT_CLASS_NAME__ implements Rule {
return null;
}
}
}
*
* @author Andrea Cavalli
*
*/
public class FractionsRule2 implements Rule {
// Rule name
@Override
public String getRuleName() {
return "FractionsRule2";
}
// Rule type
@Override
public RuleType getRuleType() {
return RuleType.CALCULATION;
}
/* Rule function
Returns:
- null if it's not executable on the function "f"
- An ObjectArrayList<Function> if it did something
*/
@Override
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Division) {
Division fnc = (Division) f;
if (fnc.getParameter2() instanceof Number) {
Number numb = (Number) fnc.getParameter2();
if (numb.equals(new Number(f.getMathContext(), 1))) {
isExecutable = true;
}
}
}
if (isExecutable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
Division fnc = (Division) f;
result.add(fnc.getParameter1());
return result;
} else {
return null;
}
}
}
}

View File

@ -0,0 +1,84 @@
/*
SETTINGS: (please don't move this part)
PATH=FractionsRule11
*/
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.FunctionOperator;
import org.warp.picalculator.math.FunctionDynamic;
import org.warp.picalculator.math.FunctionSingle;
import org.warp.picalculator.math.MathContext;
//Imports
import org.warp.picalculator.Error;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Fractions rule
* a / (b / c) = (a * c) / b
*
* @author Andrea Cavalli
*
*/
public class FractionsRule11 implements Rule {
// Rule name
@Override
public String getRuleName() {
return "FractionsRule11";
}
// Rule type
@Override
public RuleType getRuleType() {
return RuleType.EXPANSION;
}
/* Rule function
Returns:
- null if it's not executable on the function "f"
- An ObjectArrayList<Function> if it did something
*/
@Override
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Division) {
FunctionOperator fnc = (FunctionOperator) f;
Function a;
Function c;
FunctionOperator div2;
if (fnc.getParameter2() instanceof Division) {
div2 = (FunctionOperator) fnc.getParameter2();
a = fnc.getParameter1();
c = div2.getParameter2();
isExecutable = true;
} else {
isExecutable = false;
}
}
if (isExecutable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
FunctionOperator fnc = (FunctionOperator) f;
Function a;
Function b;
Function c;
FunctionOperator div2 = (FunctionOperator) fnc.getParameter2();
a = fnc.getParameter1();
b = div2.getParameter1();
c = div2.getParameter2();
result.add(new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), a, c), b));
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,82 @@
/*
SETTINGS: (please don't move this part)
PATH=FractionsRule12
*/
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.FunctionOperator;
import org.warp.picalculator.math.FunctionDynamic;
import org.warp.picalculator.math.FunctionSingle;
import org.warp.picalculator.math.MathContext;
//Imports
import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Fractions rule
* (b / c) / a = b / (a * c)
*
* @author Andrea Cavalli
*
*/
public class FractionsRule12 implements Rule {
// Rule name
@Override
public String getRuleName() {
return "FractionsRule12";
}
// Rule type
@Override
public RuleType getRuleType() {
return RuleType.EXPANSION;
}
/* Rule function
Returns:
- null if it's not executable on the function "f"
- An ObjectArrayList<Function> if it did something
*/
@Override
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Division) {
FunctionOperator fnc = (FunctionOperator) f;
Function a;
Function c;
if (fnc.getParameter1() instanceof Division) {
FunctionOperator div2 = (FunctionOperator) fnc.getParameter1();
a = fnc.getParameter1();
c = div2.getParameter2();
isExecutable = true;
}
}
if (isExecutable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
FunctionOperator fnc = (FunctionOperator) f;
Function a;
Function b;
Function c;
FunctionOperator div2 = (FunctionOperator) fnc.getParameter1();
a = fnc.getParameter2();
b = div2.getParameter1();
c = div2.getParameter2();
result.add(new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), a, c), b));
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,118 @@
/*
SETTINGS: (please don't move this part)
PATH=FractionsRule14
*/
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.FunctionOperator;
import org.warp.picalculator.math.FunctionDynamic;
import org.warp.picalculator.math.FunctionSingle;
import org.warp.picalculator.math.MathContext;
//Imports
import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Fractions rule
* (a / b) * (c / d) = (a * c) / (b * d)
*
* @author Andrea Cavalli
*
*/
public class FractionsRule14 implements Rule {
// Rule name
@Override
public String getRuleName() {
return "FractionsRule14";
}
// Rule type
@Override
public RuleType getRuleType() {
return RuleType.EXPANSION;
}
/* Rule function
Returns:
- null if it's not executable on the function "f"
- An ObjectArrayList<Function> if it did something
*/
@Override
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Multiplication) {
FunctionOperator fnc = (FunctionOperator) f;
Function a;
Function b;
Function c;
Function d;
if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Division) {
FunctionOperator div1 = (FunctionOperator) fnc.getParameter1();
FunctionOperator div2 = (FunctionOperator) fnc.getParameter2();
a = div1.getParameter1();
b = div1.getParameter2();
c = div2.getParameter1();
d = div2.getParameter2();
isExecutable = true;
} else if (fnc.getParameter1() instanceof Division) {
FunctionOperator div1 = (FunctionOperator) fnc.getParameter1();
a = div1.getParameter1();
b = div1.getParameter2();
c = fnc.getParameter2();
isExecutable = true;
} else if (fnc.getParameter2() instanceof Division) {
FunctionOperator div2 = (FunctionOperator) fnc.getParameter2();
a = fnc.getParameter1();
c = div2.getParameter1();
d = div2.getParameter2();
isExecutable = true;
}
}
if (isExecutable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
FunctionOperator fnc = (FunctionOperator) f;
Function a;
Function b;
Function c;
Function d;
if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Division) {
FunctionOperator div1 = (FunctionOperator) fnc.getParameter1();
FunctionOperator div2 = (FunctionOperator) fnc.getParameter2();
a = div1.getParameter1();
b = div1.getParameter2();
c = div2.getParameter1();
d = div2.getParameter2();
Function div = new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), a, c), new Multiplication(fnc.getMathContext(), b, d));
result.add(div);
} else if (fnc.getParameter1() instanceof Division) {
FunctionOperator div1 = (FunctionOperator) fnc.getParameter1();
a = div1.getParameter1();
b = div1.getParameter2();
c = fnc.getParameter2();
Function div = new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), a, c), b);
result.add(div);
} else if (fnc.getParameter2() instanceof Division) {
FunctionOperator div2 = (FunctionOperator) fnc.getParameter2();
a = fnc.getParameter1();
c = div2.getParameter1();
d = div2.getParameter2();
Function div = new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), a, c), d);
result.add(div);
}
return result;
} else {
return null;
}
}
}

View File

@ -10,6 +10,8 @@ import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=FractionsRule3
*/
import org.warp.picalculator.math.Function;
@ -15,6 +15,8 @@ import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -25,7 +27,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class FractionsRule3 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -48,7 +50,7 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Division) {
Function fnc = f;
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1().equals(fnc.getParameter2())) {
isExecutable = true;
}

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=FractionsRule4
*/
import org.warp.picalculator.math.Function;
@ -16,6 +16,8 @@ import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -26,7 +28,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class FractionsRule4 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -49,9 +51,9 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Power) {
Function fnc = f;
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Number) {
var n2 = fnc.getParameter2();
Function n2 = fnc.getParameter2();
if (n2.equals(new Number(f.getMathContext(), -1))) {
isExecutable = true;
}
@ -60,10 +62,10 @@ public class __INSERT_CLASS_NAME__ implements Rule {
if (isExecutable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
Function fnc = f;
var a = (fnc.getParameter1()).getParameter1();
var b = (fnc.getParameter1()).getParameter2();
var res = new Division(f.getMathContext(), b, a);
FunctionOperator fnc = (FunctionOperator) f;
Function a = ((FunctionOperator) fnc.getParameter1()).getParameter1();
Function b = ((FunctionOperator) fnc.getParameter1()).getParameter2();
Function res = new Division(f.getMathContext(), b, a);
result.add(res);
return result;
} else {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=FractionsRule5
*/
import org.warp.picalculator.math.Function;
@ -17,8 +17,11 @@ import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Division;
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.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -29,7 +32,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class FractionsRule5 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -49,15 +52,15 @@ public class __INSERT_CLASS_NAME__ implements Rule {
*/
@Override
public ObjectArrayList<Function> execute(Function f) {
public ObjectArrayList<Function> execute(Function f) throws Error {
boolean isExecutable = false;
if (f instanceof Power) {
Function fnc = f;
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1() instanceof Division) {
if (fnc.getParameter2() instanceof Multiplication && fnc.getParameter2().getParameter1().equals(new Number(f.getMathContext(), -1))) {
if (fnc.getParameter2() instanceof Multiplication && ((FunctionOperator) fnc.getParameter2()).getParameter1().equals(new Number(f.getMathContext(), -1))) {
isExecutable = true;
} else if (fnc.getParameter2() instanceof Number) {
var n2 = fnc.getParameter2();
Number n2 = (Number) fnc.getParameter2();
if (n2.getTerm().compareTo(BigDecimal.ZERO) < 0) {
isExecutable = true;
}
@ -66,19 +69,19 @@ public class __INSERT_CLASS_NAME__ implements Rule {
}
if (isExecutable) {
var root = f.getMathContext();
MathContext root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
Function fnc = f;
var a = (fnc.getParameter1()).getParameter1();
var b = (fnc.getParameter1()).getParameter2();
var c;
FunctionOperator fnc = (FunctionOperator) f;
Function a = ((FunctionOperator) fnc.getParameter1()).getParameter1();
Function b = ((FunctionOperator) fnc.getParameter1()).getParameter2();
Function c;
if (fnc.getParameter2() instanceof Multiplication) {
c = fnc.getParameter2().getParameter2();
c = ((FunctionOperator) fnc.getParameter2()).getParameter2();
} else {
c = fnc.getParameter2().multiply(new Number(root, "-1"));
c = ((Number) fnc.getParameter2()).multiply(new Number(root, "-1"));
}
var dv = new Division(root, b, a);
var pow = new Power(root, dv, c);
Function dv = new Division(root, b, a);
Function pow = new Power(root, dv, c);
result.add(pow);
return result;
} else {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=NumberRule1
*/
import org.warp.picalculator.math.Function;
@ -16,6 +16,8 @@ import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -26,7 +28,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class NumberRule1 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -49,16 +51,16 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Multiplication) {
var root = f.getMathContext();
var mult = f;
MathContext root = f.getMathContext();
FunctionOperator mult = (FunctionOperator) f;
if (mult.getParameter1() instanceof Number) {
var numb = mult.getParameter1();
Function numb = mult.getParameter1();
if (numb.equals(new Number(root, 0))) {
isExecutable = true;
}
}
if (mult.getParameter2() instanceof Number) {
var numb = mult.getParameter2();
Function numb = mult.getParameter2();
if (numb.equals(new Number(root, 0))) {
isExecutable = true;
}
@ -67,7 +69,7 @@ public class __INSERT_CLASS_NAME__ implements Rule {
if (isExecutable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add(new Number(f.getMathContext(), "0"));
result.add(new Number(f.getMathContext(), 0));
return result;
} else {
return null;

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=NumberRule2
*/
import org.warp.picalculator.math.Function;
@ -16,6 +16,8 @@ import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -26,7 +28,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class NumberRule2 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -49,16 +51,16 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Multiplication) {
var root = f.getMathContext();
var mult = f;
MathContext root = f.getMathContext();
Multiplication mult = (Multiplication) f;
if (mult.getParameter1() instanceof Number) {
var numb = mult.getParameter1();
Function numb = mult.getParameter1();
if (numb.equals(new Number(root, 1))) {
isExecutable = true;
}
}
if (mult.getParameter2() instanceof Number) {
var numb = mult.getParameter2();
Function numb = mult.getParameter2();
if (numb.equals(new Number(root, 1))) {
isExecutable = true;
}
@ -66,20 +68,20 @@ public class __INSERT_CLASS_NAME__ implements Rule {
}
if (isExecutable) {
var root = f.getMathContext();
MathContext root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
var a = null;
var aFound = false;
var mult = f;
Function a = null;
boolean aFound = false;
Multiplication mult = (Multiplication) f;
if (aFound == false & mult.getParameter1() instanceof Number) {
var numb = mult.getParameter1();
Function numb = mult.getParameter1();
if (numb.equals(new Number(root, 1))) {
a = mult.getParameter2();
aFound = true;
}
}
if (aFound == false && mult.getParameter2() instanceof Number) {
var numb = mult.getParameter2();
Function numb = mult.getParameter2();
if (numb.equals(new Number(root, 1))) {
a = mult.getParameter1();
aFound = true;

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=NumberRule3
*/
import org.warp.picalculator.math.Function;
@ -20,6 +20,8 @@ import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.functions.SumSubtraction;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -32,7 +34,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class NumberRule3 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -55,32 +57,32 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Subtraction) {
var sub = f;
FunctionOperator sub = (FunctionOperator) f;
if (sub.getParameter1().equals(sub.getParameter2())) {
isExecutable = true;
}
} else if (f instanceof Sum) {
var sub = f;
FunctionOperator sub = (FunctionOperator) f;
if (sub.getParameter1() instanceof Multiplication) {
if (sub.getParameter1().getParameter1() instanceof Number && sub.getParameter1().getParameter1().equals(new Number(f.getMathContext(), -1))) {
var neg = sub.getParameter1().getParameter2();
if (((FunctionOperator) sub.getParameter1()).getParameter1() instanceof Number && ((FunctionOperator) sub.getParameter1()).getParameter1().equals(new Number(f.getMathContext(), -1))) {
Function neg = ((FunctionOperator) sub.getParameter1()).getParameter2();
if (neg.equals(sub.getParameter2())) {
isExecutable = true;
}
}
}
} else if (f instanceof SumSubtraction) {
var sub = f;
FunctionOperator sub = (FunctionOperator) f;
if (sub.getParameter1().equals(sub.getParameter2())) {
isExecutable = true;
}
}
if (isExecutable) {
var root = f.getMathContext();
MathContext root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
if (f instanceof SumSubtraction) {
var mul = new Multiplication(root, new Number(root, 2), f.getParameter1());
Function mul = new Multiplication(root, new Number(root, 2), ((FunctionOperator) f).getParameter1());
result.add(mul);
}
result.add(new Number(root, 0));

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=NumberRule4
*/
import org.warp.picalculator.math.Function;
@ -17,6 +17,8 @@ import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.functions.SumSubtraction;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -27,7 +29,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class NumberRule4 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -54,9 +56,9 @@ public class __INSERT_CLASS_NAME__ implements Rule {
}
if (isExecutable) {
var root = f.getMathContext();
MathContext root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
var ss = f;
FunctionOperator ss = (FunctionOperator) f;
result.add(new Sum(root, ss.getParameter1(), ss.getParameter2()));
result.add(new Subtraction(root, ss.getParameter1(), ss.getParameter2()));
return result;

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=NumberRule5
*/
import org.warp.picalculator.math.Function;
@ -15,7 +15,13 @@ import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.FunctionOperator;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.functions.SumSubtraction;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -30,7 +36,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class NumberRule5 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -53,8 +59,8 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Sum || f instanceof Subtraction || f instanceof SumSubtraction) {
var root = f.getMathContext();
Function fnc = f;
MathContext root = f.getMathContext();
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1().equals(new Number(root, 0)) || fnc.getParameter2().equals(new Number(root, 0))) {
if (!(fnc.getParameter1().equals(new Number(root, 0)) && f instanceof SumSubtraction)) {
isExecutable = true;
@ -63,10 +69,10 @@ public class __INSERT_CLASS_NAME__ implements Rule {
}
if (isExecutable) {
var root = f.getMathContext();
MathContext root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
Function fnc = f;
var a = fnc.getParameter1();
FunctionOperator fnc = (FunctionOperator) f;
Function a = fnc.getParameter1();
if (a.equals(new Number(root, 0))) {
if (f instanceof Subtraction) {
a = new Multiplication(root, new Number(root, -1), fnc.getParameter2());

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=NumberRule7
*/
import org.warp.picalculator.math.Function;
@ -17,6 +17,8 @@ import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -27,7 +29,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class NumberRule7 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -50,13 +52,13 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Sum) {
isExecutable = f.getParameter1().equals(f.getParameter2());
isExecutable = ((FunctionOperator) f).getParameter1().equals(((FunctionOperator) f).getParameter2());
}
if (isExecutable) {
var root = f.getMathContext();
MathContext root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
var mult = new Multiplication(root, new Number(root, 2), f.getParameter1());
Function mult = new Multiplication(root, new Number(root, 2), ((FunctionOperator) f).getParameter1());
result.add(mult);
return result;
} else {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=UndefinedRule1
*/
import org.warp.picalculator.math.Function;
@ -17,6 +17,8 @@ import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.functions.Undefined;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -27,7 +29,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class UndefinedRule1 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -50,15 +52,15 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Power) {
var root = f.getMathContext();
Function fnc = f;
MathContext root = f.getMathContext();
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1().equals(new Number(root, 0)) && fnc.getParameter2().equals(new Number(root, 0))) {
isExecutable = true;
}
}
if (isExecutable) {
var root = f.getMathContext();
MathContext root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add(new Undefined(root));
return result;

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=UndefinedRule2
*/
import org.warp.picalculator.math.Function;
@ -17,6 +17,8 @@ import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Undefined;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -27,7 +29,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class UndefinedRule2 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -50,10 +52,10 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
if (f instanceof Division) {
var root = f.getMathContext();
Function fnc = f;
MathContext root = f.getMathContext();
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter2() instanceof Number) {
var numb = fnc.getParameter2();
Number numb = (Number) fnc.getParameter2();
if (numb.equals(new Number(root, 0))) {
isExecutable = true;
}
@ -61,7 +63,7 @@ public class __INSERT_CLASS_NAME__ implements Rule {
}
if (isExecutable) {
var root = f.getMathContext();
MathContext root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add(new Undefined(root));
return result;

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=VariableRule1
*/
import org.warp.picalculator.math.Function;
@ -18,6 +18,8 @@ import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -28,7 +30,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class VariableRule1 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -50,11 +52,11 @@ public class __INSERT_CLASS_NAME__ implements Rule {
@Override
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
Function fnc = f;
if (f instanceof Subtraction || f instanceof Sum) {
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1() instanceof Multiplication & fnc.getParameter2() instanceof Multiplication) {
var m1 = fnc.getParameter1();
var m2 = fnc.getParameter2();
FunctionOperator m1 = (FunctionOperator) fnc.getParameter1();
FunctionOperator m2 = (FunctionOperator) fnc.getParameter2();
if (m1.getParameter1().equals(m2.getParameter1()) || m1.getParameter2().equals(m2.getParameter2())) {
isExecutable = true;
}
@ -62,13 +64,14 @@ public class __INSERT_CLASS_NAME__ implements Rule {
}
if (isExecutable) {
var root = fnc.getMathContext();
FunctionOperator fnc = (FunctionOperator) f;
MathContext root = fnc.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
var m1 = fnc.getParameter1();
var m2 = fnc.getParameter2();
var a;
var b;
var x;
FunctionOperator m1 = (FunctionOperator) fnc.getParameter1();
FunctionOperator m2 = (FunctionOperator) fnc.getParameter2();
Function a;
Function b;
Function x;
if (m1.getParameter2().equals(m2.getParameter2())) {
x = m1.getParameter2();
a = m1.getParameter1();
@ -79,13 +82,13 @@ public class __INSERT_CLASS_NAME__ implements Rule {
b = m2.getParameter2();
}
var rets;
Function rets;
if (fnc instanceof Sum) {
rets = new Sum(root, a, b);
} else {
rets = new Subtraction(root, a, b);
}
var retm = new Multiplication(root, rets, x);
Function retm = new Multiplication(root, rets, x);
result.add(retm);
return result;
} else {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=VariableRule2
*/
import org.warp.picalculator.math.Function;
@ -19,6 +19,8 @@ import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -29,7 +31,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class VariableRule2 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -51,10 +53,10 @@ public class __INSERT_CLASS_NAME__ implements Rule {
@Override
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
Function fnc = f;
if (f instanceof Sum || f instanceof Subtraction) {
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter1() instanceof Multiplication) {
var m1 = fnc.getParameter1();
FunctionOperator m1 = (FunctionOperator) fnc.getParameter1();
if (m1.getParameter2().equals(fnc.getParameter2())) {
isExecutable = true;
}
@ -62,19 +64,20 @@ public class __INSERT_CLASS_NAME__ implements Rule {
}
if (isExecutable) {
var root = fnc.getMathContext();
FunctionOperator fnc = (FunctionOperator) f;
MathContext root = fnc.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
var m1 = fnc.getParameter1();
var a = m1.getParameter1();
var x = fnc.getParameter2();
FunctionOperator m1 = (FunctionOperator) fnc.getParameter1();
Function a = m1.getParameter1();
Function x = fnc.getParameter2();
var rets;
Function rets;
if (fnc instanceof Sum) {
rets = new Sum(root, a, new Number(root, 1));
} else {
rets = new Subtraction(root, a, new Number(root, 1));
}
var retm = new Multiplication(root, rets, x);
Function retm = new Multiplication(root, rets, x);
result.add(retm);
return result;
} else {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=VariableRule3
*/
import org.warp.picalculator.math.Function;
@ -19,6 +19,8 @@ import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@ -29,7 +31,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class VariableRule3 implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -51,10 +53,10 @@ public class __INSERT_CLASS_NAME__ implements Rule {
@Override
public ObjectArrayList<Function> execute(Function f) {
boolean isExecutable = false;
Function fnc = f;
if (f instanceof Sum || f instanceof Subtraction) {
FunctionOperator fnc = (FunctionOperator) f;
if (fnc.getParameter2() instanceof Multiplication) {
var m2 = fnc.getParameter2();
FunctionOperator m2 = (FunctionOperator) fnc.getParameter2();
if (m2.getParameter2().equals(fnc.getParameter1())) {
isExecutable = true;
}
@ -62,20 +64,21 @@ public class __INSERT_CLASS_NAME__ implements Rule {
}
if (isExecutable) {
var root = fnc.getMathContext();
FunctionOperator fnc = (FunctionOperator) f;
MathContext root = fnc.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
var m2 = fnc.getParameter2();
var a = m2.getParameter1();
var x = fnc.getParameter1();
FunctionOperator m2 = (FunctionOperator) fnc.getParameter2();
Function a = m2.getParameter1();
Function x = fnc.getParameter1();
var rets;
Function rets;
if (fnc instanceof Sum) {
rets = new Sum(root, new Number(root, 1), a);
} else {
rets = new Subtraction(root, new Number(root, 1), a);
}
var retm = new Multiplication(root, rets, x);
Function retm = new Multiplication(root, rets, x);
result.add(retm);
return result;
} else {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=functions.DivisionRule
*/
import org.warp.picalculator.math.Function;
@ -10,16 +10,21 @@ import org.warp.picalculator.math.FunctionSingle;
import org.warp.picalculator.math.MathContext;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.math.BigInteger;
import java.util.LinkedList;
import org.warp.picalculator.ScriptUtils;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import org.warp.picalculator.math.rules.RulesManager;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.SumSubtraction;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.Error;
/**
* Division
@ -28,7 +33,7 @@ import org.warp.picalculator.math.functions.Division;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class DivisionRule implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -47,38 +52,38 @@ public class __INSERT_CLASS_NAME__ implements Rule {
- An ObjectArrayList<Function> if it did something
*/
@Override
public ObjectArrayList<Function> execute(Function f) {
if (f instanceof Division) {
public ObjectArrayList<Function> execute(Function f) throws Error {
if (f instanceof DivisionRule) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var variable1 = f.getParameter1();
var variable2 = f.getParameter2();
var mathContext = f.getMathContext();
Function variable1 = ((FunctionOperator) f).getParameter1();
Function variable2 = ((FunctionOperator) f).getParameter2();
MathContext mathContext = f.getMathContext();
if (variable1 instanceof Number && variable2 instanceof Number) {
if (mathContext.exactMode) {
if (variable1.isInteger() && variable2.isInteger()) {
var factors1, factors2, mcm;
if (((Number)variable1).isInteger() && ((Number)variable2).isInteger()) {
LinkedList<BigInteger> factors1, factors2, mcm;
try {
factors1 = variable1.getFactors();
factors2 = variable2.getFactors();
factors1 = ((Number)variable1).getFactors();
factors2 = ((Number)variable2).getFactors();
mcm = ScriptUtils.mcm(factors1, factors2);
} catch (error) {
} catch (Exception ex) {
return null;
}
if (mcm.size() > 0) { //true if there is at least one common factor
//divide by the common factor (ab/cb = a/c)
var nmb1 = variable1.term.toBigIntegerExact();
var nmb2 = variable2.term.toBigIntegerExact();
mcm.forEach(function(integerNumber) {
BigInteger nmb1 = ((Number)variable1).getTerm().toBigIntegerExact();
BigInteger nmb2 = ((Number)variable2).getTerm().toBigIntegerExact();
for (BigInteger integerNumber : mcm) {
nmb1 = nmb1.divide(integerNumber);
nmb2 = nmb2.divide(integerNumber);
});
}
result.add(new Division(mathContext, new Number(mathContext, nmb1), new Number(mathContext, nmb2)));
return result;
}
}
} else {
//divide a by b (a/b = c)
result.add(variable1.divide(variable2));
result.add(((Number)variable1).divide((Number)variable2));
return result;
}
}

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=functions.EmptyNumberRule
*/
import org.warp.picalculator.math.Function;
@ -22,7 +22,7 @@ import org.warp.picalculator.math.rules.RulesManager;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class EmptyNumberRule implements Rule {
// Rule name
@Override
public String getRuleName() {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=functions.ExpressionRule
*/
import org.warp.picalculator.math.Function;
@ -28,7 +28,7 @@ import org.warp.picalculator.math.functions.Expression;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class ExpressionRule implements Rule {
// Rule name
@Override
public String getRuleName() {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=functions.JokeRule
*/
import org.warp.picalculator.math.Function;
@ -22,7 +22,7 @@ import org.warp.picalculator.math.rules.RulesManager;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class JokeRule implements Rule {
// Rule name
@Override
public String getRuleName() {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=functions.MultiplicationRule
*/
import org.warp.picalculator.math.Function;
@ -28,7 +28,7 @@ import org.warp.picalculator.math.functions.Division;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class MultiplicationRule implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -50,12 +50,12 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
if (f instanceof Multiplication) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var variable1 = f.getParameter1();
var variable2 = f.getParameter2();
var mathContext = f.getMathContext();
Function variable1 = ((Multiplication) f).getParameter1();
Function variable2 = ((Multiplication) f).getParameter2();
MathContext mathContext = f.getMathContext();
if (variable1 instanceof Number && variable2 instanceof Number) {
//multiply a by b (a*b = c)
result.add(variable1.multiply(variable2));
result.add(((Number)variable1).multiply((Number)variable2));
return result;
}
}

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=functions.NegativeRule
*/
import org.warp.picalculator.math.Function;
@ -29,7 +29,7 @@ import java.lang.ArithmeticException;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class NegativeRule implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -48,16 +48,16 @@ public class __INSERT_CLASS_NAME__ implements Rule {
- An ObjectArrayList<Function> if it did something
*/
@Override
public ObjectArrayList<Function> execute(Function f) {
public ObjectArrayList<Function> execute(Function f) throws Error {
if (f instanceof Negative) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var variable = f.getParameter();
var mathContext = f.getMathContext();
Function variable = ((Negative)f).getParameter();
MathContext mathContext = f.getMathContext();
if (variable instanceof Number) {
//-a = a*-1 = b
try {
result.add(variable.multiply(new Number(mathContext, -1)));
} catch (ex) {
result.add(((Number)variable).multiply(new Number(mathContext, -1)));
} catch (Exception ex) {
if (ex instanceof NullPointerException) {
throw new Error(Errors.ERROR);
} else if (ex instanceof NumberFormatException) {

View File

@ -1,49 +0,0 @@
// Imports
var ObjectArrayList = Java.type("it.unimi.dsi.fastutil.objects.ObjectArrayList");
var ScriptUtils = org.warp.picalculator.ScriptUtils;
var Rule = org.warp.picalculator.math.rules.Rule;
var RuleType = org.warp.picalculator.math.rules.RuleType;
var RulesManager = org.warp.picalculator.math.rules.RulesManager;
var BigInteger = java.math.BigInteger;
/**
* Number
*
*
* @author Andrea Cavalli
*
*/
var rule = {
// Rule name
getRuleName: function() {
return "Number";
},
// Rule type
getRuleType: function() {
return RuleType.CALCULATION;
},
/* Rule function
Returns:
- null if it's not executable on the function "f"
- An ObjectArrayList<Function> if it did something
*/
execute: function(f) {
if (ScriptUtils.instanceOf(f, Number.class)) {
var result = new ObjectArrayList();
var mathContext = f.getMathContext();
if (mathContext.exactMode) {
if (f.isInteger() == false) {
var divisor = new Number(mathContext, BigInteger.TEN.pow(f.getNumberOfDecimalPlaces()));
var number = new Number(mathContext, f.getTerm().multiply(divisor.term));
var div = new Division(mathContext, number, divisor);
result.add(div);
return result;
}
}
}
return null;
}
}
//Add this rule to the list of rules
RulesManager.addRule(engine.getInterface(rule, Rule.class));

View File

@ -0,0 +1,63 @@
/*
SETTINGS: (please don't move this part)
PATH=functions.NumberRule
*/
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.FunctionOperator;
import org.warp.picalculator.math.FunctionDynamic;
import org.warp.picalculator.math.FunctionSingle;
import org.warp.picalculator.math.MathContext;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.warp.picalculator.ScriptUtils;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import org.warp.picalculator.math.rules.RulesManager;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Number;
import java.math.BigInteger;
/**
* Number
*
*
* @author Andrea Cavalli
*
*/
public class NumberRule implements Rule {
// Rule name
@Override
public String getRuleName() {
return "Number";
}
// Rule type
@Override
public RuleType getRuleType() {
return RuleType.CALCULATION;
}
/* Rule function
Returns:
- null if it's not executable on the function "f"
- An ObjectArrayList<Function> if it did something
*/
@Override
public ObjectArrayList<Function> execute(Function f) {
if (f instanceof Number) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
MathContext mathContext = f.getMathContext();
if (mathContext.exactMode) {
if (((Number)f).isInteger() == false) {
Number divisor = new Number(mathContext, BigInteger.TEN.pow(((Number)f).getNumberOfDecimalPlaces()));
Function number = new Number(mathContext, ((Number)f).getTerm().multiply(divisor.getTerm()));
Function div = new Division(mathContext, number, divisor);
result.add(div);
return result;
}
}
}
return null;
}
}

View File

@ -1,53 +0,0 @@
// Imports
var ObjectArrayList = Java.type("it.unimi.dsi.fastutil.objects.ObjectArrayList");
var ScriptUtils = org.warp.picalculator.ScriptUtils;
var Rule = org.warp.picalculator.math.rules.Rule;
var RuleType = org.warp.picalculator.math.rules.RuleType;
var RulesManager = org.warp.picalculator.math.rules.RulesManager;
var Multiplication = org.warp.picalculator.math.functions.Multiplication;
var Sum = org.warp.picalculator.math.functions.Sum;
var Subtraction = org.warp.picalculator.math.functions.Subtraction;
var SumSubtraction = org.warp.picalculator.math.functions.SumSubtraction;
var Number = org.warp.picalculator.math.functions.Number;
var Division = org.warp.picalculator.math.functions.Division;
var Power = org.warp.picalculator.math.functions.Power;
/**
* Power
* a^b = c
*
* @author Andrea Cavalli
*
*/
var rule = {
// Rule name
getRuleName: function() {
return "Power";
},
// Rule type
getRuleType: function() {
return RuleType.CALCULATION;
},
/* Rule function
Returns:
- null if it's not executable on the function "f"
- An ObjectArrayList<Function> if it did something
*/
execute: function(f) {
if (ScriptUtils.instanceOf(f, Power.class)) {
var result = new ObjectArrayList();
var variable1 = f.getParameter1();
var variable2 = f.getParameter2();
var mathContext = f.getMathContext();
if (ScriptUtils.instanceOf(variable1, Number.class) && ScriptUtils.instanceOf(variable2, Number.class)) {
//a^b = c
result.add(variable1.pow(variable2));
return result;
}
}
return null;
}
}
//Add this rule to the list of rules
RulesManager.addRule(engine.getInterface(rule, Rule.class));

View File

@ -0,0 +1,65 @@
/*
SETTINGS: (please don't move this part)
PATH=functions.PowerRule
*/
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.FunctionOperator;
import org.warp.picalculator.math.FunctionDynamic;
import org.warp.picalculator.math.FunctionSingle;
import org.warp.picalculator.math.MathContext;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.warp.picalculator.ScriptUtils;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
import org.warp.picalculator.math.rules.RulesManager;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.functions.SumSubtraction;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Power;
/**
* Power
* a^b = c
*
* @author Andrea Cavalli
*
*/
public class PowerRule implements Rule {
// Rule name
@Override
public String getRuleName() {
return "Power";
}
// Rule type
@Override
public RuleType getRuleType() {
return RuleType.CALCULATION;
}
/* Rule function
Returns:
- null if it's not executable on the function "f"
- An ObjectArrayList<Function> if it did something
*/
@Override
public ObjectArrayList<Function> execute(Function f) throws org.warp.picalculator.Error, InterruptedException {
if (f instanceof Power) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
Function variable1 = ((FunctionOperator)f).getParameter1();
Function variable2 = ((FunctionOperator)f).getParameter2();
MathContext mathContext = f.getMathContext();
if (variable1 instanceof Number && variable2 instanceof Number) {
//a^b = c
result.add(((Number)variable1).pow((Number)variable2));
return result;
}
}
return null;
}
}

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=functions.RootRule
*/
import org.warp.picalculator.math.Function;
@ -10,6 +10,9 @@ import org.warp.picalculator.math.FunctionSingle;
import org.warp.picalculator.math.MathContext;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.warp.picalculator.Error;
import org.warp.picalculator.Errors;
import org.warp.picalculator.ScriptUtils;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
@ -23,6 +26,7 @@ import org.warp.picalculator.math.functions.Division;
import org.warp.picalculator.math.functions.Root;
import org.warp.picalculator.math.functions.RootSquare;
import java.math.BigDecimal;
import java.math.BigInteger;
/**
* Root
@ -31,7 +35,7 @@ import java.math.BigDecimal;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class RootRule implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -50,26 +54,29 @@ public class __INSERT_CLASS_NAME__ implements Rule {
- An ObjectArrayList<Function> if it did something
*/
@Override
public ObjectArrayList<Function> execute(Function f) {
var isSquare = false;
public ObjectArrayList<Function> execute(Function f) throws Error, InterruptedException {
boolean isSquare = false;
if ((isSquare = f instanceof RootSquare) || f instanceof Root) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var mathContext = f.getMathContext();
var variable1 = f.getParameter1();
var variable2 = f.getParameter2();
var isSolvable = false;
var canBePorted = false;
MathContext mathContext = f.getMathContext();
Function variable1 = ((FunctionOperator)f).getParameter1();
Function variable2 = ((FunctionOperator)f).getParameter2();
boolean isSolvable = false, canBePorted = false;
if (variable1 instanceof Number && variable2 instanceof Number) {
if (mathContext.exactMode) {
result.add(((Number)variable1).pow(new Number(mathContext, BigDecimal.ONE).divide(((Number)variable1))));
return result;
}
isSolvable = isSolvable|!mathContext.exactMode;
if (!isSolvable) {
try {
var resultVar = variable2.pow(new Number(mathContext, BigDecimal.ONE).divide(variable1));
var originalVariable = resultVar.pow(new Number(mathContext, 2));
if (originalVariable.equals(f.getParameter2())) {
Function resultVar = ((Number)variable2).pow(new Number(mathContext, BigDecimal.ONE).divide(((Number)variable1)));
Function originalVariable = ((Number)resultVar).pow(new Number(mathContext, 2));
if ((originalVariable).equals(((FunctionOperator)f).getParameter2())) {
isSolvable = true;
}
} catch (ex) {
ex.printStackTrace();
} catch (Exception ex) {
throw (Error) new Error(Errors.ERROR, ex.getMessage()).initCause(ex);
}
}
}
@ -78,7 +85,7 @@ public class __INSERT_CLASS_NAME__ implements Rule {
}
if (isSolvable) {
result.add(variable2.pow(new Number(mathContext, BigInteger.ONE).divide(variable1)));
result.add(((Number)variable2).pow(new Number(mathContext, BigInteger.ONE).divide((Number)variable1)));
return result;
}
if (canBePorted) {

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=functions.SubtractionRule
*/
import org.warp.picalculator.math.Function;
@ -28,7 +28,7 @@ import org.warp.picalculator.math.functions.Division;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class SubtractionRule implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -50,12 +50,12 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
if (f instanceof Subtraction) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var variable1 = f.getParameter1();
var variable2 = f.getParameter2();
var mathContext = f.getMathContext();
Function variable1 = ((FunctionOperator)f).getParameter1();
Function variable2 = ((FunctionOperator)f).getParameter2();
MathContext mathContext = f.getMathContext();
if (variable1 instanceof Number && variable2 instanceof Number) {
//a-b = a+(b*-1) = c
result.add(variable1.add(variable2.multiply(new Number(mathContext, -1))));
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number(mathContext, -1))));
return result;
}
}

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=functions.SumRule
*/
import org.warp.picalculator.math.Function;
@ -28,7 +28,7 @@ import org.warp.picalculator.math.functions.Division;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class SumRule implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -50,12 +50,12 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
if (f instanceof Sum) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var variable1 = f.getParameter1();
var variable2 = f.getParameter2();
var mathContext = f.getMathContext();
Function variable1 = ((FunctionOperator)f).getParameter1();
Function variable2 = ((FunctionOperator)f).getParameter2();
MathContext mathContext = f.getMathContext();
if (variable1 instanceof Number && variable2 instanceof Number) {
//a+b = c
result.add(variable1.add(variable2));
result.add(((Number)variable1).add(((Number)variable2)));
return result;
}
}

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=functions.SumSubtractionRule
*/
import org.warp.picalculator.math.Function;
@ -28,7 +28,7 @@ import org.warp.picalculator.math.functions.Division;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class SumSubtractionRule implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -50,13 +50,13 @@ public class __INSERT_CLASS_NAME__ implements Rule {
public ObjectArrayList<Function> execute(Function f) {
if (f instanceof SumSubtraction) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var variable1 = f.getParameter1();
var variable2 = f.getParameter2();
var mathContext = f.getMathContext();
Function variable1 = ((FunctionOperator)f).getParameter1();
Function variable2 = ((FunctionOperator)f).getParameter2();
MathContext mathContext = f.getMathContext();
if (variable1 instanceof Number && variable2 instanceof Number) {
//a±b = c, d
result.add(variable1.add(variable2));
result.add(variable1.add(variable2.multiply(new Number(mathContext, -1))));
result.add(((Number)variable1).add((Number)variable2));
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number(mathContext, -1))));
return result;
}
}

View File

@ -1,6 +1,6 @@
/*
SETTINGS: (please don't move this part)
PATH=__INSERT_PACKAGE_WITH_CLASS_NAME__
PATH=functions.VariableRule
*/
import org.warp.picalculator.math.Function;
@ -13,6 +13,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.nevec.rjm.BigDecimalMath;
import org.warp.picalculator.Utils;
import org.warp.picalculator.math.MathematicalSymbols;
import org.warp.picalculator.Error;
import org.warp.picalculator.ScriptUtils;
import org.warp.picalculator.math.rules.Rule;
import org.warp.picalculator.math.rules.RuleType;
@ -30,7 +31,7 @@ import org.warp.picalculator.math.functions.Number;
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
public class VariableRule implements Rule {
// Rule name
@Override
public String getRuleName() {
@ -49,11 +50,11 @@ public class __INSERT_CLASS_NAME__ implements Rule {
- An ObjectArrayList<Function> if it did something
*/
@Override
public ObjectArrayList<Function> execute(Function f) {
public ObjectArrayList<Function> execute(Function f) throws Error {
if (f instanceof Variable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var variable = f.getChar();
var mathContext = f.getMathContext();
Character variable = ((Variable)f).getChar();
MathContext mathContext = f.getMathContext();
if (mathContext.exactMode == false) {
if (variable.equals(MathematicalSymbols.PI)) {
//a = n