Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
make it build
Browse files Browse the repository at this point in the history
  • Loading branch information
mantepse committed Aug 13, 2016
1 parent d8a26e1 commit b2ee8cc
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/sage/interfaces/fricas.py
Expand Up @@ -83,7 +83,7 @@
sage: print(fricas.eval('factor(x^5 - y^5)')) # optional - fricas
4 3 2 2 3 4
- (y - x)(y + x y + x y + x y + x ) Type: Factored(Polynomial(Integer))
- (y - x)(y + x y + x y + x y + x )
We can create the polynomial `f` as a FriCAS polynomial,
then call the factor method on it. Notice that the notation
Expand All @@ -93,10 +93,10 @@
::
sage: f = fricas('x^5 - y^5') # optional - fricas
sage: f^2 # optional - fricas
sage: f^2 # optional - fricas
10 5 5 10
y - 2x y + x
sage: f.factor() # optional - fricas
sage: f.factor() # optional - fricas
4 3 2 2 3 4
- (y - x)(y + x y + x y + x y + x )
Expand Down Expand Up @@ -152,15 +152,15 @@
#
# http://www.gnu.org/licenses/
###########################################################################
from __future__ import print_function
from __future__ import absolute_import
# from __future__ import print_function
# from __future__ import absolute_import

from .axiom import PanAxiomElement, PanAxiomFunctionElement, PanAxiomExpectFunction
from sage.interfaces.axiom import PanAxiomElement, PanAxiomFunctionElement, PanAxiomExpectFunction
from sage.interfaces.tab_completion import ExtraTabCompletion
from expect import Expect, ExpectElement, FunctionElement, ExpectFunction
from sage.interfaces.expect import Expect, ExpectElement, FunctionElement, ExpectFunction
from sage.env import DOT_SAGE
import re
import six
from sage.rings.all import RealField, ZZ, QQ

FRICAS_SINGLE_LINE_START = 3 # where the output starts
FRICAS_MULTI_LINE_START = 2
Expand Down Expand Up @@ -406,7 +406,7 @@ def __getitem__(self, n):
raise NotImplementedError

def __int__(self):
raise NotImplementedError
return int(self.sage())

def bool(self):
raise NotImplementedError
Expand All @@ -418,7 +418,7 @@ def __long__(self):
raise NotImplementedError

def __float__(self):
raise NotImplementedError
return float(self.sage())

def _integer_(self, ZZ=None):
raise NotImplementedError
Expand Down Expand Up @@ -449,6 +449,13 @@ def _get_1d_output(self):
P = self._check_valid()
return P.eval('unparse(%s::InputForm)' %self._name).replace("\r\n", "")[1:-1]

def type(self):
"""
Return the type of the object in FriCAS as a FriCAS object.
"""
P = self._check_valid()
return P(self._get_type_str())

def _get_type_str(self):
P = self._check_valid()
output = P._eval_line(self._name + ";")
Expand All @@ -457,6 +464,7 @@ def _get_type_str(self):
return m.groups()[0]

def _get_type(self):
import ast
def to_list_of_lists(node):
if isinstance(node, ast.Name):
return node.id
Expand All @@ -474,6 +482,12 @@ def to_list_of_lists(node):
return to_list_of_lists(A.body[0].value)

def _get_sage_type(self, type):
from sage.rings.all import ZZ, QQ, QQbar, PolynomialRing, RDF
from sage.rings.fraction_field import FractionField
from sage.rings.finite_rings.integer_mod_ring import Integers
from sage.rings.real_mpfr import RealField
from sage.symbolic.ring import SR

if type in ["Integer", "NonNegativeInteger", "PositiveInteger"]:
return ZZ
elif type == "String":
Expand Down Expand Up @@ -576,6 +590,13 @@ def _sage_(self):
x + x - 1
"""
from sage.rings.all import ZZ, QQ, QQbar, PolynomialRing, RDF
from sage.rings.fraction_field import FractionField
from sage.rings.finite_rings.integer_mod_ring import Integers
from sage.rings.real_mpfr import RealField
from sage.symbolic.ring import SR
from sage.misc.sage_eval import sage_eval

type = self._get_type()
if type in ["Integer", "NonNegativeInteger", "PositiveInteger"]:
return ZZ(self._get_1d_output())
Expand All @@ -590,13 +611,11 @@ def _sage_(self):
return R(ZZ(x)*ZZ(b)**ZZ(e))

elif type == "DoubleFloat":
from sage.rings.all import RDF
return RDF(self._get_1d_output())

elif type == "AlgebraicNumber":
from sage.rings.all import QQbar
s = self._get_1d_output()[:-len("::AlgebraicNumber()")]
return sage.misc.sage_eval.sage_eval("QQbar(" + s + ")")
return sage_eval("QQbar(" + s + ")")

elif isinstance(type, list):
if type[0] == "List":
Expand All @@ -616,7 +635,6 @@ def _sage_(self):
return self.numer().sage()/self.denom().sage()

elif type[0] == "Polynomial":
from sage.rings.all import PolynomialRing
base_ring = self._get_sage_type(type[1])
vars = self.variables()._get_1d_output()[1:-1]
R = PolynomialRing(base_ring, vars)
Expand All @@ -628,7 +646,6 @@ def _sage_(self):
return SR(s)

elif type[0] == 'DistributedMultivariatePolynomial':
from sage.rings.all import PolynomialRing
base_ring = self._get_sage_type(type[2])
vars = type[1]
R = PolynomialRing(base_ring, vars)
Expand Down

0 comments on commit b2ee8cc

Please sign in to comment.