Ask Your Question
2

Type changing after substitution

asked 2018-06-14 12:46:15 +0100

joaoff gravatar image

Does anyone knows why after the substitution below, the scaled_s21 variable becomes of type 'sage.symbolic.expression.Expression' instead of continuing as 'sage.rings.fraction_field_element.FractionFieldElement_1poly_field'?

I'm confused. I just wanted to use the numerator() and denominator() methods, but with the type changing, I'm unable.

Thnak you!

s = polygen(CC, "s")
p = 0.894289785676221
e = s^4 + 2.14081977623463*s^3 + 3.15237117897600*s^2 + 2.31898630138664*s + 0.902488008823108
s21 = p/e
print(s21)
print(type(s21))
print(s21.parent())
omega0 = sqrt(2*pi*750e6*2*pi*1250e6)
scaled_s21 = s21.subs(s=omega0/(2*pi*1250e6-2*pi*750e6)*(s/omega0 + omega0/s))
print(scaled_s21)
print(type(scaled_s21))
print(scaled_s21.parent())

Output:

0.894289785676221/(s^4 + 2.14081977623463*s^3 + 3.15237117897600*s^2 + 2.31898630138664*s + 0.902488008823108)
<class 'sage.rings.fraction_field_element.FractionFieldElement_1poly_field'>
Fraction Field of Univariate Polynomial Ring in s over Complex Field with 53 bits of precision
0.894289785676221/(1.00000000000000*(3.75000000000000e9*pi/s + (1.00000000000000e-9)*s/pi)^4 + 2.14081977623463*(3.75000000000000e9*pi/s + (1.00000000000000e-9)*s/pi)^3 + 3.15237117897600*(3.75000000000000e9*pi/s + (1.00000000000000e-9)*s/pi)^2 + 8.69619863019990e9*pi/s + (2.31898630138664e-9)*s/pi + 0.902488008823108)
<type 'sage.symbolic.expression.Expression'>
Symbolic Ring
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-06-14 14:52:59 +0100

slelievre gravatar image

updated 2018-06-14 14:56:03 +0100

This is because in Sage, pi lives in the Symbolic Ring.

Define pi as an element of CC before defining omega0, as follows:

pi = CC.pi()

and you will obtain the desired behaviour.

sage: pi = CC.pi()
sage: s = polygen(CC)
sage: p = 0.894289785676221
sage: e = s^4 + 2.14081977623463*s^3 + 3.15237117897600*s^2 + 2.31898630138664*s + 0.902488008823108
sage: s21 = p/e
sage: s21
0.894289785676221/(x^4 + 2.14081977623463*x^3 + 3.15237117897600*x^2 + 2.31898630138664*x + 0.902488008823108)
sage: s21.parent()
Fraction Field of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision
sage: omega0 = sqrt(2*pi*750e6*2*pi*1250e6)
sage: scaled_s21 = s21.subs(s=omega0/(2*pi*1250e6-2*pi*750e6)*(s/omega0 + omega0/s))
sage: scaled_s21
0.894289785676221/(x^4 + 2.14081977623463*x^3 + 3.15237117897600*x^2 + 2.31898630138664*x + 0.902488008823108)
sage: scaled_s21.parent()
Fraction Field of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision
sage: scaled_s21.numerator()
0.894289785676221
sage: scaled_s21.denominator()
x^4 + 2.14081977623463*x^3 + 3.15237117897600*x^2 + 2.31898630138664*x + 0.902488008823108
edit flag offensive delete link more

Comments

Thank you, I was never going to find this out.

joaoff gravatar imagejoaoff ( 2018-06-14 14:57:48 +0100 )edit

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: 2018-06-14 12:46:15 +0100

Seen: 730 times

Last updated: Jun 14 '18