Comments on: Free Modules and Functional Linear Functionals http://comonad.com/reader/2011/free-modules-and-functional-linear-functionals/ types, (co)monads, substructural logic Sat, 29 Dec 2012 15:18:06 -0800 http://wordpress.org/?v=2.8.4 hourly 1 By: Edward Kmett http://comonad.com/reader/2011/free-modules-and-functional-linear-functionals/comment-page-1/#comment-64236 Edward Kmett Tue, 12 Jul 2011 14:21:32 +0000 http://comonad.com/reader/?p=356#comment-64236 @beroal: i didn't make them symbolic because they have the problem that what do you name the three different operators for ((N+1)*), (N*) and (Z*) ? whereas the precedent of log1p at least gives some intuition to the name replicate1p, and the action of replicate on lists if the repetition of a monoidal value. I had, however originally started using (#*) and (*#) for times and may revert. They are mostly provided as reasonable default implementations for the natural number multiplication and integer multiplication requirements placed on you by the module superclasses. As for the free module, technically I'm permitting the infinite free module. Haskell provides me a largely coinductive universe, I'd be remiss in not taking advantage of it. I'll throw an (infinite) in there. ;) But unlike the classical case I can't prove the duality in most cases to begin with and I'm not able to enumerate the set of all e in E such that E -> R is non-zero except when the set E is finitely enumerable itself, because I can't intensionally inspect the function I'm given. Effectively the constraint moves from requiring the function to have a finite number of non-zeros to requiring that any linear functional can only inspect a finite number of vectors, which being constructive is all it can do anyways. The invariant in question is linearity. One (potentially conservative) way to enforce that would be to never apply our continuation vector twice and take the product of the results (or add it to some value in the ring), but instead only multiply it by values we have lying around in the ring or add and subtract them. If you think about it, quantifying over the choice of a module then prevents violations of linearity. \k -> r .* f k is well typed, we can plumb in zeroes, etc, but \k -> f k * f k requires our module be strengthened to a semiring, and the unmentioned but also non-linear \k -> f k + r also would fail to type check, since f k :: m, and under quantification over the module all we're permitted to do is use the (.*) and the (+) from our module. the reason this is a problem is if you want to use the zero from a semigroup-with-zero module, you'd need a new type. There is also a performance impact from the fact that we effectively use the LeftModule dictionary as an interpreter, and most damningly it costs us the ability to use representable-tries for cheap memoization. @beroal: i didn’t make them symbolic because they have the problem that what do you name the three different operators for ((N+1)*), (N*) and (Z*) ?

whereas the precedent of log1p at least gives some intuition to the name replicate1p, and the action of replicate on lists if the repetition of a monoidal value. I had, however originally started using (#*) and (*#) for times and may revert. They are mostly provided as reasonable default implementations for the natural number multiplication and integer multiplication requirements placed on you by the module superclasses.

As for the free module, technically I’m permitting the infinite free module. Haskell provides me a largely coinductive universe, I’d be remiss in not taking advantage of it. I’ll throw an (infinite) in there. ;) But unlike the classical case I can’t prove the duality in most cases to begin with and I’m not able to enumerate the set of all e in E such that E -> R is non-zero except when the set E is finitely enumerable itself, because I can’t intensionally inspect the function I’m given. Effectively the constraint moves from requiring the function to have a finite number of non-zeros to requiring that any linear functional can only inspect a finite number of vectors, which being constructive is all it can do anyways.

The invariant in question is linearity. One (potentially conservative) way to enforce that would be to never apply our continuation vector twice and take the product of the results (or add it to some value in the ring), but instead only multiply it by values we have lying around in the ring or add and subtract them. If you think about it, quantifying over the choice of a module then prevents violations of linearity. \k -> r .* f k is well typed, we can plumb in zeroes, etc, but \k -> f k * f k requires our module be strengthened to a semiring, and the unmentioned but also non-linear \k -> f k + r also would fail to type check, since f k :: m, and under quantification over the module all we’re permitted to do is use the (.*) and the (+) from our module. the reason this is a problem is if you want to use the zero from a semigroup-with-zero module, you’d need a new type.

There is also a performance impact from the fact that we effectively use the LeftModule dictionary as an interpreter, and most damningly it costs us the ability to use representable-tries for cheap memoization.

]]>
By: Mathnerd314 http://comonad.com/reader/2011/free-modules-and-functional-linear-functionals/comment-page-1/#comment-64233 Mathnerd314 Tue, 12 Jul 2011 13:57:33 +0000 http://comonad.com/reader/?p=356#comment-64233 Oops, sorry. I meant nonassociative rings. But I guess you do have to draw the line somewhere. Oops, sorry. I meant nonassociative rings. But I guess you do have to draw the line somewhere.

]]>
By: beroal http://comonad.com/reader/2011/free-modules-and-functional-linear-functionals/comment-page-1/#comment-64213 beroal Tue, 12 Jul 2011 11:49:48 +0000 http://comonad.com/reader/?p=356#comment-64213 <em>We could capture this invariant in the type by saying that instead we want</em> Can you please explain what “invariant” you are talking about? We could capture this invariant in the type by saying that instead we want
Can you please explain what “invariant” you are talking about?

]]>
By: beroal http://comonad.com/reader/2011/free-modules-and-functional-linear-functionals/comment-page-1/#comment-64208 beroal Tue, 12 Jul 2011 11:40:05 +0000 http://comonad.com/reader/?p=356#comment-64208 <em>If we limit our discussion to free modules, then M = E -> R</em> And every element of M should be 0 on all but finite set of elements of E. This is the definition of free modules. If we limit our discussion to free modules, then M = E -> R
And every element of M should be 0 on all but finite set of elements of E. This is the definition of free modules.

]]>
By: beroal http://comonad.com/reader/2011/free-modules-and-functional-linear-functionals/comment-page-1/#comment-64199 beroal Tue, 12 Jul 2011 10:48:18 +0000 http://comonad.com/reader/?p=356#comment-64199 I suppose that “replicate1p” and “pow1p” both define repetition. IMHO you can name them with “+” and “*”, adding some symbol to denote repetition, maybe “...”? (And with the right order of arguments in “pow1p”. :) ) I suppose that “replicate1p” and “pow1p” both define repetition. IMHO you can name them with “+” and “*”, adding some symbol to denote repetition, maybe “…”? (And with the right order of arguments in “pow1p”. :) )

]]>
By: Edward Kmett http://comonad.com/reader/2011/free-modules-and-functional-linear-functionals/comment-page-1/#comment-64180 Edward Kmett Tue, 12 Jul 2011 08:46:52 +0000 http://comonad.com/reader/?p=356#comment-64180 This is what I get for trying to nod to the fact that different authors use the same words for different things. The vocabulary I'm working with here is that a semiring is a pair of semigroups with a pair of distributive laws and that a rig adds a 0 and 1 to a semiring. Some authors call what I am calling a rig above a semiring, which is somewhat annoying because the semi- just means 'not-quite' in this setting, and has no connection to the relationship between group and semigroup. Moreover it leaves the question of what to call the pair-of-semigroups construction that I'm calling semiring above. The name those authors often use is "ringoid", but that conflicts with the much more useful use of ringoid for referring to Ab-enriched categories, which is likely to wind up in my semigroupoid package. If a group is a groupoid with one object then a ringoid is a ringoid with one object. So in the vocabuary I'm using here, we get: Semiring <= Rig <= Ring which parallels Semigroup <= Monoid <= Group by adding unit(s) and additive inverses respectively. I'll see if I can clear up the verbage to make it clearer. This is what I get for trying to nod to the fact that different authors use the same words for different things.

The vocabulary I’m working with here is that a semiring is a pair of semigroups with a pair of distributive laws and that a rig adds a 0 and 1 to a semiring.

Some authors call what I am calling a rig above a semiring, which is somewhat annoying because the semi- just means ‘not-quite’ in this setting, and has no connection to the relationship between group and semigroup. Moreover it leaves the question of what to call the pair-of-semigroups construction that I’m calling semiring above. The name those authors often use is “ringoid”, but that conflicts with the much more useful use of ringoid for referring to Ab-enriched categories, which is likely to wind up in my semigroupoid package.

If a group is a groupoid with one object then a ringoid is a ringoid with one object.

So in the vocabuary I’m using here, we get:

Semiring <= Rig <= Ring

which parallels

Semigroup <= Monoid <= Group

by adding unit(s) and additive inverses respectively.

I’ll see if I can clear up the verbage to make it clearer.

]]>
By: Paul Keir http://comonad.com/reader/2011/free-modules-and-functional-linear-functionals/comment-page-1/#comment-64175 Paul Keir Tue, 12 Jul 2011 08:07:35 +0000 http://comonad.com/reader/?p=356#comment-64175 You say "If we get rid of the additive and multiplicative unit on our Rig we get down to what some authors call a Ringoid, but which we'll call a Semiring", but earlier you "...go to a Rig (often called a Semiring)". Are both of them Semirings? You say “If we get rid of the additive and multiplicative unit on our Rig we get down to what some authors call a Ringoid, but which we’ll call a Semiring”, but earlier you “…go to a Rig (often called a Semiring)”. Are both of them Semirings?

]]>
By: Edward Kmett http://comonad.com/reader/2011/free-modules-and-functional-linear-functionals/comment-page-1/#comment-64100 Edward Kmett Tue, 12 Jul 2011 03:19:47 +0000 http://comonad.com/reader/?p=356#comment-64100 Without commutative addition, you don't get many normalization opportunities. So, in the interest of drawing the line somewhere I left that off. ;) I also avoided talking about left-seminnearings and right-seminearrings. =) I do enjoy playing with the individual grains of sand in my sandbox though. Without commutative addition, you don’t get many normalization opportunities. So, in the interest of drawing the line somewhere I left that off. ;) I also avoided talking about left-seminnearings and right-seminearrings. =) I do enjoy playing with the individual grains of sand in my sandbox though.

]]>
By: Mathnerd314 http://comonad.com/reader/2011/free-modules-and-functional-linear-functionals/comment-page-1/#comment-64094 Mathnerd314 Tue, 12 Jul 2011 02:48:03 +0000 http://comonad.com/reader/?p=356#comment-64094 Your Multiplicative class seems to ignore the existence of noncommutative (semi)rings; surely this important area of mathematics shouldn't be left out? Your Multiplicative class seems to ignore the existence of noncommutative (semi)rings; surely this important area of mathematics shouldn’t be left out?

]]>