Added all the rules, converted automatically, to fix.

This commit is contained in:
Andrea Cavalli 2018-03-24 23:33:04 +01:00
parent 3fa243375b
commit 01925526a1
40 changed files with 2907 additions and 2 deletions

View File

@ -120,15 +120,17 @@ public class RulesManager {
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_MIN, "RulesManager", ruleName, "This rule is not cached. Compiling");
try {
r = compileJavaRule(scriptFile, tDir);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException e) {
e.printStackTrace();
}
}
if (r != null) {
RulesManager.addRule(r);
}
}
}
}
Utils.out.println(Utils.OUTPUTLEVEL_NODEBUG, "RulesManager", "Loaded all the rules successfully");
Utils.zip(tDir.toString(), cacheFilePath.toString(), "");
Utils.out.println(Utils.OUTPUTLEVEL_NODEBUG, "RulesManager", "Cached the compiled rules");
@ -142,6 +144,7 @@ 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('.');

View File

@ -1,3 +1,44 @@
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
ExpandRule1
ExpandRule2
ExpandRule5
ExponentRule1
ExponentRule2
ExponentRule3
ExponentRule4
ExponentRule9
ExponentRule15
ExponentRule16
ExponentRule17
FractionsRule1
FractionsRule2
FractionsRule3
FractionsRule4
FractionsRule5
FractionsRule11
FractionsRule12
FractionsRule14
NumberRule1
NumberRule2
NumberRule3
NumberRule4
NumberRule5
NumberRule7
UndefinedRule1
UndefinedRule2
VariableRule1
VariableRule2
VariableRule3
1 Rule file
2 functions/Division
3 functions/EmptyNumber
4 functions/Expression
5 functions/Joke
6 functions/Multiplication
7 functions/Negative
8 functions/Number
9 functions/Power
10 functions/Root
11 functions/Subtraction
12 functions/Sum
13 functions/SumSubtraction
14 functions/Variable
15 ExpandRule1
16 ExpandRule2
17 ExpandRule5
18 ExponentRule1
19 ExponentRule2
20 ExponentRule3
21 ExponentRule4
22 ExponentRule9
23 ExponentRule15
24 ExponentRule16
25 ExponentRule17
26 FractionsRule1
27 FractionsRule2
28 FractionsRule3
29 FractionsRule4
30 FractionsRule5
31 FractionsRule11
32 FractionsRule12
33 FractionsRule14
34 NumberRule1
35 NumberRule2
36 NumberRule3
37 NumberRule4
38 NumberRule5
39 NumberRule7
40 UndefinedRule1
41 UndefinedRule2
42 VariableRule1
43 VariableRule2
44 VariableRule3

View File

@ -0,0 +1,139 @@
/*
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;
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;
/**
* Expand rule
* -(-a) = a
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "ExpandRule2";
}
// 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) {
Function fnc = f;
if (fnc.getParameter1().equals(new Number(fnc.getMathContext(), -1))) {
var expr = fnc.getParameter2();
if (expr instanceof Sum) {
isExecutable = true;
} else if (expr instanceof Subtraction) {
isExecutable = true;
} else if (expr instanceof SumSubtraction) {
isExecutable = true;
}
}
} else if (f instanceof Subtraction || f instanceof SumSubtraction) {
Function fnc = f;
var expr = fnc.getParameter2();
if (expr instanceof Sum) {
isExecutable = true;
} else if (expr instanceof Subtraction) {
isExecutable = true;
} else if (expr instanceof SumSubtraction) {
isExecutable = true;
}
}
if (isExecutable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var root = f.getMathContext();
var expr = null;
var fromSubtraction = 0;
var subtraction = null;
if (f instanceof Multiplication) {
expr = f.getParameter2();
} else if (f instanceof Subtraction || f instanceof SumSubtraction) {
expr = f.getParameter2();
if (f instanceof Subtraction) {
fromSubtraction = 1;
} else {
fromSubtraction = 2;
}
}
if (f instanceof SumSubtraction) {
}
Function fnc = 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);
if (fromSubtraction > 0) {
subtraction = new Subtraction(root, 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);
if (fromSubtraction > 0) {
subtraction = new Subtraction(root, 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);
if (fromSubtraction > 0) {
subtraction = new SumSubtraction(root, f.getParameter1(), fnc2);
result.add(subtraction);
subtraction = new SumSubtraction(root, f.getParameter1(), fnc3);
result.add(subtraction);
result.add(subtraction);
} else {
result.add(fnc2);
result.add(fnc2);
}
}
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,72 @@
/*
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;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Negative;
import org.warp.picalculator.math.functions.Subtraction;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Expand rule
* -(-a) = a
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "ExpandRule5";
}
// 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 Negative) {
isExecutable = 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 (isExecutable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
if (f instanceof Negative) {
Function fnc = f;
result.add(((fnc.getParameter()).getParameter()).getParameter());
} else if (f instanceof Multiplication) {
Function fnc = f;
result.add(fnc.getParameter2().getParameter2());
}
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,67 @@
/*
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.Number;
import org.warp.picalculator.math.functions.Power;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Exponent rule
* 1^a=1
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "ExponentRule1";
}
// 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;
var root = f.getMathContext();
if (f instanceof Power) {
if (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;
} else {
return null;
}
}
}

View File

@ -0,0 +1,72 @@
/*
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.Multiplication;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Exponent rule
* a*a=a^2
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "ExponentRule15";
}
// 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) {
Function fnc = f;
if (fnc.getParameter1().equals(fnc.getParameter2())) {
isExecutable = true;
}
}
if (isExecutable) {
var 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);
result.add(p);
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,80 @@
/*
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.Multiplication;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.functions.Sum;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Exponent rule
* (a ^ b) * (a ^ c) = a ^ (b + c)
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "ExponentRule16";
}
// Rule type
@Override
public RuleType getRuleType() {
return RuleType.REDUCTION;
}
/* 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) {
Function fnc = f;
if (fnc.getParameter1() instanceof Power && fnc.getParameter2() instanceof Power) {
isExecutable = (fnc.getParameter1()).getParameter1().equals((fnc.getParameter2()).getParameter1());
} else if (fnc.getParameter1() instanceof Power) {
isExecutable = (fnc.getParameter1()).getParameter1().equals(fnc.getParameter2());
} else if (fnc.getParameter2() instanceof Power) {
isExecutable = (fnc.getParameter2()).getParameter1().equals(fnc.getParameter1());
}
}
if (isExecutable) {
var root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
Function fnc = 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())));
} else if (fnc.getParameter1() instanceof Power) {
result.add(new Power(root, fnc.getParameter2(), new Sum(root, 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())));
}
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,73 @@
/*
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.Multiplication;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.functions.Root;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Exponent rule
* ax=x^1/a
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "ExponentRule17";
}
// 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 Root) {
Function fnc = f;
if (fnc.getParameter1().equals(fnc.getParameter2())) {
isExecutable = true;
}
}
if (isExecutable) {
var 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);
result.add(p);
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,65 @@
/*
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.functions.Number;
import org.warp.picalculator.math.functions.Power;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Exponent rule
* a^1=a
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "ExponentRule2";
}
// 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 Power) {
Function fnc = 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;
} else {
return null;
}
}
}

View File

@ -0,0 +1,65 @@
/*
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.functions.Number;
import org.warp.picalculator.math.functions.Power;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Exponent rule
* a^0=1
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "ExponentRule3";
}
// 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 Power) {
Function fnc = 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;
} else {
return null;
}
}
}

View File

@ -0,0 +1,77 @@
/*
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.Expression;
import org.warp.picalculator.math.functions.Multiplication;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Exponent rule
* (a*b)^n=a^n*b^n
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "ExponentRule4";
}
// 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 Power) {
Function fnc = 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;
} else {
return null;
}
}
}

View File

@ -0,0 +1,70 @@
/*
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.Multiplication;
import org.warp.picalculator.math.functions.Power;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Exponent rule
* (a ^ b) ^ c = a ^ (b * c)
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "ExponentRule9";
}
// 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 Power) {
Function fnc = 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;
} else {
return null;
}
}
}

View File

@ -0,0 +1,141 @@
/*
SETTINGS: (please don't move this part)
PATH=FractionsRule2
*/
//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 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
* 0 / a = 0
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "FractionsRule1";
}
// 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;
var root = f.getMathContext();
if (f instanceof Division) {
Function fnc = f;
if (fnc.getParameter1() instanceof Number) {
var numb1 = fnc.getParameter1();
if (numb1.equals(new Number(root, 0))) {
if (fnc.getParameter2() instanceof Number) {
var numb2 = fnc.getParameter2();
if (numb2.equals(new Number(root, 0)) == false) {
isExecutable = true;
}
} else {
isExecutable = true;
}
}
}
}
if (isExecutable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add(new Number(f.getMathContext(), 0));
return result;
} else {
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,65 @@
/*
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.functions.Division;
import org.warp.picalculator.math.functions.Number;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Fractions rule
* a / a = 1
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "FractionsRule3";
}
// 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) {
Function fnc = f;
if (fnc.getParameter1().equals(fnc.getParameter2())) {
isExecutable = true;
}
}
if (isExecutable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add(new Number(f.getMathContext(), 1));
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,73 @@
/*
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.functions.Division;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Power;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Fractions rule
* (a / b) ^ -1 = b / a
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "FractionsRule4";
}
// 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 Power) {
Function fnc = f;
if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Number) {
var n2 = fnc.getParameter2();
if (n2.equals(new Number(f.getMathContext(), -1))) {
isExecutable = true;
}
}
}
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);
result.add(res);
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,88 @@
/*
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 java.math.BigDecimal;
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 org.warp.picalculator.math.functions.Power;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Fractions rule
* (a / b) ^ -c = (b / a) ^ c
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "FractionsRule5";
}
// 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 Power) {
Function fnc = f;
if (fnc.getParameter1() instanceof Division) {
if (fnc.getParameter2() instanceof Multiplication && fnc.getParameter2().getParameter1().equals(new Number(f.getMathContext(), -1))) {
isExecutable = true;
} else if (fnc.getParameter2() instanceof Number) {
var n2 = fnc.getParameter2();
if (n2.getTerm().compareTo(BigDecimal.ZERO) < 0) {
isExecutable = true;
}
}
}
}
if (isExecutable) {
var root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
Function fnc = f;
var a = (fnc.getParameter1()).getParameter1();
var b = (fnc.getParameter1()).getParameter2();
var c;
if (fnc.getParameter2() instanceof Multiplication) {
c = fnc.getParameter2().getParameter2();
} else {
c = fnc.getParameter2().multiply(new Number(root, "-1"));
}
var dv = new Division(root, b, a);
var pow = new Power(root, dv, c);
result.add(pow);
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,76 @@
/*
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.Multiplication;
import org.warp.picalculator.math.functions.Number;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Number rule
* a * 0 = 0
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "NumberRule1";
}
// 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 Multiplication) {
var root = f.getMathContext();
var mult = f;
if (mult.getParameter1() instanceof Number) {
var numb = mult.getParameter1();
if (numb.equals(new Number(root, 0))) {
isExecutable = true;
}
}
if (mult.getParameter2() instanceof Number) {
var numb = mult.getParameter2();
if (numb.equals(new Number(root, 0))) {
isExecutable = true;
}
}
}
if (isExecutable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add(new Number(f.getMathContext(), "0"));
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,95 @@
/*
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.Multiplication;
import org.warp.picalculator.math.functions.Number;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Number rule
* a * 1 = a
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "NumberRule2";
}
// 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 Multiplication) {
var root = f.getMathContext();
var mult = f;
if (mult.getParameter1() instanceof Number) {
var numb = mult.getParameter1();
if (numb.equals(new Number(root, 1))) {
isExecutable = true;
}
}
if (mult.getParameter2() instanceof Number) {
var numb = mult.getParameter2();
if (numb.equals(new Number(root, 1))) {
isExecutable = true;
}
}
}
if (isExecutable) {
var root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
var a = null;
var aFound = false;
var mult = f;
if (aFound == false & mult.getParameter1() instanceof Number) {
var 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();
if (numb.equals(new Number(root, 1))) {
a = mult.getParameter1();
aFound = true;
}
}
result.add(a);
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,92 @@
/*
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.Multiplication;
import org.warp.picalculator.math.functions.Negative;
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 it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Number rule
* a - a = 0
* -a + a = 0
* a ± a = {0, 2a}
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "NumberRule3";
}
// 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 Subtraction) {
var sub = f;
if (sub.getParameter1().equals(sub.getParameter2())) {
isExecutable = true;
}
} else if (f instanceof Sum) {
var sub = 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 (neg.equals(sub.getParameter2())) {
isExecutable = true;
}
}
}
} else if (f instanceof SumSubtraction) {
var sub = f;
if (sub.getParameter1().equals(sub.getParameter2())) {
isExecutable = true;
}
}
if (isExecutable) {
var root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
if (f instanceof SumSubtraction) {
var mul = new Multiplication(root, new Number(root, 2), f.getParameter1());
result.add(mul);
}
result.add(new Number(root, 0));
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,67 @@
/*
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.Subtraction;
import org.warp.picalculator.math.functions.Sum;
import org.warp.picalculator.math.functions.SumSubtraction;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Number rule
* a ± b = {a+b, a-b}
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "NumberRule4";
}
// 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 SumSubtraction) {
isExecutable = true;
}
if (isExecutable) {
var root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
var ss = f;
result.add(new Sum(root, ss.getParameter1(), ss.getParameter2()));
result.add(new Subtraction(root, ss.getParameter1(), ss.getParameter2()));
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,83 @@
/*
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.FunctionOperator;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Number;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Number rule
* a + 0 = a
* 0 + a = a
* a - 0 = a
* 0 - a = -a
* a ± 0 = a
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "NumberRule5";
}
// 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 Sum || f instanceof Subtraction || f instanceof SumSubtraction) {
var root = f.getMathContext();
Function fnc = 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;
}
}
}
if (isExecutable) {
var root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
Function fnc = f;
var a = fnc.getParameter1();
if (a.equals(new Number(root, 0))) {
if (f instanceof Subtraction) {
a = new Multiplication(root, new Number(root, -1), fnc.getParameter2());
} else {
a = fnc.getParameter2();
}
}
result.add(a);
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,66 @@
/*
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.Multiplication;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.functions.Sum;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Number rule
* a + a = 2a
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "NumberRule7";
}
// 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 Sum) {
isExecutable = f.getParameter1().equals(f.getParameter2());
}
if (isExecutable) {
var root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
var mult = new Multiplication(root, new Number(root, 2), f.getParameter1());
result.add(mult);
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,69 @@
/*
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.Number;
import org.warp.picalculator.math.functions.Power;
import org.warp.picalculator.math.functions.Undefined;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Undefined rule
* 0^0=undefined
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "UndefinedRule1";
}
// Rule type
@Override
public RuleType getRuleType() {
return RuleType.EXISTENCE;
}
/* 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 Power) {
var root = f.getMathContext();
Function fnc = f;
if (fnc.getParameter1().equals(new Number(root, 0)) && fnc.getParameter2().equals(new Number(root, 0))) {
isExecutable = true;
}
}
if (isExecutable) {
var root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add(new Undefined(root));
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,72 @@
/*
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 org.warp.picalculator.math.functions.Undefined;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Undefined rule
* a / 0 = undefined
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "UndefinedRule2";
}
// Rule type
@Override
public RuleType getRuleType() {
return RuleType.EXISTENCE;
}
/* 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) {
var root = f.getMathContext();
Function fnc = f;
if (fnc.getParameter2() instanceof Number) {
var numb = fnc.getParameter2();
if (numb.equals(new Number(root, 0))) {
isExecutable = true;
}
}
}
if (isExecutable) {
var root = f.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add(new Undefined(root));
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,95 @@
/*
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.FunctionOperator;
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 it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Variable rule
* ax+bx=(a+b)*x (a,b NUMBER; x VARIABLE|MULTIPLICATION)
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "VariableRule1";
}
// Rule type
@Override
public RuleType getRuleType() {
return RuleType.REDUCTION;
}
/* 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;
Function fnc = f;
if (f instanceof Subtraction || f instanceof Sum) {
if (fnc.getParameter1() instanceof Multiplication & fnc.getParameter2() instanceof Multiplication) {
var m1 = fnc.getParameter1();
var m2 = fnc.getParameter2();
if (m1.getParameter1().equals(m2.getParameter1()) || m1.getParameter2().equals(m2.getParameter2())) {
isExecutable = true;
}
}
}
if (isExecutable) {
var root = fnc.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
var m1 = fnc.getParameter1();
var m2 = fnc.getParameter2();
var a;
var b;
var x;
if (m1.getParameter2().equals(m2.getParameter2())) {
x = m1.getParameter2();
a = m1.getParameter1();
b = m2.getParameter1();
} else {
x = m1.getParameter1();
a = m1.getParameter2();
b = m2.getParameter2();
}
var 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);
result.add(retm);
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,84 @@
/*
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.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 it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Variable rule
* ax+x=(a+1)*x (a,b NUMBER; x VARIABLES)
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "VariableRule2";
}
// Rule type
@Override
public RuleType getRuleType() {
return RuleType.REDUCTION;
}
/* 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;
Function fnc = f;
if (f instanceof Sum || f instanceof Subtraction) {
if (fnc.getParameter1() instanceof Multiplication) {
var m1 = fnc.getParameter1();
if (m1.getParameter2().equals(fnc.getParameter2())) {
isExecutable = true;
}
}
}
if (isExecutable) {
var root = fnc.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
var m1 = fnc.getParameter1();
var a = m1.getParameter1();
var x = fnc.getParameter2();
var 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);
result.add(retm);
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,85 @@
/*
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.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 it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
* Variable rule
* x+ax=(a+1)*x (a,b NUMBER; x VARIABLES)
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "VariableRule3";
}
// Rule type
@Override
public RuleType getRuleType() {
return RuleType.REDUCTION;
}
/* 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;
Function fnc = f;
if (f instanceof Sum || f instanceof Subtraction) {
if (fnc.getParameter2() instanceof Multiplication) {
var m2 = fnc.getParameter2();
if (m2.getParameter2().equals(fnc.getParameter1())) {
isExecutable = true;
}
}
}
if (isExecutable) {
var root = fnc.getMathContext();
ObjectArrayList<Function> result = new ObjectArrayList<>();
var m2 = fnc.getParameter2();
var a = m2.getParameter1();
var x = fnc.getParameter1();
var 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);
result.add(retm);
return result;
} else {
return null;
}
}
}

View File

@ -0,0 +1,88 @@
/*
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;
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;
/**
* Division
* a/b = c
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "Division";
}
// 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 Division) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var variable1 = f.getParameter1();
var variable2 = f.getParameter2();
var mathContext = f.getMathContext();
if (variable1 instanceof Number && variable2 instanceof Number) {
if (mathContext.exactMode) {
if (variable1.isInteger() && variable2.isInteger()) {
var factors1, factors2, mcm;
try {
factors1 = variable1.getFactors();
factors2 = variable2.getFactors();
mcm = ScriptUtils.mcm(factors1, factors2);
} catch (error) {
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) {
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));
return result;
}
}
}
return null;
}
}

View File

@ -0,0 +1,47 @@
/*
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;
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;
/**
* EmptyNumber
*
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "EmptyNumber";
}
// 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) {
return null;
}
}

View File

@ -0,0 +1,58 @@
/*
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;
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.Expression;
/**
* Expression
* (x) = x
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "Expression";
}
// 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 Expression) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
result.add(f.getParameter(0));
return result;
}
return null;
}
}

View File

@ -0,0 +1,47 @@
/*
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;
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;
/**
* Joke
*
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "Joke";
}
// 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) {
return null;
}
}

View File

@ -0,0 +1,64 @@
/*
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;
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;
/**
* Multiplication
* a*b = c
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "Multiplication";
}
// 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 Multiplication) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var variable1 = f.getParameter1();
var variable2 = f.getParameter2();
var mathContext = f.getMathContext();
if (variable1 instanceof Number && variable2 instanceof Number) {
//multiply a by b (a*b = c)
result.add(variable1.multiply(variable2));
return result;
}
}
return null;
}
}

View File

@ -0,0 +1,74 @@
/*
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;
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.Number;
import org.warp.picalculator.math.functions.Negative;
import org.warp.picalculator.Error;
import org.warp.picalculator.Errors;
import java.lang.NullPointerException;
import java.lang.NumberFormatException;
import java.lang.ArithmeticException;
/**
* Negative
* -a = b
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "Negative";
}
// 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 Negative) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var variable = f.getParameter();
var mathContext = f.getMathContext();
if (variable instanceof Number) {
//-a = a*-1 = b
try {
result.add(variable.multiply(new Number(mathContext, -1)));
} catch (ex) {
if (ex instanceof NullPointerException) {
throw new Error(Errors.ERROR);
} else if (ex instanceof NumberFormatException) {
throw new Error(Errors.SYNTAX_ERROR);
} else if (ex instanceof ArithmeticException) {
throw new Error(Errors.NUMBER_TOO_SMALL);
}
}
return result;
}
}
return null;
}
}

View File

@ -0,0 +1,49 @@
// 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,53 @@
// 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,90 @@
/*
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;
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.Root;
import org.warp.picalculator.math.functions.RootSquare;
import java.math.BigDecimal;
/**
* Root
* ab = c
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "Root";
}
// 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) {
var 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;
if (variable1 instanceof Number && variable2 instanceof Number) {
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())) {
isSolvable = true;
}
} catch (ex) {
ex.printStackTrace();
}
}
}
if (!isSquare && !isSolvable && variable1 instanceof Number && variable1.equals(new Number(mathContext, 2))) {
canBePorted = true;
}
if (isSolvable) {
result.add(variable2.pow(new Number(mathContext, BigInteger.ONE).divide(variable1)));
return result;
}
if (canBePorted) {
result.add(new RootSquare(mathContext, variable2));
}
}
return null;
}
}

View File

@ -0,0 +1,64 @@
/*
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;
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;
/**
* Subtraction
* a-b = c
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "Subtraction";
}
// 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 Subtraction) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var variable1 = f.getParameter1();
var variable2 = f.getParameter2();
var 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))));
return result;
}
}
return null;
}
}

View File

@ -0,0 +1,64 @@
/*
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;
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;
/**
* Sum
* a+b = c
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "Sum";
}
// 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 Sum) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var variable1 = f.getParameter1();
var variable2 = f.getParameter2();
var mathContext = f.getMathContext();
if (variable1 instanceof Number && variable2 instanceof Number) {
//a+b = c
result.add(variable1.add(variable2));
return result;
}
}
return null;
}
}

View File

@ -0,0 +1,65 @@
/*
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;
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;
/**
* SumSumbraction
* a±b = c, d
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "SumSubtraction";
}
// 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 SumSubtraction) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var variable1 = f.getParameter1();
var variable2 = f.getParameter2();
var 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))));
return result;
}
}
return null;
}
}

View File

@ -0,0 +1,67 @@
/*
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;
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.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.Variable;
import org.warp.picalculator.math.functions.Number;
/**
* Variable
* a = n
*
* @author Andrea Cavalli
*
*/
public class __INSERT_CLASS_NAME__ implements Rule {
// Rule name
@Override
public String getRuleName() {
return "Variable";
}
// 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 Variable) {
ObjectArrayList<Function> result = new ObjectArrayList<>();
var variable = f.getChar();
var mathContext = f.getMathContext();
if (mathContext.exactMode == false) {
if (variable.equals(MathematicalSymbols.PI)) {
//a = n
result.add(new Number(mathContext, BigDecimalMath.pi(new java.math.MathContext(Utils.scale, Utils.scaleMode2))));
return result;
}
}
}
return null;
}
}