function f = factor(x)
%FACTOR Symbolic factorization.
%   FACTOR(S), where S is a SYM matrix, factors each element of S.
%   If S contains all integer elements, the prime factorization is computed.
%   To factor integers greater than 2^52, use FACTOR(SYM('N')).
%
%   Examples:
%
%      factor(x^9-1) is 
%      (x-1)*(x^2+x+1)*(x^6+x^3+1)
%
%      factor(sym('12345678901234567890')) is
%      (2)*(3)^2*(5)*(101)*(3803)*(3607)*(27961)*(3541)
%
%   See also FACTOR, SIMPLIFY, EXPAND, SIMPLE, COLLECT.

%   Copyright (c) 1993-98 by The MathWorks, Inc.
%   $Revision: 1.10 $  $Date: 1997/11/29 01:05:38 $

% Try the integer factorization first.
% If it fails, try the symbolic expression factorization.

[f, stat] = maple('map','ifactor',x);
if stat == 0
   f = char(f);
   f(findstr(f,'`')) = [];
   f = sym(f);
elseif (stat == 2) & strcmp('Error, (in ifactor) invalid arguments',f)
   f = maple('map','factor',x);
else
   error(f);
end;
