-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathafm7_prompt_series_results.html
More file actions
1445 lines (1236 loc) · 56.4 KB
/
afm7_prompt_series_results.html
File metadata and controls
1445 lines (1236 loc) · 56.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AFM7 MLX Prompt Series Results</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
<style>
:root {
--bg-primary: #0d1117;
--bg-secondary: #161b22;
--bg-tertiary: #21262d;
--text-primary: #c9d1d9;
--text-secondary: #8b949e;
--accent: #58a6ff;
--accent-green: #3fb950;
--accent-purple: #a371f7;
--border-color: #30363d;
}
* {
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
background-color: var(--bg-primary);
color: var(--text-primary);
line-height: 1.6;
margin: 0;
padding: 0;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 40px 20px;
}
header {
text-align: center;
margin-bottom: 60px;
padding-bottom: 40px;
border-bottom: 1px solid var(--border-color);
}
h1 {
font-size: 2.5em;
margin-bottom: 10px;
background: linear-gradient(135deg, var(--accent) 0%, var(--accent-purple) 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.subtitle {
color: var(--text-secondary);
font-size: 1.2em;
}
.meta-info {
display: flex;
justify-content: center;
gap: 30px;
margin-top: 20px;
flex-wrap: wrap;
}
.meta-item {
background: var(--bg-secondary);
padding: 10px 20px;
border-radius: 8px;
border: 1px solid var(--border-color);
}
.meta-item strong {
color: var(--accent);
}
.toc {
background: var(--bg-secondary);
border-radius: 12px;
padding: 30px;
margin-bottom: 40px;
border: 1px solid var(--border-color);
}
.toc h2 {
margin-top: 0;
color: var(--accent);
}
.toc-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 10px;
}
.toc a {
color: var(--text-primary);
text-decoration: none;
padding: 8px 12px;
border-radius: 6px;
display: block;
transition: background 0.2s;
}
.toc a:hover {
background: var(--bg-tertiary);
color: var(--accent);
}
.toc-number {
color: var(--accent);
font-weight: bold;
margin-right: 8px;
}
.prompt-section {
background: var(--bg-secondary);
border-radius: 12px;
margin-bottom: 30px;
overflow: hidden;
border: 1px solid var(--border-color);
}
.prompt-header {
background: var(--bg-tertiary);
padding: 20px 25px;
border-bottom: 1px solid var(--border-color);
}
.prompt-number {
display: inline-block;
background: var(--accent);
color: var(--bg-primary);
padding: 4px 12px;
border-radius: 20px;
font-weight: bold;
font-size: 0.85em;
margin-right: 10px;
}
.prompt-title {
font-size: 1.3em;
margin: 10px 0 0 0;
color: var(--text-primary);
}
.prompt-text {
background: var(--bg-primary);
padding: 15px 25px;
border-left: 4px solid var(--accent);
margin: 0;
font-style: italic;
color: var(--text-secondary);
}
.response-content {
padding: 25px;
}
.response-content h3 {
color: var(--accent);
border-bottom: 1px solid var(--border-color);
padding-bottom: 10px;
margin-top: 25px;
}
.response-content h3:first-child {
margin-top: 0;
}
.response-content h4 {
color: var(--accent-purple);
margin-top: 20px;
}
.response-content ul, .response-content ol {
padding-left: 25px;
}
.response-content li {
margin-bottom: 8px;
}
pre {
background: var(--bg-primary) !important;
border: 1px solid var(--border-color);
border-radius: 8px;
padding: 15px !important;
overflow-x: auto;
margin: 15px 0;
}
code {
font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
font-size: 0.9em;
}
p code {
background: var(--bg-tertiary);
padding: 2px 6px;
border-radius: 4px;
}
.math-block {
overflow-x: auto;
padding: 10px 0;
}
blockquote {
border-left: 4px solid var(--accent-purple);
margin: 15px 0;
padding: 10px 20px;
background: var(--bg-tertiary);
border-radius: 0 8px 8px 0;
}
table {
width: 100%;
border-collapse: collapse;
margin: 15px 0;
}
th, td {
border: 1px solid var(--border-color);
padding: 12px;
text-align: left;
}
th {
background: var(--bg-tertiary);
color: var(--accent);
}
.category-badge {
display: inline-block;
padding: 4px 10px;
border-radius: 15px;
font-size: 0.75em;
margin-left: 10px;
font-weight: normal;
}
.cat-math { background: #1f6feb33; color: #58a6ff; }
.cat-code { background: #3fb95033; color: #3fb950; }
.cat-physics { background: #a371f733; color: #a371f7; }
.cat-devops { background: #f8514933; color: #f85149; }
.cat-ml { background: #db61a233; color: #db61a2; }
.cat-creative { background: #f0883e33; color: #f0883e; }
footer {
text-align: center;
padding: 40px;
color: var(--text-secondary);
border-top: 1px solid var(--border-color);
margin-top: 40px;
}
@media (max-width: 768px) {
h1 { font-size: 1.8em; }
.toc-grid { grid-template-columns: 1fr; }
.meta-info { flex-direction: column; align-items: center; }
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>AFM7 MLX Prompt Series Results</h1>
<p class="subtitle">Apple Foundation Model (AFMTextV7) running on MLX with extended context</p>
<div class="meta-info">
<div class="meta-item"><strong>Model:</strong> AFM7 (6B parameters)</div>
<div class="meta-item"><strong>Framework:</strong> MLX (Apple Silicon)</div>
<div class="meta-item"><strong>Prompts:</strong> 19 diverse topics</div>
<div class="meta-item"><strong>Date:</strong> January 2026</div>
</div>
</header>
<nav class="toc">
<h2>Table of Contents</h2>
<div class="toc-grid">
<a href="#prompt-1"><span class="toc-number">1.</span> Fourier Transform</a>
<a href="#prompt-2"><span class="toc-number">2.</span> Programming Poem</a>
<a href="#prompt-3"><span class="toc-number">3.</span> Pythagorean Theorem</a>
<a href="#prompt-4"><span class="toc-number">4.</span> Swift Factorial</a>
<a href="#prompt-5"><span class="toc-number">5.</span> Binary Search (6 Languages)</a>
<a href="#prompt-6"><span class="toc-number">6.</span> Physics Equations</a>
<a href="#prompt-7"><span class="toc-number">7.</span> Neural Networks Math</a>
<a href="#prompt-8"><span class="toc-number">8.</span> Differential Equations</a>
<a href="#prompt-9"><span class="toc-number">9.</span> TypeScript REST API</a>
<a href="#prompt-10"><span class="toc-number">10.</span> Cryptography (RSA/ECC)</a>
<a href="#prompt-11"><span class="toc-number">11.</span> Systems Programming</a>
<a href="#prompt-12"><span class="toc-number">12.</span> Advanced SQL</a>
<a href="#prompt-13"><span class="toc-number">13.</span> Functional Programming</a>
<a href="#prompt-14"><span class="toc-number">14.</span> Calculus (Limits to Multivariable)</a>
<a href="#prompt-15"><span class="toc-number">15.</span> Linear Algebra</a>
<a href="#prompt-16"><span class="toc-number">16.</span> DevOps (Docker/K8s/CI-CD)</a>
<a href="#prompt-17"><span class="toc-number">17.</span> Chemistry Concepts</a>
<a href="#prompt-18"><span class="toc-number">18.</span> Tetris Game</a>
<a href="#prompt-19"><span class="toc-number">19.</span> Jacobian Calculus</a>
</div>
</nav>
<!-- Prompt 1: Fourier Transform -->
<section id="prompt-1" class="prompt-section">
<div class="prompt-header">
<span class="prompt-number">1</span>
<span class="category-badge cat-math">Mathematics</span>
<h2 class="prompt-title">Fourier Transform</h2>
</div>
<p class="prompt-text">"Explain the Fourier Transform and its discrete version."</p>
<div class="response-content">
<p>The Fourier Transform is a mathematical tool used to convert a function from the time domain to the frequency domain. It decomposes a signal into its constituent frequencies, allowing for easier analysis and manipulation.</p>
<h3>Continuous Fourier Transform (CFT)</h3>
<p>The Continuous Fourier Transform is used for continuous-time signals. It transforms a function \( f(t) \) from the time domain to the frequency domain, resulting in a complex function \( F(\omega) \). The formula for the CFT is:</p>
<div class="math-block">
\[
F(\omega) = \int_{-\infty}^{\infty} f(t) e^{-j\omega t} \, dt
\]
</div>
<p>where:</p>
<ul>
<li>\( \omega \) is the angular frequency, typically measured in radians per second.</li>
<li>\( j \) is the imaginary unit, satisfying \( j^2 = -1 \).</li>
<li>\( e^{-j\omega t} \) is the complex exponential function.</li>
</ul>
<h3>Discrete Fourier Transform (DFT)</h3>
<p>The Discrete Fourier Transform is used for discrete-time signals. It transforms a sequence of samples \( x[n] \) from the time domain to the frequency domain, resulting in a sequence of complex numbers \( X[k] \). The formula for the DFT is:</p>
<div class="math-block">
\[
X[k] = \sum_{n=0}^{N-1} x[n] e^{-j\frac{2\pi}{N} kn}
\]
</div>
<p>where:</p>
<ul>
<li>\( N \) is the number of samples.</li>
<li>\( k \) is the frequency index, typically ranging from 0 to \( N-1 \).</li>
<li>\( e^{-j\frac{2\pi}{N} kn} \) is the complex exponential function.</li>
</ul>
<h3>Key Differences</h3>
<ol>
<li><strong>Domain:</strong> CFT is used for continuous-time signals. DFT is used for discrete-time signals.</li>
<li><strong>Complexity:</strong> CFT involves an infinite integral, making it computationally intensive for large signals. DFT involves a finite sum, making it computationally efficient for discrete signals.</li>
<li><strong>Applications:</strong> CFT is used in signal processing for analyzing continuous signals, such as audio and video. DFT is used in digital signal processing for analyzing discrete signals, such as digital audio and image processing.</li>
</ol>
</div>
</section>
<!-- Prompt 2: Programming Poem -->
<section id="prompt-2" class="prompt-section">
<div class="prompt-header">
<span class="prompt-number">2</span>
<span class="category-badge cat-creative">Creative</span>
<h2 class="prompt-title">Programming Poem</h2>
</div>
<p class="prompt-text">"Give me a short poem about programming."</p>
<div class="response-content">
<blockquote style="font-style: italic; font-size: 1.1em; line-height: 1.8;">
In lines of code, a world unfolds,<br>
Where logic dances, stories told.<br>
A symphony of bits and bytes,<br>
Crafting dreams beneath the skies.<br><br>
Algorithms weave their thread,<br>
In binary whispers, secrets fed.<br>
A tapestry of zeros and ones,<br>
Where logic reigns and logic wins.<br><br>
In every line, a thought takes flight,<br>
A spark of genius, pure delight.<br>
Programming, a journey vast,<br>
Where creativity and logic last.
</blockquote>
</div>
</section>
<!-- Prompt 3: Pythagorean Theorem -->
<section id="prompt-3" class="prompt-section">
<div class="prompt-header">
<span class="prompt-number">3</span>
<span class="category-badge cat-math">Mathematics</span>
<h2 class="prompt-title">Pythagorean Theorem</h2>
</div>
<p class="prompt-text">"Show me the Pythagorean theorem using backslash bracket notation."</p>
<div class="response-content">
<p>The Pythagorean theorem can be expressed using backslash bracket notation as follows:</p>
<div class="math-block">
\[
a^2 + b^2 = c^2
\]
</div>
<p>Here, \(a\) and \(b\) are the lengths of the two legs of a right triangle, and \(c\) is the length of the hypotenuse.</p>
</div>
</section>
<!-- Prompt 4: Swift Factorial -->
<section id="prompt-4" class="prompt-section">
<div class="prompt-header">
<span class="prompt-number">4</span>
<span class="category-badge cat-code">Code</span>
<h2 class="prompt-title">Swift Factorial Functions</h2>
</div>
<p class="prompt-text">"Write a Swift function to calculate factorial using recursion and iteration."</p>
<div class="response-content">
<p>Here are two Swift functions to calculate factorial using recursion and iteration:</p>
<pre><code class="language-swift">/// Calculates the factorial of a non-negative integer using recursion.
/// - Parameter n: The non-negative integer for which to calculate the factorial.
/// - Returns: The factorial of the given integer.
func factorialRecursive(_ n: Int) -> Int {
// Base case: factorial of 0 or 1 is 1
guard n >= 0 else {
fatalError("Factorial is not defined for negative numbers.")
}
if n == 0 || n == 1 {
return 1
}
// Recursive case: n! = n * (n-1)!
return n * factorialRecursive(n - 1)
}
/// Calculates the factorial of a non-negative integer using iteration.
/// - Parameter n: The non-negative integer for which to calculate the factorial.
/// - Returns: The factorial of the given integer.
func factorialIterative(_ n: Int) -> Int {
// Base case: factorial of 0 or 1 is 1
guard n >= 0 else {
fatalError("Factorial is not defined for negative numbers.")
}
if n == 0 || n == 1 {
return 1
}
// Iterative case: factorial = 1 * 2 * 3 * ... * n
var result = 1
for i in 2...n {
result *= i
}
return result
}
// Example usage:
let n = 5
print("Factorial of \(n) using recursion: \(factorialRecursive(n))")
print("Factorial of \(n) using iteration: \(factorialIterative(n))")</code></pre>
<h4>Explanation:</h4>
<ul>
<li><strong>Factorial Recursive Function:</strong> Uses recursion to calculate the factorial. Checks if the input is 0 or 1, returning 1 (base case). For other values, calls itself with n-1 and multiplies by n.</li>
<li><strong>Factorial Iterative Function:</strong> Uses iteration to calculate the factorial. Starts with result of 1 and iteratively multiplies by each integer from 2 to n.</li>
</ul>
</div>
</section>
<!-- Prompt 5: Binary Search -->
<section id="prompt-5" class="prompt-section">
<div class="prompt-header">
<span class="prompt-number">5</span>
<span class="category-badge cat-code">Code</span>
<h2 class="prompt-title">Binary Search in 6 Languages</h2>
</div>
<p class="prompt-text">"Show me examples of the same algorithm (binary search) implemented in Python, JavaScript, Rust, Go, C++, and Java."</p>
<div class="response-content">
<p>Binary search is a classic algorithm used to find an item from a sorted array. Below are examples in six different languages:</p>
<h3>Python</h3>
<pre><code class="language-python">def binary_search(arr, target):
left, right = 0, len(arr) - 1
while left <= right:
mid = (left + right) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
left = mid + 1
else:
right = mid - 1
return -1
# Example usage
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
target = 5
print(binary_search(arr, target)) # Output: 4</code></pre>
<h3>JavaScript</h3>
<pre><code class="language-javascript">function binarySearch(arr, target) {
let left = 0;
let right = arr.length - 1;
while (left <= right) {
const mid = Math.floor((left + right) / 2);
if (arr[mid] === target) {
return mid;
} else if (arr[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return -1;
}
// Example usage
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const target = 5;
console.log(binarySearch(arr, target)); // Output: 4</code></pre>
<h3>Rust</h3>
<pre><code class="language-rust">fn binary_search(arr: &mut Vec<i32>, target: i32) -> usize {
let mut left = 0;
let mut right = arr.len() - 1;
while left <= right {
let mid = left + (right - left) / 2;
if arr[mid] == target {
return mid;
} else if arr[mid] < target {
left = mid + 1;
} else {
right = mid - 1;
}
}
return -1;
}
fn main() {
let mut arr = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let target = 5;
let index = binary_search(&mut arr, target);
println!("Index: {}", index); // Output: Index: 4
}</code></pre>
<h3>Go</h3>
<pre><code class="language-go">package main
import (
"fmt"
"sort"
)
func binarySearch(arr []int, target int) int {
sort.Ints(arr)
left, right := 0, len(arr)-1
for left <= right {
mid := left + (right-left) / 2
if arr[mid] == target {
return mid
} else if arr[mid] < target {
left = mid + 1
} else {
right = mid - 1
}
}
return -1
}
func main() {
arr := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
target := 5
index := binarySearch(arr, target)
fmt.Println("Index:", index) // Output: Index: 4
}</code></pre>
<h3>C++</h3>
<pre><code class="language-cpp">#include <iostream>
#include <vector>
#include <algorithm>
int binarySearch(std::vector<int>& arr, int target) {
int left = 0;
int right = arr.size() - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (arr[mid] == target) {
return mid;
} else if (arr[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return -1;
}
int main() {
std::vector<int> arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int target = 5;
int index = binarySearch(arr, target);
std::cout << "Index: " << index << std::endl; // Output: Index: 4
return 0;
}</code></pre>
<h3>Java</h3>
<pre><code class="language-java">import java.util.Arrays;
public class BinarySearch {
public static int binarySearch(int[] arr, int target) {
int left = 0;
int right = arr.length - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (arr[mid] == target) {
return mid;
} else if (arr[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return -1;
}
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int target = 5;
int index = binarySearch(arr, target);
System.out.println("Index: " + index); // Output: Index: 4
}
}</code></pre>
<p>Each implementation uses a similar approach to binary search, leveraging the sorted nature of the input array to efficiently locate the target value.</p>
</div>
</section>
<!-- Prompt 6: Physics Equations -->
<section id="prompt-6" class="prompt-section">
<div class="prompt-header">
<span class="prompt-number">6</span>
<span class="category-badge cat-physics">Physics</span>
<h2 class="prompt-title">Physics Equations</h2>
</div>
<p class="prompt-text">"Explain the key equations of classical mechanics, electromagnetism, and quantum mechanics with their mathematical formulations."</p>
<div class="response-content">
<h3>Classical Mechanics</h3>
<h4>1. Newton's Laws of Motion</h4>
<p><strong>First Law (Law of Inertia):</strong> An object at rest stays at rest, and an object in motion stays in motion at a constant velocity unless acted upon by a net external force.</p>
<div class="math-block">\[ \vec{F} = m \vec{a} \]</div>
<p><strong>Third Law:</strong> For every action, there is an equal and opposite reaction.</p>
<div class="math-block">\[ \vec{F}_{AB} = -\vec{F}_{BA} \]</div>
<h4>2. Conservation Laws</h4>
<p><strong>Conservation of Momentum:</strong></p>
<div class="math-block">\[ \vec{p}_{\text{total}} = \vec{p}_1 + \vec{p}_2 + \cdots = \text{constant} \]</div>
<p><strong>Conservation of Energy:</strong></p>
<div class="math-block">\[ E_{\text{total}} = KE + PE + \text{other forms of energy} = \text{constant} \]</div>
<h3>Electromagnetism</h3>
<h4>Maxwell's Equations</h4>
<p><strong>Gauss's Law for Electricity:</strong></p>
<div class="math-block">\[ \oint \vec{E} \cdot d\vec{A} = \frac{Q_{\text{enc}}}{\varepsilon_0} \]</div>
<p><strong>Gauss's Law for Magnetism:</strong></p>
<div class="math-block">\[ \oint \vec{B} \cdot d\vec{A} = 0 \]</div>
<p><strong>Faraday's Law of Induction:</strong></p>
<div class="math-block">\[ \oint \vec{E} \cdot d\vec{l} = -\frac{d\Phi_B}{dt} \]</div>
<p><strong>Ampère-Maxwell Law:</strong></p>
<div class="math-block">\[ \oint \vec{B} \cdot d\vec{l} = \mu_0 \left( I + \frac{\partial \vec{E}}{\partial t} \right) \]</div>
<p><strong>Coulomb's Law:</strong></p>
<div class="math-block">\[ F = k \frac{|q_1 q_2|}{r^2} \]</div>
<h3>Quantum Mechanics</h3>
<h4>1. Schrödinger Equation</h4>
<div class="math-block">\[ i\hbar \frac{\partial \psi}{\partial t} = \hat{H} \psi \]</div>
<h4>2. Heisenberg Uncertainty Principle</h4>
<div class="math-block">\[ \Delta x \Delta p \geq \frac{\hbar}{2} \]</div>
<h4>3. Quantum Numbers</h4>
<ul>
<li><strong>Principal Quantum Number (n):</strong> \( n = 1, 2, 3, \ldots \)</li>
<li><strong>Angular Momentum Quantum Number (l):</strong> \( l = 0, 1, 2, \ldots, n-1 \)</li>
<li><strong>Magnetic Quantum Number (m_l):</strong> \( m_l = -l, -l+1, \ldots, 0, \ldots, l-1, l \)</li>
<li><strong>Spin Quantum Number (m_s):</strong> \( m_s = +\frac{1}{2}, -\frac{1}{2} \)</li>
</ul>
</div>
</section>
<!-- Prompt 7: Neural Networks Math -->
<section id="prompt-7" class="prompt-section">
<div class="prompt-header">
<span class="prompt-number">7</span>
<span class="category-badge cat-ml">ML/AI</span>
<h2 class="prompt-title">Neural Networks Mathematics</h2>
</div>
<p class="prompt-text">"Explain the mathematical foundations of neural networks, including backpropagation, loss functions, and optimization algorithms."</p>
<div class="response-content">
<h3>1. Layers and Neurons</h3>
<ul>
<li><strong>Input Layer:</strong> The first layer where input data is fed into the network.</li>
<li><strong>Hidden Layers:</strong> Intermediate layers where neurons process the input data.</li>
<li><strong>Output Layer:</strong> The last layer where the network produces an output.</li>
</ul>
<h3>2. Activation Functions</h3>
<p>Activation functions introduce non-linearity into the neural network:</p>
<ul>
<li><strong>Sigmoid Function:</strong> \( \sigma(x) = \frac{1}{1 + e^{-x}} \)</li>
<li><strong>ReLU:</strong> \( \text{ReLU}(x) = \max(0, x) \)</li>
<li><strong>Tanh Function:</strong> \( \tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}} \)</li>
</ul>
<h3>3. Loss Functions</h3>
<ul>
<li><strong>Mean Squared Error (MSE):</strong> \( \text{MSE}(y, \hat{y}) = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 \)</li>
<li><strong>Cross-Entropy Loss:</strong> \( \text{CE}(y, \hat{y}) = -\sum_{i=1}^{n} y_i \log(\hat{y}_i) \)</li>
<li><strong>Binary Cross-Entropy Loss:</strong> \( \text{BCE}(y, \hat{y}) = -\sum_{i=1}^{n} y_i \log(\hat{y}_i) + (1-y_i) \log(1-\hat{y}_i) \)</li>
</ul>
<h3>4. Backpropagation</h3>
<p>The algorithm used to update the weights of the neural network based on the loss function:</p>
<ol>
<li><strong>Forward Propagation:</strong> Compute the output by passing input data through each layer.</li>
<li><strong>Calculate Error:</strong> Compute the error between predicted and actual output using the loss function.</li>
<li><strong>Backward Propagation:</strong> Propagate the error backward, calculating gradients using the chain rule.</li>
<li><strong>Weight Update:</strong> Update weights using an optimization algorithm.</li>
</ol>
<h3>5. Optimization Algorithms</h3>
<ul>
<li><strong>Gradient Descent:</strong> Updates weights by moving in the direction of the negative gradient.</li>
<li><strong>Stochastic Gradient Descent (SGD):</strong> Uses a random subset of training data for faster convergence.</li>
<li><strong>Adam:</strong> Adaptive learning rate optimization that adjusts the rate for each parameter.</li>
<li><strong>RMSprop:</strong> Uses a moving average of squared gradients for adaptive learning rates.</li>
</ul>
</div>
</section>
<!-- Prompt 8: Differential Equations -->
<section id="prompt-8" class="prompt-section">
<div class="prompt-header">
<span class="prompt-number">8</span>
<span class="category-badge cat-math">Mathematics</span>
<h2 class="prompt-title">Numerical Methods for Differential Equations</h2>
</div>
<p class="prompt-text">"Implement numerical methods for solving differential equations with mathematical explanations."</p>
<div class="response-content">
<h3>1. Euler's Method</h3>
<p>A simple numerical technique for approximating solutions to ODEs based on the tangent line slope.</p>
<p><strong>Formula:</strong> For \( \frac{dy}{dx} = f(x, y) \):</p>
<div class="math-block">\[ y_{n+1} = y_n + h \cdot f(x_n, y_n) \]</div>
<p>where \( h \) is the step size.</p>
<h3>2. Runge-Kutta Methods (RK4)</h3>
<p>Provides more accurate approximations by averaging slopes:</p>
<div class="math-block">
\[ k_1 = h \cdot f(x_n, y_n) \]
\[ k_2 = h \cdot f(x_n + \frac{h}{2}, y_n + \frac{k_1}{2}) \]
\[ k_3 = h \cdot f(x_n + \frac{h}{2}, y_n + \frac{k_2}{2}) \]
\[ k_4 = h \cdot f(x_n + h, y_n + k_3) \]
\[ y_{n+1} = y_n + \frac{1}{6}(k_1 + 2k_2 + 2k_3 + k_4) \]
</div>
<h3>3. Finite Difference Methods</h3>
<p>Used to approximate solutions by discretizing the continuous domain into a grid:</p>
<div class="math-block">\[ u_{i,j}^{n+1} = u_{i,j}^n + \Delta t \cdot f(i, j, u_{i,j}^n) \]</div>
<h3>4. Stability Analysis</h3>
<ul>
<li><strong>Local Stability:</strong> Numerical solution remains bounded near the initial condition.</li>
<li><strong>Global Stability:</strong> Numerical solution converges to the exact solution as \( h \to 0 \).</li>
</ul>
</div>
</section>
<!-- Prompt 9: TypeScript REST API -->
<section id="prompt-9" class="prompt-section">
<div class="prompt-header">
<span class="prompt-number">9</span>
<span class="category-badge cat-code">Code</span>
<h2 class="prompt-title">TypeScript REST API</h2>
</div>
<p class="prompt-text">"Create a complete REST API with TypeScript, including database models, controllers, middleware, and tests."</p>
<div class="response-content">
<h3>Database Model</h3>
<pre><code class="language-typescript">// models/product.ts
import mongoose from 'mongoose';
const ProductSchema = new mongoose.Schema({
name: String,
price: Number,
quantity: Number,
});
const Product = mongoose.model('Product', ProductSchema);
export default Product;</code></pre>
<h3>Controller</h3>
<pre><code class="language-typescript">// controllers/product.ts
import express from 'express';
import Product from '../models/product';
const router = express.Router();
router.get('/', async (req, res) => {
try {
const products = await Product.find();
res.json(products);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
router.post('/', async (req, res) => {
try {
const product = new Product({
name: req.body.name,
price: req.body.price,
quantity: req.body.quantity,
});
await product.save();
res.json(product);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
router.put('/:id', async (req, res) => {
try {
const product = await Product.findByIdAndUpdate(req.params.id, req.body, { new: true });
if (!product) {
res.status(404).json({ error: 'Product not found' });
}
res.json(product);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
router.delete('/:id', async (req, res) => {
try {
await Product.findByIdAndDelete(req.params.id);
res.json({ message: 'Product deleted' });
} catch (error) {
res.status(500).json({ error: error.message });
}
});
export default router;</code></pre>
<h3>Tests</h3>
<pre><code class="language-typescript">// tests/product.test.ts
import chai from 'chai';
import chaiHttp from 'chai-http';
import app from '../app';
import Product from '../models/product';
const expect = chai.expect;
const request = chaiHttp.request(app);
describe('Product API', () => {
beforeEach(async () => {
await Product.deleteMany();
});
it('should get all products', async () => {
const response = await request.get('/products');
expect(response.status).to.equal(200);
expect(response.body).to.be.an('array');
});
it('should create a new product', async () => {
const response = await request.post('/products', {
name: 'Test Product',
price: 10.0,
quantity: 10,
});
expect(response.status).to.equal(201);
expect(response.body).to.be.an('object');
});
});</code></pre>
</div>
</section>
<!-- Prompt 10: Cryptography -->
<section id="prompt-10" class="prompt-section">
<div class="prompt-header">
<span class="prompt-number">10</span>
<span class="category-badge cat-math">Cryptography</span>
<h2 class="prompt-title">RSA, ECC, and Secure Hashing</h2>
</div>
<p class="prompt-text">"Explain the mathematics behind RSA encryption, elliptic curve cryptography, and implement secure hashing."</p>
<div class="response-content">
<h3>RSA Encryption</h3>
<p>RSA is based on the mathematical difficulty of factoring large composite numbers.</p>
<h4>Key Generation</h4>
<ol>
<li>Choose two large prime numbers, \( p \) and \( q \).</li>
<li>Compute \( n = p \times q \).</li>
<li>Compute \( \phi(n) = (p-1) \times (q-1) \).</li>
<li>Choose an integer \( e \) such that \( 1 < e < \phi(n) \) and \( e \) is coprime to \( \phi(n) \).</li>
<li>Compute \( d \) as the modular multiplicative inverse of \( e \) modulo \( \phi(n) \).</li>
</ol>
<h4>Encryption/Decryption</h4>
<div class="math-block">
\[ c = m^e \pmod{n} \quad \text{(Encryption)} \]
\[ m = c^d \pmod{n} \quad \text{(Decryption)} \]
</div>
<h3>Elliptic Curve Cryptography (ECC)</h3>
<p>ECC uses the algebraic structure of elliptic curves over finite fields, known for efficiency and security with smaller key sizes.</p>
<h3>Secure Hashing</h3>
<p>Produces a fixed-size string from an input, designed to be one-way and collision-resistant.</p>
<h4>Properties:</h4>
<ul>
<li><strong>Deterministic:</strong> Same input always produces the same hash.</li>
<li><strong>One-way:</strong> Computationally infeasible to reverse.</li>
<li><strong>Collision-resistant:</strong> Hard to find two different inputs with the same hash.</li>
</ul>
<h4>Implementation Example</h4>
<pre><code class="language-python">import hashlib
def sha256(message):
return hashlib.sha256(message.encode()).hexdigest()
# Example usage
message = "Hello, World!"
hash_value = sha256(message)
print(f"Hash of '{message}': {hash_value}")</code></pre>
</div>
</section>
<!-- Prompt 11: Systems Programming -->
<section id="prompt-11" class="prompt-section">
<div class="prompt-header">
<span class="prompt-number">11</span>
<span class="category-badge cat-code">Systems</span>
<h2 class="prompt-title">Low-Level Systems Programming</h2>
</div>
<p class="prompt-text">"Show examples of low-level systems programming in C, Rust, and assembly including memory management, concurrency, and syscalls."</p>
<div class="response-content">
<h3>C - Memory Management</h3>
<pre><code class="language-c">#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void allocateMemory(void **ptr, size_t size) {
if (*ptr == NULL) {
*ptr = (void *)malloc(size);
if (*ptr == NULL) {
perror("Memory allocation failed");
exit(EXIT_FAILURE);
}
}
}
void freeMemory(void *ptr) {
if (ptr != NULL) {
free(ptr);
}
}
int main() {
int *ptr = NULL;
allocateMemory(&ptr, 1024);
printf("Memory allocated: %p\n", ptr);
freeMemory(ptr);
return 0;
}</code></pre>
<h3>C - Concurrency with pthreads</h3>
<pre><code class="language-c">#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void* worker(void* arg) {
int i = *(int*)arg;