简体   繁体   English

寻找类别对象可部分消耗的类型类(化学工程)

[英]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我要的例子 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.根据预定义的比例将一种物质分离用于 2 个不同过程的转换拆分。

And so on...等等...

Not a function不是 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.如您所见,每个化学过程不仅仅是一个 function,因为它的目标不是“计算”一个值,而是将一定量的某些物质转化为其他物质。

Maybe a Category?也许是一个类别?

This led me to consider categories which generalize the notion of functions.这让我想到了概括函数概念的类别。

class Category cat where -- | class 类别猫在哪里 -- | the identity morphism id:: cat aa恒等态射 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).从 function diag a = (a, a) 您可以看到它能够复制 object(这在化学工程中是不可能的)。

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? Haskell 中的任何有用实现或我可以查找的研究论文?

Linear logic线性逻辑

Using Curry-Howard, perhaps it's easier to find an equivalent logic first and then map to the category.使用Curry-Howard,或许先找一个等价逻辑再找map归类会更简单。 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.这可能是 Linear Haskell 的一个很好的应用程序。GHC 9.0 和更新版本支持LinearHaskell ,它启用线性函数。

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.你的PreCartesian class 太强了。 The class you actually want should abstract only a symmetric monoidal category你真正想要的 class 应该只抽象一个对称的幺半群类别

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. attachUnit ... regroup regroup'是样板,需要它是因为 Haskell 的(,) / ()并不是真正的幺半群。

Alternatively the class could be called Braided , which would also have swap .或者 class 可以称为Braided ,它也有swap The difference is that a symmetric category demands swap. swap ≡ id不同之处在于对称类别需要swap. swap ≡ id swap. swap ≡ id , which does seem reasonable in your case. swap. swap ≡ id ,这在你的情况下似乎是合理的。

In constrained-categories , I called the class that encapsulates these methods Morphism .constrained-categories中,我调用了封装这些方法的 class 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 . (这是一个用词不当;遗憾的是,为了与 Haskell 的标准类保持紧密兼容,我选择了相当糟糕的名称,并且只暗示了数学名称。)您的PreCartesian对应于我的PreArrow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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