gusl: (Default)
[personal profile] gusl
Tomorrow, after my last session with my math tutee, I will teach him to play around with Lisp. Hopefully, it will replace his calculator.

download (Can anyone suggest a better Lisp environment for Windows?)

Lisp, because of its prefix notation, makes it possible to express empty additions and multiplications. This makes it easier to see why the value of an empty addition is 0, while the value of an empty multiplication is 1.

Other advantages:
* using formal languages prevents notational confusion
* with a formal language, the communication between teacher and student can be completely precise, at least AFA procedures are concerned. For expressing arguments or proofs, something like Coq would be needed. For communicating about intuitions, I have no idea.

Here's some code I'm hoping to go over with him:
;; BASIC STUFF
(defun ^ (x y) (expt x y))
(defun eqn-true? (eqn)
   (= (eval (second eqn)) (eval (third eqn))))


;;;;;;;;;;;;;;;;;;;;;;;;;;
;; OPERATIONS
;;;;;;;;;;;;;;;;;;;;;;;;;


;;addition

(+ 1 1)

(+ 2 7)

(+ 0 4)

(+ 4 6 1)

(+)


;;multiplication

(* 3 4 2)

(* 1 0)

(* 5)

(*)


;;adding negative numbers

(+ 5 -3)

(+ 2 -3)

(+ 3 -3)

(+ -1 5)

(+ -7 5)

(+ -3 -3)

(+ -8 8)


;;multiplying negative numbers

(* 5 -1)

(* 4 -3)

(* -7 2)

(* -4 -1)

(* -10 -3)

(* -5 5)



;;;;;;;;;;;;;;;;;;;;;;;;;;
;; MORE COMPLEX EXPRESSIONS
;;;;;;;;;;;;;;;;;;;;;;;;;

(+ 1 (* -2 3))

(* (+ 1 -2) 3)

(* (+ 1 1) (+ 2 1) (+ 3 1) (+ 4 1))

(+ (* 0 -1) (* 1 2) (* 2 -3) (* 3 4))

(+ (* 2 1) (* 2 (+ 1 1)))



;;;;;;;;;;;;;;;;;;;;;;;;;;
;; FUNCTIONS
;;;;;;;;;;;;;;;;;;;;;;;;;


(defun square (x)
    (* x x))

(square 5)

(square 7)


;;EXERCISE: write a 'cube' function






;; BONUS: see what happens when you do...

(mapcar #'square '(1 2 3 4 5 6))


;;--------------

(defun substs (tokens expr)
    (reduce #'(lambda (xpr tok) (subst (second tok) (first tok) xpr))
            tokens :initial-value expr))

;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SUBSTITUTIONS
;;;;;;;;;;;;;;;;;;;;;;;;;

(subst 3 'x '(+ x x))
(eval *)


(substs '((x 1) (y 3)) '(+ x y))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; EQUATIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(= 1 1)

(= 2 (+ 1 1))

(= (square 3) 8)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; EQUATIONS WITH VARIABLES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; you can use substs to test whether equations are valid!

(substs '((x 1)(y 1)) '(= (^ (+ x y) 2) (+ (^ x 2) (^ y 2))))
(eqn-true? *)



;; whenever you are in doubt if an equation is valid, test it this way:
;;   * plug-in values for all your variables, and check if it works...
;;   * if it works, it's probably true, but do check again with different values!

Which LISP?

Date: 2005-12-21 12:17 am (UTC)
From: [identity profile] http://users.livejournal.com/_greg/
It seems that one of the great stumbling blocks to the success of LISP is its unbridlable malleability: too many dialects, too much variation among implementations of supposedly the same dialect and too much unique tool-building underlying every project. Despite all of that, and also because of it, LISP is one of my long-time favorite languages. I prefer the Scheme-based dialects. A particularly good set is here:

http://www.plt-scheme.org

Enjoy,

_Greg

lisp

Date: 2006-01-22 12:52 pm (UTC)
From: (Anonymous)
Good to know that there is a windows implementation for LISP.

I'll give it a try.

Visit My Blog (http://mundomatematicas.blogspot.com)

Re: lisp

Date: 2006-01-22 12:59 pm (UTC)
From: [identity profile] gustavolacerda.livejournal.com
hi. Glad to be of help!
How did you find my blog?

February 2020

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags