Giter Site home page Giter Site logo

Comments (3)

non avatar non commented on July 27, 2024

Hi @theamytran,

So it sounds like your proposal is something like this?

trait Annihilating[A] {
  def combine(x: A, y: A): A
  def annihilator: A
}

// and then elsewhere
class AnnihilatingForSet[A: Semigroup] extends Annihilating[Set[A]] {
  def combine(x: Set[A], y: Set[A]): Set[A] = x & y
  def annihilator: Set[A] = Set.empty[A]
}

val x = Set(1,2,3)
val y = Set.empty[Int]
AnnihilatingForSet[Int].combine(x, y) // returns Set()

Currently it would be possible to do something similar by defining a Semiring[Set[A]] using empty sets, unions, and intersections (which we currently have: https://github.com/typelevel/algebra/blob/master/core/src/main/scala/algebra/instances/set.scala#L26).

I guess I have a few questions for the group:

  1. Does anyone know of any algorithms or structures that need only multiplication and zero?
  2. How often do people encounter semigroups which can't be monoids but could be annihilators?
  3. Would it make more sense to put this in the semigroup hierarchy or keep it alone?

My 2ยข is that it seems reasonable to add AnnihilatingSemigroup (and AnnihilatingMonoid) if we can think of more use cases that would benefit from having them. The set example is less compelling to me only because we already have Semiring[Set[A]].

from algebra.

theamytran avatar theamytran commented on July 27, 2024

Here's another use case: interval intersection. https://gist.github.com/kenbot/1c37f10cd2ac8de2e988

from algebra.

johnynek avatar johnynek commented on July 27, 2024

IntervalSets can also have Semirings as a note.

@theamytran do you have an algorithm in mind that you would write that uses a annihilation in the abstract?

from algebra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.