Ask Your Question
1

How to force the substitution since subs is not working?

asked 2022-05-01 00:58:43 +0100

ny2292000 gravatar image

updated 2022-05-01 05:31:09 +0100

slelievre gravatar image

I have an expression containing alpha_1, beta_1, gamma_1.

They are normalized by the constraint alpha_1^2 + beta_1^2 + gamma_1^2 = 1.

That would simplify the expression. Somehow subs doesn't work.

After defining dkkr1 as

dkkr1 = 2*I*pi*sqrt(-c^2*gamma_1^2 - (alpha_1^2 + beta_1^2)*c^2 + v2^2)*sqrt((alpha_1^2 + beta_1^2 + gamma_1^2)*v1^2 + c^2)*beta_1/(c^2*gamma_1^2 + (alpha_1^2 + beta_1^2)*c^2 - v2^2) - 2*(-I*pi*sqrt(-c^2*gamma_1^2 - (alpha_1^2 + beta_1^2)*c^2 + v2^2)*sqrt((alpha_1^2 + beta_1^2 + gamma_1^2)*v1^2 + c^2)*alpha_1^2*c^4 - I*pi*sqrt(-c^2*gamma_1^2 - (alpha_1^2 + beta_1^2)*c^2 + v2^2)*sqrt((alpha_1^2 + beta_1^2 + gamma_1^2)*v1^2 + c^2)*c^4*gamma_1^2 + (I*pi*sqrt(-c^2*gamma_1^2 - (alpha_1^2 + beta_1^2)*c^2 + v2^2)*sqrt((alpha_1^2 + beta_1^2 + gamma_1^2)*v1^2 + c^2)*beta_1^2*v1^2 + I*pi*sqrt(-c^2*gamma_1^2 - (alpha_1^2 + beta_1^2)*c^2 + v2^2)*sqrt((alpha_1^2 + beta_1^2 + gamma_1^2)*v1^2 + c^2)*c^2)*v2^2)*Delta/(c^6*gamma_1^4 + 2*(alpha_1^2 + beta_1^2)*c^6*gamma_1^2 + (alpha_1^4 + 2*alpha_1^2*beta_1^2 + beta_1^4)*c^6 + ((alpha_1^2 + beta_1^2 + gamma_1^2)*v1^2 + c^2)*v2^4 + (c^4*gamma_1^6 + 3*(alpha_1^2 + beta_1^2)*c^4*gamma_1^4 + 3*(alpha_1^4 + 2*alpha_1^2*beta_1^2 + beta_1^4)*c^4*gamma_1^2 + (alpha_1^6 + 3*alpha_1^4*beta_1^2 + 3*alpha_1^2*beta_1^4 + beta_1^6)*c^4)*v1^2 - 2*(c^4*gamma_1^2 + (alpha_1^2 + beta_1^2)*c^4 + (c^2*gamma_1^4 + 2*(alpha_1^2 + beta_1^2)*c^2*gamma_1^2 + (alpha_1^4 + 2*alpha_1^2*beta_1^2 + beta_1^4)*c^2)*v1^2)*v2^2)

I try to substitute

dkkr1= dkkr1.subs(sqrt(1- alpha_1^2 - beta_1^2)  ==  gamma_1)
show(dkkr1)

I am new to SageMath and would love to learn how to make this work.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2022-05-01 07:29:07 +0100

tmonteil gravatar image

The thing to understand is that the subs method work at the level of the expression tree : when the pattern is found in the tree, it is replaced.

For example, 2*(a + b) is represented as the following tree:

*
├── 2
└── +
    ├── a
    └── b

However, the addition is not considered as a binary operation, but as an operation of arbitrary arity, hence 2*(a + b + c) is not represented as

*
├── 2
└── +
    ├── a
    └── +
        ├── b
        └── c

but as

*
├── 2
└── +
    ├── a
    ├── b
    └── c

This implies that a+b is not a subtree of a+b+c.

In particular, you have to define two different rules to replace alpha_1^2 + beta_1^2 with 1 - gamma_1^2 and alpha_1^2 + beta_1^2 + gamma_1^2 with 1.

In terms of code, the previous explanations translate to:

sage: dkkr1.subs(alpha_1^2 + beta_1^2 == 1-gamma_1^2, alpha_1^2 + beta_1^2 + gamma_1^2 == 1)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-05-01 00:58:43 +0100

Seen: 278 times

Last updated: May 01 '22