davidedc / Algebrite

Computer Algebra System in Javascript (Typescript)
http://algebrite.org
MIT License
955 stars 59 forks source link

log(a) + log(b) = log(a*b) works when given symbols, but not when given numbers #120

Open derivitaandrew opened 4 years ago

derivitaandrew commented 4 years ago

Similar to #119.

Algebrite knows that ln(a) + ln(b) = ln(a*b), but if you plug in most numbers for a and b, it no longer recognizes the rule On Algebrite.org:

(ln(a) + ln(b)) - (ln(a*b)) // Expected: 0; Actual: 0
(ln(2) + ln(3)) - (ln(2*3)) // Expected: 0; Actual: log(2)+log(3)-log(6)

It's very weird that it knows a general principal, but can't use it in specific cases. It will only work when a or b is 1.

In another twist, it knows abstractly that ln(a) - ln(b) = ln(a/b), but will only work on specific numbers a and b when they are the same or coprime: image

oshempek commented 4 years ago

It's preserving the expression and not computing it. A somewhat hacky way that I found to make it work is if you run 'ln(2) + ln(3) - ln(2*3) +0.0' it should correctly return 0 (well rather 0.0 ). I'm guessing this forces it to look at it as floats and not just integers.

I've run into similar problems regarding constants like pi, e when I want their numeric values up to a certain precision. Like 'pi+0.0' would return its numeric value but for some reason the same doesn't happen with 'e + 0.0'. However, if you do (e^(2.0)/e), it returns the numeric value of e. A cursory glance at the docs didn't help me figure out the proper way of doing this.

Edit: float( ln(2) + ln(3) - ln(2*3)) is probably the right way to get the numeric value.