mentat-collective / emmy

The Emmy Computer Algebra System.
https://emmy.mentat.org
GNU General Public License v3.0
406 stars 24 forks source link

Add multiple-argument gcd, lcm, patterned on `g/*` and friends #89

Open sritchie opened 3 years ago

sritchie commented 3 years ago

This is how the operation is defined in Scheme:

(define (g:gcd:n args)
  (cond ((null? args) :zero)
        ((null? (cdr args)) (car args))
        (else
         (let lp
             ((as (cddr args))
              (ans (g:gcd:bin (car args) (cadr args))))
           (cond ((null? as) ans)
                 ((g:one? ans) ans)
                 (else
                  (lp (cdr as) (g:gcd:bin ans (car as)))))))))

The task here would be to

kolharsam commented 3 years ago

@sritchie like you'd suggested, I'd like to get started with this!

sritchie commented 3 years ago

That's excellent, @kolharsam ! Some tips:

(fn call
  ([] default-case)
  ([x] (unary-fn x))
  ([x y] (binary-fn x y))
  ([x y & more]
   (reduce call (call x y) more)))

tests go into test/sicmutils/generic_test.cljc

Let me know if I can help with anything!

sritchie commented 3 years ago

@kolharsam assigned you, so this is yours :)