Added cardano.

Pascal J. Bourguignon [2018-12-29 16:07]
Added cardano.
Filename
future/cardano.lisp
diff --git a/future/cardano.lisp b/future/cardano.lisp
new file mode 100644
index 0000000..8ea7f76
--- /dev/null
+++ b/future/cardano.lisp
@@ -0,0 +1,13 @@
+(defun cardano (a b c d)
+  "Solve a 3rd degree equation."
+  (let* ((Q   (/ (- (* 3 a c) (* b b))
+                 9 a a))
+         (R   (/ (- (* 9 a b c) (* 27 a a d) (* 2 b b b))
+                 54 a a a))
+         (vqr (sqrt (+ (* q q q) (* r r))))
+         (S   (expt (+ r vqr) 1/3))
+         (U   (expt (- r vqr) 1/3))
+         (x1  (- (+ s u) (/ b 3 a)))
+         (x2  (+ (/ (+ s u) -2) (/ b -3 a) (* #C(0 1) (/ (sqrt 3)  2) (- s u))))
+         (x3  (+ (/ (+ s u) -2) (/ b -3 a) (* #C(0 1) (/ (sqrt 3) -2) (- s u)))))
+    (list x1 x2 x3)))
ViewGit