We're sunsetting PodQuest on 2025-07-28. Thank you for your support!
Export Podcast Subscriptions
cover of episode Episode 147: Gabriella Gonzalez discusses the intersection of algebra and programming

Episode 147: Gabriella Gonzalez discusses the intersection of algebra and programming

2023/7/15
logo of podcast Elucidations

Elucidations

AI Deep Dive Transcript
People
G
Gabriela Gonzalez
M
Matt Teichman
Topics
Gabriela Gonzalez: 我认为很多人听到"代数"这个词,想到的是高中代数,例如解方程2*x=16。然而,抽象代数更通用,它研究的是在非数字对象上进行的代数运算,例如代码或程序。这使得它能够应用于各种领域,例如食谱、正则表达式和并发编程。在食谱中,我们可以用乘法表示多个成分的组合,用加法表示成分的替代。分配律在这些情况下仍然成立。类似地,在正则表达式中,顺序匹配类似于乘法,而"或"匹配类似于加法。在并发编程中,Haskell语言的软件事务内存(STM)允许指定事务,这些事务可以作为原子操作执行,并且可以进行"或"操作。通过抽象代数,我们可以找到不同领域中代数结构的相似性,从而实现跨领域的算法和思想复用。例如,快速幂算法可以应用于非数字对象,只要这些对象具有乘法运算。抽象代数定义了各种抽象接口,例如半群、幺半群和半环,这些接口可以用于不同类型的对象。自然数可以被视为加法半群,而空列表可以作为列表的单位元。在正则表达式中,单位元是总是失败匹配的正则表达式(0)和匹配空字符串的正则表达式(1)。在成分列表中,单位元是不可满足的成分(0)和空成分集(1)。在并发编程中,单位元是总是失败的事务(0)和总是成功的事务(1)。通过研究正则表达式的代数性质,我们可以重用抽象接口,例如在不同类型对象上使用sum函数。函数式编程的核心是简单的代数类型,其他一切都是建立在这些基础之上的。函数式编程中的记录类型可以被视为类型的乘积,而和类型可以被视为类型的加法。函数类型类似于幂运算。这些简单的代数类型是编程所需的一切,其他一切都是建立在这些基础之上的。 Matt Teichman: 我很好奇,除了数字,代数方程中的变量还能代表什么?例如,两个杯子里的水混合在一起,这算不算加法?抽象代数的魅力在于它揭示了看似不同的事物之间的统一性。例如,食谱中的成分列表类似于正则表达式,其中匹配成分类似于匹配字符串。数学有助于跨领域进行思想的交叉传播,我们可以将一个领域中的洞见应用于其他领域。在程序设计中,通过使用抽象接口,我们可以重用相同的函数在多个不同领域。例如,sum函数可以用于对非数字对象进行求和。函数式编程与抽象数学的结合,可以使代码具有更强的持久性,因为其基础是简单的数学概念。等式推理是理解程序行为的一种方法,而抽象代数中的代数定律可以简化等式推理的过程。引用透明性在哲学逻辑和计算机编程中都有应用。我们可以对代码进行抽象推理,即使我们不知道输入是什么。

Deep Dive

Shownotes Transcript

In this episode, Matt talks to Gabriella Gonzalez) about how basic concepts from the branch of math known as abstract algebra) can help us simplify our

computer programs and organize our thoughts.

Algebra. That thing they make us do in school. What was that again? Oh yeah, that’s right; it’s where you get to manipulate equations containing variables. Like, if I have an equation that looks like this:

2⋅x = 16

Then I can divide both sides by two and get a new version where x stands alone, i.e. solve for x:

(2⋅x) / 2 = 16 / 2

*x *= 8

If you took algebra in school, you might remember learning a bunch of tricks for pushing parts of equations around to get one of the variables to appear only on one side and thus solve for it. Being able to solve for variables in equations proves useful for lots of things: like, if you can translate a word problem into one of those equations, finding the answer is often as simple as tinkering with the equation in some obvious way.

Abstract algebra is somewhat similar in that it also involves manipulating equations containing variables, except the twist is that now you aren’t necessarily manipulating numbers anymore. The variables can stand for something else, and there are more general versions of plus-like, times-like, etc. operations that you can do on these other things. You might be wondering: what on earth could a variable in an equation stand for other than a number? Well, in this episode, Gabriella Gonzalez gives a bunch of examples. You can have equations for cooking recipes, for computer programs, for transactions performed on databases, and for regular expressions. (A regular expression is a special type of computer program for identifying strings that fit a particular pattern and pulling information out of them.)

Gonzalez then goes on to argue that the point of all this is to avoid re-inventing the wheel. Often, when you write a computer program to add some numbers, though this isn’t necessariy obvious at the time of writing, you aren’t actually drawing meaningfully on the fact that they’re numbers. If that’s the case, then what you can often do is make your code that adds things abstract so you only have to write your program once, but then you can re-use it on all these different other kinds of entities other than numbers.

The overall payoff of all that, according to this month’s distinguished guest, is that by following algebra-driven design, you can keep your code simple and easy to understand, while still having it do fancy things. This is particularly important today, when our software just seems to keep getting fancier and fancier, but the usual ways of accomplishing that goal make it unreliable and well nigh impossible to keep up to date.

Join us as Gabriella Gonzalez gives us the tour through various algebraic systems that occur all over the place in computer science, philosophy, and linguistics!

Matt Teichman

-

Hosted on Acast. See acast.com/privacy) for more information.