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, 25 Mar 2021 20:18:08 +0100Splitting a matrixhttps://ask.sagemath.org/question/56377/splitting-a-matrix/Dear SAGE community,
I am looking for a way that can help me split this matrix, A
A = matrix([[x], [x - 2*y]]), which is a linear combination of variables x, and y
into a Coefficient matrix, C = matrix([[1, 0], [1, -2]]) times the vector containing independent variables b = matrix([[x], [y]]).
Basically, A = C*b.
If there's a way to obtain the matrix C, would be really helpful.
-TIAApoorvThu, 25 Mar 2021 20:18:08 +0100https://ask.sagemath.org/question/56377/Combinations(range(100), 100).list() takes foreverhttps://ask.sagemath.org/question/53225/combinationsrange100-100list-takes-forever/ As title suggests,
`Combinations( range(100), 100 ).list()` takes forever.
On the other hand, `Combinations( range(100), 0 ).list()` is pretty fast.
Is there anything I can do to improve the performance?Symbol 1Mon, 31 Aug 2020 04:28:20 +0200https://ask.sagemath.org/question/53225/Iteration over a Combinations(alist, 5).list()https://ask.sagemath.org/question/53220/iteration-over-a-combinationsalist-5list/ Dear all,
I have a big set built as : Combinations([1,2,3,4,5,6,7], 5).list() through which I need to iterate. In real life, the list [1,2,3,4,5,6,7] has 72 components. I don't need this set of combinations, only to iterate through it.
I did not find the proper way to do that with the combinat package, but I have the feeling I overlooked something.
Many thanks if you have infos on this issue!
Best, O. Olivier R.Sun, 30 Aug 2020 15:52:38 +0200https://ask.sagemath.org/question/53220/Combination under constrained situation with a conditionhttps://ask.sagemath.org/question/52345/combination-under-constrained-situation-with-a-condition/Step 1: I want to take a number `n` as input from user
Step 2: We form the set `S` consisting of elements from `0` to `n*(2^{n-1})`
Step 3: Now I pick each possible two-element subsets of `S` and store it in `P`.
Step 4: Now I need to pick `n*(2^{n-1})` two-element subsets from `P`
such that each number that occurs in that set occurs exactly `n` times
neither less nor more and put them all in a list.
Example
n = 2
n*(2^{n-1}) = 2*(2^{2-1}) = 4
S = {0,1,2,3,4}
p = {(0,1),(0,2),(0,3),(0,4),(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)}
Step 4 One element which satisfies condition of step 4; HERE `n = 2`.
`{(0,1),(1,2),(2,3),(0,3)}` which has `2*(2^{n-1}) = 2*(2^{2-1}) = 4` elements.
Now see in the above set
- `0` occurred `n=2` times only in `(0,1)` and `(0,3)` only
- `1` occurred `n=2` times only in `(0,1)` and `(1,2)` only
- `2` occurred `n=2` times only in `(1,2)` and `(2,3)` only
- `3` occurred `n=2` times only in `(2,3)` and `(0,3)` only
Similarly we may get for `{(0,1),(1,4),(4,2),(2,0)}` we can easily verify like above.
Now based on `n` the number of elements size etc will vary.
Kindly help if possible any one.sriramSun, 05 Jul 2020 20:36:40 +0200https://ask.sagemath.org/question/52345/selector behavior difference , Combinations or Arrangements listhttps://ask.sagemath.org/question/51799/selector-behavior-difference-combinations-or-arrangements-list/HI
I opened this question first then I deleted it after a while
now I re-open it because finally I do not know if its a pb or not!.
sorry for my versatile behavior
Ubuntu 18.04 , SageMath 9.0 notebook
why if I uncoment line 3 of the code below, I get **TraitError: Invalid selection: value not found.**
but code is ok if line 3 commented
anIndexL=[1..5]
anCoupleIndexL=Arrangements(anIndexL,2).list()
#anCoupleIndexL=Combinations(anIndexL,2).list()
show(anCoupleIndexL)
@interact
def _( nbStepMax=slider(1,20,1,default=20),anCouple = selector(anCoupleIndexL,default=anCoupleIndexL[0])):
show(anCouple)
Arrangements return object parent is 𝙰𝚛𝚛𝚊𝚗𝚐𝚎𝚖𝚎𝚗𝚝𝚜 𝚘𝚏 𝚝𝚑𝚎 𝚜𝚎𝚝[𝟷,𝟸,𝟹,𝟺,𝟻] 𝚘𝚏 𝚕𝚎𝚗𝚐𝚝𝚑 𝟸
As Combinations return object is a simple list.
anIndexL=[1..5]
anCoupleIndexL0=Arrangements(anIndexL,2).list()
anCoupleIndexL1=Combinations(anIndexL,2).list()
anCoupleIndexStrL0=[]
print("test parent couple for anCoupleIndexL0")
for an in anCoupleIndexL0 :
anT=[]
for e in an :
show(e.parent())
show(an.parent())
anCoupleIndexStrL0.append(anT)
anCoupleIndexStrL1=[]
print("test parent couple for anCoupleIndexL1")
for an in anCoupleIndexL1 :
anT=[]
for e in an :
show(e.parent())
show(an.parent())
anCoupleIndexStrL1.append(anT)ortolljSun, 07 Jun 2020 08:39:52 +0200https://ask.sagemath.org/question/51799/dividing range by combinationshttps://ask.sagemath.org/question/50477/dividing-range-by-combinations/The following is an example:
temp = range(5)
L = [2,1,2]
Then we know that
> $_5\rm C_2 \times _3\rm C_1 \times _2\rm C_2 = 30$
We can get every combinations as following:
result = []
for A in Combinations(temp, L[0]):
temp = list(set(temp) - set(A))
for B in Combinations(temp, L[1]):
temp = list(set(temp) - set(B))
result += [[A,B, temp]]
temp = list(set(range(5))- set(A))
temp = range(5)
Then `result` is
[[[0, 1], [2], [3, 4]], [[0, 1], [3], [2, 4]], [[0, 1], [4], [2, 3]], [[0, 2], [1], [3, 4]], [[0, 2], [3], [1, 4]], [[0, 2], [4], [1, 3]], [[0, 3], [1], [2, 4]], [[0, 3], [2], [1, 4]], [[0, 3], [4], [1, 2]], [[0, 4], [1], [2, 3]], [[0, 4], [2], [1, 3]], [[0, 4], [3], [1, 2]], [[1, 2], [0], [3, 4]], [[1, 2], [3], [0, 4]], [[1, 2], [4], [0, 3]], [[1, 3], [0], [2, 4]], [[1, 3], [2], [0, 4]], [[1, 3], [4], [0, 2]], [[1, 4], [0], [2, 3]], [[1, 4], [2], [0, 3]], [[1, 4], [3], [0, 2]], [[2, 3], [0], [1, 4]], [[2, 3], [1], [0, 4]], [[2, 3], [4], [0, 1]], [[2, 4], [0], [1, 3]], [[2, 4], [1], [0, 3]], [[2, 4], [3], [0, 1]], [[3, 4], [0], [1, 2]], [[3, 4], [1], [0, 2]],[[3, 4], [2], [0, 1]]]
The problem is that
'How can I get the general case?'
> temp = range(k)
> L = [$e_1$, $e_2$, $\cdots$, $e_n$ ], where $\sum_{i=1} ^n e_i = k$
I don't know the size of list L.parkjrFri, 03 Apr 2020 02:32:00 +0200https://ask.sagemath.org/question/50477/Divide Combinations(n,k) into multiple parts (n > 1110)https://ask.sagemath.org/question/45606/divide-combinationsnk-into-multiple-parts-n-1110/I asked a similar question here: https://ask.sagemath.org/question/45347/sagemath-heap-size-limit/. I closed it, because the answer matched the question there. However, now I have an extra question related to it:
C = Combinations(2110, 3)
C_cardinality = binomial(2110, 3) # 1.563.429.820
N = C_cardinality / 95 # Number of parts = 95 (chunk size)
R = range(0, C_cardinality , N)
Because C_cardinality is too big, I would like to divide C into multiple parts, which are then used on multiple computers to process separately. In order to be sure that these multiple parts are totally different but covering the whole C, I use C's list:
c0 = C.list()[R[0]:R[0]+N]
c1 = C.list()[R[1]:R[1]+N]
c2 = C.list()[R[2]:R[2]+N]
...
However, my computer's RAM (memory 128GB) is not enough to store the `C`'s list. Therefore, I iterate `C` and store in a CSV instead:
def storeCSV(data, fo, wtype='a'):
with open(fo, wtype) as wFile:
write_file = csv.writer(wFile)
write_file.writerow([data])
index = 0
count = 0
for c in C:
storeCSV(c, "part_%s.csv" % index)
count += 1
if count == N:
count = 0
index += 1
print index
Unfortunately, this CSV write is too slow, i.e ~6000 write/min, which means I have to wait about 3800 hours for the whole `C` to finish.
You might wonder why I need to divide `C` into multiple parts. After having these parts, I will run the following code on different computers with a purpose to collect information among set of 3 numbers:
v = MatrixSpace(GF(2), 3,9)
g3 = (c for c in c0 if block_matrix(3, 1, [v[c[0]], v[c[1]], v[c[2]]]).rank() >= 6) # or c1, c2, ..., cN
rel = dict()
for g in list(map(tuple,g3)):
# (1, 2, 3)
rel.setdefault(g[::2], []).append(g[1]) # '[1, 3]': 2
rel.setdefault(g[:2], []).append(g[-1]) # '[1, 2]': 3
rel.setdefault(g[1:], []).append(g[0]) # '[2, 3]': 1
Specifically, I got all Combinations of 3 numbers within `c0, c1,...,cN`. Then, I filter what I need and store in `g3`. For all `g3` of format (A, B, C), I collect (A,B), (B,C), (A,C) as keys and C,A,B as values respectively. The most important reason I must collect this in a Python dictionary is that I need to retrieve any `rel[(X, Y)]` later on.
I wish the problem is described clearly and someone can support. Thank a lot !!!imnvshSun, 03 Mar 2019 01:25:24 +0100https://ask.sagemath.org/question/45606/Simple counting on restricted n-ary k-tupleshttps://ask.sagemath.org/question/11068/simple-counting-on-restricted-n-ary-k-tuples/I have some simple counting problems, for example, how many n-ary k-tuples, i.e. $(v_0,v_1,\ldots, v_k)$ with $0\le v_i < n$, are there which have $v_0=1$, and $m$ non-zero coordinates.
What sort of functionality is there is Sage or other computer algebra systems for answering such questions for general $n,k$ and $m$?alejandroericksonWed, 11 Jun 2014 07:57:19 +0200https://ask.sagemath.org/question/11068/Find linear combinations that meet certain criteriahttps://ask.sagemath.org/question/10881/find-linear-combinations-that-meet-certain-criteria/Hey,
I am quite new to SAGE, this is my first project. I'm not even sure if it is solvable or not, but here is what I want to do:
- w_1 is the smallest multiple of 5 that is >=
(volume / 30)
- w_n = w_1 + 5*n
- w_max is the largest multiple of 5 that is <=
((volume / 24) + 30)
- were n increases until w_n == w_max
I want to find all solutions to:
- (w_1)*(r_1) + (w_2)*(r_2) + ... +
(w_n)*(r_n) == volume
Given each/any r can be any integer from 5 to 10 and that the sum of all r's is less than or equal 30. Volume is just some constant integer multiple of 5 between 5425 and 7200. Its just an initial condition I want to be able to change. Is this possible or is it too many possibilities for SAGE to handle? I have some programing experience (C and .net ) and a little math experience(Calc 1,2 and 3 as well as differential equations) but I don't know were to start really. If there is any more information I can provide that would be useful I would be very happy to do so. I don't expect someone to make it for me, but I'm not quite sure what kind of approach I should be trying use, so I don't really know what to look up. Any help or advice is welcome.
Thanks.waryhermitFri, 03 Jan 2014 12:19:54 +0100https://ask.sagemath.org/question/10881/