ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 13 May 2021 05:24:35 +0200Can't print from init.sagehttps://ask.sagemath.org/question/57096/cant-print-from-initsage/I have some useful functions in init.sage. I wanted to list them and their parameters as an easy mnemonic, but although I can put functions in init.sage, a print statement doesn't work. Nothing prints when the kernel starts. Can I print from init.sage in some way?cybervigilanteThu, 13 May 2021 05:24:35 +0200https://ask.sagemath.org/question/57096/How to format the output of integrate() function when printing?https://ask.sagemath.org/question/57036/how-to-format-the-output-of-integrate-function-when-printing/ I want to compute the integral of a function like this:
fi = -0.000004*x^4*y^3+0.000015*x^4*y^2
print(integrate(fi,x))
It prints:
-(8e-07)*x^5*y^3 + (3e-06)*x^5*y^2
Is there a way to format the output so that:
- it uses normal decimal notation instead of exponential one (-0.0000008 instead of -(8e-07))
- it has a given precision (it will print 0.000001 instead of 0.000001111 for example)
I know how to do this with a single variable but not when displaying what the integrate() function returns.MichaelTheSlavSun, 09 May 2021 16:46:15 +0200https://ask.sagemath.org/question/57036/Print function in notebook not recognizing backspace characterhttps://ask.sagemath.org/question/52046/print-function-in-notebook-not-recognizing-backspace-character/ The following gives different output in SageMath 9.1 in notebook (Jupyter) versus SageMath 9.1 in a terminal session. The terminal agrees with my local installation of Python 3.7 and give the (expected) output.
print("test\b\b\brun")
The Jupyter notebook cell returns "tesrun". The others return "trun".
Maybe some weird bug?Robert BellTue, 16 Jun 2020 19:41:18 +0200https://ask.sagemath.org/question/52046/How to delete print()https://ask.sagemath.org/question/51205/how-to-delete-print/ I want to do print a loading String, while a heavy function is loading and to delete it afterwards:
print("Loading...")
callFunction()
delete print
I've already tried with python syntax, and nothing works apparently. Does anyone of you know a solution? Thank you in advance.
BryanSat, 02 May 2020 14:07:55 +0200https://ask.sagemath.org/question/51205/Add a text in Latex in front of a resulthttps://ask.sagemath.org/question/47978/add-a-text-in-latex-in-front-of-a-result/%display latex
var('A, x, y, l, alpha, beta, R, p_x, p_y');
U= A*x^(alpha)*y^(beta);
show(U)
this print U. But I would like to see "U(x) = ..." in a larger font that the standard one which is too small printed on a large device. More generaly , I would like to print some sentences before to disply a resultCyrilleThu, 19 Sep 2019 19:31:46 +0200https://ask.sagemath.org/question/47978/Printing from parallel processeshttps://ask.sagemath.org/question/48382/printing-from-parallel-processes/I am trying to use Sage's parallelization with `@parallel(p_iter='fork')` (I need `fork` specifically to work around the problems brought up [here](https://ask.sagemath.org/question/48270/sage-stalls-during-computation/).)
If I use `print` to show some messages, they only appear when the parallelized function has finished. Example:
@parallel(1, timeout=10)
def fun(x):
print('Starting %d' % x)
sleep(5)
print('Finished %d' % x)
return x*x
list(fun([2,3,4]))
The "Starting" and the "Finished" messages show up simultaneously, even though they are issued with a 5 second time difference.
How can I print a message so that it will show up immediately?
I need this when I am running a Sage script in a terminal. I am not using Sage interactively in this case and I am not using the notebook interface.SzabolcsThu, 17 Oct 2019 11:40:21 +0200https://ask.sagemath.org/question/48382/I can't show special charactershttps://ask.sagemath.org/question/48098/i-cant-show-special-characters/ Hi everyone! Thank you in advance for your time. I'm working in Ubuntu 18.04 and Sagemath 8.1. I want to show a string with special characters, like accents. I don't have problems with printing something like "á" in my Jupyter notebook, but when I use show, I get something like this
`PGh0bWw+PHNjcmlwdCB0eXBlPSJtYXRoL3RleDsgbW9kZT1kaXNwbGF5Ij5cbmV3Y29tbWFuZHtcQm9sZH1bMV17XG1hdGhiZnsjMX19XHZlcmJ8w6F8PC9zY3JpcHQ+PC9odG1sPg==`
How can I fix this? If somebody could help me, I'll appreciate that too much.
jdk2pySun, 29 Sep 2019 21:16:03 +0200https://ask.sagemath.org/question/48098/How to show more results in sagemathcell?https://ask.sagemath.org/question/46676/how-to-show-more-results-in-sagemathcell/If I put following comand in http://sagemath.askplanck.cn/
1+2
10+20
100+200
If Evaluate above command, I can only get last result: 300. What I wish is too get 3 results one by one in **my own sagemath server** , How can I do in configure file.
In https://cocalc.com/, if I put above comand, it shows 3 results. This is nice,and is what I want. Is it possible in such like sagmathcell?
PS. I don't want to put command as following (which can show 3 results):
print 1+2
print 10+20
print 100+200
Thank you very much for your suggestion.
JohnJohn BaoSun, 26 May 2019 14:47:46 +0200https://ask.sagemath.org/question/46676/"print" statement vs function for Sage-py3https://ask.sagemath.org/question/45994/print-statement-vs-function-for-sage-py3/With the upcoming migration of Sage from Python2 to Python3, I was wondering if Sage's default new behavior will be the current `print` statement (e.g., `print 'hello'`) or will it change to Python3's `print` command (e.g., `print('hello')`).
In case of a change from the current behavior, will there be a way to keep backwards compatibility for code written Python2-style?
Thanks for your answers!dsejasTue, 02 Apr 2019 22:56:46 +0200https://ask.sagemath.org/question/45994/printing far later than the actual print statementhttps://ask.sagemath.org/question/44622/printing-far-later-than-the-actual-print-statement/I have some code in a jupyter notebook which takes some time to run. When I run it, it does multiple calculations in which between there are print statements such that I can see certain results. Now the thing is that it sometimes chooses to wait with revealing the results of print statements. With this I mean:
My code first prints some results, then 20 seconds later it prints a lot more result. But I added the current time to all my print statements, which reveals that most of them could have been shown less than a second after the first results were printed. This makes sense since it finishes off with calculating a groebner basis, which takes longer than any of the other calculations, but I don't know why it wouldn't show any of the print statements which are done before the groebner basis calculations start.
Is there a way to make certain that it immediately prints instead of waiting until a later step of the program?ArtuurMon, 10 Dec 2018 15:50:23 +0100https://ask.sagemath.org/question/44622/Printing latexhttps://ask.sagemath.org/question/40849/printing-latex/I am using sage and would like to implement a function that prints a variable in latex, so I can copy and paste it directly into my latex file. However I am unsure how to do this. This is what I have attempted:
def printlatex(a):
return '$', latex(a), '$'
a = 1*2
printlatex(a)
This returns the tuple `('$', 2, '$')`, which I don't want.
How would I implement the function so it returns `$2$`pytonnoobMon, 29 Jan 2018 15:58:25 +0100https://ask.sagemath.org/question/40849/how to print the printout not too long on Sagecellhttps://ask.sagemath.org/question/39240/how-to-print-the-printout-not-too-long-on-sagecell/I try to printout this.
myList = []
for i in range (64):
myList.append(i)
print myList
Result:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
What i need is like below
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
Someone help me pls...NiyamabrataSat, 21 Oct 2017 17:01:06 +0200https://ask.sagemath.org/question/39240/Priniting Horizontally??https://ask.sagemath.org/question/36978/priniting-horizontally/Hello, guys! hope you are having a good day. First of all, I'm very new to sage and this forum, so would you please be generous to my question,, please?..
So, I was trying to do some recursive/iterative calculations as follows:
def calculator(L1,L2):
c=0
m=len(L1)
n=len(L2)
print '('
if m==0:
c=c+0
print '+'
print c
print ')'
elif m==1:
l1=L1[0]
l2=L2[0]
if l1<l2:
c=c+l1
print '+'
print c
print ')'
else:
c=c+0
print '+'
print c
print ')'
else:
for i in range(m):
l1=L1[i]
l2=L2[i]
if l1<l2:
c=c+l2
print '+'
print c
print ')'
else:
L3=[L1[j] for j in range(i)]+[L1[j] for j in range(i+1,m)]
L4=[L2[j] for j in range(i)]+[L2[j] for j in range(i+1,n)]
c=c+(-1)^m*calculator(L3,L4)
print '+'
print c
print ')'
return c
And, if we calculate, for example,
L1=[5,7,3]; L2=[7,5,2]; calculator(L1,L2)
then we get: (I've intentionally wrote vertically in the below, because that is exactly the sage gives us as a result)
(
+
7
)
(
+
7
)
(
+
5
)
+
12
)
+
-5
)
(
+
7
)
(
+
5
)
+
12
)
+
-17
)
-17
BUT!, if we actually, calculate by hand, then we get:
calculator([5,7,3],[7,5,2])
=7-calculator([5,3],[7,2])-calculator([5,7],[7,5]
=7-(7+calculator([5],[7]))-(7+calculator([5],[7])
=7-(7+(5))-(7+(5))=-17
And I actually want 7-(7+(5))-(7+(5))=-17 as a result... Can any body help me how to solve this kind of problem,, please...
And, moreover, if it is possible to get the result like
"calculator([5,7,3],[7,5,2])
=7-calculator([5,3],[7,2])-calculator([5,7],[7,5]
=7-(7+calculator([5],[7]))-(7+calculator([5],[7])
=7-(7+(5))-(7+(5))=-17"
then, it would be much greater...!
Oh one last thing to note is that even though we get the vertical result as above, if we write down horizontally that result, we get
(
+
7
)
(
+
7
)
(
+
5
)
+
12
)
+
-5
)
(
+
7
)
(
+
5
)
+
12
)
+
-17
)
-17
which shows us that there are some redundancy in the result and some parentheses are showing weirdly...
Can any body,, please help me how to solve this kind of problem... Thank you for help! and I hope you have a great day!!! I wish you the best luck for your future! Thank you!sssageeeeSat, 18 Mar 2017 19:14:33 +0100https://ask.sagemath.org/question/36978/How to not print equations and numbers on a single linehttps://ask.sagemath.org/question/36551/how-to-not-print-equations-and-numbers-on-a-single-line/My question is the inverse to [this one](https://ask.sagemath.org/question/36183/how-to-print-equations-and-numbers-on-a-single-line/). Since yesterday I have been unable to print to more than one line in the sage cloud. This is particularly annoying with matrices as the output is now squeezed into one line as in [this picture.](http://imgur.com/a/r2mV0) Line breaks '\n' are ignored entirely. There seems to be nothing that will force printing to a second line, other than word wrap.
I've tested this on several computers and browsers and it is the same each time. Is it a display setting that was somehow activated on my sage cloud account? user101214Fri, 10 Feb 2017 21:08:37 +0100https://ask.sagemath.org/question/36551/Why show() is not working when we are using with print?https://ask.sagemath.org/question/35806/why-show-is-not-working-when-we-are-using-with-print/Why show() is not working when we are using with print?
---
I have written a program to find a matrix as a result.
When I have finished and was tring to polish the output, I ended up the situation to use,
`print " The matrix is ", show(A)`
The output is just
> The matrix is
its not giving the matrix.
if I use show() without print function, its giving the matrix.
How to fix this issue??
Thanks for helping..
Workdone:
---
As [William Stein](https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/) has given in his answer, I have used,
sys.stdout.flush()
after print function. But it didnt help me.
I will give my subroutine, since if there is any bug in the code also give a bug in show() funciton.
A=matrix(Integers(12),[[1,0,3,1],[0,2,0,3],[0,0,6,1],[0,0,0,2]])
S24=[[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]]
C2=zero_matrix(Integers(12),6,6)
for i in range(6):
for j in range(6):
C2[i,j]=A.matrix_from_rows_and_columns(S24[i],S24[j]).det()
print "The compound matrix C2(A)=", '\n'
sys.stdout.flush()
show(C2)daviddglWed, 30 Nov 2016 03:34:53 +0100https://ask.sagemath.org/question/35806/Displaying mathematical notation as "strings"https://ask.sagemath.org/question/34784/displaying-mathematical-notation-as-strings/ Hello!
I can't seem to find if there is a command (or if sage is even capable) to display mathematical notation as a string to be printed, rather than evaluated.
For example, if I try;
foo = exp(x)
foo2 = str(foo)
Then using "foo2" displays e^x, rather than the actual superscript x. Although this isn't terribly surprising to me, I'm curious if there is a way to get the actual correct notation?
An even more important one would be limit notation. I can't figure out how to display the text "Lim" with "x -> 0" underneath the text "Lim" at all in sage.
If these features aren't possible that would be good to know, but it seems like a common and straight forward issue. Unfortunately googling gets drown in irrelevant hits and I don't know the appropriate term to search for. A pointer in the right direction would be much appreciated.Jason021Fri, 09 Sep 2016 16:24:17 +0200https://ask.sagemath.org/question/34784/how to print without new linehttps://ask.sagemath.org/question/32984/how-to-print-without-new-line/ I wanna use print, but I want it to skip the new line. In Python 3 you should be able to use print(".",end=""), but it gives back: "SyntaxError: invalid syntax".
What's the problem right there and is there a work arround or different funktion?
print("Def: R ",end = "")
if str(p) is not None:
print \ {',', '.join([str(p) for p in pol]),'}'raharthMon, 04 Apr 2016 14:38:11 +0200https://ask.sagemath.org/question/32984/Calling a C function with printf from sagehttps://ask.sagemath.org/question/32628/calling-a-c-function-with-printf-from-sage/ Hi,
I'm trying to run the first example in doc.sagemath.org/html/en/thematic_tutorials/cython_interface.html on SageMathCloud. After creating the necessary hello.c and hello_sage.pyx, I tried running the Cython function in a sage notebook:
%runfile hello_sage.pyx
my_bridge_function()
The problem is that I see the pyx was compiled successfully, but nothing is printed.
I would appreciate any help on how to run the example, or an alternative way to print from a C function that would be visible in the notebook.
(I have a more complex C file that I'm trying to run, but it is difficult to debug it without printing)
ThankskroovyMon, 22 Feb 2016 15:25:01 +0100https://ask.sagemath.org/question/32628/Print to latex according to line widthhttps://ask.sagemath.org/question/29630/print-to-latex-according-to-line-width/ Sometimes I need to print to latex really big polynomials. If I use `latex` command I will get something like this (black line means edge of page):
![image description](/upfiles/14434283547657527.png)
Reason is in fact that output of `latex` command exceeds maximum line width. Is it possible to create multi-line formulas by means of sage `latex` command or some other command?petRUShkaMon, 28 Sep 2015 10:21:29 +0200https://ask.sagemath.org/question/29630/Printing typeset output in the notebook?https://ask.sagemath.org/question/29495/printing-typeset-output-in-the-notebook/I'm sure this is a very trivial question, but I've not been able to find a simple answer.
If I use a `print` statement within a loop then the output so produced is not typeset, even though I have the typeset box ticked, and results of single commands are typeset. Is there an alternative to `print` which produces typeset output? I'm using Sage 6.2 in Ubuntu 14.04.
Thanks!AlasdairSat, 19 Sep 2015 11:34:49 +0200https://ask.sagemath.org/question/29495/How to set printing width for 'print' function?https://ask.sagemath.org/question/26166/how-to-set-printing-width-for-print-function/This code:
print 'X' * 140
Shows 2 actual lines with wrap simbol:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
I have screen wide enough to handle 140 character so I woul like to have the string intact and see it as one string. How to set printing width to a custom value?PetrThu, 12 Mar 2015 12:51:58 +0100https://ask.sagemath.org/question/26166/How to Run Entire Worksheet?https://ask.sagemath.org/question/23443/how-to-run-entire-worksheet/ Hello,
Now I have many cells of calculation in sagemath worksheet. I am looking for a way to run the entire worksheet at once, and generate result for printing. Any ideas? Thanks!Rongcui DongWed, 16 Jul 2014 22:40:09 +0200https://ask.sagemath.org/question/23443/Is there any method of printing of sagecloud worksheet? (Yes, I tryed ctrl+P)https://ask.sagemath.org/question/10719/is-there-any-method-of-printing-of-sagecloud-worksheet-yes-i-tryed-ctrlp/Hello!<br>
I created some work at sage cloud and decided to print my work in pdf file. I tried to use ctrl+p, but the result is very bad :'(<br>
Help me please. Thanks a lot! AndreWinSun, 10 Nov 2013 10:42:57 +0100https://ask.sagemath.org/question/10719/access to printed outputhttps://ask.sagemath.org/question/10788/access-to-printed-output/Maybe relating to this question: [Access output from previous cells](http://ask.sagemath.org/question/769/access-output-from-previous-cells)
Assume I defined a function that takes a string and prints it:
def f(s):
print s
return
Now the output of the cell
f('hello')
is just the word 'hello'.
Is there any way to access this output, for example read it as a variable?
The problem occurs when I have a MixedIntegerLinearProgram p and access it with
p.show(). I then want to do something with the printed output of this command, e.g. write it to a file.
mfFri, 29 Nov 2013 11:05:06 +0100https://ask.sagemath.org/question/10788/Printing matriceshttps://ask.sagemath.org/question/10613/printing-matrices/Trying to format the output of a matrix, B. Sage reports: type 'print obj.str()' to see all of the entries)
But print B.str() doesn't give me any format options. Is there a way control output like a regular print statement?
Thanks,
-ddaldrichTue, 15 Oct 2013 20:20:44 +0200https://ask.sagemath.org/question/10613/How well print a list of matrices ?https://ask.sagemath.org/question/10529/how-well-print-a-list-of-matrices/In a program, I use the function "print" for printing lists of matrices.
Unfortunately, the displaying is not as well as it could, see the following example :
sage: MM=[identity_matrix(QQ,3) for i in range(3)]
sage: MM
[
[1 0 0] [1 0 0] [1 0 0]
[0 1 0] [0 1 0] [0 1 0]
[0 0 1], [0 0 1], [0 0 1]
]
sage: print(MM)
[[1 0 0]
[0 1 0]
[0 0 1], [1 0 0]
[0 1 0]
[0 0 1], [1 0 0]
[0 1 0]
[0 0 1]]
> Is there a way to print a list of
> matrices as the first above ?
(Perhaps by saving it on an external file, what would be the line code for that ?)
Sébastien PalcouxTue, 10 Sep 2013 08:18:10 +0200https://ask.sagemath.org/question/10529/sage -c "print diff(x^4,x)"https://ask.sagemath.org/question/9416/sage-c-print-diffx4x/I'm using 5.3 on Ubuntu 64 bit.
I would like to have the following print **4x^3** to standard out.
$ ./sage -c "print diff(x^4,x)"
Traceback (most recent call last):
File "/home/xuwang/sage/local/bin/sage-eval", line 15, in <module>
eval(compile(s,'<cmdline>','exec'))
File "<cmdline>", line 1, in <module>
NameError: name 'x' is not defined
$xuwangSat, 13 Oct 2012 10:19:19 +0200https://ask.sagemath.org/question/9416/Printing in different colors in notebookhttps://ask.sagemath.org/question/9619/printing-in-different-colors-in-notebook/That's it. Instead of
print "Hello world"
and getting the output in the standard blue (in the notebook), I want to have a different color sometime. Is this possible? Much love.G-SageFri, 07 Dec 2012 15:46:09 +0100https://ask.sagemath.org/question/9619/css print stylesheethttps://ask.sagemath.org/question/8796/css-print-stylesheet/What stylesheet is used when printing? It doesn't seem to be notebook.css.
Background:
Originally I wanted the text size to scale depending on whether I was inside or outside a notebook cell (make the text big when I'm editing, small when I'm not) but I can't seem to make that work.
Now I'm taking a new tack-- make input cell text small relative to text cell text when printing. The problem is that the notebook seems to use a different stylesheet when printing, so @media selectors aren't working.
Thanks--G BFri, 16 Mar 2012 18:44:12 +0100https://ask.sagemath.org/question/8796/collect multiple variables and simplify their coefficientshttps://ask.sagemath.org/question/8369/collect-multiple-variables-and-simplify-their-coefficients/Hi there!
In Mathematica you can do the following: Collect[expr, {var1, var2, var3}, Simplify]
This transforms
expr = var1*expr11 + var2*expr22 + var1*var2*expr12 + ...
to
var1*Simplify[expr11] + var2*Simplify[expr22] + var1*var2*Simplify[expr12] + ...
I was wondering if there is an easy way to do this in Sage.
So my questions are:
1) How can you collect multiple variables?
2) How can you manipulate their coefficients? (each coefficient is independent)
3*) How can you print the result in a pretty way? (e.g. collecting the expression by coefficients and printing each term in a new line)
Thanks for your help!
nablaoperatorSun, 09 Oct 2011 16:50:44 +0200https://ask.sagemath.org/question/8369/