News for hackers. Stuff that matters.
Re:Pokémon Go Is Teaching Americans the Metric System by derefr on Saturday July 23, 2016 @01:02PM (#12150105)
> we should work with a number class that has a value and a unit.

Not even a unit. I've always wanted a (majorly-adopted) language and platform where "Integer" or even "Number" are low-level mostly-ignored value types, and you instead work with a type that might be called (something snappier, but equivalent to) "RationalComplexPolynomialUnitedMeasurementWithPrecision".

Like, why can't my stdlib functions all take:

    (-5/6±3.5 + i±1/2) km^2/s^2
...and do something sensible (stoichiometrically) with it?
Re:Pokémon Go Is Teaching Americans the Metric System by Someone on Saturday July 23, 2016 @02:34PM (#12150488)
Because it gets messy very soon. To start with, you would have to pick a set of distributions that is closed under the set of operations you want to perform.

If you pick 'all normal distributions' as your set, that means that you can only allow addition, subtraction, and multiplication by a constant (= a normal distribution with zero variance); you won't be able to compute x^2, take a square root, compute |x|, etc. That rules out, for example, computing the variance of a set of inexactly known numbers.

To make matters worse, to do this really well, you have to track where values come from. You really want:

  x = 6±3.5m
  z = x - x
to have z equal to 0±0m, but

  x = 6±3.5m
  y = 6±3.5m
  z = x - y
to have z equal to 0±4.9m. Similarly, x+x should be 12±7m, and x+y should be 12±4.9m

The best you probably can do is to forget about the second issue, and do interval arithmetic. That is useful, but gives you extremely pessimistic results.

Edit: a good solution also would resolve the question of how to handle conditionals. if x > 0 could pick each of its branches according to the probability that x is larger than zero, or even execute both branches partially (whatever that would mean), according to the distribution of x.

Re:Pokémon Go Is Teaching Americans the Metric System by simcop2387 on Saturday July 23, 2016 @08:54PM (#12151707)
Why would x+y be 12+-4.9m? shouldn't it be the same +-7m?
Re:Pokémon Go Is Teaching Americans the Metric System by nialo on Saturday July 23, 2016 @09:26PM (#12151787)
The parent is taking the error numbers as something like 1 standard deviation on a normal distribution, rather than an absolute limit. so, x = 6±3.5m means something like "x is equal to 6 + a random number taken from a normal distribution with standard deviation 3.5 centered around 0" and y is the same, but with a _different_ random number.

(I'm a little hazy on exactly what distribution is being assumed, but the basic idea of x and y being different random numbers is the important thing)

In principle one could also interpret x = 6±3.5m as "x is equal to 6 + a random number taken uniformly from the rand -3.5 to 3.5" or something, and then x+y would be 12+-7, but the real world numbers this is nominally supposed to represent don't really work that way. I think this is what is mean by "The best you probably can do is to forget about the second issue, and do interval arithmetic. That is useful, but gives you extremely pessimistic results."

Re:Pokémon Go Is Teaching Americans the Metric System by simcop2387 on Sunday July 24, 2016 @04:25PM (#12154694)
Yea interval arithmatic is what i thought was being talked about before. It's one of the things that lead me to seeing all kinds of issues trying to move forward with the language i made/mentioned in another comment. I decided that I needed to lift how I was handling numerics into multiple types: floats, rationals, intervals, etc. and design the whole thing so that you could have more than one kind of interval (i hadn't thought about doing it the way you describe), like open and closed around the upper and lower limits.
Re:Pokémon Go Is Teaching Americans the Metric System by simcop2387 on Saturday July 23, 2016 @01:29PM (#12150200)
Closest I can come is my esoteric language I made. It's a rough clone of Frink, but diverged during development in a number of ways:

http://search.cpan.org/dist/Language-Farnsworth/lib/Language...

It's missing the ranged/bracketed number support, but will do the rest of that.

13:27:11 < simcop2387> farnsworth: (-5/6+3.5 + i-1/2) km^2/s^2 -> "kJ/kg" 13:27:12 < farnsworth> simcop2387: (2166.66666666666 + 1000.00000000000*I) kJ/kg

It'll auto-convert things into floats if you use them, but it's 100 digit accuracy (configurable). Development has halted, mostly because I couldn't decide how I wanted to tackle adding objects as a first class data type and had a number of issues with the parser I needed to solve to make my life saner (easy way to force a difference between a variable and unit named "kg" etc.)

I might pick it up again and try using the parser combinators in Rust and actually compile the language down instead of an interpreter (though i'd remove eval[] to do that).

Re:Pokémon Go Is Teaching Americans the Metric System by haasn on Saturday July 23, 2016 @09:00PM (#12151720)
Some languages, like Haskell, let you extend the numerical types to whatever representation works well for your causes. A few years ago I wrote a library for embedding units of measure into every figure (at the type level), including e.g. auto-converting between units.

It's somewhat bitrotten but it may still be interesting if you're into this sort of thing: See [1] for an example of how it looks in practice.

[1] https://github.com/haasn/units/blob/master/tests/Tests.hs

Re:Pokémon Go Is Teaching Americans the Metric System by ced on Saturday July 23, 2016 @03:23PM (#12150675)

   using SIUnits, SIUnits.ShortUnits
   using Measurements

   ((-5/6±0.1) + 1im)km^2/s^2

   > -833333.3333333334 ± 100000.0 + 1.0e6 ± 0.0im m²s⁻²

   typeof(((-5/6±0.1) + 1im)km^2/s^2)

   > SIUnits.SIQuantity{Complex{Measurements.Measurement{Float64}},2,0,-2,0,0,0,0,0,0}
In Julia.
Re:Pokémon Go Is Teaching Americans the Metric System by khaled on Saturday July 23, 2016 @07:02PM (#12151385)
All measurements in TeX must have a unit, even if the value is zero. Only counters take unitless numbers.