forked from incanter/incanter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added incanter.symbolic, Bryce Nyeggen's port of symbolic differentia…
…tion from SICP, see http://mitpress.mit.edu/sicp/full-text/sicp/book/node39.html
- Loading branch information
Showing
2 changed files
with
128 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
;;; symbolic-test-cases.clj -- Unit tests of Incanter functions | ||
|
||
;; by David Edgar Liebke http://incanter.org | ||
;; May 3 2010 | ||
|
||
;; Copyright (c) David Edgar Liebke, 2009. All rights reserved. The use | ||
;; and distribution terms for this software are covered by the Eclipse | ||
;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | ||
;; which can be found in the file epl-v10.html at the root of this | ||
;; distribution. By using this software in any fashion, you are | ||
;; agreeing to be bound by the terms of this license. You must not | ||
;; remove this notice, or any other, from this software. | ||
|
||
|
||
|
||
(ns incanter.symbolic-tests | ||
(:use clojure.test | ||
(incanter core symbolic))) | ||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
;; UNIT TESTS FOR incanter.stats.clj | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
(deftest deriv-test | ||
(is (= (deriv (+ x 3) x) 1)) | ||
(is (= (deriv (* x y) x) 'y)) | ||
(is (= (deriv (* (* x y) (+ x 3)) x) '(+ (* (+ x 3) y) (* x y)))) | ||
(is (= (deriv (* (* x y) (+ x 3)) y) '(* (+ x 3) x))) | ||
|
||
(is (= (deriv (* x y (+ x 3)) x) '(+ (* y (+ x 3)) (* y x)))) | ||
(is (= (deriv (* x y (+ x 3)) y) '(* (+ x 3) x))) | ||
|
||
(is (= (deriv (sin x) x) '(cos x))) | ||
(is (= (deriv (cos x) x) '(* -1 (sin x)))) | ||
|
||
(is (= (deriv (sin (* x y)) y) '(* x (cos (* x y))))) | ||
|
||
(is (= (deriv (pow x 3) x) '(* 3 (pow x 2)))) | ||
(is (= (deriv (** x 3) x) '(* 3 (pow x 2)))) | ||
|
||
(is (= (deriv (pow x 3) x 2) '(* 3 (* 2 x)))) | ||
|
||
(is (= (deriv (* x y (+ x 3)) x 2) '(+ y y))) | ||
(is (= (deriv (* x y (+ x 3)) x 3) 0)) | ||
|
||
(is (= (deriv (+ (* 3 x) (* 8 x)) x) 11)) | ||
) |