寻找类别对象部分可消耗的类型类(化学工程)
问题
我希望描述化学工程中将某些物质转化为其他物质的过程。是否有一个类别描述消耗“物质”的态射?
我想要建模的示例
举一些例子:
将两种物质组合成混合物的转换混合物。
将物质煮沸成一些副产品的转化沸腾。
一种转换拆分,根据预定义的比例将物质分离以用于 2 个不同的过程。
依此类推...
不是函数
正如您所看到的,每个化学过程不仅仅是一个函数,因为它的目标不是“计算”一个值,而是将一定数量的某些物质转化为其他的。
也许是一个类别?
这让我考虑概括函数概念的类别。
类别类别猫在哪里 --|恒等态射 id :: cat aa
-- | morphism composition
(.) :: cat b c -> cat a b -> cat a c
从概念上讲,这是可行的,因为化学过程可以完全以这种方式组合。
更具体的类别
我知道有更具体的类别实例可以编码更多的抽象(例如,笛卡尔类别)。笛卡尔类别引入产品:
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
但是,存在一个问题。从概念上讲,笛卡尔范畴中的态射“计算”而不是“消耗”它们的对象。从函数 diag a = (a, a) 中您可以看到它能够复制对象(这在化学工程中是不可能的)。
似乎大多数类别类型类处理“计算”而不是“消耗”。
消耗类别?
是否有任何类别描述消耗其对象的态射?我可以寻找 Haskell 中任何有用的实现或研究论文吗?
线性逻辑
使用 Curry-Howard,也许首先找到等效逻辑然后映射到类别会更容易。我偶然发现了线性逻辑,这似乎有帮助:
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 a a
-- | 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 (e.g., 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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可能是 Linear Haskell 的一个很好的应用! GHC 9.0 及更高版本支持支持线性函数的 LinearHaskell。
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?
您的
PreCartesian
类太强大了。您真正想要的类应该仅抽象 对称幺半群类别attachUnit
...regroup'
是样板文件,需要它是因为 Haskell 的(,)
/()
并不是真正的幺半群。或者,该类可以称为
Braided
,其中也有swap
。不同之处在于对称类别需要 swap 。 swap == id,这在你的情况下似乎是合理的。在
constrained-categories
中,我调用了封装这些方法的类Morphism
。 (这是一个用词不当;遗憾的是,我在误导性的努力中选择了相当糟糕的名称,以保持与 Haskell 的标准类的紧密兼容性,并且仅暗示数学名称。)您的PreCartesian
对应于我的PreArrow
。Your
PreCartesian
class is too strong. The class you actually want should abstract only a symmetric monoidal categoryattachUnit
...regroup'
are boilerplates, needed because Haskell's(,)
/()
isn't really a monoid.Alternatively the class could be called
Braided
, which would also haveswap
. The difference is that a symmetric category demandsswap . swap ≡ id
, which does seem reasonable in your case.In
constrained-categories
, I called the class that encapsulates these methodsMorphism
. (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.) YourPreCartesian
corresponds to myPreArrow
.