<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Jun 4, 2010, at 1:19 AM, Alexander Solla wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>We don't necessarily have to compute the inverse of the distribution via sampling to do it. &nbsp;It can be done algebraically, in terms of the convolution operator. &nbsp;Since the types are enumerated, wouldn't something like... work?</div><div><br></div><div><font class="Apple-style-span" face="Courier" size="3"><span class="Apple-style-span" style="font-size: 12px;">-- A set and binary operation. &nbsp;We have an algebra. &nbsp;I like the J for 'join'.</span></font></div><div><font class="Apple-style-span" face="Courier">-- With this algebra, we can use the real-complex analytical methods to</font></div><div><font class="Apple-style-span" face="Courier">-- interpret the terms later, if we want to actually reify a Distribution</font></div><div><span class="Apple-style-span" style="font-family: Courier; ">-- instance as a "Real" (Float, Double) function.</span></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier" size="3"><span class="Apple-style-span" style="font-size: 12px;">&gt; data DistributionJ a = UniformDistribution Uniform a</span></font></div><div><font class="Apple-style-span" face="Courier" size="3"><span class="Apple-style-span" style="font-size: 12px;">&gt;</span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="Courier" size="3"><span class="Apple-style-span" style="font-size: 12px;">                       | ...</span></font></span></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="Courier" size="3"><span class="Apple-style-span" style="font-size: 12px;">&gt;<span class="Apple-tab-span" style="white-space:pre">        </span>               | ExponentialDistribution Exponential a</span></font></span></div><div><font class="Apple-style-span" face="Courier"><span class="Apple-style-span" style="white-space: pre;">&gt;<span class="Apple-tab-span" style="white-space:pre">                </span>       | DistributionJ a `Convolve` (DistributionJ a)</span></font></div><div><font class="Apple-style-span" face="Courier"><span class="Apple-style-span" style="white-space: pre;"><br></span></font></div><div><font class="Apple-style-span" face="Courier"><span class="Apple-style-span" style="white-space: pre;"><br></span></font></div><div><font class="Apple-style-span" face="Courier"><span class="Apple-style-span" style="white-space: pre;">-- I hope I understand the semantics for the PromptT monad.</span></font></div><div><font class="Apple-style-span" face="Courier"><span class="Apple-style-span" style="white-space: pre;">&gt; newtype RVarT m a = RVarT { unRVarT :: PromptT (Prim, DistributionJ) m a }</span></font></div><div><font class="Apple-style-span" face="Courier"><span class="Apple-style-span" style="white-space: pre;"><br></span></font></div><div><span class="Apple-style-span" style="white-space: pre;"><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">I guess threading fst and snd in all the low level computations is inelegant, but it's a step closer.</span></font></span></div></div></blockquote></div><br><div>An algebraic solution would work as long as the user only made use of a very small set of supported operations. &nbsp;Unfortunately, even detecting whether they have done so in any implementation supporting Monad is not really feasible. &nbsp;The Functor/Applicative/Monad classes allow inclusion of arbitrary functions in the construction of an RVar, which is a very big part of the usefulness of the system. &nbsp;Even in a simple no-op defininion such as "fmap id x", fmap has no way of discovering whether the function is "id", "negate", "primes !!", or worse, so the only way (I believe) to effectively propagate the algebraic part would be to drop the Functor, Applicative and Monad instances and work with RVars solely via some combinator library. &nbsp;At that point, why not just work with the symbolic form directly and choose at the end whether to sample or compute a pdf? &nbsp;You could make DistributionJ an instance of Distribution to make it sampleable, and do precisely that. &nbsp;In fact, that would probably be a pretty nifty thing to do.</div><div><br></div><div>-- James</div><div><br></div><div>PS - the usage of DistributionJ in the prompt wouldn't quite work, because a "DistributionJ a" would just be a standin for a computation of type "m a" where "m" is the monad in which the variable is eventually sampled. &nbsp;There is no way to rediscover the particular constructor that was used for the prompt, for approximately the same reasons as above.</div></body></html>