Do you know a tool that automatically adds parentheses to a mathematical equality?
For example, given an input:
2 + 6 / 2 + 3 * 2 + 4 = 22
That automatically solves:
(2 + 6) / 2 + 3 * (2 + 4) = 22
Thank you!
Auto Solve Parentheses in math equality??
Auto Solve Parentheses in math equality??
Last edited by zikitrake on Wed Sep 14, 2022 7:48 am, edited 1 time in total.
PB 6.21 beta, PureVision User
Re: Auto Solve Parentheses in math equality??
Assuming : operator = division?
You could parse the equation and solve all combinations of parentheses until solution agrees with equality.
You could parse the equation and solve all combinations of parentheses until solution agrees with equality.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Auto Solve Parentheses in math equality??
Yes, ":" = "/"... I just changed itskywalk wrote: Tue Sep 13, 2022 9:32 pm Assuming : operator = division?
You could parse the equation and solve all combinations of parentheses until solution agrees with equality.

I don't know how to get all the combinations and do the calculation on them

2 + 6 / 2 + 3 * 2 + 4
(2 + 6) / 2 + 3 * 2 + 4
2 + 6 / (2 + 3 * 2) + 4
(2 + 6 / 2) + 3 * (2 + 4)....
PB 6.21 beta, PureVision User
Re: Auto Solve Parentheses in math equality??
What you have to think of is, these calculations are like trees.
You have leaves like all the numbers and you have nodes like all the operators.
Now, you can add edges to connect the leaves with the nodes, and the nodes to each other, like:
At this point, you can change the edges randomly or in a deterministic way, and check all the results.
When you find a solution, you can create the inline-form of the tree and you can set the needed parentheses depending on the operator precedence:
You have leaves like all the numbers and you have nodes like all the operators.
Code: Select all
Nodes: + : + * +
Leaves: 2 6 2 3 2 4
Code: Select all
+ ---
/ \
: +
/ | / |
Nodes: + \ * \
/ \ | / \ |
Leaves: 2 6 2 3 2 4
When you find a solution, you can create the inline-form of the tree and you can set the needed parentheses depending on the operator precedence:
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: Auto Solve Parentheses in math equality??
Search for rpn eval Reverse polish notation, shunting yard algorithm
Re: Auto Solve Parentheses in math equality??
Really thank you, @idle and @STARGÅTE for yours tips, but it's too advanced for me
My son has a hard time solving this type of exercise (putting parentheses where they belong) and I was wondering if there was an online utility that would do it automatically so he can practice/check it out.
Again, thanks anyway!


My son has a hard time solving this type of exercise (putting parentheses where they belong) and I was wondering if there was an online utility that would do it automatically so he can practice/check it out.
Again, thanks anyway!
PB 6.21 beta, PureVision User
Re: Auto Solve Parentheses in math equality??
In my opinion math problems like this are ambiguous on purpose when parentheses are omitted from them. I think it comes down to personal preference in this case. Buuut, I'm not a math wiz so I'm sure there's more to it than trying to apply PEMDAS(or any of those alternative acronyms!) to all of life's problems.
How should these types of problems be solved when order of operation can go several directions?
edit: oh, wait. My bad, I completely glossed over the part where it's already solved haha
How should these types of problems be solved when order of operation can go several directions?
edit: oh, wait. My bad, I completely glossed over the part where it's already solved haha

▓▓▓▓▓▒▒▒▒▒░░░░░