JAMET

425 Reputation

4 Badges

7 years, 183 days

MaplePrimes Activity


These are questions asked by JAMET

restart;
A002487 := proc (m) local a, b, n; option remember; a := 1; b := 0; n := m; while 0 < n do if type(n, odd) then b := a+b else a := a+b end if; n := floor((1/2)*n) end do; b end proc; listeinverse := proc (L::list) local i; [seq(op(nops(L)-i, L), i = 0 .. nops(L)-1)] end proc; Brocot := proc (n) local c, i, L, M, r; L := NULL; r := 2^n; L := [seq(A002487(i), i = 0 .. r)]; M := listeinverse(L); c[0] := 0, 1/cat(0); for i to r do c[i] := L[i]/M[i] end do; c[r+1] := 1/cat(0); return [seq(c[i], i = 1 .. r+1)], r+1 end proc; for i from 0 to 4 do B || i := Brocot(i) end do;
                              [   1]   
                        B0 := [0, -], 2
                              [   0]   
                             [      1]   
                       B1 := [0, 1, -], 3
                             [      0]   
                          [   1        1]   
                    B2 := [0, -, 1, 2, -], 5
                          [   2        0]   
                    [   1  1  2     3        1]   
              B3 := [0, -, -, -, 1, -, 2, 3, -], 9
                    [   3  2  3     2        0]   
       [   1  1  2  1  3  2  3     4  3  5     5        1]    
 B4 := [0, -, -, -, -, -, -, -, 1, -, -, -, 2, -, 3, 4, -], 17
       [   4  3  5  2  5  3  4     3  2  3     2        0]    
              rang := proc(M::list, a)  ...  end;;
                    /       1\ 
                rang|B2[1], -|;
                    \       2/ 
                / d        \        
                |--- don(x)| t work;
                \ dx       /        

F := proc (N) local a, b, L; L := NULL; L := sort([op({seq(seq(a/b, a = 0 .. b), b = 1 .. N)})]); return L, nops(L) end proc; F(1); F(2); F(3); F(4);
                           [0, 1], 2
                          [   1   ]   
                          [0, -, 1], 3
                          [   2   ]   
                       [   1  1  2   ]   
                       [0, -, -, -, 1], 5
                       [   3  2  3   ]   
                    [   1  1  1  2  3   ]   
                    [0, -, -, -, -, -, 1], 7
                    [   4  3  2  3  4   ]   
rang(F(3)[1], 2/3);
                        /[   1  1  2   ]  2\
                    rang|[0, -, -, -, 1], -|
                        \[   3  2  3   ]  3/

         Fract := proc(P::posint, Q::posint)  
         local p,q:
         for p from 1 to P-1 do
            for q from 1 to Q-1 do
              if (P-p)*q-P*(Q-q)=1 the return (p/q,(P-p)/(Q-q): fi:
          od:od:  
       end;
        debug(Fract);
        Fract(5, 13);
        Fract(77, 200);

 

pellsolve := proc (D::posint) local P, Q, a, A, B, i; if type(sqrt(D), integer) then error "D must be a nonsquare integer" end if; P := 0; Q := 1; a := floor(sqrt(D)); A := 1, a; B := 0, 1; for i do P := a*Q-P; Q := (D-P^2)/Q; a := floor((P+sqrt(D))/Q); A := A[2], a*A[2]+A[1]; B := B[2], a*B[2]+B[1]; if Q = 1 and `mod`(i, 2) = 0 then break end if end do; return A[1], B[1] end proc;
pellsolve(107);
                            962, 93
isolve(x^2-107*y = 13);
       /                             2             \   
      { x = 21 - 107 _Z1, y = 107 _Z1  - 42 _Z1 + 4 }, 
       \                                           /   

         /                             2               \ 
        { x = 86 - 107 _Z1, y = 107 _Z1  - 172 _Z1 + 69 }
         \                                             / 
genpellsolve := proc (D::posint, N::integer) local t, u, L1, L2, sols, x, y; if type(sqrt(D), integer) then error "D must be a nonsquare integer" end if; t, u := pellsolve(D); if 0 < N then L1 := 0; L2 := floor(sqrt((1/2)*N*(t-1)/D)) elif N < 0 then L1 := ceil(sqrt(-N/D)); L2 := floor(sqrt(-(1/2)*N*(t+1)/D)) else return {[0, 0]} end if; sols := {}; for y from L1 to L2 do x := sqrt(N+D*y^2); if type(x, integer) then sols := sols union {[x, y]}; if `mod`(x^2+D*y^2, N) <> 0 or `mod`(2*x*y, N) <> 0 then sols := sols union {[-x, y]} end if end if end do; DEBUG(); return sols end proc;

Debug inefficace

First 31 32 33 Page 33 of 33