NB. Euclid gojyohou euc1=: 3 : ' <. 2%/\ {: y' euc0=: ],|/@: (/:~@( _2&{.)) NB. Usage: euc0 ^:(i.6) 105 38 NB. Usage:euc1 euc0 ^:(i.5) 105 38 NB. viewer of contunious fraction NB. Usage: 6 mk_cf 19 11x NB. x is repeat times NB. add x to last number(important!) mk_cf=: 4 : 'tmp0 ,: 0, <. _1 x: tmp0=.2%/\(* tmp0) # tmp0=:{: euc0 ^:(i.x) y' NB. **************************** NB. ---------------------------------------- NB. calc pell equation NB. Usage euclid using Extended precision 2 x: NB. euc1 euc0 ^:(i.6) 2 x: %: 5x NB. ---sub script--- s2f =: [: 2&x: %: NB. square to contuneous fraction for pellian D base_mat=: 1 1,:1 0 NB. make base matrisex mat_mp=: [: +/ . * / > NB. innner products for many continueous matrices NB. ---main script----------- find_cf=: 3 : 0 ({. tmp1),euc1 euc0 ^:(i. 12) 1,{: tmp1=: s2f0 y NB. find continueou fraction // i.n is fixed 12 NB. Usage: find_cf 3 NB. not sqrt 3 : NB. find_cf2=: 4 : ' ({. tmp1),euc1 euc0 ^:(i.x) 1,{: tmp1=: s2f0 y NB. dyad type NB. 20 find_cf2 13 // for long term x is length ) calc_pell=: 3 : 0 NB. Pell equation NB. Usage: calc_pell 2 1 1 1 4 --> 8 5,: 3 2 NB. pell equation is x^2-7*sqrt7y^2=1 -- >8^2 -y*3^2=1 NB.y is sqrt(7) ->[2 ,1 1 1 4 ](even) --> even ->drop tail of 4 select. 2=#y case. 1 do. list =. y fcase. do. if. 0 = 2 | # }. y do. list =.}: y else. list=. }: y, }.y end. end. NB.overbar parts is even-> drop last item calc_pell_mat list ) calc_pell_mat=: 3 : 0 list=. y tmp=. ({@> list )(<0 0)}(L:0) (# list) # input data tmp, 8 5,: 3 2 NB. pell equation is x^2-7*sqrt7y^2=1 -- >8^2 -y*3^2=1 NB.y is sqrt(7) ->[2 ,1 1 1 4 ](even) --> even ->drop tail of 4 list =.}: y tmp=. ({@> list )(<0 0)}(L:0) (# list) # input data tmp,{. y) * *: >{: y' NB. check answer NB. Usage: y is D;x y --> lasy is 1 is OK NB. ------------------------------- NB. find continueous fraction s2f0=: 3 : ' tmp0 , 1, (%: y) - tmp0=.<.&%: y' NB. squre to fraction NB. find continueou fraction NB. Usage: