Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2): Difference between revisions
Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2) (view source)
Revision as of 13:53, 10 March 2023
, 1 year ago→{{header|Common Lisp}}
Line 1,965:
(multiple-value-list (floor u v))))
(defmacro absorb-x-term (ng xsource
`(let ((a12 (ng8-a12 ,ng))
(a1 (ng8-a1 ,ng))
Line 1,974:
(b2 (ng8-b2 ,ng))
(b (ng8-b ,ng))
(term (funcall ,xsource
(setf ,ix (1+ ,ix))▼
(if term
(let ((ng^ (ng8 (+ a2 (* a12 term))
Line 1,986 ⟶ 1,985:
;; Replace the x source with one that never
;; returns a term.
(setf ,xsource #'
(setf ,ng (ng8 a12 a1 a12 a1 b12 b1 b12 b1)))))
(defmacro absorb-y-term (ng ysource
`(let ((a12 (ng8-a12 ,ng))
(a1 (ng8-a1 ,ng))
Line 1,998 ⟶ 1,997:
(b2 (ng8-b2 ,ng))
(b (ng8-b ,ng))
(term (funcall ,ysource
(if term
(let ((ng^ (ng8 (+ a1 (* a12 term)) a12
Line 2,010 ⟶ 2,008:
;; Replace the y source with one that never
;; returns a term.
(setf ysource #'
(setf ,ng (ng8 a12 a12 a2 a2 b12 b12 b2 b2)))))
(defun cf->thunk (cf)
#'(lambda ()
(let ((term (cf-ref cf i)))
(defun no-terms-thunk ()
nil)
(defun apply-ng8 (ng8 x y)
(declare (ng8 ng8))
(let ((ng ng8)
(xsource
(ysource
▲ (ix 0)
▲ (iy 0))
(flet
((main ()
Line 2,063 ⟶ 2,069:
when (eq absorb 'x)
do (absorb-x-term ng xsource
when (eq absorb 'y)
do (absorb-y-term ng ysource
(make-cf #'main))))
|