简体   繁体   中英

Looking for a typeclass where category objects are partially consumable (chemical engineering)

Question

I'm looking to describe processes in chemical engineering that that transmute some substances into others. Is there a category that describes morphisms that consume "substances"?

Examples of what I would like to model

To give some examples:

A transformation mix that combines two substances into a mixture.

A transformation boil that boils a substance into some byproducts.

A transformation split that separates a substance to be used in 2 different processes according to a pre-defined proportion.

And so on...

Not a function

As you can see, each chemical process is not merely a function, since its goal is not to "compute" a value but to translate some amounts of certain substances into others.

Maybe a Category?

This led me to consider categories which generalize the notion of functions.

class Category cat where -- | the identity morphism id:: cat aa

-- | morphism composition
(.) :: cat b c -> cat a b -> cat a c

Conceptually this works since chemical processes are composable exactly in this way.

More specific Category

I know there are more specific instances of categories that encode more abstractions (eg, Cartesian categories). A Cartesian category introduces products:

instance PreCartesian Hask (,) where
    fst = Prelude.fst
    snd = Prelude.snd
    diag a = (a,a)
    (f &&& g) a = (f a, g a)

-- alias
class (Monoidal k p i, PreCartesian k p) => Cartesian k p i | k -> p i 
instance (Monoidal k p i, PreCartesian k p) => Cartesian k p i

However, there is an issue. Conceptually, morphisms in Cartesian categories "compute with" rather than "consume" their objects. From the function diag a = (a, a) you can see that it's able to duplicate the object (this is not be possible in chemical engineering).

It seems like most category typeclasses deal with "computation" rather than "consumption".

Consumable Categories?

Are there any categories which describe morphisms that consume their objects? Any useful implementations in Haskell or research papers that I could look for?

Linear logic

Using Curry-Howard, perhaps it's easier to find an equivalent logic first and then map to the category. I stumbled on linear logic which seems to help:

more about linear logic

This could be a nice application of Linear Haskell. GHC 9.0 and newer supports the LinearHaskell , which enable linear functions.

There's certainly prior art in the use of linear logic for reaction modelling .

If multiple reactants can combine, maybe what you're looking for is an operad, rather than a category.

Is there any particular reason why multisets don't suffice as a basic representation?

Your PreCartesian class is too strong. The class you actually want should abstract only a symmetric monoidal category

class Category k where   id :: k a a
                         (.) :: k b c -> k a b -> k a c
class=>Monoidal k where  attachUnit :: k a (a,())
                         detachUnit :: k (a,()) a
                         regroup :: k (a, (b, c)) ((a, b), c)
                         regroup' :: k ((a, b), c) (a, (b, c))
                         (***) :: k a b -> k α β -> k (a,α) (b,β)
class=>Symmetric k where swap :: k (a,b) (b,a)

attachUnit ... regroup' are boilerplates, needed because Haskell's (,) / () isn't really a monoid.

Alternatively the class could be called Braided , which would also have swap . The difference is that a symmetric category demands swap. swap ≡ id swap. swap ≡ id , which does seem reasonable in your case.

In constrained-categories , I called the class that encapsulates these methods Morphism . (Which is quite a misnomer; regrettably, I chose the names rather poorly in a misguided effort to keep close compatibility with Haskell's standard classes and only hint at the mathematical names.) Your PreCartesian corresponds to my PreArrow .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM