| #include <stdio.h> |
| #include <stdint.h> |
| #include <math.h> |
|
|
| |
| |
| |
| |
| |
| |
|
|
| |
| |
|
|
| |
| void pingala_meters(int n) { |
| int total = 1 << n; |
| printf("Pingala's Meters (Binary Patterns) for n=%d:\n", n); |
| printf("Total: %d patterns\n\n", total); |
| |
| for (int i = 0; i < total; i++) { |
| printf(" Meter %2d: ", i); |
| |
| for (int j = n-1; j >= 0; j--) { |
| printf("%c", (i >> j) & 1 ? 'G' : 'L'); |
| } |
| printf(" (0x%0*X)\n", (n+3)/4, i); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| void pingala_meru_prastara(int rows) { |
| printf("\nPingala's Meru Prastara (Pascal's Triangle):\n"); |
| printf("Used for combinatorial counting in architecture search\n\n"); |
| |
| int triangle[20][20] = {0}; |
| |
| for (int i = 0; i < rows; i++) { |
| triangle[i][0] = 1; |
| triangle[i][i] = 1; |
| |
| for (int j = 1; j < i; j++) { |
| triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j]; |
| } |
| |
| |
| for (int s = 0; s < rows - i; s++) printf(" "); |
| for (int j = 0; j <= i; j++) { |
| printf("%4d", triangle[i][j]); |
| } |
| printf("\n"); |
| } |
| } |
|
|
| |
| |
| uint64_t pingala_nCr(int n, int r) { |
| if (r > n) return 0; |
| if (r == 0 || r == n) return 1; |
| |
| |
| uint64_t result = 1; |
| for (int i = 1; i <= r; i++) { |
| result = result * (n - r + i) / i; |
| } |
| return result; |
| } |
|
|
| int main() { |
| printf("ββββββββββββββββββββββββββββββββββββββββββββββββββββ\n"); |
| printf("β PINGALA'S ALGORITHMS (Chandas Shastra) β\n"); |
| printf("β ~300 BCE - First Binary System β\n"); |
| printf("ββββββββββββββββββββββββββββββββββββββββββββββββββββ\n\n"); |
| |
| |
| pingala_meters(4); |
| |
| |
| pingala_meru_prastara(8); |
| |
| |
| printf("\nPingala's nCr (Attention Head Selection):\n"); |
| int n = 14; |
| for (int r = 0; r <= n; r += 2) { |
| printf(" C(%2d, %2d) = %10lu\n", n, r, pingala_nCr(n, r)); |
| } |
| |
| printf("\nβ
These map directly to:\n"); |
| printf(" β’ Neural architecture search (all patterns)\n"); |
| printf(" β’ Attention head selection (nCr)\n"); |
| printf(" β’ Beam search initialization (binary enumeration)\n"); |
| printf(" β’ Dropout mask generation (random meter selection)\n"); |
| |
| return 0; |
| } |
|
|