armanbilge / schrodinger

Give your cats a set of dice
Apache License 2.0
36 stars 4 forks source link

An anecdote... 😏 #335

Closed benhutchison closed 10 months ago

benhutchison commented 10 months ago

Whoops, somehow using an emoji created the issue prematurely.

Anyway, an anecdote..

In an unpublished project, I have opaque types that model non-negative Integers, Doubles and Decimals.

Initially, I added bespoke operations as extension methods to each, but that got boring fast. So I switched to using Algebra; define surface-syntax in terms of the typeclasses in Typelevel algebra and Spire, and then implement those TCs for my non-negative types. Has proved quite practical, and feels like a much more solid base to go forward upon.

However. It turned out to be far from obvious what algebras to implement for non-negative integral and rational data types. I got as far as Semifield which gave me everything but subtraction. Solving subtraction led me down a fascinating wikipedia rabbit hole and ultimately to the discovery of Monus.

But then I hit another doubt. What algebraic structure models non-negative rationals, in entirety? M-Semiring doesnt include division. Semifield doesn't include monus-subtraction. Is there such thing as a "M-Semifield"? 🤔 💭

Surely the combined mathematical GDP of the world has been able to give name to the algebra of such a ubiquitous class of numbers as the non-negative rationals/reals..? surely..?

And it was in the spirit of doubtful inquiry that I accidentally googled your project, number 2 after wikipedia. "Arman Bilge woz here!"

And sure enough, it does seem like the weight type W in your Resampler is intended to be a non-negative rational.

And that felt like an anecdote worth sharing... :)

benhutchison commented 10 months ago

Actually, can I ask you about your take on Monus?

You extend PartialOrder which is consistent with wikipedia etc. However, IIUC, a partial ordering means that this Monus cannot be a Metric, because if two elements a & b are incomparable, we cant use eg max(monus(a, b), monus(b, a)) to find a distance between them.

We can sensibly define distance between pair of non-negative numbers. In your view, is there a case for an OrderedMonus typeclass, ie Monus+Order, that could also implement eg Spire's MetricSpace[N, N]?