eki / mathcraft

A mathtastic computer algebra system.
0 stars 0 forks source link

Add log function #13

Open eki opened 4 years ago

eki commented 4 years ago

Consider how to represent the base. In math, log is often written as log b (n) where the b is a subscript. Although, the b is often left off, there are usually several possible bases.

We could move the base in, or, because it's a number, just place it directly after the "keyword" log? log2(64), log10(1000), loge(10) ... since that last one looks the worst, maybe e is the default base?

Okay, more research, when written as log(n) the base that is implied can change by field of study. So, this is not a great choice. We could implement the log function to take a base as the second parameter as in log(n, b) which is how Ruby implements log.

We can also use ln for natural logarithm (log with base e). And, if function names are identifiers which match a regexp like [a-zA-Z]\w+, then we could have functions log2(n) and log10(n).

So, this combination of functions feels most right: