3 ms·
Integral Calculus in Lambda Calculus (Lisp)
- jrockway 18y agoA fancy title for what amounts to addition and function evaluation.
- jgrant27 18y agoWhat else does integration primarily entail ?
- jrockway 18y agoSymbolic integration would be much more interesting than Riemann sums.
- jgrant27 18y agoagreed
- jgrant27 18y agoI'm not going to implement that for you. Sorry. See Norvig's "Paradigms of Artificial Intelligence Programming - Case Studies in Common Lisp", Chapter 8 - Symbolic Mathematics : A Simplification Program, 8.6 - Integration, page 252. http://norvig.com/paip.html http://norvig.com/paip.html
- mahmud 18y agoIntegration usually means symbolic integration. Numerical integration of the definite integral is usually referred to as Quadrature, or Numerical Integration: http://en.wikipedia.org/wiki/Numerical_integration http://en.wikipedia.org/wiki/Numerical_integration
- jgrant27 18y agoThat would depend on who's using the word "usually". See Norvig's "Paradigms of Artificial Intelligence Programming - Case Studies in Common Lisp", Chapter 8 - Symbolic Mathematics : A Simplification Program, 8.6 - Integration, page 252. http://norvig.com/paip.html http://norvig.com/paip.html
- jobeirne 18y agoThere's a great bit about this in the first chapter of the SICP.
- jrockway 18y agoOne other thing. The Lisp is rather non-idiomatic. Here is how I'd write it: (defparameter small-dx 0.00001) (defun integrate (f a b &optional (dx small-dx)) "integrate a function f from a to b" (loop for x from a to b by dx sum (* dx (funcall f x)))) Then you can use it like: (flet ((f1 (x) 1) (f2 (x) (expt x 2)) (f3 (x) (* x (exp (expt x 2))))) (format t "f1: ~A, f2: ~A, f3: ~A~%" (integrate #'f1 0 5) (integrate #'f2 0 5) (integrate #'f3 0 5))) In conclusion, CL is not Scheme. (Edit: Initially I said that the code doesn't compile. It does -- storing functions in the value slot of variables threw me off a bit. Very Scheme-like.)
- jgrant27 18y agoThe code compiles and runs just fine on any CL compiler. Try SBCL or CLozure CL. Actually the loop macro in CL can be a very contentious topic. I'd hardly refer to the loop macro as idiomatic. Imperative and functional styles in CL can both be idiomatic. Anyway who said CL was Scheme ?
- jrockway 18y agoAnyway who said CL was Scheme ? Your style strongly hints at a Scheme background. Nothing you do is wrong, but if you read a bunch of Lisp code, you wouldn't see many people doing things the way you did. OTOH, if you read a bunch of Scheme code, it would look exactly like yours. Also, I don't think the use of loop is a point of contention. LOOP is in the CL spec, tail recursion isn't. (The ITERATE package is a nicer loop, but the idea is the same.)
- jgrant27 18y agoInteresting opinion regarding my style. Thanks for explaining. There are many things in the CL spec that are very contentious. Arguably too many. Dan Weinreb pointed this out earlier in the week(http://ilc2009.scheming.org/node/7 http://ilc2009.scheming.org/node/7) which inspired a response from me(http://jng.imagine27.com/articles/2009-04-07-135246_cl_hard_to_compile_efficiently.html http://jng.imagine27.com/articles/2009-04-07-135246_cl_hard_...) although not directly related to the "too many concepts, irregular" argument but then again this may effect how per formant/stable code can be written in a language. Yes tail-recursion is not part of the spec along with many other implementation aspects that probably should be.
- rkowalick 18y agoI would really impressed by seeing some kind of wacky function paired with a fixed point combinator so that when a function is integrable, the combinator spits out as a fixed point the answer.