我如何考虑编程中的数学?

时间:2022-12-17 15:03:41

I'm not sure if this is for SO or not. I am reading some of my old math textbooks and trying to understand math in general. Not how to figure something. I can do that but rather what is it that math is doing.

我不确定这是否是为了SO。我正在阅读一些旧的数学教科书,并试图理解一般的数学。不是如何形象。我能做到这一点,而不是数学正在做什么。

I'm sure this is painfully obvious but I never thought about it until I thought more about game programming. Is it right to think about math as the "language" that is used to explain, precisely explain, why things work?

我确信这是非常明显的,但直到我更多地考虑游戏编程,我才想到它。将数学看作是用来解释,准确解释为什么有效的“语言”是正确的吗?

I'm having a hard time asking it and again, I'm sure it's obvious to most, but after years of math I'm finally thinking when someone asks to "find the equation of a line" that people recognized certain characteristics of a line (y=mx+b) in space and found relationship. They needed something beside a huge paragraph (like this one) and something very precise. We call this math and at its base it's nothing more than a symbolic way to represent things.

我很难再问它,我确信这对大多数人来说是显而易见的,但经过多年的数学考验,我终于想到当有人要求“找到一条线的等式”时,人们会认识到某些特征。线(y = mx + b)在空间中找到了关系。他们需要一个巨大的段落旁边的东西(像这个)和非常精确的东西。我们称这种数学为基础,它只不过是一种表征事物的象征性方式。

Really, I was thinking, "I know why they said 'find the equation of a line'."

真的,我在想,“我知道为什么他们说'找到一条线的等式'。”

So now I am thinking, not just googling for a formula that tells me how to turn a curve with a walking man or follow a path, but why and how do I represent this mathematically and then programatically.

所以现在我在思考,不只是谷歌搜索一个公式,告诉我如何与一个行走的人转弯曲线或遵循一条路径,但为什么以及如何以数学方式然后以编程方式表示。

Just hoping for comments on math in programming.

希望对编程中的数学有所评论。

11 个解决方案

#1


To my way of thinking, I create a "model" of some aspect of the world. Examples:

按照我的思维方式,我创造了一个世界某些方面的“模型”。例子:

  • Profit = Income - Expenditure
  • 利润=收入 - 支出

  • I throw a ball it's path will be a parabola with equation ...
  • 我扔了一个球,它的路径将是抛物线的方程式......

I then represent the model in a computer program. So some kind of abstaction underpins the program, sometimes the math is so "obvious" we hardly notice it, sometimes (eg. simulation games) it's both very clearly there and pretty darn tricky.

然后我在计算机程序中表示模型。所以某种抽象是程序的基础,有时数学是如此“明显”,我们几乎没有注意到它,有时候(例如模拟游戏)它非常清楚,并且相当棘手。

Key idea: math can be used to model reality, most business systems can be viewed as represented as a model of reality.

关键思想:数学可以用来模拟现实,大多数商业系统可以被视为现实模型。

Having said that, in 30 years of programming the amount of true (algebra, calculus) maths I have done is negligable.

话虽如此,在30年的编程中,我所做的真数(代数,微积分)数学的数量是可以忽略不计的。

#2


Steve Yegge wrote a very good article that you may find helpful: Math Every Day

史蒂夫·耶格写了一篇非常好的文章,你可能会觉得有用:每天数学

#3


I recommend that you look into materials related to the theory of computation. For example:

我建议您研究与计算理论相关的材料。例如:

These are not papers for the faint of heart, but they will give you insights into the beautiful relationship between mathematics and computer science.

这些不是关于胆小者的论文,但它们会让你深入了解数学与计算机科学之间的美好关系。

You might want to start with a textbook on the subject of computation theory before you tackle the papers listed above, e.g.

在解决上面列出的论文之前,你可能想要从一本关于计算理论主题的教科书开始,例如:

  • Introduction to the Theory of Computation - Michael Sipser
  • 计算理论导论 - Michael Sipser

#4


Math for a programmer is like a hammer for a carpenter. The carpenter doesn't use the hammer for everything, but if he doesn't have one, there's a lot he can't do.

程序员的数学就像是木匠的锤子。木匠不会把锤子当作一切,但如果他没有锤子,那么他就做不了多少。

#5


Not sure what your precise question is ... Some thoughts:

不确定你的确切问题是什么......有些想法:

  • Programming is nothing but math (Functional programming, Lambda calculus, programming == math)
  • 编程只不过是数学(函数式编程,Lambda演算,编程==数学)

  • Math is a kind of language - An abstract description/representation of an expression in thought
  • 数学是一种语言 - 思想中表达的抽象描述/表示

  • Math helps you to formalize expressions: Instead of For all integer numbers x from one to ten the square of x is less than 250 you can write ∀x ∈ {1..10} (x² < 250)
  • 数学帮助你形式化表达式:而不是对于所有整数x从1到10,x的平方小于250你可以写∀x∈{1..10}(x²<250)

  • Programming (a programming language) does the same thing and helps to formalize algorithms.

    编程(编程语言)做同样的事情并有助于形式化算法。

  • The kind math that is commonly used in computer programms is numeric math, but with some efforts, you can also perform symbolic computations

    计算机程序中常用的数学类型是数学数学,但通过一些努力,您还可以执行符号计算

#6


I think math is really the concepts behind the symbols instead of the symbols themselves, but when most people speak of math, they're not making the distinction. They're just thinking of the symbols. Partly, this is because of they way math is taught in school, where the focus is on the mechanistic manipulation of the symbols to get correct results, rather than what the concepts are.

我认为数学实际上是符号背后的概念而不是符号本身,但是当大多数人谈论数学时,他们并没有做出区分。他们只是想着符号。部分地,这是因为他们在学校教授数学,其中重点是对符号进行机械操作以获得正确的结果,而不是概念。

This is similar to the way non-programmers view programming. They look at a computer program and see gibberish, whereas a programmer in the given language (after more or less effort) understands the behavior the code represents.

这类似于非程序员查看编程的方式。他们查看计算机程序并看到乱码,而使用给定语言的程序员(经过或多或少的努力)理解代码所代表的行为。

Some people are better at retaining the meaning of such symbols than others. I think there are people who might appreciate math more than they think if they could get past that barrier to the concepts.

有些人比其他人更善于保留这些符号的含义。我认为有些人可能会比他们想象的更能理解数学,如果他们能够克服这些概念的障碍。

#7


I agree with Taylor. Math inside computers is a very deep topic with numerical methods. The biggest issues is precision and the fact that 32 bits only get you so far. There are some really cool (and complicated) functions that describe how to find integrals and such with computers, but because we can't be exact with our answers, and because computers are limited with what they can do (add, multiply, etc) there are lots of methods of how to estimate math to a great deal of precision.

我同意泰勒。计算机内的数学是一个非常深入的主题与数值方法。最大的问题是精度和32位只能让你到目前为止的事实。有一些非常酷(和复杂)的函数描述了如何使用计算机查找积分等,但是因为我们无法准确回答我们的问题,并且因为计算机受限于他们可以做的事情(添加,乘法等)有很多方法可以很好地估算数学。

If you are interested in that topic, all the more power to you. That was one class I struggled through.

如果您对该主题感兴趣,那么您将获得更多权力。那是我奋斗过的一堂课。

#8


I'm looking at something similar (financial models) - similar in that we come up with mathematical models, and then implement these in code.

我正在寻找类似的东西(财务模型) - 类似于我们提出数学模型,然后在代码中实现这些。

The main issue you face from a programming perspective is taking a model that is expressed in mathematical terms (which assume continuity, infinitely small time/space steps etc.) and then translate these into 'discrete' models, that assume finite time/space steps (e.g. the ball moves every 1mm, or every 1ms).

从编程角度来看,您面临的主要问题是采用以数学术语表示的模型(假设连续性,无限小的时间/空间步长等),然后将这些模型转换为“离散”模型,假设有限的时间/空间步长(例如,球每1毫米移动一次,或每1毫秒移动一次)。

The translation of these models is not necessarily trivial, and you should have a look at appropriate references for these (Numerical Recipes is a classic). The implementation in code is often very different to how you might express the problem in mathematical terms.

这些模型的翻译不一定是微不足道的,你应该看看这些模型的适当参考(Numerical Recipes是经典的)。代码中的实现通常与您在数学术语中表达问题的方式非常不同。

#9


I think Math in programming with time, silence and good food such that I have a lot of paper and a pen, friends-to-ask-help and a pile of books from Rudin to Bourbaki on the top of my Macbook on the floor.

我认为数学在编程中有时间,沉默和美食,所以我有很多纸和笔,朋友请求帮助以及从我的Macbook顶部的Rudin到Bourbaki的一堆书。

#10


I think why is a philosophical question.

我想为什么是一个哲学问题。

As far as how I think of math/programming and the interplay between... I think of them as layers of modeling. At the lowest, 'truest' level there is some fundamental truth, whatever that may be. Then there is the mathematical modeling of this truth, upon which the 'language' of mathematics is developed (fortunately there is only one language?). Then there is another layer, that of modeling and approximations. In the case of y=mx+b, its only a line within one model, it could be anything. Being visual beings, the most beneficial is perhaps geometric (lines, surfaces, etc). Then upon this there is the computational modeling, the numerical methods/analysis if you will.

至于我如何看待数学/编程以及...之间的相互作用......我认为它们是建模的层次。在最低的,“最真实的”水平上,无论可能是什么,都有一些基本的事实。然后是这个真理的数学模型,在此基础上开发了数学的“语言”(幸运的是,只有一种语言?)。然后是另一层,即建模和近似层。在y = mx + b的情况下,它在一个模型中只有一条线,它可以是任何东西。作为视觉生物,最有益的可能是几何(线条,表面等)。然后是计算机建模,数值方法/分析,如果你愿意的话。

As to how do i think of things, I like to think in the modeling perspective. That is, I like to conceptually model some process, and then apply the math and then the numerical methods. Middle out development if you will (to draw an N-tier analogy).

至于我如何看待事物,我喜欢在建模的角度思考。也就是说,我喜欢在概念上模拟一些过程,然后应用数学然后应用数值方法。如果你愿意,可以进行中间开发(绘制N层类比)。

As an afterthought, perhaps the modeling could be called engineering.

作为事后的想法,也许建模可以称为工程。

#11


The best way to get the type of understanding that you're looking for is to work through "story problems" (i.e. problems stated in words rather than equations). From this and your other questions, you're mostly looking at trigonometry.

获得所需理解类型的最佳方法是解决“故事问题”(即用词语而不是方程式表达的问题)。从这个和你的其他问题来看,你主要是看三角学。

In short, I would recommend trying the trig book from the Schaum's Outline Series -- they are cheap (~$13) and have lots of problems with solutions.

简而言之,我建议尝试使用Schaum的大纲系列中的trig书 - 它们很便宜(约13美元)并且在解决方案方面存在很多问题。

There are other routes to finding problems in math to solve, such as just make up game design problems to solve. Here are two: 1) show an object moving around a circle at constant speed, and 2) show two object moving along to different lines that don't intersect, and draw a line between them. Or you could get a book that walks you through these types of things. But you've got to work out a number of problems to force you to think things through yourself.

还有其他途径可以解决数学问题,例如解决游戏设计问题。这里有两个:1)显示以恒定速度围绕圆移动的对象,以及2)显示两个对象沿着不相交的不同线移动,并在它们之间画一条线。或者你可以得到一本书,引导你完成这些类型的事情。但是你必须解决一些问题,迫使你自己思考问题。

#1


To my way of thinking, I create a "model" of some aspect of the world. Examples:

按照我的思维方式,我创造了一个世界某些方面的“模型”。例子:

  • Profit = Income - Expenditure
  • 利润=收入 - 支出

  • I throw a ball it's path will be a parabola with equation ...
  • 我扔了一个球,它的路径将是抛物线的方程式......

I then represent the model in a computer program. So some kind of abstaction underpins the program, sometimes the math is so "obvious" we hardly notice it, sometimes (eg. simulation games) it's both very clearly there and pretty darn tricky.

然后我在计算机程序中表示模型。所以某种抽象是程序的基础,有时数学是如此“明显”,我们几乎没有注意到它,有时候(例如模拟游戏)它非常清楚,并且相当棘手。

Key idea: math can be used to model reality, most business systems can be viewed as represented as a model of reality.

关键思想:数学可以用来模拟现实,大多数商业系统可以被视为现实模型。

Having said that, in 30 years of programming the amount of true (algebra, calculus) maths I have done is negligable.

话虽如此,在30年的编程中,我所做的真数(代数,微积分)数学的数量是可以忽略不计的。

#2


Steve Yegge wrote a very good article that you may find helpful: Math Every Day

史蒂夫·耶格写了一篇非常好的文章,你可能会觉得有用:每天数学

#3


I recommend that you look into materials related to the theory of computation. For example:

我建议您研究与计算理论相关的材料。例如:

These are not papers for the faint of heart, but they will give you insights into the beautiful relationship between mathematics and computer science.

这些不是关于胆小者的论文,但它们会让你深入了解数学与计算机科学之间的美好关系。

You might want to start with a textbook on the subject of computation theory before you tackle the papers listed above, e.g.

在解决上面列出的论文之前,你可能想要从一本关于计算理论主题的教科书开始,例如:

  • Introduction to the Theory of Computation - Michael Sipser
  • 计算理论导论 - Michael Sipser

#4


Math for a programmer is like a hammer for a carpenter. The carpenter doesn't use the hammer for everything, but if he doesn't have one, there's a lot he can't do.

程序员的数学就像是木匠的锤子。木匠不会把锤子当作一切,但如果他没有锤子,那么他就做不了多少。

#5


Not sure what your precise question is ... Some thoughts:

不确定你的确切问题是什么......有些想法:

  • Programming is nothing but math (Functional programming, Lambda calculus, programming == math)
  • 编程只不过是数学(函数式编程,Lambda演算,编程==数学)

  • Math is a kind of language - An abstract description/representation of an expression in thought
  • 数学是一种语言 - 思想中表达的抽象描述/表示

  • Math helps you to formalize expressions: Instead of For all integer numbers x from one to ten the square of x is less than 250 you can write ∀x ∈ {1..10} (x² < 250)
  • 数学帮助你形式化表达式:而不是对于所有整数x从1到10,x的平方小于250你可以写∀x∈{1..10}(x²<250)

  • Programming (a programming language) does the same thing and helps to formalize algorithms.

    编程(编程语言)做同样的事情并有助于形式化算法。

  • The kind math that is commonly used in computer programms is numeric math, but with some efforts, you can also perform symbolic computations

    计算机程序中常用的数学类型是数学数学,但通过一些努力,您还可以执行符号计算

#6


I think math is really the concepts behind the symbols instead of the symbols themselves, but when most people speak of math, they're not making the distinction. They're just thinking of the symbols. Partly, this is because of they way math is taught in school, where the focus is on the mechanistic manipulation of the symbols to get correct results, rather than what the concepts are.

我认为数学实际上是符号背后的概念而不是符号本身,但是当大多数人谈论数学时,他们并没有做出区分。他们只是想着符号。部分地,这是因为他们在学校教授数学,其中重点是对符号进行机械操作以获得正确的结果,而不是概念。

This is similar to the way non-programmers view programming. They look at a computer program and see gibberish, whereas a programmer in the given language (after more or less effort) understands the behavior the code represents.

这类似于非程序员查看编程的方式。他们查看计算机程序并看到乱码,而使用给定语言的程序员(经过或多或少的努力)理解代码所代表的行为。

Some people are better at retaining the meaning of such symbols than others. I think there are people who might appreciate math more than they think if they could get past that barrier to the concepts.

有些人比其他人更善于保留这些符号的含义。我认为有些人可能会比他们想象的更能理解数学,如果他们能够克服这些概念的障碍。

#7


I agree with Taylor. Math inside computers is a very deep topic with numerical methods. The biggest issues is precision and the fact that 32 bits only get you so far. There are some really cool (and complicated) functions that describe how to find integrals and such with computers, but because we can't be exact with our answers, and because computers are limited with what they can do (add, multiply, etc) there are lots of methods of how to estimate math to a great deal of precision.

我同意泰勒。计算机内的数学是一个非常深入的主题与数值方法。最大的问题是精度和32位只能让你到目前为止的事实。有一些非常酷(和复杂)的函数描述了如何使用计算机查找积分等,但是因为我们无法准确回答我们的问题,并且因为计算机受限于他们可以做的事情(添加,乘法等)有很多方法可以很好地估算数学。

If you are interested in that topic, all the more power to you. That was one class I struggled through.

如果您对该主题感兴趣,那么您将获得更多权力。那是我奋斗过的一堂课。

#8


I'm looking at something similar (financial models) - similar in that we come up with mathematical models, and then implement these in code.

我正在寻找类似的东西(财务模型) - 类似于我们提出数学模型,然后在代码中实现这些。

The main issue you face from a programming perspective is taking a model that is expressed in mathematical terms (which assume continuity, infinitely small time/space steps etc.) and then translate these into 'discrete' models, that assume finite time/space steps (e.g. the ball moves every 1mm, or every 1ms).

从编程角度来看,您面临的主要问题是采用以数学术语表示的模型(假设连续性,无限小的时间/空间步长等),然后将这些模型转换为“离散”模型,假设有限的时间/空间步长(例如,球每1毫米移动一次,或每1毫秒移动一次)。

The translation of these models is not necessarily trivial, and you should have a look at appropriate references for these (Numerical Recipes is a classic). The implementation in code is often very different to how you might express the problem in mathematical terms.

这些模型的翻译不一定是微不足道的,你应该看看这些模型的适当参考(Numerical Recipes是经典的)。代码中的实现通常与您在数学术语中表达问题的方式非常不同。

#9


I think Math in programming with time, silence and good food such that I have a lot of paper and a pen, friends-to-ask-help and a pile of books from Rudin to Bourbaki on the top of my Macbook on the floor.

我认为数学在编程中有时间,沉默和美食,所以我有很多纸和笔,朋友请求帮助以及从我的Macbook顶部的Rudin到Bourbaki的一堆书。

#10


I think why is a philosophical question.

我想为什么是一个哲学问题。

As far as how I think of math/programming and the interplay between... I think of them as layers of modeling. At the lowest, 'truest' level there is some fundamental truth, whatever that may be. Then there is the mathematical modeling of this truth, upon which the 'language' of mathematics is developed (fortunately there is only one language?). Then there is another layer, that of modeling and approximations. In the case of y=mx+b, its only a line within one model, it could be anything. Being visual beings, the most beneficial is perhaps geometric (lines, surfaces, etc). Then upon this there is the computational modeling, the numerical methods/analysis if you will.

至于我如何看待数学/编程以及...之间的相互作用......我认为它们是建模的层次。在最低的,“最真实的”水平上,无论可能是什么,都有一些基本的事实。然后是这个真理的数学模型,在此基础上开发了数学的“语言”(幸运的是,只有一种语言?)。然后是另一层,即建模和近似层。在y = mx + b的情况下,它在一个模型中只有一条线,它可以是任何东西。作为视觉生物,最有益的可能是几何(线条,表面等)。然后是计算机建模,数值方法/分析,如果你愿意的话。

As to how do i think of things, I like to think in the modeling perspective. That is, I like to conceptually model some process, and then apply the math and then the numerical methods. Middle out development if you will (to draw an N-tier analogy).

至于我如何看待事物,我喜欢在建模的角度思考。也就是说,我喜欢在概念上模拟一些过程,然后应用数学然后应用数值方法。如果你愿意,可以进行中间开发(绘制N层类比)。

As an afterthought, perhaps the modeling could be called engineering.

作为事后的想法,也许建模可以称为工程。

#11


The best way to get the type of understanding that you're looking for is to work through "story problems" (i.e. problems stated in words rather than equations). From this and your other questions, you're mostly looking at trigonometry.

获得所需理解类型的最佳方法是解决“故事问题”(即用词语而不是方程式表达的问题)。从这个和你的其他问题来看,你主要是看三角学。

In short, I would recommend trying the trig book from the Schaum's Outline Series -- they are cheap (~$13) and have lots of problems with solutions.

简而言之,我建议尝试使用Schaum的大纲系列中的trig书 - 它们很便宜(约13美元)并且在解决方案方面存在很多问题。

There are other routes to finding problems in math to solve, such as just make up game design problems to solve. Here are two: 1) show an object moving around a circle at constant speed, and 2) show two object moving along to different lines that don't intersect, and draw a line between them. Or you could get a book that walks you through these types of things. But you've got to work out a number of problems to force you to think things through yourself.

还有其他途径可以解决数学问题,例如解决游戏设计问题。这里有两个:1)显示以恒定速度围绕圆移动的对象,以及2)显示两个对象沿着不相交的不同线移动,并在它们之间画一条线。或者你可以得到一本书,引导你完成这些类型的事情。但是你必须解决一些问题,迫使你自己思考问题。