3 ms·
Indeed, posts like this are of historical interest, but today, take Python: dx = 0.0001 def deriv(f): return lambda x: (f(x + dx) - f(x)) / dx
by Will_Parker 9y ago
Indeed, posts like this are of historical interest, but today, take Python:
dx = 0.0001
def deriv(f):
return lambda x: (f(x + dx) - f(x)) / dx
This works just the same as the author's example and looks even more like the calculus formula people are used to.
- exDM69 9y agoNow do the same using symbolic computation. SymPy does it beautifully but it's much much more complicated than the equivalent in Scheme. Symbolic differentation a topic covered in the early chapters of SICP. Doing the same in Python requires intimate knowledge of the dark corners of Python and is not at all suitable for an example in an introductory computer science class.
- brlewis 9y agof(x + dx) does look more conventional than (f (+ x dx)), but (/ numerator denominator) looks more like the conventional fraction syntax than putting a / somewhere in the middle of a line.
- Will_Parker 9y agoI'll give you that but also, ask 100 random people what "3/4" means and what "(/ 3 4)" means.
- klibertp 9y agoAre you sure random people are going to recognize "3/4" notation? It could be different for "3 ÷ 4", but I think "3/4" is not widely used outside of programming?
- archgoon 9y agoHave you ever looked at a cookbook? http://www.tasteofhome.com/recipes/how-to-cook/how-to-cut-down-recipes http://www.tasteofhome.com/recipes/how-to-cook/how-to-cut-do... Taken a drive? https://c1.staticflickr.com/5/4149/5174138836_6603010a7d_b.jpg https://c1.staticflickr.com/5/4149/5174138836_6603010a7d_b.j...
- omaranto 9y agoIt's used outside of programming in, say, mathematics. :)
- brlewis 9y agoYes, I'm sure hardly any would say "three fourths" for (/ 3 4) and a lot of them would for 3/4. (A lot of them might also say "three or four".) Incidentally Scheme syntax recognizes 3/4 as a rational number. It will do rational arithmetic without floating point problems.
- syncsynchalt 9y agoRacket (and others?) gives you a sugar of (n . / . d) to infix any two-arg function if that's a stumbling block.
- deleted 9y ago[deleted]
- int_19h 9y agoI don't know, things like 1/2 are pretty conventional fraction syntax. But if you really wanted to, you could always do the same thing in Python, since newlines are basically just ignored inside parentheses: (numerator / denominator) Or even place / on its own line if so desired.