Boolean function $f$ such that it tells whether an integer only has factors from a factor base (in maple)

42 Views Asked by At

Suppose we are given a factor base $\beta$ and we wants to write a Boolean function $f$ such that it tells whether an integer only has factors in $\beta$ or not.

If my factor base is $\beta=\left\{ 2, 3, 5,7 \right\}, f(10)=f(2 \times 5)=\ $yes and $f(22)=f(2 \times 11)= \ $no. How do you write a such function in maple? I'm new to maple and only know basic built-in functions like ifactor.

1

There are 1 best solutions below

2
On BEST ANSWER

First, the ifactors command, some list-indexing basics, and conversion of a list to a set.

ifactors(336);

       [1, [[2, 4], [3, 1], [7, 1]]]

ifactors(336)[2];

          [[2, 4], [3, 1], [7, 1]]

ifactors(336)[2][1..,1];

                 [2, 3, 7]

{ifactors(336)[2][1..,1][]};

                 {2, 3, 7}

So now we can build a handy, re-usable procedure.

T:=proc(n::integer, b::set(integer))
    {ifactors(n)[2][1..,1][]} subset b;
end proc:

B:={2,3,5,7}:

T(10,B);

               true

T(11,B);

              false

T(28,B);

               true