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

Develop a parser for arbitrary expressions in the calc engine #526

Open
mcooley opened this issue May 31, 2019 · 13 comments
Open

Develop a parser for arbitrary expressions in the calc engine #526

mcooley opened this issue May 31, 2019 · 13 comments
Labels
Enhancement help wanted Issues identified as good community contribution opportunities needs spec Pri: 1

Comments

@mcooley
Copy link
Member

mcooley commented May 31, 2019

Problem Statement
Currently, Calculator executes all operations in immediate mode--press an operator, get a new answer. For multiple scenarios, it would be useful for the user to enter an expression like "(5 + 2) * 3" and have Calculator parse and compute the result.

Evidence or User Insights
Several proposed features could leverage this work:

Proposal
Add code and tests to the calc engine to parse mathematical expressions as strings.

Goals

  • A developer can use the CalcManager library to convert an expression into a numerical result
  • Expressions support order of operations, e.g. "(5 + 2) * 3" = 21
  • Expressions support evaluation of functions, e.g. "sqrt(4)"
    • Functions are implemented for as many existing calculator operators as possible
    • Each function has a thoughtful name informed by similar systems
  • Expressions are evaluated using the arbitrary-precision engine
  • When invalid expressions are passed to the engine, error information is returned which could be used to construct a helpful error message
  • Parsing and evaluation is deterministic, and ideally not locale-dependent
  • The parser can find expressions embedded in natural language sentences with loose syntax (e.g. "what is the square root of sin(3 - 2)" evaluates to "what is the square root of [expression tree]"), for future use in voice input scenarios

Non-Goals

  • Integrate expression parsing with the Calculator UI (tracked by other issues)
  • Natural language intent recognition, e.g. "what is the square root of 4" evaluating to "sqrt(4)"

Requested Assignment
I'm happy to help with this, but would be great for someone else to implement.

@ghost
Copy link

ghost commented Jun 1, 2019

This pitch looks like it has everything it needs for review. In the meantime, we'll keep this idea open for discussion so the community has the chance to provide feedback. Check out our New Feedback Process for more info on the user-centered process we follow for new feature development.

@ghost
Copy link

ghost commented Jun 5, 2019

This pitch looks like it has everything it needs for review. In the meantime, we'll keep this idea open for discussion so the community has the chance to provide feedback. Check out our New Feedback Process for more info on the user-centered process we follow for new feature development.

@MicrosoftIssueBot
Copy link
Collaborator

This is your friendly Microsoft Issue Bot. I've seen this issue come in and have gone to tell a human about it.

@rudyhuyn
Copy link
Contributor

rudyhuyn commented Jun 17, 2019

For information, I already built an expression parser to improve the PasteManager and managing a lot of operations not currently supported (ln, log, sqrt, etc...) and already covering all your needs (history edition, ink, edition in scientific):

#344 (and proto-PR here: https://github.com/rudyhuyn/calculator/tree/AddExpressionParser)

Don't hesitate to take a look

@leduyquang753
Copy link

If this will be implemented, I suggest making the mathematical operators customizable, as they are regional, cultural and personal preferences.
For example, I would write "16 + 28 × 5 – 27 ÷ 3" as "16 + 78.5 – 27:3".

@ghost
Copy link

ghost commented Jul 29, 2019

We reviewed the pitch and would love to explore this idea further! The pitch is a great start, but there are still some open questions. I am moving this issue into planning to iron out some of those details and I created calculator-specs/expressionParser to track progress. A human will follow up with some feedback on your pitch shortly. Keep in mind that not all ideas that make it into the planning phase are guaranteed to make it to release. For more information on next steps, check out our spec workflow.

@grochocki
Copy link
Contributor

Overall, this seems like a great improvement! A couple comments/questions:

  • NLP is listed as a goal, and while we should should keep this in mind, we don't feel it is strictly necessary here.
  • Unsure if we can pull off being truly locale-independent, but definitely worth a try
  • Can/should error-handling be split off as a separate issue?

I suggest making the mathematical operators customizable, as they are regional, cultural and personal preferences.

@leduyquang753 I am not sure I understand your example; can you clarify? I agree we should support any standard input methods, but I don't think it makes sense to support custom operator input assignment.

@grochocki grochocki added the help wanted Issues identified as good community contribution opportunities label Jul 29, 2019
@rudyhuyn
Copy link
Contributor

rudyhuyn commented Jul 29, 2019

I agree, custom operators will require a lot more work (including a dialog to modify them) and can create many issues with shortcuts or when new features will be added to the Calculator.

@leduyquang753
Based on your example, when you write "personal preferences", I suppose you don't mean Users can select a random character but "the user must be able to use the symbols of his/her/their choice from among the official symbols".

If it's the case, I agree with that, all official symbols should be supported, it's the case of the proto I wrote some months ago. Of course, except when they create a conflict.

The goal should be to allow a user to copy & paste a formula from a website, whatever the language of the website and make it work without any modification. For example:

Multiplication:

  • ×
  • *
  • (note: this is not the period symbol, already used as a decimal separator in some languages)
  • probably not x (the letter X, this one is questionable because can be also used in formula and hexadecimal notation)

Division:

  • / (slash)
  • (solidus)
  • ÷ (obelus, used widely in Europe and probably other countries)
  • : (used in some Eastern Europe countries) - we will need to check if this symbol isn't used for something else in some regions

@leduyquang753
Copy link

leduyquang753 commented Jul 29, 2019

⋅ (note: this is not the period symbol, already used as a decimal separator in some languages)

Actually Vietnam uses the period to indicate multiplication (officially used in education, textbook images can be included if needed). In order not to create conflicts (if the decimal separator is already period), a check can be easily implemented.

@HowardWolosky
Copy link
Member

It may be worthwhile to review what @rudyhuyn started in #344 when working through the spec'ing for this issue.

@crutkas
Copy link
Member

crutkas commented Dec 8, 2020

Like to state, PowerToys would very much like this :)

@crutkas
Copy link
Member

crutkas commented Dec 8, 2020

is there a list of expressions this will support? Example: bin2dec or arcsin

@gounaman
Copy link

so like is anything happening with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement help wanted Issues identified as good community contribution opportunities needs spec Pri: 1
Projects
None yet
Development

No branches or pull requests

9 participants