Live data from Hacker News

Show HN: Kalk, A calculator with math syntax, complex numbers

kalk.strct.net

81–90 of 90 posts

Re: Show HN: Kalk, A calculator with math syntax, complex numbers

#81

For fun, try to run this: `2 + 2 * 10%` in all calculators you have access to: on you phone, on your desktop, in kalk. As they say, "the answer will surprise you" :)

Forth, once using fixed point and scaling 2e+2:

      2 dup 100 10 */ swap 100 * + .S 220 OK

Re: Show HN: Kalk, A calculator with math syntax, complex numbers

#82
post #70
post #67

Earlier quoted context omitted.

The derivation comes from Taylor series expansion of the exponential function e^x = 1 + x/1! + x^2/2! + x^3/3! + … You can throw together a program that will show numerically that this both converges to e^x for real x and that e^ix converges to cos(x)+i*sin(x). You can also find proofs online I’m sure.

Why do it numerically? Show that e^ix converges, then you can reorder the sums, grouping the odd and even terms you get series expansions for cos(x) and i sin(x).

Just to be pedantic, the Taylor series definition of the exponential converges absolutely, hence we can reorder the terms by odd/even powers without changing the sum.

Re: Show HN: Kalk, A calculator with math syntax, complex numbers

#83
post #73

Earlier quoted context omitted.

Yeah the name isn't very good. This wasn't actually supposed to become something, it was a quick thing I made when I was bored, that suddenly expanded into all this, haha. I like being able to type `kalk` in the terminal, but maybe something needs to be added to the name to make it more recognisable.

"kalk" is a great name for a calculator since the word also means "chalk" in a number of European (and descendant) languages.

Oh haha nice!

Re: Show HN: Kalk, A calculator with math syntax, complex numbers

#84

Pity it's not in homebrew. I realize I can manually download a binary and manually install it and make a note somewhere where I got it from in case I forget and then periodically re-check manually if an update is out, or just never install any updates, but I'm trying to not do that if it can be helped.

Yeah maybe it should be on homebrew and other package managers. Didn't actually expect it to get this much attention! I'll see what I can do

Re: Show HN: Kalk, A calculator with math syntax, complex numbers

#85
post #66

Earlier quoted context omitted.

It's the exponential notation for complex numbers, see for example https://tutorial.math.lamar.edu/Extras/ComplexPrimer/Forms.a...

That post proves the point: it jumps from "use cos(t) + i sin(t)" to "use e^it" with zero explanation about why it's related to 2.718281828... The reason I posted my comment is because e^(i pi) is obviously supposed to be -1+0j. But I see now that I was using the calculator incorrectly (I was doing the equivalent of πe^i) but there was a bug in the parenthesis operator preventing me from typing it that way on mobile.

> it jumps from "use cos(t) + i sin(t)" to "use e^it" with zero explanation about why it's related to 2.718281828...

It really isn't, beyond the fact that exp(1) = 2.718…. Then, by definition exp(it) = exp(1)^(it) = e^it. It isn't much more than a notational artifact as far as I'm concerned. For that matter, raising any base b to a power is equivalently just scaling it by ln(b) and plugging it into exponential function, that is, b^it = cos(ln(b) * t) + i sin(ln(b) * t).

Re: Show HN: Kalk, A calculator with math syntax, complex numbers

#86
post #85

Earlier quoted context omitted.

That post proves the point: it jumps from "use cos(t) + i sin(t)" to "use e^it" with zero explanation about why it's related to 2.718281828... The reason I posted my comment is because e^(i pi) is obviously supposed to be -1+0j. But I see now that I was using the calculator incorrectly (I was doing the equivalent of πe^i) but there was a bug in the parenthesis operator preventing me from typing it that way on mobile.

> it jumps from "use cos(t) + i sin(t)" to "use e^it" with zero explanation about why it's related to 2.718281828... It really isn't, beyond the fact that exp(1) = 2.718…. Then, by definition exp(it) = exp(1)^(it) = e^it. It isn't much more than a notational artifact as far as I'm concerned. For that matter, raising any base b to a power is equivalently just scaling it by ln(b) and plugging it into exponential functi…

That last equation clarified things greatly for me. Thanks.

Re: Show HN: Kalk, A calculator with math syntax, complex numbers

#87
post #70
post #67

Earlier quoted context omitted.

The derivation comes from Taylor series expansion of the exponential function e^x = 1 + x/1! + x^2/2! + x^3/3! + … You can throw together a program that will show numerically that this both converges to e^x for real x and that e^ix converges to cos(x)+i*sin(x). You can also find proofs online I’m sure.

Why do it numerically? Show that e^ix converges, then you can reorder the sums, grouping the odd and even terms you get series expansions for cos(x) and i sin(x).

You actually have to understand calculus for that to actually prove it to you, but, you can show that it seems to work out numerically with a bit of programming knowledge, which I imagine is more common on Hacker News.

I don't think either the numerical or symbolic proofs really help build intuition though. This video [1] kinda helps, although it glosses over the critical fact "multiplying by i rotates counterclockwise 90°."

[1] https://youtu.be/v0YEaeIClKY

Re: Show HN: Kalk, A calculator with math syntax, complex numbers

#88
post #87
post #70

Earlier quoted context omitted.

Why do it numerically? Show that e^ix converges, then you can reorder the sums, grouping the odd and even terms you get series expansions for cos(x) and i sin(x).

You actually have to understand calculus for that to actually prove it to you, but, you can show that it seems to work out numerically with a bit of programming knowledge, which I imagine is more common on Hacker News. I don't think either the numerical or symbolic proofs really help build intuition though. This video [1] kinda helps, although it glosses over the critical fact "multiplying by i rotates counterclockwi…

Hmm. This is the second time I've seen that "multiplying by i rotates counterclockwise 90 degrees."

I agree that this is one way to interpret the result. But is it literally equivalent to matrix multiplication by a 2D rotation matrix? Someone tried to say it was, which I felt skeptical about.

(Also, thank you.)

Re: Show HN: Kalk, A calculator with math syntax, complex numbers

#89
post #87

Earlier quoted context omitted.

You actually have to understand calculus for that to actually prove it to you, but, you can show that it seems to work out numerically with a bit of programming knowledge, which I imagine is more common on Hacker News. I don't think either the numerical or symbolic proofs really help build intuition though. This video [1] kinda helps, although it glosses over the critical fact "multiplying by i rotates counterclockwi…

Hmm. This is the second time I've seen that "multiplying by i rotates counterclockwise 90 degrees." I agree that this is one way to interpret the result. But is it literally equivalent to matrix multiplication by a 2D rotation matrix? Someone tried to say it was, which I felt skeptical about. (Also, thank you.)

It is literally equivalent to a rotation matrix:

    [cos π/2  -sin π/2] [x] = [0  -1] [x] = [0 - y] = [-y]
    [sin π/2   cos π/2] [y]   [1   0] [y]   [x + 0]   [ x]
Compare to:

i (x + iy) = ix + i²y = -y + ix

For the general case of rotation in the complex plane, multiplying by a complex number with an absolute value of 1 (i.e. on the unit circle) rotates by that number's angle from the positive reals. Normally you'd write such a number as e^iθ, but since that's what we're trying to get to, we can instead write it as cos θ + i sin θ.

    [cos θ  -sin θ] [x] = [x cos θ - y sin θ]
    [sin θ   cos θ] [y] = [x sin θ + y cos θ]
Compare to:

(cos θ + i sin θ) (x + iy)

= x cos θ + ix sin θ + iy cos θ + i²y sin θ

= (x cos θ - y sin θ) + i (x sin θ + y cos θ)

Maybe the cause of your skepticism is that it seems unintuitive that complex numbers, which are 2-dimensional in linear-algebra-speak, could be as powerful as 2×2 matrices, which are 4-dimensional. But keep in mind that 2×2 matrices can perform any linear transformation on 2-dimensional vectors using only matrix multiplication, whereas complex number multiplication can only scale and rotate, and you need to use complex addition to get translation, and I'm not sure off the top of my head if it's possible to get shear transformations using complex numbers.

Re: Show HN: Kalk, A calculator with math syntax, complex numbers

#90
post #89

Earlier quoted context omitted.

Hmm. This is the second time I've seen that "multiplying by i rotates counterclockwise 90 degrees." I agree that this is one way to interpret the result. But is it literally equivalent to matrix multiplication by a 2D rotation matrix? Someone tried to say it was, which I felt skeptical about. (Also, thank you.)

It is literally equivalent to a rotation matrix: [cos π/2 -sin π/2] [x] = [0 -1] [x] = [0 - y] = [-y] [sin π/2 cos π/2] [y] [1 0] [y] [x + 0] [ x] Compare to: i (x + iy) = ix + i²y = -y + ix For the general case of rotation in the complex plane, multiplying by a complex number with an absolute value of 1 (i.e. on the unit circle) rotates by that number's angle from the positive reals. Normally you'd write such a numb…

I just wanted to say, thank you so much for explaining this so thoroughly. I feel much more comfortable using complex numbers now that I allowed myself to believe "it's literally equivalent to a rotation matrix."

(I'm a former gamedev, so rotation matrices are very intuitive. But for some reason, I never made the connection to complex numbers, except in an abstract math-y sort of way.)

@mayfer also tried to explain to me that it was a rotation matrix. This tweet chain was helpful; posting it here in case anyone needs further convincing: https://twitter.com/theshawwn/status/1400591835052056580

Post reply on HN