Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 1794
Image: ubuntu2004
1
load("__common__.sage")
2
3
def generator():
4
# shuffle 2,3,4,5 to get dimensions
5
dims = [2,3,4]
6
shuffle(dims)
7
8
# create matrices. only first two are multiply-able
9
m = list(zip([
10
random_matrix(QQ,dims[0],dims[1],algorithm='echelonizable',rank=min(dims[0],dims[1]),upper_bound=7),
11
random_matrix(QQ,dims[1],dims[2],algorithm='echelonizable',rank=min(dims[1],dims[2]),upper_bound=7),
12
random_matrix(QQ,dims[0],dims[2],algorithm='echelonizable',rank=min(dims[0],dims[2]),upper_bound=7),
13
],["L","R","N"]))
14
shuffle(m)
15
16
matrices, indices = zip(*m)
17
18
letters = ["A","B","C"]
19
20
productName = letters[indices.index("L")] + letters[indices.index("R")]
21
product = matrices[indices.index("L")] * matrices[indices.index("R")]
22
23
24
return {
25
"A": matrices[0],
26
"B": matrices[1],
27
"C": matrices[2],
28
"productName": productName,
29
"product": product
30
}
31
32
33