A69 ==== Subject: Re: //N bug, but WHY? Actually, however strange it may seem, there is no bug involved here at all. You are using machine precision arithemtic and it is quite normal for machine precision arithemtic to give quite different answers two algebraically equivalent expressions if one (or both) is ill conditioned. It is quite often the case that one form of an expression is ill conditioned and machine precision will give you an answer that is way off while another form is well conditioned and you will get a pretty good answer even with machine precision. You can see quite clearly how this happens here. Just evaluate the same expression but using bignum arithmetic with reasonable precision: In[1]:= N[[FullSimplify[Cosh[(43*Pi)/Sqrt[2]] + (1 - Cosh[43*Sqrt[2]*Pi])*Csch[43*Sqrt[2]*Pi]* Sinh[(43*Pi)/Sqrt[2]]]],50] Out[1]= 6.5517875178543440140500579682357879451030334737036144280 42203561`50.*^-42 No problem here. Now In[2]:= N[Cosh[(43*Pi)/Sqrt[2]] + (1 - Cosh[43*Sqrt[2]*Pi])* Csch[43*Sqrt[2]*Pi]*Sinh[(43*Pi)/Sqrt[2]], 50] Internal precision limit $MaxExtraPrecision =`50. reached while evaluating .... Out[2]= 6.551787517854344014050058`14.31640268976547*^-42 The answers are very close but the message tells you that the second expression is ill conditioned and even high precision aritmetic is having problems with it. Thus there is no bug here at all, it is just one of the facts of life one has to live with. Andrzej Kozlowski Chiba, JAPAN > Evaluating (using //N) two exact same expressions, gives wrong > answer unless > fullsimplify is used first, I spent 2 days on a problem thinking my > answer > was wrong, but turned out Mathematica 5 was giving me buggy answers, I > debugged it to this point, but WHY in the world is this happening? > Please > help!!! cut and paste below to see the test case: In[243]:= > !((Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ > 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // > FullSimplify) // > N[IndentingNewLine] > Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ > 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // N) > Out[243]= > !(6.551787517854307`*^-42) > Out[244]= > !((-1.9342813113834067`*^25)) > ==== Subject: Re: GroebnerBasis (was Re: Documentation) > Likewise > GroebnerBasis[{x - y, x - 1.01 y}, {x, y}] > gives the correct {1. y, x} while > GroebnerBasis[{x - y, x - 1.01 y}, {x, y}] > gives the incorrect {x - 1.001 y} Oh, that last example should be GroebnerBasis[{x - y, x - 1.001 y}, {x, y}] of course. /Stefan ==== Subject: Re: superscripts > Would this work??? Cell[BoxData[RowBox[{Symbolize, > [,TagBox[StyleBox[RowBox[{a,StyleBox[0,FontSize->8, > FontVariations->{CompatibilityType->Superscript}]}]], NotationBoxTag, > TagStyle->NotationTemplateStyle], ]}]], Input] > I am afraid not! In[1]:= Needs[Utilities`Notation`] In[2]:= Symbolize[NotationBoxTag[ StyleBox[(a*StyleBox[0, Rule[FontSize, 8.`], Rule[FontVariations, List[Rule[CompatibilityType, Superscript]]]])] ]] In[3]:= a[UnderBracket]Superscript[UnderBracket]0 + a^1 Out[3]= 1 + a In[4]:= a[UnderBracket]Superscript[UnderBracket]0 = 2 !(* RowBox[{(Set::write), :, RefGuideLinkText , ButtonFrame->None, ButtonData:>General::write])>}]) Out[4]= 2 Set::write:Tag !(Power) in !(a^0) is Protected. !(*ButtonBox[More[Ellipsis], ButtonStyle->RefGuideLinkText, ButtonFrame->None, ButtonData:>General::write]) However, these ones work like a charm: In[5]:= Symbolize[NotationBoxTag[(a^0)]] In[6]:= a[UnderBracket]Superscript[UnderBracket]0 + a^1 Out[6]= a + a[UnderBracket]Superscript[UnderBracket]0 In[7]:= a[UnderBracket]Superscript[UnderBracket]0 = 2 Out[7]= 2 In[8]:= a[UnderBracket]Superscript[UnderBracket]0 + a^1 Out[8]= 2 + a In[9]:= Symbolize[NotationBoxTag[([ScriptCapitalA]^0)]] In[10]:= [ScriptCapitalA][UnderBracket]Superscript[UnderBracket]0 = [ScriptCapitalA]^2 Out[10]= [ScriptCapitalA]^2 /J.M. ==== Subject: Re: //N bug, but WHY? It's because the second expression is numerically meaningless with machine precision numbers. The two terms are nearly equal and opposite. Observe... N[{Cosh[(43*Pi)/Sqrt[2]], (1 - Cosh[43*Sqrt[2]*Pi])*Csch[43*Sqrt[2]*Pi]* Sinh[(43*Pi)/Sqrt[2]]}, 100] Plus @@ % {1.5263010243767668658026837562551913006201477453400952790176417034559634087 44 7565329239768148460217896689984877687881804`100.*^41, -1.5263010243767668658026837562551913006201477453400952790176417034559634087 447565328584589396674783495284979080869067972`100.00000000000003*^41} 6.55178751785434401405005796818813832`17.331689612939737*^-42 David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Evaluating (using //N) two exact same expressions, gives wrong answer unless fullsimplify is used first, I spent 2 days on a problem thinking my answer was wrong, but turned out Mathematica 5 was giving me buggy answers, I debugged it to this point, but WHY in the world is this happening? Please help!!! cut and paste below to see the test case: In[243]:= !((Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // FullSimplify) // N[IndentingNewLine] Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // N) Out[243]= !(6.551787517854307`*^-42) Out[244]= !((-1.9342813113834067`*^25)) ==== Subject: Re: //N bug, but WHY? >Evaluating (using //N) two exact same expressions, gives wrong >answer unless fullsimplify is used first, I spent 2 days on a >problem thinking my answer was wrong, but turned out Mathematica 5 >was giving me buggy answers, I debugged it to this point, but WHY >in the world is this happening? When you use //N on an expression transformed by FullSimplify, you are not evaluating the identical expression. This is important since in a more complex expression you can get loss of precision as each portion of the expression is converted to machine precision. In your particular case, consider In[9]:= N[{Cosh[(43*Pi)/Sqrt[2]], (1 - Cosh[43*Sqrt[2]*Pi])* Csch[43*Sqrt[2]*Pi]* Sinh[(43*Pi)/Sqrt[2]]}] Out[9]= {1.526301024376754*^41, -1.5263010243767541*^41} As you can see, the original expression is summing two nearly equal things with opposite sign. This leads to loss of precision whenever it occurs. By using FullSimplify, you are transforming the expression to a form where this doesn't occur. As a result, you get a more accurate answer. This really isn't a bug in N. It is just the nature of using finite precision. -- To reply via email subtract one hundred and four ==== Subject: ListDensityPlot Legend? dear mathgroup, how does one add a legend to a ListDensityPlot. i've a matrix that contains only 0,1 or 2 entries. ListDensityPlot plots the regions in three different colors. i would like to add a legend that indicates the colors and their corresponding numbers (0,1, or 2). Tom Wickham-Jones' ExtendGraphics package is doing almost what i want for ListContourPlot, however, for ListDensityPlot it's not working. Any ideas? juergen ==== Subject: Re: ListDensityPlot Legend? Small correction for the labels of the legend << Graphics`Legend` t = Table[Random[Integer, 2], {5}, {5}]; ShowLegend[ListDensityPlot[t, ColorFunction -> ( Hue[#/3] &), DisplayFunction -> Identity], {Hue[#/3] &, 3, 0, 2, LegendPosition -> {1.1, -.3}}] Sorry for the trouble yehuda > dear mathgroup, how does one add a legend to a ListDensityPlot. > i've a matrix that contains only 0,1 or 2 entries. ListDensityPlot plots > the regions in three different colors. i would like to add a legend that > indicates the colors and their corresponding numbers (0,1, or 2). > Tom Wickham-Jones' ExtendGraphics package is doing almost what i want for > ListContourPlot, however, for ListDensityPlot it's not working. > Any ideas? juergen ==== Subject: Re: ListDensityPlot Legend? Hi Juergen Please try the following code. << Graphics`Legend` t = Table[Random[Integer, 2], {5}, {5}]; ShowLegend[ListDensityPlot[t, ColorFunction -> ( Hue[#/3] &), DisplayFunction -> Identity], {Hue[#/3] &, 3, 2, 0, LegendPosition -> {1.1, -.3}}] yehuda > dear mathgroup, how does one add a legend to a ListDensityPlot. > i've a matrix that contains only 0,1 or 2 entries. ListDensityPlot plots > the regions in three different colors. i would like to add a legend that > indicates the colors and their corresponding numbers (0,1, or 2). > Tom Wickham-Jones' ExtendGraphics package is doing almost what i want for > ListContourPlot, however, for ListDensityPlot it's not working. > Any ideas? juergen ==== Subject: Re: ListDensityPlot Legend? and Graphics`Legend` does not help ? Needs[Graphics`Legend`] data = Table[Random[Integer, {0, 2}], {128}, {128}]; ShowLegend[ ListDensityPlot[data, DisplayFunction -> Identity], {GrayLevel[1 - #] &, 3, 2, 0, LegendPosition -> {1.1, -.4}}]; Jens juejung schrieb im > dear mathgroup, how does one add a legend to a ListDensityPlot. > i've a matrix that contains only 0,1 or 2 > entries. ListDensityPlot plots > the regions in three different colors. i would > like to add a legend that > indicates the colors and their corresponding > numbers (0,1, or 2). > Tom Wickham-Jones' ExtendGraphics package is > doing almost what i want for > ListContourPlot, however, for ListDensityPlot > it's not working. > Any ideas? juergen > ==== Subject: Re: FrameTicks bug (SUMMARY) > Well, I guess it's not actually a bug, but . . . FrameTicks -> {Automatic, Automatic, None, None} puts tick marks AND numerical labels on bottom and left edges. FrameTicks -> {None, Automatic, Automatic, None} puts tick marks and numerical labels on left edge, tick > marks and NO NUMERICAL LABELS on top edge. And yehuda ben-shimol replied: > use True instead of Automatic -- that is > FrameTicks -> {None, True, True, None}] it's a lot simpler than several of the other workarounds that were proposed . . . ) 2) And I guess this could be described at a minimum as a documentation bug, since True is not listed as an option in the online Help window for FrameTicks; only Automatic is listed (Mac version 5.1). ==== Subject: Re: //N bug, but WHY? You are trying to substract two very close large numbers, and of course you are entering to the limits of machine precision. Cosh[(43*Pi)/Sqrt[2]]//N returns 1.5263010243767756*^41 and (1 - Cosh[43*Sqrt[2]*Pi])*Csch[43*Sqrt[2]*Pi]* Sinh[(43*Pi)/Sqrt[2]]//N returns -1.5263010243767758*^41 so if you evaluate the original expression with high precision N[Cosh[(43*Pi)/Sqrt[2]] + (1 - Cosh[43*Sqrt[2]*Pi])* Csch[43*Sqrt[2]*Pi]*Sinh[(43*Pi)/Sqrt[2]], 50] you will get 6.5517875178543440140500579682357879451030334737036144 2804220253`50.*^-42 Now, FullSimplify[Cosh[(43*Pi)/Sqrt[2]] + (1 - Cosh[43*Sqrt[2]*Pi])* Csch[43*Sqrt[2]*Pi]*Sinh[(43*Pi)/Sqrt[2]]] returns Sech[(43*Pi)/Sqrt[2]] And this can be evaluated by //N without suffering precision problems. Sech[(43*Pi)/Sqrt[2]]//N 6.551787517854306*^-42 I hope this helps yehuda > Evaluating (using //N) two exact same expressions, gives wrong answer unless > fullsimplify is used first, I spent 2 days on a problem thinking my answer > was wrong, but turned out Mathematica 5 was giving me buggy answers, I > debugged it to this point, but WHY in the world is this happening? Please > help!!! cut and paste below to see the test case: In[243]:= > !((Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ > 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // FullSimplify) // > N[IndentingNewLine] > Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ > 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // N) > Out[243]= > !(6.551787517854307`*^-42) > Out[244]= > !((-1.9342813113834067`*^25)) > ==== Subject: Fw: Re: Set of strings reducing problem ----- Original Message ----- ==== Subject: Re: Re: Set of strings reducing problem > Hello! I've tried this: In[21]:= > L={111,11X,112,1X1,1XX,1X2,121,12X,122} > Out[21]= > {111,11X,112,1X1,1XX,1X2,121,12X,122} > In[22]:= > cl=Characters/@L; > In[23]:= > r = Dispatch[{1 + X -> D, 1 + 2 -> M, 1 + U -> T, > X + 2 -> U, X + M -> T, 2 + D -> T }]; > In[24]:= > ncl =StringJoin @@@ ( cl //. { > x___List, > {a___, p_String, c___}, > {a___, q_String, c___}, > y___List } : { x, {a, p+q/.r,c}, y } /; > StringQ[(p+q)/.r]) > Out[24]= > {111,11X,112,1X1,1XX,1X2,121,12X,122} > As you can see, it didn't reduce my set of strings... Any clue? > Edson P.S.: What are those symbols at your code: !!ll and < Does your code run on Mathematica 5.1? > ----- Original Message ----- ==== > Subject: Re: Set of strings reducing problem >> one possibility is to use simple pattern matching: >> Mathematica 5.2 for Linux x86 (64 bit) >> Copyright 1988-2005 Wolfram Research, Inc. >> -- Motif graphics initialized -- >> In[1]:= !!ll >> L={11111111, >> 11112111, >> 1111X111, >> 21122211}; >> cl=Characters/@L; >> r = Dispatch[{1 + X -> D, 1 + 2 -> M, 1 + U -> T, >> X + 2 -> U, X + M -> T, 2 + D -> T }]; >> ncl =StringJoin @@@ ( cl //. { >> x___List, >> {a___, p_String, c___}, >> {a___, q_String, c___}, >> y___List } :> { x, {a, p+q/.r,c}, y } /; >> StringQ[(p+q)/.r]) >> In[1]:= <> Out[1]= {1111T111, 21122211} >> -- >> Rolf Mertig >> GluonVision GmbH >> Berlin >> ==== Subject: Fw: Set of strings reducing problem ----- Original Message ----- ==== Subject: Re: Set of strings reducing problem > Hello! I've tried this: In[27]:= > l=Characters[{111,112,11X}] > Out[27]= > {{1,1,1},{1,1,2},{1,1,X}} > In[28]:= > FixedPoint[listReduce,l]//ColumnForm > Out[28]= > !(* > InterpretationBox[GridBox[{ > {({1, 1, 1})}, > {({1, 1, M})}, > {({1, 1, T})}, > {({1, 1, D})}, > {({1, 1, 2})}, > {({1, 1, U})}, > {({1, 1, X})} > }, > GridBaseline->{Baseline, {1, 1}}, > ColumnAlignments->{Left}], > ColumnForm[ {{1, 1, 1}, {1, 1, M}, {1, 1, T}, {1, > 1, > D}, {1, 1, 2}, {1, 1, U}, {1, 1, X}}], > Editable->False]) > As you can see the result is not what I expected! I had a 3 elements list > and got a 7 elements list. The curiosity is that the result I wanted is in the list : 11T Any clue to solve this? > Edson > ----- Original Message ----- ==== > Subject: Set of strings reducing problem >> and thus spake Edson Ferreira [2005.07.07 @ 05:21]: > I have a problem that I haven't got any clue to solve with Mathematica. Let's say a have a list of n equal length strings: >> [ ... ] >> here's an implementation of your approach. it's quite wordy, but i >> think it should work. >> first set up your string transformation rules, i'm using a throwaway >> symbol s[] to attach the rules to: >> s /: Plus[s[1], s[X]] = D; >> s /: Plus[s[1], s[2]] = M; >> s /: Plus[s[1], s[U]] = T; >> s /: Plus[s[X], s[2]] = U; >> s /: Plus[s[X], s[M]] = T; >> s /: Plus[s[2], s[D]] = T; >> s /: Plus[s[s1_String], s[s2_String]] := s1 >> the last rule is something i threw in to handle string combinations you >> didn't supply. you'll probably want to handle these differently. >> (* this is just UnsortedUnion from the help browser, see Union[] *) >> uniq[x_]:= Module[{f}, f[y_] := (f[y] = Sequence[]; y); f /@ x] >> (* this applies the string transformations iff the two lists differ >> in exactly one position *) >> stringReduce[l1_List, l2_List] := Module[ >> {t = Equal @@@ Transpose[{l1, l2}], p}, >> If[Count[t, False] == 1, >> p = Position[t, False][[1, 1]]; >> ReplacePart[l1, Plus @@ (s /@ {l1[[p]], l2[[p]]}), p], >> Sequence @@ {l1, l2} >> ] >> ] >> now, the trivial function that will actually do an iteration >> of the list: >> listReduce[l_List] := uniq[stringReduce@@@Tuples[l,2]] >> (* tuples is new in 5.1. if you don't have 5.1, you can use this: >> Flatten[Outer[List, l, l, 1],1] >> to achieve the same thing (those are two ell's and a one) *) >> finally, we can use FixedPoint to reduce the list until it can be >> reduced no more. I created a simple list of sample strings to test: >> alphabet = {1, X, 2, U, M, D, T}; >> l = Flatten[{ >> {1, 1, 1, 1, #, 1, 1, 1}, >> {2, 1, 1, 1, #, 1, 1, 2}} & /@ alphabet, 1]; >> FixedPoint[listReduce,l]//ColumnForm >> {1, 1, 1, 1, 1, 1, 1, 1} >> {2, 1, 1, 1, 1, 1, 1, 2} >> {2, 1, 1, 1, X, 1, 1, 2} >> {2, 1, 1, 1, 2, 1, 1, 2} >> {2, 1, 1, 1, U, 1, 1, 2} >> {2, 1, 1, 1, M, 1, 1, 2} >> {2, 1, 1, 1, D, 1, 1, 2} >> {2, 1, 1, 1, T, 1, 1, 2} >> {1, 1, 1, 1, D, 1, 1, 1} >> {1, 1, 1, 1, M, 1, 1, 1} >> {1, 1, 1, 1, T, 1, 1, 1} >> {1, 1, 1, 1, X, 1, 1, 1} >> {1, 1, 1, 1, 2, 1, 1, 1} >> {1, 1, 1, 1, U, 1, 1, 1} >> In this simple case, only one pass is necessary. >> If you want to process the strings as they are in 221111X11 >> form, you can simply slap in a call to Characters[] and StringJoin[]. >> -- >> /*------------------------------* >> | stephen layland | >> | Documentation Programmer | >> | http://members.wri.com/layland | >> *------------------------------*/ > ==== Subject: Re: //N bug, but WHY? your expression consists of a sum with 2 terms that have opposite signs and nearly the same magnitude. The absolute value is of the order of 10^41 and the difference 10^-41. Therefore, if you calculate with machine precision= 16 digits, this is doomed to fail. On the other hand, the help for N[] is partly wrong. Consider the help: N[expr] is equivalent to N[expr, MachinePrecision] a=10^16+1; b=10^16; N[a-b] gives 1. because the argument of N is evaluated with infinite precision before N sees it. We can prevent this by wrapping a and b in a function that can not be evaluated with infinite precision: a=Sqrt[10^16+1]; b=Sqrt[10^16]; N[a-b] gives 0. because 10^16+1 is now evaluated with machine precision giving 10^16. On the other hand, N[a-b,16] gives 5.00.. 10^-9, here it seems that the intermediate calulations are done with higher precision, exactly what the help says. Even N[a-b,1] gives 5. 10^-9 In short: N[expr] does all calculation in machine precision, whereas N[expr,number] does all intermediate calculation with high enough (up to an upper Limit of $MaxExtraPrecision) precision to garantee a result precision of number sincerely, Daniel > Evaluating (using //N) two exact same expressions, gives wrong answer unless > fullsimplify is used first, I spent 2 days on a problem thinking my answer > was wrong, but turned out Mathematica 5 was giving me buggy answers, I > debugged it to this point, but WHY in the world is this happening? Please > help!!! cut and paste below to see the test case: In[243]:= > !((Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ > 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // FullSimplify) // > N[IndentingNewLine] > Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ > 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // N) > Out[243]= > !(6.551787517854307`*^-42) > Out[244]= > !((-1.9342813113834067`*^25)) ==== Subject: Re: //N bug, but WHY? dh, I don't think the help for N[] is partly wrong, as I try to explain below. > your expression consists of a sum with 2 terms that have opposite signs > and nearly the same magnitude. The absolute value is of the order of > 10^41 and the difference 10^-41. Therefore, if you calculate with > machine precision= 16 digits, this is doomed to fail. On the other hand, the help for N[] is partly wrong. > Consider the help: > N[expr] is equivalent to N[expr, MachinePrecision] we have The numerical value of MachinePrecision is $MachinePrecision. So, In[1]:= $MachinePrecision Out[1]= 15.9546 Or even: In[2]:= N[MachinePrecision] Out[2]= 15.9546 > a=10^16+1; b=10^16; > N[a-b] gives 1. because the argument of N is evaluated with infinite > precision before N sees it. Since N does not have any Hold attributes, like any such function it evaluates its arguments before doing anything else. > We can prevent this by wrapping a and b in a > function that can not be evaluated with infinite precision: > a=Sqrt[10^16+1]; b=Sqrt[10^16]; > N[a-b] gives 0. because 10^16+1 is now evaluated with machine precision > giving 10^16. As the help says, N converts each successive argument of any function it encounters to numerical form, unless the head of the function has an attribute such as NHoldAll. This explains the behavior you observed. > On the other hand, > N[a-b,16] gives 5.00.. 10^-9, here it seems that the intermediate > calulations are done with higher precision, exactly what the help says. > Even > N[a-b,1] gives 5. 10^-9 > You seem to be assuming that N[a-b,16] is equivalent to N[a-b], but as I pointed out above, that is incorrect. N[a-b,16] essentially converts all numbers to extended precision numbers in order to achieve a result of at least 16 digits of precision. It does not convert numbers to machine precision numbers. > In short: > N[expr] does all calculation in machine precision, whereas > N[expr,number] does all intermediate calculation with high enough (up to > an upper Limit of $MaxExtraPrecision) precision to garantee a result > precision of number > I believe this is a reasonable paraphrase of the help. Carl Woll Wolfram Research > sincerely, Daniel >> Evaluating (using //N) two exact same expressions, gives wrong answer >> unless >> fullsimplify is used first, I spent 2 days on a problem thinking my >> answer >> was wrong, but turned out Mathematica 5 was giving me buggy answers, I >> debugged it to this point, but WHY in the world is this happening? >> Please >> help!!! >> cut and paste below to see the test case: >> In[243]:= >> !((Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ >> 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // FullSimplify) >> // >> N[IndentingNewLine] >> Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ >> 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // N) >> Out[243]= >> !(6.551787517854307`*^-42) >> Out[244]= >> !((-1.9342813113834067`*^25)) > ==== Subject: Re: //N bug, but WHY? ... >>Evaluating (using //N) two exact same expressions, gives wrong answer unless >... The same question was asked the previous day, and answered, in sci.math.symbolic. Symbio knows about email enough to provide a bogus return address, but doesn't know much about numerical computation, and is unwilling to learn. So he or she asks and asks. At least Symbio found the mathematica newsgroup. It occurs to me that the right answer, for someone like Symbio who really doesn't want to be burdened by any computational knowledge, is simple: Never EVER use N[...], but always N[...,], and hope for the best. In Symbio's case he or she should just replace the the locution ......//N with the locution .....//N[#,16]& and Symbio's answer comes out right. No need for FullSimplify etc etc. So in this regard, there is a bug and it even has a fix. More significantly, and the reason I bother to write again, is the following advice. (at least if you believe in the validity of the Mathematica software-float numerics). Suggestion to WRI: Change the meaning of N to N[#,16]& and alter N so that the only time the current N[] is used is by explicit demand, e.g. N[...., DoItFasterAndMaybeWrongUsingMachineArithmetic] RJF ==== Subject: Re: //N bug, but WHY? > .... Evaluating (using //N) two exact same expressions, gives wrong answer unless >>... > The same question was asked the previous day, and answered, in sci.math.symbolic. > Symbio knows about email enough to provide a bogus return address, but > doesn't know much about numerical computation, and is unwilling to learn. > So he or she asks and asks. At least Symbio found the mathematica newsgroup. It occurs to me that the right answer, for someone like Symbio > who really doesn't want to > be burdened by any computational knowledge, is simple: Never EVER use N[...], > but always N[...,], and hope for the best. > In Symbio's case he or she should just replace the > the locution ......//N with the locution > .....//N[#,16]& > and Symbio's answer comes out right. No need for FullSimplify etc etc. So in this regard, there is a bug and it even has a fix. More significantly, and the reason I bother to write again, is > the following advice. > (at least if you believe in the validity of the Mathematica > software-float numerics). Suggestion to WRI: Change the meaning of N to N[#,16]& and alter N so that > the only time the current N[] is used is by explicit > demand, e.g. N[...., DoItFasterAndMaybeWrongUsingMachineArithmetic] > RJF > I tried it this way: Unprotect[N]; N /: Options[N] = Union[Evaluate[Options[N]], {QuickAndDirty -> False}]; HoldPattern[N[x_, opt:(o_ -> v_)..]] := If[(QuickAndDirty /. {opt}) == True, N[x, MachinePrecision, (* NOT $MachinePrecision! *) Sequence @@ DeleteCases[{opt}, QuickAndDirty -> True]], N[x]]; HoldPattern[N[x_]] := N[x, $MachinePrecision]; N::usage = N[expr] gives the numerical value of expr. N[expr, n] attempts to give a result with n-digit precision. N[expr,QuickAndDirty->True] will most likely ignore problems arising from a poorly conditioned expr.; QuickAndDirty::usage = QuickAndDirty is a boolean option for N. If set to True, N will not recognize ill conditioned expressions; Protect[N]; In[8]:= expr = Cosh[(43*Pi)/Sqrt[2]] + (1 - Cosh[43*Sqrt[2]*Pi])*Csch[43*Sqrt[2]*Pi]*Sinh[(43*Pi)/Sqrt[2]]; In[9]:=N[expr, QuickAndDirty -> True] Out[9]=-1.9342813113834067*^25 In[10]:=N[expr] N::meprec: Internal precision limit $MaxExtraPrecision = 49.99999999999999` reached while evaluating Cosh[(43*Pi)/Sqrt[2]] + (1 - Cosh[43*Sqrt[2]*Pi])*Csch[43*Sqrt[2]*Pi]*Sinh[(43*Pi)/Sqrt[2]]. More... Out[10]= 0``21.45463265565461 so we see at least, that something has gone wrong. In[11]:= Block[{$MaxExtraPrecision = 86}, N[expr]] Out[11]= 6.551787517854344014050058`15.954589770191*^-42 -- http://people.freenet.de/Peter_Berlin/ ==== Subject: Re: //N bug, but WHY? > Evaluating (using //N) two exact same expressions, gives wrong answer unless > fullsimplify is used first, I spent 2 days on a problem thinking my answer > was wrong, but turned out Mathematica 5 was giving me buggy answers, I > debugged it to this point, but WHY in the world is this happening? Please > help!!! cut and paste below to see the test case: In[243]:= > !((Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ > 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // FullSimplify) // > N[IndentingNewLine] > Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ > 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // N) > Out[243]= > !(6.551787517854307`*^-42) > Out[244]= > !((-1.9342813113834067`*^25)) No bug and nothing magic here; just the misunderstanding of what machine-precision arithmetic is and its pitfalls in some circumstances. In[1]:= expr = Cosh[(43*Pi)/Sqrt[2]] + (1 - Cosh[43*Sqrt[2]*Pi])* Csch[43*Sqrt[2]*Pi]*Sinh[(43*Pi)/Sqrt[2]] Out[1]= Cosh[(43*Pi)/Sqrt[2]] + (1 - Cosh[43*Sqrt[2]*Pi])*Csch[43*Sqrt[2]*Pi]* Sinh[(43*Pi)/Sqrt[2]] In[2]:= exprfs = FullSimplify[expr] Out[2]= Sech[(43*Pi)/Sqrt[2]] Both expressions do not seem to be two exact same expressions. Let try to expand the first one to see what happens: In[3]:= TrigExpand[expr] Out[3]= 1/(Cosh[Pi/Sqrt[2]]^43 + 903*Cosh[Pi/Sqrt[2]]^41*Sinh[Pi/Sqrt[2]]^2 + 123410*Cosh[Pi/Sqrt[2]]^39*Sinh[Pi/Sqrt[2]]^4 + 6096454*Cosh[Pi/Sqrt[2]]^37*Sinh[Pi/Sqrt[2]]^6 + 145008513*Cosh[Pi/Sqrt[2]]^35*Sinh[Pi/Sqrt[2]]^8 + 1917334783*Cosh[Pi/Sqrt[2]]^33*Sinh[Pi/Sqrt[2]]^10 + 15338678264*Cosh[Pi/Sqrt[2]]^31*Sinh[Pi/Sqrt[2]]^12 + 78378960360*Cosh[Pi/Sqrt[2]]^29*Sinh[Pi/Sqrt[2]]^14 + 265182149218*Cosh[Pi/Sqrt[2]]^27*Sinh[Pi/Sqrt[2]]^16 + 608359048206*Cosh[Pi/Sqrt[2]]^25*Sinh[Pi/Sqrt[2]]^18 + 960566918220*Cosh[Pi/Sqrt[2]]^23*Sinh[Pi/Sqrt[2]]^20 + 1052049481860*Cosh[Pi/Sqrt[2]]^21*Sinh[Pi/Sqrt[2]]^22 + 800472431850*Cosh[Pi/Sqrt[2]]^19*Sinh[Pi/Sqrt[2]]^24 + 421171648758*Cosh[Pi/Sqrt[2]]^17*Sinh[Pi/Sqrt[2]]^26 + 151532656696*Cosh[Pi/Sqrt[2]]^15*Sinh[Pi/Sqrt[2]]^28 + 36576848168*Cosh[Pi/Sqrt[2]]^13*Sinh[Pi/Sqrt[2]]^30 + 563921995*Cosh[Pi/Sqrt[2]]^9*Sinh[Pi/Sqrt[2]]^34 + 32224114*Cosh[Pi/Sqrt[2]]^7*Sinh[Pi/Sqrt[2]]^36 + 962598*Cosh[Pi/Sqrt[2]]^5*Sinh[Pi/Sqrt[2]]^38 + 12341*Cosh[Pi/Sqrt[2]]^3*Sinh[Pi/Sqrt[2]]^40 + 43*Cosh[Pi/Sqrt[2]]*Sinh[Pi/Sqrt[2]]^42) Wow! Things are getting worse :-) except if the second expression can be expanded in a similar way. Let's check In[4]:= TrigExpand[expr] == TrigExpand[exprfs] Out[4]= True Good. Now let's check that the expressions by themselves are equal: In[5]:= expr == exprfs !(* RowBox[{(N::meprec), :, RefGuideLinkText, ButtonFrame->None, ButtonData:>General::meprec])>}]) Out[5]= Cosh[(43*Pi)/Sqrt[2]] + (1 - Cosh[43*Sqrt[2]*Pi])*Csch[43*Sqrt[2]*Pi]* Sinh[(43*Pi)/Sqrt[2]] == Sech[(43*Pi)/Sqrt[2]] Okay. Mathematica is not able to tell us whether both expressions are equal; however, the warning message gives us a crucial clue. Thus we now try to use 50 digits, say. In[6]:= N[expr, 50] !(* RowBox[{(N::meprec), :, RefGuideLinkText, ButtonFrame->None, ButtonData:>General::meprec])>}]) Out[6]= 6.551787517854344014050058`14.31640268976547*^-42 We still get a warning message but things are getting definitely better. Having a look at the specified documentation, we try In[7]:= Block[{$MaxExtraPrecision = 1000}, N[expr, 50]] Out[7]= 6.55178751785434401405005796823578794510303347370361442804220253`50.*^ -42 In[8]:= N[exprfs, 50] Out[8]= 6.55178751785434401405005796823578794510303347370361442804220253`50.*^ -42 and we can see that both values are equal (up to 50 digits in our example). We have just done is using arbitrary-precision arithmetic (safe but slow) rather than machine-size precision arithmetic (fast but sometimes surprising, hardware dependent). /J.M. ==== Subject: Re: //N bug, but WHY? The term Cosh[43Pi/Sqrt[2]] has the value 1.5263010243767756 x 10^41, and the rest of the expression has a nearly equal but opposite value - so evaluated to machine precision the subtraction leaves just noise. If you apply FullSimplify it simplifies your expression to something that has only one term - so that presumably yields the correct answer. David Bailey http://www.dbaileyconsultancy.co.uk ==== Subject: Re: //N bug, but WHY? > Evaluating (using //N) two exact same expressions, gives wrong answer unless > fullsimplify is used first, I spent 2 days on a problem thinking my answer > was wrong, but turned out Mathematica 5 was giving me buggy answers, I > debugged it to this point, but WHY in the world is this happening? Please > help!!! cut and paste below to see the test case: In[243]:= > !((Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ > 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // FullSimplify) // > N[IndentingNewLine] > Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ > 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // N) > Out[243]= > !(6.551787517854307`*^-42) > Out[244]= > !((-1.9342813113834067`*^25)) The simplified expression is Sech[(43*Pi)/Sqrt[2]], wich is - with respect to numeric evaluation - completely different from Cosh[(43*Pi)/Sqrt[2]] + (1 - Cosh[43*Sqrt[2]*Pi]) * Csch[43*Sqrt[2]*Pi] * Sinh[(43*Pi)/Sqrt[2]]], where rounding errors occur, which are blown up by the large numbers (Exp[43*Pi/Sqrt[2]] is about 3*10^41). You can't expect a correct result using 16-digit numerics. Try instead: Block[{$MaxExtraPrecision = 86}, N[Cosh[(43*Pi)/Sqrt[2]] + (1 - Cosh[43*Sqrt[2]*Pi])*Csch[43*Sqrt[2]*Pi]*Sinh[(43*Pi)/Sqrt[2]], $MachinePrecision]] this will give you: 6.551787517854344014050058*10^-42 -- http://people.freenet.de/Peter_Berlin/ ==== Subject: Re: //N bug, but WHY? if you use N[] the expression is converted into machine precision numbers, these numbers have only 16 digits and if you make calculations with numbers that need more than 16 digits you get errors. Try Block[{$MaxExtraPrecision = 1000}, (N[#1, 32] & )[Cosh[(43*Pi)/Sqrt[2]] + (1 - Cosh[43*Sqrt[2]*Pi])*Csch[43*Sqrt[2]*Pi]* Sinh[(43*Pi)/Sqrt[2]]]] Jens symbio schrieb im Newsbeitrag > Evaluating (using //N) two exact same > expressions, gives wrong answer unless > fullsimplify is used first, I spent 2 days on a > problem thinking my answer > was wrong, but turned out Mathematica 5 was > giving me buggy answers, I > debugged it to this point, but WHY in the world > is this happening? Please > help!!! cut and paste below to see the test case: In[243]:= > !((Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 > @2 [Pi]])) Csch[ > 43 @2 [Pi]] Sinh[(43 > [Pi])/@2] // FullSimplify) // > N[IndentingNewLine] > Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 > [Pi]])) Csch[ > 43 @2 [Pi]] Sinh[(43 > [Pi])/@2] // N) > Out[243]= > !(6.551787517854307`*^-42) > Out[244]= > !((-1.9342813113834067`*^25)) ==== Subject: Re: //N bug, but WHY? expr=Cosh[(43*Pi)/Sqrt[2]]+(1-Cosh[ 43*Sqrt[2]*Pi])*Csch[43*Sqrt[2]*Pi]*Sinh[(43*Pi)/Sqrt[2]]; You are trying to take the difference of two very large numbers. Precision is an issue term1=expr[[1]] Cosh[(43*Pi)/Sqrt[2]] term2=expr[[2]] (1 - Cosh[43*Sqrt[2]*Pi])*Csch[43*Sqrt[2]*Pi]*Sinh[(43*Pi)/Sqrt[2]] term1//N 1.526301024376754*^41 term2//N -1.5263010243767541*^41 %+%% -1.9342813113834067*^25 expr//N -1.9342813113834067*^25 Using explicit precision will eliminate the problem N[expr,20] 6.55178751785434401405005796823578794`20.*^-42 However, if you simplify, there is only one small term FullSimplify[expr] Sech[(43*Pi)/Sqrt[2]] %//N 6.5517875178544*^-42 Bob Hanlon > ==== > Subject: //N bug, but WHY? Evaluating (using //N) two exact same expressions, gives wrong answer unless > fullsimplify is used first, I spent 2 days on a problem thinking my answer > was wrong, but turned out Mathematica 5 was giving me buggy answers, I > debugged it to this point, but WHY in the world is this happening? Please > help!!! cut and paste below to see the test case: In[243]:= > !((Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ > 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // FullSimplify) // > N[IndentingNewLine] > Cosh[(43 [Pi])/@2] + ((1 - Cosh[43 @2 [Pi]])) Csch[ > 43 @2 [Pi]] Sinh[(43 [Pi])/@2] // N) > Out[243]= > !(6.551787517854307`*^-42) > Out[244]= > !((-1.9342813113834067`*^25)) > ==== Subject: Re: ListDensityPlot Legend? Juergen, How about something like the following? Needs[Graphics`Colors`] matrix = Table[Random[Integer, {0, 2}], {25}, {25}]; colorfunc[z_] := Switch[z, 0, DodgerBlue, 1, LimeGreen, 2, Apricot] mplot = ListDensityPlot[matrix, Frame -> False, ColorFunction -> colorfunc, ColorFunctionScaling -> False, DisplayFunction -> Identity]; Show[Graphics[ {Rectangle[{0, 0}, {1, 1}, mplot], colorfunc[0], Rectangle[{1.05, 0.5}, {1.15, 0.6}], colorfunc[1], Rectangle[{1.05, 0.6}, {1.15, 0.7}], colorfunc[2], Rectangle[{1.05, 0.7}, {1.15, 0.8}], Black, Text[0, {1.1, 0.55}], Text[1, {1.1, 0.65}], Text[2, {1.1, 0.75}], Text[Data Matrix, {0.2, 1.05}, {-1, 0}]}], PlotRange -> {{-0.05, 1.3}, {-0.05, 1.1}}, AspectRatio -> Automatic, TextStyle -> {FontSize -> 14, FontWeight -> Bold}, Background -> Linen, ImageSize -> 450]; David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ dear mathgroup, how does one add a legend to a ListDensityPlot. i've a matrix that contains only 0,1 or 2 entries. ListDensityPlot plots the regions in three different colors. i would like to add a legend that indicates the colors and their corresponding numbers (0,1, or 2). Tom Wickham-Jones' ExtendGraphics package is doing almost what i want for ListContourPlot, however, for ListDensityPlot it's not working. Any ideas? juergen ==== Subject: What we get from (0.0*x), (0.0^x) and similar stuff Many users will see nothing wrong with what we get from the following: In[1]:= Clear[x,y]; {x^0.0, x^0, 0*x*y} Out[2]= {1., 1, 0} But the kernel does nothing to simplify the next input. I suppose this is because the result is Indeterminate in the case of (0.0*Infinity), or (0^0). So then why didn't the kernel account for that with the previous example? In[3]:= {0.0*x*y,0^x,0.0^x} Out[3]= {0. x y, 0^x, 0.^x} We can use the definitions below to ensure the input above returns {0. , 1, 0.} and some will consider this a nice improvement. In[4]:= Unprotect[Times,Power]; Times[0.0,__?(#=!=Indeterminate&&Head[#]=!=DirectedInfinity&)]=0.0; Power[0,_?((!NumericQ[#]||Positive[Re[#]])&&Head[#]=!=DirectedInfinity&)]=0; Power[0.0,_?((!NumericQ[#]||Positive[Re[#]])&&Head[#]=!=DirectedInfinity&)]= 0.0; In[9]:= {0.0*x*y, 0^x, 0.0^x} Out[9]= {0., 0, 0.} After making the above definitions we still get Indeterminate or ComplexInfinity whenever we should. See the next input as an example. In[10]:= {0*x*«, 0*x*Indeterminate, 0^0, 0^Indeterminate, 0^(I-3)} Out[10]= {Indeterminate, Indeterminate, Indeterminate, Indeterminate, ComplexInfinity} However some users might want to always acount for the possibity that we might have (0*Infinity) or (0^0) and so prefer that the list below would return itself. However, I think it isn't possible to do that because since Mathematica Version 3 Times and Power use built-in definitions before user definitions. Am I wrong? Can anyone change the outcome below? In[11]:= Clear[Times,Power]; {x^0.0,x^0,0*x*y} Out[11]= {1., 1, 0} -------- Ted Ersek ==== Subject: Tsunami simulation added to visualization site With the official release of Mathematica 5.2, I have posted a new tsunami simulation to my visualization site. The new visualization is provided as a FLASH animation as well as static bitmaps: http://members.wri.com/jeffb/visualization/animations.shtml and http://members.wri.com/jeffb/visualization/3d.shtml The 3D bitmaps show a comparison between a 32-bit simulation and a 64-bit simulation. The 64-bit simulation allowed for a higher resolution simulation and therefore a smoother result. For more information on this example, see the What's New in 5.2 pages: http://members.wri.com/jeffb/visualization/animations.shtml -Jeff ==== Subject: multiple line copy in InputForm Can anyone tell me how to copy multiple lines in InputForm in Mathematica? For example, When I try to put 3 lines into same cell and at end of each expression I put //InputForm, it only returns the last item in the cell. Also, is there an automatic way to get ALL expressions entered as InputForm? instead of having to type //InputForm at end of each line??? In[59]:= ab + b // InputForm ab + b // InputForm c + d // InputForm Out[61]//InputForm= c + d ==== Subject: Re: multiple line copy in InputForm > Can anyone tell me how to copy multiple lines in InputForm in Mathematica? First, select the cell(s) you want to convert by clicking on the right square bracket(s), holding down the shift or ctrl key (on Windows) to select multiple cells if necessary. Then, in the menu bar select Cell -> Convert To -> InputForm. > Also, is there an automatic way to get ALL expressions entered as InputForm? > instead of having to type //InputForm at end of each line??? Change the default option by selecting in the menu bar Cell -> Default InputFormatType -> InputForm. /J.M. ==== Subject: Superscript Problem Jean-Marc Gulliet, I appreciate your spending the time on my problem. I have two points to make. First, I have just begun using Mathematica, so I would have difficulty applying your algorithm. Second, it would be best to describe my problem in its proper context. I am attaching a Mathematica file that describes the problem and what I have done to circumvent the problem. In short, I placed the superscripts along with the other subscripts that I used in the problem. I simply want to use the superscripts as LABELS and do NOT want them to be interpreted as an exponents. If after reading my attachment you feel you can help, I would greatly appreciate it. Please, however, do not spend too much of your time tending to the problem. Stan CreatedBy='Mathematica 5.1' Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. *******************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 4669, 122]*) (*NotebookOutlinePosition[ 5305, 144]*) (* CellTagsIndexPosition[ 5261, 140]*) (*WindowFrame->Normal*) Notebook[{ Cell[BoxData[ ((;))], Input], Cell[BoxData[ (For[i = 1, i < 8, (i++), For[j = 1, j < 8, (j++), B[i, j] = [Sum]+(n = 1)%3([Sum]+(k = 0)%1([Sum]+(l = 0)%1([Sum]+(p = 0)%1([Sum]+(q = 0)%1((KroneckerDelta[i, 2 ((n + l)) - ((k + 1))]* KroneckerDelta[j, 2 ((n + q)) - ((p + 1))]* b_(n - 1, 2 ((n + l)) - ((k + 1)), 2 ((n + q)) - ((p + 1)))))))))]])], Input], Cell[BoxData[], Input], Cell[CellGroupData[{ Cell[BoxData[ (MatrixForm[Array[B, {7, 7}]])], Input], Cell[BoxData[ TagBox[ RowBox[{(, [NoBreak], GridBox[{ {(b_(0, 1, 1)), (b_(0, 1, 2)), (b_(0, 1, 3)), 0, 0, 0, 0}, {(b_(0, 2, 1)), (b_(0, 2, 2) + b_(1, 2, 2)), (b_(0, 2, 3) + b_(1, 2, 3)), (b_(1, 2, 4)), (b_(1, 2, 5)), 0, 0}, {(b_(0, 3, 1)), (b_(0, 3, 2) + b_(1, 3, 2)), (b_(0, 3, 3) + b_(1, 3, 3)), (b_(1, 3, 4)), (b_(1, 3, 5)), 0, 0}, { 0, (b_(1, 4, 2)), (b_(1, 4, 3)), (b_(1, 4, 4) + b_(2, 4, 4)), (b_(1, 4, 5) + b_(2, 4, 5)), (b_(2, 4, 6)), (b_(2, 4, 7))}, { 0, (b_(1, 5, 2)), (b_(1, 5, 3)), (b_(1, 5, 4) + b_(2, 5, 4)), (b_(1, 5, 5) + b_(2, 5, 5)), (b_(2, 5, 6)), (b_(2, 5, 7))}, {0, 0, 0, (b_(2, 6, 4)), (b_(2, 6, 5)), (b_(2, 6, 6)), (b_(2, 6, 7))}, {0, 0, 0, (b_(2, 7, 4)), (b_(2, 7, 5)), (b_(2, 7, 6)), (b_(2, 7, 7))} }, RowSpacings->1, ColumnSpacings->1, ColumnAlignments->{Left}], [NoBreak], )}], Function[ BoxForm`e$, MatrixForm[ BoxForm`e$]]]], Output] }, Open ]], Cell[BoxData[ ((;))], Input], Cell[BoxData[ (((*;)([IndentingNewLine]) ))], Input] }, FrontEndVersion->5.1 for Macintosh, ScreenRectangle->{{4, 1280}, {0, 1002}}, WindowSize->{945, 767}, WindowMargins->{{4, Automatic}, {Automatic, 4}} ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[1754, 51, 96, 2, 39, Input], Cell[1853, 55, 499, 9, 193, Input], Cell[2355, 66, 26, 0, 39, Input], Cell[CellGroupData[{ Cell[2406, 70, 61, 1, 39, Input], Cell[2470, 73, 1523, 32, 207, Output] }, Open ]], Cell[4008, 108, 361, 5, 154, Input], Cell[4372, 115, 293, 5, 92, Input] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************) ==== Subject: Re: Superscript Problem >Jean-Marc Gulliet, >I appreciate your spending the time on my problem. I have two points to >make. First, I have just begun using Mathematica, so I would have >difficulty applying your algorithm. Second, it would be best to >describe my problem in its proper context. I am attaching a Mathematica >file that describes the problem and what I have done to circumvent the >problem. In short, I placed the superscripts along with the other >subscripts that I used in the problem. I simply want to use the >superscripts as LABELS and do NOT want them to be interpreted as an >exponents. If after reading my attachment you feel you can help, I >would greatly appreciate it. Please, however, do not spend too much of >your time tending to the problem. >Stan > CreatedBy='Mathematica 5.1' Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible >application, such as Mathematica, MathReader or Publicon. The data >for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do >one of the following: * Save the data starting with the line of stars above into a file > with a name ending in .nb, then open the file inside the > application; * Copy the data starting with the line of stars above to the > clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be >sent directly in email or through ftp in text mode. Newlines can be >CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- >compatible application, you must delete the line below containing >the word CacheID, otherwise Mathematica-compatible applications may >try to use invalid cache data. For more information on notebooks and Mathematica-compatible >applications, contact Wolfram Research: > web: http://www.wolfram.com > email: info@wolfram.com > phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from >Wolfram Research. >*******************************************************************) (*CacheID: 232*) >(*NotebookFileLineBreakTest >NotebookFileLineBreakTest*) >(*NotebookOptionsPosition[ 4669, 122]*) >(*NotebookOutlinePosition[ 5305, 144]*) >(* CellTagsIndexPosition[ 5261, 140]*) >(*WindowFrame->Normal*) Notebook[{ >Cell[BoxData[ > ((;))], >Input], Cell[BoxData[ > (For[i = 1, i < 8, (i++), > For[j = 1, > j < 8, (j++), B[i, > j] = [Sum]+(n = 1)%3([Sum]+(k = 0)%1([Sum]+(l = >0)%1([Sum]+(p = 0)%1([Sum]+(q = 0)%1((KroneckerDelta[i, > 2 ((n + l)) - ((k + 1))]* > KroneckerDelta[j, 2 ((n + q)) - ((p + 1))]* > b_(n - 1, 2 ((n + l)) - ((k + 1)), 2 ((n + >q)) - ((p + 1)))))))))]])], Input], Cell[BoxData[], Input], Cell[CellGroupData[{ Cell[BoxData[ > (MatrixForm[Array[B, {7, 7}]])], Input], Cell[BoxData[ > TagBox[ > RowBox[{(, [NoBreak], GridBox[{ > {(b_(0, 1, 1)), (b_(0, 1, 2)), (b_(0, 1, 3)), 0, > 0, 0, 0}, > {(b_(0, 2, 1)), (b_(0, 2, 2) + > b_(1, 2, 2)), (b_(0, 2, 3) + > b_(1, 2, 3)), (b_(1, 2, 4)), (b_(1, 2, 5)), 0, > 0}, > {(b_(0, 3, 1)), (b_(0, 3, 2) + > b_(1, 3, 2)), (b_(0, 3, 3) + > b_(1, 3, 3)), (b_(1, 3, 4)), (b_(1, 3, 5)), 0, > 0}, > { > 0, (b_(1, 4, 2)), (b_(1, 4, 3)), (b_(1, 4, 4) + > b_(2, 4, 4)), (b_(1, 4, 5) + > b_(2, 4, 5)), (b_(2, 4, 6)), (b_(2, 4, 7))}, > { > 0, (b_(1, 5, 2)), (b_(1, 5, 3)), (b_(1, 5, 4) + > b_(2, 5, 4)), (b_(1, 5, 5) + > b_(2, 5, 5)), (b_(2, 5, 6)), (b_(2, 5, 7))}, > {0, 0, > 0, (b_(2, 6, 4)), (b_(2, 6, 5)), (b_(2, 6, > 6)), (b_(2, 6, 7))}, > {0, 0, > 0, (b_(2, 7, 4)), (b_(2, 7, 5)), (b_(2, 7, > 6)), (b_(2, 7, 7))} > }, > RowSpacings->1, > ColumnSpacings->1, > ColumnAlignments->{Left}], [NoBreak], )}], > Function[ BoxForm`e$, > MatrixForm[ BoxForm`e$]]]], Output] >}, Open ]], Cell[BoxData[ > ((superscript, but Mathematica treats all superscripts as exponents thereby >producing unity whenever the superscript is zero. The problem was >circumvented by adopting triple subscripts with the first subscript playing >the role of the superscript>;))], Input], Cell[BoxData[ > (((*)(,)(1)(,)(1)(,)( )))I would like to be !(b_((1)(,) >(1)( ))%0) because it has a special physical >significance.>;)([IndentingNewLine]) > ))], Input] >}, >FrontEndVersion->5.1 for Macintosh, >ScreenRectangle->{{4, 1280}, {0, 1002}}, >WindowSize->{945, 767}, >WindowMargins->{{4, Automatic}, {Automatic, 4}} >] (******************************************************************* >Cached data follows. If you edit this Notebook file directly, not >using Mathematica, you must remove the line containing CacheID at >the top of the file. The cache data will then be recreated when >you save this file from within Mathematica. >*******************************************************************) (*CellTagsOutline >CellTagsIndex->{} >*) (*CellTagsIndex >CellTagsIndex->{} >*) (*NotebookFileOutline >Notebook[{ >Cell[1754, 51, 96, 2, 39, Input], >Cell[1853, 55, 499, 9, 193, Input], >Cell[2355, 66, 26, 0, 39, Input], Cell[CellGroupData[{ >Cell[2406, 70, 61, 1, 39, Input], >Cell[2470, 73, 1523, 32, 207, Output] >}, Open ]], >Cell[4008, 108, 361, 5, 154, Input], >Cell[4372, 115, 293, 5, 92, Input] >} >] >*) (******************************************************************* >End of Mathematica Notebook file. >*******************************************************************) > Why not try this, CreatedBy='Mathematica 5.1' Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. *******************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 2430, 67]*) (*NotebookOutlinePosition[ 3075, 89]*) (* CellTagsIndexPosition[ 3031, 85]*) (*WindowFrame->Normal*) Notebook[{ Cell[BoxData[{ (For[i = 1, i < 8, (i++), For[j = 1, j < 8, (j++), B[i, j] = [Sum]+(n = 1)%3([Sum]+(k = 0)%1([Sum]+ (l = 0)%1([Sum]+(p = 0)%1([Sum]+(q = 0)%1((KroneckerDelta[i, 2 ((n + l)) - ((k + 1))]* KroneckerDelta[j, 2 ((n + q)) - ((p + 1))]* Subscript[Superscript[b, n - 1], 2*((n + 1)) - ((k + 1)), 2*((n + q)) - ((p + l))]))))))]]), [IndentingNewLine], (MatrixForm[Array[B, {7, 7}]])}], Input] }, FrontEndVersion->5.1 for Microsoft Windows, ScreenRectangle->{{0, 1024}, {0, 695}}, WindowSize->{945, 752}, WindowMargins->{{Automatic, 2}, {Automatic, -23}} ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[1754, 51, 672, 14, 161, Input] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************) Pratik -- Pratik Desai Graduate Student UMBC Department of Mechanical Engineering Phone: 410 455 8134 ==== Subject: Re: Superscript Problem Hi Stan, you are right most superscripts are treated as an exponent. A way around is to use low level input, e.g. SubsuperscriptBox The drawback is, that you must use DisplayForm to view the glamour if it. Example: a1=SubsuperscriptBox[b, 0, 0]; a2=SubsuperscriptBox[b, 1, 0]; (*do not use the same variable name on the left side like inside SubsuperscriptBox*) with a1 and a2 you can do whatever you want, but if you want to see the super and subscripts you need to use DisplayForm a1 gives: SubsuperscriptBox[b, 0, 0] not what you want but: a1 //DisplayForm gives bd0u0 where I use d for subscript and u for superscript. a1 a1 //DisplayForm gives (bd0u0)^2 a1 a2 //DisplayForm gives bd0u0 bd1u0 sincerely, Daniel > Jean-Marc Gulliet, > I appreciate your spending the time on my problem. I have two points to > make. First, I have just begun using Mathematica, so I would have > difficulty applying your algorithm. Second, it would be best to > describe my problem in its proper context. I am attaching a Mathematica > file that describes the problem and what I have done to circumvent the > problem. In short, I placed the superscripts along with the other > subscripts that I used in the problem. I simply want to use the > superscripts as LABELS and do NOT want them to be interpreted as an > exponents. If after reading my attachment you feel you can help, I > would greatly appreciate it. Please, however, do not spend too much of > your time tending to the problem. > Stan > CreatedBy='Mathematica 5.1' Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible > application, such as Mathematica, MathReader or Publicon. The data > for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do > one of the following: * Save the data starting with the line of stars above into a file > with a name ending in .nb, then open the file inside the > application; * Copy the data starting with the line of stars above to the > clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be > sent directly in email or through ftp in text mode. Newlines can be > CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- > compatible application, you must delete the line below containing > the word CacheID, otherwise Mathematica-compatible applications may > try to use invalid cache data. For more information on notebooks and Mathematica-compatible > applications, contact Wolfram Research: > web: http://www.wolfram.com > email: info@wolfram.com > phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from > Wolfram Research. > *******************************************************************) (*CacheID: 232*) > (*NotebookFileLineBreakTest > NotebookFileLineBreakTest*) > (*NotebookOptionsPosition[ 4669, 122]*) > (*NotebookOutlinePosition[ 5305, 144]*) > (* CellTagsIndexPosition[ 5261, 140]*) > (*WindowFrame->Normal*) Notebook[{ > Cell[BoxData[ > ((;))], > Input], Cell[BoxData[ > (For[i = 1, i < 8, (i++), > For[j = 1, > j < 8, (j++), B[i, > j] = [Sum]+(n = 1)%3([Sum]+(k = 0)%1([Sum]+(l = > 0)%1([Sum]+(p = 0)%1([Sum]+(q = 0)%1((KroneckerDelta[i, > 2 ((n + l)) - ((k + 1))]* > KroneckerDelta[j, 2 ((n + q)) - ((p + 1))]* > b_(n - 1, 2 ((n + l)) - ((k + 1)), 2 ((n + > q)) - ((p + 1)))))))))]])], Input], Cell[BoxData[], Input], Cell[CellGroupData[{ Cell[BoxData[ > (MatrixForm[Array[B, {7, 7}]])], Input], Cell[BoxData[ > TagBox[ > RowBox[{(, [NoBreak], GridBox[{ > {(b_(0, 1, 1)), (b_(0, 1, 2)), (b_(0, 1, 3)), 0, > 0, 0, 0}, > {(b_(0, 2, 1)), (b_(0, 2, 2) + > b_(1, 2, 2)), (b_(0, 2, 3) + > b_(1, 2, 3)), (b_(1, 2, 4)), (b_(1, 2, 5)), 0, > 0}, > {(b_(0, 3, 1)), (b_(0, 3, 2) + > b_(1, 3, 2)), (b_(0, 3, 3) + > b_(1, 3, 3)), (b_(1, 3, 4)), (b_(1, 3, 5)), 0, > 0}, > { > 0, (b_(1, 4, 2)), (b_(1, 4, 3)), (b_(1, 4, 4) + > b_(2, 4, 4)), (b_(1, 4, 5) + > b_(2, 4, 5)), (b_(2, 4, 6)), (b_(2, 4, 7))}, > { > 0, (b_(1, 5, 2)), (b_(1, 5, 3)), (b_(1, 5, 4) + > b_(2, 5, 4)), (b_(1, 5, 5) + > b_(2, 5, 5)), (b_(2, 5, 6)), (b_(2, 5, 7))}, > {0, 0, > 0, (b_(2, 6, 4)), (b_(2, 6, 5)), (b_(2, 6, > 6)), (b_(2, 6, 7))}, > {0, 0, > 0, (b_(2, 7, 4)), (b_(2, 7, 5)), (b_(2, 7, > 6)), (b_(2, 7, 7))} > }, > RowSpacings->1, > ColumnSpacings->1, > ColumnAlignments->{Left}], [NoBreak], )}], > Function[ BoxForm`e$, > MatrixForm[ BoxForm`e$]]]], Output] > }, Open ]], Cell[BoxData[ > (( superscript, but Mathematica treats all superscripts as exponents thereby > producing unity whenever the superscript is zero. The problem was > circumvented by adopting triple subscripts with the first subscript playing > the role of the superscript>;))], Input], Cell[BoxData[ > (((* )(,)(1)(,)(1)(,)( )))I would like to be !(b_((1)(,) > (1)( ))%0) because it has a special physical > significance.>;)([IndentingNewLine]) > ))], Input] > }, > FrontEndVersion->5.1 for Macintosh, > ScreenRectangle->{{4, 1280}, {0, 1002}}, > WindowSize->{945, 767}, > WindowMargins->{{4, Automatic}, {Automatic, 4}} > ] (******************************************************************* > Cached data follows. If you edit this Notebook file directly, not > using Mathematica, you must remove the line containing CacheID at > the top of the file. The cache data will then be recreated when > you save this file from within Mathematica. > *******************************************************************) (*CellTagsOutline > CellTagsIndex->{} > *) (*CellTagsIndex > CellTagsIndex->{} > *) (*NotebookFileOutline > Notebook[{ > Cell[1754, 51, 96, 2, 39, Input], > Cell[1853, 55, 499, 9, 193, Input], > Cell[2355, 66, 26, 0, 39, Input], Cell[CellGroupData[{ > Cell[2406, 70, 61, 1, 39, Input], > Cell[2470, 73, 1523, 32, 207, Output] > }, Open ]], > Cell[4008, 108, 361, 5, 154, Input], > Cell[4372, 115, 293, 5, 92, Input] > } > ] > *) (******************************************************************* > End of Mathematica Notebook file. > *******************************************************************) > ==== Subject: An Integral best handled by Mathematica_4 I am attaching two Mathematica files that work on two relatively simple integrals. Both integrals are safely handled with Mathematica_4. However, when I tried the same integrals with Mathematica_5, a number of constraints were added. I believe that Mathematica_5 has enlarged the region of analyticity to include complex paths of integration. I would like to know the correct way of imposing the proper constraints to produce the same results as in Mathematica_4? [Attachments are not allowed. Please contact the author to obtain them - moderator] ==== Subject: Re: Simplify poly=p (p-1) b^2+s^2; prod=Sqrt[poly] Sqrt[1/poly]; Since 00] 1 Equivalently, PowerExpand[prod] 1 Bob Hanlon > ==== > Subject: Simplify I'm having some trouble getting an expression to simplify in an obvious > way. (There seems to be a long tradition of users posting to this group > with similar troubles.) The expression is poly = p (p - 1) b^2 + s^2 > prod = Sqrt [poly] Sqrt[1/poly] > Simplify[prod, {0 < p < 1, s > 0, b.93[Micro]Reals}] which should return one, I think, but doesn't. I'd be grateful for suggestions. Paul ==== Subject: Re: Simplify >I'm having some trouble getting an expression to simplify in an >obvious way. (There seems to be a long tradition of users posting >to this group with similar troubles.) >The expression is > poly = p (p - 1) b^2 + s^2 > prod = Sqrt [poly] Sqrt[1/poly] > Simplify[prod, {0 < p < 1, s > 0, b.81.8b.8c[Micro]Reals}] >which should return one, I think, but doesn't. prod//PowerExpand will do what you want. However, you should be aware that the transformation done by PowerExpand is not valid in general which is why it is not one of the transformations used by Simplify or FullSimplify. -- To reply via email subtract one hundred and four ==== Subject: Re: Simplify Paul, I don't think it should simplify. The following simplifies. poly = p*(p - 1)*b^2 + s^2 prod = Sqrt[poly]*Sqrt[1/poly] Simplify[prod, p > 1 && s > 0 && b [Element] Reals] 1 Simplify[prod, p > 1 && {s, b} [Element] Reals] 1 David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ I'm having some trouble getting an expression to simplify in an obvious way. (There seems to be a long tradition of users posting to this group with similar troubles.) The expression is poly = p (p - 1) b^2 + s^2 prod = Sqrt [poly] Sqrt[1/poly] Simplify[prod, {0 < p < 1, s > 0, b.93[Micro]Reals}] which should return one, I think, but doesn't. I'd be grateful for suggestions. Paul ==== Subject: positive square root I work in a world where the square root is always a positive number. But Mathematica allows for the possibility of negative square roots. Two questions arise: (1) Is there a way to tell Mathematica that I'm only interested in positive square roots? (2) My current solution is to use, e.g., Abs[Sqrt[z]]. But when Mathematica echoes this, it puts the Abs function *under* the radical, so it looks like Sqrt[Abs[z]]. Is this a bug in the display? ==== Subject: D[...] change in 5.1 In previous version two lines below seemed to work as intended: In: n /: D[n[i_], x[j_], NonConstants -> {n,r}] := (1/r)( d[i,j] - n[i] n[j] ); D[ 1 + n[k], x[l] ] Out: (-n[k] n[l] + d[k,l]) r But now in ver 5.1 I get something like: Out: D[n, x[l], NonConstants -> {J, r, n}] (1) The funny part is that D[ n[k], x[l] ] is recognized and substituted by the expression associated with definition of n. I wonder whether there is a possibility to get Mathematica 5.1 recognize n[k] as an indexed symbol n. Alexei Akolzin. ==== Subject: Light and surface colors Hi to everyone. I've just obtained a Student License of Mathematica, and I'm working in graphics... I've created, after a half-day of work, an image representing an ellipsoid, with a colored surface When I try to represent it, I must put Ligthing->False to see surface colors. I'd like to know if there's a way to obtain a rendered image, in which I can have both light and surface color, to give a shadow to the figure and create a more 3D effect. Below there's the code... Daniele -------------------------- << Graphics`ContourPlot3D`; a = 7; b = 5; c = 4; r = 1; ellipsoid = ContourPlot3D[ (x/a)^2 + (y/b)^2 + (z/c)^2 - r, { x, -10, 10}, {y, -10, 10}, {z, -10, 10}, PlotPoints -> 12, AspectRatio -> Automatic ]; (*It finds the median point of vertices of a list of a 3D coordinates*) midpoint[l_] := Apply[Plus, Transpose[l], 2]/Length[l]; (*Function to map in the ellipsoid surface*) pressure[x_, y_, z_] := x^2 + y^2 + Sin[4z]; (*Color Function*) color[x_] := Hue[pressure @@ midpoint[x]/50]; (*Rule to change original graphic object*) colorpolygon = Polygon[coord_] :> {color[coord],EdgeForm[{}],Polygon[coord]}; (*creation of new, colored ellipsoid*) coloredellipse = ellipsoid /. colorpolygon; (*Visualization of the shape*) (*I'd like to have also the light...*) Show[coloredellipse, Lighting -> False]; ==== Subject: Re: Simplify >I'm having some trouble getting an expression to simplify in an >obvious way. (There seems to be a long tradition of users posting >to this group with similar troubles.) >The expression is > poly = p (p - 1) b^2 + s^2 > prod = Sqrt [poly] Sqrt[1/poly] > Simplify[prod, {0 < p < 1, s > 0, b.81.8b.8c[Micro]Reals}] >which should return one, I think, but doesn't. prod//PowerExpand will do what you want. However, you should be aware that the transformation done by PowerExpand is not valid in general which is why it is not one of the transformations used by Simplify or FullSimplify. -- To reply via email subtract one hundred and four ==== Subject: Re: Simplify > I'm having some trouble getting an expression to simplify in an >> obvious >> way. (There seems to be a long tradition of users posting to this >> group >> with similar troubles.) >> The expression is >> poly = p (p - 1) b^2 + s^2 >> prod = Sqrt [poly] Sqrt[1/poly] >> Simplify[prod, {0 < p < 1, s > 0, b.93[Micro]Reals}] >> which should return one, I think, but doesn't. >> I'd be grateful for suggestions. >> Paul > prod /. {p -> 1/2, s -> 0, b -> 1} > -1 > prod /. {p -> 1/2, s -> 1, b -> 0} > 1 > FullSimplify[Abs[prod], {0 < p < 1, s > 0, b.93[Micro]Reals}] > 1 > Andrzej Kozlowski I just noticed that my first example prod /. {p -> 1/2, s -> 0, b -> 1} violates the assumption that s>0. A correct example is prod /. {p -> 1/2, s -> 1/10, b -> 1} -1 I find it curious that some people seem to be recommending a work around (using PowerExpand) that will give the desired answer 1 since this desired answer is simply wrong (of course on the assumption that one follows the usual mathematical conventions that are needed to make Sqrt (a single valued) function). Andrzej Kozlowski ==== Subject: Re: Simplify >I'm having some trouble getting an expression to simplify in an obvious >way. (There seems to be a long tradition of users posting to this group >with similar troubles.) The expression is poly = p (p - 1) b^2 + s^2 > prod = Sqrt [poly] Sqrt[1/poly] > Simplify[prod, {0 < p < 1, s > 0, b.93[Micro]Reals}] which should return one, I think, but doesn't. I'd be grateful for suggestions. Paul > Hi If you look at the help on Sqrt you will find this disclaimer Sqrt[a b] is not automatically converted to Sqrt[a] Sqrt[b] However the next line says These conversions can be done using PowerExpand, but will typically be correct only for positive real arguments. so If you try this Clear[p, b, s, prod, poly] poly[p_, b_, s_] = p *(p - 1) *b^2 + s^2 Sqrt[poly[p, b, s]] *Sqrt[1/poly[p, b, s]] // PowerExpand >>1 Pratik -- Pratik Desai Graduate Student UMBC Department of Mechanical Engineering Phone: 410 455 8134 ==== Subject: Re: Simplify > I'm having some trouble getting an expression to simplify in an > obvious > way. (There seems to be a long tradition of users posting to this > group > with similar troubles.) The expression is poly = p (p - 1) b^2 + s^2 > prod = Sqrt [poly] Sqrt[1/poly] > Simplify[prod, {0 < p < 1, s > 0, b.93[Micro]Reals}] which should return one, I think, but doesn't. I'd be grateful for suggestions. Paul prod /. {p -> 1/2, s -> 0, b -> 1} -1 prod /. {p -> 1/2, s -> 1, b -> 0} 1 FullSimplify[Abs[prod], {0 < p < 1, s > 0, b.93[Micro]Reals}] 1 Andrzej Kozlowski ==== Subject: Simplify I'm having some trouble getting an expression to simplify in an obvious way. (There seems to be a long tradition of users posting to this group with similar troubles.) The expression is poly = p (p - 1) b^2 + s^2 prod = Sqrt [poly] Sqrt[1/poly] Simplify[prod, {0 < p < 1, s > 0, b.93[Micro]Reals}] which should return one, I think, but doesn't. I'd be grateful for suggestions. Paul ==== Subject: Re: Simplify Hi. The fact that Mathematica doesn't simplify the expression with 1 is due to the operand of the Sqrt[] function that must be POSITIVE ( > 0)! If you try with that assumption the Simplify command carries out its work. ~Scout~ paulvonhippel at yahoo ha scritto nel messaggio > I'm having some trouble getting an expression to simplify in an obvious > way. (There seems to be a long tradition of users posting to this group > with similar troubles.) The expression is poly = p (p - 1) b^2 + s^2 > prod = Sqrt [poly] Sqrt[1/poly] > Simplify[prod, {0 < p < 1, s > 0, b.93[Micro]Reals}] which should return one, I think, but doesn't. I'd be grateful for suggestions. Paul > ==== Subject: Re: Simplify > I'm having some trouble getting an expression to simplify in an obvious > way. (There seems to be a long tradition of users posting to this group > with similar troubles.) The expression is poly = p (p - 1) b^2 + s^2 > prod = Sqrt [poly] Sqrt[1/poly] > Simplify[prod, {0 < p < 1, s > 0, b=CF=B5Reals}] which should return one, I think, but doesn't. I'd be grateful for suggestions. Paul > It's quite easy: In[1]:= $Assumptions = 1 > p > 0 < s && Element[b, Reals]; poly = p*(p - 1)*b^2 + s^2; prod = Sqrt[poly]*Sqrt[1/poly]; In[4]:= Simplify[prod, s > Abs[b]*Sqrt[p*(1 - p)] ] Out[4]= 1 In[5]:= Simplify[prod, s < Abs[b]*Sqrt[p*(1 - p)]] Out[5]= -1 -- http://people.freenet.de/Peter_Berlin/ ==== Subject: Re: Simplify > I'm having some trouble getting an expression to simplify in an obvious > way. (There seems to be a long tradition of users posting to this group > with similar troubles.) The expression is poly = p (p - 1) b^2 + s^2 > prod = Sqrt [poly] Sqrt[1/poly] > Simplify[prod, {0 < p < 1, s > 0, b.93[Micro]Reals}] which should return one, I think, but doesn't. I'd be grateful for suggestions. Paul > There is indeed a long tradition of users posting questions about Simplify and FullSimplify, however most of these are misunderstandings. In your case it is easier to consider simplifying Sqrt[x]Sqrt[1/x] (where x is your polynomial). This also fails unless you add the assumption that x>0 (which implies that x is also Real): Simplify[Sqrt[x]Sqrt[1/x],x>0] To see why this assumption is necessary consider the case where x=-1. You get Sqrt[-1]Sqrt[-1], which equals I*I, which is -1. The other thing to remember about Simplify and FullSimplify is that there is no guarantee of success, nor is the concept of the simplest form well defined - so you don't always get complete simplification even when it is valid. David Bailey http://www.dbaileyconsultancy.co.uk ==== Subject: Re: Simplify Hi Paul, a square root has in general 2 solutions. Therfore, if you replace your expression by one you loose the solution -1. There is a function that does what you want: PowerExpand. However, this function does potentially unsave operations by making assumptions about its arguments. Using PowerExpand, you better check if the answer is what you want. sincerely, Daniel > I'm having some trouble getting an expression to simplify in an obvious > way. (There seems to be a long tradition of users posting to this group > with similar troubles.) The expression is poly = p (p - 1) b^2 + s^2 > prod = Sqrt [poly] Sqrt[1/poly] > Simplify[prod, {0 < p < 1, s > 0, b.93[Micro]Reals}] which should return one, I think, but doesn't. I'd be grateful for suggestions. Paul > ==== Subject: Re: Simplify > I'm having some trouble getting an expression to simplify in an obvious > way. (There seems to be a long tradition of users posting to this group > with similar troubles.) The expression is poly = p (p - 1) b^2 + s^2 > prod = Sqrt [poly] Sqrt[1/poly] > Simplify[prod, {0 < p < 1, s > 0, b.93[Micro]Reals}] which should return one, I think, but doesn't. I'd be grateful for suggestions. Paul > Hi Paul, Use *PowerExpand* rather than *Simplify* since *Simplify* does not expand powers. In[1]:= poly = p*(p - 1)*b^2 + s^2 Out[1]= b^2*(-1 + p)*p + s^2 In[2]:= prod = Sqrt[poly]*Sqrt[1/poly] Out[2]= Sqrt[1/(b^2*(-1 + p)*p + s^2)]* Sqrt[b^2*(-1 + p)*p + s^2] In[3]:= PowerExpand[prod] Out[3]= 1 /J.M.