leesugil / symbolic

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

breaking the limitation of x^(int) - unary, binary, ternary operations #3

Closed leesugil closed 5 months ago

leesugil commented 5 months ago

parsing / printing mathematical expression are one thing, symbols defined is another thing.

in the current pilot design, the symbol structure has a member "power" which was meant to be used in evaluation and also in displaying.

but then to display them correctly either on the LHS or the RHS, i had to add expression numbers.

but what if i have a symbolic power?

so basically i have to be able to express "nested mathematical expressions" as much as one wishes. a + b is one expr, but also things like (expr1) * log_(expr2) (expr3)^(expr4^expr5) should be possible.

it is necessary to separate actual mathematical operations from parsing / displaying conventional expressions.

most of mathematical operations will come from the standard C library, so what's more important is to define the scope of expr and its members.

basically, all math operations should be able to accept expr instead of just doubles. -> this requires re-writing wrapper functions for the standard library. basically double -> symbol { name, value }.

at the time of writing this, a binary tree feels like a good candidate structure for expr in the following sense: -a + (b * c)

having such nested structure makes sense, though care should be taken that this example only portrays unary and binary operations forming the element of an expr.

(for the future use, statement should also be defined that can be evaluated T/F.)

let op be a ternary-tree structure defining n-ary operations. op.n : n from the n-ary (0 for just printing?) op.name: within its n-level group, name will be used to determine it binary search outcome. op.d: the human-eye display of the operation given expr arguments. -> should be a pointer to a function that prints.

leesugil commented 5 months ago

here's an example to think about when designing a tree structure for each expression.

consider (a + (a + b)) + ((a + b) + b).

let p be a root tree of this expression.

how should addTree(p, "a + b") or lookUpTree(p, "a + b") be implemented?

two "a + b" terms appearing in the expression are the same and requires an extra identifier to use this binary tree structure.

leesugil commented 5 months ago

resolved, now f^g works where g is another expression, and f^g is evaluated as double iff both f and g are double