; functions for finding the statistics of a list of numbers
; All functions assume they are given a list of numbers and return a number
; Some functions need minimum of one number in the list and some at least two.
; Qualities: these a simple demonstartion that are not designed to be fast
; or accurate
(define (square x) (* x x))
(define ( sumsquares x) ( sum (squares x) ))
(define ( squaresum x) ( square (sum x) ))
(define ( sd x) (sqrt(float (var x)))); sd means standard deviation
(define ( mean x) ( / (sum x) (length x) ))
(define ( var x) ; var is the variance of the numbers in the list
(/ (- (sumsquares x)
(/ (squaresum x)
(length x)
)
)
(- (length x) 1
)
);/
);define
; Our LISP has length predefined
; (define (length x)
; (if (null x) 0 (1+ (length (cdr x)))
; )
;)
(define (sum x); add up the items in a list
( if (null x) 0 (+ (car x) (sum (cdr x)))
)
)
(define ( squares x) ; replace each number in list by its square
( if (null x) NIL (cons (square(car x)) (squares(cdr x))))
)