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, 07 Oct 2021 12:34:38 +0200other way of creating a list of perfect squareshttps://ask.sagemath.org/question/59269/other-way-of-creating-a-list-of-perfect-squares/ Hi there! I am currently explaining a certain exercise to my buddy and part of it consists in creating a list of perfect squares up to root of 64 (included) therefore the list has to look like this [0, 1, 4, 9, 16, 25, 36, 49, 64]
My first idea was this
squares=[i*i for i in range(sqrt(64)+1)]
which works but I am now trying to do it in a way so that is not compressed such us
for i in range(sqrt(64)+1)
squares=[i*i]
print(squares)
But I keep getting this error
for i in range(sqrt(Integer(64))+Integer(1))
^
SyntaxError: invalid syntax
Any ideas of what I am doing wrong?
jhonvi2Thu, 07 Oct 2021 12:34:38 +0200https://ask.sagemath.org/question/59269/While loopshttps://ask.sagemath.org/question/58989/while-loops/The goal to find the smallest value of a that satisfies the condition below. I realise I could use "if" instead of "while", but len(Lpathcellsdim4[s]) is big, and I want the computer to stop after it finds the first value of a satisfying the condition. I would be grateful for suggestions. Are there sage worksheets or tutorials to learn this type of thing? I have other, more complicated examples, where I want the computer to stop after it has found the first of many solutions.
The following gives an error "TypeError: argument of type 'sage.rings.integer.Integer' is not iterable"
b=0
for a in range(len(Lpathcellsdim4[s])):
while Lvectorspolyfacesdim5[Lpathcellsdim4[s][a][0]][Lpathcellsdim4[s][a][1]][Lpathcellsdim4[s][a][2]] not in Lsimppdim5[n][5][5]:
b=b+1IngridMon, 13 Sep 2021 10:14:57 +0200https://ask.sagemath.org/question/58989/too many for loopshttps://ask.sagemath.org/question/53647/too-many-for-loops/ I am trying to solve a Diophantine system with more than 20 variables. I have been trying to use:
\\
for a in srange(1,100):
for b in srange(1,a+1):
.
.
.
if (a+b+...)^(1\2) in ZZ and if (a+b+...)^(1/3) in ZZ:
print(a,b,...)
The problem is I have more than 20 variables and hence more than 20 of these for loops and Python doesnt allow that. Any help on an easy workaround would be greatly appreciated! This is not for homework or anything, I am just trying to do some computational research on Diophantine systems and I am running into some trouble. brennanTue, 29 Sep 2020 10:24:15 +0200https://ask.sagemath.org/question/53647/Area under function with rectangleshttps://ask.sagemath.org/question/49856/area-under-function-with-rectangles/I'm assigned to write a simple function which gives me the area under x^4 between an interval, but using a series of rectangles instead of a straight integral. I have to write a function that defines the minimum height of these rectangles and another function defining the maximum height, and then find the average value. I am a **total** newbie, so as trivial as it sounds, I've no clue how to define those functions.
I dont know how to make one define minimum heights and the other define maximum, and I don't think what I came up with as a sum of rectangles is correct.
def Smin(n):
sum=0
a=0
b=6
width=(b-a)/n
for i in range (1,n+1):
sum=width*(sum+i**4)
return sum
Any help will be greatly apreciated.alesilybar001Sat, 08 Feb 2020 22:45:41 +0100https://ask.sagemath.org/question/49856/How to get all digraphs with loopshttps://ask.sagemath.org/question/35736/how-to-get-all-digraphs-with-loops/ I'm trying to count all of the directed graphs on n vertices which have fixed in/out degree, up to isomorphism. I would like to allow loops, though not multiple edges. I can't figure out how to tell the digraphs iterrator to include the ones with loops, though i see this is an option in the graphs iterator. I would appreciate suggestions to get around this/explanations why it is not an option.BillyFri, 25 Nov 2016 10:30:55 +0100https://ask.sagemath.org/question/35736/Error while trying to use srange and for loopshttps://ask.sagemath.org/question/26992/error-while-trying-to-use-srange-and-for-loops/ I am trying to execute some instructions containing for loops and variables in sranges. The instructions are simple; yet I keep getting an error message and can't figure out where the error is. My program is at https://cloud.sagemath.com/projects/f9c3371c-3682-4811-b236-f62976d8fa24/files/scratch.sagews. I am trying to use this simple program to see if I have correctly executed a much larger program.C. ThompsonMon, 01 Jun 2015 01:25:40 +0200https://ask.sagemath.org/question/26992/how do I set label of multiedges graphhttps://ask.sagemath.org/question/25659/how-do-i-set-label-of-multiedges-graph/ Hello,
Let me consider a graph that I often need to use: the graph with one vertex and three loops.
sage: G = DiGraph([(0,0,'a'), (0,0,'b'), (0,0,'c')])
Is there a way to change the labels after the creation? Because
sage: G.set_edge_label(0,0,'d')
Traceback (most recent call last):
...
RuntimeError: Cannot set edge label, since there are multiple edges from 0 to 0.
VincentvdelecroixSat, 31 Jan 2015 21:01:13 +0100https://ask.sagemath.org/question/25659/How to get an arbitrary orientation of a graph.https://ask.sagemath.org/question/9835/how-to-get-an-arbitrary-orientation-of-a-graph/**I'VE COMPLETELY REVISED MY QUESTION**
I wish to take a simple undirected graph (i.e. the complete graph K_4)
Arbitrarily direct said graph, and then create a line graph from the directed version of the graph.
However, in Sage it appears to create a line graph that shows a connection between two edges (that are just inverses of each other), so what I really want is a line graph that doesn't give an edge connected to its own inverse.
**That's why I asked if we could remove cycles of length 2, but that doesn't seem to solve the problem.**
Here's what I am trying to work out:
G = graphs.RandomGNP(4,1)
GD = G.to_directed() #orients G
m = GD.size() #number of edges of digraph GD
LG = GD.line_graph() #the line graph of the digraph
IM = identity_matrix(QQ,GD.size())
T = LG.adjacency_matrix()#returns the adjacency matrix of the line graph
var('u') #defines u as a variable
X=IM-u*T #defines a new matrix X
Z=X.det() #defines polynomial in u aka inverse of the Ihara zeta function
Z #computes determinant of X
Z.coefficients(u) #extracts coefficients
considering my graph is a complete graph on 4 vertices - the coefficients should be as such:
[coeff,degree of u]
[1,0], [0,1], [0,2],[-8,3],[-2,4]
**NOTE:**
im only interested in coefficients up to the order of n=#of nodes in the graph, so here for K_4 obviously n=4.
where the coefficient of u^3 corresponds to the negative of twice the number of triangles in K_4
where the coefficient u^4 corresponds to the negative of twice the number of squares in K_4
**Here is an image of a K_4 graph minus an edge and the line graph construction of K_4 that i want**
![Here is an image of a K_4 graph minus an edge and the line graph construction of K_4 that i am after](http://dl.dropbox.com/u/2399196/graph.png)jtaaFri, 22 Feb 2013 20:59:05 +0100https://ask.sagemath.org/question/9835/memory increasing when generating lots of hyperelliptic curves (without storing them)https://ask.sagemath.org/question/8437/memory-increasing-when-generating-lots-of-hyperelliptic-curves-without-storing-them/Executing the code given below (it generates hyperelliptic curves), the used memory increases all the time. Since nothing is stored permanently, this should not happen. How do I avoid it? (It is not really a problem with the example given, but using more loops, it becomes a problem.)
Here an example code:
F = GF(4, 'a')
R.<t> = PolynomialRing(F)
for x in F:
for y in F:
for z in F:
h = x*t^2 + y*t + z
for a in F:
for b in F:
for c in F:
for d in F:
for e in F:
f = t^5 + a*t^4 + b*t^3 + c*t^2 + d*t + e
C = HyperellipticCurve(f,h)
Daniel KrennFri, 04 Nov 2011 10:59:41 +0100https://ask.sagemath.org/question/8437/