2013-02-03 58 views
0

有一天,我想簡化下面的表達式:簡化複雜的表達式

a Conjugate[a]//FullSimplify 

太好了!我們收到的答案是Abs [a]^2。 現在,我想是這樣的:

a b Conjugate[a]//FullSimplify (*a Conjugate[a] b will return the same output*) 

很遺憾,沒有簡化。 LeafCount更喜歡Abs [a]^2 b的非簡化表達式。 ComplexityFunction應該能夠解決這個問題: ComplexityFunction

我用上面的鏈接提供的功能:

f[e_] := StringLength[ToString[InputForm[e]]] 
FullSimplify[a Conjugate[a] b, ComplexityFunction -> f] 

我仍然得到了不想要的形式。

是否有解決方法?

回答

1

我剛剛在我的問題here在StackExchange上了解到這一點。你可以這樣做:

f[expr_]:=expr/.x_*Conjugate[x_]:>Abs[x]^2 
Simplify[a Conjugate[a] b,TransformationFunctions->{Automatic,f},ComplexityFunction->(StringLength[ToString[InputForm[#]]]&)] 

它會給b Abs[a]^2

+0

看起來不錯,謝謝! –