Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing documentation for syntax (parser) #43

Open
creativecreatorormaybenot opened this issue Jan 7, 2021 · 4 comments
Open

Missing documentation for syntax (parser) #43

creativecreatorormaybenot opened this issue Jan 7, 2021 · 4 comments
Labels
documentation Indicates a need for improvements or additions to documentation

Comments

@creativecreatorormaybenot
Copy link
Contributor

creativecreatorormaybenot commented Jan 7, 2021

I think it is awesome that functions like Log are supported 🙌

Problem

However, I cannot seem to figure out how to use something like log_e(x).

I would expect this to use e as the base and be equivalent to ln(x), however, it throws during parsing.

FormatException: The input String is not a correct expression
@creativecreatorormaybenot
Copy link
Contributor Author

And btw, @fkleon what is this supposed to represent?

inputStrings.add('log(10,100)');

Afaic, log only takes 1 argument. I tried log(e,x) just out of curiosity, however, it did not work.

@fkleon fkleon added the documentation Indicates a need for improvements or additions to documentation label Jan 8, 2021
@fkleon
Copy link
Owner

fkleon commented Jan 8, 2021

Hi @creativecreatorormaybenot - thanks for your questions and reports, always great to get feedback from users!

I agree that the parser syntax documentation is mostly missing, I'll add some specific documentation to the appropriate expression classes. As you've discovered the unit tests are the source of truth at the moment.
Historically the parser was just an afterthought mainly for testing purposes, but people seem to use it a lot! There's also a new parser implementation in the pipeline that will hopefully fix some of the oddities and issues.

Regarding your specific question, math-expressions implements two logarithm functions:

  • Log is the generic logarithm function with arbitrary base and argument. The parser does not support constants such as π (Pi) or e (Euler's Number), so you can only approximate the natural algorithm with this, e.g. log(2.71828, x) (read: logarithm base 2.71828 of x)
  • Ln is the natural logarithm function (log base e). This can be expressed as ln(x) (read: logarithm base e of x)

Hope that answers your question, I'll leave the ticket open though for the documentation improvements.

@fkleon
Copy link
Owner

fkleon commented Jan 8, 2021

This is not explicitly documented yet, but starting from version 2.0.0 the parser should be compatible with thetoString() representation of any expression. So in addition to the tests, the toString() implementation of an expression defines the expected syntax.

@creativecreatorormaybenot
Copy link
Contributor Author

@fkleon These news on the parser are absolutely amazing! Thank you ✨

We actually also have some unit tests for expression equality (using your package for evaluation) and I wanted to add a test for ln(x) = log_e(x).

I also realized how log worked after a while (that e, was unsupported) and came up with ln(x) / ln(10) = log(10, x) 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Indicates a need for improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants