       Re: Mathematicas simplifications

• To: mathgroup at smc.vnet.net
• Subject: [mg96326] Re: Mathematicas simplifications
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Wed, 11 Feb 2009 05:24:38 -0500 (EST)
• Organization: The Open University, Milton Keynes, UK
• References: <gmrmfk\$a0f\$1@smc.vnet.net>

```In article <gmrmfk\$a0f\$1 at smc.vnet.net>,
Kilian Kilger <kilian at nihilnovi.de> 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
>
> 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,

"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
them.

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

In:= SquareFreeQ[Divisors[n]]

Out= True

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

Out= Divisors[n]

In:= Select[n, SquareFreeQ]

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

Out= Select[n, SquareFreeQ]

In:= Select[n[], SquareFreeQ]

Out= n[]

Regards,
--Jean-Marc

```

• 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