MathGroup Archive 1996

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

Search the Archive

Re: Bug??

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3807] Re: Bug??
  • From: Harald Berndt <haraldb at nature.berkeley.edu>
  • Date: Sat, 27 Apr 1996 00:55:29 -0400
  • Organization: University of California Forest Prodcts Lab
  • Sender: owner-wri-mathgroup at wolfram.com

Theo Pillay wrote:

> I came across the following strange (and highly frustrating) behaviour while
> using MMA to do some simple substitutions. The relevant parts of the text
> file I was using are reproduced below.
> 
> f[x,y] = a[x] y + b[x];
> 
> F1 = f[x,y];
> 
> F2 = y2 (D[f[x,y], y]  - D[r[x], x]) + D[f[x,y],x];
> 
> F3 = r[x];
> 
> eight = -y2 A[x,y] D[F2,y] - 2 y2 B[x,y,y2] D[F3,y] +
>         2 y2 D[F2,y,x] + y2^2 D[F2,{y,2}] - A[x,y] D[F2,x] +
>         B[x,y,y2] D[F2,y2] -
>         2 B[x,y,y2] D[F3,x] - D[B[x,y,y2], y] F1 - D[B[x,y,y2], y2] F2
>         - D[B[x,y,y2],x] F3 + D[F2, {x,2}];  (* 1 *)
> 
> I get different answers for eight depending on the position of line (1). As
> shown I get the wrong answer, but it works if I move (1) up to the previous
> line (i.e next to F2). This is worse than irritating - anybody know what's
> happening here?
> 

The behavior may seem "strange" but it is consistent. One needs to 
remember that one is dealing with a computer: these stupid things do 
exactly what you tell them to do, not what you want them to do. In 
this case, I believe you've become a victim of Mathematica's rich 
variety af assignments and their respective evaluation orders.

There is Set[], SetDelayed[], UpValues, DownValues and whatnot, and 
there are heads of expressions, like Symbol[], Pattern[], etc. ...(For 
example, execute the statements Head[x] and Head[x_], before you ever 
mention x in your Mma session).

Without looking into the detail of your problem formulation too much, 
I'd like to suggest the general rule that if you want to create 
functions as in your first input line you'd do it with SetDelayed[] as 
assignment and Pattern[] type expressions in the function arguments:

f[x_, y_] := a[x] y + b[x]

My hunch is that if you do this consistently in all your function 
definitions, the behavior you get will be much closer to what you 
want.

-- 
______________________________________________________________________
Harald Berndt,                                University of California
Research Specialist                         Forest Products Laboratory

Phone:	510-215-4224                                FAX:			510-215-4299
______________________________________________________________________

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: NDSolve Results
  • Next by Date: Mathematica NDSolve
  • Previous by thread: Re: Bug??
  • Next by thread: Re: Bug??