[Date Index]
[Thread Index]
[Author Index]
# Re: Impossible?
Arturas Acus wrote:
>
> Hello,
>
> I would like to construct a function which gives me an absolute Level of
> subexpression in expression. For example I want:
>
> a*(b+c*(d+AbsoluteLevelQ[e]))
>
> evaluate to
>
> Level[a*(b+c*(d+e)),e].
> ( AbsoiuteLevelQ climbs up until reaches In[], after that calls Level
> )
>
> More generally, I would like to control absolute level (level in respect
> to In[%]) at which patter matching take place. For example if pattern
> matches at Level n>3, then rule is applied, but if it matches at
> Level n<3 then not.
>
> I suspect, that evaluation machinery here is hardly involved. Do
> Mathematica language provides tools for such a control? Please comment
> if solution don't exist.
>
> Arturas Acus
> Institute of Theoretical
> Physics and Astronomy
> Gostauto 12, 2600,Vilnius
> Lithuania
>
> E-mail: acus@itpa.lt
> Fax: 370-2-225361
> Tel: 370-2-612906
Every mathematica expression is a list of some sort. If you type in an
algebraic expression like:
In[6]:=
f=x*Sin[y]+3*Exp[-x^3-4 x +7];
The various "elements" of f can be found just like in a regular list. I
show a few examples below:
In[7]:=
f[[0]]
Out[7]=
Plus
In[8]:=
f[[1]]
Out[8]=
3*E^(7 - 4*x - x^3)
In[9]:=
f[[2]]
Out[9]=
x Sin[y]
In[12]:=
Dimensions[f[[1]]]
Out[12]=
{2}
In[13]:=
f[[1,1]]
Out[13]=
3
In[14]:=
f[[1,2]]
Out[14]=
E^(7 - 4*x - x^3)
You might also check out the LeafCount,TreeForm, Level, Depth, Position
etc. in chapter 2.1.4 of the mathematica book. In particular,
something like
MatrixForm[Table[Level[f,n],{n,1,Depth[f]}]]
can give you a graphic representation of the data available and
Level[f,Depth[f]]
returns a list of all possible subexpressions.
{3, E, 7, -4, x, -4*x, -1, x, 3, x^3, -x^3, 7 - 4*x - x^3,
E^(7 - 4*x - x^3), 3*E^(7 - 4*x - x^3), x, y, Sin[y],
x*Sin[y]}
To find the complete location of one of those elements, say 7, use:
Position[f,7,Depth[f]]
which returns an exact description of where in the expression you can
find that subexpression:
{{1,2,2,1}}
Hope that helps.
--
Remove the _nospam_ in the return address to respond.
Prev by Date:
**Re: Mathematica Plot [help]**
Next by Date:
**Re: Left and right quotes**
Prev by thread:
**Re: Impossible?**
Next by thread:
**Re: Impossible?**
| |