Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: Evaluation question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82253] Re: Evaluation question
  • From: Yaroslav Bulatov <yaroslavvb at gmail.com>
  • Date: Tue, 16 Oct 2007 03:29:43 -0400 (EDT)
  • References: <200710120656.CAA04613@smc.vnet.net><fepuqv$hvl$1@smc.vnet.net>

Perhaps the following example makes more more sense --

Block[{f},
 SetAttributes[f, NumericFunction];
 f[1, 2] // NumericQ // TracePrint;
 Unevaluated[f[1, 2]] // NumericQ // TracePrint;
 ]

In the first example, the arguments of f are evaluated.
In the second example, Unevaluated wrapper prevents evaluation of the
arguments, so NumericQ doesn't "know" that f's arguments are numeric.


Yaroslav

On Oct 14, 10:30 pm, Andrzej Kozlowski <a... at mimuw.edu.pl> wrote:
> I think this involves a rather subtle difference between an
> expression and its value. (It is sometimes obscured by the fact that
> soem expressions evaluate to themselves so are their own values). In
> this case, it is the values of Plus that are considered numerical,
> but values are obtianed after evaluation. The unevaluated expression
> Plus[1,2] is not itself numerical.
>
> Andrzej Kozlowski
>
> On 14 Oct 2007, at 20:10, Szabolcs Horv=E1t wrote:
>
> > Andrzej Kozlowski wrote:
> >> On 14 Oct 2007, at 08:00, Andrzej Kozlowski wrote:
> >>> Wihtout evaluation 1+2 is just a symbol and not the number 3 so
> >>> NumericQ returns False.
> >> I should have been more precise. Unevaluated 1+2 is an expression
> >> (rather than a symbol); in fact it is the expression Plus[1,2],
> >> which of course is not numeric. It's value is, of course, numeric, =
> >> but that is obtained only after evaluation.
>
> > But Plus has the attribute NumericFunction, therefore it should be
> > considered "numerical" whenever all of its arguments are numerical.
>
> > For example, see In[2] and In[3] below.  f[1,2] stays unevaluated,
> > but NumericQ[f[1,2]] still returns True because 'f' has the
> > attribute NumericFunction, and all of its arguments (1 and 2) are
> > numerical.
>
> >>>> In[1]:= NumericQ[Unevaluated[1+2]]//Trace
> >>>> Out[1]= {NumericQ[1+2],False}
>
> >>>> In[2]:= SetAttributes[f,NumericFunction]
>
> >>>> In[3]:= NumericQ[f[1,2]]//Trace
> >>>> Out[3]= {NumericQ[f[1,2]],True}
>
> >>>> In[4]:= NumericQ[Unevaluated[f[1,2]]]//Trace
> >>>> Out[4]= {NumericQ[f[1,2]],False}
>
> >>> I do not find this surprising. Wihtout evaluation 1+2 is just a
> >>> symbol and not the number 3 so NumericQ returns False.
>
> > --
> > Szabolcs




  • Prev by Date: Re: format mixed integers & floats with text styling (see )
  • Next by Date: Re: Releasing several Holds simultaneously
  • Previous by thread: Re: Evaluation question
  • Next by thread: combine implicitplot with findroot