Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistencies with associativity of multiplication. #637

Open
dex-k opened this issue Oct 25, 2024 · 3 comments
Open

Inconsistencies with associativity of multiplication. #637

dex-k opened this issue Oct 25, 2024 · 3 comments
Labels

Comments

@dex-k
Copy link

dex-k commented Oct 25, 2024

Hi, I just came across Numbat from this post, and went to try it out. After skimming the documentation, I tried to do a currency conversion:

>>> 1 usd * ( aud / usd )

  1 dollar × (australian_dollar / dollar)

      = 1 AUD    [Money]

>>> aud / usd

  australian_dollar / dollar

      = 0.665332

>>> 1 usd * 0.665332

  1 dollar × 0.665332

      = 0.665332 $    [Money]

>>> 1 * usd * (aud/usd)

  1 dollar × (australian_dollar / dollar)

      = 1 AUD    [Money]

>>> 1 * (aud/usd) * usd

  1 × (australian_dollar / dollar) × dollar

      = 0.665332 $    [Money]

Having read the (seemingly) relevant parts of the documentation again, I don't understand why all of the former snippets don't evaluate to the same result. Is this intended behaviour?

@Goju-Ryu
Copy link
Contributor

This looks a bit odd. I think it might be associated with the issues discussed following this comment on another issue.

And just in case you are unaware, it looks like you are trying to convert between currencies which is much more easily done this way: 1 usd -> aud or with the keyword to instead of the arrow if you prefer.

@dex-k
Copy link
Author

dex-k commented Oct 26, 2024

Thank you, that's helpful to know.

@sharkdp
Copy link
Owner

sharkdp commented Dec 27, 2024

What is the exact issue here?

>>> 1 * usd * (aud/usd)

  1 dollar × (australian_dollar / dollar)

      = 1 AUD    [Money]

>>> 1 * (aud/usd) * usd

  1 × (australian_dollar / dollar) × dollar

      = 0.665332 $    [Money]

These two results do not look the same, but they are equal, as you can confirm by running:

>>> 1 * (aud/usd) * usd == 1 * usd * (aud/usd)

    = true    [Bool]

Yes, the unit may change when changing the order or multiplication (do you mean "commutativity" instead of "associativity"?). And we should probably change that. For example, we could always choose the "smaller" unit. Or we could always choose the "more fundamental" unit (and if impossible, fall back to some internal ordering of units). Is this what's bothering you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants