Hacker News new | ask | show | jobs
by pxx 1682 days ago
I use it whenever I have something mildly annoying to convert, especially dates. e.g. https://www.wolframalpha.com/input/?i=1636221900+unix+time+i...

Probably an incredibly trivial use-case but still useful regularly for me...

2 comments

I use GNU date(1) for this:

    $ TZ=Europe/Warsaw date --date=@1636221900
    sáb 06 nov 2021 19:05:00 CET
    $ TZ=Europe/Warsaw date --date=2021-11-06T19:05 +%s
    1636221900
    $ echo $(( ($(TZ=Europe/Riga date +%s --date=2021-11-05T17:00) - $(TZ=America/New_York date +%s --date=2021-12-05T09:00)) / 3600 ))
    -719
However, this is super dangerous, because for whatever reason date(1) lies if you give it a nonexistent timezone, pretending that it understands you but actually giving you UTC:

    $ TZ=Mars date --date=@1636221900
    sáb 06 nov 2021 18:05:00 Mars
There's a list of valid timezones that you can conveniently browse with tab-completion after you spend 14 keystrokes to navigate there:

    $ TZ=/usr/share/zoneinfo/Europe/
    Amsterdam    Berlin       Chisinau     Isle_of_Man  Lisbon       Mariehamn    Paris        San_Marino   Stockholm    Vaduz        Zagreb
    Andorra      Bratislava   Copenhagen   Istanbul     Ljubljana    Minsk        Podgorica    Sarajevo     Tallinn      Vatican      Zaporozhye
    Astrakhan    Brussels     Dublin       Jersey       London       Monaco       Prague       Saratov      Tirane       Vienna       Zurich
    Athens       Bucharest    Gibraltar    Kaliningrad  Luxembourg   Moscow       Riga         Simferopol   Tiraspol     Vilnius      
    Belfast      Budapest     Guernsey     Kiev         Madrid       Nicosia      Rome         Skopje       Ulyanovsk    Volgograd    
    Belgrade     Busingen     Helsinki     Kirov        Malta        Oslo         Samara       Sofia        Uzhgorod     Warsaw       
    $ TZ=/usr/share/zoneinfo/Europe/Riga date
    dom 07 nov 2021 06:50:44 EET

I wish I had a really good calendar math utility program that handled this sort of thing properly.
> I wish I had a really good calendar math utility

Might be a good learning exercise in machine learning: translating natural-language queries from that domain to whatever standard utility.

Maybe, and it wouldn't have to be as slow and unresponsive as Wolfram Vertical Line Alpha or obscure your answers as an attempt to upsell you, but I think it would still tend to have the same kinds of essential usability problems: a gulf of execution in figuring out how to phrase a query so the system would understand it, and a gulf of evaluation in figuring out whether the calculation it had carried out was the calculation you wanted.
It doesn't work so good for times but I often use Google search to multiply numbers with units together and get a result in the units I want without having to worry about screwing up unit conversions.

Example: 4 atomic mass units * (1000 nm/sec)^2

Google Result: 6.64215616 × 10-39 joules

I use this all the time. I use wolfram alpha for solving equations or systems of equations but I use google for unit conversions because it's got better input parsing (frankly).

I should try the wolfram alpha math entry mode probably, I think that didn't exist when I started using it. If I could manually enter the equations with stricter formatting to ensure it's interpreted properly I'd use it more.

A reminder that GNU Units still exists, e.g.

  $ units
  Currency exchange rates from FloatRates (USD base) on 2021-01-17 
  3677 units, 109 prefixes, 114 nonlinear units
  
  You have: 4 amu * (1000 nm/s)^2
  You want: joules
          * 6.6421563e-39
          / 1.5055352e+38

  You have: ^D
It’s slightly less DWIMish (you have to say “atomicmassunits”, “atomicmassunit”, “amu”, or “u”, not “atomic mass units”) and somewhat awkward as a separate tool, but then resorting to your web browser for unit conversions is awkward in a different way. Non-interactive invocations, like units VALUE-OR-UNIT UNIT, work as well.

[1]: https://www.gnu.org/software/units/

Thanks for the reminder =)

Alas, I often have to do these kinds of calculations on a random publicish computer or my phone and Google's converter is platform-independent. But not using Google services when feasible is certainly net good.

And of course my TI-89 had equally good unit conversion for practical purposes (since you can define your own units) so somehow the world is still playing catchup to a calculator from the 90s...

If you’re organized enough to have space for Termux on your phone, it does wonders in this department. I feel silly every time I punch Python code into that teensy touch keyboard, but damned if I know anything else that has a better input UI and isn’t orders of magnitude less versatile. (Maple Calculator and microMathematics are still on the “there was an attempt” level, in my experience.)
There's an Android GUI for a units(1) calculator in F-Droid. I have it on my phone.
The TI-89 was/is an amazing device.
+1 for 'units'. I like it for conversion between millilightseconds and miles, to get the theoretical best-case latency between two places.

i.e. if it's x milliseconds ping, it can't be more than m miles away.

You have a missing factor of two.
... Seriously, though, if you’re actually need this type of calculation regularly and didn’t just pick a random example, atomic-scale calculations are absolutely miserable to do in SI (and this is not a problem, it’s a human-scale, engineering system, after all; and its metrological aspects, which were the actual advance originally, are completely unimportant here).

If I had to do this in my head or with a desk calculator, I’d just do it in high-energy units (c = ℏ = 1, mass and energy in eV, length and time in eV^-1). So,

  4 amu = 4 × 0.93 GeV (a proton weighs 939 MeV, an amu is slightly smaller due do binding energy, rounding to 1 GeV is good enough for most purposes) ≈ 4 GeV,

  (1000 nm / s)^2 = (1e4 Å / s)^2 = (1e4 / 1.97 keV^-1 s^-1)^2 (an angstrom is a typical atomic size, a keV is a typical [large] atomic energy, a fermi aka femtometer is a typical nuclear size, a MeV is a typical [not so large] nuclear energy, remember any of 197 MeV fm = 1.97 keV Å = 1, though again 200 is almost always good enough) ≈ (1e4 / 2 keV^-1 s^-1)^2 = 25e6 keV^-2 s^-2,

  4 GeV × 25e6 keV^-2 s^-2 = 4e6 keV × 100e6/4 × keV^-2 s^-2 = 1e14 keV^-1 s^-2.
This is slightly inconvenient, we wanted energy in eV, but the seconds don’t seem to want to go away. I don’t remember Planck’s constant in eV s, but I do remember 2 keV Å ≈ 1 and 300e3 km/s = 3e8 m/s = 1, so let’s sprinkle it with those,

  1e14 keV^-1 s^-2 ≈ 1e14 keV^-1 s^-2 × (2 keV Å)^2 / (3e8 m/s)^2 = 4/9 × 1e14 × 1e-16 keV Å^2 m^-2 = 0.44 × 1e14 × 1e-16 keV × (1e-10)^2 ≈ 0.44e-22 keV ≈ 0.44e-19 eV.
The hardest part is pretending to be a normal person: you have to remember what an electronvolt actually is in normal units. Good thing this is numerically the same as remembering the charge of an electron in coulombs (1 eV = 1.6e-19 J),

  0.44e-19 eV = 0.44e-19 eV × 1.6e-19 J / eV (turns out converting to a decimal fraction wasn’t a good idea after all, powers of two FTW) ≈ 4/9 × 16 × 1e-1 × 1e-19 × 1e-19 J = 64/9 × 1e-39 J ≈ 63/9 × 1e-39 J = 7e-39 J.
Good enough to a couple percent.

OK, I won’t pretend that this is easy or that I did it flawlessly the first time just now, but I do think this looks like a skill you could plausibly learn, unlike the textbook “SI all the things” calculation. The good news is that you’ve just seen essentially all the relevant constants you’re going to have to remember, except maybe Avogadro’s number if you’re going to have moles somewhere.

(One place where this doesn’t help is first-principles chemistry, things like electrolysis, because you need to subtract large binding energies to get a change that’s hundreds to thousands times smaller. Calculating things to a couple percent just isn’t good enough.)

Yes, I am familiar with this system. If anything, being a physicist is all the better reason to want a computer to deal with the units though...

My example was entirely contrived of course, a less contrived one would be estimating how long a gas cylinder will last. The tank name plate might say it has 200 cubic feet (sigh) and you need to flow at 10mL/min. How many months does the tank last? I'm talking about quick engineering tasks, not theory.

BTW, the answer is about 13 months, whatever that is in eV^{-1}:

https://www.google.com/search?hl=en&q=200%20cubic%20feet%20%...

Which took me about 15 seconds to type. Just different use cases.

units(1) can handle this but by default it gives you the answer in seconds.

    You have: 200 ft**3 / (10 mL/min)
    You want: months
     * 12.921493