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.Mon, 16 May 2022 14:30:00 +0200listing all those pairs of tuples which are permutations of each otherhttps://ask.sagemath.org/question/62464/listing-all-those-pairs-of-tuples-which-are-permutations-of-each-other/Suppose I have a list of tuples like
import itertools
l=range(0,6)
m=itertools.combinations(l,2)
list(m)
How do I get those pairs of tuples `(i,j);(x,y)` such that `(i,j)=(y,x)`? Also, is there a way to generalize this, that is, I would to have pairs of tuples `(a,b,c,...);(x,y,z...)` such that `(a,b,c...)=(z,y,x...)`. Is there any efficent way of doing this? Thanks beforehand.vidyarthiMon, 16 May 2022 14:30:00 +0200https://ask.sagemath.org/question/62464/How to create lists of n-tuples efficiently?https://ask.sagemath.org/question/56756/how-to-create-lists-of-n-tuples-efficiently/The ultimate problem I'm trying to solve, is that given two integers *p* and *q*, I would like to create a list (say "*List1*"), whose entries are (all of the) lists of length *2q* which:
1) For all *L* in *List1*, the first *q* entries are between 0 and *pq-1* (inclusive), and the next *q* entries are between *pq* and *2pq-1* (inclusive)
2) For all *L* in *List1*, the entries are strictly increasing, that is for all *1<=i<=2pq*, *L[i] < L[i+1]*
I have a way of doing this which is very "brute force", where I first construct the list of lists of length 1, then the list of lists of length 2, etc.
I'm imagining (hoping) there exists some way for me to just iterate over all *2q* -tuples (without repetition) of numbers from 1 to *2pq* Something along the lines of
List1 = []
for x in 2q-tuples of [0, 1, 2, ..., 2pq-1]:
if x satisfies 1) and 2):
List1.append(x)
I suppose I would want to convert x to a list before appending to List1, or many there's some way to iterate over lists instead of tuples. That's not so important, I just want an efficient way to construct these lists.sum8tionWed, 21 Apr 2021 19:12:26 +0200https://ask.sagemath.org/question/56756/How to create 31-tuples with nonnegative entries that sum to 1https://ask.sagemath.org/question/48623/how-to-create-31-tuples-with-nonnegative-entries-that-sum-to-1/Hello. I would like to know how to create all 31-tuples (sequence of 31 numbers) whose entries are real, nonnegative, and sum up to one. One such kind of tuple would be one where exactly one of the 31 entries is 1 and all of the other remaining 30 entries are 0.
How could I ask Sage to do this?
Thank you.merluzaTue, 05 Nov 2019 18:54:26 +0100https://ask.sagemath.org/question/48623/How to print a text file containing multiple tuples from a functionhttps://ask.sagemath.org/question/26710/how-to-print-a-text-file-containing-multiple-tuples-from-a-function/ I am trying to use Sagemath Cloud to create a text file with multiple columns of data. Each column is the input or output value of the variables of a system of functions being evaluated with for loops. I am very new to Python, and when I try to do this, I either get an error message or I get a text file with only one line, and that line is constantly overwritten by a new value of the function. On my own laptop with its standalone version of Sage, I can easily generate what I want simply by telling Sage to print the values of the variables of the function for each iteration of the for loops. The standalone version even creates an output text file that I can save. How do I do this with the cloud version?C. ThompsonMon, 04 May 2015 01:42:46 +0200https://ask.sagemath.org/question/26710/