Skip to content

Commit 783fd7f

Browse files
authored
add calculations for false properties to AT5 (#947)
* add calculations for false properties to AT5 * remove tedious cube scenario * remove unused falsehard variable * use assertion rather than printing warning * show example calculations for non-properties * remove unused sample values
1 parent 440738a commit 783fd7f

2 files changed

Lines changed: 59 additions & 48 deletions

File tree

source/linear-algebra/exercises/outcomes/AT/AT5/generator.sage

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,61 @@ class Generator(BaseGenerator):
88
v2 = vector([x2,y2])
99
v3 = vector([x3,y3])
1010
v = vector([x,y])
11+
cs, ds = 2,3
12+
v1s = vector([1,2])
13+
v2s = vector([2,3])
14+
v3s = vector([3,4])
15+
vs = vector([1,2])
1116
vectorsimplify = lambda v : vector([simplify(expand(x)) for x in v])
1217

1318
true_property_options = ["add_assoc","add_comm","mul_assoc","dist_v","dist_s","mul_id"]
1419
false_only_property_options = ["add_id","add_inv"]
1520

16-
def verify(plus,times,hardfalseproperties=[]):
21+
def verify(plus,times):
1722
trueproperties={}
18-
falseproperties=hardfalseproperties
23+
falseproperties={}
1924
for prop in true_property_options:
2025
if prop == "add_assoc":
2126
LHS = plus(v1,plus(v2,v3))
2227
RHS = plus(plus(v1,v2),v3)
28+
LHS_sample = plus(v1s,plus(v2s,v3s))
29+
RHS_sample = plus(plus(v1s,v2s),v3s)
2330
elif prop == "add_comm":
2431
LHS = plus(v1,v2)
2532
RHS = plus(v2,v1)
33+
LHS_sample = plus(v1s,v2s)
34+
RHS_sample = plus(v2s,v1s)
2635
elif prop == "mul_assoc":
2736
LHS = times(c*d,v)
2837
RHS = times(c,times(d,v))
38+
LHS_sample = times(cs*ds,vs)
39+
RHS_sample = times(cs,times(ds,vs))
2940
elif prop == "mul_id":
3041
LHS = times(1,v)
3142
RHS = v
43+
LHS_sample = times(1,vs)
44+
RHS_sample = vs
3245
elif prop == "dist_v":
3346
LHS = times(c,plus(v1,v2))
3447
RHS = plus(times(c,v1),times(c,v2))
48+
LHS_sample = times(cs,plus(v1s,v2s))
49+
RHS_sample = plus(times(cs,v1s),times(cs,v2s))
3550
elif prop == "dist_s":
3651
LHS = times(c+d,v)
3752
RHS = plus(times(c,v),times(d,v))
53+
LHS_sample = times(cs+ds,vs)
54+
RHS_sample = plus(times(cs,vs),times(ds,vs))
3855
LHS = vectorsimplify(LHS)
3956
RHS = vectorsimplify(RHS)
4057
if LHS == RHS:
41-
trueproperties[prop]=vectorsimplify(LHS)
58+
trueproperties[prop]=LHS
4259
else:
43-
falseproperties.append(prop)
60+
falseproperties[prop]={
61+
"LHS": LHS,
62+
"RHS": RHS,
63+
"LHS_sample": LHS_sample,
64+
"RHS_sample": RHS_sample
65+
}
4466
for prop in false_only_property_options:
4567
if "dist_s" in trueproperties and "mul_id" in trueproperties:
4668
if prop == "add_id":
@@ -54,9 +76,6 @@ class Generator(BaseGenerator):
5476
if vectorsimplify(LHS) != vectorsimplify(RHS):
5577
falseproperties.append("add_inv")
5678
return (trueproperties, falseproperties)
57-
58-
#Use this to code in false properties that cannot be checked automatically ("add_id" and "add_inv")
59-
hardfalseproperties=[]
6079

6180
#Use this to list a property that is true, but you don't want students to check
6281
#because it is too easy (usually "add_comm") or too hard
@@ -73,8 +92,6 @@ class Generator(BaseGenerator):
7392
theta = lambda v : vector([v[0]+a,v[1]+b])
7493
untheta = lambda v : vector([v[0]-a,v[1]-b])
7594

76-
hardfalseproperties += ["add_id","add_inv"]
77-
7895
elif n==1:
7996
plus = lambda v1,v2 : vector([v1[0]+v2[0], v1[1]+v2[1]])
8097
r1 = randrange(1,9)
@@ -87,9 +104,7 @@ class Generator(BaseGenerator):
87104

88105
elif n==2:
89106
plus = lambda v1,v2 : vector([v1[0]+v2[0], v1[1]+v2[1]])
90-
r2 = randrange(2,4)
91-
#times= lambda c,v : vector([c*v[0],c^(r2)*v[1]])
92-
times= lambda c,v : vector([c^(r2)*v[0],c*v[1]])
107+
times= lambda c,v : vector([c^2*v[0],c*v[1]])
93108
a=randrange(1,8)
94109
b=randrange(2,8)
95110
theta = lambda v: vector([v[0]+b*v[1],v[1]+a])
@@ -131,12 +146,12 @@ class Generator(BaseGenerator):
131146
oplus = lambda v1,v2 : theta(plus(untheta(v1),untheta(v2)))
132147
otimes = lambda c,v : theta(times(c,untheta(v)))
133148

134-
trueproperties, falseproperties = verify(oplus,otimes,hardfalseproperties)
149+
trueproperties, falseproperties = verify(oplus,otimes)
150+
135151
for prop in true_no_check_properties:
136-
if prop in trueproperties.keys():
137-
trueproperties.pop(prop)
138-
else:
139-
print("WARNING: Property "+prop + " was false.")
152+
assert prop in trueproperties.keys()
153+
trueproperties.pop(prop)
154+
140155
trueproperty, verification = choice(list(trueproperties.items()))
141156

142157
return {
@@ -145,5 +160,5 @@ class Generator(BaseGenerator):
145160
"trueproperty": {
146161
trueproperty: verification
147162
},
148-
"falseproperties": {f: True for f in falseproperties},
163+
"falseproperties": falseproperties,
149164
}

source/linear-algebra/exercises/outcomes/AT/AT5/template.xml

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,6 @@ Show both sides simplify to <m>{{add_comm}}</m>.
4747
</outtro>
4848
</knowl>
4949
<!-- {{/add_comm}} -->
50-
<!-- {{#add_id}} -->
51-
<!-- <knowl>
52-
<content>
53-
<p>
54-
Show that there exists an additive identity element, that is:
55-
<me>
56-
\text{There exists }(w,z)\in V
57-
\text{ such that }(x,y)\oplus(w,z)=(x,y).
58-
</me>
59-
</p>
60-
</content>
61-
<outtro><p>TODO</p></outtro>
62-
</knowl> -->
63-
<!-- {{/add_id}} -->
64-
<!-- {{#add_inv}} -->
65-
<!-- <knowl>
66-
<content>
67-
<p>
68-
Show that additive inverses exist.
69-
</p>
70-
</content>
71-
<outtro><p>TODO</p></outtro>
72-
</knowl> -->
73-
<!-- {{/add_inv}} -->
7450
<!-- {{#mul_assoc}} -->
7551
<knowl>
7652
<content>
@@ -160,14 +136,20 @@ any one of the following properties does not hold:
160136
<!-- {{#add_assoc}} -->
161137
<item>
162138
<p>
163-
Vector addition is not associative.
139+
Vector addition is not associative: <me>(x_1,y_1)\oplus((x_2,y_2)\oplus(x_3,y_3))={{LHS}}</me>
140+
<me>((x_1,y_1)\oplus(x_2,y_2))\oplus(x_3,y_3)={{RHS}}</me>
141+
For example: <me>(1,2)\oplus((2,3)\oplus(3,4))={{LHS_sample}}</me>
142+
<me>((1,2)\oplus(2,3))\oplus(3,4)={{RHS_sample}}</me>
164143
</p>
165144
</item>
166145
<!-- {{/add_assoc}} -->
167146
<!-- {{#add_comm}} -->
168147
<item>
169148
<p>
170-
Vector addition is not commutative.
149+
Vector addition is not commutative: <me>(x_1,y_1)\oplus(x_2,y_2)={{LHS}}</me>
150+
<me>(x_2,y_2)\oplus(x_1,y_1)={{RHS}}</me>
151+
For example: <me>(1,2)\oplus(2,3)={{LHS_sample}}</me>
152+
<me>(2,3)\oplus(1,2)={{RHS_sample}}</me>
171153
</p>
172154
</item>
173155
<!-- {{/add_comm}} -->
@@ -188,28 +170,42 @@ Additive inverses do not always exist.
188170
<!-- {{#mul_assoc}} -->
189171
<item>
190172
<p>
191-
Scalar multiplication is not associative.
173+
Scalar multiplication is not associative: <me>c\odot(d\odot(x,y))={{LHS}}</me>
174+
<me>(cd)\odot(x,y)={{RHS}}</me>
175+
For example: <me>2\odot(3\odot(1,2))={{LHS_sample}}</me>
176+
<me>(2\cdot 3)\odot(1,2)={{RHS_sample}}</me>
192177
</p>
193178
</item>
194179
<!-- {{/mul_assoc}} -->
195180
<!-- {{#mul_id}} -->
196181
<item>
197182
<p>
198-
<m>1</m> is not a scalar multiplication identity.
183+
<m>1</m> is not a scalar multiplication identity: <me>1\odot(x,y)={{LHS}} \neq (x,y)</me>
184+
For example: <me>1\odot(1,2)={{LHS_sample}} \neq (1,2)</me>
199185
</p>
200186
</item>
201187
<!-- {{/mul_id}} -->
202188
<!-- {{#dist_v}} -->
203189
<item>
204190
<p>
205-
Scalar multiplication does not distribute over vector addition.
191+
Scalar multiplication does not distribute over vector addition:
192+
<me>c\odot((x_1,y_1)\oplus(x_2,y_2))={{LHS}}</me>
193+
<me>(c\odot(x_1,y_1))\oplus(c\odot(x_2,y_2))={{RHS}}</me>
194+
For example:
195+
<me>2\odot((1,2)\oplus(2,3))={{LHS_sample}}</me>
196+
<me>(2\odot(1,2))\oplus(2\odot(2,3))={{RHS_sample}}</me>
206197
</p>
207198
</item>
208199
<!-- {{/dist_v}} -->
209200
<!-- {{#dist_s}} -->
210201
<item>
211202
<p>
212-
Scalar multiplication does not distribute over scalar addition.
203+
Scalar multiplication does not distribute over scalar addition:
204+
<me>(c+d)\odot(x,y)={{LHS}}</me>
205+
<me>(c\odot(x,y))\oplus(d\odot(x,y))={{RHS}}</me>
206+
For example:
207+
<me>(2+3)\odot(1,2)={{LHS_sample}}</me>
208+
<me>(2\odot(1,2))\oplus(3\odot(1,2))={{RHS_sample}}</me>
213209
</p>
214210
</item>
215211
<!-- {{/dist_s}} -->

0 commit comments

Comments
 (0)