Factoring in Maple

321 Views Asked by At

I am currently working on writing a procedure in Maple. What I need to be able to do is factor a number. The few commands I know to help with this are;

ifactor(12); (2)^2(3)

divisors(12); {1, 2, 3, 4, 6, 12}

But what I am wanting is to factor a larger number and have Maple give it to me in pairs. For example

12 - (1,12),(2,6),(3,4)

3

There are 3 best solutions below

0
On
Pairs:= proc(N::posint)
local 
     L:= [numtheory:-divisors(N)[]],
     n:= nops(L),
     k
;
     [seq([L[k],L[n-k+1]], k= 1..iquo(n,2)+irem(n,2))]
end proc;
4
On

My attempt is very basic in shape than the other good way.

[> with(numtheory);
   a := divisors(12): nops(a):
   for i to nops(a) do
   for j to nops(a) do
      if `and`(a[i]*a[j] = 12, i <= j) then print([a[i], a[j]])
      end if;
   end do;
   end do;


                                 [1, 12]
                                 [2, 6]
                                 [3, 4]
0
On
P:= n -> select(p->(p[1]<=p[2]),[seq([d,n/d], d=numtheory:-divisors(n))]);