leesugil / symbolic

Symbolic calculator for arithmetic operations with fractions
GNU General Public License v3.0
1 stars 0 forks source link

organizing the flow #16

Closed leesugil closed 4 months ago

leesugil commented 5 months ago

the current version is a mix of the legacy design ("make it work first") and the goal design ("a true symbolic algebra program"). it's difficult to see how parsing, parenthesizing, and evaluation is done in a clear flow-chart. for example, is there a specific order of operations (not mathematical binary operations, this on later) to be applied to a given expression, like altExpr -> distExpr -> commExpr -> ... ?

doing this will not only visualize the flow of the product but also help us analyze performance issues

also, of all these altExpr, expExpr, distExpr, commExpr, assocExpr, evalExpr, etc.,

  1. which ones should be merged?
  2. which ones can be applied as -ExprNode instead of -Expr to improve performance?
  3. which ones require re-branching node-wise? (because most of the process feels like you only need to re-branch at the end, the top node, but also some operations require identifying the new p->op, and then accessing the new p->left->op and p->right->op to determine the parenthesis criteria)

-- edit --

  1. how can we assure we consider all possibilities of combinations?
    _a * b * c                        3! = 3 * 2 * 1 = 6 ways of pure arrangement of letters,
                                       each arrangement having two forms - left-assoc and right-assoc
    (a * b)* c                        left-assoc
      (b * a)* c                  comm in left
       b *(a * c)                 right-assoc
              b *(c * a)          comm in right
             (b * c)* a           left-assoc
                   (c * b)* a     comm in left
                    c *(b * a)    right-assoc
    a *(b * c)                       right-assoc
       a *(c * b)                 comm in right
      (a * c)* b                  left-assoc
            (c * a)* b            comm in left
             c *(a * b)           right-assoc
                   c *(b * a)     comm in right (repeat)
                  (c * b)* a      left-assoc (repeat)

    looks like there's a different branching going other than the usual tree of Expr, each of the 12 arrangements yielding their own Expr tree.

so the current Expr tree should be more of called as eval tree, where as a given mathematical expression should have a different tree listing all possible different ways of expressing the same thing.

that's an exponential growth.

leesugil commented 5 months ago

regarding 3., maybe we should keep the parenthesis for all terms during the process, and run parenthExpr once on the final Expr to make it visually appealing. (along with maybe replacing " * " with " ")

leesugil commented 4 months ago

IMG_70BD8831B3C2-1

leesugil commented 4 months ago

resolved. added displyExpr to remove parenthesis and * for final output