-
Notifications
You must be signed in to change notification settings - Fork 0
/
mathfunctions.py
1913 lines (1520 loc) · 91 KB
/
mathfunctions.py
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
import random, math
def generate_addition_problems(n_samples):
problems_and_solutions = []
for _ in range(n_samples):
a = random.randint(-10000, 10000)
b = random.randint(-10000, 10000)
result = a + b
problem = f"{a} + {b} = ?"
solution = f"{a} + {b} = {result}"
problems_and_solutions.append(problem + "\n" + solution)
return problems_and_solutions
def generate_addition_problems2(number_of_samples):
results_addition = []
for i in range(number_of_samples):
for j in range(number_of_samples):
a = i - 100
b = j - 100
result = a + b
part1 = str(a) + " + " + str(b) + " = "
part2 = str(result)
results_addition.append(part1 + "\n" + part2)
return results_addition
def generate_subtraction_problems(n_samples):
problems_and_solutions = []
for _ in range(n_samples):
a = random.randint(-1000, 1000)
b = random.randint(-1000, 1000)
result = a - b
problem = f"{a} - {b} = ?"
solution = f"{a} - {b} = {result}"
problems_and_solutions.append(problem + "\n" + solution)
return problems_and_solutions
def generate_subtraction_problems2(number_of_samples):
results_subtraction = []
for i in range(number_of_samples):
for j in range(number_of_samples):
a = i - 100
b = j - 100
result = a - b
part1 = str(a) + " - " + str(b) + " = "
part2 = str(result)
results_subtraction.append(part1 + "\n" + part2)
return results_subtraction
def generate_power_problems(number_of_samples):
results_power = []
for i in range(number_of_samples):
for j in range(number_of_samples):
a = i - 30
b = j - 30
result = a ** b
part1 = str(a) + " ^ " + str(b) + " = "
part2 = str(result)
results_power.append(part1 + "\n" + part2)
return results_power
def generate_multiplication_problems(number_of_samples):
results_multiplication = []
for i in range(number_of_samples):
for j in range(number_of_samples):
a = i - 1000
b = j - 1000
result = a * b
part1 = str(a) + " * " + str(b) + " = "
part2 = str(result)
results_multiplication.append(part1 + "\n" + part2)
return results_multiplication
def generate_division_problems(number_of_samples):
results_division = []
for i in range(number_of_samples):
for j in range(number_of_samples):
a = i - 1000
b = j - 1000
if b == 0: # avoiding division by zero
part1 = str(a) + " / " + str(b) + " = "
part2 = "Not defined - Division by zero is not defined"
results_division.append(part1 + "\n" + part2)
continue
result = round(a / b, 2) # rounding to 2 decimal places
part1 = str(a) + " / " + str(b) + " = "
part2 = str(result)
results_division.append(part1 + "\n" + part2)
return results_division
def generate_addition_with_3_numbers_problems(number_of_samples):
results_addition_3_nums = []
for _ in range(number_of_samples):
a = random.randint(-100000000, 100000000)
b = random.randint(-100000000, 100000000)
c = random.randint(-100000000, 100000000)
result = a + b + c
part1 = str(a) + " + " + str(b) + " + " + str(c) + " = "
part2 = str(result)
results_addition_3_nums.append(part1 + "\n" + part2)
return results_addition_3_nums
def generate_addition_subtraction_with_3_numbers_problems(number_of_samples):
results_addition_subtraction_3_nums = []
for _ in range(number_of_samples):
a = random.randint(-100000000, 100000000)
b = random.randint(-100000000, 100000000)
c = random.randint(-100000000, 100000000)
result = a + b - c
part1 = str(a) + " + " + str(b) + " - " + str(c) + " = "
part2 = str(result)
results_addition_subtraction_3_nums.append(part1 + "\n" + part2)
return results_addition_subtraction_3_nums
def generate_addition_subtraction_with_3_numbers_problems(number_of_samples):
results_addition_subtraction = []
for _ in range(number_of_samples):
a = random.randint(-100000000, 100000000)
b = random.randint(-100000000, 100000000)
c = random.randint(-100000000, 100000000)
result = a + b - c
part1 = str(a) + " + " + str(b) + " - " + str(c) + " = "
part2 = str(result)
results_addition_subtraction.append(part1 + "\n" + part2)
return results_addition_subtraction
def generate_subtraction_subtraction_with_3_numbers_problems(number_of_samples):
results_subtraction_subtraction = []
for _ in range(number_of_samples):
a = random.randint(-100000000, 100000000)
b = random.randint(-100000000, 100000000)
c = random.randint(-100000000, 100000000)
result = a - b - c
part1 = str(a) + " - " + str(b) + " - " + str(c) + " = "
part2 = str(result)
results_subtraction_subtraction.append(part1 + "\n" + part2)
return results_subtraction_subtraction
def generate_multiplication_division_with_3_numbers_problems(number_of_samples):
results_multiplication_division = []
for _ in range(number_of_samples):
a = random.randint(-100000000, 100000000)
b = random.randint(-100000000, 100000000)
c = 0
while c == 0:
c = random.randint(9, 100)
result = a * b / c
part1 = str(a) + " * " + str(b) + " / " + str(c) + " = "
part2 = str(result)
results_multiplication_division.append(part1 + "\n" + part2)
return results_multiplication_division
def generate_addition_division_with_3_numbers_problems(number_of_samples):
results_addition_division_3_nums = []
for _ in range(number_of_samples):
a = random.randint(-100000000,100000000)
b = random.randint(-100000000,100000000)
c = 0
while c == 0:
c = random.randint(-14,29)
result = a + b / c
part1 = str(a) + " + " + str(b) + " / " + str(c) + " = "
part2 = str(result)
results_addition_division_3_nums.append(part1 + "\n" + part2)
return results_addition_division_3_nums
def generate_addition_multiplication_with_3_numbers_problems(number_of_samples):
results_addition_multiplication_3_nums = []
for _ in range(number_of_samples):
a = random.randint(-100000000,100000000)
b = random.randint(-100000000,100000000)
c = random.randint(-10000,10000)
result = a + b * c
part1 = str(a) + " + " + str(b) + " * " + str(c) + " = "
part2 = str(result)
results_addition_multiplication_3_nums.append(part1 + "\n" + part2)
return results_addition_multiplication_3_nums
def generate_addition_with_5_numbers_problems(number_of_samples):
results_addition_5_nums = []
for _ in range(number_of_samples):
a = random.randint(-100000000,100000000)
b = random.randint(-100000000,100000000)
c = random.randint(-100000000,100000000)
d = random.randint(-100000000,100000000)
e = random.randint(-100000000,100000000)
result = a + b + c + d + e
part1 = str(a) + " + " + str(b) + " + " + str(c) + " + " + str(d) + " + " + str(e) + " = "
part2 = str(result)
results_addition_5_nums.append(part1 + "\n" + part2)
return results_addition_5_nums
def generate_exponential_with_2_numbers_problems(number_of_samples):
results_exponential_2_nums = []
for _ in range(number_of_samples):
a = random.randint(-100000,100000) / 100
b = random.randint(0,200) / 20
result = a ** b
part1 = str(a) + " ** " + str(b) + " = "
part2 = str(result)
results_exponential_2_nums.append(part1 + "\n" + part2)
return results_exponential_2_nums
import random
import operator
# Mapping of operations
ops = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.truediv
}
def generate_random_math_problems(number_of_samples, min_numbers=3, max_numbers=6):
results = []
for _ in range(number_of_samples):
# Randomly choose the number of operands in this problem
num_operands = random.randint(min_numbers, max_numbers)
operands = []
operators = []
for _ in range(num_operands):
operands.append(random.randint(-1000, 1000)) # reduce the range to make computations faster
operators.append(random.choice(list(ops.keys())))
# Insert a division operation, if chosen
if random.choice([True, False]):
# Add a division operation
pos = random.randint(0, num_operands-2) # position to insert the operation
operators[pos] = '/'
operands[pos+1] = random.randint(1, 100) # make sure we don't divide by zero
# Calculate result
result = operands[0]
for i in range(1, num_operands):
result = ops[operators[i-1]](result, operands[i])
# Build the problem string
problem = ""
for i in range(num_operands):
problem += str(operands[i])
if i != num_operands - 1:
problem += " " + operators[i] + " "
else:
problem += " = "
# Append problem and solution to results
results.append(problem + "\n" + str(result))
return results
def generate_hypothenuse_with_pythagoras(number_of_samples):
# define templates for each step
template_intro = ["We are given a right-angled triangle with side 'a' measuring {side1} units and side 'b' measuring {side2} units. We're looking to find the length of the hypotenuse (h).",
"We have a right triangle where the lengths of sides 'a' and 'b' are {side1} units and {side2} units respectively. We are tasked with finding the length of the hypotenuse (h).",
"In a right-angled triangle with sides 'a' and 'b' of lengths {side1} units and {side2} units respectively, we are searching for the length of the hypotenuse (h).",
"Given a right triangle with side lengths of 'a' = {side1} units and 'b' = {side2} units, we're aiming to find the length of the hypotenuse, 'h'.",
"In a scenario where we have a right triangle, side 'a' is {side1} units long and side 'b' is {side2} units long. Our objective is to compute the length of the hypotenuse (h).",
"Imagine a right triangle with sides 'a' and 'b' that measure {side1} units and {side2} units respectively. Our mission is to determine the length of the hypotenuse, denoted as 'h'.",
"Let's consider a right-angled triangle, where the length of side 'a' is {side1} units and side 'b' is {side2} units. We're looking to ascertain the length of the hypotenuse, 'h'.",
"We're dealing with a right triangle here. Side 'a' is {side1} units, side 'b' is {side2} units. Our goal? To find out how long the hypotenuse (h) is.",
"Think of a right-angled triangle. Side 'a' has a length of {side1} units, and side 'b' is {side2} units long. We're tasked with determining the length of the hypotenuse (h).",
"Picture this: a right triangle. Side 'a' measures {side1} units, side 'b' measures {side2} units. Our task is to figure out the length of the hypotenuse, 'h'.",
"Let's work with a right-angled triangle where side 'a' equals {side1} units and side 'b' equals {side2} units. Our task is to identify the length of the hypotenuse, 'h'.",
"We have a right triangle at our hands, with side 'a' being {side1} units long and side 'b' being {side2} units long. We're aiming to uncover the length of the hypotenuse, denoted as 'h'."]
template_step1 = ["Step 1: According to the Pythagorean theorem, the square of the hypotenuse is equal to the sum of the squares of the other two sides.",
"The first step is to remember the Pythagorean theorem, which states that in any right triangle, the square of the length of the hypotenuse is the sum of the squares of the lengths of the other two sides.",
"We begin with the Pythagorean theorem, which says the hypotenuse's square is the sum of the squares of the other two sides.",
"Firstly, we apply the Pythagorean theorem. It states that the square of the hypotenuse is equivalent to the sum of the squares of the other two sides.",
"Starting off with the Pythagorean theorem, the square of the hypotenuse equals the sum of the squares of the other two sides.",
"The initial step is guided by the Pythagorean theorem. This theorem posits that the hypotenuse's square equals the sum of the squares of the other two sides.",
"Our journey starts with the Pythagorean theorem, declaring that the square of the hypotenuse amounts to the sum of the squares of the other two sides.",
"First and foremost, we acknowledge the Pythagorean theorem, asserting that the square of the hypotenuse is the total of the squares of the other two sides.",
"We kick off with the Pythagorean theorem, which claims the square of the hypotenuse is the aggregate of the squares of the other two sides.",
"Step one involves the Pythagorean theorem. This theorem suggests that the square of the hypotenuse equals the accumulation of the squares of the other two sides.",
"Let's start with the Pythagorean theorem, according to which the square of the hypotenuse equals the summation of the squares of the other two sides.",
"We start by applying the Pythagorean theorem. It says the square of the hypotenuse is the combination of the squares of the other two sides."]
template_step2 = ["Step 2: Applying the theorem, we get {side1}^2 + {side2}^2 = h^2.",
"Next, we apply the theorem to our specific situation, yielding {side1}^2 + {side2}^2 = h^2.",
"We then apply this theorem to our case, which gives us {side1}^2 + {side2}^2 = h^2.",
"The theorem applied to our case gives us {side1}^2 + {side2}^2 = h^2.",
"When we apply this theorem, we get {side1}^2 + {side2}^2 = h^2.",
"Upon application of the theorem, the equation is {side1}^2 + {side2}^2 = h^2.",
"By implementing the theorem, we obtain {side1}^2 + {side2}^2 = h^2.",
"In applying the theorem, we derive {side1}^2 + {side2}^2 = h^2.",
"Through the theorem's application, it follows that {side1}^2 + {side2}^2 = h^2.",
"Upon using the theorem, we are left with {side1}^2 + {side2}^2 = h^2.",
"By leveraging the theorem, we get {side1}^2 + {side2}^2 = h^2.",
"Through utilizing the theorem, we attain {side1}^2 + {side2}^2 = h^2."]
template_step3 = ["Step 3: Simplifying the equation, we have {side1}^2 + {side2}^2 = h^2.",
"In the third step, we simplify the equation, which gives us {side1}^2 + {side2}^2 = h^2.",
"Then, we simplify the equation, resulting in {side1}^2 + {side2}^2 = h^2.",
"We proceed to simplify the equation to {side1}^2 + {side2}^2 = h^2.",
"Simplifying the equation leaves us with {side1}^2 + {side2}^2 = h^2.",
"On simplifying the equation, we have {side1}^2 + {side2}^2 = h^2.",
"We then simplify the equation, and we get {side1}^2 + {side2}^2 = h^2.",
"We simplify the equation next, yielding {side1}^2 + {side2}^2 = h^2.",
"When we simplify the equation, it becomes {side1}^2 + {side2}^2 = h^2.",
"Upon simplification of the equation, we get {side1}^2 + {side2}^2 = h^2.",
"Simplification of the equation results in {side1}^2 + {side2}^2 = h^2.",
"By simplifying the equation, we obtain {side1}^2 + {side2}^2 = h^2."]
template_step4 = ["Step 4: Taking the square root of both sides, we find that h = sqrt({side1}^2 + {side2}^2).",
"In the fourth step, we take the square root of both sides, which leads us to h = sqrt({side1}^2 + {side2}^2).",
"Next, we take the square root of both sides of the equation, giving us h = sqrt({side1}^2 + {side2}^2).",
"We now take the square root of both sides of the equation to get h = sqrt({side1}^2 + {side2}^2).",
"We take the square root on both sides of the equation, resulting in h = sqrt({side1}^2 + {side2}^2).",
"By taking the square root on both sides, we get h = sqrt({side1}^2 + {side2}^2).",
"When we take the square root of both sides, we find that h = sqrt({side1}^2 + {side2}^2).",
"Upon taking the square root of both sides, it results in h = sqrt({side1}^2 + {side2}^2).",
"Taking the square root of both sides of the equation, we obtain h = sqrt({side1}^2 + {side2}^2).",
"After taking the square root on both sides, we conclude that h = sqrt({side1}^2 + {side2}^2).",
"By taking the square root on both sides, it is found that h = sqrt({side1}^2 + {side2}^2).",
"We determine h by taking the square root of both sides, which yields h = sqrt({side1}^2 + {side2}^2)."]
template_conclusion = ["So, the length of the hypotenuse (h) is approximately {hypotenuse} units.",
"Therefore, the length of the hypotenuse, 'h', is roughly {hypotenuse} units.",
"Hence, the length of the hypotenuse (h) is about {hypotenuse} units.",
"As a result, the hypotenuse 'h' measures approximately {hypotenuse} units.",
"So, 'h', the hypotenuse, has a length of approximately {hypotenuse} units.",
"In conclusion, the hypotenuse 'h' is roughly {hypotenuse} units long.",
"Thus, the length of the hypotenuse (h) is approximately {hypotenuse} units.",
"Accordingly, the length of the hypotenuse, noted as 'h', is around {hypotenuse} units.",
"This means that the length of the hypotenuse 'h' is nearly {hypotenuse} units.",
"Consequently, the hypotenuse 'h' measures about {hypotenuse} units.",
"This leads us to conclude that the hypotenuse (h) is approximately {hypotenuse} units long.",
"Subsequently, the length of the hypotenuse, known as 'h', is nearly {hypotenuse} units."]
results = []
for _ in range(number_of_samples):
side1 = random.randint(1, 100)
side2 = random.randint(1, 100)
hypotenuse = math.sqrt(side1**2 + side2**2)
# randomly select a template for each step
explanation_intro = random.choice(template_intro).format(side1=side1, side2=side2)
explanation_step1 = random.choice(template_step1)
explanation_step2 = random.choice(template_step2).format(side1=side1, side2=side2)
explanation_step3 = random.choice(template_step3).format(side1=side1, side2=side2)
explanation_step4 = random.choice(template_step4).format(side1=side1, side2=side2)
explanation_conclusion = random.choice(template_conclusion).format(hypotenuse=round(hypotenuse, 2))
# combine all steps to form the final explanation
explanation = explanation_intro + '\n' + explanation_step1 + '\n' + explanation_step2 + '\n' + explanation_step3 + '\n' + explanation_step4 + '\n' + explanation_conclusion
results.append(explanation)
return results
import math
import random
import random
import math
def generate_missing_side_with_pythagoras(number_of_samples):
# define templates for each step
template_intro = ["We are given a right-angled triangle with hypotenuse 'h' measuring {hypotenuse} units and one side 'a' measuring {side1} units. We're looking to find the length of the other side.",
"Consider a right triangle where the lengths of the hypotenuse 'h' is {hypotenuse} units and one side 'a' is {side1} units. We are tasked with finding the length of the missing side.",
"Imagine a right-angled triangle. The hypotenuse 'h' measures {hypotenuse} units, one side 'a' measures {side1} units. Our task is to figure out the length of the other side.",
"Let's work with a right-angled triangle where the hypotenuse 'h' equals {hypotenuse} units and one side 'a' equals {side1} units. Our task is to identify the length of the other side.",
"Picturing a right triangle, we know the length of the hypotenuse 'h' to be {hypotenuse} units and one of the sides 'a' to be {side1} units. Our aim is to find the length of the remaining side.",
"We are dealing with a right-angled triangle, with a hypotenuse 'h' of {hypotenuse} units and one side 'a' of {side1} units. We need to find out how long the other side is.",
"Envision a right triangle with hypotenuse 'h' at {hypotenuse} units and a side 'a' at {side1} units. We are searching for the length of the second side."]
template_step1 = ["Step 1: According to the Pythagorean theorem, the square of the hypotenuse is equal to the sum of the squares of the other two sides. In this case, we can rearrange the formula to find the missing side.",
"The first step is to remember the Pythagorean theorem, which states that in any right triangle, the square of the length of the hypotenuse is the sum of the squares of the lengths of the other two sides. We'll modify the formula to calculate our missing side.",
"We start by applying the Pythagorean theorem. In our situation, we will adjust the theorem to calculate the missing side length.",
"Step one involves the Pythagorean theorem. Given our scenario, we'll be tweaking the theorem to compute the length of the missing side.",
"The initial step calls upon the Pythagorean theorem. The square of the hypotenuse is equal to the sum of the squares of the other two sides. We'll alter this theorem to find the length of the missing side.",
"We first turn to the Pythagorean theorem, where the hypotenuse's square equals the sum of the squares of the other two sides. We will adapt this theorem for our needs.",
"Firstly, we make use of the Pythagorean theorem. This theorem states that the square of the hypotenuse is the sum of the squares of the other two sides. We will rearrange this to find the missing side."]
template_step2 = ["Step 2: Applying the rearranged theorem, we get {hypotenuse}^2 - {side1}^2 = missing side^2.",
"Next, we apply the adjusted theorem to our specific situation, yielding {hypotenuse}^2 - {side1}^2 = missing side^2.",
"We then apply this modified theorem to our case, which gives us {hypotenuse}^2 - {side1}^2 = missing side^2.",
"When we apply this revised theorem, we get {hypotenuse}^2 - {side1}^2 = missing side^2.",
"The next step involves using the modified theorem, which gives us {hypotenuse}^2 - {side1}^2 = missing side^2.",
"Following this, we apply our adjusted formula. This provides us with {hypotenuse}^2 - {side1}^2 = missing side^2.",
"Moving on, we utilize the rearranged formula, which results in {hypotenuse}^2 - {side1}^2 = missing side^2."]
template_step3 = ["Step 3: Taking the square root of both sides, we find that the missing side = sqrt({hypotenuse}^2 - {side1}^2).",
"In the third step, we take the square root of both sides, which leads us to missing side = sqrt({hypotenuse}h^2 - {side1}^2).",
"Next, we take the square root of both sides of the equation, giving us missing side = sqrt({hypotenuse}^2 - {side1}^2).",
"We now take the square root of both sides of the equation to get missing side = sqrt({hypotenuse}^2 - {side1}^2).",
"Lastly, we will take the square root of both sides of our equation. This gives us missing side = sqrt({hypotenuse}^2 - {side1}^2).",
"The final step is to take the square root of both sides, leading us to missing side = sqrt({hypotenuse}^2 - {side1}^2).",
"The concluding step requires us to take the square root of both sides, resulting in missing side = sqrt({hypotenuse}^2 - {side1}^2)."]
template_conclusion = ["So, the length of the missing side is approximately {missing_side} units.",
"Therefore, the length of the missing side is roughly {missing_side} units.",
"Hence, the length of the missing side is about {missing_side} units.",
"As a result, the missing side measures approximately {missing_side} units.",
"Thus, the missing side is approximately {missing_side} units long.",
"This implies that the missing side's length is approximately {missing_side} units.",
"Consequently, the length of the missing side is roughly {missing_side} units.",
"In conclusion, the missing side is about {missing_side} units long."]
samples = []
for _ in range(number_of_samples):
hypotenuse = round(random.uniform(1, 100), 2)
side1 = round(random.uniform(0.5, hypotenuse), 3)
missing_side = round(math.sqrt(hypotenuse**2 - side1**2), 3)
problems = []
problem = '\n'.join([
random.choice(template_intro).format(hypotenuse=hypotenuse, side1=side1),
random.choice(template_step1),
random.choice(template_step2).format(hypotenuse=hypotenuse, side1=side1),
random.choice(template_step3).format(hypotenuse=hypotenuse, side1=side1),
random.choice(template_conclusion).format(missing_side=missing_side)
])
problems.append(problem)
return problems
#print(generate_missing_side_with_pythagoras(1)[0])
import random
def addition_step_by_step1(number_of_samples):
def generate_addition_problem():
num1 = random.randint(1, 9999999999)
num2 = random.randint(1, 9999999999)
return num1, num2, num1 + num2
templates = [
"Alright, let's solve this problem step by step. We have {} and {} and we're adding them together.",
"No problem, let's work through this together. We're starting with {} and {} and adding them all up.",
"Sure thing! We've got {} and {} and we're gonna add them together.",
"OK, let's do this. We've got {} and {} and we're adding them all together.",
"Let's get this math done. We have {} and {} and we're going to add them all together.",
"Okay, we are given {} and {}. Let's add them up step by step.",
"We have numbers {} and {}. Let's start adding them together.",
"Let's break this down. We're going to add {} and {} together.",
"Ready to do some math? We're starting with {} and {} and adding them up.",
"Let's solve this addition problem. We have {} and {}, and we need to add them together.",
"Not to worry, we've got {} and {}. Let's get to adding them!",
"We are presented with {} and {}. Let's work out the sum.",
"Okay, we are tasked with adding {} and {}. Let's begin!",
"Here we go! We're going to add {} and {} together.",
"We've got two numbers: {} and {}. Let's find their sum."
]
problems = []
for _ in range(number_of_samples):
num1, num2, result = generate_addition_problem()
explanation = random.choice(templates).format(num1, num2)
explanation += "\n\n"
num1, num2 = str(num1), str(num2)
max_len = max(len(num1), len(num2))
carry = 0
for i in range(max_len):
cur_digit_sum = carry
cur_digit1 = int(num1[-i-1]) if i < len(num1) else 0
cur_digit2 = int(num2[-i-1]) if i < len(num2) else 0
cur_digit_sum += cur_digit1 + cur_digit2
explanation += f"Step {i+1}: We'll start by adding the digits {cur_digit1} & {cur_digit2} in column {i+1} and get {cur_digit_sum}.\n"
if cur_digit_sum > 9:
explanation += f"We'll write down the last digit {cur_digit_sum%10} and carry the {cur_digit_sum//10} to the next column.\n\n"
carry = cur_digit_sum//10
else:
explanation += "\n"
carry = 0
explanation += f"So, {num1} + {num2} = {result}.\n\n"
problems.append(explanation)
return problems
def addition_step_by_step2(number_of_samples):
def generate_addition_problem():
num1 = random.randint(1, 9999)
num2 = random.randint(1, 9999)
return num1, num2, num1 + num2
templates = [
"Alright, let's solve this problem step by step. We have {} and {} and we're adding them together.",
"No problem, let's work through this together. We're starting with {} and {} and adding them all up.",
"Sure thing! We've got {} and {} and we're gonna add them together.",
"OK, let's do this. We've got {} and {} and we're adding them all together.",
"Let's get this math done. We have {} and {} and we're going to add them all together.",
"Okay, we are given {} and {}. Let's add them up step by step.",
"We have numbers {} and {}. Let's start adding them together.",
"Let's break this down. We're going to add {} and {} together.",
"Ready to do some math? We're starting with {} and {} and adding them up.",
"Let's solve this addition problem. We have {} and {}, and we need to add them together.",
"Not to worry, we've got {} and {}. Let's get to adding them!",
"We are presented with {} and {}. Let's work out the sum.",
"Okay, we are tasked with adding {} and {}. Let's begin!",
"Here we go! We're going to add {} and {} together.",
"We've got two numbers: {} and {}. Let's find their sum."
]
problems = []
for _ in range(number_of_samples):
num1, num2, result = generate_addition_problem()
explanation = random.choice(templates).format(num1, num2)
explanation += "\n\n"
num1, num2 = str(num1), str(num2)
max_len = max(len(num1), len(num2))
carry = 0
for i in range(max_len):
cur_digit_sum = carry
cur_digit1 = int(num1[-i-1]) if i < len(num1) else 0
cur_digit2 = int(num2[-i-1]) if i < len(num2) else 0
cur_digit_sum += cur_digit1 + cur_digit2
explanation += f"Step {i+1}: We'll start by adding the digits {cur_digit1} & {cur_digit2} in column {i+1} and get {cur_digit_sum}.\n"
if cur_digit_sum > 9:
explanation += f"We'll write down the last digit {cur_digit_sum%10} and carry the {cur_digit_sum//10} to the next column.\n\n"
carry = cur_digit_sum//10
else:
explanation += "\n"
carry = 0
explanation += f"So, {num1} + {num2} = {result}.\n\n"
problems.append(explanation)
return problems
import random
def substraction_step_by_step1(number_of_samples):
templates = [
"Alright, let's solve this problem step by step. We have {} and {}, and we're subtracting the second number from the first.",
"No problem, let's work through this together. We're starting with {} and are subtracting {} from it.",
"Sure thing! We've got {} and {}, and we're going to subtract the second number from the first.",
"OK, let's do this. We've got {} and {}, and we're subtracting the second number from the first.",
"Let's get this math done. We have {} and {}, and we're going to subtract the second number from the first.",
"Alright, ready to do some subtraction? We're taking {} and subtracting {} from it.",
"We can solve this together! We're beginning with {} and removing {} from it.",
"Got it! So, we have {} and {}, and we'll subtract the latter from the former.",
"Okay, let's tackle this math problem. We're starting with {} and subtracting {}.",
"Let's dive into this subtraction. We'll start with {} and subtract {} from it."
]
problems = []
for _ in range(number_of_samples):
num1 = random.randint(0, 1000000000)
num2 = random.randint(0, 1000000000)
if num2 > num1:
num1, num2 = num2, num1
result = num1 - num2
explanation = random.choice(templates).format(num1, num2)
explanation += "\n\n"
nums = [str(num1), str(num2)]
max_len = max([len(num) for num in nums])
borrow = 0
try:
for i in range(max_len):
cur_digit_diff = int(nums[0][-i-1]) - borrow
cur_digit = int(nums[1][-i-1]) if i < len(nums[1]) else 0
cur_digit_diff -= cur_digit
explanation += f"Step {i+1}: We'll start by subtracting the digit {cur_digit} and the borrow {borrow} from {cur_digit_diff + borrow+cur_digit} in column {i+1} and get {cur_digit_diff}.\n"
if i ==0:
if cur_digit_diff < 0:
explanation += f"We add {cur_digit_diff} to 10 and get {(cur_digit_diff + 10)%10} as the first digit of the result.\n\n"
borrow = 1
else:
explanation += f"{cur_digit_diff} is the first digit of our result.\n\n"
borrow = 0
else:
if cur_digit_diff < 0:
explanation += f"We add {cur_digit_diff} to 10 and get {(cur_digit_diff + 10)%10} as the next digit of the result.\n\n"
borrow = 1
else:
explanation += f"{cur_digit_diff} is the next digit of our result.\n\n"
borrow = 0
except:
continue
explanation += f"So, {num1} - {num2} = {result}."
problems.append(explanation)
return problems
def substraction_step_by_step2(number_of_samples):
templates = [
"Alright, let's solve this problem step by step. We have {} and {}, and we're subtracting the second number from the first.",
"No problem, let's work through this together. We're starting with {} and are subtracting {} from it.",
"Sure thing! We've got {} and {}, and we're going to subtract the second number from the first.",
"OK, let's do this. We've got {} and {}, and we're subtracting the second number from the first.",
"Let's get this math done. We have {} and {}, and we're going to subtract the second number from the first.",
"Alright, ready to do some subtraction? We're taking {} and subtracting {} from it.",
"We can solve this together! We're beginning with {} and removing {} from it.",
"Got it! So, we have {} and {}, and we'll subtract the latter from the former.",
"Okay, let's tackle this math problem. We're starting with {} and subtracting {}.",
"Let's dive into this subtraction. We'll start with {} and subtract {} from it."
]
problems = []
for _ in range(number_of_samples):
num1 = random.randint(0, 1000000)
num2 = random.randint(0, 100000)
if num2 > num1:
num1, num2 = num2, num1
result = num1 - num2
explanation = random.choice(templates).format(num1, num2)
explanation += "\n\n"
nums = [str(num1), str(num2)]
max_len = max([len(num) for num in nums])
borrow = 0
try:
for i in range(max_len):
cur_digit_diff = int(nums[0][-i-1]) - borrow
cur_digit = int(nums[1][-i-1]) if i < len(nums[1]) else 0
cur_digit_diff -= cur_digit
explanation += f"Step {i+1}: We'll start by subtracting the digit {cur_digit} and the borrow {borrow} from {cur_digit_diff + borrow+cur_digit} in column {i+1} and get {cur_digit_diff}.\n"
if i ==0:
if cur_digit_diff < 0:
explanation += f"We add {cur_digit_diff} to 10 and get {(cur_digit_diff + 10)%10} as the first digit of the result.\n\n"
borrow = 1
else:
explanation += f"{cur_digit_diff} is the first digit of our result.\n\n"
borrow = 0
else:
if cur_digit_diff < 0:
explanation += f"We add {cur_digit_diff} to 10 and get {(cur_digit_diff + 10)%10} as the next digit of the result.\n\n"
borrow = 1
else:
explanation += f"{cur_digit_diff} is the next digit of our result.\n\n"
borrow = 0
except:
continue
explanation += f"So, {num1} - {num2} = {result}."
problems.append(explanation)
return problems
import random
import random
import random
def multiplication_step_by_step(number_of_samples):
problems = []
for _ in range(number_of_samples):
x = random.randint(0, 1000)
y = random.randint(0, 500)
result = 0
templates = [
f"Alright, let's solve this math problem step by step. First, we have the number {x}. Next, we see the multiplication sign, which means we need to multiply something. And what are we multiplying it by? We multiply it by {y}. So, we're going to take the number {x} and add it to itself {y} times.",
f"OK, let's work through this together. We're starting with {x} and we're going to multiply it by {y}, which means we add {x} to itself {y} times.",
f"Sure thing! We've got {x} and we're gonna multiply it by {y}. That's the same as adding {x} to itself {y} times.",
f"Let's get this math done. We have {x} and we're going to multiply it by {y}. This is the same as taking {x} and adding it to itself {y} times.",
f"OK, let's crack this. We're given {x} and our task is to multiply it by {y}. Essentially, we'll be adding {x} to itself {y} times.",
f"Without delay, let's solve this. We've got {x} and we will be multiplying it by {y}, that is, adding {x} to itself {y} times.",
f"Sure thing, let's get straight to it. We start with {x} and we're going to multiply it by {y}, which means adding {x} to itself {y} times.",
f"Let's roll up our sleeves and solve this. We have {x} and we're going to multiply it by {y}, essentially adding {x} to itself {y} times."
]
explanation = random.choice(templates)
explanation += "\n"
for i in range(1, y+1):
result += x
explanation += f"Step {i}: {result-x} + {x} = {result}\n"
explanation += f"\nSo, {x}*{y} = {result}"
problems.append(explanation)
return problems
def multiplication_step_by_step_short1(number_of_samples):
templates = [
"Let's calculate {num1} x {num2}",
"We're going to solve {num1} multiplied by {num2}",
"Alright, let's work through {num1} times {num2} step by step",
"No problem, we've got {num1} and {num2} to multiply",
"Sure thing! Let's multiply {num1} and {num2} together"
]
alternative_texts = [
"that equals",
"which equals",
"that is equal",
"what gives us",
"that results in",
"yielding",
"giving us",
"producing",
"resulting in"
]
problems = []
for _ in range(number_of_samples):
num1 = random.randint(0, 10000)
num2 = random.randint(0, 10000)
num1_str = str(num1)
num2_str = str(num2)
template = random.choice(templates)
explanation = template.format(num1=num1, num2=num2) + "\n"
explanation += f"{num1} × {num2} = {num2} × ({num1_str})\n"
partial_sums = []
for i, digit in enumerate(num1_str[::-1]):
partial_product = int(digit) * num2 * (10 ** i)
partial_sums.append(partial_product)
alternative_text = random.choice(alternative_texts)
explanation += f"+ {num2} × {digit}{'0' * i} {alternative_text} {partial_product}\n"
result = sum(partial_sums)
explanation += f"\n= {result}\n"
problems.append(explanation)
return problems
def multiplication_step_by_step_short2(number_of_samples):
templates = [
"Let's calculate {num1} x {num2}",
"We're going to solve {num1} multiplied by {num2}",
"Alright, let's work through {num1} times {num2} step by step",
"No problem, we've got {num1} and {num2} to multiply",
"Sure thing! Let's multiply {num1} and {num2} together"
]
alternative_texts = [
"that equals",
"which equals",
"that is equal",
"what gives us",
"that results in",
"yielding",
"giving us",
"producing",
"resulting in"
]
problems = []
for _ in range(number_of_samples):
num1 = random.randint(0, 100000000)
num2 = random.randint(0, 100000000)
num1_str = str(num1)
num2_str = str(num2)
template = random.choice(templates)
explanation = template.format(num1=num1, num2=num2) + "\n"
explanation += f"{num1} × {num2} = {num2} × ({num1_str})\n"
partial_sums = []
for i, digit in enumerate(num1_str[::-1]):
partial_product = int(digit) * num2 * (10 ** i)
partial_sums.append(partial_product)
alternative_text = random.choice(alternative_texts)
explanation += f"+ {num2} × {digit}{'0' * i} {alternative_text} {partial_product}\n"
result = sum(partial_sums)
explanation += f"\n= {result}\n"
problems.append(explanation)
return problems
import random
def division_step_by_step1(number_of_samples):
templates = [
"Let's divide {dividend} by {divisor}.",
"We're going to perform division on {dividend} with {divisor} as the divisor.",
"Alright, let's work through the division of {dividend} by {divisor} step by step.",
"No problem, we've got {dividend} and {divisor} for the division.",
"Sure thing! Let's divide {dividend} by {divisor} together."
]
def long_division(dividend, divisor):
quotient = dividend // divisor
remainder = dividend % divisor
return quotient, remainder
#explanation += template.format(dividend=dividend, divisor=divisor) + "\n"
explanations = []
def step_by_step_solution(dividend, divisor):
quotient, remainder = long_division(dividend, divisor)
result = str(quotient) + " R" + str(remainder)
solution = f"{dividend} ÷ {divisor} = {result}\n"
#solution += f"We want to divide {dividend} by {divisor}.\n"
template =random.choice(templates)
solution += template.format(dividend=dividend, divisor=divisor) + "\n"
temp_dividend = str(dividend)
temp_result = ""
current_remainder = 0
result=""
for i, digit in enumerate(temp_dividend):
current_remainder = current_remainder * 10 + int(digit)
current_quotient, current_remainder = long_division(current_remainder, divisor)
temp_result += str(current_quotient)
if i ==0:
prev_remainder = temp_dividend[i:i + 1]
solution += f"\nStep {i + 1}:\n"
solution += f"{divisor} goes into {prev_remainder} {current_quotient} times with a remainder of {current_remainder}.\n"
solution += f"Write down {current_quotient} as next digit of of the result. \n"
result+=str(current_quotient)
result=str(int(result))
solution += f"Result so far: {result}\n"
solution += f"Subtract {current_quotient * divisor} from {current_remainder + current_quotient * divisor} to get {current_remainder}.\n"
if str(temp_dividend[i + 1:i + 2])=="":
break
prev_remainder= int(str(current_remainder) +str(temp_dividend[i + 1:i + 2]))
solution += f"Bring next digit ({temp_dividend[i + 1:i + 2]}) of the dividend behind the {current_remainder} and repeat the process: {prev_remainder} / {divisor}\n"
solution += f"\nThe final result is {result} with a remainder of {current_remainder}."
return solution
for i in range(number_of_samples):
dividend = random.randint(10, 99999)
divisor = random.randint(1, 9)
solution = step_by_step_solution(dividend, divisor)
explanations.append(solution)
return explanations
def division_step_by_step2(number_of_samples):
def long_division(dividend, divisor):
quotient = dividend // divisor
remainder = dividend % divisor
return quotient, remainder
def step_by_step_solution(dividend, divisor):
quotient, remainder = long_division(dividend, divisor)
result = str(quotient) + " R" + str(remainder)
templates = {
"introduction": [
"{dividend} ÷ {divisor} \n",
"We're dividing {dividend} by {divisor} \n",
"{dividend} divided by {divisor} \n",
"We look at the division of {dividend} by {divisor} \n",
"We divide {dividend} by {divisor}\n",
"Let's divide {dividend} by {divisor}\n"
],
"divide_statement": [
"We want to divide {dividend} by {divisor}.\n",
"Our goal is to divide {dividend} by {divisor}.\n",
"We're looking to find how many times {divisor} goes into {dividend}.\n",
"Let's see how many times {divisor} fits into {dividend}.\n",
"The aim is to understand the frequency of {divisor} in {dividend}.\n",
"We want to figure out the number of times {dividend} can be divided by {divisor}.\n"
],
"step": [
"\nStep {step_number}:\n",
"\nMoving on to step {step_number}:\n",
"\nLet's proceed to step {step_number}:\n",
"\nGoing ahead to step {step_number}:\n",
"\nAdvancing to step {step_number}:\n",
"\nOn to step {step_number}:\n"
],
"division_process": [
"{divisor} goes into {prev_remainder} {current_quotient} times with a remainder of {current_remainder}.\n",
"When dividing {prev_remainder} by {divisor}, we get {current_quotient} with a remainder of {current_remainder}.\n",
"The number {divisor} fits into {prev_remainder} {current_quotient} times, leaving a remainder of {current_remainder}.\n",
"{divisor} can be fit into {prev_remainder} {current_quotient} times, resulting in a remainder of {current_remainder}.\n",
"{prev_remainder} divided by {divisor} is {current_quotient} with a remainder of {current_remainder}.\n",
"If we divide {prev_remainder} by {divisor}, we get {current_quotient} and a remainder of {current_remainder}.\n"
],
"write_quotient": [
"Write down {current_quotient} as next digit of the result. \n",
"Record the quotient {current_quotient} as the next digit in the result. \n",
"The number {current_quotient} becomes the next digit in our result. \n",
"Put {current_quotient} as the next digit of the answer. \n",
"Use {current_quotient} as the next digit of our solution. \n",
"The next digit of our result is {current_quotient}. \n"
],
"subtraction": [
"Subtract {product} from {sum} to get {remainder}.\n",
"If we take {product} away from {sum}, we end up with {remainder}.\n",
"Deduct {product} from {sum} and we're left with {remainder}.\n",
"Subtracting {product} from {sum} leaves us with {remainder}.\n",
"If we subtract {product} from {sum}, we get {remainder}.\n",
"The remainder is {remainder} after subtracting {product} from {sum}.\n"
],
"next_digit": [
"Bring next digit ({next_digit}) of the dividend behind the {current_remainder} and repeat the process: {prev_remainder} / {divisor}\n",
"Take the next digit ({next_digit}) from the dividend and append it to {current_remainder}, then repeat: {prev_remainder} / {divisor}\n",
"Fetch the next digit ({next_digit}) from the dividend, attach it to {current_remainder} and continue: {prev_remainder} / {divisor}\n",
"Grab the next digit ({next_digit}) from the dividend, add it to {current_remainder}, then carry on: {prev_remainder} / {divisor}\n",
"Include the next digit ({next_digit}) from the dividend after {current_remainder}, then repeat: {prev_remainder} / {divisor}\n",
"Append the next digit ({next_digit}) from the dividend to {current_remainder} and continue with: {prev_remainder} / {divisor}\n"
],
"final_result": [
"\nThe final result is {result} with a remainder of {remainder}.",
"\nOur division results in {result} with a remaining {remainder}.",
"\nThe final outcome is {result}, with a leftover of {remainder}.",
"\nIn conclusion, the division gives {result} with a balance of {remainder}.",
"\nAfter the division, we end up with {result} and a remainder of {remainder}.",
"\nThe quotient of the division is {result}, and the remainder is {remainder}."
]
}
solution = random.choice(templates['introduction']).format(dividend=dividend, divisor=divisor)
solution += random.choice(templates['divide_statement']).format(dividend=dividend, divisor=divisor)
temp_dividend = str(dividend)
temp_result = ""
current_remainder = 0
result = ""
first_decimal=True
i = 0
while len(result.split('.')[1] if '.' in result else result) < 8:
current_remainder = current_remainder * 10 + int(temp_dividend[i]) if i < len(temp_dividend) else current_remainder * 10
current_quotient, current_remainder = long_division(current_remainder, divisor)
temp_result += str(current_quotient)
if i == 0:
prev_remainder = temp_dividend[i:i + 1]
solution += random.choice(templates['step']).format(step_number=i+1)
solution += random.choice(templates['division_process']).format(divisor=divisor, prev_remainder=prev_remainder, current_quotient=current_quotient, current_remainder=current_remainder)
result += str(current_quotient)
if i >= len(temp_dividend) - 1 and '.' not in result:
result += '.'