How can I create a custom keyboard for math functions in WPF?

  • Thread starter Thread starter DivergentSpectrum
  • Start date Start date
  • Tags Tags
    Functions
Click For Summary

Discussion Overview

The discussion centers around creating a custom keyboard for inputting mathematical functions in a WPF application. Participants explore methods for transforming user input into executable code for numerical procedures, such as integration, and consider the complexities involved in parsing mathematical expressions.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant expresses a desire to allow users to input a mathematical function as a string, which the program would then process for numerical procedures.
  • Another participant notes the complexity of parsing the input string, highlighting the need to identify terms, operators, and function keywords.
  • Some participants suggest that using a keypad similar to a calculator might simplify the input process, although they acknowledge that parsing would still be necessary.
  • There is a mention of compiler theory as a potential approach for parsing input, with one participant suggesting that an interpreter could be built using lexical analysis and parsing tools.
  • Another participant outlines three approaches to the problem: using scripting languages with an eval() function, manually parsing the input, or employing a hybrid approach that combines languages like Python with C.
  • One participant clarifies that a built-in keyboard with buttons for each function could be a more user-friendly solution compared to a standard keypad.

Areas of Agreement / Disagreement

Participants express varying opinions on the best approach to implement the custom keyboard and parse mathematical functions. There is no consensus on a single method, and multiple competing views remain regarding the complexity and feasibility of different solutions.

Contextual Notes

Participants mention the need for parsing techniques and the potential inefficiency of re-evaluating user input each time a function is called. The discussion also touches on the limitations of standard keypads in capturing complex mathematical expressions.

DivergentSpectrum
Messages
149
Reaction score
15
i would like to have the user enter a math function. ie cos(x)-e^x + x^2
it will be typed into a text box and then the program performs a numerical procedure on the function (ie integration)

In other words, how do i transform the input string into a method?
 
Technology news on Phys.org
bluntwcrackrap said:
i would like to have the user enter a math function. ie cos(x)-e^x + x^2
it will be typed into a text box and then the program performs a numerical procedure on the function (ie integration)

In other words, how do i transform the input string into a method?
Not very easily.
Your code will need to parse the input string, looking for terms (expressions that are added together), operators such as - for negation and ^ for exponents, function keywords such as cos, sin, tan, ln, and so on.
 
hmm, i was thinking it would be complicated. i suppose if i used a keypad (like on a calculator) it would be easier right?
 
bluntwcrackrap said:
hmm, i was thinking it would be complicated. i suppose if i used a keypad (like on a calculator) it would be easier right?
?
All you can get from the keypad are the numeric digits and the arithmetic operators (+, -, *, and /). You still have to parse the input, building numbers out of the input digits, and figuring out which things are added, subtracted, and so on.
 
bluntwcrackrap said:
i would like to have the user enter a math function. ie cos(x)-e^x + x^2
it will be typed into a text box and then the program performs a numerical procedure on the function (ie integration)

In other words, how do i transform the input string into a method?

Have you taken a compiler class yet? That's basically the technique you would use to parse the input and turn it into executable code...
 
You don't need a lot of "compiler theory" to do this. You could build an interpreter to evaluate the expressions quite simply with lexical analysis and parsing tools like lex and yacc (or bison, or whatever the unix community calls it these days). You can probably find something similar as a lex-and-yacc tutorial on the web.

It won't be very efficient to re-interpret the user input every time you want to evaluate the function, but something that works slowly is a better starting point than nothing at all.
 
It depends on which language you are using. There is an easy way and a hard way and a hybrid way.

1) Easy: Some scripting languages can evaluate a string as a line of code even when it is running. Look for languages that can "evaluate" a text string as though it was code in that language. Look for an eval() function. Perl and Python are two such languages.

2) Hard: Otherwise, you will have to parse the input string and perform math operations in code that you write. As AlephZero says, lex and yacc can help you do that. You will need to define a language that can be parsed.

3) Hybrid: Languages like Python can be called from C programs. You can let the Python do the evaluation part and return results to C to do the rest. I don't have any real experience with this.
 
Last edited:
Mark44 said:
?
All you can get from the keypad are the numeric digits and the arithmetic operators (+, -, *, and /). You still have to parse the input, building numbers out of the input digits, and figuring out which things are added, subtracted, and so on.

I mean a built in keyboard where I have buttons for each function built into the ui.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
11
Views
4K
Replies
55
Views
7K
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
13
Views
8K
  • · Replies 2 ·
Replies
2
Views
3K