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

Add Semifield and CommutativeSemifield to algebra #3979

Merged
merged 2 commits into from
Oct 1, 2021

Conversation

armanbilge
Copy link
Member

Introduces a Semifield and CommutativeSemifield to algebra. I'm going by the second definition on Wikipedia:

  • a commutative monoid for addition (+)
  • a group for multiplication (*)

Thanks in advance!

@armanbilge
Copy link
Member Author

@johnynek would you mind reviewing this? Thanks!

Copy link
Contributor

@johnynek johnynek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Are there examples you have in mind that are not other structures?

Are there any instances we can create that we couldn't fully express before?

@armanbilge
Copy link
Member Author

armanbilge commented Aug 29, 2021

@johnynek Thanks for the review! I'm using semifields for non-negative reals in my probabilistic programming library, where probabilities are added, multiplied, and divided (but never negative). For example, I have a LogDouble type which will have this: https://github.com/armanbilge/schrodinger/blob/main/log-double/src/main/scala/schrodinger/LogDouble.scala#L67

Not sure if this is anything we can add to Algebra itself.

@johnynek
Copy link
Contributor

johnynek commented Oct 1, 2021

I can't restart the microsite build. Can you push again? I want to make sure it was a flake.

@armanbilge
Copy link
Member Author

Absolutely. But this was a known issue, see #3974 (comment)

@armanbilge
Copy link
Member Author

@johnynek good to go.

@johnynek johnynek merged commit 3cf10c6 into typelevel:main Oct 1, 2021
@benhutchison
Copy link
Member

Thank you @armanbilge & @johnynek for adding Semifield & friends 🙏

I'm guessing the algebra type-classes must sometimes feel obscure and even that no one notices/appreciates the work. So I thought I'd share my story..

Having defined a non-negative sub-species of BigDecimal, I went looking for the right algebra to implement +, * and /, without negation. And lo and behold, I discovered Semifield was exactly what I needed. At first, I assumed it was part of @non's original vision, but then noticed it is missing from the algebra docs and got curious how/when it came to be.

On docs, I do think an extra two rows are needed in the Ring table. But then it further qualifies the statement that "every lower structure is also an instance of the structures above it"; I actually wonder if with another two exceptions, that over-generalization has gone past time?

@armanbilge
Copy link
Member Author

Thanks!

I do think an extra two rows are needed in the Ring table.

Indeed!

I actually wonder if with another two exceptions, that over-generalization has gone past time?

Yes, agree, probably an inheritance diagram would be more useful at this point :) (in addition to the existing table.)

armanbilge added a commit that referenced this pull request Apr 19, 2023
Update Ring-like table in Algebra for Semifield added in #3979
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants