leesugil / symbolic

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

function recognition #15

Closed leesugil closed 4 months ago

leesugil commented 5 months ago

can it do something like f(x, y) = x^2 + 2 x y + y^2 so that i can also calculate (f(x + dx, y) - f(x, y)) / dx ?

leesugil commented 4 months ago

f(x + dx, y) now works

leesugil commented 4 months ago

g(x) = f(x + dx) - f(x) not working. hypothesis: 1) 'x' read from 'g(' 2) wiring fails as when the 'formula' is parsed, f(x) and f(x + dx) must have been parsed weird. test the hypothesis. IF true, then here's the suggested update: when wiring, before scanning x, update the expression first, replacing f(x) and f(x + dx) by it's actual expression.

leesugil commented 4 months ago

three cases:

intput: h(x) = 5 * [1] 31996 segmentation fault ./a.out 2> /dev/null

intput: f(x) = 5 _removing var x [1] 32001 trace trap ./a.out 2> /dev/null

intput: h(x) = f(x) [1] 32009 segmentation fault ./a.out 2> /dev/null

leesugil commented 4 months ago

the three cases are resolved

leesugil commented 4 months ago

the original issue has been resolved with updateFuncComp.

however, there are two concerns with the current adaptation: 1) once updateFuncComp is called, like for example on g(x) = f(x + dx) - f(x), it completely replaces f(x + dx) and f(x) by its explicit formula in the name formula for g(x), so even if a change happens on the actual formula of f later, it's not reflected in g as g already lost the "f(" parts in its expression. this suggests that g should keep f(x + dx) and f(x) in its original expression, and should somehow have another version of Expr for replacement/calculation purposes. 2) Symb, Func, Var should be fundamentally the same, right? the current working version didn't start from the perfect design plan, but it seems reasonable to merge all of them. so, for example, g has its members

one thing to add is to be able to call things like "g(5) = f(5 + dx) - f(5)" when f is not defined. this requires a major update in Expr as it'll require a further parsing capabilities like

f(x, y, z)
    / \
  x   y, z
        / \
       y  z
leesugil commented 4 months ago

progress update

IMG_CE811302CC1F-1

Screenshot 2024-02-15 at 3 29 29 PM

updateExpr and evalSymb: ideally, when "h" is called, its p->formula->name "f((x))" is called, which should be understood as "f(x)", then "f(x)"->formula->name should be called.

leesugil commented 4 months ago
Screenshot 2024-02-15 at 5 36 36 PM

highlighted part shouldn't have happened. it just returns "f((x))" as the originally registered as "h(x) = f(x)". the return also should be evaluated.

leesugil commented 4 months ago

resolved