Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (make-list n el)
- (cond
- ((= n 0) '())
- ((= n 1) (list el))
- (else (cons el (make-list (- n 1) el)))))
- (define (mul-diff-term term sym)
- (if (= (cadr term) (caddr term))
- (diff (car term) sym)
- (car term)))
- (define (range i j)
- (if (= i j)
- (list i)
- (cons i (range (+ i 1) j))))
- (define (zip as bs cs)
- (map list as bs cs))
- (define (gen-mul-terms terms)
- (map (lambda (t) (zip terms (make-list (length terms) t) (range 1 (length terms)))) (range 1 (length terms))))
- (define (diff expr sym)
- (if (not (list? expr))
- (if (eq? expr sym)
- 1
- 0)
- (let ((op (car expr))
- (args (cdr expr)))
- (cond
- ((eq? op '+) (cons '+ (map (lambda (f) (diff f sym)) args)))
- ((eq? op '*) (cons '+ (map (lambda (terms) (cons '* (map (lambda (term) (mul-diff-term term sym)) terms))) (gen-mul-terms args))))
- (else '?))))
- )
- ;(cons '+ (map (lambda (t) (cons '* (map (lambda (s) (mul-diff-term s 'x)) t))) (gen-mul-list '(x x y))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement