-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathisprogrammingmath.html
222 lines (210 loc) · 12.2 KB
/
isprogrammingmath.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html>
<html>
<head>
<link rel="canonical" href="https://hardmath123.github.io/isprogrammingmath.html"/>
<link rel="stylesheet" type="text/css" href="/static/base.css"/>
<title>Programming is not math - Comfortably Numbered</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="alternate" type="application/rss+xml" title="Comfortably Numbered" href="/feed.xml" />
<!--
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$']]}
});
</script>
-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-Um5gpz1odJg5Z4HAmzPtgZKdTBHZdw8S29IecapCSB31ligYPhHQZMIlWLYQGVoc" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-YNHdsYkH6gMx9y3mRkmcJ2mFUjTd0qNQQvY9VYZgQd7DcN7env35GzlmFaZ23JGp" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-vZTG03m+2yp6N6BNi5iM4rW4oIwk5DfcNdFfxkk9ZWpDriOkXX8voJBFrAO7MpVl" crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.body, {
// customised options
// • auto-render specific keys, e.g.:
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false},
{left: '\\begin{align}', right: '\\end{align}', display: true},
{left: '\\(', right: '\\)', display: false},
{left: '\\[', right: '\\]', display: true}
],
// • rendering keys, e.g.:
throwOnError : false
});
});
</script>
</head>
<body>
<header id="header">
<script src="static/main.js"></script>
<div>
<a href="/"><span class="left-word">Comfortably</span> <span class="right-word">Numbered</span></a>
</div>
</header>
<article id="postcontent" class="centered">
<section>
<h1>Programming is not math</h1>
<center><em><p>My two cents on a couple of blog posts.</p>
</em></center>
<h4>Thursday, July 24, 2014 · 5 min read</h4>
<p>So recently, Sarah Mei blogged that <a href="http://www.sarahmei.com/blog/2014/07/15/programming-is-not-math/">programming is not
math</a>. Jeremy
Kun <a href="http://j2kun.svbtle.com/programming-is-not-math-huh">responded</a>, pointing
out that math is an integral part of programming.</p>
<p>I found both articles interesting, but I wanted to add my thoughts on some
things both of them wrote. So here they are.</p>
<p>Let’s start with math. Math feels like mining. You know there’s gold somewhere
below you. Perhaps it’s some theorem you’re trying to prove. Math is about
digging in the right direction from the right spot in the massive network of
tunnels we’ve already derived. And although you can dig in any direction, it’s
not always obvious how to proceed from where you are to your target. The most
brilliant mathematicians are the ones who have the best intuition about which
way to dig. Some directions are obviously less efficient than others—digging
through a rocky bit is much harder (but a clever mathematician might notice
that it’s just a thin wall and there’s gold on the other side).</p>
<p>For example, consider a problem like <em>“Find the area of a triangle with side
lengths 39, 52, and 65.”</em> This was on my math final back in 7th grade. We were
taught the path that goes through Heron’s formula. Calculate semiperimeter,
multiply, square root. That’s the long way through soft earth. Of course, if
you haven’t noticed already, there’s an easier way. You notice that 39, 52, and
65 are all multiples of 13, which is suspicious. If you divide by 13, you get
3, 4, and 5 which is a Pythagorean triple! So this is just a right triangle
scaled up by a factor of 13. So the area is just the half the product of the
two smaller side lengths.</p>
<p>This was the short path through the rocky earth. You need intuition to even
consider going that way; and that intuition isn’t easy to acquire.</p>
<p>This is far from a perfect analogy, but it suffices to explain why a lot of
people find math hard. Many schools teach you the paths to take, rather than
the intuition you need to build up to be able to find them yourself.</p>
<p>I write all this to make a contrast with CS: <em>the majority of CS doesn’t
require mathematical rock-wall insights</em>. You simply need to be able to think
about how to solve problems by breaking them into smaller problems. You never
get ‘stuck’, because you can <em>always</em> reduce a problem you have to something
else (even if it’s an ugly brute-force solution). Math has dead ends and paths
that circle back to where you were originally. Programming is like building a
skyscraper: the only way is up.</p>
<p>This, I think, is why many people find programming easier than pure math.</p>
<blockquote>
<p>…computer science is not programming. At most academic CS schools, the
explicit intent is that students learn programming as a byproduct of learning
CS. Programming itself is seen as rather pedestrian, a sort of exercise left
to the reader.</p>
<p>— Sarah Wei</p>
</blockquote>
<p>I thought this was rather interesting. I have seen this idea in a lot of
places, but I have the opposite viewpoint.</p>
<p>CS is a way to formalize programming concepts. Learning programming isn’t a
byproduct of learning CS, but rather learning CS is a byproduct of learning
programming. The more you have programmed, the more problems you have solved,
and the more CS ideas you’ve internalized.</p>
<p>Here’s an example. You have a curb 100 meters long. (Idealized) cars 3 meters
long park randomly along the curb, one after another, until there’s no space
greater than 3 meters between any two cars. Write a program to simulate this
many times and compute the average number of cars that can park.</p>
<p>Take a moment to try to envision this program.</p>
<p>If you took an awesome CS class, you should have ended up with something like this:</p>
<pre><code class="lang-scheme">(define (number-of-cars len)
(if (< len 3) 0 ; can't park any cars, too short
(+ 1 ; +1 for current car
(let ((offset (random)))
(+ ; compute number of cars on left and right side
(number-of-cars (* (- len 3) offset))
(number-of-cars (* (- len 3) (- 1 offset))))))))
</code></pre>
<p>Guess what? It’s <em>tree recursion</em>, which is, surprise surprise, a classic ‘CS
concept’. But your programming mind didn’t think of it as a tree recursion
problem. CS formalizes the idea of tree recursion because it’s so common in
programming. It gives this idea a name, and lets you use this name when
communicating with humans. It lets you use someone else’s Tree implementation,
knowing exactly what to expect. It gives you an overview of common ideas that
expand on trees—binary search trees, or perhaps breadth-first searching.</p>
<p>But in the end, it’s all programming that has been catalogued so that you can
do math on it.</p>
<blockquote>
<p>I taught Ruby on Rails, which is a web programming framework; people came
because they wanted to learn how to make websites. Because of those
motivations, the curriculum had virtually no math.</p>
<p>— Sarah Wei</p>
</blockquote>
<p>Ah, this brings up the topic of a really interesting discussion I had with some
friends a while ago. Here’s a summary:</p>
<p>There’s a lot of CS to be learned by studying the Internet: networking,
protocol design, language design, layout engines, and security are just a few.</p>
<p>But is setting up a web server really programming? We felt it’s a distinction
between building and assembling. Teaching someone how to make a web server with
today’s frameworks is more about teaching them Ruby syntax and the APIs, and
less about algorithms and logic. It’s not raw computer science, it’s following
some instructions and inputting your own values. Using a clay mold shouldn’t
count as sculpting.</p>
<p>As much as I admire initiatives to teach CS, I feel that we should be teaching
the algorithmic beauty alongside the more practical day-to-day skills.</p>
<blockquote>
<p>Specifically, learning to program is more like learning a new language than
it is like doing math problems.</p>
<p>— Sarah Wei</p>
</blockquote>
<p>A lot of people talk about CS as math and language, but I’ve always felt that
it’s more like building a tower with LEGOs. Programming isn’t about the
language you use—it’s about the paradigm. Once you understand classes and
methods, learning a new language of the same paradigm is at best a weekend job.
Instead, programming is about taking blocks you already have, and fitting them
together. The language is just a medium to communicate with the computer; we
could use punch cards, or command lines, or fancy graphical programming
software. What matters is what that medium is communicating. Writing in general
follows this, too—writing a good blog post requires an exciting idea to convey.
Text is just a medium to communicate the idea.</p>
<blockquote>
<p>It helps even more that mathematics and programming readily share topics. You
teach graph coloring for register allocation, linear algebra and vector
calculus for graphics, combinatorics for algorithms.</p>
<p>— Jeremy Kun</p>
</blockquote>
<p>Programming isn’t about math you <em>implement</em>.</p>
<p>Understanding, for example, vector algebra to write a raytracer is important to
know <em>what</em> you’re doing, but it’s not programming—programming is being able to
know <em>how</em> to do it.</p>
<p>To be successful in the modern computing landscape, you need to know math
because the ability to compute is enhanced by the ability to put computation in
a mathematical context. Twenty or thirty years ago, you might have considered
discrete math (parsing), calculus (waveforms), and trig (graphics) to be
instrumental. Today, it’s statistics (big data) and number theory (crypto).</p>
<h3 id="conclusion">Conclusion</h3>
<p>What I wanted to say—and ended up digressing in rambles along the way—was that
the intrinsic difference between math and computing is that math needs you to
have good taking-apart intuition, while programming needs you to have good
putting-together intuition.</p>
<p>And so here’s a parting thought: in my school, CS is lumped with all the other
electives. Theater, drawing, photography, food, and auto tech are in the same
category. Would you move CS to the math department? Hint: this isn’t a trivial
question!</p>
</section>
<div id="comment-breaker">◊ ◊ ◊</div>
</article>
<footer id="footer">
<div>
<ul>
<li><a href="https://github.com/kach">
Github</a></li>
<li><a href="feed.xml">
Subscribe (RSS feed)</a></li>
<li><a href="https://twitter.com/hardmath123">
Twitter</a></li>
<li><a href="https://creativecommons.org/licenses/by-nc/3.0/deed.en_US">
CC BY-NC 3.0</a></li>
</ul>
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-46120535-1', 'hardmath123.github.io');
ga('require', 'displayfeatures');
ga('send', 'pageview');
</script>
</footer>
</body>
</html>