3 ms·
the classic problem for such number systems is linear algebra https://yosefk.com/blog/can-your-static-type-system-handle-linear-algebra.html https://yosefk.com/
by kragen 3y ago
the classic problem for such number systems is linear algebra https://yosefk.com/blog/can-your-static-type-system-handle-linear-algebra.html https://yosefk.com/blog/can-your-static-type-system-handle-l...
the issue is that each column and each row of a matrix can have different units. worse, gauss-jordan elimination chooses which rows to operate on dynamically. there is eventually a solution to this problem in c++ far down the comments thread
i don't see anything in https://numbat.dev/doc/type-system.html https://numbat.dev/doc/type-system.html about aggregate types such as vectors, matrices, maps, arrays, lists, trees, records, etc., though it does have a suggestively named scalar type. i wonder how it handles this sort of thing
- sharkdp 3y agoNo, we do not have aggregate types in Numbat yet. But it is definitely something I would like to support. Note that it is possible to construct a type system solution to this problem (vectors/matrices with non-uniform units). A colleague of mine has an excellent talk on this: https://www.youtube.com/watch?v=SLSTS-EvOx4 https://www.youtube.com/watch?v=SLSTS-EvOx4 By 'Scalar', in the document you referenced, we mean a dimensionless quantity. Not a scalar in the scalar-vector-matrix-tensor sense. Maybe I should rethink that notation.
- kragen 3y agothanks, i'll take a look i know it's possible (even in c++ apparently) but so far it seems difficult
- spott 3y agoInteresting article... though to be honest, I'm not sure I buy the premise. In the article, he states: "Let's call the matrix of all (xi 1) `X` and let's call the vector of all yi `Y`", and then states that the units of `X` are (m 1). But if you instead say the units of `X` are just m, the "1" is in units "m", then the problem goes away, the whole matrix has the same units ("m"), and everything works fine. I'll be honest in that I've never thought of a matrix having multiple units per column... and I can't think of any example where you aren't just putting the units in the wrong place. Let me know if you have a concrete example that might work.
- adastra22 3y agoIf you multiply by a transform where the first entry is 1, the second entry is d/dx, the third entry is d^2/dx^2, etc. You will get a different unit for each entry of the vector. Also most of economics consists of linear systems with non homogeneous units. The first entry could be bushels of wheat, the next demand for steel, etc.
- spott 3y agoOne way to think of this is that there are always multiple ways to break up the units when moving a system of equations into matrix form. What I’m trying to say is that there is always one way to break up the units that leads to matrices and vectors with a consistent unit. Transform vectors like you mentioned can have an implicit 1 with the right units in them in order to make the vector have a consistent unit. > Also most of economics consists of linear systems with non homogeneous units. The system of equations needs to have some sort of unit consistency. Which means there is some way to split up the units to keep the matrices and vectors with consistent units or the math doesn’t actually make sense.
- adastra22 3y agoI don't understand the point you are making. These systems are intrinsically non-homogeneous in their typing. In input-output analysis in economics, for example, the elements of a vector represent the amounts of a commodity (coal, steel, electricity, etc.), and the columns of the demand matrix represent how much of each commodity is required to produce one unit of that commodity as output. So the type of row 1 is "kg of coal", the type of row 2 is "kg of steel", the type of row 3 is "kJ of energy", etc. Given this matrix and a vector representing the starting quantities, you can do some linear algebra to get a matrix representing how much of each quantity to allocate to each sector, and a vector representing the resulting output. The type of these vectors are "[kg Coal, kg Steel, kJ electricity, ...]" I don't now how you can "have an implicit 1 with the right units in them in order to make the vector have a consistent unit" given this setup.
- 3y ago