这是寻找整数幂根但在 clojure 中的重新散列:
我如何找到一个数字的所有整数根?
所以我想要一个功能:
(defn roots [ex num] .....)
调用时给出:
(roots 4 81) => [3, -3, 3i, -3i]
    我为 Maths 找到的最好的库是 apache commons math library
使用将此添加到您的 project.clj
[org.apache.commons/commons-math3 "3.0"]
它内置了一个 nth-root 方法,以下可以是包装器:
(导入 org.apache.commons.math3.complex.Complex)
(定义复杂
  ([re] (复数 re 0))
  ([我]
      (Complex/valueOf re im)))
(defn nth-root [#^Complex cm] (seq (.nthRoot cm)))
(defmethod 打印方法
  复杂的
  [这个w]
  (print (format "(%f %fi)" (re this) (im this))))
(nth-root (复数 1 4) 6)
;; => ((1.235513 0.277543i) (0.377397 1.208757i) (-0.858115 0.931214i) (-1.235513 -0.277543i) (-0.377397 -1.208757i) (0.858115 -0.931214i)
    user> (defn nth-root
          [n x]
        (long (Math/pow x (/ 1.0 n))))
#'user/nth-root
user> (nth-root 4 81)
3
老实说,我不知道在 Clojure 中处理复数的标准化方法。您可能必须Complex使用defrecord.