1 | initial version |
The problem is that if you ask sage to convert an expression from SR to FunctionField(SR,'<some var="" name="">') it can do so by considering the entire expression as a "constant" function as far as the function field is concerned. You'll have to tell sage that you want something different. One thing that doesn't work would be to evaluate the expression in the variable that you want:
expr1(s=FF.0)
This doesn't work because in sage, "symbolic expression evaluation" is expected to yield a "symbolic expression". Hence sage first tries to turn FF.0
into an SR element, and fails there (rightly): Note that in FF, we can only represent expressions that have FF.0 occur rationally, whereas in expr1 a priori, we might have variables also occur in exponents etc. So it wouldn't be safe for sage to try anything else.
If you absolutely have to do this, you'll have to do it by hand: determine the coefficients of the numerator and denominator as polynomials in s and reconstruct an element of FF out of it. That isn't as bad as it sounds:
def SRpoleval(expr,var,value):
return sum(c*value**e for c,e in expr.coefficients(var))
def SRtoFF(expr):
return SRpoleval(expr.numerator(),SR('s'),FF.0)/SRpoleval(expr.denominator(),SR('s'),FF.0)
With this you'll get
sage: SRtoFF(expr1)
(s^4 + s^2 + (a^2 + 3)*s + 2)/(s^3 + s + 3)
sage: SRtoFF(expr1).denominator()
s^3 + s + 3
Now do
sage: SRtoFF((sin(SR('s'))+SR('s')^2)/(exp(1+SR('s')^2)-SR('s')^2))
(-s^2 - sin(s))/(s^2 - e^(s^2 + 1))
to see why you should probably not do this in general. I doubt that creating a function field over SR is the best solution to whatever problem you are working on.