PaddiM8 / kalker

Scientific calculator with math syntax that supports user-defined variables and functions, complex numbers, and estimation of derivatives and integrals
https://kalker.xyz
MIT License
1.59k stars 70 forks source link

function application #31

Closed bieganski closed 2 years ago

bieganski commented 3 years ago
$ f(x) =  x^2
$ f 2
4
$ g(x,y) = x^2y
g 1 2
Expected 2 arguments for function g, but got 1.

Haskell-like function application would be very useful, is it meant to be supported only for one-param functions?

PaddiM8 commented 3 years ago

Well, this kind of thing is currently made to only support one-param functions, to avoid even more ambiguity. the problem is that it needs to be able to figure out if you're multiplying or not. For example if you write sin2x, it should interpret it as sin(2*x), and spaces are not kept from the tokenizing. However, if given enough context, the parser may be able to figure it out, but that may lead to excessive complexity.

abrudz commented 3 years ago

I disagree that g 1 2 should work. It is fairly common in mathematics to temporarily adopt additional notation, so one can e.g. say:

Let x∗y denote 1-(1-x)+(1-y). Now, 0.5∗0.5 = 0.75 …

When using a 2-param function without parenthesis, the first parameter should be taken from the left of the function name. This will allow writing the above human language as:

>> ∗(x,y) = 1-(1-x)(1-y)
>> 0.5∗0.5
0.75
PaddiM8 commented 2 years ago

This would lead to excessive complexity and is probably not worth it.