Commits (8)
 ... ... @@ -1572,7 +1572,7 @@ class FriCASElement(ExpectElement): from sage.functions.other import abs from sage.misc.functional import symbolic_sum, symbolic_prod from sage.rings.infinity import infinity register_symbol(I, {'fricas': '%i'}) register_symbol(I, {'fricas': '(%i::EXPR Complex INT)'}) register_symbol(e, {'fricas': '%e'}) register_symbol(pi, {'fricas': 'pi'}) # fricas uses both pi and %pi register_symbol(lambda: infinity, {'fricas': 'infinity'}) ... ... @@ -1720,7 +1720,7 @@ class FriCASElement(ExpectElement): We can also convert FriCAS's polynomials to Sage polynomials:: sage: a = fricas(x^2 + 1); a.typeOf() # optional - fricas sage: a = fricas("x^2 + 1"); a.typeOf() # optional - fricas Polynomial(Integer) sage: a.sage() # optional - fricas x^2 + 1 ... ...
 ... ... @@ -945,6 +945,75 @@ class FriCASConverter(InterfaceInit): import sage.interfaces.fricas super(FriCASConverter, self).__init__(sage.interfaces.fricas.fricas) def pyobject(self, ex, obj): """ EXAMPLES:: sage: 2._fricas_().domainOf() # optional - fricas PositiveInteger() sage: (-1/2)._fricas_().domainOf() # optional - fricas Fraction(Integer()) sage: SR(2)._fricas_().domainOf() # optional - fricas Expression(Integer()) sage: (sqrt(2))._fricas_().domainOf() # optional - fricas Expression(Integer()) sage: pi._fricas_().domainOf() # optional - fricas Pi() sage: asin(pi)._fricas_() # optional - fricas asin(%pi) sage: ex = (I+sqrt(2)+2) sage: ex._fricas_().domainOf() # optional - fricas Expression(Complex(Integer())) sage: ex._fricas_()^2 # optional - fricas +-+ (4 + 2 %i)\|2 + 5 + 4 %i sage: (ex^2)._fricas_() # optional - fricas +-+ (4 + 2 %i)\|2 + 5 + 4 %i """ try: result = getattr(obj, self.name_init)() if (isinstance(obj, NumberFieldElement_quadratic) and obj.parent() == GaussianField): return "((%s)::EXPR COMPLEX INT)" % result except AttributeError: result = repr(obj) return "((%s)::EXPR INT)" % result def symbol(self, ex): """Convert the argument, which is a symbol, to FriCAS. In this case, we do not return an `Expression Integer`, because FriCAS frequently requires elements of domain `Symbol` or `Variable` as arguments, for example to `integrate`. Moreover, FriCAS is able to do the conversion itself, whenever the argument should be interpreted as a symbolic expression. EXAMPLES:: sage: x._fricas_().domainOf() # optional - fricas Variable(x) sage: (x^2)._fricas_().domainOf() # optional - fricas Expression(Integer()) sage: (2*x)._fricas_().integrate(x) # optional - fricas 2 x """ return repr(ex) def derivative(self, ex, operator): """ Convert the derivative of ``self`` in FriCAS. ... ...
 ... ... @@ -374,7 +374,7 @@ def fricas_integrator(expression, v, a=None, b=None, noPole=True): sage: fricas_integrator(cos(x), x) # optional - fricas sin(x) sage: fricas_integrator(1/(x^2-2), x, 0, 1) # optional - fricas 1/4*sqrt(2)*(log(3*sqrt(2) - 4) - log(sqrt(2))) -1/8*sqrt(2)*(log(2) - log(-24*sqrt(2) + 34)) sage: fricas_integrator(1/(x^2+6), x, -oo, oo) # optional - fricas 1/6*sqrt(6)*pi ... ... @@ -387,33 +387,46 @@ def fricas_integrator(expression, v, a=None, b=None, noPole=True): Check that in case of failure one gets unevaluated integral:: sage: integral(cos(ln(cos(x))), x, 0, pi/8, algorithm='fricas') # optional - fricas sage: integral(cos(ln(cos(x))), x, 0, pi/8, algorithm='fricas') # optional - fricas integrate(cos(log(cos(x))), x, 0, 1/8*pi) sage: integral(cos(ln(cos(x))), x, algorithm='fricas') # optional - fricas sage: integral(cos(ln(cos(x))), x, algorithm='fricas') # optional - fricas integral(cos(log(cos(x))), x) Check that :trac:`28641` is fixed:: sage: integrate(sqrt(2)*x^2 + 2*x, x, algorithm="fricas") # optional - fricas 1/3*sqrt(2)*x^3 + x^2 sage: integrate(sqrt(2), x, algorithm="fricas") # optional - fricas sqrt(2)*x sage: integrate(1, x, algorithm="fricas") # optional - fricas x """ if not isinstance(expression, Expression): expression = SR(expression) from sage.interfaces.fricas import fricas ex = fricas(expression) e_fricas = fricas(expression) v_fricas = fricas(v) if a is None: result = ex.integrate(v) result = e_fricas.integrate(v_fricas) else: seg = fricas.equation(v, fricas.segment(a, b)) seg = fricas.equation(v_fricas, fricas.segment(a, b)) if noPole: result = ex.integrate(seg, '"noPole"') result = e_fricas.integrate(seg, '"noPole"') else: result = ex.integrate(seg) result = e_fricas.integrate(seg) result = result.sage() if result == "failed": return expression.integrate(v, a, b, hold=True) result = expression.integrate(v, a, b, hold=True) if result == "potentialPole": elif result == "potentialPole": raise ValueError("The integrand has a potential pole" " in the integration interval") ... ...