-
Notifications
You must be signed in to change notification settings - Fork 243
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
Partial algebras. #341
Partial algebras. #341
Conversation
Renamed the Action syntax classes accordingly instead of GroupOps, PointOps. Added PartialAction implementation, with both Option-like and PartialFunction-like semantics. Added implementation of Semigroupoid, PartialMonoid, Groupoid. Added syntax for partial operations, with both Option-like and PartialFunction-like semantics.
Note: I haven't yet ported the tests (especially the relevant laws) to Spire. In particular, I'd like a review of the naming scheme (Semigroupoid, PartialMonoid, Groupoid) from people who already have a feet in category theory. In particular, even if a PartialMonoid looks very much like a Category, I want to avoid the C-word who has already countless usages. Last note: As discussed in #337, even the goal is not to define in Spire all algebraic structures known under the sun, the partial algebraic structures are needed because Group should inherit from Groupoid, and not the other way around --- which prevents moving Groupoid into an extra library. Usage examples:
|
…o the full algebra on Option[A]. Useful for tests.
Laws have been defined for partial algebras and actions. All these laws are under the existing GroupLaws and ActionLaws hierarchy, to enable mix'n'match: i.e. |
Awesome! I'm sorry I haven't had more time to comment on all this work -- there have been a lot of things going on. It seems promising, and I will dig in and give concrete feedback as soon as I can. Thanks for working on this. |
@non: no worries, I have my own local snapshot for now. To advance the discussion, do you have in mind concrete examples of partial algebras/actions, that could be provided in Spire, either in spire.std or spire.optional, or in test cases ? For now, I'm thinking of Semigroupoid[Seq[A]], PartialMonoid[Seq[A]], Groupoid[Seq[A]] given A: Semigroup/Monoid/Group, where the partial operation is defined only on sequences with compatible sizes. There is also the groupoid of invertible matrices, where matrices of the same size are compatible, but we probably do not want to go down that path (i.e. define partial rings, and so on). There is also the pedagogical example of the 15 puzzle: https://cornellmath.wordpress.com/2008/01/27/puzzles-groups-and-groupoids/ For partial actions, there is of course the action of a permutation on a Seq, where the Seq has to have a compatible size. |
…eption Replace some sys.errors with proper exceptions.
Hi @denisrosset, I'm going to get an 0.9.0 release out, (mostly to get your interval bug fixes and improvements released) and then my next plan is to get this stuff merged. I'm hoping to do it this week while I'm on vacation. |
There is still a lot of work to be done making the documentation more complete, up-to-date, and useful. But this commit is a start, and adds the credits and changes for the newest relese.
Hi @non, I'd like to release my alasc library for finite groups, and my project depends on Groupoid and PartialAction. Any chance you'd accept a reduced version of this PR for 0.9.0? otherwise, of course, I can live with a local SNAPSHOT. I'm thinking of:
and Both objects (partial actions and groupoids) have unambiguous names and clear laws stated in the mathematical litterature --- this is not the case for This would imply minimal changes to the syntax and laws packages. We could then discuss for a future release:
What do you think ? |
So, I did already release 0.9.0. But I am willing to merge this quickly and do an 0.9.1 release too. I think we can get it out before 2015. |
OK, thanks! I see that 0.9.0 is out, so there is no hurry. Let's identify the parts that are uncontroversial from the ones that require discussion, and I'll be happy to split to PR in several pieces. I'd like to see a 0.9.1 release after the steps 1 (and 2?) below, because they introduce new super traits for Action and Group: Step 1: We can discuss quickly (there is not much wiggle room in implementation/naming these):
Step 2: Check that the following are meaningful:
Step 3: Brainstorm around
|
I think the design (point #1) seems good. The biggest questions I have are around what symbolic operators we should use. If we try to hit all possible combinations I worry we will "use up" the design space, and also end up with really cumbersome symbols. |
As far as which instances Spire should provide, I think we can be minimal here. One of the advantages of a shared type class is that it lets other libraries decide which instances are meaningful and implement them. They can always pass the types and instances back upstream if they are very useful generally. |
Also, as we get more and more algebras, I'm trying to do a better job of partitioning the With that in mind, I think it would make sense to put these into |
Operators: Right now it looks like we will be adding:
What do you think @tixxit? |
Regarding: |
Let's put them in |
Okay, right, that totally makes sense. Given that usage, how would you feel about just using |
I'm ok with merging Then |
So in the other bug you said you were favoring only definining If we introduce something like What do you think? |
I agree completely with you for spire. Still, I'm favoring methods that are not bound to a particular How could we reconcile the two ? should we have a minimalistic partial algebra trait in non/algebra, and a more complete one Spire, with an isInstanceOf check in Spire's extended syntax ? |
I'm writing a proposal right in this PR (for simplicity, I will not submit a PR to algebra). |
That sounds good. Thanks again for bearing with us on all of this. |
The split is done; in the code, the traits that do not use For consistency, I redefined the partial operators to be I'm still undecided for the implementation of the
The only drawback is the explosion of (specialized) classes. The Then, we would have the following operators:
Instead of an implicit conversion in 3., we could also implement a special macro with an |
@non, you asked for examples, have a look at the law checking code: |
Actually, should we be more consistent in naming the partial methods, by having both |
Tests with YourKit Java Profiler indicate that the following code (when a generic import spire.algebra._
import spire.syntax.all._
implicit object SeqIntGroupoid extends Groupoid[Seq[Int]] {
def inverse(a: Seq[Int]) = a.map(-_)
def opIsDefined(f: Seq[Int], g: Seq[Int]) = f.size == g.size
def op(f: Seq[Int], g: Seq[Int]) = Seq.tabulate(f.size)(i => f(i) + g(i))
}
for (i <- 1 to 100000) (Seq(1,2,3) |+|? Seq(4,5,6)).getOrElseFast(Seq.empty[Int]) does not allocate |
Note that I'm triggering a bug in the 2.10 compiler with the enrichment, because of the value class return type; the CI will be not passing for 2.10. This is probably a variant of https://issues.scala-lang.org/browse/SI-8702 . |
@non : I see that a lot of work is being done on non/algebra, I will have a look at it. This can wait until the work there is finished. |
Yeah sorry I haven't been more responsive. I'm definitely giving it some thought. |
One note to add: if we are willing to not require What do you think about this? @tixxit? |
We could also use inheritance the other way around, e.g. have partial algebras inherit the regular ones --- this is actually what is done in We would thus remove the Nullbox / non-Nullbox distinction and use Nullbox everywhere. There would be an implicit wrapper for the regular algebras used partially, so a small overhead --- except if we can write a macro that generates a I am waiting for @tixxit before making a move. |
I would prefer to avoid inheriting in that direction -- the |
Split Action into LeftAction and RightAction.
Renamed the Action syntax classes accordingly instead of GroupOps, PointOps.
Added PartialAction implementation, with both Option-like and PartialFunction-like semantics.
Added implementation of Semigroupoid, PartialMonoid, Groupoid.
Added syntax for partial operations, with both Option-like and PartialFunction-like semantics.