From: David Park on 22 Apr 2010 03:29 The surer and more stable method for manipulating complex expressions is always ComplexExpand. Conjugate[a b]; ComplexExpand[%, {b}, TargetFunctions -> {Conjugate}] a Conjugate[b] or Conjugate[a b]; Simplify[%, a \[Element] Reals] a Conjugate[b] David Park djmpark(a)comcast.net http://home.comcast.net/~djmpark/ From: slawek [mailto:a(a)b.c] In[1] := Im[a] ^= 0; Conjugate[a b] Out[1] := Conjugate[a b] It is not funny, Mathematica 6 properly evaluates the result a Conjugate[b] What happens? slawek
From: slawek on 22 Apr 2010 03:29 U=BFytkownik "David Bailey" <dave(a)removedbailey.co.uk> napisa=B3 w wiadomo=B6ci grup dyskusyjnych:hqmoku$4d7$1(a)smc.vnet.net... > 1) The answer from 7.0.1 is not wrong - just not in the form you desired. Thanks for a reply. It is wrong because Mathematica should present results in the simplest form and the Conjugate[a] is not the simplest form. > 2) Your code assumed that Conjugate called Im internally - this is the > sort of assumption that may vary from one version to the next. Mathematica should check all data on a symbol: is it real? is it complex? is it a matrix? is it a constant? The Im[variable]^=0 was a well known practice to define that a variable is real. Nevertheless you are right: Mathematica degrade from older to 6.0 and 7.0 versions - no more RealsOnly, no ReIm, no working Conjugate. Some changes was forced by poor implementation - e.g. RealsOnly gives horrible wrong results in some cases. > FullSimplify[Conjugate[a b], Im[a] == 0] %/.Conjugate[a b]->a Conjugate[b] is far more simple anyway. > Conjugate[b]) is actually no simpler than Conjugate[a b] Your point of view. I have some nasty integrals, and Conjugate[a b] glue to a^4 to give a^5 Integrate[Conjugate[b]...., ...]. I think that a^5 as a factor is a little simpler than Conjugate[a b] inside Integrate. > In[8]:= complexity[expr_] := LeafCount[expr] + > 10*Count[expr, Conjugate[x_ y_], {0, Infinity}]; > > FullSimplify[Conjugate[a b], Im[a] == 0, > ComplexityFunction -> complexity] A nice feature. Actually I really need to disable Integrate[], because integrals are too complicated for Mathematica (and for me too), but the some simplifications of the kernels of (multiple) integrals are ok. The complete "notebook evaluation" took about an hour. Well, I would substitute: %//.Integrate->dummyIntegration. > Note that although that looks like a lot of work, you can wrap the > process up in a function that you define at startup, or in a package, > and then use as required. The whole notebook (yes, it is about the plasma physics and so on, Very Boring Things) have got about 150 input entries. Some are like this: diff[f_, m_] := Module[{i}, D[f[\[Tau]], \[Tau]] -> D[InterpolatingPolynomial[ Table[{i h, f[\[Tau] + i h]}, {i, -m, 0}], x], x] /. x -> 0 // FullSimplify] discretize2m[eq_, m_] := Solve[eq //. {diff[Subscript[A, 1], m], diff[Subscript[A, 2], m], HoldPattern[Integrate[f_, it_]] -> \[ScriptCapitalI][f, it/h + 1], \[Tau] -> (j - 1) h, \[Tau]a -> (k - 1) h, \[Tau]b -> (l - 1) h, Subscript[A, \[Eta]_][x_] -> Subscript[Z, \[Eta]][x/h]} /. Subscript[Z, \[Eta]_][j_] -> Subscript[Z, \[Eta]][j + 1] // Simplify, {Subscript[Z, 1][j], Subscript[Z, 2][j]}] /. \[ScriptCapitalI][h^n_ f_, lst_] -> h^n \[ScriptCapitalI][f, lst] // Flatten // FullSimplify The problematic was a one single line. Conjugate[a b]->a Conjugate[b] was sufficient to fix this problem. But I lost hours to debug .ma ported from 6.0 to 7.0.1.0 . BTW, this particular notebook generate an crude Fortran code which solves some integro-delayed-difference-equations. slawek slawek
From: Murray Eisenberg on 22 Apr 2010 03:30 As usual, ComplexExpand is your friend in such circumstances. In Mathematica 7: ComplexExpand[Conjugate[a b], b, TargetFunctions -> Conjugate] a Conjugate[b] Without the TargetFunctions option: ComplexExpand[Conjugate[a b], b] -I a Im[b] + a Re[b] On 4/21/2010 4:30 AM, slawek wrote: > In[1] := Im[a] ^= 0; Conjugate[a b] > > Out[1] := Conjugate[a b] > > It is not funny, Mathematica 6 properly evaluates the result > > a Conjugate[b] > > What happens? > > slawek > > -- Murray Eisenberg murray(a)math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305
From: David Bailey on 23 Apr 2010 03:48 slawek wrote: > U=BFytkownik "David Bailey" <dave(a)removedbailey.co.uk> napisa=B3 w wiadomo=B6ci > grup dyskusyjnych:hqmoku$4d7$1(a)smc.vnet.net... >> 1) The answer from 7.0.1 is not wrong - just not in the form you desired. > > Thanks for a reply. > > It is wrong because Mathematica should present results in the simplest form > and the Conjugate[a] is not the simplest form. > >> 2) Your code assumed that Conjugate called Im internally - this is the >> sort of assumption that may vary from one version to the next. > > Mathematica should check all data on a symbol: is it real? is it complex? is > it a matrix? is it a constant? The Im[variable]^=0 was a well known practice > to define that a variable is real. Nevertheless you are right: Mathematica > degrade from older to 6.0 and 7.0 versions - no more RealsOnly, no ReIm, no > working Conjugate. Some changes was forced by poor implementation - e.g. > RealsOnly gives horrible wrong results in some cases. > >> FullSimplify[Conjugate[a b], Im[a] == 0] > > %/.Conjugate[a b]->a Conjugate[b] is far more simple anyway. > >> Conjugate[b]) is actually no simpler than Conjugate[a b] > > Your point of view. I have some nasty integrals, and Conjugate[a b] glue to > a^4 to give a^5 Integrate[Conjugate[b]...., ...]. I think that a^5 as a > factor is a little simpler than Conjugate[a b] inside Integrate. > Try comparing: a Conjugate[b] // TreeForm and Conjugate[a b] //TreeForm If you do this, you will see why I said that neither was more simple than the other. This often happens - one form may be more desirable than another for some purpose without being simpler. David Bailey http://www.dbaileyconsultancy.co.uk
From: Murray Eisenberg on 23 Apr 2010 03:51 "Should" is a very demanding word! What you might like Mathematica to do and what Mathematica actually does according to its consistent set of rules and language design may be two quite different things. On 4/22/2010 3:29 AM, slawek wrote: > U=BFytkownik "David Bailey"<dave(a)removedbailey.co.uk> napisa=B3 w wiadomo=B6ci > grup dyskusyjnych:hqmoku$4d7$1(a)smc.vnet.net... >> 1) The answer from 7.0.1 is not wrong - just not in the form you desired. > > Thanks for a reply. > > It is wrong because Mathematica should present results in the simplest form > and the Conjugate[a] is not the simplest form. > >> 2) Your code assumed that Conjugate called Im internally - this is the >> sort of assumption that may vary from one version to the next. > > Mathematica should check all data on a symbol: is it real? is it complex? is > it a matrix? is it a constant? The Im[variable]^=0 was a well known practice > to define that a variable is real. Nevertheless you are right: Mathematica > degrade from older to 6.0 and 7.0 versions - no more RealsOnly, no ReIm, no > working Conjugate. Some changes was forced by poor implementation - e.g. > RealsOnly gives horrible wrong results in some cases. > >> FullSimplify[Conjugate[a b], Im[a] == 0] > > %/.Conjugate[a b]->a Conjugate[b] is far more simple anyway. > >> Conjugate[b]) is actually no simpler than Conjugate[a b] > > Your point of view. I have some nasty integrals, and Conjugate[a b] glue to > a^4 to give a^5 Integrate[Conjugate[b]...., ...]. I think that a^5 as a > factor is a little simpler than Conjugate[a b] inside Integrate. > >> In[8]:= complexity[expr_] := LeafCount[expr] + >> 10*Count[expr, Conjugate[x_ y_], {0, Infinity}]; >> >> FullSimplify[Conjugate[a b], Im[a] == 0, >> ComplexityFunction -> complexity] > > A nice feature. Actually I really need to disable Integrate[], because > integrals are too complicated for Mathematica (and for me too), but the some > simplifications of the kernels of (multiple) integrals are ok. The complete > "notebook evaluation" took about an hour. Well, I would substitute: > %//.Integrate->dummyIntegration. > >> Note that although that looks like a lot of work, you can wrap the >> process up in a function that you define at startup, or in a package, >> and then use as required. > > The whole notebook (yes, it is about the plasma physics and so on, Very > Boring Things) have got about 150 input entries. Some are like this: > > diff[f_, m_] := > Module[{i}, > D[f[\[Tau]], \[Tau]] -> > D[InterpolatingPolynomial[ > Table[{i h, f[\[Tau] + i h]}, {i, -m, 0}], x], x] /. x -> 0 // > FullSimplify] > > discretize2m[eq_, m_] := Solve[eq //. > {diff[Subscript[A, 1], m], diff[Subscript[A, 2], m], > HoldPattern[Integrate[f_, it_]] -> \[ScriptCapitalI][f, > it/h + 1], > \[Tau] -> (j - 1) h, \[Tau]a -> (k - > 1) h, \[Tau]b -> (l - 1) h, > Subscript[A, \[Eta]_][x_] -> Subscript[Z, \[Eta]][x/h]} /. > Subscript[Z, \[Eta]_][j_] -> Subscript[Z, \[Eta]][j + 1] // > Simplify, {Subscript[Z, 1][j], > Subscript[Z, 2][j]}] /. \[ScriptCapitalI][h^n_ f_, lst_] -> > h^n \[ScriptCapitalI][f, lst] // Flatten // FullSimplify > > The problematic was a one single line. Conjugate[a b]->a Conjugate[b] was > sufficient to fix this problem. > > But I lost hours to debug .ma ported from 6.0 to 7.0.1.0 . > > BTW, this particular notebook generate an crude Fortran code which solves > some integro-delayed-difference-equations. > > slawek > > > slawek > > > -- Murray Eisenberg murray(a)math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305
|
Pages: 1 Prev: Finding the extreme function values. Next: Header and Footer Number of Pages |