-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathTrainer.py
More file actions
2030 lines (1536 loc) · 69.9 KB
/
Copy pathMathTrainer.py
File metadata and controls
2030 lines (1536 loc) · 69.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 08:44:33 2020
WxPython
https://stackoverflow.com/questions/18532827/using-wxpython-to-get-input-from-user
https://en.wikipedia.org/wiki/Learning_curve
@author: 危機
"""
"""
MATH:
Addition & Substraction:
Modulus Addition & Substraction
Residual Addition & Substraction
Fractions
Multiplication & Division:
Powers:
Raise Fractions to Powers
Powers to Powers
Fractions Sumplification of Powers
Algebra:
Addition & Substraction of Polynomials:
Random number of summations
Fractional Coefficients
Fractional Degrees
Multiplication & Division of Polynomials:
Fractional Coefficients
1st Degree
Mix from 0th to nth degree
Fractional Degrees
Factorization
Fractional Coefficients
1st Degree
Mix from 0th to nth degree
Fractional Degrees
Functions
Find numerical value
Polynomials Raised to Powers:
Powers
Chapter XI Baldor Algebra
Maximum Common Divisor
M.C.D. of 2 to n Polynomials
Minimum Common Divisor
M.C.D. of 2 to n Polynomials
Equations
Physics
Inequalities
Procedure:
Start with an easy level and go increasing the difficulty untill a breakpoint
then start with the second last successful level
https://docs.sympy.org/latest/modules/parsing.html
https://stackoverflow.com/questions/48531276/how-to-create-symbol-polynomial-from-given-array-with-sympy
https://guao.org/sites/default/files/biblioteca/%C3%81lgebra%20de%20Baldor.pdf
https://docs.sympy.org/latest/modules/polys/reference.html
https://docs.sympy.org/latest/tutorial/simplification.html
https://docs.sympy.org/latest/modules/polys/index.html
"""
"""
Total problems:
10 Levels
Part A 10*5
Part B 10*5
Thresh:
90% Right
75% Above Time
"""
"""
Thresholds
After passing a level put a higher thresh
Thread the timer
Adapt the timer
Adapt levels
Level down when many failed
2 Levels up if perfect or near perfect
2 Levels down if very bad
Find specific tasks:
Specific Multiplications table
Specific Functions
"""
"""
Training session:
Select topics and the number of levels or number of tries for every topic
Learning Curves and Forgetting Curves
Intensity of the training:
"""
"""
Matrices:
Addition-Substraction
Multiplication
Gauss Jordan
Finding Rotation, Identity, Exchange matrices
Factorization
Fractional Coefficients
1st Degree
Mix from 0th to nth degree
Fractional Degrees
Calculus
Derivatives:
Based on the derivative formulas in cheatsheets solve problems. These are the blueprints
Integrals:
Based on the integral formulas in cheatsheets solve problems. These are the blueprints
Multivariate Cilindrical and Spherical Coordinates:
"""
# =============================================================================
# %% Settings
# =============================================================================
'''
Add Sign to the mat variable that is saved in the settings
Check if everything needed to reconstruct the problem is saved in the settings dict
https://docs.sympy.org/latest/modules/evalf.html
https://docs.sympy.org/latest/modules/evalf.html
https://docs.sympy.org/latest/tutorial/manipulation.html
https://tex.stackexchange.com/questions/503342/display-content-in-two-column-layout-in-pylatex
https://stackoverflow.com/questions/36560642/pylatex-basic-script-wont-run-because-script-interpreter-could-not-be-found
'''
# =============================================================================
# %% PATH
# =============================================================================
PATH = 'D:/LifeWare Technologies/Math Trainer/Hist/'
exercises_PATH = 'D:/LifeWare Technologies/Math Trainer/Exercises/'
# =============================================================================
# %% Libs
# =============================================================================
import sympy as spy, os, numpy as np, winsound
#from sympy import init_printing
from time import time, sleep
import datetime
from sympy import symbols, simplify, Function, Symbol, init_session, latex
from sympy.parsing.sympy_parser import parse_expr
from sympy.parsing.sympy_parser import standard_transformations, implicit_multiplication_application
from sympy.printing.mathml import print_mathml
#init_session()
#spy.init_printing()
from pylatex import Document, Section, Subsection, Command, Math
from pylatex.utils import italic, NoEscape
from pylatex.package import Package
from pylatex import PageStyle, Head, MiniPage, Foot, LargeText, MediumText, LineBreak, simple_page_number
from pylatex.utils import bold
# =============================================================================
# %% Sympy Settings
# =============================================================================
transformations = (standard_transformations + (implicit_multiplication_application,))
# =============================================================================
# %% Defs
# =============================================================================
def intNumLevel(level,n,n_probs): # Returns the set of problems for this level
rng = np.random.default_rng()
mat = rng.integers(10, size=(n+1,level,n_probs))
mask = np.array([10**i0 for i0 in range(level-1,-1,-1)]).reshape([1,level])
for i0 in range(n_probs):
mat[:,:,i0] = mat[:,:,i0]*mask
return mat
def intMultNumLevel(level,n,n_probs): # Returns the set of problems for this level
rng = np.random.default_rng()
mat_0 = rng.integers(10, size=(level,n_probs))
mat_1 = rng.integers(2, high = 9, size=(n+1,n_probs))
mask = np.array([10**i0 for i0 in range(level-1,-1,-1)]).reshape([1,level])
for i0 in range(n_probs):
mat_0[:,i0] = mat_0[:,i0]*mask
mask = np.array([10**i0 for i0 in range(n,-1,-1)]).reshape([1,n+1])
for i0 in range(n_probs):
mat_1[:,i0] = mat_1[:,i0]*mask
return [mat_0,mat_1]
def intNumPolynomial(level,n,n_probs,ranges): # Returns the set of problems for this level
rng = np.random.default_rng()
# mat = rng.integers(ranges, size=(n,level,n_probs))
mat = rng.integers(ranges, size=(n,level,n_probs))
# variables = [Symbol('x_'+str(i0)) for i0 in range(self.n)]
mat_ = []
for i0 in range(len(mat[:,0,0])):
# x = Symbol('x_'+str(i0))
mat_.append( mat[i0,:,:]*Symbol('x_'+str(i0)) )
mat = np.reshape(mat_,list(mat.shape))
return mat
def intMultNumPolynomial(level,n,n_probs,exponentials,ranges): # Returns the set of problems for this level
rng = np.random.default_rng()
mat_0 = rng.integers(10, size=(level,n_probs))
mat_0_p = rng.integers(0, high=exponentials+1, size=(level,n_probs))
mat_1 = rng.integers(2, high = 9, size=(n,n_probs))
mat_1_p = rng.integers(0, high=exponentials+1, size=(n+1,n_probs))
mat_0_ = []
for i0 in range(len(mat_0[:,0])):
temp = Symbol('x_'+str(i0))**mat_0_p[i0,:]
mat_0_.append( mat_0[i0,:]*temp )
mat_0 = np.reshape(mat_0_,list(mat_0.shape))
mat_1_ = []
for i0 in range(len(mat_1[:,0])):
temp = Symbol('x_'+str(i0))**mat_1_p[i0,:]
mat_1_.append( mat_1[i0,:]*temp )
mat_1 = np.reshape(mat_1_,list(mat_1.shape))
return [mat_0,mat_1]
def intMultNumPolynomialDer(level,n,n_probs,exponentials,ranges): # Returns the set of problems for this level
rng = np.random.default_rng()
mat_0 = rng.integers(1, high=10, size=(level,n_probs))
mat_0_p = rng.integers(1, high=exponentials+1, size=(level,n_probs))
mat_1 = rng.integers(2, high = 9, size=(n,n_probs))
mat_1_p = rng.integers(1, high=exponentials+1, size=(n+1,n_probs))
mat_0_ = []
for i0 in range(len(mat_0[:,0])):
temp = Symbol('x_'+str(i0))**mat_0_p[i0,:]
mat_0_.append( mat_0[i0,:]*temp )
mat_0 = np.reshape(mat_0_,list(mat_0.shape))
mat_1_ = []
for i0 in range(len(mat_1[:,0])):
temp = Symbol('x_'+str(i0))**mat_1_p[i0,:]
mat_1_.append( mat_1[i0,:]*temp )
mat_1 = np.reshape(mat_1_,list(mat_1.shape))
return [mat_0,mat_1]
level = 6
n = 4
#n = 1
exponentials = 3
n_probs = 25
ranges_ = 11
#mat_0,mat_1 = intMultNumPolynomial(level,n,n_probs,exponentials,ranges_) # Returns the set of problems for this level
mat = intNumPolynomial(level,n,n_probs,ranges_) # Returns the set of problems for this level
def changeLevelN(n_page,level,n):
if ((n_page > 2) and ( (n_page % 2) > 0 )):
level = level + 1
if ((n_page > 4) and ( (n_page % 4) == 0 )):
n = n + 1
level = level - 4
return n_page,level,n
def saveData(level,n,problem,n_page,PATH):
settings = {}
settings['level'] = level
settings['n'] = n
settings['problem'] = problem
settings['n_page'] = n_page
np.save(PATH+'settings', [settings], allow_pickle=True)
# =============================================================================
# %% Defs Latex
# =============================================================================
def headerExercisese(doc):
with doc.create(Section('Derivadas')):
doc.preamble.append(Command('usepackage', 'multicol'))
doc.append(NoEscape(r"\pagenumbering{gobble}"))
doc.append('Resolver todas las derivadas por la definicion de limites.')
doc.append(italic('###################'))
doc.append(NoEscape(r"\\"))
doc.append(NoEscape(r"\centerline{\rule{13cm}{0.4pt}}"))
# doc.append(NoEscape(r"\textcolor[RGB]{0,0,220}{\rule{\linewidth}{0.2pt}}"))
doc.append(NoEscape(r'\begin{multicols}{2}'))
doc.append(NoEscape(r"\begin{enumerate}"))
# with doc.create(Subsection('A subsection')):
# doc.append('Also some crazy characters: $&#{}')
def fill_document(doc):
"""Add a section, a subsection and some text to the document.
:param doc: the document
:type doc: :class:`pylatex.document.Document` instance
"""
with doc.create(Section('A section')):
doc.append('Some regular text and some ')
doc.append(italic('italic text. '))
with doc.create(Subsection('A subsection')):
doc.append('Also some crazy characters: $&#{}')
#if __name__ == '__main__':
# # Basic document
# doc = Document('basic')
# fill_document(doc)
#
# doc.generate_pdf(clean_tex=False)
# doc.generate_tex(filepath=exercises_PATH)
#
# # Document with `\maketitle` command activated
# doc = Document()
#
# doc.preamble.append(Command('title', 'Awesome Title'))
# doc.preamble.append(Command('author', 'Anonymous author'))
# doc.preamble.append(Command('date', NoEscape(r'\today')))
# doc.append(NoEscape(r'\maketitle'))
#
# fill_document(doc)
#
# doc.generate_pdf('basic_maketitle', clean_tex=False)
#
# # Add stuff to the document
# with doc.create(Section('A second section')):
# doc.append('Some text.')
#
# doc.generate_pdf('basic_maketitle2', clean_tex=False)
# tex = doc.dumps() # The document as string in LaTeX syntax
# =============================================================================
# %% Class
# =============================================================================
class sumLevel():
def __init__(self):
# A Part of the problems: Add two levels after every Page
# B Part of the problems: Add one n every two levels
self.PATH = PATH+'/Addition/'
try:
os.mkdir(self.PATH)
self.level = 5
self.n = 1
self.problem = {}
self.n_probs = 15
self.n_page = 1
settings = {}
settings['level'] = self.level
settings['n'] = self.n
settings['problem'] = self.problem
settings['n_page'] = self.n_page
np.save(self.PATH+'settings', [settings], allow_pickle=True)
except:
# Load hist
settings = np.load(self.PATH+'settings.npy', allow_pickle=True)
settings = list(settings)
settings = settings[0]
self.level = settings['level']
self.n = settings['n']
self.problem = settings['problem']
self.n_page = settings['n_page']
self.n_probs = 15
def process(self):
settings = {}
mat = intNumLevel(self.level,self.n,self.n_probs)
idx = 'level_'+str(self.level)+'-n'+str(self.n)+'nPage'+str(self.n_page)
self.problem[idx] = {'problems':mat,'results':[]}
results = []
for i0 in range(self.n_probs):
mat_tmp = np.sum(mat[:,:,i0],axis=1)
print('\n')
for i1 in range(len(mat_tmp)):
print(' ' + str('{:,}'.format(mat_tmp[i1])).zfill(self.level)+'\r')
if (i1 < len(mat_tmp)-1):
print('+')
else:
print('_'*(self.level+3))
right_format = False
tick = time()
while not right_format:
try:
x = int(input('Answer: '))
right_format = True
except:
right_format = False
tock = time()-tick
if x == sum(mat_tmp):
results.append([True, tock])
print('Right')
else:
results.append([False, x, tock])
print('Wrong \n')
print('Solution: ' + str(sum(mat_tmp)))
if ( (i0 == self.n_probs-1) or (i0 == int(self.n_probs/2))):
winsound.Beep(150, 100)
sleep(45)
a = 0
self.n_page,self.level,self.n = changeLevelN(self.n_page,self.level,self.n)
self.problem[idx] = {'problems':mat,'results':results,'datetime':str(datetime.datetime.now())}
self.n_page = self.n_page + 1
# settings['level'] = self.level
# settings['n'] = self.n
# settings['problem'] = self.problem
# settings['n_page'] = self.n_page
#
# np.save(self.PATH+'settings', [settings], allow_pickle=True)
saveData(self.level,self.n,self.problem,self.n_page,self.PATH)
# def changeLevelN(self):
# if ((self.n_page > 2) and ( (self.n_page % 2) > 0 )):
# self.level = self.level + 1
#
# if ((self.n_page > 4) and ( (self.n_page % 4) == 0 )):
# self.n = self.n + 1
# self.level = self.level - 4
#------------------------------------------------------------------------------
class substractionLevel():
def __init__(self):
# A Part of the problems: Add two levels after every Page
# B Part of the problems: Add one n every two levels
self.PATH = PATH+'/Substraction/'
try:
os.mkdir(self.PATH)
self.level = 5
self.n = 1
self.problem = {}
self.n_probs = 15
self.n_page = 1
settings = {}
settings['level'] = self.level
settings['n'] = self.n
settings['problem'] = self.problem
settings['n_page'] = self.n_page
np.save(self.PATH+'settings', [settings], allow_pickle=True)
except:
# Load hist
settings = np.load(self.PATH+'settings.npy', allow_pickle=True)
settings = list(settings)
settings = settings[0]
self.level = settings['level']
self.n = settings['n']
self.problem = settings['problem']
self.n_page = settings['n_page']
self.n_probs = 15
def process(self):
settings = {}
mat = intNumLevel(self.level,self.n,self.n_probs)
idx = 'level_'+str(self.level)+'-n'+str(self.n)+'nPage'+str(self.n_page)
self.problem[idx] = {'problems':mat,'results':[]}
results = []
for i0 in range(self.n_probs):
mat_tmp = np.sum(mat[:,:,i0],axis=1)
rng = np.random.default_rng()
sign = rng.integers(2, size=(self.n,self.n_probs))
print('\n')
for i1 in range(len(mat_tmp)):
# print('\n')
# print(' ' + str(mat_tmp[i1]).zfill(self.level)+'\r')
if (i1 < len(mat_tmp)-1):
if sign[0][i1] > 0:
mat_tmp[i1] = -1*mat_tmp[i1]
# print('-')
# else:
# print('+')
if ( len(str(mat_tmp[i1]).zfill(self.level)) > self.level ):
print(' ' + str('{:,}'.format(mat_tmp[i1])).zfill(self.level)+'\r')
else:
print(' ' + str('{:,}'.format(mat_tmp[i1])).zfill(self.level)+'\r')
print('+')
else:
print(' ' + str('{:,}'.format(mat_tmp[i1])).zfill(self.level)+'\r')
print('_'*(self.level+3))
right_format = False
tick = time()
while not right_format:
try:
x = int(input('Answer: '))
right_format = True
except:
right_format = False
tock = time()-tick
if x == sum(mat_tmp):
results.append([True, tock])
print('Right')
else:
results.append([False, x, tock])
print('Wrong \n')
print('Solution: ' + str(sum(mat_tmp)))
if ( (i0 == self.n_probs-1) or (i0 == int(self.n_probs/2))):
winsound.Beep(150, 100)
sleep(45)
a = 0
# if ((self.n_page > 2) and ( (self.n_page % 2) > 0 )):
# self.level =+ 1
#
# if ((self.n_page > 2) and ( (self.n_page % 4) == 0 )):
# self.n =+ 1
self.n_page,self.level,self.n = changeLevelN(self.n_page,self.level,self.n)
self.n_page = self.n_page + 1
self.problem[idx] = {'problems':mat,'results':results,'datetime':str(datetime.datetime.now())}
saveData(self.level,self.n,self.problem,self.n_page,self.PATH)
#------------------------------------------------------------------------------
class MultiplicationLevel():
def __init__(self):
# A Part of the problems: Add two levels after every Page
# B Part of the problems: Add one n every two levels
self.PATH = PATH+'/Multiplication/'
try:
os.mkdir(self.PATH)
self.level = 3
self.n = 0
self.problem = {}
self.n_probs = 25
self.n_page = 1
settings = {}
settings['level'] = self.level
settings['n'] = self.n
settings['problem'] = self.problem
settings['n_page'] = self.n_page
np.save(self.PATH+'settings', [settings], allow_pickle=True)
except:
# Load hist
settings = np.load(self.PATH+'settings.npy', allow_pickle=True)
settings = list(settings)
settings = settings[0]
self.level = settings['level']
self.n = settings['n']
self.problem = settings['problem']
self.n_page = settings['n_page']
self.n_probs = 15
def process(self):
settings = {}
mat = intMultNumLevel(self.level,self.n,self.n_probs)
mat0, mat1 = mat
idx = 'level_'+str(self.level)+'-n'+str(self.n)+'nPage'+str(self.n_page)
self.problem[idx] = {'problems':mat,'results':[]}
results = []
for i0 in range(self.n_probs):
mat_tmp_0 = np.sum(mat0[:,i0],axis=0)
mat_tmp_1 = np.sum(mat1[:,i0],axis=0)
print('\n')
print(' ' + str('{:,}'.format(mat_tmp_0)).zfill(self.level)+'\r')
print('*')
print(' ' + ' '*(self.level-(self.n+1)) + str('{:,}'.format(mat_tmp_1)).zfill(self.n+1)+'\r')
print('_'*(self.level+3))
right_format = False
tick = time()
while not right_format:
try:
x = int(input('Answer: '))
right_format = True
except:
right_format = False
tock = time()-tick
if x == (mat_tmp_0*mat_tmp_1):
results.append([True, tock])
print('Right')
else:
results.append([False, x, tock])
print('Wrong \n')
print('Solution: ' + str(mat_tmp_0*mat_tmp_1))
if ( (i0 == self.n_probs-1) or (i0 == int(self.n_probs/2))):
winsound.Beep(150, 100)
sleep(45)
self.n_page,self.level,self.n = changeLevelN(self.n_page,self.level,self.n)
self.n_page = self.n_page + 1
self.problem[idx] = {'problems':mat,'results':results,'datetime':str(datetime.datetime.now())}
saveData(self.level,self.n,self.problem,self.n_page,self.PATH)
class DivLevel():
def __init__(self):
# A Part of the problems: Add two levels after every Page
# B Part of the problems: Add one n every two levels
self.PATH = PATH+'/Div/'
try:
os.mkdir(self.PATH)
self.level = 3
self.n = 0
self.problem = {}
self.n_probs = 25
self.n_page = 1
settings = {}
settings['level'] = self.level
settings['n'] = self.n
settings['problem'] = self.problem
settings['n_page'] = self.n_page
settings['n_probs'] = self.n_probs
np.save(self.PATH+'settings', [settings], allow_pickle=True)
except:
# Load hist
settings = np.load(self.PATH+'settings.npy', allow_pickle=True)
settings = list(settings)
settings = settings[0]
self.level = settings['level']
self.n = settings['n']
self.problem = settings['problem']
self.n_page = settings['n_page']
self.n_probs = settings['n_probs']
def process(self):
settings = {}
mat = intMultNumLevel(self.level,self.n,self.n_probs)
mat0, mat1 = mat
idx = 'level_'+str(self.level)+'-n'+str(self.n)+'nPage'+str(self.n_page)
self.problem[idx] = {'problems':mat,'results':[]}
results = []
for i0 in range(self.n_probs):
mat_tmp_0 = np.sum(mat0[:,i0],axis=0)
mat_tmp_1 = np.sum(mat1[:,i0],axis=0)
print('\n')
print(' ' + ' '*(self.n+1) + str('{:,}'.format(mat_tmp_0)).zfill(self.level)+'\r')
print('/')
print(' ' + str('{:,}'.format(mat_tmp_1)).zfill(self.n+1)+'\r')
print('_'*(self.level+3))
right_format = False
tick = time()
while not right_format:
try:
x = int(input('Answer: '))
right_format = True
except:
right_format = False
tock = time()-tick
if x == int(mat_tmp_0/mat_tmp_1):
results.append([True, tock])
print('Right')
else:
results.append([False, x, tock])
print('Wrong \n')
print('Solution: ' + str(mat_tmp_0/mat_tmp_1))
if ( (i0 == self.n_probs-1) or (i0 == int(self.n_probs/2))):
winsound.Beep(150, 100)
sleep(45)
self.n_page,self.level,self.n,self.n_probs = self.changeLevelN()
self.n_page = self.n_page + 1
self.problem[idx] = {'problems':mat,'results':results,'datetime':str(datetime.datetime.now())}
self.saveData()
def changeLevelN(self):
if ((self.n_page > 2) and ( (self.n_page % 2) > 0 )):
self.level = self.level + 1
if ((self.n_page > 4) and ( (self.n_page % 4) == 0 )):
self.n = self.n + 1
self.level = self.level - 4
self.n_probs = 10
return self.n_page,self.level,self.n,self.n_probs
def saveData(self):
settings = {}
settings['level'] = self.level
settings['n'] = self.n
settings['problem'] = self.problem
settings['n_page'] = self.n_page
settings['n_probs'] = self.n_probs
np.save(self.PATH+'settings', [settings], allow_pickle=True)
# =============================================================================
# %% Algebra
# =============================================================================
class PolynomialsSum():
def __init__(self):
# A Part of the problems: Add two levels after every Page
# B Part of the problems: Add one n every two levels
self.PATH = PATH+'/Polynomials Addition/'
try:
os.mkdir(self.PATH)
self.level = 3
self.n = 3
self.problem = {}
self.n_probs = 10
self.n_page = 1
settings = {}
settings['level'] = self.level
settings['n'] = self.n
settings['problem'] = self.problem
settings['n_page'] = self.n_page
np.save(self.PATH+'settings', [settings], allow_pickle=True)
except:
# Load hist
settings = np.load(self.PATH+'settings.npy', allow_pickle=True)
settings = list(settings)
settings = settings[0]
self.level = settings['level']
self.n = settings['n']
self.problem = settings['problem']
self.n_page = settings['n_page']
self.n_probs = 10
def changeLevelN(self):
if ((self.n_page > 4) and ( (self.n_page % 4) > 0 )):
self.level = self.level + 1
if ((self.n_page > 8) and ( (self.n_page % 8) == 0 )):
self.n = self.n + 1
self.level = self.level - 4
return self.n_page, self.level, self.n
def process(self):
settings = {}
mat = intNumPolynomial(self.level,self.n,self.n_probs,101)
idx = 'level_'+str(self.level)+'-n'+str(self.n)+'nPage'+str(self.n_page)
self.problem[idx] = {'problems':mat,'results':[]}
results = []
rng = np.random.default_rng()
sign = rng.integers(2, size=(self.n*self.level,self.n_probs))
sign = (sign*2)-1
for i0 in range(self.n_probs):
sign_ = sign[:,i0]
mat_tmp = mat[:,:,i0]
mat_tmp_ = [mat_tmp[:,i1] for i1 in range(np.shape(mat_tmp)[1])]
mat_tmp_ = np.reshape(mat_tmp_,[np.shape(mat_tmp)[1],np.shape(mat_tmp)[0]]).reshape([1,-1]).reshape([1,-1])
mat_tmp_ = mat_tmp_*sign_
mat_tmp_ = mat_tmp_[0]
mat_tmp__ = []
for i1,tmp in enumerate(sign_):
if tmp > 0:
mat_tmp__.append( '+ ' + str(mat_tmp_[i1]) )
elif tmp < 0:
try:
mat_tmp__.append( '- ' + str(mat_tmp_[i1]).split('-')[1] )
except:
a = 0
mat_tmp__ = ' '.join(mat_tmp__)
# for i1 in range(len(mat_tmp)):
# print(' ' + str(mat_tmp[i1]).zfill(self.level)+'\r')
# if (i1 < len(mat_tmp)-1):
# print('+')
# else:
# print('_'*(self.level+3))
print('Solve the Polynomial Operation: \n')
print(mat_tmp__)
right_format = False
tick = time()
while not right_format:
try:
x = parse_expr(input('Answer: '))
right_format = True
except:
right_format = False
tock = time()-tick
if x == np.sum(mat_tmp_):
results.append([True, tock])
print('Right')
else:
results.append([False, x, tock])
print('Wrong \n')
print('Solution: ' + str(sum(mat_tmp_)))
if ( (i0 == self.n_probs-1) or (i0 == int(self.n_probs/2))):
winsound.Beep(150, 100)
sleep(45)
a = 0
self.n_page,self.level,self.n = self.changeLevelN()
self.problem[idx] = {'problems':mat,'results':results, 'sign':sign_,'datetime':str(datetime.datetime.now())}
self.n_page = self.n_page + 1
saveData(self.level,self.n,self.problem,self.n_page,self.PATH)
#------------------------------------------------------------------------------
class PolynomialsOp():
def __init__(self):
# A Part of the problems: Add two levels after every Page
# B Part of the problems: Add one n every two levels
self.PATH = PATH+'/Polynomials Operations/'
try:
os.mkdir(self.PATH)
self.level = 3
self.n = 1
self.problem = {}
self.n_probs = 10
self.exponentials = 3
self.n_page = 1
settings = {}
settings['level'] = self.level
settings['n'] = self.n
settings['exponentials'] = self.exponentials
settings['problem'] = self.problem
settings['n_page'] = self.n_page
np.save(self.PATH+'settings', [settings], allow_pickle=True)
except:
# Load hist
settings = np.load(self.PATH+'settings.npy', allow_pickle=True)
settings = list(settings)
settings = settings[0]
self.level = settings['level']
self.n = settings['n']
self.problem = settings['problem']
self.n_page = settings['n_page']
self.exponentials = settings['exponentials']
self.n_probs = 10
def changeLevelN(self):
if ((self.n_page > 4) and ( (self.n_page % 4) > 0 )):
self.level = self.level + 1
if ((self.n_page > 8) and ( (self.n_page % 8) == 0 )):
self.n = self.n + 1
self.level = self.level - 4
self.exponentials = self.exponentials-1
if ((self.n_page > 3) and ( (self.n_page % 4) > 0 )):
self.exponentials = self.exponentials + 1
return self.n_page, self.level, self.n
def saveData(self):
settings = {}
settings['level'] = self.level
settings['n'] = self.n
settings['problem'] = self.problem
settings['n_page'] = self.n_page
settings['exponentials'] = self.exponentials
np.save(self.PATH+'settings', [settings], allow_pickle=True)
def process(self):
settings = {}
mat = intMultNumPolynomial(self.level,self.n,self.n_probs,self.exponentials,101)