4 ms·
> Why should this be obvious? This is very natural, and consistent with standard mathematical notation. It's an abuse of notation so common that is barely eve
by enriquto 3y ago
> Why should this be obvious?
This is very natural, and consistent with standard mathematical notation. It's an abuse of notation so common that is barely ever mentioned in elementary mathematics. For example, when you work with functions f:R→R, like f:x↦3x², it is common to denote constants by their value. Thus you write 7 instead of x↦7. Then you can write simply f+7, where f is a function and 7 is a value, and everybody understands what you mean. No need to write ridiculously correct stuff like f+(x↦7) .
Broadcasting with arrays is very natural if you interpret an array as a function of its indices. It is exactly the same thing as above!
I second that we should be using APL anyways.
- medo-bear 3y ago> This is very natural, and consistent with standard mathematical notation. Which mathematical notation? One of the first things a student of linear algebra gets taught is that you cant add scalars to vectors. The example you gave is not what is taught in most math classes, and seems weird to everyone unless you come from Bourbaki camp. > Broadcasting with arrays is very natural if you interpret an array as a function of its indices. It is exactly the same thing as above! But an array is just a contiguous data structure, not a function of its indicies.
- enriquto 3y agoI don't understand what you mean. Precisely the Bourbaki camp would be the only people who would avoid the broadcasting notation that is commonly used in math.
- medo-bear 3y ago> Thus you write 7 instead of x↦7 I meant this. Very few people look at a number 7 and think of it as a constant function
- enriquto 3y agoMy point exactly. That's what makes broadcasting natural!
- medo-bear 3y agoOur positions diverge because you take the extra-formal specification in mathematics as basis, and then say, "nah thats too formal", broadcasting is more natural. On the other hand I take elementary to undergrad mathematics as basis and say that rules about adding (using a standard '+' symbol) a scalar to a vector in numpy via broadcasting is confusing.
- ayhanfuat 3y agoJulia requires you to explicitly specify if you want to use broadcasting (i.e. `[2, 4, 8] + 3` fails so you need to do `[2, 4, 8] .+ 3`). When I first came across this I thought it was unnecessary but the more I use it the more I like it because I think it improved my mental model of broadcasting. With numpy it was mostly trial and error.
- enriquto 3y ago> But an array is just a contiguous data structure, not a function of its indicies. When you do signal processing, you pretty much interpret 1d arrays as functions of time, 2d arrays as functions on the plane, etc. In that case, it is very natural. If I have an array "A" that represents an image, I can change the britghtness and contrast of the image by doing an operation like "B = α*A + β". This notation requires broadcasting because β is a constant, not an array (or, equivalently, a function).
- medo-bear 3y ago> If I have an array "A" that represents an image, I can change the britghtness and contrast of the image by doing an operation like "B = α*A + β". But you dont write it like this in linear algebra. You write B = αA + b where b is just a vector. Or at least you would make β bold to distinguish it from a scalar
- enriquto 3y agoI'm not talking about matrices as in linear algebra, I'm talking about functions. If you interpret a vector or a matrix as a function of its indices, then B = α*A + β means just B(t) = α*A(t) + β for all relevant t. This broadcasting is used everywhere in signal and image processing, and it would be extremely unnatural if your language forced you to write some monstrosity that modified the constant β so that it has the same type as A.
- medo-bear 3y ago> If you interpret a vector or a matrix as a function of its indices What exactly does this mean?
- enriquto 3y agoA vector v = (v[0], v[1], v[2], ..., v[100]) is exactly the same thing as a function v taking a number i and returning a value v[i]. Since you can sum scalars to functions, it is natural to sum scalars to vectors.