MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Mathematicas simplifications

In article <gmrmfk$a0f$1 at>,
 Kilian Kilger <kilian at> wrote:

> if I type in Mathematica 7 for example
> Select[Divisors[n],SquareFreeQ]
> It gives me 
> Divisors[n]
> as a response, which is wrong. If I type
> f[n_] := Select[Divisors[n],SquareFreeQ]
> and then 
> f[4]
> it gives me 
> {1,2}
> which is correct. If I type (afterwards)
> f[n]
> again the wrong answer "Divisors[n]" is shown. What am I doing wrong? Same 
> happens in many other circumstances. 

The result you obtain might be surprising; it is not wrong however, 
though the documentation for Select is misleading somehow. It reads:

"Select[list, crit] picks out all elements e_i of list for which 
crit[e_i] is True."

Indeed, there is no need for the first argument to be a list. The first 
argument can be any *non-atomic* expression, that is 'n' will generate 
an error whereas 'n[]' will not. 'n' alone is a *symbol*, i.e. an atom 
that cannot be decomposed further, while 'n[]' is an *expression* with 
head 'n' and no arguments []. 

The situation is similar for SquareFree[expr], which "gives True if expr 
is a square-free polynomial or number, and False otherwise," but at 
least it is clear (at least for experienced users) that 'expr' can be 
any valid Mathematica expression. 

Arguably, the documentation for Select[] should have read Select[expr, 
crit] to give a clue that expressions are accepted, not just lists 
(which are just a subset of all possible Mathematica expresssions).

Also, keep in mind that Mathematica works on symbolic expressions as 
string of tokens and do not attempt to add any mathematical meaning to 

I hope that the above comment has shed some light on the issue. Here is 
an illustration of the main points:

In[1]:= SquareFreeQ[Divisors[n]]

Out[1]= True

In[2]:= Select[Divisors[n], SquareFreeQ]

Out[2]= Divisors[n]

In[3]:= Select[n, SquareFreeQ]

During evaluation of In[3]:= Select::normal: Nonatomic expression \
expected at position 1 in Select[n,SquareFreeQ]. >>

Out[3]= Select[n, SquareFreeQ]

In[4]:= Select[n[], SquareFreeQ]

Out[4]= n[]


  • Prev by Date: Re: testing if a point is inside a polygon
  • Next by Date: Re: Re: testing if a point is inside a polygon
  • Previous by thread: Re: Mathematicas simplifications
  • Next by thread: Re: Mathematicas simplifications