jiggzson / nerdamer

a symbolic math expression evaluator for javascript
http://www.nerdamer.com
MIT License
514 stars 82 forks source link

nerdamer.convertToLaTeX(e.text('decimals')) #579

Closed SomebodyLikeEveryBody closed 3 years ago

SomebodyLikeEveryBody commented 3 years ago

Hello,

I'm currently working on a front-end calculator and your library is absolutely awesome for that, thanks a lot ! (https://github.com/SomebodyLikeEveryBody/Solve4Me, https://somebodylikeeverybody.github.io/Solve4Me/).

I'm displaying the LaTeX results (obtained by nerdamer.convertToLaTeX() function) in the web page (using jqMath.js.)

However, I want to have results that are not as fractions (like 2/3 = 0.66666 or pi = 3.141592653589793160 instead of "245850922/78256779", so I use the text('decimal') function, but obviously the nerdamer.convertToLatex() function undo that and put back the fractions representation... To be clear, here is what happens:

let e1 = nerdamer('pi').toString(); // returns "pi"
let e2 = nerdamer(e1).evaluate().toString(); // returns "245850922/78256779", so approximation of pi as fraction representation
let e3 = nerdamer(e2).text('decimals');  // returns "3.141592653589793160", everything's working fine

// and then if I want to display e3 as LaTeX:
let LaTeXStr = nerdamer.convertToLaTeX(e3);  // returns "\\frac{245850922}{78256779}", that is to say the fractions representation again !

Am I missing something ? Or is there a bug in the nerdamer.convertToLaTeX() function ? I'm reading the source code currently but I don't find the thing for the moment...

Thank you !

jiggzson commented 3 years ago

@SomebodyLikeEveryBody, I think there should be an option to explicitly request it to return the output in decimal form. Let me dig in a little and figure this out.

jiggzson commented 3 years ago

@SomebodyLikeEveryBody, fixed on dev. You can now call it as nerdamer.convertToLaTeX(e, {decimals: true}). Also your project looks interesting but it wasn't readily apparent to me how it works. Can you give me a brief overview of it.

SomebodyLikeEveryBody commented 3 years ago

You rocks, thank you very much.

Well, Solve4Me is/was suppose(d) to be a sort of calculator (like SageMath is by using jupyter), but to avoid the server problematics (security, performances management, etc), I wanted something very simple, running only on client side with a server whose only job is to send the html/css/javascript code and all the calculations and entry management is done in the browser, or with no server with the pages running in local with a file:// protocol (I often work with computers with absolutely no dev environement and no possibility to install anything)

For now, there are 3 screens,

and the statements will be notified on the output screen, it simplifies the readability to me

And finally, if you press ctrl + enter (or press the "solve" button on the bottom of the page) it validates the input and show the result in the output screen.

For now it is working for very simple problems and there are many many bugs but I am king of proud of the interface.

In the future, the best to me would be to have something like SageMath, but with a better Latex output that it actually have (I like when the output resume the question in latex, like if you type solve(3x + 4 = 42, x) I like when the output is "Solutions of x ∈ |R ∋ 3x + 4 = 42: [ 38/3, ]" or something like that), and ideally all in a full front-end management.

I really learnt a lot about how to process algebra calculations by code thanks to your project so thank you again !

jiggzson commented 3 years ago

@SomebodyLikeEveryBody, glad to have been able to play a small part in the development of your app. It definitely sounds like it has some potential and I hope you realize it fully.

I wanted something very simple, running only on client side with a server whose only job is to send the html/css/javascript code and all the calculations and entry management is done in the browser, or with no server with the pages running in local with a file:// protocol (I often work with computers with absolutely no dev environement and no possibility to install anything)

Ironically that's the whole reason started this project. It was supposed to be a light wrapper around JS numbers to be able to do some symbolic computation in addition to standard numerical computation in the browser. Never thought I'd still be going with it.

In the future, the best to me would be to have something like SageMath, but with a better Latex output that it actually have (I like when the output resume the question in latex, like if you type solve(3x + 4 = 42, x) I like when the output is "Solutions of x ∈ |R ∋ 3x + 4 = 42: [ 38/3, ]" or something like that), and ideally all in a full front-end management.

Sounds like our goals are again aligned. Although, I no longer have any need for this project, I still enjoy helping others in my spare time. Depending on the level of attention this project receives, I may decide to take a swing at a full rewrite but this time targeting a CAS and not just a lightweight wrapper. This would have a ton of challenges but it might be fun.