-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3979 from armanbilge/topic/algebra/semifield
Add `Semifield` and `CommutativeSemifield` to algebra
- Loading branch information
Showing
5 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
algebra-core/src/main/scala/algebra/ring/CommutativeSemifield.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package algebra | ||
package ring | ||
|
||
import scala.{specialized => sp} | ||
|
||
/** | ||
* CommutativeSemifield is a Semifield that is commutative under multiplication. | ||
*/ | ||
trait CommutativeSemifield[@sp(Int, Long, Float, Double) A] | ||
extends Any | ||
with Semifield[A] | ||
with CommutativeRig[A] | ||
with MultiplicativeCommutativeGroup[A] | ||
|
||
object CommutativeSemifield | ||
extends AdditiveMonoidFunctions[CommutativeSemifield] | ||
with MultiplicativeGroupFunctions[CommutativeSemifield] { | ||
@inline final def apply[A](implicit r: CommutativeSemifield[A]): CommutativeSemifield[A] = r | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package algebra | ||
package ring | ||
|
||
import scala.{specialized => sp} | ||
|
||
/** | ||
* Semifield consists of: | ||
* | ||
* - a commutative monoid for addition (+) | ||
* - a group for multiplication (*) | ||
* | ||
* Alternately, a Semifield can be thought of as a DivisionRing without an additive inverse. | ||
*/ | ||
trait Semifield[@sp(Int, Long, Float, Double) A] extends Any with Rig[A] with MultiplicativeGroup[A] | ||
|
||
object Semifield extends AdditiveMonoidFunctions[Semifield] with MultiplicativeGroupFunctions[Semifield] { | ||
@inline final def apply[A](implicit ev: Semifield[A]): Semifield[A] = ev | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters