Jump to content

Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2): Difference between revisions

Line 1,965:
(multiple-value-list (floor u v))))
 
(defmacro absorb-x-term (ng xsource ix)
`(let ((a12 (ng8-a12 ,ng))
(a1 (ng8-a1 ,ng))
Line 1,974:
(b2 (ng8-b2 ,ng))
(b (ng8-b ,ng))
(term (funcall ,xsource ,ix)))
(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 #'(lambda (i) nil)no-terms-thunk))))
(setf ,ng (ng8 a12 a1 a12 a1 b12 b1 b12 b1)))))
 
(defmacro absorb-y-term (ng ysource iy)
`(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 ,iy)))
(setf ,iy (1+ ,iy))
(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 #'(lambda (i) nil)no-terms-thunk))))
(setf ,ng (ng8 a12 a12 a2 a2 b12 b12 b2 b2)))))
 
(defun cf->thunk (cf)
(let (iy(i 0))
#'(lambda ()
(let ((term (cf-ref cf i)))
(setf ,ixi (1+ ,ixi))
(ix 0 term))))
 
(defun no-terms-thunk ()
nil)
 
(defun apply-ng8 (ng8 x y)
(declare (ng8 ng8))
(let ((ng ng8)
(xsource #'(lambda (i) (cf-ref>thunk x i)))
(ysource #'(lambda (i) (cf-ref>thunk y i)))
(ix 0)
(iy 0))
(flet
((main ()
Line 2,063 ⟶ 2,069:
 
when (eq absorb 'x)
do (absorb-x-term ng xsource ix)
 
when (eq absorb 'y)
do (absorb-y-term ng ysource iy))))
 
(make-cf #'main))))
1,448

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.