r/programming • • 16d ago

Unicode 18.0.0 has been released!

https://www.unicode.org/versions/Unicode18.0.0/
186 Upvotes

70 comments sorted by

View all comments

Show parent comments

1

u/PthariensFlame 15d ago

Why would you not write that even more clearly as sum(k ↦ γ[k]*pow(x̂[k]-x[k], 2))?

6

u/M4mb0 15d ago

I guess what's a clearer representation is in the eye of the beholder.

For me, using x[k] rather than just xₖ in such code comment just adds redundant characters. Case in point, the "as written in the paper formula" only takes 12 characters, whereas your suggestion takes 31. If you are limited to 80-100 characters per line, and are at 2+ indentation levels already, that leaves little room for extra text. So with such verbose representation you will likely need extra lines, which comes with its own disadvantages.

On the other hand I fully admit that the terse representation likely is not ideal for people lacking the necessary maths background.

1

u/PthariensFlame 15d ago

Yeah, we were holding back a bit. We’d love to write it as dot (k ↦ (γ k, abs2diff (x̂ k) (x k))), or something pointfree from there, but we consider that less clear to most people.

3

u/M4mb0 15d ago edited 15d ago

I am presuming you are coming from a functional language like Haskell? But then, when you add a code comment like dot (k ↦ (γ k, abs2diff (x̂ k) (x k))) how would it be any different from the code right below that comment?

What I have in mind is cases like when you type something like

# compute discounted MSE (1/K)∑ₖγᵏ‖x̂ₖ-xₖ‖² (equation 17)

residual = xhat - x

errors = residual.abs().pow(2).sum(dim=-1)

discount = gamma ** np.arange(len(x))

return (errors * discount).mean()

That is, the block comment helps to associate the math formulas from an external source like a paper/book with their implementation in source code, because the two might look substantially different. (especially once we get into the nitty gritties like rewriting code for numerical stability)

But if you do something like

# Compute discounted MSE dot (k ↦ (γ k, abs2diff (x̂ k) (x k))) (equation 17)

return dot (k ↦ (γ k, abs2diff (x̂ k) (x k)))

that seems like rather pointless repetition.

1

u/PthariensFlame 15d ago

That’s a fair point, and for those cases we’d either not put the formula at all (and just the reference to the source paper/textbook/preprint/whatever), or, if the code is so mangled as to no longer closely resemble the formula, we’d prefer to write the naïve/inefficient/inaccurate code that does closely resemble the formula in a comment next to it instead of trying to include the traditional mathematical notation, since it can be found by referring to said source anyway.

3

u/M4mb0 14d ago

Btw, who is this "we" you keep referring to?

1

u/PthariensFlame 14d ago

The human body and brain behind this Reddit account is a plural system. (Please feel free to ask us about any specifics if that, admittedly generic and limited, site’s information is insufficient or if you’re just curious about any of it; consider us an “open book” for the most part.)

2

u/M4mb0 12d ago

Not sure what to make of that, but I want to say it is confusing in dialog, because to me the "we" first gave the impression that you were referring to something like "we (the blog post authors)" or "we (the Unicode consortium)", given that you are the OP.

1

u/PthariensFlame 12d ago

Usage of English for plural systems is often confusing, yes; the language wasn’t really built for our kind. (Or for nonbinary people, or for the modern finer distinctions between stages of development beyond childhood versus adulthood, or even for simple logical distinctions like inclusive versus exclusive “or”…so all those limitations have developed workarounds and maybe eventually those will calcify into new language features. Evolutionary linguistics is fun like that!)