Prev: Persistent assumption
Next: Financial Data - Currencies
From: Vince Virgilio on 6 Jan 2010 05:56 On Jan 5, 1:43 am, Richard Fateman <fate...(a)cs.berkeley.edu> wrote: SNIP > Are you describing Mathematica here? It seems to me that it is an > exception that Head[a+b*I] is Plus, but Head[3+4I] is Complex. SNIP Please explain why that is an exception. 'a' and 'b' can be anything, not necessarily numbers. Hence a + b*I can be anything as well (say, notebookA + notebookB * I). Not so for 3, 4, and 3 + 4*I. Vince Virgilio
From: DrMajorBob on 6 Jan 2010 05:58 Unlike "The Mathematica Book", we don't read "Doc Center" in order, or even, really, notice that there IS an order. Bobby On Tue, 05 Jan 2010 00:43:00 -0600, Vince Virgilio <blueschi(a)gmail.com> wrote: > Fred, > > > On Jan 4, 6:01 am, Fred Klingener <gigabitbuc...(a)BrockEng.com> wrote: > > SNIP > >> further mention that that hidden level can be discovered even by an >> "unsophisticated user" as the output of //FullForm would be like >> sharing the secret handshake. >> >> First line in tutorial/Applying TransformationRules: >> >> expr/.lhs->rhs apply a transformation rule to FullForm[expr] > > SNIP > > True. > > However, for what it's worth, FullForm appears straightforwardly in > the Doc Center: > > In Doc Center . . . > First section is "Core Language" > First bullet is "Language Overview" > First link is "Symbolic Expressions" > First documented command is "FullForm" > > Then a one-liner for ReplaceAll occurs a few lines down. Yes, as you > say, the one-liner needs an edit. > > I think this doc structure qualifies Mathematica as sufficiently > "discoverable" [*]. > > Vince Virgilio > > [*] I.e. 3rd bullet, second section, at: > http://accu.org/index.php/journals/1572 > -- DrMajorBob(a)yahoo.com
From: David Park on 6 Jan 2010 05:59 I don't think that it is correct to expect that a mathematical object has a Head. Mathematica only gives us various representations of objects and different representations have different Heads. Thus 3 + 4 I, ComplexPolar[5, ArcTan[4/3]] (in Presentations), 5 E^(I ArcTan[4/3]), Complex[3,4] all represent the same mathematical object but all have different Heads. (Plus, ComplexPolar, Times, Complex). What might be confusing is that Complex is a NUMBER and not a symbolic expression. WRI could improve the Help for Complex by changing the first note to: "You can enter a complex number in the form x + I y, where x and y are Integer, Real, Rational or Complex numbers." "Expressions such as Complex[a,b] with Symbols are not meaningful and are left unevaluated. Symbolic complex expressions contain Complex numbers only as subparts." And then, among the first examples, they might show: "Complex expressions may contain Complex numbers as subparts and can be manipulated with routines such as Conjugate and ComplexExpand." x + I y % // FullForm ComplexExpand[Conjugate[%]] % // FullForm x + I y Plus[x,Times[Complex[0,1],y]] x - I y Plus[x,Times[Complex[0,-1],y]] Very few users would use Complex numbers in isolation without combining them in symbolic expressions. So why not stand users up and point them in the right direction instead of just saying that the Help is 'formally correct'? For those who use Help, of course. David Park djmpark(a)comcast.net http://home.comcast.net/~djmpark/ From: Richard Fateman [mailto:fateman(a)cs.berkeley.edu] [SNIP] Are you describing Mathematica here? It seems to me that it is an exception that Head[a+b*I] is Plus, but Head[3+4I] is Complex. [SNIP] You assume that people read the documentation. This is provably false. RJF
From: Richard Fateman on 6 Jan 2010 05:59 I think it is interesting that the same issue came up in the design of another computer algebra system, years ago. That is, which objects are "atomic" and which are decomposable for purposes of substitution. And further, of those which are decomposable, how much cleverness should be applied during substitution For example, Exp[I x] -Exp[- I x] /. Exp[I x] -> s should probably result in s-1/s. In Mathematica, one gets s-E^(-Ix). can either (1) Make this come out s-1/s or (2) Argue that Mathematica already does the right thing, blame the user, blame the documentation, blame the nature of mathematics, claim that it is impossible to "read the user's mind" etc. To me, the question is simply, by what programming technique can we make Mathematica do the truly expected thing. In this case, and I believe in every other case, a transformation of the rules will help. In particular, using the rule x-> -I Log[s] instead of Exp[x I] -> s. Is it possible that Mathematica could make this change? How could it possibly make such a transformation? (hint. Solve for variable s) For another example, x/5 /. 1/5->Fifth results in Fifth x but 3/5 /. 1/5 -> Fifth is unchanged. Is it possible that Mathematica could do this consistently? Maybe it could notice the rule is Rational[1, ...] -> <something> and decide that constitutes some possible point of dispute as to what to do syntactically, and produce another rule, say Rational[a_,5]->a*Fifth instead. I think there are only a few other cases. The only one that comes to mind is complex numbers. Suggestions? (The suggestion that this program must not be written because it is wrong, has already been offered.) Checking for these possible transformations could be done by a program in a relatively short time. Call it BetterRules. Then instead of X /. Y one could do X /. BetterRules[Y]. A more appropriate name or alternate syntax could be arranged. All that is needed is a further elaboration of BetterRules, not more argument. It is possible to look at the (free, open) source code of decades-old programs. (email me for the name; Steve C might censor this note if I wrote it here. :) David Park wrote: > I don't think that it is correct to expect that a mathematical object has a > Head. Mathematica only gives us various representations of objects and > different representations have different Heads. Thus > > 3 + 4 I, ComplexPolar[5, ArcTan[4/3]] (in Presentations), 5 E^(I > ArcTan[4/3]), Complex[3,4] > > all represent the same mathematical object but all have different Heads. > (Plus, ComplexPolar, Times, Complex). > I'm not sure what you mean. I expect that all Mathematica objects have Heads, which are kind of like types in other languages. > What might be confusing is that Complex is a NUMBER and not a symbolic > expression. A number is a symbolic expression too. Just a simple one that is "atomic". Calling a complex number "atomic" and non-decomposable is a hack that can be useful and can be detrimental. > WRI could improve the Help for Complex by changing the first > note to: > > "You can enter a complex number in the form x + I y, where x and y are > Integer, Real, Rational or Complex numbers." > > "Expressions such as Complex[a,b] with Symbols are not meaningful and are > left unevaluated. The user who types this in to Mathematica clearly has in mind something meaningful. It seems to me that it has the same meaning as a+b*I, and perhaps Mathematica should just produce that, instead of the unevaluated Complex. It would probably require no explanation, which is a plus. > Symbolic complex expressions contain Complex numbers only > as subparts." > This does not define "symbolic complex expression" , "contain" "subpart" or "Complex number" [with capital]. > And then, among the first examples, they might show: > > "Complex expressions may contain Complex numbers as subparts and can be > manipulated with routines such as Conjugate and ComplexExpand." > > x + I y > % // FullForm > ComplexExpand[Conjugate[%]] > % // FullForm > > x + I y > Plus[x,Times[Complex[0,1],y]] > x - I y > Plus[x,Times[Complex[0,-1],y]] > > Very few users would use Complex numbers in isolation without combining them > in symbolic expressions. I don't know. doing arithmetic on complex numbers is done by Fortran, and Fortran doesn't have symbolic ANYTHING. > So why not stand users up and point them in the > right direction instead of just saying that the Help is 'formally correct'? > > For those who use Help, of course. > What I would say is Because of the disparity in internal representations (see below) , for replacements on parts of complex expressions, don't use /. ... use /. BetterRules[ ...] or use transformation or selection programs such as Conjugate, Im, Re, ... << advanced section on internal representation of complex numbers>> Mathematica has a special form for imaginary and complex constants that provides certain efficiencies, but at the cost of two representations for items that would be expected to be more similar. I is Complex[0,1] internally. 3/4+4.2 I is simplified to Complex[3/4,4.2]. The parts of Complex must be explicit Numbers. x+4*I is simplified to Plus [x, Times[4, Complex[0,1]]]. etc examples. > > David Park > djmpark(a)comcast.net > http://home.comcast.net/~djmpark/ > > > From: Richard Fateman [mailto:fateman(a)cs.berkeley.edu] > > [SNIP] > > Are you describing Mathematica here? It seems to me that it is an > exception that Head[a+b*I] is Plus, but Head[3+4I] is Complex. > > [SNIP] > > You assume that people read the documentation. This is provably false. > > RJF > > >
From: DrMajorBob on 7 Jan 2010 02:28
Some good points, David. When help says "You can enter a complex number in the form x + I y", it is seriously misleading, without the qualification you added below. x + I y is NOT a number (of any kind) when a and b are undefined, and neither is Complex[x, y]: NumericQ(a)Complex[x, y] False If they ARE defined, the result isn't necessarily complex (or even sensible): Complex[0, I] N@% Complex[0, I] Complex[0., 0. + 1. I] What the heck is that? Complex[0.`, 0.` + 1.` I] // Simplify Complex[0., 0. + 1. I] Bobby On Wed, 06 Jan 2010 04:59:15 -0600, David Park <djmpark(a)comcast.net> wrote: > I don't think that it is correct to expect that a mathematical object > has a > Head. Mathematica only gives us various representations of objects and > different representations have different Heads. Thus > > 3 + 4 I, ComplexPolar[5, ArcTan[4/3]] (in Presentations), 5 E^(I > ArcTan[4/3]), Complex[3,4] > > all represent the same mathematical object but all have different Heads. > (Plus, ComplexPolar, Times, Complex). > > What might be confusing is that Complex is a NUMBER and not a symbolic > expression. WRI could improve the Help for Complex by changing the first > note to: > > "You can enter a complex number in the form x + I y, where x and y are > Integer, Real, Rational or Complex numbers." > > "Expressions such as Complex[a,b] with Symbols are not meaningful and are > left unevaluated. Symbolic complex expressions contain Complex numbers > only > as subparts." > > And then, among the first examples, they might show: > > "Complex expressions may contain Complex numbers as subparts and can be > manipulated with routines such as Conjugate and ComplexExpand." > > x + I y > % // FullForm > ComplexExpand[Conjugate[%]] > % // FullForm > > x + I y > Plus[x,Times[Complex[0,1],y]] > x - I y > Plus[x,Times[Complex[0,-1],y]] > > Very few users would use Complex numbers in isolation without combining > them > in symbolic expressions. So why not stand users up and point them in the > right direction instead of just saying that the Help is 'formally > correct'? > > For those who use Help, of course. > > > David Park > djmpark(a)comcast.net > http://home.comcast.net/~djmpark/ > > > From: Richard Fateman [mailto:fateman(a)cs.berkeley.edu] > > [SNIP] > > Are you describing Mathematica here? It seems to me that it is an > exception that Head[a+b*I] is Plus, but Head[3+4I] is Complex. > > [SNIP] > > You assume that people read the documentation. This is provably false. > > RJF > > > -- DrMajorBob(a)yahoo.com |