Algorithm to partition a complex equation into 2 master equations

In summary, the conversation discusses the implementation of a function called partitionEquation in the CalculusWizard class. This function is responsible for partitioning an equation into two parts, separated by the operator with the lowest precedence. The enum eqOps is used to represent the different types of operators. The conversation also mentions the challenges of parsing equations and provides a resource for learning more about it. Finally, the conversation discusses a potential issue with equations containing multiple operators.
  • #1
Jamin2112
986
12
My Calculus tool is coming along. The only thing left is to write some it's helper functions, such as the one described below:

Code:
void CalculusWizard::partitionEquation(const std::string & eq, std::string & eq1, std::string & eq2, CalcWizConsts::eqOps & oper)
{
	/* Given an equation eq, partion eq into 
	   eq = eq1 oper eq2
	   where oper is the operator with the lowest precedence, 
	   e.g. eq = "x*sin(x)+x^2" --> eq1 = "x*sin(x)", oper = ADDITION, eq2 = "x^2".
	   If there is no operator, e.g. eq = "x", then oper = NONE.
	*/
}

which uses

Code:
enum eqOps { ADDITION, SUBTRACTION, MULTIPLICATION, DIVISION, COMPOSITION, NONE };

defined in

Code:
namespace CalcWizConsts.

Does anyone have advice for how I should start out on this function? Or is there any resource you could direct me to where I could learn this type of thing?
 
Technology news on Phys.org
  • #2
Welcome to the fascinating world of parsers and lexical analysers.

What should your function do if the equation looks like x + x + x?
 
  • #4
voko said:
Welcome to the fascinating world of parsers and lexical analysers.

What should your function do if the equation looks like x + x + x?

In that case,

eq1 = x,
eq2 = x + x
 
  • #5
Jamin2112 said:
In that case,

eq1 = x,
eq2 = x + x

+ is too easy, because it is associative. Be careful when you have x - y - z.

I think in your notation eq2 would then become y ##+## z. Or better, eq1 should have been x - y.
 

1. What is an algorithm?

An algorithm is a set of step-by-step instructions for solving a specific problem or completing a task.

2. What is a complex equation?

A complex equation is an equation that involves multiple variables, operations, and functions.

3. Why is it necessary to partition a complex equation into 2 master equations?

Partitioning a complex equation into 2 master equations can make it easier to understand and solve the equation. It can also help identify patterns and relationships within the equation.

4. How do you determine which parts of the complex equation should be separated into 2 master equations?

This can vary depending on the specific equation, but generally, you want to identify any sub-equations or functions within the larger equation that can be solved independently. These can then be separated into their own master equations.

5. Can an algorithm be used to partition any complex equation into 2 master equations?

While there are general guidelines for partitioning a complex equation, it ultimately depends on the specific equation and its components. Some equations may not lend themselves well to being split into 2 master equations using an algorithm.

Similar threads

  • Programming and Computer Science
Replies
4
Views
3K
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
275
  • STEM Academic Advising
Replies
13
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Replies
1
Views
3K
  • General Math
Replies
13
Views
9K
Back
Top