Back in 2004 I taught a minicourse on J in the number theory classroom
at the national math meetings. I might be able to dig up hard copies,
but the source for the 150-200 p booklet was an obscure version of Tex I
can no longer process. However, in response to a query in April 2009 I
updated the continued fraction prelab to J6.02 and offer the script:
NB. nt_g Continued Fractions and Pell's Equation
5 (+%) 3x
(+%)/1 1 1 1x
1 (+%) 1 (+%) 1 (+%) 1x
(+%)/\1 1 1 1 1 1x
2 x: (+%)/\1 1 1 1 1 1x
NB. finite continued fraction to convergents
fcf_to_cv=:2&x:@:((+%)/\)@:x:
fcf_to_cv 3 1 2 1
NB. rational to finite continued fraction
r_to_fcf=: 3 : 0
'r0 r1'=.2 x: y
z=.i.0
while. r1 ~: 0 do.
q=.<. r0 % r1
z=.z,q
'r0 r1'=. r1,r0-q*r1
end.
z
)
x:1p1
r_to_fcf x: 1p1
r_to_fcf 15r4
fcf_to_cv r_to_fcf 15r4
NB. finite continued fraction to rational
fcf_to_r=: %/@:{:@:fcf_to_cv
fcf_to_r 3 1 3
fcf_to_r 1 2 3 4 5 2 1
NB. quadratic poly translation
qp_tr=: 0 1 1&*@] + (] p. -@[) , (-@+:@[ * {:@]),0:
3 qp_tr 0 0 1
10 qp_tr 3 1000 10
NB. floor of root of quadratic poly
p. 6 _5 1
p. 1 _5 6
fr_qp =: >./@:<.@:>@:{:@p.
]t=:fr_qp _10 0 1
(-t) qp_tr _10 0 1
p. _10 0 1
p. (-t) qp_tr _10 0 1
NB. quadratic poly to periodic continued fraction
NB. (extra: list of polys)
qp_to_pcfx=:3 : 0
qpl=.,: qp=.(**@{:) y
z=.i.0
while. -. qp e. }: qpl do.
t=.fr_qp qp
z=.z,t
qp=.(**@{:)|. (-t) qp_tr qp
qpl=.qpl,qp
end.
z;qpl
)
qp_to_pcfx _3 0 1
NB. quadratic poly to periodic continued fraction
qp_to_pcf =: 3 : 0
'z qpl'=. qp_to_pcfx y
i=.(}: i. {:)qpl
(i{.z);i}.z
)
qp_to_pcf _3 0 1
; qp_to_pcf _106 0 1
fcf_to_cv ; qp_to_pcf _106 0 1
]'x y'=._2{fcf_to_cv ;qp_to_pcf _106 0 1
(x^2) - 106 *y^2
c_f_unit=: _2&{@:fcf_to_cv@:;@:qp_to_pcf@:(,&0 1)@:-"0
n=: 101 102 103 105 106 107 108 109
]'x y'=:|:c_f_unit n
(x^2) - n *y^2
sel_sqf=: <&2@:(>./)@:{:@:(__&q:)"0 # ]
(;"0 1 c_f_unit)sel_sqf 1000+i.20
NB. e
cv_e=: 3 : '2,,1,.~1,.+:>:i.y'
cv_e 4
cv_e 7
fcf_to_r cv_e 5
18j16 ": fcf_to_r cv_e 5
18j16 ": ^1
den2_dp=:<:@#@":@*:@{:@:(2&x:)
fmte=:(j./@:(2 0&+)@: den2_dp ": ])
fmte fcf_to_r cv_e 4
fmte fcf_to_r cv_e 10
fmte fcf_to_r cv_e 20
NB. pi
r_to_fcf x: 1p1
r_to_fcf (<.@o. %]) 10^15x
r_to_fcf (<.@o. %]) 10^30x
r_to_fcf (<.@o. %]) 10^50x
fcf_to_r\3 7 15 1 292 1 1 1 2 1 3 1 14
--
Clifford A. Reiter
Lafayette College, Easton, PA 18042
http://webbox.lafayette.edu/~reiterc/
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm