线性代数的本质_本质代数

线性代数的本质

Let’s start with a question, in the list of five objects [red, rEd, rED, green, GREEN], which pairs of objects are equal? Most would say that “red” is not equal to “green”, but there may be debate on whether “red” is equal to “rED”. Can we settle the debate? In this case, one approach would be to consider two “equivalence classes”

让我们从一个问题开始,在五个对象(红色,rEd,rED,绿色,绿色)的列表中,哪些对象对相等? 大多数人会说“红色”不等于“绿色”,但是关于“红色”是否等于“ rED”可能存在争议。 我们可以解决辩论吗? 在这种情况下,一种方法是考虑两个“等价类”

  1. [red, rEd, rED]

    [红色,红色,红色]
  2. [green, GREEN]

    [绿色,绿色]

where two objects are considered equal if and only if they are in the same equivalence class. This yields a precise, crisp notion of equality.

当且仅当两个对象在同一个等效类中时,才将它们视为相等。 这产生了精确,清晰的平等概念。

There are a lot of applications where only the equivalence class of an object “matters”, and the particular object does not. However, it is often quite hard to directly represent the equivalence class in a computer, and it instead must be represented as a particular object of that class. We might notice that despite this limitation, we can often still make useful progress.

在许多应用程序中,仅对象的等价类“重要”,而特定对象则没有。 但是,通常很难直接在计算机中表示等效类,而必须将其表示为该类的特定对象。 我们可能会注意到,尽管有此限制,但我们通常仍可以取得有益的进步。

For example, these objects could be concrete representations of computer programs (e.g. source code), and the equivalence classes are behaviors of the program (note a well-engineered compiler preserves the equivalence class through various transformations). The objects could be mathematical expressions, and the equivalence classes the logical or algebraic “statements” which those expressions represent. Often we desire to manipulate an expression such that its “meaning” is preserved.

例如,这些对象可以是计算机程序(例如源代码)的具体表示,而等价类是程序的行为(请注意,精心设计的编译器会通过各种转换来保留等价类)。 对象可以是数学表达式,而等价类则是这些表达式表示的逻辑或代数“陈述”。 通常,我们希望对表达式进行操作,以保留其“含义”。

Notably, we don’t need to stop in the realm of math or programming objects. The objects under discussion can be quite abstract, and might represent a large variety of things, for example they could represent color, shape, texture, sound, etc. (try to think of equivalence classes for these, you will often find that you are able to do so easily). Given that there are so many different types of objects and equivalence classes, it might seem like a hopeless task to say anything in general about these systems. But surprisingly, it seems some progress can made, which is the topic of this post.

值得注意的是,我们不需要停在数学或编程对象领域。 所讨论的对象可能非常抽象,可能代表各种各样的事物,例如,它们可能代表颜色,形状,纹理,声音等。(尝试考虑这些事物的等效类,您通常会发现自己是能够轻松做到)。 鉴于对象和等效类的类型如此之多,对这些系统进行一般性的论述似乎是一项绝望的任务。 但是令人惊讶的是,似乎可以取得一些进展,这是本文的主题。

取得进步:本质与表达 (Making Progress: Essences and Expressions)

We will now give special, technical names to the objects and equivalence classes described above. Namely, an equivalence class will be referred to as an “essence”, and an object will be referred to as an “expression”.

现在,我们将为上述对象和等效类提供特殊的技术名称。 即,将等价类称为“本质”,将对象称为“表达式”。

Now we’re ready to define the framework of “essence algebras”. In, ahem, essence:

现在我们准备定义“本质代数”的框架。 在本质上:

Definition: An essence algebra is a set of “essences” and a set of “expressions”, where each expression has exactly one essence.

定义:本质代数是一组“要素”和一组“表达式”,其中每个表达式恰好具有一个本质。

Here are some typical additional things we can attach to essence algebras:

这是我们可以附加到本质代数的一些典型附加事物:

  1. Essence operators. These input one or more essences, and output another essence.

    精华算子。 这些输入一个或多个要素,而输出另一个要素。
  2. A simplification operator. This inputs an expression, and outputs another expression with the same essence as the input.

    简化运算符。 这将输入一个表达式,然后输出与输入实质相同的另一个表达式。
  3. External operators. These input an essence, and output some arbitrary value.

    外部运营商。 这些输入本质,并输出一些任意值。

The key motivation for essence algebras is that we can often productively manipulate expressions to say things about essences without ever “writing down” those essences. Specifically, we can often compute external operators directly on expressions, bypassing the conversion into an essence. The simplification operator facilitates this process by making the input expression more computationally tractable.

本质代数的主要动机是,我们经常可以有效率地操纵表达式来表达关于本质的事情,而无需“写下”这些本质。 具体来说,我们通常可以直接在表达式上直接计算外部运算符,而无需将转换转换为本质。 简化运算符通过使输入表达式在计算上更易于处理来简化此过程。

Some notes. Sometimes what I’m calling an essence might be called a “value” by others. I’m choosing to call it something different to avoid confusion with values which are assigned to variables in many examples of essence algebras (which are _not_ the same thing as an essence), and to emphasize the fact that an essence is typically “more complicated” than a value.

一些注意事项。 有时我所说的本质可能被其他人称为“价值”。 我选择将其称为不同名称,以避免在许多本质代数示例(与本质不相同)中混淆分配给变量的值,并强调这样一个事实,即本质通常“更复杂”比值。

The concept of an essence is also quite similar to the concept of a “type” in programming language theory. However, an essence tends to be much more specific than a type; a typical type might be “integer”, and a typical essence might be “a function that returns its argument squared” (although some higher-order type theories may get closer to the notion of essence). In fact, it appears that simple type systems can be expressed as essence algebras, making essence algebras the more general notion (experts, please comment!).

本质的概念也与编程语言理论中的“类型”概念非常相似。 但是,本质往往比类型更具体。 典型的类型可能是“整数”,典型的本质可能是“返回其参数平方的函数”(尽管某些高阶类型理论可能更接近本质的概念)。 实际上,似乎简单类型系统可以表示为本质代数,使本质代数成为更笼统的概念(专家,请发表评论!)。

Up until this point, this definition might seem extremely vague, general, and useless. Let’s look at some concrete examples of essence algebras.

到现在为止,这个定义似乎非常模糊,笼统和无用。 让我们看一下本质代数的一些具体示例。

整数算术 (Integer Arithmetic)

Basic operations on integers. Note: This is not full arithmetic. It’s a stripped-down version containing only addition and multiplication for simplicity’s sake.

整数的基本运算。 注意:这不是完整的算法。 为简化起见,它是精简版本,仅包含加法和乘法。

Essences: All integers. E.g., -2, -1, 0, 1, 2, etc.

本质:所有整数。 例如-2,-1、0、1、2等。

Expressions: The set of objects produced by the following formal grammar:

表达式:以下形式语法产生的对象集:

An expression is one of:

表达式是以下之一:

  1. Primitive (i.e., just an integer)

    原始的(即,只是一个整数)
  2. (Expression + Expression)

    (表情+表情)
  3. (Expression * Expression)

    (表情*表情)

Example expressions: 1, 5, 1+3, 2 * 4, (2 + (4 * 5)), etc.

示例表达式:1、5、1 + 3、2 * 4,(2 +(4 * 5))等

Essence operators: Addition and multiplication.

本质运算符:加法和乘法。

Simplification operator: Function which “evaluates” an expression. E.g., given the expression 1+1, it returns the primitive 2. Here, it’s trivial to write a program that can evaluate any (finite) expression into a primitive integer.

简化运算符:“评估”表达式的函数。 例如,给定表达式1 + 1,它将返回原语2。在这里,编写可以将任何(有限)表达式求值为原语整数的程序都是很简单的。

External operators: Nothing too interesting here, but a trivial one would be getting the integer value of an essence in some external integer representation, e.g. 64-bit signed integer.

外部运算符:这里没有什么太有趣的,但是琐碎的运算符将以某种外部整数表示形式(例如64位有符号整数)获取要素的整数值。

Ok, that was a neat simple example. What else can we do?

好的,这是一个简单的示例。 我们还能做什么?

Let’s move to high school and do some (elementary) algebra.

让我们上高中,做一些(基础)代数。

实变量上的符号表达式 (Symbolic Expressions Over Real Variables)

These are a bit difficult to define in prose, but they roughly correspond to the types of symbolic objects manipulated by high school students during an elementary algebra or calculus class. Let’s look at how to frame them in an essence algebra.

这些在散文中很难定义,但它们大致对应于高中学生在基础代数或微积分课上操纵的符号对象的类型。 让我们看看如何在本质代数中构建它们。

Essences: Mappings of all assignments of variables to some output type. Example essences:

本质:所有变量分配到某种输出类型的映射。 本质示例:

  1. f(x): real -> real := x + 1

    f(x):实->实:= x + 1
  2. f(x): real -> bool := (x == 3)

    f(x):实-> bool:=(x == 3)
  3. f(x, y): (real, real) -> real := x * y + 4

    f(x,y):(实数,实数)->实数:= x * y + 4

Expressions: the set of objects produced by the following formal grammar:

表达式:由以下形式语法产生的一组对象:

An expression is one of:

表达式是以下之一:

  1. Primitive real number (e.g. 1)

    原始实数(例如1)
  2. Variable (e.g. x)

    变量(例如x)
  3. (Expression + Expression)

    (表情+表情)
  4. (Expression * Expression)

    (表情*表情)
  5. (Expression == Expression) (equality)

    (表达式==表达式)(相等)
  6. AND(Expression, Expression) (logical conjunction)

    AND(表达式,表达式)(逻辑合取)
  7. OR(Expression, Expression) (logical disjunction)

    或(表达,表达)(逻辑析取)

Note: there are ignored type issues (e.g. AND of two integers makes no sense) which are unimportant for the current discussion, but can be solved in a few ways, e.g. by being more careful about the formal grammar definition (introducing a BooleanExpression etc), or introducing a TypeError result type.

注意:存在被忽略的类型问题(例如,两个整数的AND毫无意义),这对于当前的讨论而言并不重要,但是可以通过几种方式解决,例如,通过更加注意形式语法定义(引入BooleanExpression等) ,或引入TypeError结果类型。

Essence operators: We won’t focus on them, but they exist.

精华算子:我们不会专注于它们,但它们确实存在。

Simplification operator: There are many choices here, but the general flavor is that they can do “expression simplification” as a typical high school student might. Example, given the expression 1 + x + 2, the simplification operator might output the expression x + 3. Note the essence of the expression is precisely preserved (i.e., for all possible values of x, the result of the expression is the same real number. Strictly speaking, we need some entity that reduces the substituted expressions into a final real number to prove that this is the case (e.g. reducing (1 + 4 + 2) into 7, but we’ll ignore this detail)). The other typical property of the simplification operator is that the complexity of the expression is reduced (typically meaning that we need less symbols and levels of nesting to represent the same essence). Here, we went from “1 + x + 2” (5 symbols) to “x + 3” (3 symbols), an improvement of 2 symbols.

简化运算符:这里有很多选择,但是总的来说,他们可以像典型的高中生那样进行“表情简化”。 例如,给定表达式1 + x + 2,简化运算符可能会输出表达式x +3。请注意,表达式的本质已精确保留(即,对于x的所有可能值,表达式的结果都是相同的实数。严格来说,我们需要一些实体来将替换表达式简化为最终的实数,以证明是这种情况(例如将(1 + 4 + 2)简化为7,但我们将忽略此细节)。 简化运算符的另一个典型属性是表达式的复杂度降低了(通常意味着我们需要更少的符号和嵌套级别来表示相同的本质)。 在这里,我们从“ 1 + x + 2”(5个符号)变为“ x + 3”(3个符号),改进了2个符号。

External operators: There are a lot of possibilities here. One example is the operator that computes the “simplest form” of an essence, outputting an expression. E.g. the essence of “2*x — x” would map to “x”. Another is an operator that “solves” an equation (outputting real values for all arguments to the essence). One might also study operators that output whether a (boolean-valued) essence is logically consistent (i.e., satisfiable).

外部运营商:这里有很多可能性。 一个例子是运算符,它计算要素的“最简单形式”,并输出一个表达式。 例如,“ 2 * x — x”的本质将映射为“ x”。 另一个是运算符,它“求解”一个方程式(将本质的所有自变量输出为实数值)。 可能还会研究输出(布尔值)要素在逻辑上是否一致(即可满足)的运算符。

What else can we do with essence algebras?

本质代数还能做什么?

发行版 (Distributions)

Here, we are using the word distribution in a specific sense. Roughly speaking, define a “distribution” as a probability distribution in the traditional sense, but removing the constraint that all probabilities sum to one. These distributions are often useful for talking about multiple simultaneous sub-objects (e.g. multiple possible outcomes of an experiment, multiple types of assets owned by a portfolio, or multiple answers to a question). Such distributions can also be sensibly “sampled” to produce random sequences of values. So how can we frame them in terms of an essence algebra?

在这里,我们使用特定意义上的单词分布。 粗略地说,将“分布”定义为传统意义上的概率分布,但是消除了所有概率加总为一个的约束。 这些分布通常对于讨论多个同时存在的子对象很有用(例如,实验的多种可能结果,投资组合拥有的多种资产或问题的多个答案)。 还可以合理地对此类分布进行“采样”以产生值的随机序列。 那么我们如何用本质代数来构架它们呢?

Essences: Mappings of a “sample value” to a real-valued “weight”.

本质:“样本值”到实值“权重”的映射。

Example essences:

本质示例:

  1. f(x): integer -> real := (x == 0 ? 1.0 : (x == 2 ? 3.0 : 0.0 )). This is pseudocode for: “if x is 0, output 1, if x is 2, output 3, else output 0”. This could be thought of as a discrete mass distribution, or, loosely, an (unnormalized) discrete probability mass function.

    f(x):整数->实数:=(x == 0?1.0:(x == 2?3.0:0.0))。 这是伪代码:“如果x为0,则输出1,如果x为2,则输出3,否则输出0”。 这可以被认为是离散质量分布,或者松散地是(未归一化)离散概率质量函数。
  2. f(x): RealInterval -> Real := Integrate(GaussianPdf(z), dz, from: z=x.start, to: z=x.end). This is one way of representing a continuous gaussian distribution over a single real variable. It inputs a RealInterval (consisting of a start and end) and outputs a real-valued “mass” for that interval by integrating the gaussian probability density function.

    f(x):RealInterval-> Real:= Integrate(GaussianPdf(z),dz,from:z = x.start,to:z = x.end)。 这是一种表示单个实变量上连续高斯分布的方法。 它输入一个RealInterval(由开始和结束组成),并通过积分高斯概率密度函数来输出该间隔的实值“质量”。

Expressions: the set of objects produced by the following formal grammar:

表达式:由以下形式语法产生的一组对象:

An expression is one of:

表达式是以下之一:

  1. Impulse. (define this as a function that maps a single sample space value to a weight)

    冲动。 (将此定义为将单个样本空间值映射到权重的函数)
  2. ScalarWeighting(Expression, weight), where the weight is a real number. This means to multiply the weights of all sample space values in the input expression by the given weight.

    ScalarWeighting(Expression,weight),其中权重是实数。 这意味着将输入表达式中所有样本空间值的权重乘以给定的权重。
  3. Basket(Expression0, Expression1, …), where each weight is a real number. This represents the “addition” of sub-distributions.

    Basket(Expression0,Expression1,…),其中每个权重均为实数。 这表示子分布的“添加”。
  4. (Expression * Expression) (this represents the Cartesian product of all sample space values in the two input expressions. There are a bunch of details as to what this actually means but they aren’t important.)

    (表达式*表达式)(这表示两个输入表达式中所有样本空间值的笛卡尔积。关于这实际上意味着什么有很多细节,但并不重要。)

Essence operators: At least the addition and product operations defined above.

本质运算符:至少是上面定义的加法和乘积运算。

Simplification operator: There are many choices here. For the case of discrete distributions (i.e., those with a countable number of sample space values), we can hack together a quick prototype along the following lines. Imagine our input expression is Basket(Basket(“x”: 1, “y”: 2), “x”: 3) (where the sample space values are “x” and “y”). We can simplify this input expression into a single, “flattened” Basket: {“x”: 4, “y”: 2}. This is done simply by aggregating weights for all encountered sample space values.

简化运算符:这里有很多选择。 对于离散分布(即,具有数量可观的样本空间值的分布),我们可以按照以下几行内容快速编写原型。 假设我们的输入表达式是Basket(Basket(“ x”:1,“ y”:2),“ x”:3)(其中样本空间值为“ x”和“ y”)。 我们可以将此输入表达式简化为单个“展平”的篮子:{“ x”:4,“ y”:2}。 只需通过汇总所有遇到的样本空间值的权重即可完成。

External operators: Again, there are a lot of choices, but one interesting one is the idea of “sampling” a distribution, which outputs a particular sample space value chosen “randomly”.

外部运算符:同样,有很多选择,但是一个有趣的选择是对分布进行“采样”的思想,该分布输出“随机”选择的特定采样空间值。

There’s one more example of an essence algebra that I found useful, and it was the one that pushed me over the edge to write this blog post.

我发现本质代数的另一个例子是有用的,正是这个例子使我无法撰写本文。

几何区域 (Geometric Regions)

Essences: Mappings of N-dimensional real-valued vector to a boolean. These can be thought of regions of space, and include lines, triangles, squares, spheres, etc.

本质:N维实值向量到布尔值的映射。 这些可以认为是空间区域,包括直线,三角形,正方形,球形等。

Example essences:

本质示例:

  1. f(x): real->bool = 1 < x < 2 (this is a line segment of length 1).

    f(x):实数-> bool = 1 <x <2(这是长度为1的线段)。
  2. f(x, y): (real, real) -> AND(0 < x < 10, 5 < y < 15) (this is a (filled) square with area 100 whose center is at (x,y)=(5, 10))

    f(x,y):(实数,实数)-> AND(0 <x <10,5 <y <15)(这是一个(填充的)正方形,区域100的中心为(x,y)=( 5、10))

Expressions: the set of objects produced by the following formal grammar:

表达式:由以下形式语法产生的一组对象:

An expression is one of:

表达式是以下之一:

  1. Primitive region. Some given computable function f: real^N -> bool.

    原始区域。 某些给定的可计算函数f:real ^ N-> bool。
  2. Intersection(Expression, Expression)

    交叉口(表情,表情)
  3. Union(Expression, Expression)

    联合(表达,表达)

Simplification operator: This heavily depends on the representation of primitive regions, but we can sketch an example. Imagine all primitive regions are represented as 2D boxes. Note the intersection of two 2D boxes is either empty or another 2D box (ignore the degenerate cases as they can technically be represented as zero-length 2D boxes themselves). Thus, if we have an input expression AND(Box2D(0 < x < 10, 0 < y < 10), Box2D(5 < x < 15, 5 < y < 15)), a reasonable simplification operator might output Box2D(5 < x < 10, 5 < y < 10).

简化运算符:这在很大程度上取决于基本区域的表示形式,但是我们可以画一个例子。 想象所有原始区域都表示为2D框。 请注意,两个2D框的交集要么是空的,要么是另一个2D框(忽略退化的情况,因为它们在技术上可以表示为零长度2D框本身)。 因此,如果我们有一个输入表达式AND(Box2D(0 <x <10,0 <y <10),Box2D(5 <x <15,5 <y <15)),则合理的简化运算符可能会输出Box2D(5 <x <10,5 <y <10)。

External operators: Several possibilities again, but one simple and useful example is the hypervolume operator. (For one dimension, this is the length, for two dimensions it’s the area, for three dimensions it’s the volume, etc).

外部运算符:再次有几种可能,但是一个简单而有用的例子是超容量运算符。 (对于一维,这是长度,对于二维,这是面积,对于三个维,是体积,等等)。

最后的想法 (Final Thoughts)

Essence algebras can often be nicely expressed in traditional object-oriented programming languages like Python or C++. Specifically, each production rule in the expression grammar corresponds a class. An instance of one of those classes corresponds to a particular expression. It is often useful to enforce immutability on the expression instances to make it easier to reason about their manipulation. Using Python and integer arithmetic as an example, we’d have a base class IntegerExpression, a class Integer(IntegerExpression) (representing a primitive integer expression), a class Add(IntegerExpression) with two instance IntegerExpression variables, etc. We’d have a static function simplify(x: IntegerExpression) -> IntegerExpression. And we could have an external operator extract_int(x: IntegerExpression) -> int.

本质代数通常可以在传统的面向对象的编程语言(如Python或C ++)中很好地表达。 具体来说,表达语法中的每个生产规则都对应一个类。 这些类之一的实例对应于特定表达式。 在表达式实例上强制不变性以使其推理起来更容易通常是很有用的。 以Python和整数算术为例,我们将有一个基类IntegerExpression,一个Integer(IntegerExpression)类(表示原始整数表达式),一个具有两个实例IntegerExpression变量的Add(IntegerExpression)类,等等。静态函数simple(x:IntegerExpression)-> IntegerExpression。 我们可以有一个外部运算符extract_int(x:IntegerExpression)-> int。

One might notice that the simplification operator and external operators for an arbitrary essence algebra can often be implemented surprisingly straightforwardly in your favorite programming language by following this framework. I, at least, found it interesting that so many mathematical systems could be expressed nicely within it. I have used this framework as the foundation for several experimental projects, including a functional programming language and a mathematical prover. I hope you found this topic interesting. Thanks for reading.

也许您会注意到,遵循此框架,对于任意本质代数的简化运算符和外部运算符通常可以在您喜欢的编程语言中直接实现,令人惊讶。 至少,我发现有趣的是,其中可以很好地表达许多数学系统。 我已将此框架用作几个实验项目的基础,其中包括功能编程语言和数学证明者。 希望您对此话题感兴趣。 谢谢阅读。

翻译自: https://medium.com/@tdoneal/essence-algebras-bd382b23dabe

线性代数的本质

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值