User loginNavigation 
Are scalars "just" degenerate matrices?I'm working on a Haskell library implementing the ideas in George Hart's book Multidimensional Analysis: Algebras and Systems for Science and Engineering. In essence explains the way that physical dimensions propagate through matrix equations when different locations in a single matrix may not share the same physical dimension, which happens all the time in a bunch of useful engineering/optimization/signalprocessing applications. This is all well and good, and the dimensional library is a great jumpingoff point that handles all of the typelevel arithmetic. My question/puzzle is in several parts, so I'll start with a motivating example. If you look at the dimensional library, or most any approach to static typing of physical dimensions (or units, whether to track dimensions or units is a separate battle which I'm not exploring today), it works by representing dimensioned quantities using a phantom type that encodes their dimensions. When you do this in a library you end up with There are two solutions to this untidyness: The first is introducing a system for userdefined coercions between types. The drawback is that inferring where to put such coercions is difficult, complicates/clutters the principle type of pretty much every polymorphic function, and doesn't mix well with a lot of other type system features that are desirable. In summary, it's good if your language already has it, but adding it to your language to solve this problem opens a large can of worms. The second is to simply declare that all numbers have a dimension, it's just coincidence that that dimension is often 1. In Haskellspeak, you move all the types like The second option seems justified for a greenfield language design, even though it requires sweeping changes, because I can't think of a logical difference between a dimensionless 37 and a dimensionally naive 37 and because you can almost always erase the phantom type so there needn't be a performance problem. Question one: are there valid objections? Question two (bonus): literals that have the value 0 can be interpreted as polymorphic in their dimension, are there good objections for teaching the compiler about this rule? CSS is the only language I know of that does this, but it seems like a good idea. When you start to track matrix sizes, you run into a similar problem where scalars and vectors start to look like degenerate matrices in the same way that dimensionally naive 37s are degenerate dimensioned 37s at dimension one. Adopting this convention recovers a single multiplication operator, saving you from scalar * scalar, scalar * vector, scalar * matrix, vector * matrix, matrix * matrix, and all the flipped versions. Scalar addition, inversion, and exponentiation maintain the same meanings if you look at them as degenerate matrix addition and exponentiation (at least for integer exponents?), and so do all the common trigonometric functions. When you start to track matrix types for the nonuniformly dimensioned matrices I mentioned in the first paragraph, you end up realizing that matrix size checking falls out naturally from checking matrix dimensions (in the sense of physical dimensions) because you end up with an index type like This motivates the third question: what are the objections to treating all scalar numbers everywhere not only as degenerate dimensionless quantities, but as degenerate dimensionless matrices? I have three objections so far:
TL;DR: Is By Douglas McClean at 20120912 04:09  LtU Forum  previous forum topic  next forum topic  other blogs  5878 reads

Browse archivesActive forum topicsNew forum topics 
Recent comments
3 hours 11 min ago
3 hours 59 min ago
4 hours ago
10 hours 40 min ago
20 hours 14 min ago
22 hours 23 min ago
22 hours 33 min ago
23 hours 32 min ago
1 day 1 hour ago
1 day 6 hours ago