@@ -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 }
0 commit comments