|
|
|
|
@@ -1,11 +1,10 @@
|
|
|
|
|
package org.nwapw.abacus.plugin;
|
|
|
|
|
|
|
|
|
|
import org.nwapw.abacus.context.MutableReductionContext;
|
|
|
|
|
import org.nwapw.abacus.context.MutableEvaluationContext;
|
|
|
|
|
import org.nwapw.abacus.function.*;
|
|
|
|
|
import org.nwapw.abacus.number.NaiveNumber;
|
|
|
|
|
import org.nwapw.abacus.number.NumberInterface;
|
|
|
|
|
import org.nwapw.abacus.number.PreciseNumber;
|
|
|
|
|
import org.nwapw.abacus.tree.Reducer;
|
|
|
|
|
import org.nwapw.abacus.tree.TreeNode;
|
|
|
|
|
import org.nwapw.abacus.tree.VariableNode;
|
|
|
|
|
|
|
|
|
|
@@ -23,12 +22,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public final TreeValueOperator opSet = new TreeValueOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 0) {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, TreeNode[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, TreeNode[] params) {
|
|
|
|
|
return params.length == 2 && params[0] instanceof VariableNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, TreeNode[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, TreeNode[] params) {
|
|
|
|
|
String assignTo = ((VariableNode) params[0]).getVariable();
|
|
|
|
|
NumberInterface value = params[1].reduce(context.getReducer());
|
|
|
|
|
if(value == null) throw new EvaluationException();
|
|
|
|
|
@@ -41,12 +40,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public final TreeValueOperator opDefine = new TreeValueOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 0) {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, TreeNode[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, TreeNode[] params) {
|
|
|
|
|
return params.length == 2 && params[0] instanceof VariableNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, TreeNode[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, TreeNode[] params) {
|
|
|
|
|
String assignTo = ((VariableNode) params[0]).getVariable();
|
|
|
|
|
context.setDefinition(assignTo, params[1]);
|
|
|
|
|
NumberInterface value = params[1].reduce(context.getReducer());
|
|
|
|
|
@@ -59,12 +58,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public static final NumberOperator OP_ADD = new NumberOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 0) {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params[0].add(params[1]);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -73,12 +72,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public static final NumberOperator OP_SUBTRACT = new NumberOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 0) {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params[0].subtract(params[1]);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@@ -88,12 +87,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public static final NumberOperator OP_NEGATE = new NumberOperator(OperatorAssociativity.LEFT, OperatorType.UNARY_PREFIX, 0) {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params[0].negate();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -102,12 +101,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public static final NumberOperator OP_MULTIPLY = new NumberOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 1) {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params[0].multiply(params[1]);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -136,7 +135,7 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface instanceForPi() {
|
|
|
|
|
MutableReductionContext dummyContext = new MutableReductionContext(null, this, null);
|
|
|
|
|
MutableEvaluationContext dummyContext = new MutableEvaluationContext(null, this, null);
|
|
|
|
|
NumberInterface C = FUNCTION_SQRT.apply(dummyContext, new PreciseNumber("10005")).multiply(new PreciseNumber("426880"));
|
|
|
|
|
NumberInterface M = PreciseNumber.ONE;
|
|
|
|
|
NumberInterface L = new PreciseNumber("13591409");
|
|
|
|
|
@@ -167,12 +166,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public static final NumberOperator OP_DIVIDE = new NumberOperator(OperatorAssociativity.LEFT, OperatorType.BINARY_INFIX, 1) {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 2 && params[1].compareTo(context.getInheritedNumberImplementation().instanceForString(Integer.toString(0))) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params[0].divide(params[1]);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -182,14 +181,14 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
public static final NumberOperator OP_FACTORIAL = new NumberOperator(OperatorAssociativity.RIGHT, OperatorType.UNARY_POSTFIX, 0) {
|
|
|
|
|
//private HashMap<Class<? extends NumberInterface>, ArrayList<NumberInterface>> storedList = new HashMap<Class<? extends NumberInterface>, ArrayList<NumberInterface>>();
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1
|
|
|
|
|
&& params[0].fractionalPart().compareTo(context.getInheritedNumberImplementation().instanceForString("0")) == 0
|
|
|
|
|
&& params[0].signum() >= 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
NumberImplementation implementation = context.getInheritedNumberImplementation();
|
|
|
|
|
if (params[0].signum() == 0) {
|
|
|
|
|
return implementation.instanceForString("1");
|
|
|
|
|
@@ -214,13 +213,13 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public static final NumberOperator OP_NPR = new NumberOperator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 0) {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 2 && params[0].fractionalPart().signum() == 0
|
|
|
|
|
&& params[1].fractionalPart().signum() == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
NumberImplementation implementation = context.getInheritedNumberImplementation();
|
|
|
|
|
if (params[0].compareTo(params[1]) < 0 ||
|
|
|
|
|
params[0].signum() < 0 ||
|
|
|
|
|
@@ -245,13 +244,13 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public static final NumberOperator OP_NCR = new NumberOperator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 0) {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 2 && params[0].fractionalPart().signum() == 0
|
|
|
|
|
&& params[1].fractionalPart().signum() == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return OP_NPR.apply(context, params).divide(OP_FACTORIAL.apply(context, params[1]));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -260,12 +259,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public static final NumberFunction FUNCTION_ABS = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params[0].multiply(context.getInheritedNumberImplementation().instanceForString(Integer.toString(params[0].signum())));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -274,12 +273,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public static final NumberFunction FUNCTION_LN = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1 && params[0].compareTo(context.getInheritedNumberImplementation().instanceForString("0")) > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
NumberImplementation implementation = context.getInheritedNumberImplementation();
|
|
|
|
|
NumberInterface param = params[0];
|
|
|
|
|
NumberInterface one = implementation.instanceForString("1");
|
|
|
|
|
@@ -310,7 +309,7 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
* @param x value at which the series is evaluated. 0 < x < 2. (x=2 is convergent but impractical.)
|
|
|
|
|
* @return the partial sum.
|
|
|
|
|
*/
|
|
|
|
|
private NumberInterface getLogPartialSum(MutableReductionContext context, NumberInterface x) {
|
|
|
|
|
private NumberInterface getLogPartialSum(MutableEvaluationContext context, NumberInterface x) {
|
|
|
|
|
NumberImplementation implementation = context.getInheritedNumberImplementation();
|
|
|
|
|
NumberInterface maxError = x.getMaxError();
|
|
|
|
|
x = x.subtract(implementation.instanceForString("1")); //Terms used are for log(x+1).
|
|
|
|
|
@@ -355,12 +354,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public static final NumberFunction FUNCTION_RAND_INT = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return context.getInheritedNumberImplementation().instanceForString(Long.toString(Math.round(Math.random() * params[0].floor().intValue())));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -369,7 +368,7 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public static final NumberOperator OP_CARET = new NumberOperator(OperatorAssociativity.RIGHT, OperatorType.BINARY_INFIX, 2) {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
NumberInterface zero = context.getInheritedNumberImplementation().instanceForString("0");
|
|
|
|
|
return params.length == 2
|
|
|
|
|
&& !(params[0].compareTo(zero) == 0
|
|
|
|
|
@@ -378,7 +377,7 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
NumberImplementation implementation = context.getInheritedNumberImplementation();
|
|
|
|
|
NumberInterface zero = implementation.instanceForString("0");
|
|
|
|
|
if (params[0].compareTo(zero) == 0)
|
|
|
|
|
@@ -400,12 +399,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public static final NumberFunction FUNCTION_SQRT = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return OP_CARET.apply(context, params[0], context.getInheritedNumberImplementation().instanceForString(".5"));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -415,12 +414,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public static final NumberFunction FUNCTION_EXP = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
NumberImplementation implementation = context.getInheritedNumberImplementation();
|
|
|
|
|
NumberInterface maxError = params[0].getMaxError();
|
|
|
|
|
int n = 0;
|
|
|
|
|
@@ -453,12 +452,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public final NumberFunction functionSin = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
NumberImplementation implementation = context.getInheritedNumberImplementation();
|
|
|
|
|
NumberInterface pi = piFor(params[0].getClass());
|
|
|
|
|
NumberInterface twoPi = pi.multiply(implementation.instanceForString("2"));
|
|
|
|
|
@@ -478,12 +477,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public final NumberFunction functionCos = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return functionSin.apply(context, piFor(params[0].getClass()).divide(context.getInheritedNumberImplementation().instanceForString("2"))
|
|
|
|
|
.subtract(params[0]));
|
|
|
|
|
}
|
|
|
|
|
@@ -493,12 +492,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public final NumberFunction functionTan = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return functionSin.apply(context, params[0]).divide(functionCos.apply(context, params[0]));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -507,12 +506,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public final NumberFunction functionSec = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return context.getInheritedNumberImplementation().instanceForString("1").divide(functionCos.apply(context, params[0]));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -521,12 +520,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public final NumberFunction functionCsc = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return context.getInheritedNumberImplementation().instanceForString("1").divide(functionSin.apply(context, params[0]));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -535,12 +534,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public final NumberFunction functionCot = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return functionCos.apply(context, params[0]).divide(functionSin.apply(context, params[0]));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -550,13 +549,13 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public final NumberFunction functionArcsin = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1
|
|
|
|
|
&& FUNCTION_ABS.apply(context, params[0]).compareTo(context.getInheritedNumberImplementation().instanceForString("1")) <= 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
NumberImplementation implementation = context.getInheritedNumberImplementation();
|
|
|
|
|
if (FUNCTION_ABS.apply(context, params[0]).compareTo(implementation.instanceForString(".8")) >= 0) {
|
|
|
|
|
NumberInterface[] newParams = {FUNCTION_SQRT.apply(context, implementation.instanceForString("1").subtract(params[0].multiply(params[0])))};
|
|
|
|
|
@@ -584,12 +583,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public final NumberFunction functionArccos = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1 && FUNCTION_ABS.apply(context, params[0]).compareTo(context.getInheritedNumberImplementation().instanceForString("1")) <= 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return piFor(params[0].getClass()).divide(context.getInheritedNumberImplementation().instanceForString("2"))
|
|
|
|
|
.subtract(functionArcsin.apply(context, params));
|
|
|
|
|
}
|
|
|
|
|
@@ -600,12 +599,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public final NumberFunction functionArccsc = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1 && FUNCTION_ABS.apply(context, params[0]).compareTo(context.getInheritedNumberImplementation().instanceForString("1")) >= 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
NumberInterface[] reciprocalParamArr = {context.getInheritedNumberImplementation().instanceForString("1").divide(params[0])};
|
|
|
|
|
return functionArcsin.apply(context, reciprocalParamArr);
|
|
|
|
|
}
|
|
|
|
|
@@ -616,12 +615,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public final NumberFunction functionArcsec = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1 && FUNCTION_ABS.apply(context, params[0]).compareTo(context.getInheritedNumberImplementation().instanceForString("1")) >= 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
NumberInterface[] reciprocalParamArr = {context.getInheritedNumberImplementation().instanceForString("1").divide(params[0])};
|
|
|
|
|
return functionArccos.apply(context, reciprocalParamArr);
|
|
|
|
|
}
|
|
|
|
|
@@ -632,12 +631,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public final NumberFunction functionArctan = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
NumberImplementation implementation = context.getInheritedNumberImplementation();
|
|
|
|
|
if (params[0].signum() == -1) {
|
|
|
|
|
NumberInterface[] negatedParams = {params[0].negate()};
|
|
|
|
|
@@ -674,12 +673,12 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
*/
|
|
|
|
|
public final NumberFunction functionArccot = new NumberFunction() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean matchesParams(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public boolean matchesParams(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return params.length == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public NumberInterface applyInternal(MutableReductionContext context, NumberInterface[] params) {
|
|
|
|
|
public NumberInterface applyInternal(MutableEvaluationContext context, NumberInterface[] params) {
|
|
|
|
|
return piFor(params[0].getClass()).divide(context.getInheritedNumberImplementation().instanceForString("2"))
|
|
|
|
|
.subtract(functionArctan.apply(context, params));
|
|
|
|
|
}
|
|
|
|
|
@@ -719,7 +718,7 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
* @param x where the series is evaluated.
|
|
|
|
|
* @return the value of the series
|
|
|
|
|
*/
|
|
|
|
|
private static NumberInterface sinTaylor(MutableReductionContext context, NumberInterface x) {
|
|
|
|
|
private static NumberInterface sinTaylor(MutableEvaluationContext context, NumberInterface x) {
|
|
|
|
|
NumberInterface power = x, multiplier = x.multiply(x).negate(), currentTerm = x, sum = x;
|
|
|
|
|
NumberInterface maxError = x.getMaxError();
|
|
|
|
|
int n = 1;
|
|
|
|
|
@@ -738,7 +737,7 @@ public class StandardPlugin extends Plugin {
|
|
|
|
|
* @param phi an angle (in radians).
|
|
|
|
|
* @return theta in [0, 2pi) that differs from phi by a multiple of 2pi.
|
|
|
|
|
*/
|
|
|
|
|
private static NumberInterface getSmallAngle(MutableReductionContext context, NumberInterface phi, NumberInterface pi) {
|
|
|
|
|
private static NumberInterface getSmallAngle(MutableEvaluationContext context, NumberInterface phi, NumberInterface pi) {
|
|
|
|
|
NumberInterface twoPi = pi.multiply(context.getInheritedNumberImplementation().instanceForString("2"));
|
|
|
|
|
NumberInterface theta = FUNCTION_ABS.apply(context, phi).subtract(twoPi
|
|
|
|
|
.multiply(FUNCTION_ABS.apply(context, phi).divide(twoPi).floor())); //Now theta is in [0, 2pi).
|
|
|
|
|
|