Port most non-function rules from Java to the DSL
This commit is contained in:
parent
6b814b84b6
commit
7d9b08affd
@ -12,38 +12,4 @@ functions/SumRule
|
||||
functions/SumSubtractionRule
|
||||
functions/VariableRule
|
||||
ExpandRule1
|
||||
ExpandRule2
|
||||
ExpandRule5
|
||||
ExponentRule1
|
||||
ExponentRule2
|
||||
ExponentRule3
|
||||
ExponentRule4
|
||||
ExponentRule8
|
||||
ExponentRule9
|
||||
ExponentRule15
|
||||
ExponentRule16
|
||||
ExponentRule17
|
||||
FractionsRule1
|
||||
FractionsRule2
|
||||
FractionsRule3
|
||||
FractionsRule4
|
||||
FractionsRule5
|
||||
FractionsRule6
|
||||
FractionsRule7
|
||||
FractionsRule8
|
||||
FractionsRule9
|
||||
FractionsRule10
|
||||
FractionsRule11
|
||||
FractionsRule12
|
||||
FractionsRule14
|
||||
NumberRule1
|
||||
NumberRule2
|
||||
NumberRule3
|
||||
NumberRule4
|
||||
NumberRule5
|
||||
NumberRule7
|
||||
UndefinedRule1
|
||||
UndefinedRule2
|
||||
VariableRule1
|
||||
VariableRule2
|
||||
VariableRule3
|
||||
ExponentRule17
|
9
rules/dsl/expand.rules
Normal file
9
rules/dsl/expand.rules
Normal file
@ -0,0 +1,9 @@
|
||||
expansion ExpandRule2a:
|
||||
a * (b + c) -> a*b + a*c
|
||||
expansion ExpandRule2b:
|
||||
(b + c) * a -> a*b + a*c
|
||||
|
||||
expansion ExpandRule5a:
|
||||
-(-a) -> a
|
||||
expansion ExpandRule5b:
|
||||
-1 * (-1 * a) -> a
|
27
rules/dsl/exponent.rules
Normal file
27
rules/dsl/exponent.rules
Normal file
@ -0,0 +1,27 @@
|
||||
calculation ExponentRule1:
|
||||
1^a -> 1
|
||||
|
||||
calculation ExponentRule2:
|
||||
a^1 -> a
|
||||
|
||||
calculation ExponentRule3:
|
||||
a^0 -> 1
|
||||
|
||||
expansion ExponentRule4:
|
||||
(a * b) ^ n -> a^n * b^n
|
||||
|
||||
expansion ExponentRule8:
|
||||
a ^ (b + c) -> a^b * a^c
|
||||
|
||||
expansion ExponentRule9:
|
||||
(a ^ b) ^ c -> a ^ (b * c)
|
||||
|
||||
expansion ExponentRule15:
|
||||
a * a -> a^2
|
||||
|
||||
reduction ExponentRule16a:
|
||||
a^b * a^c -> a ^ (b + c)
|
||||
reduction ExponentRule16b:
|
||||
a^b * a -> a ^ (b + 1)
|
||||
reduction ExponentRule16c:
|
||||
a * a^b -> a ^ (1 + b)
|
56
rules/dsl/fractions.rules
Normal file
56
rules/dsl/fractions.rules
Normal file
@ -0,0 +1,56 @@
|
||||
calculation FractionsRule1:
|
||||
0 / a -> 0
|
||||
|
||||
calculation FractionsRule2:
|
||||
a / 1 -> a
|
||||
|
||||
expansion FractionsRule3:
|
||||
a / a -> 1
|
||||
|
||||
expansion FractionsRule4:
|
||||
(a / b) ^ -1 -> b / a
|
||||
|
||||
expansion FractionsRule5a:
|
||||
(a / b) ^ (-1 * c) -> (b / a) ^ c
|
||||
expansion FractionsRule5b:
|
||||
(a / b) ^ -c -> (b / a) ^ c
|
||||
|
||||
expansion FractionsRule6:
|
||||
a ^ -1 -> 1 / a
|
||||
|
||||
expansion FractionsRule7a:
|
||||
a ^ -b -> 1 / a^b
|
||||
expansion FractionsRule7b:
|
||||
a ^ (-1 * b) -> 1 / a^b
|
||||
|
||||
calculation FractionsRule8a:
|
||||
(-1 * a) / (-1 * b) -> a / b
|
||||
calculation FractionsRule8b:
|
||||
(-1 * a) / (b * -1) -> a / b
|
||||
calculation FractionsRule8c:
|
||||
(a * -1) / (-1 * b) -> a / b
|
||||
calculation FractionsRule8d:
|
||||
(a * -1) / (b * -1) -> a / b
|
||||
|
||||
expansion FractionsRule9a:
|
||||
(-1 * a) / b -> -1 * (a / b)
|
||||
expansion FractionsRule9b:
|
||||
(a * -1) / b -> -1 * (a / b)
|
||||
|
||||
expansion FractionsRule10a:
|
||||
a / (-1 * b) -> -1 * (a / b)
|
||||
expansion FractionsRule10b:
|
||||
a / (b * -1) -> -1 * (a / b)
|
||||
|
||||
expansion FractionsRule11:
|
||||
a / (b / c) -> (a * c) / b
|
||||
|
||||
expansion FractionsRule12:
|
||||
(b / c) / a -> b / (c * a)
|
||||
|
||||
expansion FractionsRule14a:
|
||||
(a / b) * (c / d) -> (a * c) / (b * d)
|
||||
expansion FractionsRule14b:
|
||||
(a / b) * c -> (a * c) / b
|
||||
expansion FractionsRule14c:
|
||||
a * (c / d) -> (a * c) / d
|
33
rules/dsl/number.rules
Normal file
33
rules/dsl/number.rules
Normal file
@ -0,0 +1,33 @@
|
||||
calculation NumberRule1a:
|
||||
0 * a -> 0
|
||||
calculation NumberRule1b:
|
||||
a * 0 -> 0
|
||||
|
||||
calculation NumberRule2a:
|
||||
1 * a -> a
|
||||
calculation NumberRule2b:
|
||||
a * 1 -> a
|
||||
|
||||
calculation NumberRule3a:
|
||||
a - a -> 0
|
||||
calculation NumberRule3b:
|
||||
(-1 * a) + a -> 0
|
||||
calculation NumberRule3c:
|
||||
a +- a -> [0, 2*a]
|
||||
|
||||
expansion NumberRule4:
|
||||
a +- b -> [a + b, a - b]
|
||||
|
||||
calculation NumberRule5a:
|
||||
a + 0 -> a
|
||||
calculation NumberRule5b:
|
||||
0 + a -> a
|
||||
calculation NumberRule5c:
|
||||
a - 0 -> a
|
||||
calculation NumberRule5d:
|
||||
0 - a -> -1 * a
|
||||
calculation NumberRule5e:
|
||||
a +- 0 -> a
|
||||
|
||||
expansion NumberRule7:
|
||||
a + a -> 2 * a
|
5
rules/dsl/undefined.rules
Normal file
5
rules/dsl/undefined.rules
Normal file
@ -0,0 +1,5 @@
|
||||
existence UndefinedRule1:
|
||||
0^0 -> undefined
|
||||
|
||||
existence UndefinedRule2:
|
||||
a / 0 -> undefined
|
18
rules/dsl/variable.rules
Normal file
18
rules/dsl/variable.rules
Normal file
@ -0,0 +1,18 @@
|
||||
reduction VariableRule1a:
|
||||
x*a + x*b -> (a + b) * x
|
||||
reduction VariableRule1b:
|
||||
x*a - x*b -> (a - b) * x
|
||||
reduction VariableRule1c:
|
||||
a*x + b*x -> (a + b) * x
|
||||
reduction VariableRule1d:
|
||||
a*x - b*x -> (a - b) * x
|
||||
|
||||
reduction VariableRule2a:
|
||||
a*x + x -> (a + 1) * x
|
||||
reduction VariableRule2b:
|
||||
a*x - x -> (a - 1) * x
|
||||
|
||||
reduction VariableRule3a:
|
||||
x + a*x -> (1 + a) * x
|
||||
reduction VariableRule3b:
|
||||
x - a*x -> (1 - a) * x
|
@ -1,80 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=ExpandRule2
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Sum;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
import it.cavallium.warppi.util.Errors;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Expand rule
|
||||
* a(b+c)=ab+ac
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExpandRule2 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(final Function f) throws Error {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Multiplication) {
|
||||
final Multiplication fnc = (Multiplication) f;
|
||||
if (fnc.getParameter1() instanceof Sum)
|
||||
isExecutable = true;
|
||||
else if (fnc.getParameter2() instanceof Sum)
|
||||
isExecutable = true;
|
||||
else
|
||||
isExecutable = false;
|
||||
}
|
||||
if (isExecutable) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final MathContext root = f.getMathContext();
|
||||
|
||||
final Multiplication fnc = (Multiplication) f;
|
||||
final Sum sum;
|
||||
final Function a;
|
||||
if (fnc.getParameter1() instanceof Sum) {
|
||||
sum = (Sum) fnc.getParameter1();
|
||||
a = fnc.getParameter2();
|
||||
} else if (fnc.getParameter2() instanceof Sum) {
|
||||
sum = (Sum) fnc.getParameter2();
|
||||
a = fnc.getParameter1();
|
||||
} else
|
||||
throw new Error(Errors.UNBALANCED_STACK);
|
||||
|
||||
final Function b = sum.getParameter1();
|
||||
final Function c = sum.getParameter2();
|
||||
final Multiplication ab = new Multiplication(root, a, b);
|
||||
final Multiplication ac = new Multiplication(root, a, c);
|
||||
result.add(new Sum(root, ab, ac));
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=ExpandRule5
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.FunctionSingle;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Negative;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Expand rule
|
||||
* -(-a) = a
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExpandRule5 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Negative)
|
||||
isExecutable = ((FunctionSingle) f).getParameter() instanceof Negative;
|
||||
else if (f instanceof Multiplication)
|
||||
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());
|
||||
|
||||
if (isExecutable) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
|
||||
if (f instanceof Negative) {
|
||||
final Negative fnc = (Negative) f;
|
||||
result.add(((FunctionSingle) ((FunctionSingle) fnc.getParameter()).getParameter()).getParameter());
|
||||
} else if (f instanceof Multiplication) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
result.add(((FunctionOperator) fnc.getParameter2()).getParameter2());
|
||||
}
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=ExponentRule1
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Power;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Exponent rule
|
||||
* 1^a=1
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExponentRule1 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
final MathContext root = f.getMathContext();
|
||||
if (f instanceof Power)
|
||||
if (((Power) f).getParameter1().equals(new Number(root, 1)))
|
||||
isExecutable = true;
|
||||
|
||||
if (isExecutable) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Number(root, 1));
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=ExponentRule15
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Power;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Exponent rule
|
||||
* a*a=a^2
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExponentRule15 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Multiplication) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter1().equals(fnc.getParameter2()))
|
||||
isExecutable = true;
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
final Function a = fnc.getParameter1();
|
||||
final Function two = new Number(root, 2);
|
||||
final Function p = new Power(root, a, two);
|
||||
result.add(p);
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=ExponentRule16
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Power;
|
||||
import it.cavallium.warppi.math.functions.Sum;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Exponent rule
|
||||
* (a ^ b) * (a ^ c) = a ^ (b + c)
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExponentRule16 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Multiplication) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter1() instanceof Power && fnc.getParameter2() instanceof Power)
|
||||
isExecutable = ((FunctionOperator) fnc.getParameter1()).getParameter1().equals(((FunctionOperator) fnc.getParameter2()).getParameter1());
|
||||
else if (fnc.getParameter1() instanceof Power)
|
||||
isExecutable = ((FunctionOperator) fnc.getParameter1()).getParameter1().equals(fnc.getParameter2());
|
||||
else if (fnc.getParameter2() instanceof Power)
|
||||
isExecutable = ((FunctionOperator) fnc.getParameter2()).getParameter1().equals(fnc.getParameter1());
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter1() instanceof Power && fnc.getParameter2() instanceof Power)
|
||||
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, ((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), ((FunctionOperator) fnc.getParameter2()).getParameter2())));
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=ExponentRule2
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Power;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Exponent rule
|
||||
* a^1=a
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExponentRule2 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Power) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter2().equals(new Number(f.getMathContext(), 1)))
|
||||
isExecutable = true;
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(((FunctionOperator) f).getParameter1());
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=ExponentRule3
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Power;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Exponent rule
|
||||
* a^0=1
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExponentRule3 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Power) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter2().equals(new Number(f.getMathContext(), 0)))
|
||||
isExecutable = true;
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Number(f.getMathContext(), 1));
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=ExponentRule4
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Power;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Exponent rule
|
||||
* (a*b)^n=a^n*b^n
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExponentRule4 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Power) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter1() instanceof Multiplication && fnc.getParameter2() instanceof Number)
|
||||
isExecutable = true;
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
final FunctionOperator mult = (FunctionOperator) fnc.getParameter1();
|
||||
final Function a = mult.getParameter1();
|
||||
final Function b = mult.getParameter2();
|
||||
final Function n = fnc.getParameter2();
|
||||
final Function p1 = new Power(root, a, n);
|
||||
final Function p2 = new Power(root, b, n);
|
||||
final Function retMult = new Multiplication(root, p1, p2);
|
||||
result.add(retMult);
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=ExponentRule8
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Power;
|
||||
import it.cavallium.warppi.math.functions.Sum;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Exponent rule
|
||||
* (a) ^ (b+c) = a ^ b * a ^ c
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExponentRule8 implements Rule {
|
||||
// Rule name
|
||||
@Override
|
||||
public String getRuleName() {
|
||||
return "ExponentRule8";
|
||||
}
|
||||
|
||||
// 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(final Function f) {
|
||||
if (f instanceof Power) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter2() instanceof Sum) {
|
||||
final Sum sum = (Sum) fnc.getParameter2();
|
||||
final MathContext root = f.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Function a = fnc.getParameter1();
|
||||
final Function b = sum.getParameter1();
|
||||
final Function c = sum.getParameter2();
|
||||
result.add(new Multiplication(root, new Power(root, a, b), new Power(root, a, c)));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=ExponentRule9
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Power;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Exponent rule
|
||||
* (a ^ b) ^ c = a ^ (b * c)
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExponentRule9 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Power) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter1() instanceof Power)
|
||||
isExecutable = true;
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final FunctionOperator powC = (FunctionOperator) f;
|
||||
final FunctionOperator powB = (FunctionOperator) powC.getParameter1();
|
||||
final Function p = new Power(root, powB.getParameter1(), new Multiplication(root, powB.getParameter2(), powC.getParameter2()));
|
||||
result.add(p);
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=FractionsRule1
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Fractions rule
|
||||
* 0 / a = 0
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class FractionsRule1 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
final MathContext root = f.getMathContext();
|
||||
if (f instanceof Division) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter1() instanceof Number) {
|
||||
final Function numb1 = fnc.getParameter1();
|
||||
if (numb1.equals(new Number(root, 0)))
|
||||
if (fnc.getParameter2() instanceof Number) {
|
||||
final Function numb2 = fnc.getParameter2();
|
||||
if (numb2.equals(new Number(root, 0)) == false)
|
||||
isExecutable = true;
|
||||
} else
|
||||
isExecutable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Number(f.getMathContext(), 0));
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=FractionsRule10
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Number rule
|
||||
* a/(-b) = -(a/b)
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class FractionsRule10 implements Rule {
|
||||
// Rule name
|
||||
@Override
|
||||
public String getRuleName() {
|
||||
return "FractionsRule10";
|
||||
}
|
||||
|
||||
// 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(final Function f) {
|
||||
if (f instanceof Division) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final Division div = (Division) f;
|
||||
if (div.getParameter2() instanceof Multiplication && ((Multiplication) div.getParameter2()).isNegative()) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(Multiplication.newNegative(root, new Division(root, div.getParameter1(), ((Multiplication) div.getParameter2()).toPositive())));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=FractionsRule11
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Division) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
@SuppressWarnings("unused")
|
||||
Function a;
|
||||
@SuppressWarnings("unused")
|
||||
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) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
Function a;
|
||||
Function b;
|
||||
Function c;
|
||||
|
||||
final 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;
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=FractionsRule12
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Division) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
@SuppressWarnings("unused")
|
||||
Function a;
|
||||
@SuppressWarnings("unused")
|
||||
Function c;
|
||||
if (fnc.getParameter1() instanceof Division) {
|
||||
final FunctionOperator div2 = (FunctionOperator) fnc.getParameter1();
|
||||
a = fnc.getParameter1();
|
||||
c = div2.getParameter2();
|
||||
isExecutable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
Function a;
|
||||
Function b;
|
||||
Function c;
|
||||
|
||||
final FunctionOperator div2 = (FunctionOperator) fnc.getParameter1();
|
||||
a = fnc.getParameter2();
|
||||
b = div2.getParameter1();
|
||||
c = div2.getParameter2();
|
||||
result.add(new Division(fnc.getMathContext(), b, new Multiplication(fnc.getMathContext(), c, a)));
|
||||
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=FractionsRule14
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Multiplication) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
@SuppressWarnings("unused")
|
||||
Function a;
|
||||
@SuppressWarnings("unused")
|
||||
Function b;
|
||||
@SuppressWarnings("unused")
|
||||
Function c;
|
||||
@SuppressWarnings("unused")
|
||||
Function d;
|
||||
if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Division) {
|
||||
final FunctionOperator div1 = (FunctionOperator) fnc.getParameter1();
|
||||
final 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) {
|
||||
final FunctionOperator div1 = (FunctionOperator) fnc.getParameter1();
|
||||
a = div1.getParameter1();
|
||||
b = div1.getParameter2();
|
||||
c = fnc.getParameter2();
|
||||
isExecutable = true;
|
||||
} else if (fnc.getParameter2() instanceof Division) {
|
||||
final FunctionOperator div2 = (FunctionOperator) fnc.getParameter2();
|
||||
a = fnc.getParameter1();
|
||||
c = div2.getParameter1();
|
||||
d = div2.getParameter2();
|
||||
isExecutable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
Function a;
|
||||
Function b;
|
||||
Function c;
|
||||
Function d;
|
||||
|
||||
if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Division) {
|
||||
final FunctionOperator div1 = (FunctionOperator) fnc.getParameter1();
|
||||
final FunctionOperator div2 = (FunctionOperator) fnc.getParameter2();
|
||||
a = div1.getParameter1();
|
||||
b = div1.getParameter2();
|
||||
c = div2.getParameter1();
|
||||
d = div2.getParameter2();
|
||||
final 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) {
|
||||
final FunctionOperator div1 = (FunctionOperator) fnc.getParameter1();
|
||||
a = div1.getParameter1();
|
||||
b = div1.getParameter2();
|
||||
c = fnc.getParameter2();
|
||||
final Function div = new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), a, c), b);
|
||||
result.add(div);
|
||||
} else if (fnc.getParameter2() instanceof Division) {
|
||||
final FunctionOperator div2 = (FunctionOperator) fnc.getParameter2();
|
||||
a = fnc.getParameter1();
|
||||
c = div2.getParameter1();
|
||||
d = div2.getParameter2();
|
||||
final Function div = new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), a, c), d);
|
||||
result.add(div);
|
||||
}
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=FractionsRule2
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Fractions rule
|
||||
* a / 1 = a
|
||||
*
|
||||
* @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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Division) {
|
||||
final Division fnc = (Division) f;
|
||||
if (fnc.getParameter2() instanceof Number) {
|
||||
final Number numb = (Number) fnc.getParameter2();
|
||||
if (numb.equals(new Number(f.getMathContext(), 1)))
|
||||
isExecutable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Division fnc = (Division) f;
|
||||
result.add(fnc.getParameter1());
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=FractionsRule3
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Fractions rule
|
||||
* a / a = 1
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class FractionsRule3 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Division) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter1().equals(fnc.getParameter2()))
|
||||
isExecutable = true;
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Number(f.getMathContext(), 1));
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=FractionsRule4
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Power;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Fractions rule
|
||||
* (a / b) ^ -1 = b / a
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class FractionsRule4 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Power) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Number) {
|
||||
final Function n2 = fnc.getParameter2();
|
||||
if (n2.equals(new Number(f.getMathContext(), -1)))
|
||||
isExecutable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
final Function a = ((FunctionOperator) fnc.getParameter1()).getParameter1();
|
||||
final Function b = ((FunctionOperator) fnc.getParameter1()).getParameter2();
|
||||
final Function res = new Division(f.getMathContext(), b, a);
|
||||
result.add(res);
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=FractionsRule5
|
||||
*/
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Power;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Fractions rule
|
||||
* (a / b) ^ -c = (b / a) ^ c
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class FractionsRule5 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(final Function f) throws Error {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Power) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter1() instanceof Division)
|
||||
if (fnc.getParameter2() instanceof Multiplication && ((FunctionOperator) fnc.getParameter2()).getParameter1().equals(new Number(f.getMathContext(), -1)))
|
||||
isExecutable = true;
|
||||
else if (fnc.getParameter2() instanceof Number) {
|
||||
final Number n2 = (Number) fnc.getParameter2();
|
||||
if (n2.getTerm().compareTo(BigDecimal.ZERO) < 0)
|
||||
isExecutable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
final Function a = ((FunctionOperator) fnc.getParameter1()).getParameter1();
|
||||
final Function b = ((FunctionOperator) fnc.getParameter1()).getParameter2();
|
||||
Function c;
|
||||
if (fnc.getParameter2() instanceof Multiplication)
|
||||
c = ((FunctionOperator) fnc.getParameter2()).getParameter2();
|
||||
else
|
||||
c = ((Number) fnc.getParameter2()).multiply(new Number(root, "-1"));
|
||||
final Function dv = new Division(root, b, a);
|
||||
final Function pow = new Power(root, dv, c);
|
||||
result.add(pow);
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=FractionsRule6
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Power;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Number rule
|
||||
* a ^ -1 = 1/a
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class FractionsRule6 implements Rule {
|
||||
// Rule name
|
||||
@Override
|
||||
public String getRuleName() {
|
||||
return "FractionsRule6";
|
||||
}
|
||||
|
||||
// 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Power) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final Power pow = (Power) f;
|
||||
if (pow.getParameter2() instanceof Number) {
|
||||
final Function numb = pow.getParameter2();
|
||||
if (numb.equals(new Number(root, -1)))
|
||||
isExecutable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Function a = new Division(root, new Number(root, 1), ((Power) f).getParameter1());
|
||||
result.add(a);
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=FractionsRule7
|
||||
*/
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Power;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Number rule
|
||||
* a ^ -b = 1/(a^b)
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class FractionsRule7 implements Rule {
|
||||
// Rule name
|
||||
@Override
|
||||
public String getRuleName() {
|
||||
return "FractionsRule7";
|
||||
}
|
||||
|
||||
// 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(final Function f) {
|
||||
if (f instanceof Power) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final Power pow = (Power) f;
|
||||
if (pow.getParameter2() instanceof Number) {
|
||||
final Number numb = (Number) pow.getParameter2();
|
||||
if (numb.getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Function a = new Division(root, new Number(root, 1), new Power(root, ((Power) f).getParameter1(), ((Number) ((Power) f).getParameter2()).multiply(new Number(root, -1))));
|
||||
result.add(a);
|
||||
return result;
|
||||
}
|
||||
} else if (pow.getParameter2() instanceof Multiplication && ((Multiplication) pow.getParameter2()).getParameter1().equals(new Number(root, -1))) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Function a = new Division(root, new Number(root, 1), new Power(root, ((Power) f).getParameter1(), ((Multiplication) ((Power) f).getParameter2()).getParameter2()));
|
||||
result.add(a);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=FractionsRule8
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Number rule
|
||||
* -a/-b = a/b
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class FractionsRule8 implements Rule {
|
||||
// Rule name
|
||||
@Override
|
||||
public String getRuleName() {
|
||||
return "FractionsRule8";
|
||||
}
|
||||
|
||||
// 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(final Function f) {
|
||||
if (f instanceof Division) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final Division div = (Division) f;
|
||||
if (div.getParameter1() instanceof Multiplication && ((Multiplication) div.getParameter1()).isNegative())
|
||||
if (div.getParameter2() instanceof Multiplication && ((Multiplication) div.getParameter2()).isNegative()) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Division(root, ((Multiplication) div.getParameter1()).toPositive(), ((Multiplication) div.getParameter2()).toPositive()));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=FractionsRule9
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Number rule
|
||||
* (-a)/b = -(a/b)
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class FractionsRule9 implements Rule {
|
||||
// Rule name
|
||||
@Override
|
||||
public String getRuleName() {
|
||||
return "FractionsRule9";
|
||||
}
|
||||
|
||||
// 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(final Function f) {
|
||||
if (f instanceof Division) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final Division div = (Division) f;
|
||||
if (div.getParameter1() instanceof Multiplication && ((Multiplication) div.getParameter1()).isNegative()) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(Multiplication.newNegative(root, new Division(root, ((Multiplication) div.getParameter1()).toPositive(), div.getParameter2())));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=NumberRule1
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Number rule
|
||||
* a * 0 = 0
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class NumberRule1 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Multiplication) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final FunctionOperator mult = (FunctionOperator) f;
|
||||
if (mult.getParameter1() instanceof Number) {
|
||||
final Function numb = mult.getParameter1();
|
||||
if (numb.equals(new Number(root, 0)))
|
||||
isExecutable = true;
|
||||
}
|
||||
if (mult.getParameter2() instanceof Number) {
|
||||
final Function numb = mult.getParameter2();
|
||||
if (numb.equals(new Number(root, 0)))
|
||||
isExecutable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Number(f.getMathContext(), 0));
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=NumberRule2
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Number rule
|
||||
* a * 1 = a
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class NumberRule2 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Multiplication) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final Multiplication mult = (Multiplication) f;
|
||||
if (mult.getParameter1() instanceof Number) {
|
||||
final Function numb = mult.getParameter1();
|
||||
if (numb.equals(new Number(root, 1)))
|
||||
isExecutable = true;
|
||||
}
|
||||
if (mult.getParameter2() instanceof Number) {
|
||||
final Function numb = mult.getParameter2();
|
||||
if (numb.equals(new Number(root, 1)))
|
||||
isExecutable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
Function a = null;
|
||||
boolean aFound = false;
|
||||
final Multiplication mult = (Multiplication) f;
|
||||
if (aFound == false & mult.getParameter1() instanceof Number) {
|
||||
final Function numb = mult.getParameter1();
|
||||
if (numb.equals(new Number(root, 1))) {
|
||||
a = mult.getParameter2();
|
||||
aFound = true;
|
||||
}
|
||||
}
|
||||
if (aFound == false && mult.getParameter2() instanceof Number) {
|
||||
final Function numb = mult.getParameter2();
|
||||
if (numb.equals(new Number(root, 1))) {
|
||||
a = mult.getParameter1();
|
||||
aFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
result.add(a);
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=NumberRule3
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Subtraction;
|
||||
import it.cavallium.warppi.math.functions.Sum;
|
||||
import it.cavallium.warppi.math.functions.SumSubtraction;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Number rule
|
||||
* a - a = 0
|
||||
* -a + a = 0
|
||||
* a ± a = {0, 2a}
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class NumberRule3 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Subtraction) {
|
||||
final FunctionOperator sub = (FunctionOperator) f;
|
||||
if (sub.getParameter1().equals(sub.getParameter2()))
|
||||
isExecutable = true;
|
||||
} else if (f instanceof Sum) {
|
||||
final FunctionOperator sub = (FunctionOperator) f;
|
||||
if (sub.getParameter1() instanceof Multiplication)
|
||||
if (((FunctionOperator) sub.getParameter1()).getParameter1() instanceof Number && ((FunctionOperator) sub.getParameter1()).getParameter1().equals(new Number(f.getMathContext(), -1))) {
|
||||
final Function neg = ((FunctionOperator) sub.getParameter1()).getParameter2();
|
||||
if (neg.equals(sub.getParameter2()))
|
||||
isExecutable = true;
|
||||
}
|
||||
} else if (f instanceof SumSubtraction) {
|
||||
final FunctionOperator sub = (FunctionOperator) f;
|
||||
if (sub.getParameter1().equals(sub.getParameter2()))
|
||||
isExecutable = true;
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
if (f instanceof SumSubtraction) {
|
||||
final Function mul = new Multiplication(root, new Number(root, 2), ((FunctionOperator) f).getParameter1());
|
||||
result.add(mul);
|
||||
}
|
||||
result.add(new Number(root, 0));
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=NumberRule4
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Subtraction;
|
||||
import it.cavallium.warppi.math.functions.Sum;
|
||||
import it.cavallium.warppi.math.functions.SumSubtraction;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Number rule
|
||||
* a ± b = {a+b, a-b}
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class NumberRule4 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof SumSubtraction)
|
||||
isExecutable = true;
|
||||
|
||||
if (isExecutable) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final FunctionOperator ss = (FunctionOperator) f;
|
||||
result.add(new Sum(root, ss.getParameter1(), ss.getParameter2()));
|
||||
result.add(new Subtraction(root, ss.getParameter1(), ss.getParameter2()));
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=NumberRule5
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Subtraction;
|
||||
import it.cavallium.warppi.math.functions.Sum;
|
||||
import it.cavallium.warppi.math.functions.SumSubtraction;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
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 NumberRule5 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Sum || f instanceof Subtraction || f instanceof SumSubtraction) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final 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;
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final 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());
|
||||
else
|
||||
a = fnc.getParameter2();
|
||||
result.add(a);
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=NumberRule7
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Sum;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Number rule
|
||||
* a + a = 2a
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class NumberRule7 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Sum)
|
||||
isExecutable = ((FunctionOperator) f).getParameter1().equals(((FunctionOperator) f).getParameter2());
|
||||
|
||||
if (isExecutable) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Function mult = new Multiplication(root, new Number(root, 2), ((FunctionOperator) f).getParameter1());
|
||||
result.add(mult);
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=UndefinedRule1
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Power;
|
||||
import it.cavallium.warppi.math.functions.Undefined;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Undefined rule
|
||||
* 0^0=undefined
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class UndefinedRule1 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Power) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter1().equals(new Number(root, 0)) && fnc.getParameter2().equals(new Number(root, 0)))
|
||||
isExecutable = true;
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Undefined(root));
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=UndefinedRule2
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Division;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Undefined;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Undefined rule
|
||||
* a / 0 = undefined
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class UndefinedRule2 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Division) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter2() instanceof Number) {
|
||||
final Number numb = (Number) fnc.getParameter2();
|
||||
if (numb.equals(new Number(root, 0)))
|
||||
isExecutable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Undefined(root));
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=VariableRule1
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Subtraction;
|
||||
import it.cavallium.warppi.math.functions.Sum;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
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 VariableRule1 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Subtraction || f instanceof Sum) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter1() instanceof Multiplication & fnc.getParameter2() instanceof Multiplication) {
|
||||
final FunctionOperator m1 = (FunctionOperator) fnc.getParameter1();
|
||||
final FunctionOperator m2 = (FunctionOperator) fnc.getParameter2();
|
||||
if (m1.getParameter1().equals(m2.getParameter1()) || m1.getParameter2().equals(m2.getParameter2()))
|
||||
isExecutable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
final MathContext root = fnc.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final FunctionOperator m1 = (FunctionOperator) fnc.getParameter1();
|
||||
final FunctionOperator m2 = (FunctionOperator) fnc.getParameter2();
|
||||
Function a;
|
||||
Function b;
|
||||
Function 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();
|
||||
}
|
||||
|
||||
Function rets;
|
||||
if (fnc instanceof Sum)
|
||||
rets = new Sum(root, a, b);
|
||||
else
|
||||
rets = new Subtraction(root, a, b);
|
||||
final Function retm = new Multiplication(root, rets, x);
|
||||
result.add(retm);
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=VariableRule2
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Subtraction;
|
||||
import it.cavallium.warppi.math.functions.Sum;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Variable rule
|
||||
* ax+x=(a+1)*x (a,b NUMBER; x VARIABLES)
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class VariableRule2 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Sum || f instanceof Subtraction) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter1() instanceof Multiplication) {
|
||||
final FunctionOperator m1 = (FunctionOperator) fnc.getParameter1();
|
||||
if (m1.getParameter2().equals(fnc.getParameter2()))
|
||||
isExecutable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
final MathContext root = fnc.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final FunctionOperator m1 = (FunctionOperator) fnc.getParameter1();
|
||||
final Function a = m1.getParameter1();
|
||||
final Function x = fnc.getParameter2();
|
||||
|
||||
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));
|
||||
final Function retm = new Multiplication(root, rets, x);
|
||||
result.add(retm);
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
package rules;
|
||||
/*
|
||||
SETTINGS: (please don't move this part)
|
||||
PATH=VariableRule3
|
||||
*/
|
||||
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Multiplication;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.Subtraction;
|
||||
import it.cavallium.warppi.math.functions.Sum;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.math.rules.RuleType;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Variable rule
|
||||
* x+ax=(a+1)*x (a,b NUMBER; x VARIABLES)
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class VariableRule3 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(final Function f) {
|
||||
boolean isExecutable = false;
|
||||
if (f instanceof Sum || f instanceof Subtraction) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
if (fnc.getParameter2() instanceof Multiplication) {
|
||||
final FunctionOperator m2 = (FunctionOperator) fnc.getParameter2();
|
||||
if (m2.getParameter2().equals(fnc.getParameter1()))
|
||||
isExecutable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isExecutable) {
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
final MathContext root = fnc.getMathContext();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final FunctionOperator m2 = (FunctionOperator) fnc.getParameter2();
|
||||
final Function a = m2.getParameter1();
|
||||
final Function x = fnc.getParameter1();
|
||||
|
||||
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);
|
||||
|
||||
final Function retm = new Multiplication(root, rets, x);
|
||||
result.add(retm);
|
||||
return result;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user