- .
> Funny. While it was considered obsolete and superseded by
>> FoldList in
>> Mathematica 2, Mathematica 1 (!) already did
> have a function Accumulate, defined as
> Accumulate[f, g[e1, e2, e3, ...]] <==> g[e1, f[e1, e2], f[f[e1,
>> e2], e3],
>> ...]
> so that
> Accumulate[Plus, Range[5]] <==> {1, 3, 6, 10, 15}
> However, Accumulate in Mathematica 1 clearly was not restricted
>> to Plus
>> but rather specifically intended for dealing
> with functions that take exactly two arguments - so, I believe that
>> Accumulate in Mathematica 6 is much less usable
> than the former in Mathematica 1.
> Maybe I'm missing something here - but what was the rationale behind
>> re-implementing Accumulate in such a restricted
> version now?
>> /oskar
>> You are missing just one thing - performance. Accumulate in this
> restricted sense is incredibly fast - and extremly useful.
> Andrzej Kozlowski
>
--
DrMajorBob@bigfoot.com
===
Subject: Re: The uses of Condition (/;)
> Usage C is described in the Mathematica 6 documentation under Condition -
More
> information (and nowhere else I think)
Yes, that's what I meant by hidden: it's hidden under More
information. I thought that using /; with Module is completely
different from the other two uses, therefore it would deserve an
explanation at a more prominent place in the documentation.
But Ingolf Dahl's and your examples showed that this is not the
case---in fact, B and C are sub-cases of the same kind of usage. My
confusion came from not realizing that /; has a higher precedence than ;.
Szabolcs
> in the form
lhs:=Module[{vars},rhs/;test]
They say that this usage allows local variables to be shared between
> test and rhs
> On the same Documentation page , under Scope, there is a concrete
> example of usage C.
f[x_] := Module[{u}, u^2 /; ((u = x - 1) > 0)]
here it is seen that the pattern (u) is a local variable.
> In your examples you were using x, a global variable, so no difference
> was apparent.
> In C, condition is evaluated before definition, for example (please
> make sure you have Remove[f] before typing this:
f[x_] := Module[{u}, (Print [u]; u^2) /; ((u = x - 1) > 0)]
> f[3]
> 2
> 4
> u only acquires a value after cond is evaluated and then def (Print
> [u]; u^2) will be evaluated.
> A and B are very similar, but A is considered a bit faster, because
> evaluation stops immediately if the cond is not safisfied
===
Subject: Re: The uses of Condition (/;)
> Assuming that you mean (as in your examples for testing)
> A. pattern /; condition := definition
> I think A & B do yield the same results.
> Despite the fact that Condition has a higher Precedence than
> SetDelayed and RuleDelayed, Condition seems to apply itself the
> entire assignment or rule, not just the definition. Perhaps the
> documentation emphasizes both A and B to bring out this somewhat
> unexpected behavior.
>
No, Condition does not apply itself to the entire assignment or rule.
the 2 definitions
j[x_] := Sqrt[x] /; x > 0
jj[x_] := (Sqrt[x] /; x > 0)
are equivalent. Condition (/; ) attaches itself to the nearest
expression on its left, in accordance to the precedence levels.
Indeed Condition is an exotic little beast.
Let's observe it in its natural habitat...
Evaluate the following:
On[]
j[1]
j[-1]
Off[]
As you see, Condition does not appear anywhere. Instead we see
RuleCondition and $Conditionhold, twoTop Secret internal symbols.
Let's now observe Condition outside its natural habitat...
Evaluate the following:
On[]
x=3
Sqrt[x] /; x > 0
Off[]
Here we finally see Condition in action, but...it does not really do
very much. For some reason x gets replaced in the first argument, but
not in the second. Please note that Condition has HoldAll attribute.
Not yet satisfied we try...
On[]
Sqrt[x] /; 3 > 0
Sqrt[x] /; True
Sqrt[x] /; False
Off[]
As we see, when we use Condition by itself, It reappears in the trace,
but there is no (simple?) way to make it evaluate to something
meaningful, even of the test is clearly passed or rejected.
It seems that Condition can only be used in the well-known ways, never
by itself
So my question is: what does Condition evaluates to, if test is True.
And if test is False?
Apparently there is no easy answer
===
Subject: Re: Re: The uses of Condition (/;)
> Changing slightly topic:
> In the same Condition documentation page we find:
> {6, -7, 3, 2, -1, -2} /. x_ /; x < 0 -> w
> giving
> {6, w, 3, 2, w, w}
> and that 's ok. The x_ stand for the individual elements in the list
But why then
> {6, -7, 3, 2, -1, -2} /. x_ -> w
> gives
> w
> instead of
> {w,w,w,w,w,w} ?
> shouldn't the x_ still stand for the individual elements in the list?
>
This is because in the first example the entire list does not satisfy
the condition and the second cases it does (there is no condition).
The diffeence is essentially the same as here:
{6, -7, 3, 2, -1, -2} /. x_ /; (Head[x] == Integer) -> w
{w, w, w, w, w, w}
{6, -7, 3, 2, -1, -2} /. x_ /; (Head[x] == List) -> w
w
If you use Trace on both you will see that the actual pattern
matching is exactly the same.
Andr
===
Subject: Re: The uses of Condition (/;)
> Changing slightly topic:
In the same Condition documentation page we find:
{6, -7, 3, 2, -1, -2} /. x_ /; x < 0 -> w
> giving
> {6, w, 3, 2, w, w}
> and that 's ok. The x_ stand for the individual elements in the list
> But why then
> {6, -7, 3, 2, -1, -2} /. x_ -> w
> gives
> w
> instead of
> {w,w,w,w,w,w} ?
shouldn't the x_ still stand for the individual elements in the list?
This is because x_ matches the complete list {6, -7, 3, 2, -1, -2}. Try
x_?NumberQ instead or use a level specification:
Replace[{6, -7, 3, 2, -1, -2}, x_ -> w, {1}]
Szabolcs
===
Subject: Re: The uses of Condition (/;)
> I think the real example in case C should be
> h1[x_] := Module[{}, (Print[def]; x) /; (Print[cond]; x > 5)]
> because your h[x_] expression is interpreted as
> h[x_] := Module[{}, Print[def]; (x /; (Print[cond]; x > 5))]
> which does not correspond to the case C. It instead corresponds to
> D. pattern := Module[{}, expr1; (definition /; condition)]
> This leads us to an answer to your question. We define a new pattern, a
> modification of pattern B:
> E. pattern := (expr1; (definition /; condition))
> with the example
> g1[x_] := (Print[expr1]; ((Print[def]; x) /; (Print[cond]; x >
5)))
> In[8]:= g1[0]
> During evaluation of In[8]:= expr1
> During evaluation of In[8]:= cond
> Out[8]= g1[0]
> This function behaves similar to the D function, and we see that Module
is
> just a wrapper. Module here is useful if we want to share local variables
> between the definition and the expression, so that we can transfer sub
> results and do not have to repeat calculations.
> I do not see how to modify A to get the same kind of evaluation as with
the
> case E.
> See also the MathGroup discussion about precedence of operators earlier
this
> week.
>
precedence than ;)!
So in fact cases B and C are sub-cases of the same usage, and Module
has no importance. All that matters is that Condition[] be the
expression that would be returned by the function. (Well, almost:
Condition[] must be returned by a restricted set of built-ins, like
CompoundExpression or Module. f[x_] := Identity[x /; x > 5] does not
work. But this is understandable, since in Mathematica the return
value is not a well defined concept.)
Szabolcs
===
Subject: Re: Simple equation won't plot
> When I type following commands in Mathematica 6.0.1:
> m = 70; a = 0.08; x0 = 5000; g = 9.81;
> x[t_] = x0 - m*Log[Cosh[t*Sqrt[g*a]/Sqrt[m]]]/a;
> P1ot[x[t], {t, 0, 60}]
> I don't get a plot, but instead:
> P1ot[5000 - 875. Log[Cosh[0.105884 t]], {t, 0, 60}]
> How can I get a real plot? I tried [N[x[t]] and Evaluate[x[t]] but
nothing
> worked...
> Why is t_ used in the second equation?
> The source of these equations is Ferdinand F. Cap's book Mathematical
> methods in physics and engineering with Mathematica
The code was copy pasted from an electronic version of the book.
===
Subject: Plot boundaries not respected
When I type the following in Mathematica 6.0.1 Linux x86_64 version
Plot[Exp[x], {x, -10, 2}]
I get a plot to y-axis value 2.2 in stead of Exp[2]=7.4
Why are the plot boundaries not respected?
===
Subject: Re: NDSolve with functions of vectors
I'm trying to keep a specific form because this is meant to be a sort of
tutorial for students who have never used Mathematica. That's why I'd like to
figure out why what I did is not working. I defined a[0]==X, so if X={1,1,1},
then shouldn't Mathematica recognize a[s] as having 3 components? When I
tried U[a[s]] within NDSolve, it keeps giving me an error saying that a[s]
only has 1 component. I've tried U[a[s][[1]],a[s][[2]],a[s][[3]]] and
Mathematica tells me that the second and third components of a[s] do not
exist. Is what I'm saying making any sense? It's hard to explain.
===
Subject: Re: NDSolve with functions of vectors
I tried that and I keep getting an error:
Part::partw: Part 2 of a[s] does not exist.
-John
===
Subject: Re: NDSolve with functions of vectors
I get the same error as Jerry. Something in NDSolve keeps making x[s] a
single component value despite the fact that the initial condition has 3
components. Is this a bug in Mathematica?
===
Subject: How to change the font size in legend
Style[hoge,Large]
but it didnt work. If u know something about it, plz teach me :)
thanx for advance
Shingo
1304
===
Subject: Re: Converting a number back to a symbol?

- .
> Funny. While it was considered obsolete and superseded by
> FoldList in
> Mathematica 2, Mathematica 1 (!) already did
> have a function Accumulate, defined as
> Accumulate[f, g[e1, e2, e3, ...]] <==> g[e1, f[e1, e2], f[f[e1,
> e2], e3],
> ...]
> so that
> Accumulate[Plus, Range[5]] <==> {1, 3, 6, 10, 15}
> However, Accumulate in Mathematica 1 clearly was not restricted
> to Plus
> but rather specifically intended for dealing
> with functions that take exactly two arguments - so, I believe that
> Accumulate in Mathematica 6 is much less usable
> than the former in Mathematica 1.
> Maybe I'm missing something here - but what was the rationale behind
> re-implementing Accumulate in such a restricted
> version now?
/oskar
> You are missing just one thing - performance. Accumulate in this
>> restricted sense is incredibly fast - and extremly useful.
> Andrzej Kozlowski
>
===
Subject: Re: Re: Manipulating a complex modulus expression
> Each new application of Simplify or FullSimplify is an adventure :-)
> Indeed ... I am curious: if one nests ComplexExpand inside Simplify
> (or FullSimplify) would the simplifier automatically know that all
> (non-designated) variables are real?
> If that is so, that would be a form of intraprocess inheritance
> typical of
> some languages.
>
It is easy to show that the answer is no. For example
FullSimplify[Im[ComplexExpand[Re[z]]]]
Im[z]
Andrzej Kozlowski
===
Subject: Re: Simple equation won't plot
When I paste your statement into a notebook, the word Plot isn't recognized
as a reserved word. Doubleclicking it and retyping Plot fixed this and
everything worked as expected. Perhaps there is a hidden character in the
expression.
The t_ is a pattern with the name t and specifies that the argument can be
anything not just t. Look up Blank.
Bob Hanlon
> When I type following commands in Mathematica 6.0.1:
> m = 70; a = 0.08; x0 = 5000; g = 9.81;
> x[t_] = x0 - m*Log[Cosh[t*Sqrt[g*a]/Sqrt[m]]]/a;
> P1ot[x[t], {t, 0, 60}]
> I don't get a plot, but instead:
> P1ot[5000 - 875. Log[Cosh[0.105884 t]], {t, 0, 60}]
> How can I get a real plot? I tried [N[x[t]] and Evaluate[x[t]] but
nothing
> worked...
> Why is t_ used in the second equation?
> The source of these equations is Ferdinand F. Cap's book Mathematical
> methods in physics and engineering with Mathematica
===
Subject: Re: Can you get a package back to a notebook easily?
Correction to the following note, previously posted: CVS isn't an IDE
(Integrated Development Environment). Rather, it's a version control
system. The following makes more sense if you substitute VCS for IDE.
Tom
> No, reading a package into the front end as a notebook is
> unsatisfactory: you get back only initialized input cells, in
> rather poor condition, and everything else is lost. Why bother? The
> reverse is true: you can easily reconstruct a package from a notebook.
>> I am asking this because I want to know if I need to save my
>> notebook and my package in CVS, or only my package?
> Back in the old days (version 3?), notebooks would become unstable
> when ported between operating systems (Mac and Windows in my case).
> I think Wolfram is well beyond this issue now, but I remain
> skittish. No way am I going to trust a notebook to an IDE like CVS.
> So what I do is sync the packages into the IDE and store the
> notebooks elsewhere. (I keep four copies of important notebooks!
> Two on computers, one on local backup, one on remote backup.) If
> the IDE fouls up, I can easily recreate versions of the packages
> from my notebooks.
> One compromise with this approach is that I don't keep all versions
> of all notebooks. (My notebooks are typically 2-100 megabytes
> each.) So the selection of saved notebooks will not always
> correspond exactly to the sync'ed packages, but I get away with it.
===
Subject: Re: The uses of Condition (/;)
Assuming that you mean (as in your examples for testing)
A. pattern /; condition := definition
I think A & B do yield the same results.
Despite the fact that Condition has a higher Precedence than
SetDelayed and RuleDelayed, Condition seems to apply itself the
entire assignment or rule, not just the definition. Perhaps the
documentation emphasizes both A and B to bring out this somewhat
unexpected behavior.
> According to the documentation, /; can be used in three different
> ways, illustrated below:
> A. pattern /; condition = definition
> B. pattern := definition /; condition
> C. pattern := Module[{}, definition /; condition]
===
Subject: Re: Simple equation won't plot
> When I type following commands in Mathematica 6.0.1:
> m = 70; a = 0.08; x0 = 5000; g = 9.81;
> x[t_] = x0 - m*Log[Cosh[t*Sqrt[g*a]/Sqrt[m]]]/a;
> P1ot[x[t], {t, 0, 60}]
> I don't get a plot, but instead:
> P1ot[5000 - 875. Log[Cosh[0.105884 t]], {t, 0, 60}]
Try fixing the typo. You have a numeral one instead of the letter l in
Plot.
> Why is t_ used in the second equation?
This identifies t as an argument in the function.
--
Helen Read
University of Vermont
===
Subject: Re: Simple equation won't plot
You misspelled Plot (with the numeral 1 in place of the letter l).
(Whoever decided the two should look so nearly identical is roasting in =
hades, I hope.)
m = 70; a = 0.08; x0 = 5000; g = 9.81;
x[t_] = x0 - m*Log[Cosh[t*Sqrt[g*a]/Sqrt[m]]]/a
Plot[x[t], {t, 0, 60}]
works just fine.
The second line (a) isn't an equation and (b) uses t_ on the left to
define a pattern named t.
Bobby
> When I type following commands in Mathematica 6.0.1:
> m = 70; a = 0.08; x0 = 5000; g = 9.81;
> x[t_] = x0 - m*Log[Cosh[t*Sqrt[g*a]/Sqrt[m]]]/a;
> P1ot[x[t], {t, 0, 60}]
> I don't get a plot, but instead:
> P1ot[5000 - 875. Log[Cosh[0.105884 t]], {t, 0, 60}]
> How can I get a real plot? I tried [N[x[t]] and Evaluate[x[t]] but
> nothing
> worked...
> Why is t_ used in the second equation?
> The source of these equations is Ferdinand F. Cap's book Mathematical
> methods in physics and engineering with Mathematica
--
DrMajorBob@bigfoot.com
===
Subject: Re: Simple equation won't plot
Is this as simple as 'Plot' vs 'P1ot'? If so, I usually find these
bugs by using completion in the editor, i.e. P1o