jiggzson / nerdamer Goto Github PK
View Code? Open in Web Editor NEWa symbolic math expression evaluator for javascript
Home Page: http://www.nerdamer.com
License: MIT License
a symbolic math expression evaluator for javascript
Home Page: http://www.nerdamer.com
License: MIT License
The npm packages are in need of updating. The last npm version is 0.5.7
(a^2)/a = a, but the *b screws it up
btw, thanks for the last fix.
nerdamer.solveEquations(['x+y=1', '2_x=6', '4_z+y=6']) throws "System must contain all linear equations!"
When the expression is requested as latex, often brackets aren't added when there should be. For example when the expression has a non-unit multiplier or power. This issue is strictly related to the latex generator as expression values are correct when the text method is called.
There's another one I stumbled apon ;-)
a(b+c)-a(b+c) = 0 as it should.
const wtf = nerdamer('4 (s^2 + t^2) s').buildFunction(['s', 't']).toString()
// wtf ==
function anonymous(s,t
/*``*/) {
return 4*(Math.pow(s,2)+Math.pow(t,2)*s); // s should be right of the bracket
}
Hi, I don't know if that't my bad or nerdamer mistake, but sin(x) looks like sin(abs(x))...
The library has helped me a lot in building a graphing system, I am stuck at one place , Can you people design a way where if I can detect any equation of the form (x-a)^2 + (x-b)^2 = r^2 (i.e. is a generalized circle equation) and can let me know that its a circle (i.e. I want to know if any user types in this type of circle equation i want to know its a circle )
Hello, the result of the following tests has changed. Could I ask you to confirm that the new results are correct?
given: 'integrate(x*asin(x), x)',
expected: '(-1/4)*asin(x)+(1/2)*asin(x)*x^2+(1/4)*sqrt(-x^2+1)*x'
actual: '(-1/4)*asin(x)+(1/2)*asin(x)*x^2+(1/4)*cos(asin(x))*sin(asin(x))'
given: 'integrate(q/((2-3*x^2)^(1/2)), x)',
expected: 'asin(sqrt(2)^(-1)*sqrt(3)*x)*q*sqrt(3)^(-1)'
actual: 'asin(3*sqrt(6)^(-1)*x)*q*sqrt(3)^(-1)'
given: 'integrate(x*(x+a)^3, x)',
expected: '((1/4)*x^4+(3/2)*a^2*x^2+a*x^3+a^3*x)*x+(-1/2)*a^2*x^3+(-1/2)*a^3*x^2+(-1/20)*x^5+(-1/4)*a*x^4'
actual: '(1/2)*a^3*x^2+(1/5)*x^5+(3/4)*a*x^4+a^2*x^3'
given: 'integrate(8*x^3/(6*x^2+3*a^2), x)',
expected: '8*((-1/24)*a^2*log(3*a^2+x^2)+(1/12)*x^2)'
actual: '8*((-1/24)*a^2*log(2*x^2+a^2)+(1/12)*x^2)'
given: 'integrate(log(a*x+b),x)',
expected: '((a*x+b)*log(a*x+b)-a*x-b)*a^(-1)'
actual: '-x+a^(-1)*b*log(a*x+b)+log(a*x+b)*x'
given: 'integrate(t*log(x)^3,x)',
expected: '(-3*log(x)^2+6*log(x)+log(x)^3-6)*t*x'
actual: '(-3*log(x)^2*x-6*x+6*log(x)*x+log(x)^3*x)*t'
given: 'integrate(5*x*e^(-8*a*x^2),x)',
expected: '(-5/16)*a^(-1)*e^(-8*a*x^2)*log(e)^(-1)'
actual: '(-5/16)*a^(-1)*e^(-8*a*x^2)'
given: 'integrate((x+7)/(x+1)^3,x)',
expected: '(-1/2)*(1+x)^(-1)+(-1/2)*(1+x)^(-2)*(7+x)'
actual: '(-1/2)*(1+x)^(-1)+(-7/2)*(1+x)^(-2)+(-1/2)*(1+x)^(-2)*x'
Is it possible to make the LaTeX generator return the decimal value instead of the fraction?
3/10 = 0.3 instead of 3/10
I know that we will face a floating point issue (because the result will be 0.30000000000000004). Perhaps add a BigDecimal library to handle it?
When setting a function, calling it afterwards throws an error.
Hello, i am using nerdamer in my serverside application.
When i try to use diff function i get error
_nerdamer2.default.diff is not a function
nerdamer.reserved() shows
csc, sec, cot, erf, fact, mod, GCD, PI, E, cos, sin, tan, acos, asin, atan, exp, min, max, floor, ceiling, round, vector, matrix, parens, sqrt, log, abs, invert, transpose, dot
version 0.5.7
import:
import nerdamer from 'nerdamer'
usage:
let diff = nerdamer.diff(funcY)
How can i use diff function in my case?
How do you feel about adding **
as a synonym for ^
, to match the ES syntax?
hmm, this might be related to #40?
For example
var x = nerdamer('x^2+i').buildFunction();
console.log(x.toString())
//function anonymous(i,x
///**/) {
//return i+Math.pow(x,2);
//}
This should throw an error or account for i
I've tried on demo and in the javascript console:
var e = nerdamer('ceiling(2.4)', null, 'numer');
console.log(e.text());
//returns ceiling(2.4), expected 3
It's not working. I didn't detect the issue on the code. Maybe you guys can take look?
When using the latex method, the parentheses are not correctly applied, if two or more terms are multiplied in brackets.
I stumbled upon this SO post, mentioning that there should be an integration branch.
Have you added symbolic integration, or is it only for polynomials? If not, I could try starting a basic implementation in the calculus add-on.
Does this library support bit shifting and bitwise operators?
As this is something I can really use :)
Thanks
Is it?
throws Error:
undefined:3
return 0.3333333333333333*Math.pow(,0.3333333333333333);
^
SyntaxError: Unexpected token ,
at new Function (<anonymous>)
> nerdamer('x y').evaluate({x: 2}).text('decimals')
'xy'
> nerdamer('x^2 y').evaluate({x: 2}).text('decimals')
'4*y'
I just noticed that multiple -
(and brackets) don't seem to get along in some cases. Here are two failing test cases.
{
given: '-(1)--(1-1--1)',
expected: '0' // current result: -2
},
{
given: '-(-(1))-(--1)',
expected: '0' // current result: 2
}
I see that the Symbol prototype does not have an evaluate method, but the master nerdamer function has an option to evaluate by passing an object. Is there currently a way to evaluate a Symbol object in a similar way, by passing an object with variable-value pairs?
As an explicit example, if I get a Symbol object returned from the integrate function, is there currently a way to evaluate that Symbol at a numerical value?
The sort order of polynomials is backwards in Safari.
In Node and Chrome: nerdamer("x^2+2x+1").toTeX() = x^{2}+2 \cdot x+1
In Safari it's 1+2 \cdot x+x^{2}
On the input "(a-b)^2 - (b-a)^2", it doesn't simplify to 0. This could probably be fixed by always formatting expressions of type (±a ± b ± c ± ...)^2n so that 'a' has a positive coefficient (i.e 'a' doesn't have a minus sign in front).
Evaluating (x+1)/(x^2 -i) gives x/(x^2 - i) + (1)/(x^2 +i) at http://nerdamer.com/demo
It doesn't like imaginary numbers.
var x = nerdamer('solve(x^2+2*x+7,x)');
console.log(x.toString())
//[(209774887/85640239)*i-1,(-159018721/64919121)*i-1]
The numeric solution is returned. Nerdamer is perfectly capable of returning the algebraic solution for univariate polynomials and should make this its first option.
console.log(nerdamer.solveEquations("x+1=2", "x").toString())
console.log(nerdamer("x=1").text("fractions"))
console.log(nerdamer.solveEquations("x+1=2", "x").toString())
this logs an empty string for the third line
Compared with the following solution:
nerdamer("factor(x^2+2x+1)") = "(x+1)^2"
I would expect the following result:
nerdamer("factor(x^2+x+1/4)") = "(x+1/2)^2"
Entering formulas like
sqrt(2x)
or
sqrt(2*x)
etc. give weird results like
√((3880899 x)/2744210)
Hello!
If I enter nerdamer('(x+4)(x+3)')
or something along those lines, the expression does not get simplified. Could we implement a fix for this?
Is there any way to parse a string to LaTeX using nerdamer prior to nerdamer evaluting the string? For example -- taking 'x*x' and returning 'x \cdot x' instead of 'x^2' ?
nerdamer("alpha+beta").toTeX() = "\alpha+\beta" would be convenient.
var e = nerdamer('e^(2*i*PI) +e^(i*PI)');
console.log(e.text());
e^(3.141592653589793_i)+e^(6.283185307179586_i)
Euler's identity could be useful in solving complex exponential. (E.g (a+bi)^n )
Extend buildFunction for functions outside the core.
I believe that would be better if nerdamer could detect and register custom functions. Like this:
if(/([a-z])\([a-z](.*)\)=/i.test(input)) {
var fn = input.match(/[a-z]+\(/i)[0].replace('(', '');
var exp = input.split('=')[1];
var arguments = input.replace(fn, '').replace(exp, '').replace('=', '').replace('(', '').replace(')', '').split(',');
nerdamer.setFunction(fn, arguments, exp);
}
It worked fine with the functions below:
hyp(a, b) = sqrt(a^2 + b^2)
f(x) = x^2
Sorry for not sending a pull request, I'm just an amateur.
I am build a graphing system using your Library thanks a lot you made such a library helped me a lot but I am finding an issue in getting the value of y when that Equation is of the form below:
var equation = (x-1)^2 + (y-1)^2 - (4)
var val = nerdamer(equation, { x: 4});
var parse = val + "=0"; Where parse is "(-1+y)^2+5=0"
var sol = nerdamer.solveEquations(parse, 'y');
Error: From Algebra , Invalid array length as in the rpSolution function the degree parameter is coming up as NaN (not a number).
Please can you help me in this because I am looping though the value to get the value of 'y' to generate a circle.
The library is supporting the equation x^2 + y^2 =4, But if i am adding the center value then its not working example (x-1)^2 + (y-1)^2 - (4)
the nerdamer output for this is correct, but not helpful
For example, derivative of x^2pi should be 2pix, but this lib will give a result x^2.
It seems that in diff() pi is not supported.
var x = nerdamer('solve(x^2+a,x)');
console.log(x.toString())
//[(1/2)*sqrt((-1)),(-1/2)*sqrt((-1))]
result shows 1 instead of a
Example: (a+x)--(x+a) will throw an error.
(x+3)^2 outputs NaN.
(x-(-3))^2 works.
same with 1/(x+3)
nerdamer('pi * x').evaluate({x: 2}).text('decimals') // ~= 6.28
nerdamer('pi * x').buildFunction(['x'])(0) // ReferenceError: pi is not defined
The function body is just pi * x
, and pi apparently isn't bound. I'd expect Math.PI to be used.
Manually doing nerdamer.setConstant('pi', Math.PI) fixes it, but that shouldn't be necessary.
As an aside, what's the deal with *
? Sometimes it works, othertimes you get weird errors.
When using the latex or toTeX method, the parentheses are not correctly applied, if one or more terms in brackets are multiplied with -1.
In the new version, the order of polynomials is changed in the LaTeX output. I would expect the following result:
nerdamer("x^2+x+1").latex() = "x^2+x+1"
Can the LaTeX output optionally again be switched to the old style?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.