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.Fri, 08 Jan 2021 17:51:05 +0100A way to request user input in Sagemath cellhttps://ask.sagemath.org/question/55194/a-way-to-request-user-input-in-sagemath-cell/In this period of pandemic, with students using systems ranging from computer to phone,
I was planning to use HTML pages with Sage cells, but they don't support `input`.
Is there a way to request user input in Sage cells?CyrilleFri, 08 Jan 2021 17:51:05 +0100https://ask.sagemath.org/question/55194/A function being an inputhttps://ask.sagemath.org/question/45504/a-function-being-an-input/I have the following code and I am trying to get an output, and I keep getting an error y is not defined. Could you please help?
var('y')
f = sage_eval(str(input("What is the function:" )), locals = {'y' == y})
integral(f,y,0,16)EnlightenedFunkMon, 18 Feb 2019 23:36:48 +0100https://ask.sagemath.org/question/45504/Problem regarding user input in Sage manifoldshttps://ask.sagemath.org/question/38273/problem-regarding-user-input-in-sage-manifolds/I am unable to take input from user in case of sage manifold,i am working in differentiable manifold.Especially,I am having problem to take input from user in case of vector fields(differentiable manifold)
Any help is appreciatedShouvikSat, 15 Jul 2017 10:48:51 +0200https://ask.sagemath.org/question/38273/what is the equivalent of cin>> in sagehttps://ask.sagemath.org/question/34671/what-is-the-equivalent-of-cin-in-sage/I am familiar with C++. In C++, the syntax to give input is cin>>. What is the equivalent of cin>> in sage ?
I am declaring an integer $n$ (in C++ syntax we write int n) and the user will give the value of $n$ when the program is being run.
How do I do that ?
It would be really helpful if you can give an example. (Say, the purpose of the program is to print an integer given by the user. What will be the syntax ?)nebuckandazzerWed, 31 Aug 2016 22:08:43 +0200https://ask.sagemath.org/question/34671/worksheet to console ?https://ask.sagemath.org/question/27055/worksheet-to-console/ Hi
I have written a code in sageworksheet format, it runs nice and smooth on sagecloud, but I have one problem : I want to make it more interactive so the user can enter the parameters by himself, so I'm willing to convert this into a sage script or a pyhton script, I have installed sage on my ubuntu machine, again the code runs on the notebook but not on the console it gives me some syntax error on " P<x> " All I want is to make it run as a Python script or Sage script so I can use input function to ask users to enter the parameters !
Here is the code :
P.<x> = PolynomialRing(ZZ);
def bezout(f,g):
P.<x> = PolynomialRing(QQ)
f = f+x-x
g = g+x-x
e=xgcd(f,g)
gcd=e[0]
u=e[1]
v=e[2]
return (u,v,gcd)
def polymod(f,q):
P.<x> = PolynomialRing(QQ)
f = f
c = f.coefficients(sparse=False)
N = len(c)
for i in range(N):
c[i] = Rational(c[i]).mod_ui(q);
p = sum(c[i]*(x^(i)) for i in range(N));
return p
def center(f,q):
u = q/2
v = -u
c = f.coefficients(sparse=False)
N = len(c)
for i in range(N):
if c[i]<v:
c[i] = c[i] + q;
elif c[i]>u:
c[i] = c[i] - q;
else:
c[i] = c[i];
p = sum(c[i]*(x^(i)) for i in range(N));
return p
class Ntru:
N = None
p = None
q = None
d = None
f = None
g = None
h = None
fp = None
fq = None
Phi = None
def __init__(self,N,p,q,d):
self.N = N
self.p = p
self.q = q
self.d = d
v = self.N
self.Phi = x^v -1
def test(self):
if not is_prime(self.N):
print "N n est pas premier, pensez a changer ce parametre"
return False
if gcd(self.N,self.p) != 1:
print "N et p ne sont pas premiers entre eux, pensez a changer ces parametres"
return False
if gcd(self.N,self.q) != 1:
print "N et q ne sont pas premiers entre eux, pensez a changer ces parameres"
return False
if self.q <= (6*self.d+1)*self.p :
print "q doit etre superieur a (6d+1)*p "
return False
return True
def genPublicKey(self,f_new,g_new):
self.f = f_new
self.g = g_new
(b_f,b_phi,bz) = bezout(self.f,self.Phi)
self.fp = polymod(b_f,self.p)
self.fq = polymod(b_f,self.q)
self.h = polymod((self.fq*self.g).quo_rem(self.Phi)[1],self.q)
if not self.test():
print "le cryptage ne peut s effectuer avec ces parametres !"
quit()
def encrypt(self,message,rand):
if self.h!=None:
temp=(self.p*rand*self.h + message).quo_rem(self.Phi)[1]
e=polymod(temp,self.q)
return e
else:
print "Impossible de faire le cryptage : la cle n a pas encore ete generee"
print "Veuillez en generer une avec la fonction genPublicKey"
def decrypt(self,encryptedMsg):
a = (self.f*encryptedMsg).quo_rem(self.Phi)[1]
a = polymod(a,self.q)
a = center(a,self.q)
tmp = (self.fp*a).quo_rem(self.Phi)[1]
m=polymod(tmp,self.p)
return m
NTRU=Ntru(167,3,128,3)
f = 1+x-x^2-x^3-x^4+x^5+x^6
g = -1+x^2+x^3+x^4-x^5-x^6
NTRU.f = f
NTRU.g = g
NTRU.genPublicKey(f,g)
print "La cle publique est : ",NTRU.h
msg = 1+x+x^4+x^5+x^6
rand = -1 -x + x^2 + x^3 - x^4 + x^6
enc = NTRU.encrypt(msg,rand)
print "Le Message crypte est : ",enc
dec = NTRU.decrypt(enc)
print "Le Message dechiffre est : ",dec
print "Le Message en clair etait : ",msg
Thank you !
hashiramaMon, 08 Jun 2015 21:44:29 +0200https://ask.sagemath.org/question/27055/How to input from file?https://ask.sagemath.org/question/26221/how-to-input-from-file/ I have a file with set of matrices in a file.
How to put them into array of matrices in sage?
Example of file:
[1,0,0]
[0,1,0]
[1,1,1]
[0,1,0]
[1,0,0]
[0,0,1]
FeckousTue, 17 Mar 2015 17:17:22 +0100https://ask.sagemath.org/question/26221/3d plotting keywordshttps://ask.sagemath.org/question/24288/3d-plotting-keywords/ I would love to know how to see all of the optional keywords in Sage Functions. For example, when searching for implicit_plot3d keywords, I tried using help(), tried going all over a Google Search, and tried going to the Sage documentation, but I could only find a partial list. Some of the examples used a keyword called "gradient", yet I could not find this in any keyword list for the function. Is there a way that I can take any Sage function, and see *all* of the optional keywords?themathman303Fri, 26 Sep 2014 05:37:37 +0200https://ask.sagemath.org/question/24288/"showing" both input and outputhttps://ask.sagemath.org/question/24039/showing-both-input-and-output/Is there a way to get Sage to show the "pretty" versions of both the input and the output of a calculation, instead of just the output? (sort of like the TI-89 and such)
For example, when I enter as input "integrate(x^2, x, 0, 3)" it correctly returns 9. But can I get it to return something like (the typeset version of) \int_0^3 x^2 dx = 9 ? It's obvious enough in this example what I'm asking for but some queries get complicated and seeing them as they would be printed helps make sure I'm asking Sage for what I mean to ask for.mathochistSat, 06 Sep 2014 22:41:45 +0200https://ask.sagemath.org/question/24039/Graph based on y value as the input, and x as the output?https://ask.sagemath.org/question/10307/graph-based-on-y-value-as-the-input-and-x-as-the-output/I need to identify the vertex of the following parabola:
3x-7 = y^2-5y
According to the book's author, since this contains a y^2 term rather than an x^2 term; I must obtain an end result with the standard form x = a(y - k)^2 + h
The answer, i.e. vertex, is (1/4, 5/2)
I did the following in sage 5.9, and as you can see the vertex point isn't located at the parabola, since the x in the 1st statement's equation, should be y. But sage says y is undefined:
p1 = plot( (1/3)*((x - 5/2)^2) + 1/4, (x,-15, 15), ymin =-5 , ymax = 25)
p3 = point((1/4, 5/2), size = 25)
p0 = p1 + p3
show(p0)
Is it possible for Sage to graph the equation based f(y), as opposed to the standard f(x), so i can see the vertex match up with the parabola.bxdinMon, 01 Jul 2013 13:39:49 +0200https://ask.sagemath.org/question/10307/Read sparse matrix in Harwell-Boeing Exchange Formathttps://ask.sagemath.org/question/9879/read-sparse-matrix-in-harwell-boeing-exchange-format/I'm currently creating some really large matrices, and hope they will end up reasonably sparse. I would like to toy with them in sage some day. Looking for a suitable standardized storage format, I just learned about the [Harwell-Boeing Exchange Format](http://math.nist.gov/MatrixMarket/formats.html#hb). **Is there some functionality provided by sage to read such files?**
If not, should I rather read the file and construct a matrix from it using a standard matrix constructor, or should I create my own matrix subclass whith an internal format that closely resembles the file format?MvGWed, 06 Mar 2013 17:06:33 +0100https://ask.sagemath.org/question/9879/can't use networkx.read_dot()https://ask.sagemath.org/question/8641/cant-use-networkxread_dot/
When trying the following
import networkx
networkx.read_dot("foo.dot")
I get
ImportError Traceback (most recent call last)
/home/bla/tmp/<ipython console> in <module>()
/local/usr/share/sage/local/lib/python/networkx/drawing/nx_agraph.pyc in read_dot(path)
197 except ImportError:
198 raise ImportError, \
--> 199 "read_dot() requires pygraphviz: http://networkx.lanl.gov/pygraphviz"
200 A=pygraphviz.AGraph(file=path)
201 return from_agraph(A)
ImportError: read_dot() requires pygraphviz: http://networkx.lanl.gov/pygraphviz
It seems that I'm missing something really simple here. After a fair time browsing the documentation, however, I couldn't find what :(
Thanks in advance.rcThu, 19 Jan 2012 18:36:09 +0100https://ask.sagemath.org/question/8641/