On Mon, Apr 11, 2022 at 11:33 AM Ethan Furman <ethan@stoneleaf.us> wrote:
On 4/10/22 21:33, Stephen J. Turnbull wrote:

> I guess you could call the associative law of multiplication "dumb
> luck", but most mathematicians will consider that hate speech.

My apologies for not understanding your example.  The counter example I had in my head, and should have written down,
was something like:

   15mpg * 7l == how many miles?

where

   mpg = miles per gallons
     l = litres

I'm pretty sure the answer there is not 105.

Really? ;-) ;-)
 
>>> import pint
>>> ureg = pint.UnitRegistry()
>>> mpg = ureg.define('mpg = 1 * mile / gallon')
>>> dist = 15 * ureg.mpg * 7 * ureg.l
>>> dist
<Quantity(105, 'liter * mpg')>

It is 105 ... but in some weird distance units.

>>> dist.to(ureg.miles)
<Quantity(27.7380655, 'mile')>

Or, in a more readable way! ;-) ;-)

> python -m ideas -t easy_units
Ideas Console version 0.0.30. [Python version: 3.9.10]

>>> import pint
>>> ureg = pint.UnitRegistry()
>>> ureg.define('mpg = 1 * mile / gallon')
>>> dist = 15[mpg] * 7[l]
>>> dist.to(1[mile]) 
<Quantity(27.7380655, 'mile')>

André Roberge

Thought: I should probably make it even easier to convert units within ideas...
 

--
~Ethan~
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/OGHZSHZZEVHP4MLWXZSH45DGZYO7WDC6/
Code of Conduct: http://python.org/psf/codeofconduct/