Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Re: Ask Mathematica to sub for a long expression

  • To: mathgroup at smc.vnet.net
  • Subject: [mg71947] Re: [mg71921] Re: Ask Mathematica to sub for a long expression
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Tue, 5 Dec 2006 06:04:47 -0500 (EST)
  • References: <ekp4o4$2fq$1@smc.vnet.net><ekudat$86k$1@smc.vnet.net> <200612041138.GAA02860@smc.vnet.net>

On 4 Dec 2006, at 20:38, carlos at colorado.edu wrote:

> aaronfude at gmail.com wrote:
>> Hi,
>>
>> Thanks for all the responses. It doesn't quite work for me, but maybe
>> with a little extra expertise it will. The problem is that that  
>> pattern
>> is not always obvious w/o extra algebra. The basic problem is
>> summarized in the fact that the following doesn't work the way I'd  
>> like
>> it to:
>>
>> -a-b/.a+b->c
>>
>> 2a+2b/.a+b->c
>>
>> Many thanks in advance!
>>
>> Aaron Fude
>
> Replacing nontrivial patterns sometimes works, sometimes it doesnt.
> It may depends on FullForm details.  This violates a basic tenet of
> computer science: user-level results should not depend on internal
> representation.

This  would be true if FullForm was "internal representation".  
However, it is not: Mathematica's programming language *is* exactly  
what FullForm shows; all other forms are just shortcuts, "macros" or  
visually pleasing representations of it. In my opinion, if you don't  
think in FulLForm you can't program fluently in Mathematica.


> Here is a simple example.
>
> ClearAll[f,a,b,c,i];
> f[b_,c_]:=1/(c+b^2);
> v=Table[{i,f[b,i]/.b^2->16},{i,-6,6}];
> ListPlot[v,PlotJoined->True];
>
> Try to track the source of the error message and the plot gap.
>
Yes, this is a fair test of your understanding of the Mathematica  
programming language: if you can't see immediately that this will not  
work you have some learning to do. In fact, this involves  
understanding not just of FullForm but also of the evaluation process  
- another essential aspect of Mathematica programming. In this case,  
as in many similar ones,  a simple solution is to insert Evaluate int  
the right place:


v=Table[Evaluate[{i,f[b,i]/.b^2->16}],{i,-6,6}];

ListPlot[v,PlotJoined->True];

Andrzej Kozlowski
Tokyo, Japan



  • Prev by Date: Re: Re: Pythonika: Python in Mathematica
  • Next by Date: Re: Drawing function with 3 variables in a graph
  • Previous by thread: Re: Re: Ask Mathematica to sub for a long expression
  • Next by thread: Re: Ask Mathematica to sub for a long expression