Open Happypig375 opened 7 years ago
(Inserted into #202)
Ideally it would also do the rationalization, and here is a bunch of tests (not sending as PR as the syntax has not been confirmed):
Input | My answer |
---|---|
6/sqrt(3) | 2sqrt(3) |
1/(sqrt(2)-1) | sqrt(2)+1 |
3/(sqrt(5)+sqrt(8)) | 2sqrt(2)-sqrt(5) |
sqrt(2)/(sqrt(6)-sqrt(2)) | (sqrt(3)+1)/2 |
(sqrt(7)-3)/(sqrt(7)+3) | 3sqrt(7)-8 |
(5-2sqrt(2))/(2sqrt(2)-3) | 2sqrt(2)+7/2 |
(3sqrt(3)+sqrt(7))/(2sqrt(3)-sqrt(7)) | 5+sqrt(21) |
(3+sqrt(5)/((sqrt(5)+1)(sqrt(5)-2)) | (7+3sqrt(5))/2 |
1/(3sqrt(2)+sqrt(5))-1/(3sqrt(2)-sqrt(5)) | -2sqrt(5)/13 |
2sqrt(5)/(4-sqrt(5))+3/(sqrt(5)+4) | 2-5/11sqrt(5) |
6/(3+sqrt(3))*6/(sqrt(3)-1) | 6sqrt(3) |
4/(sqrt(x^2+2x+4)+sqrt(x^2-2x+4)) | (sqrt(x^2+2x+4)-sqrt(x^2-2x+4))/x |
(x^2-1)/(sqrt(x^2+x+1)-x) | x sqrt(x^2+x+1)-sqrt(x^2+x+1)+x^2-x |
@Happypig375 . I like your suggestions and some of the simplifications in the table above should probably be the default behavior of the library. Other than the initial examples, did you have any other simplifications in mind?
http://nerdamer.com/functions/Expression.sub.html
x = nerdamer('cos(x)*tan(x)').sub('tan(x)', 'sin(x)/cos(x)').evaluate()
This is also a simplification.
6^(2π)-36^π => -36^pi+6^(2*pi) Can simplify to 0.
floor(floor(x)) can=> floor(x) floor(ceil(x)) can=> ceil(x) ceil(floor(x)) can=> floor(x) trunc(round(ceil(floor(x)))) can=> floor(x) etc.
asin(sin(3)) can=> pi-3
sec(x)cos(x) can=> 1
This one is more important. sqrt(2)*sqrt(6) should=> 4*sqrt(3) (reference to #312)
http://www.dummies.com/education/math/calculus/using-identities-to-express-a-trigonometry-function-as-a-pair-of-functions/ The trig conversion table should be somewhat helpful.
@Happypig375 the list you provided contains only basic trig identities. A much more extensive conversion method which includes double angle identities, etc. is already contained in the Calculus.js add-on. I think I'll move that to the core and utilize that one. If you run into more simplifications please do share.
Thought on this: Just like Wolfram Alpha, provide different simplifications with different criteria? Like simplify(x/x) => [0, x <> 0] (Not x!=0 because that is factorial(x)=0)
Note: Currently nerdamer has <, >, <=, >=, =, == but no <>.
Sounds good. Keep in mind that equality operators were an idea I was toying with so that's why they're not documented. I guess we can still tweak them as we go.
Ah, and that requires #251 to be implemented. Forgot to say.
((-1/3)*cos(x)*sin(x)^2+(-2/3)*cos(x))-(-cos(x)+(1/3)cos(x)^3) => (-1/3)*cos(x)*sin(x)^2+(-1/3)*cos(x)^3+(1/3)*cos(x) should=> 0
log(1+x)-log(1-x)-log((1+x)/(1-x)) should=> 0
Thought: Maybe defining rules (e.g. replace("log(x)-log(y)", "log(x/y)")) for the simplifier in the parser would help organise and be easier to add new rules.
Nerdamer does not use a rule based parser. Remember? Are you talking about when we switch to version 8? Are you familiar when any of the existing JavaScript rule based parsers out there?
Are you talking about when we switch to version 8?
0.8, actually. ( ͡° ͜ʖ ͡°)
Are you familiar when any of the existing JavaScript rule based parsers out there?
Nope, the only JavaScript library that I am familiar with is literally nerdamer. My natural programming language is C#.
Another look at Algebrite:
I don't think nerdamer can currently do this (factor does the middle one only). This function would be really helpful!