Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 1794
Image: ubuntu2004
1
load("__common__.sage")
2
3
def generator():
4
var('x1 x2 x3 y1 y2 y3 c d x y')
5
oplus=r"(x_1,y_1)\oplus (x_2,y_2)&="
6
otimes=r"c \odot (x,y) &="
7
trueproperties=["vector addition is associative",
8
"vector addition is commutative",
9
"there exists an additive identity element",
10
"additive inverses exist",
11
"scalar multiplication is associative",
12
"1 is a scalar multiplication identity",
13
"scalar multiplication distributes over vector addition",
14
"scalar multiplication distributes over scalar addition"
15
]
16
truepropertiessymb=[r"\left((x_1,y_1)\oplus(x_2,y_2)\right)\oplus(x_3,y_3)=(x_1,y_1)\oplus\left((x_2,y_2)\oplus(x_3,y_3)\right)",
17
r"(x_1,y_1)\oplus(x_2,y_2)=(x_2,y_2)\oplus(x_1,y_1)",
18
r"\text{There exists }(w,z)\in V\text{ such that }(x,y)\oplus(w,z)=(x,y)",
19
"additive inverses exist",
20
r"a\odot(b\odot (x,y))=(ab)\odot(x,y)",
21
r"1\odot(x,y)=(x,y)",
22
r"c\odot \left((x_1,y_1)\oplus(x_2,y_2)\right)=c\odot(x_1,y_1)\oplus c\odot(x_2,y_2)",
23
r"(c+d)\odot(x,y)=c\odot(x,y)\oplus d\odot (x,y)"
24
]
25
falseproperties=["vector addition is not associative",#0
26
"vector addition is not commutative",#1
27
"there is no additive identity element",#2
28
"additive inverses do not always exist",#3
29
"scalar multiplication is not associative",#4
30
"1 is not a scalar multiplication identity",#5
31
"scalar multiplication does not distribute over vector addition",#6
32
"scalar multiplication does not distribute over scalar addition"#7
33
]
34
n = randrange(0,10)
35
if n==1:
36
def oplusop(v1,v2):
37
return vector([randrange(2,5)*v1[0]+v2[0], v1[1]+randrange(1,4)*v2[1]])
38
39
def otimesop(c,v):
40
return vector([c*v[0],c*v[1]])
41
42
trueproperty= trueproperties[6]
43
truetex=truepropertiessymb[6]
44
falseproperty=[ falseproperties[0],falseproperties[1],falseproperties[7]]
45
46
elif n==2:
47
def oplusop(v1,v2):
48
return vector([randrange(1,5)*v1[0]*v2[0], v1[1]+randrange(2,5)*v2[1]])
49
50
def otimesop(c,v):
51
return vector([c*v[0],0])
52
53
trueproperty= trueproperties[2]
54
truetex=truepropertiessymb[2]
55
falseproperty=[ falseproperties[0], falseproperties[1], falseproperties[3], falseproperties[5], falseproperties[6], falseproperties[7]]
56
elif n==3:
57
def oplusop(v1,v2):
58
return vector([v1[0]+v2[0]+randrange(1,5), v1[1]+v2[1]])
59
60
def otimesop(c,v):
61
return vector([c*v[0],v[1]^c])
62
63
trueproperty= trueproperties[0]
64
truetex=truepropertiessymb[0]
65
falseproperty=[falseproperties[6], falseproperties[7]]
66
elif n==4:
67
def oplusop(v1,v2):
68
return vector([v1[0]+v2[0], v1[1]+v2[1]])
69
70
def otimesop(c,v):
71
return vector([randrange(2,6)*c*v[0],randrange(2,6)*c*v[1]])
72
73
trueproperty= trueproperties[7]
74
truetex=truepropertiessymb[7]
75
falseproperty=[falseproperties[4], falseproperties[5],falseproperties[6]]
76
elif n==5:
77
def oplusop(v1,v2):
78
return vector([v1[0]+v2[0], v1[1]+v2[1]])
79
80
def otimesop(c,v):
81
return vector([c^(randrange(2,4))*v[0],c^(randrange(2,5))*v[1]])
82
83
trueproperty= trueproperties[6]
84
truetex=truepropertiessymb[6]
85
falseproperty=[falseproperties[7]]
86
elif n==6:
87
def oplusop(v1,v2):
88
return vector([v1[0]+v2[0], v1[1]+v2[1]-randrange(2,7)])
89
90
def otimesop(c,v):
91
return vector([c*v[0],c*v[1]])
92
93
trueproperty= trueproperties[0]
94
truetex=truepropertiessymb[0]
95
falseproperty=[falseproperties[6], falseproperties[7]]
96
elif n==7:
97
def oplusop(v1,v2):
98
return vector([v1[0]+v2[0], v1[1]+v2[1]])
99
100
def otimesop(c,v):
101
r=randrange(3,8)
102
return vector([c*v[0],c*v[1]-r*c+r])
103
104
trueproperty= trueproperties[4]
105
truetex=truepropertiessymb[4]
106
falseproperty=[falseproperties[6],falseproperties[7]]
107
elif n==8:
108
def oplusop(v1,v2):
109
return vector([v1[0]+v2[0]+randrange(2,7), sqrt(v1[1]^2+v2[1]^2)])
110
111
def otimesop(c,v):
112
return vector([c*v[0],c*v[1]])
113
114
trueproperty= trueproperties[0]
115
truetex=truepropertiessymb[0]
116
falseproperty=[falseproperties[2], falseproperties[6],falseproperties[7]]
117
elif n==9:
118
def oplusop(v1,v2):
119
return vector([randrange(2,7)*(v1[0]+v2[0]), randrange(2,7)*(v1[1]+v2[1])])
120
121
def otimesop(c,v):
122
return vector([c*v[0],c*v[1]])
123
124
trueproperty= trueproperties[6]
125
truetex=truepropertiessymb[6]
126
falseproperty=[falseproperties[0], falseproperties[7]]
127
else: #n==0
128
def oplusop(v1,v2):
129
return vector([v1[0]*v2[0], v1[1]*v2[1]])
130
131
def otimesop(c,v):
132
return vector([v[0]^c,v[1]^c])
133
134
trueproperty= trueproperties[2]
135
truetex=truepropertiessymb[2]
136
falseproperty=[falseproperties[3]]
137
138
139
return {
140
"oplus": [oplus,oplusop(vector([x1,y1]),vector([x2,y2]))],
141
"otimes": [otimes,otimesop(c,vector([x,y]))],
142
"trueproperty": trueproperty,
143
"truetex": truetex,
144
"falseproperties": falseproperty,
145
}
146