Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*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 2002

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

Search the Archive

RE: Re: Evaluation of Conditional Definitions(2)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33933] RE: [mg33819] Re: Evaluation of Conditional Definitions(2)
  • From: "David Park" <djmp at earthlink.net>
  • Date: Tue, 23 Apr 2002 07:14:27 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Dear Hartmut and Allan,

It would be interesting to know WHY that construction forces Update. But, in
any case, it does not seem practical to me from a user's viewpoint. A user
of a package can't be expected to write every expression twice, with and
without the global condition.

Hartmut, in our particular case, the values we are assigning are not usually
numbers but algebraic expressions. So the NValues scheme won't be a help.

I think that a better control of evaluation might be a nice feature for
Mathematica. Right now there are two methods. You can write direct
definitions which are always applied. Or you can write the definitions in
the form of rules and then apply the various rules as needed. I suppose one
could group the rules into various levels of evaluation and then apply
entire groups or rules.

Suppose that you could give your own definitions (of all kinds) a
precedence, and merge them in with the existing precedence system. Then
suppose that your could tell Mathematica to only evaluate to a certain
precedence level. This would be very useful. It might be possible to think
out a clearer and more uniform system of evaluation control. But, perhaps,
it is easier said than done!

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

> From: Wolf, Hartmut [mailto:Hartmut.Wolf at t-systems.com]
To: mathgroup at smc.vnet.net
>
> Dear David and Allan,
>
> this is a very ingenious method to force the Update of g when accessing
> dependend expressions. It might however become a bit nasty to follow all
> involved dependencies when assigning values, e.g. for the case where you
> have many conditional definitions all dependend on the same
> global variable.
> Here I report on an observation I made, where update is forced by only
> introducing a condition on that global variable:
>
> In[1]:= Clear[f, a, UseDefinition, expr]
> In[2]:= f[a] /; UseDefinition := 2
>
> In[3]:= UseDefinition = False;
> In[4]:= expr := f[a] /; UseDefinition
>         expr := f[a]
>
> (* it only works if the Condition is attached to the rhs *)
>
> In[6]:= Information["expr", LongForm -> False]
>         Global`expr
>         expr := f[a] /; UseDefinition
>         expr := f[a]
>
> In[7]:= expr
> Out[7]= f[a]
>
> In[8]:= UseDefinition = True;
> In[9]:= expr
> Out[9]= 2
>
> In[10]:= UseDefinition = False;
> In[11]:= expr
> Out[11]= f[a]
>
> In[12]:= UseDefinition = True;
> In[13]:= expr
> Out[13]= 2
>
> In[14]:= UseDefinition = False;
> In[15]:= expr
> Out[15]= f[a]
>
> Of course all this might be accidential behaviour and unreliable. What
> bothers me is: a precise understanding of the exact evaluation sequence is
> fundamental for mastering programming. Quite obviously mine has shown to
> have holes.
>
>
>
> David, possibly for your application it might suffice to assign NValues to
> your symbol. So you might easily decide when you want to have kept the
> results of a calculation in symbolical or when in numerical form:
>
> In[126]:= Clear[f, g, a]
>
> In[127]:= N[f[a], ___] = 2
>           N[g[a], ___] = 3
> Out[127]= 2
> Out[128]= 3
>
> In[129]:= NValues /@ {f, g}
> Out[129]= {{HoldPattern[N[f[a], ___]] :> 2},
>            {HoldPattern[N[g[a], ___]] :> 3}}
>
> In[130]:= expr := f[a] + g[a]
>
> In[131]:= expr
> Out[131]= f[a] + g[a]
>
> In[141]:= expr + 5 // N
> Out[141]= 10.
>
> Observe that the result cannot be a precise number, yet of any precision.
>
>
> Another application:
>
> In[142]:=
> a = {{Cos[\[CurlyPhi]], Sin[\[CurlyPhi]]},
>      {-Sin[\[CurlyPhi]], Cos[\[CurlyPhi]]}}
>
> In[144]:= N[\[CurlyPhi]] = \[Pi]/3;
>
> In[145]:= HoldForm[Transpose[a].{1, 0}] // TraditionalForm
> Out[145]//TraditionalForm=
> \!\(\*FormBox[TagBox[\(a\^T . {1, 0}\), HoldForm], TraditionalForm]\)
>
> In[146]:= % // ReleaseHold
> Out[146]=
> {Cos[\[CurlyPhi]], Sin[\[CurlyPhi]]}
>
> In[147]:= % // N
> Out[147]= {0.5, 0.866025}
>
> In[149]:= \!\(\@3/2 // N\)
> Out[149]= 0.866025
>
> yours, Hartmut
>
>
>



  • Prev by Date: Re: Why No Solution Using Solve?
  • Next by Date: RE: Re: Evaluation of Conditional Definitions(2)
  • Previous by thread: Re: Evaluation of Conditional Definitions(2)
  • Next by thread: RE: Re: Evaluation of Conditional Definitions(2)