ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 13 Jan 2020 16:24:53 -0600Unable to convert string to rational when plus sign is addedhttp://ask.sagemath.org/question/49537/unable-to-convert-string-to-rational-when-plus-sign-is-added/This looks like a bug. The code
QQ('+1')
gives the exception
> TypeError: unable to convert '+1' to a
> rational
This happens with any positive rational, not just 1.
Also, this does not happen with neither
ZZ('+1')
nor
PolynomialRing(QQ,names='x')('+1')
Is this actually a bug? If it is, can someone investigate it and write a trac ticket? I'm quite new to Sagemath and Python and quite unskilled yet to do it properly. Thank you!Jose BroxMon, 13 Jan 2020 16:24:53 -0600http://ask.sagemath.org/question/49537/The shortest string containing all given substringshttp://ask.sagemath.org/question/47438/the-shortest-string-containing-all-given-substrings/I found a problem from https://www.ohjelmointiputka.net/postit/tehtava.php?tunnus=tuet . An English translation goes like this:
A person wants to learn playing tuba. His neigbours get angry for the noise so he tries to find a song that contains as few tunes as possible that he is able to play all four or less tune combinations. The tunes are c, d, e, f, g, a, and h. Output the minimal song.
I tried a code from https://artofproblemsolving.com/community/c163h1889399_shortest_string_containing_all_substrings .
def de_bruijn(k, n):
"""
de Bruijn sequence for alphabet k
and subsequences of length n.
"""
alphabet = k
k = len(k)
a = [0] * k * n
sequence = []
def db(t, p):
if t > n:
if n % p == 0:
sequence.extend(a[1:p + 1])
else:
a[t] = a[t - p]
db(t + 1, p)
for j in range(a[t - p] + 1, k):
a[t] = j
db(t + 1, t)
db(1, 1)
return "".join(alphabet[i] for i in sequence)
seq = de_bruijn("cdefgah", 4)
print(seq)
But the validator on the site says that hccc is missing.
So, how can I use Sagemath to solve the problem that if a set contains letters a, c, d, e, f, g, h, how to find the shortest string containing all one to four letter long substrings?Jaakko SeppäläThu, 08 Aug 2019 08:48:23 -0500http://ask.sagemath.org/question/47438/no module string in sage on Debian 10http://ask.sagemath.org/question/47350/no-module-string-in-sage-on-debian-10/ When I launch sage on Debian 10, I obtain the following message
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.6, Release Date: 2019-01-15 │
│ Using Python 2.7.16. Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
Traceback (most recent call last):
File "/usr/share/sagemath/bin/sage-ipython", line 12, in <module>
from sage.repl.interpreter import SageTerminalApp
File "/usr/lib/python2.7/dist-packages/sage/repl/interpreter.py", line 108, in <module>
from sage.repl.preparse import preparse
File "/usr/lib/python2.7/dist-packages/sage/repl/preparse.py", line 227, in <module>
from sage.repl.load import load_wrap
File "/usr/lib/python2.7/dist-packages/sage/repl/load.py", line 19, in <module>
from sage.cpython.string import str_to_bytes, bytes_to_str, FS_ENCODING
ImportError: No module named string
Can you help me?
ThanksfylouFri, 02 Aug 2019 09:03:01 -0500http://ask.sagemath.org/question/47350/Single quotes vs double quoteshttp://ask.sagemath.org/question/46325/single-quotes-vs-double-quotes/Hello, Sage Community.
According to Python's PEP8 on [string quotes](https://www.python.org/dev/peps/pep-0008/#string-quotes), there is no preference between single quotes and double quotes for enclosing strings. Does this rule also applies to Sage? Is there any *de facto* standard?
I always assumed that a huge project like SageMath should have its own set of style rules. (For example, Scilab, another open-source alternative to Matlab, has its coding-style guidelines!)
I suppose this question is specially directed to Sage developers, but any concrete (not opinion-based) answer is welcome!dsejasTue, 23 Apr 2019 13:04:31 -0500http://ask.sagemath.org/question/46325/How to connect Magma_free, SAGE and GAP (problem concerning a MAGMA string not readable by GAP)?http://ask.sagemath.org/question/45267/how-to-connect-magma_free-sage-and-gap-problem-concerning-a-magma-string-not-readable-by-gap/ Hi,
I'd like to ask the following:
I'd like to use SAGE in order to compute something with the free magma online calculator and then convert it into a GAP object. Unfortunately, there occurs an error, and I don't know, how to fix this. Any help is very much appreciated.
I followed the example on page 91 of http://www.math.rwth-aachen.de/~Thomas.Breuer/ctbllib/doc/manual.pdf
Here is what I did:
sage: gap.LoadPackage('"ctbllib"');
sage: ct=magma_free("G:=Alt(5);ct:=CharacterTable(G);ct;")
sage: tmpdir = gap.DirectoryTemporary()
sage: file=gap.Filename(tmpdir, '"magmatable"')
sage: gap.FileString(file,ct)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-fd546564c72c> in <module>()
----> 1 gap.FileString(file,ct)
/opt/sage/local/lib/python2.7/site-packages/sage/interfaces/interface.pyc in __call__(self, *args, **kwds)
627
628 def __call__(self, *args, **kwds):
--> 629 return self._parent.function_call(self._name, list(args), kwds)
630
631 def _instancedoc_(self):
/opt/sage/local/lib/python2.7/site-packages/sage/interfaces/gap.pyc in function_call(self, function, args, kwds)
921
922 """
--> 923 args, kwds = self._convert_args_kwds(args, kwds)
924 self._check_valid_function_name(function)
925
/opt/sage/local/lib/python2.7/site-packages/sage/interfaces/interface.pyc in _convert_args_kwds(self, args, kwds)
530 for i, arg in enumerate(args):
531 if not isinstance(arg, InterfaceElement) or arg.parent() is not self:
--> 532 args[i] = self(arg)
533 for key, value in iteritems(kwds):
534 if not isinstance(value, InterfaceElement) or value.parent() is not self:
/opt/sage/local/lib/python2.7/site-packages/sage/interfaces/interface.pyc in __call__(self, x, name)
278
279 if isinstance(x, string_types):
--> 280 return cls(self, x, name=name)
281 try:
282 return self._coerce_from_special_method(x)
/opt/sage/local/lib/python2.7/site-packages/sage/interfaces/expect.pyc in __init__(self, parent, value, is_name, name)
1443 except (RuntimeError, ValueError) as x:
1444 self._session_number = -1
-> 1445 raise_(TypeError, TypeError(*x.args), sys.exc_info()[2])
1446 except BaseException:
1447 self._session_number = -1
/opt/sage/local/lib/python2.7/site-packages/sage/interfaces/expect.pyc in __init__(self, parent, value, is_name, name)
1438 else:
1439 try:
-> 1440 self._name = parent._create(value, name=name)
1441 # Convert ValueError and RuntimeError to TypeError for
1442 # coercion to work properly.
/opt/sage/local/lib/python2.7/site-packages/sage/interfaces/interface.pyc in _create(self, value, name)
474 def _create(self, value, name=None):
475 name = self._next_var_name() if name is None else name
--> 476 self.set(name, value)
477 return name
478
/opt/sage/local/lib/python2.7/site-packages/sage/interfaces/gap.pyc in set(self, var, value)
1387 """
1388 cmd = ('%s:=%s;;' % (var, value)).replace('\n','')
-> 1389 self._eval_line(cmd, allow_use_file=True)
1390
1391 def get(self, var, use_file=False):
/opt/sage/local/lib/python2.7/site-packages/sage/interfaces/gap.pyc in _eval_line(self, line, allow_use_file,
wait_for_prompt, restart_if_needed)
787 return ''
788 else:
--> 789 raise RuntimeError(message)
790
791 except KeyboardInterrupt:
TypeError: Gap terminated unexpectedly while reading in a large line:
Gap produced error output
Syntax error: ; expected in /home/boehmler/.sage/temp/mahlzahn/8255/interface/\
tmp8325 line 1
\$sage2:=Character Table of Group G-------------------------------------------\
----------Class | 1 2 3 4 5Size | 1 15 20 12 12Order | 1 2\
3 5 5---------------------------p = 2 1 1 3 5 4p = 3 1\
2 1 5 4p = 5 1 2 3 1 1---------------------------X.1 + \
1 1 1 1 1X.2 + 3 -1 0 Z1 Z1#2X.3 + 3 -1 0 Z1#2 Z1X.4 \
+ 4 0 1 -1 -1X.5 + 5 1 -1 0 0Explanation of Character Valu\
e Symbols--------------------------------------# denotes algebraic conjugation\
, that is,#k indicates replacing the root of unity w by w^kZ1 = (Cyclotomi\
cField(5: Sparse := true)) ! [ RationalField() | 0, 0, -1, -1 ];;
^
executing Read("/home/boehmler/.sage/temp/mahlzahn/8255/interface/tmp8325");
sage:
BernFri, 01 Feb 2019 10:23:52 -0600http://ask.sagemath.org/question/45267/Evaluate from string an equation that has integer divisionhttp://ask.sagemath.org/question/44328/evaluate-from-string-an-equation-that-has-integer-division/ I have the following Python list that contains strings of equations.
L = ['651/349*t + 5382747/9778631000', 't + 57879/196133000', '1000/349*t + 57879/68450417']
You can see that all of the equations have integer division. Because this is obtained by some program, I can not edit the strings.
When I evaluate for `t=1.0` with the following code in SageMath (for example), it does not evaluate as an Euclidean division.
F = function('F')(t)
for k in L:
F(t) = eval(k)
Fc = fast_callable(F, vars=[t])
val2eval = 1.0
print(Fc(val2eval).n(13))
It gives
1.00000000000000
1.00000000000000
2.00000000000000
And should be give
1.86587997307599
1.00029510077345
2.86617507384944
Of course I can solve this by modifying MANUALLY the strings of the equations by indicating that the denominator is a real number and not an integer (I put a decimal point at the end of the integer in the denominator) as following.
L = ['651/349.*t + 5382747/9778631000.', 't + 57879/196133000.', '1000/349.*t + 57879/68450417.']
But this is not the idea, the strings of the equations are generated automatically and one can not modify by editing manually, because it will be implemented in a process where it should be create at least 2000 equations.
Is there some elegant solution for this? --Many thanks!loSuarezBSun, 18 Nov 2018 11:21:18 -0600http://ask.sagemath.org/question/44328/Finding the frequency of each number in a stringhttp://ask.sagemath.org/question/43096/finding-the-frequency-of-each-number-in-a-string/ Hi, I have a string of numbers like s=[(11,23),(33,47),(98,20),...,(34,65)] produced by a code in Jupyter. The biggest number is 100. How can I order the numbers based on their frequency of repetition in s? For example for a simple case like s1=[(1,4),(2,4),(4,1)] the result is
Number 4 frequency 3
Number 1 frequency 2
number 2 frequency 1ASHSun, 22 Jul 2018 04:59:41 -0500http://ask.sagemath.org/question/43096/saving to a .csv filehttp://ask.sagemath.org/question/40137/saving-to-a-csv-file/ In my computations I got a list of strings:
vect = ['00011', '00010', '01011', '01111', '01100']
I need to save it as .csv file, each element row by row, ideally like this:
00011
00010
01011
01111
01100
I use a code:
import csv
C = vect
with open('file_path_vec.csv', 'w') as f:
c = csv.writer(f)
c.writerows(C)
But what I get in my .csv looks like this:
0,0,0,1,1
0,0,0,1,0
0,1,0,1,1
0,1,1,1,1
0,1,1,0,0
Why does it add commas in between? How can I get rid of them?XeniaWed, 13 Dec 2017 08:08:16 -0600http://ask.sagemath.org/question/40137/Typesetting text in TeX view()http://ask.sagemath.org/question/9041/typesetting-text-in-tex-view/Is there a standard way to typeset TeX formulas together with normal text via view()?
So far I've been using
tex_string = "\hbox{- stationary points: }"
for pt in stats:
tex_string += latex(pt)
tex_string += ", "
view(tex_string)
where `stats` is a list of some points (defined with formulas).MathemageThu, 07 Jun 2012 06:36:23 -0500http://ask.sagemath.org/question/9041/How to make a function of 'fname' that produce a file named 'fname'http://ask.sagemath.org/question/36655/how-to-make-a-function-of-fname-that-produce-a-file-named-fname/ Hi all,
Typing a correction on some recurrent sequences $u_{n+1}=f(u_n)$ I use sage to build a nice plot illustrating the behavior of the sequence depending on the initial data.
I took a nice function from this awesome [book.](http://sagebook.gforge.inria.fr/)
def escargot(f,x,u0,n,xmin,xmax,file):
u = u0
P = plot(x, x, xmin, xmax, color='gray')
for i in range(n):
P+= line([[u,u],[u,f(u)],[f(u),f(u)]], color ='red')
u = f(u)
P += f.plot(x, xmin, xmax, color='blue')
P.save('/home/myfolder/f1a.png')
So everyhting work perfectly but, since there is a lot of examples to produce, I would like to make the function to have an extra argument say filename so that now the file so that now the plot is saved in /home/myfolder/filename.png,
but I have no idea how sage manipulate string.
Help would be welcome !
Laurent BSat, 18 Feb 2017 12:38:48 -0600http://ask.sagemath.org/question/36655/sage interactive not working the same in website as mathcloudhttp://ask.sagemath.org/question/31854/sage-interactive-not-working-the-same-in-website-as-mathcloud/ I made a sage interactive. It works great on math cloud. However when I copy paste and format into html and make it online. The interactive says that it does not have enough arguments to format string. Why would this happen if it is the same code?
Here is my code:
<h2>Double integrater</h2>
Alternative to Mathematica double integrater. Way Better!
<div id="mycell">
x,y = var('x,y')
html("<h1>Double Integrator<h1>")
@interact
def interplay(function= input_box(x*y),lower_x_bound= input_box(0),upper_x_bound = input_box(x),lower_y_bound=input_box(0),upper_y_bound=input_box(1),dydx = checkbox(default = False)):
try:
if dydx == False:
result = integral(integral(function,x,lower_x_bound,upper_x_bound),y,lower_y_bound,upper_y_bound)
q ="$\int_{%s}^{%s} \int_{%s}^{%s} %s \,dx\,dy = %s $" % (lower_y_bound, upper_y_bound,lower_x_bound,upper_x_bound,function,result)
else:
result = integral(integral(function,y,lower_y_bound,upper_y_bound),x,lower_x_bound,upper_x_bound)
q ="$\int_{%s}^{%s} \int_{%s}^{%s} %s \,dx\,dy = %s $" % (lower_y_bound, upper_y_bound,lower_x_bound,upper_x_bound,function,result)
pretty_print(html("%s" %q))
except Exception as e :
print("Please enter better inputs")
print(e)
html("<p> done</p>")
</div>
collabmathSat, 26 Dec 2015 22:59:25 -0600http://ask.sagemath.org/question/31854/Generate all binary strings of length nhttp://ask.sagemath.org/question/30644/generate-all-binary-strings-of-length-n/ I need to generate all binary strings of length 15 and then access individual bits. Is there some function for that?
Thank YouProWed, 11 Nov 2015 15:48:42 -0600http://ask.sagemath.org/question/30644/How to cast a string with an exponent from sys.argv to an Integer ?http://ask.sagemath.org/question/29597/how-to-cast-a-string-with-an-exponent-from-sysargv-to-an-integer/Hi,
For an exercise, I have written a Python script that takes an integer argument. Of course, the input in sys.argv is of type 'str', so I cast it to an Integer. It works, but I am supposed to accept numbers written like '123^1237' too, with a hat for the exponent. And I cannot find how to do that. In the sage interpreter, I can type "n = Integer(123^1237)" without any problem, but in my script it fails with a "TypeError: unable to convert '123^1237' to an integer". ThanksOnoxSat, 26 Sep 2015 10:00:01 -0500http://ask.sagemath.org/question/29597/Difficulties evaluating an expression stringhttp://ask.sagemath.org/question/10959/difficulties-evaluating-an-expression-string/For some recent computations, I devolved some initial calculus to the Maxima sub-system, and I've ended up with a list `eqs` of Maxima expressions. I want to transfer this list out of Maxima. This works:
sage: eqs2 = [repr(xx) for xx in eqs]
but gives me strings, which are not useful. And this:
sage: eqs2 = [sage_eval(repr(xx)) for xx in eqs]
returns the error message
NameError: name 'a43' is not defined
which is strange, as it is defined as a variable:
sage: a43
a43
I could create a list of local variables:
vars = {'a21':a21,'a31':a31}
and so on, and use
sage_eval(xx,vars)
but as there are 20 more variables, this would be tedious.
Is there a better way?
AlasdairFri, 24 Jan 2014 13:17:42 -0600http://ask.sagemath.org/question/10959/How to add string tick labels to 2D plots?http://ask.sagemath.org/question/9945/how-to-add-string-tick-labels-to-2d-plots/Hi folks, i want to add string tick labels to a 2D plot, e.g. `['$100', '$200', '$300']` on the x-axis instead of the ticks `[1, 2, 3]`. I see from [http://stackoverflow.com/questions/5439708/python-matplotlib-creating-date-ticks-from-string](http://stackoverflow.com/questions/5439708/python-matplotlib-creating-date-ticks-from-string) that i can do this with matplotlib via
from matplotlib import pyplot as plt
plt.plot([1,2,3],[3,4,3])
ax = plt.gca()
ax.set_xticks([1,2,3])
ax.set_xticklabels(['$100','$200','$300'])
Is there a Sage way to accomplish the same thing?
Personally, i find Sage plotting commands more user-friendly than matplotlib commands.araichevSun, 24 Mar 2013 12:48:21 -0500http://ask.sagemath.org/question/9945/How to output 'decimal' numbers in different radix.http://ask.sagemath.org/question/9657/how-to-output-decimal-numbers-in-different-radix/For example, how to output the fraction 13/7 as a 'decimal' number in the base 6?
Perhaps to 4 'digits' after the 'decimal' point if the representation is not finite.mlvFri, 28 Dec 2012 17:09:31 -0600http://ask.sagemath.org/question/9657/Save plot in SVG with plain text stringshttp://ask.sagemath.org/question/9261/save-plot-in-svg-with-plain-text-strings/Hi all,
as previously stated I am quite inexpert in using both SAGE and Python. I am trying to create figure for a LaTeX report. I am working on a machine on which I cannot use the package to integrate SAGE in LaTeX.
I am quite able to create plots and save them in SVG files. The real problem is that every caption or text in my plots appears as a embedded font or shape or whatever.
Here is an example:
TestPlot=plot(sin(x),(x,0,2*pi))+text("a stupid comment",(pi,2))
show(TestPlot)
TestPlot.save('TestPlot.svg')
This code generates the plot but when I start looking into the SVG file I can see that the caption "a stupid comment" was exported as:
<g id="text_13">
<!-- a stupid comment -->
<defs>
<path id="BitstreamVeraSans-Roman-20"/>
<path d="
M54.8906 33.0156
L54.8906 0
L45.9062 0
L45.9062 32.7188
Q45.9062 40.4844 42.875 44.3281
Q39.8438 48.1875 33.7969 48.1875
Q26.5156 48.1875 22.3125 43.5469
Q18.1094 38.9219 18.1094 30.9062
L18.1094 0
L9.07812 0
L9.07812 54.6875
L18.1094 54.6875
L18.1094 46.1875
Q21.3438 51.125 25.7031 53.5625
Q30.0781 56 35.7969 56
Q45.2188 56 50.0469 50.1719
Q54.8906 44.3438 54.8906 33.0156" id="BitstreamVeraSans-Roman-6e"/>
...
Q40.5312 48.4844 33.4062 48.4844
Q26.2656 48.4844 22.1875 42.8438
Q18.1094 37.2031 18.1094 27.2969
Q18.1094 17.3906 22.1875 11.75
Q26.2656 6.10938 33.4062 6.10938
Q40.5312 6.10938 44.6094 11.75
Q48.6875 17.3906 48.6875 27.2969" id="BitstreamVeraSans-Roman-70"/>
</defs>
<g style="fill:#0000ff;" transform="translate(241.978030233 60.4907451923)scale(0.1 -0.1)">
<use xlink:href="#BitstreamVeraSans-Roman-61"/>
<use x="61.279296875" xlink:href="#BitstreamVeraSans-Roman-20"/>
<use x="93.06640625" xlink:href="#BitstreamVeraSans-Roman-73"/>
<use x="145.166015625" xlink:href="#BitstreamVeraSans-Roman-74"/>
<use x="184.375" xlink:href="#BitstreamVeraSans-Roman-75"/>
<use x="247.75390625" xlink:href="#BitstreamVeraSans-Roman-70"/>
<use x="311.23046875" xlink:href="#BitstreamVeraSans-Roman-69"/>
<use x="339.013671875" xlink:href="#BitstreamVeraSans-Roman-64"/>
<use x="402.490234375" xlink:href="#BitstreamVeraSans-Roman-20"/>
<use x="434.27734375" xlink:href="#BitstreamVeraSans-Roman-63"/>
<use x="489.2578125" xlink:href="#BitstreamVeraSans-Roman-6f"/>
<use x="550.439453125" xlink:href="#BitstreamVeraSans-Roman-6d"/>
<use x="647.8515625" xlink:href="#BitstreamVeraSans-Roman-6d"/>
<use x="745.263671875" xlink:href="#BitstreamVeraSans-Roman-65"/>
<use x="806.787109375" xlink:href="#BitstreamVeraSans-Roman-6e"/>
<use x="870.166015625" xlink:href="#BitstreamVeraSans-Roman-74"/>
</g>
</g>
</g>
</g>
Here I have eliminated a lot of lines for sake of readability. This renders well in SVG viewers but as I convert it to pdf+LaTeX with inkscape the caption is not, of course, converted in LaTeX and thus the appearance of the report is not consistent. Is there a way to force the export to actually export a text object?
What I'd like to have is something like this:
<text
x="160.75159"
y="209.35091"
id="text2987"
xml:space="preserve"
style="font-size:10px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Lucida Sans;-inkscape-font-specification:Lucida Sans"><tspan
x="160.75159"
y="209.35091"
id="tspan2989">\emph{some stupid comment}</tspan></text>
where, as you can see I can also use some LaTeX syntax with no problem.
Best regards,
mcirri
mcirriTue, 21 Aug 2012 22:03:40 -0500http://ask.sagemath.org/question/9261/How to construct a polynomial from string?http://ask.sagemath.org/question/9144/how-to-construct-a-polynomial-from-string/Hi,
I can run the following (putting in a .sage file) successfully.
*R.<x> = QQ[]*
*f = x^3 - x^2 + x -1*
*p = x - 2*
*print f.quo_rem(p)*
But how about I have a string 'x^3 - x^2 + x -1', how can I construct f.
f = SR('x^3 - x^2 + x -1') is not working as there is no member function quo_rem for Expression.
Thanks.skyplutoMon, 09 Jul 2012 19:47:25 -0500http://ask.sagemath.org/question/9144/Converting string into number does not work properlyhttp://ask.sagemath.org/question/9034/converting-string-into-number-does-not-work-properly/Here is an example with huge integer number "n".
n=2^7000000;
Sage can convert huge integer number into string very quickly:
s=str(n);
But the other way, i.e. the same huge string converting back into integer number is very slow:
m=int(s);
It should be done in approximately same time as variables "m", "n", "s" are of the same length.
I also tried to use eval(s) and sage_eval(s) instead of int(s) and all are very slow.
Mathematica can do all the above operation much more quickly than Sage.
Do you know, where the problem is?
Is there some other function besides "int", "eval" and "sage_eval" that can do it faster?azerbajdzanWed, 06 Jun 2012 01:02:20 -0500http://ask.sagemath.org/question/9034/coerce pari type or string to rational function workaround?http://ask.sagemath.org/question/8114/coerce-pari-type-or-string-to-rational-function-workaround/I am getting some rational functions from pari/gp and want to work with them in Sage. I can't figure out how to do the coercion. I tried coercing them directly, and even via a string.
Here's what I've tried:
Make a pari type rational function:
sage: test = gp.simplify((x+y)/y)
This is the field I want to put it in:
sage: R.<x,y> = PolynomialRing(QQ)
sage: S = R.fraction_field()
coercing directly doesn't work:
sage: S(test)
Traceback (most recent call last):
...
TypeError: unable to convert 1/y*x + 1 to a rational
So I tried making a string out of it:
sage: str(test)
'1/y*x + 1'
Of course, sage would accept that string if I typed it in directly:
sage: S(1/y*x + 1)
(x + y)/y
But it won't accept it as a string:
sage: S(str(test))
Traceback (most recent call last):
...
TypeError: no canonical coercion from Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field to Rational Field
sage: S('1/y*x + 1')
Traceback (most recent call last):
...
TypeError: no canonical coercion from Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field to Rational Field
All of this works fine for polynomials (just remove the denominator of y from the example above). I think these are bugs and I will report them as such, if you agree. But in the meantime, does anyone have a workaround I can use?Kate StangeSun, 22 May 2011 09:11:39 -0500http://ask.sagemath.org/question/8114/