Calccedo-v2 is the next revolution of calccedo, it support many features like addSemantic, like add addVariable, like addConstant, like injectFunction
I start calccedo at 2018, calccedo help java developers to build complex calculation programs, you can build appliacation Like ( Matlab | prolog | Rasperri) using calccedo
,build Calculator using Java, Calccedo is a calculation engine framework library based on Java language to help developers for building applications that need complex mathematical equations, Calccedo is not just framework library, it is work as interperter and act as AI Engine
add constants like PI = 3.14 , Li(Lithium)=3, Na(soʊdiəm) =11
inject functions like f(x)=x^2+2x+1
support (sinh , cosh , tanh)
support (asin , acos , atan)
support (pi , PI) as a 3.14
support (In(1)=0)
support Radians and Degrees for Angels calculation
you can build complicated mathematical application using Calccedo-V2
Claccedo make you happy
Development
Calculate simple operation
import com.calccedo.handlers.CalccedoHandler;
/**
*
* @author Ibrahim
*/
public class TestCalccedo extends CalccedoHandler{
public TestCalccedo(){
super.enableDeepTrace(true);
}
public static void main(String [] args){
TestCalccedo calccedoHandler = new TestCalccedo();
String formula = "1+5+sin(30)+20+70+80+90";
String result = calccedoHandler.calculate(formula);
System.out.println(result);
}
}
Add Semantic to calccedo, hint semantic replace addCustomOperand in calccedo v1
sometimes you need to add custom operand as a constant like Sin(30)=0.5 and because calccedo works only with Radians Degree
if you run Math.sin(30) in Java JDK standard it it will return 1.444444449 but in Algebra Math it should return 0.5
calccedo offers four overloaded methods to add custom operand as a constant to ignore standard result that Java JRE produce
important!
Custom operand you will add can accept any length of charchaters, like celsius(10)= 10.131550 rather than v1 it should take three chars
Woooooooooooooooooooooooooooooooooooooooow Calcedo V2 solve this issue
addSemantic(String semanticName,int quoteNumber,double value);
addSemantic(String semanticName,double quoteNumber,double value);
addSemantic(String semanticName,int quoteNumber,Object object);
addSemantic(String semanticName,double quoteNumber,Object object);
important!
in calccedo v1 it is not allowed: to add subset of custom operand that added before
if you add sin(30)=0.5 , it is not allowed to add asin(30)=50
because asin is a subset of sin word which added before
calccedo-V2 solve this issues now you can add sin(30)=0.5 and asin(30)=1.1254566
Adding Sin(30) to calccedo as a semantic Sin(30)=0.5
import com.calccedo.handlers.CalccedoHandler;
/**
*
* @author Ibrahim
*/
public class TestCalccedo extends CalccedoHandler{
public TestCalccedo(){
super.enableDeepTrace(false);
super.addSemantic("Sin",30,0.5);
super.addSemantic("Sin",30.0,0.5);
}
public static void main(String [] args){
TestCalccedo calccedoHandler = new TestCalccedo();
String formula = "Sin(30)";
String result = calccedoHandler.calculate(formula);
System.out.println(result);
}
}
Adding Tan(90) to calccedo as an Illegal custom operand Tan(90)=Error
import com.calccedo.handlers.CalccedoHandler;
import com.calccedo.handlers.Infinity;
/**
*
* @author Ibrahim
*/
public class TestCalccedo extends CalccedoHandler{
public TestCalccedo(){
super.enableDeepTrace(false);
super.addSemantic("Tan",90,Infinity.class);
super.addSemantic("Tan",90.0,Infinity.class);
}
public static void main(String [] args){
TestCalccedo calccedoHandler = new TestCalccedo();
String formula = "Tan(90)";
String result = calccedoHandler.calculate(formula);
System.out.println(result);
}
}
Calculate complicated operation
import com.calccedo.handlers.CalccedoHandler;
/**
*
* @author Ibrahim
*/
public class TestCalccedo extends CalccedoHandler{
public TestCalccedo(){
super.enableDeepTrace(true);
}
public static void main(String [] args){
TestCalccedo calccedoHandler = new TestCalccedo();
String formula = "(5(1+2)+3sin(30cos(30+30))+(5*7+10%2)+(10^21+5E10)/5)";
String result = calccedoHandler.calculate(formula);
System.out.println(result);
}
}
Adding Variable
import com.calccedo.handlers.CalccedoHandler;
/**
*
* @author Ibrahim
*/
public class TestCalccedo extends CalccedoHandler{
public TestCalccedo(){
super.enableDeepTrace(true);
super.addVariable("x", 3);
super.addVariable("y", 3);
}
public static void main(String [] args){
TestCalccedo calccedoHandler = new TestCalccedo();
String formula = "x+y";
String result = calccedoHandler.calculate(formula);
System.out.println(result);
}
}
Adding Constant
import com.calccedo.handlers.CalccedoHandler;
/**
*
* @author Ibrahim
*/
public class TestCalccedo extends CalccedoHandler{
public TestCalccedo(){
super.enableDeepTrace(true);
super.addConstant("sat", 1);
super.addConstant("sun", 2);
super.addConstant("mon", 3);
super.addConstant("tue", 4);
super.addConstant("wed", 5);
super.addConstant("thu", 6);
super.addConstant("fri", 7);
}
public static void main(String [] args){
TestCalccedo calccedoHandler = new TestCalccedo();
String formula = "sat + sun + mon + tue + wed + thu + fri";
String result = calccedoHandler.calculate(formula);
System.out.println(result);
}
}
Inject Function
calccedo so easy to calculate function formula like f(x) = x^2+2x+1 calccedo make it easy
first step: we will create class that implement method that do function formula
/**
*
* @author Ibrahim
*/
public class Equations {
/* implement fn(x) = x^2+2x+1
important! each time you want to implement function, you should follow this standard steps in calccedo
which mean you should declare method as it is methodName(Number... numbers) for every function you want to inject
*/
public double fn(Number... numbers){
double result=0;
result = numbers[0]^2 + 2*numbers[0] + 1;
return result;
}
}
second step: create class that inject function from previous class
import com.calccedo.handlers.CalccedoHandler;
/**
*
* @author Ibrahim
*/
public class TestCalccedo extends CalccedoHandler{
public TestCalccedo(){
super.enableDeepTrace(true);
/*
inject function using method name [fn] that declared in Equation class
*/
super.injectFunction(Equations.class,"fn");
/*
you can also rename injectedFunction to any name you want like this:
*/
super.injectFunction("fun",Equations.class,"fn");
}
public static void main(String [] args){
TestCalccedo calccedoHandler = new TestCalccedo();
String formula = "fn(50)";
String result = calccedoHandler.calculate(formula);
System.out.println(result);
// in this case you will notice that calccedo handle fun(50) as fn(50) because they are reference to same function
formula = "fun(50)";
String result = calccedoHandler.calculate(formula);
System.out.println(result);
}
}