Live data from Hacker News

Show HN: Numbat – A programming language with physical dimensions as types

numbat.dev

21–30 of 122 posts

Re: Show HN: Numbat – A programming language with physical dimensions as types

#21

A month cannot be unambiguously represented as a length of time, as the length of a month is variable.

It looks as if they're defining a month as some amount of days. (30.4369, given the following.)

    >>> 1 day + 1 month

      1 day + 1 month
          = 31.4369 day

Re: Show HN: Numbat – A programming language with physical dimensions as types

#23

How does Numbat infer the type/unit for operations that involve transcendental functions like the trigonometric functions and the natural logarithm? How about for exponents that are not integers (rational or irrational)? I've seen from to time some empirical equations that result to this. Usually, it's just hand-waved away and the non-integer units are ignored or dropped when the transcendental function is evaluated.…

Those types of functions are only allowed to take in dimensionless (ie scalar) values. Numbat seems to handle this correctly, see [1].

[1]: https://numbat.dev

Re: Show HN: Numbat – A programming language with physical dimensions as types

#24
post #22
post #4

This is great. I want this as an addon to JS and Python.

For Python, there is the Pint library: https://pint.readthedocs.io/en/stable/

Another python alternative that work well with numpy arrays is astropy.units (also mentioned on the pint website):

https://docs.astropy.org/en/stable/units/

Re: Show HN: Numbat – A programming language with physical dimensions as types

#25
Or you could just use Nim [0], where this sort of thing can be implemented in Nim's macro system. Then you have a regular programming language combined with CT safe units. :)

It even pretty much looks identical to those Numbat snippets!

    import unchained
    
    let earth_mass = 5.972168e24.kg
    let solar_mass = 1.9885e30.kg
    let lunar_mass = 7.342e22.kg
    
    let distance_sun = 1.AU  # astronomical unit
    let distance_moon = 384_400.km
    
    let force_sun = G_Newton * earth_mass * solar_mass / distance_sun
    let force_moon = G_Newton * earth_mass * lunar_mass / distance_moon
    
    echo force_sun / force_moon
    # 69593.6 UnitLess

Sorry for the shameless plug. ;) Numbat looks quite cool though and the article talks about a lot of things to think about when writing such a program / lib / programming language.

[0]: https://github.com/SciNim/Unchained

Re: Show HN: Numbat – A programming language with physical dimensions as types

#26
post #23

How does Numbat infer the type/unit for operations that involve transcendental functions like the trigonometric functions and the natural logarithm? How about for exponents that are not integers (rational or irrational)? I've seen from to time some empirical equations that result to this. Usually, it's just hand-waved away and the non-integer units are ignored or dropped when the transcendental function is evaluated.…

Those types of functions are only allowed to take in dimensionless (ie scalar) values. Numbat seems to handle this correctly, see [1]. [1]: https://numbat.dev

I guess that's logical, still a bit tedious in converting values to scalars...

Re: Show HN: Numbat – A programming language with physical dimensions as types

#27
post #25

Or you could just use Nim [0], where this sort of thing can be implemented in Nim's macro system. Then you have a regular programming language combined with CT safe units. :) It even pretty much looks identical to those Numbat snippets! import unchained let earth_mass = 5.972168e24.kg let solar_mass = 1.9885e30.kg let lunar_mass = 7.342e22.kg let distance_sun = 1.AU # astronomical unit let distance_moon = 384_400.km…

[deleted]
Post reply on HN