From f3ed8e5f0b78017a6b425e6cc98797afb3a4b9a2 Mon Sep 17 00:00:00 2001 From: ateium munol Date: Fri, 14 Nov 2025 16:00:35 +0530 Subject: [PATCH 1/6] make merge sort, yet to do diagram --- algorithms/MegeSort.typ | 133 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 algorithms/MegeSort.typ diff --git a/algorithms/MegeSort.typ b/algorithms/MegeSort.typ new file mode 100644 index 0000000..f2927a3 --- /dev/null +++ b/algorithms/MegeSort.typ @@ -0,0 +1,133 @@ +#import "../lib/style.typ": * +#import "../lib/mapcode.typ": * + +== Merge Sort + +Compute the binomial coefficient $C(n, k)$, which represents the number of ways to choose $k$ elements from a set of $n$ elements. + +Formal definition: +$ +m(a) := cases( + a & "if " |a| <= 1, + "merge"(m(h_l a), m(h_r a)) & "else" +) +$ + +Example: +- C(5, 2) = 10 +- C(5, 0) = 1 +- C(5, 5) = 1 +- C(10, 3) = 120 + +*As mapcode:* + +Primatives +1. array data structure. Also size of array $a$ is given by $|a|$ +2. merge function: $"merge"(a,b)$ returns sorted array containing elements of $a$ and $b$ +3. List Halving operators ($h_l$ and $h_r$): $h_l a$ returns an array with first $⌈(|a|)/2⌉$ elements of $a$ while $h_r a$ returns the rest +4. Given an array $a$, define family of sets $h^n a$ such that +$ +h^n a := cases( + a & "if " n=0, + h^{n-1} a union \{h_l x "|" x in h^{n-1} a\} union \{h_r x "|" x in h^{n-1} a\} & "else" +) +$ + + +$ +I = A = { "set of arrays" } quad +X_(a) & = h^{⌈log_2 |a|⌉}_a -> { "set of arrays" }_bot quad quad quad \ +rho(a) & = { "arr" -> bot | "arr" in h^⌈log_2 |a|⌉ a } \ +F(x("arr")) & = cases( + "arr" & "if " |"arr"|<=1, + "merge"(x(h_l "arr"),x(h_r "arr")) & "if " x(h_l "arr") "," x(h_r "arr") != bot, + bot & "else" + )\ +pi_(a) (x) & = x(a) +$ + +#let inst_n = 5; +#let inst_k = 3; +#figure( + caption: [Binomial Coefficient computation using mapcode for $n = #inst_n$ and $k = #inst_k$; A Pascal's Triangle style visualization is used.], +$#{ + let rho = ((inst_n, inst_k)) => { + let x = () + for i in range(0, inst_n + 1) { + let row = () + for j in range(0, inst_k + 1) { + row.push(none) + } + x.push(row) + } + x + } + + let F_i = (x) => ((i,j)) => { + if j == 0 or j == i {1} + else if i >= j { + let idx = (i, j) + let val1 = if x.at(i - 1).at(j - 1) != none {x.at(i - 1).at(j - 1)} else {none} + let val2 = if x.at(i - 1).at(j) != none {x.at(i - 1).at(j)} else {none} + if val1 != none and val2 != none {val1 + val2} else {none} + } else { + none + } + } + let F = map_tensor(F_i, dim: 2) + + let pi = ((n, k)) => (x) => x.at(n).at(k) + + // draw a pascal triangle style matrix + let x_h(x, diff_mask:none) = { + set text(weight: "bold") + // trim if j < i + let trim = (x) => { + let res = () + for i in range(0, x.len()) { + let row = () + for j in range(0, x.at(i).len()) { + if j <= i { + row.push(x.at(i).at(j)) + } else { + // row.push(none) + } + } + res.push(row) + } + res + } + x = trim(x) + let rows = () + for i in range(0, x.len()) { + let row = () + for j in range(0, x.at(i).len()) { + let val = if x.at(i).at(j) != none {[$#x.at(i).at(j)$]} else {[$bot$]} + if diff_mask != none and diff_mask.at(i).at(j) { + // changed element: highlight + row.push(rect(stroke: gray, fill: yellow.transparentize(70%), inset: 4pt)[$#val$]) + } else { + row.push(rect(stroke: gray, inset: 4pt)[$#val$]) + } + } + rows.push( + grid( + columns: row.len() * (14pt,), + rows: 14pt, + align: center + horizon, + ..row + ) + ) + } + grid(align: center, ..rows) + } + + mapcode-viz( + rho,F, pi((inst_n, inst_k)), + X_h: x_h, + pi_name: [$mpi ((#inst_n, #inst_k))$], + group-size: calc.min(3, inst_n), + cell-size: 20mm, scale-fig: 85% + )((inst_n, inst_k)) +} +$) \ No newline at end of file From d3fde14e51fdeea563570166ab3d50bb20532864 Mon Sep 17 00:00:00 2001 From: ateium munol Date: Sat, 15 Nov 2025 19:26:57 +0530 Subject: [PATCH 2/6] doing matrix chain dp --- .gitignore | 3 ++ algorithms/MegeSort.typ | 87 +-------------------------------- algorithms/matrix_mul_chain.typ | 36 ++++++++++++++ 3 files changed, 40 insertions(+), 86 deletions(-) create mode 100644 algorithms/matrix_mul_chain.typ diff --git a/.gitignore b/.gitignore index f444db2..2f702b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +algorithms/mergggee.typ +algorithms/evenodd.typ +algorithms/01-Knapsack.typ # General .vscode .idea diff --git a/algorithms/MegeSort.typ b/algorithms/MegeSort.typ index f2927a3..4b8241b 100644 --- a/algorithms/MegeSort.typ +++ b/algorithms/MegeSort.typ @@ -18,7 +18,7 @@ Example: - C(5, 0) = 1 - C(5, 5) = 1 - C(10, 3) = 120 - +/* ddc */ *As mapcode:* Primatives @@ -46,88 +46,3 @@ F(x("arr")) & = cases( pi_(a) (x) & = x(a) $ -#let inst_n = 5; -#let inst_k = 3; -#figure( - caption: [Binomial Coefficient computation using mapcode for $n = #inst_n$ and $k = #inst_k$; A Pascal's Triangle style visualization is used.], -$#{ - let rho = ((inst_n, inst_k)) => { - let x = () - for i in range(0, inst_n + 1) { - let row = () - for j in range(0, inst_k + 1) { - row.push(none) - } - x.push(row) - } - x - } - - let F_i = (x) => ((i,j)) => { - if j == 0 or j == i {1} - else if i >= j { - let idx = (i, j) - let val1 = if x.at(i - 1).at(j - 1) != none {x.at(i - 1).at(j - 1)} else {none} - let val2 = if x.at(i - 1).at(j) != none {x.at(i - 1).at(j)} else {none} - if val1 != none and val2 != none {val1 + val2} else {none} - } else { - none - } - } - let F = map_tensor(F_i, dim: 2) - - let pi = ((n, k)) => (x) => x.at(n).at(k) - - // draw a pascal triangle style matrix - let x_h(x, diff_mask:none) = { - set text(weight: "bold") - // trim if j < i - let trim = (x) => { - let res = () - for i in range(0, x.len()) { - let row = () - for j in range(0, x.at(i).len()) { - if j <= i { - row.push(x.at(i).at(j)) - } else { - // row.push(none) - } - } - res.push(row) - } - res - } - x = trim(x) - let rows = () - for i in range(0, x.len()) { - let row = () - for j in range(0, x.at(i).len()) { - let val = if x.at(i).at(j) != none {[$#x.at(i).at(j)$]} else {[$bot$]} - if diff_mask != none and diff_mask.at(i).at(j) { - // changed element: highlight - row.push(rect(stroke: gray, fill: yellow.transparentize(70%), inset: 4pt)[$#val$]) - } else { - row.push(rect(stroke: gray, inset: 4pt)[$#val$]) - } - } - rows.push( - grid( - columns: row.len() * (14pt,), - rows: 14pt, - align: center + horizon, - ..row - ) - ) - } - grid(align: center, ..rows) - } - - mapcode-viz( - rho,F, pi((inst_n, inst_k)), - X_h: x_h, - pi_name: [$mpi ((#inst_n, #inst_k))$], - group-size: calc.min(3, inst_n), - cell-size: 20mm, scale-fig: 85% - )((inst_n, inst_k)) -} -$) \ No newline at end of file diff --git a/algorithms/matrix_mul_chain.typ b/algorithms/matrix_mul_chain.typ new file mode 100644 index 0000000..9ad3c0d --- /dev/null +++ b/algorithms/matrix_mul_chain.typ @@ -0,0 +1,36 @@ + + +== Euclidean GCD +#set math.equation(numbering: none) + +Given a sequence of matrices $A_(n_1 times n_2),A_(n_2 times n_3),..,A_(n_(q-1) times q_i)$, Compute the minimum number of scalar multiplication required to multiply all of them. +The algorithm takes in vector $d = (n_1,..,n_q)$ and returns an integer. + +Formal definition: $"num_mul"(d) := T_d (0,|d|-2)$ where + +$ + T_d (i, j) = min_{k|i<=k 38000 $ +- $"num_mul"(13, 5, 89, 3, 34) -> 2856$ + +*As mapcode:* + +_primitives_: `mod`($mod$) is strict. i.e operation on $bot$ is undefined. + +$ + I = "vec"[NN] quad quad quad X & = NN times NN -> NN_bot quad quad quad + A = NN \ + rho(d) & = {(i,j) -> bot | i,j in NN} \ + F_d (x) & = cases( + 0 & "if " i = j, + min { x(i,k)+ x(k+1,j)+d(i) dot d(j+1) dot d(k+1) |i<=k Date: Sat, 15 Nov 2025 20:41:01 +0530 Subject: [PATCH 3/6] finished matrix chain dp --- algorithms/matrix_mul_chain.bak.typ | 148 ++++++++++++++++++++++++++++ algorithms/matrix_mul_chain.typ | 127 +++++++++++++++++++++++- 2 files changed, 273 insertions(+), 2 deletions(-) create mode 100644 algorithms/matrix_mul_chain.bak.typ diff --git a/algorithms/matrix_mul_chain.bak.typ b/algorithms/matrix_mul_chain.bak.typ new file mode 100644 index 0000000..689dafd --- /dev/null +++ b/algorithms/matrix_mul_chain.bak.typ @@ -0,0 +1,148 @@ +#import "../lib/style.typ": * +#import "../lib/mapcode.typ": * + +== Optimal Matrix Chain Multiplication +#set math.equation(numbering: none) + +Given a sequence of matrices $A_(n_1 times n_2),A_(n_2 times n_3),..,A_(n_(q-1) times q_i)$, Compute the minimum number of scalar multiplication required to multiply all of them. +The algorithm takes in vector $d = (n_1,..,n_q)$ and returns an integer. + +Formal definition: $"num_mul"(d) := T_d (0,|d|-2)$ where + +$ + T_d (i, j) = min_{k|i<=k 38000 $ +- $"num_mul"(13, 5, 89, 3, 34) -> 2856$ + +*As mapcode:* + +_primitives_: `mod`($mod$) is strict. i.e operation on $bot$ is undefined. + +$ + I = "vec"[NN] quad quad quad X & = NN times NN -> NN_bot quad quad quad + A = NN \ + rho(d) & = {(i,j) -> bot | i,j in NN} \ + F_d (x) & = cases( + 0 & "if " i = j, + min { x(i,k)+ x(k+1,j)+d(i) dot d(j+1) dot d(k+1) |i<=k { + let x = () + for i in range(0, inst_dimvecs.len() - 1) { + let row = () + for w in range(0, inst_dimvecs.len() - 1) { + row.push(none) + } + x.push(row) + } + x + } + + let F_i(d) = (x) => ((i, j)) => { + if i == j { + 0 + } else { + let mut = none + let min_val = none + for k in range(i, j) { + let term1 = x.at(i).at(k) + let term2 = x.at(k+1).at(j) + let product = d.at(i) * d.at(j+1) * d.at(k+1) + + // If any component is none, the result is none + if term1 == none or term2 == none { + // Continue to check other k values, but min_val becomes none + min_val = none + } else if min_val != none { + let current = term1 + term2 + product + if current < min_val { + min_val = current + } + } + } + min_val + } + } + + + let F = (inst_dimvecs) => map_tensor(F_i(inst_dimvecs), dim: 2) + + let pi = ((dimvec)) => (x) => { + let m = dimvec.len() + x.at(0).at(m - 2) + } + + // (2, 3, 4, 5), (3, 4, 5, 6), 5) + let I_h(inst_dimvecs) = { + [ + $d: vec(..#inst_dimvecs.map(i => [#i]), delim: "[")_(#inst_dimvecs.len())$ + ] + } + + + let x_h(x, diff_mask:none) = { + set text(weight: "bold") + let rows = () + + + let header_cells = () + header_cells.push(rect(fill: green.transparentize(70%), inset: 14pt)[$id$]) + + + for w in range(0, x.at(0).len()) { + header_cells.push(rect(fill: orange.transparentize(70%), inset: 14pt)[$#w$]) + } + rows.push(grid(columns: header_cells.len() * (14pt,), rows: 14pt, align: center + horizon, ..header_cells)) + + for i in range(0, x.len()) { + let row = () + + if i == 0 { + row.push(rect(fill: green.transparentize(70%), inset: 14pt)[$0$]) + }else{ + row.push(rect(fill: green.transparentize(70%), inset: 14pt)[$#i$]) + } + + for w in range(0, x.at(i).len()) { + let val = if x.at(i).at(w) != none {[$#x.at(i).at(w)$]} else {[$bot$]} + if diff_mask != none and diff_mask.at(i).at(w) { + row.push(rect(stroke: gray, fill: yellow.transparentize(70%), inset: 14pt)[$#val$]) + } else { + row.push(rect(stroke: gray, inset: 14pt)[$#val$]) + } + } + + rows.push(grid(columns: row.len() * (30pt,), rows: 14pt, align: center + horizon, ..row)) + } + + grid(align: center, ..rows) + } + + mapcode-viz( + rho, F(inst_dimvecs), pi(inst_dimvecs), + I_h: I_h, + X_h: x_h, + F_name: [$F_(w,v)$], + pi_name: [$\pi_(w,v,C)$], + group-size: calc.min(3, inst_dimvecs.len()), + cell-size: 60mm, scale-fig: 75% + )(inst_dimvecs) +}$) + diff --git a/algorithms/matrix_mul_chain.typ b/algorithms/matrix_mul_chain.typ index 9ad3c0d..f29c09f 100644 --- a/algorithms/matrix_mul_chain.typ +++ b/algorithms/matrix_mul_chain.typ @@ -1,6 +1,7 @@ +#import "../lib/style.typ": * +#import "../lib/mapcode.typ": * - -== Euclidean GCD +== Optimal Matrix Chain Multiplication #set math.equation(numbering: none) Given a sequence of matrices $A_(n_1 times n_2),A_(n_2 times n_3),..,A_(n_(q-1) times q_i)$, Compute the minimum number of scalar multiplication required to multiply all of them. @@ -34,3 +35,125 @@ $ + +#let inst_dimvecs = (13, 5, 89, 3, 34); +#let inst_dm = inst_dimvecs.len(); + + +#figure( + caption: [Optimal Matrix Chain Multiplication for dimensions = #inst_dimvecs.], +$#{ + let rho = (inst_dimvecs) => { + let x = () + for i in range(0, inst_dimvecs.len() - 1) { + let row = () + for w in range(0, inst_dimvecs.len() - 1) { + row.push(none) + } + x.push(row) + } + x + } + + let safe_operation(a, b, c, op) = { + if a == none or b == none or c == none { + none + } else { + op(a, b, c) + } + } + + let F_i(d) = (x) => ((i, j)) => { + if i == j { + 0 + } else { + let min_val = none + let mut = none + for k in range(i, j) { + let current = safe_operation( + x.at(i).at(k), + x.at(k+1).at(j), + d.at(i) * d.at(j+1) * d.at(k+1), + (a, b, c) => a + b + c + ) + + if current != none { + if min_val == none or current < min_val { + min_val = current + } + } else { + // If we want to propagate none immediately: + // return none + // If we want to check all k but return none if any is none: + min_val = none + } + } + min_val + } + } + + + let F = (inst_dimvecs) => map_tensor(F_i(inst_dimvecs), dim: 2) + + let pi = ((dimvec)) => (x) => { + let m = dimvec.len() + x.at(0).at(m - 2) + } + + // (2, 3, 4, 5), (3, 4, 5, 6), 5) + let I_h(inst_dimvecs) = { + [ + $d: vec(..#inst_dimvecs.map(i => [#i]), delim: "[")$ + ] + } + + + let x_h(x, diff_mask:none) = { + set text(weight: "bold") + let rows = () + + + let header_cells = () + header_cells.push(rect(fill: green.transparentize(70%), inset: 14pt)[$id$]) + + + for w in range(0, x.at(0).len()) { + header_cells.push(rect(fill: orange.transparentize(70%), inset: 14pt)[$#w$]) + } + rows.push(grid(columns: header_cells.len() * (30pt,), rows: 14pt, align: center + horizon, ..header_cells)) + + for i in range(0, x.len()) { + let row = () + + if i == 0 { + row.push(rect(fill: green.transparentize(70%), inset: 14pt)[$0$]) + }else{ + row.push(rect(fill: green.transparentize(70%), inset: 14pt)[$#i$]) + } + + for w in range(0, x.at(i).len()) { + let val = if x.at(i).at(w) != none {[$#x.at(i).at(w)$]} else {[$bot$]} + if diff_mask != none and diff_mask.at(i).at(w) { + row.push(rect(stroke: gray, fill: yellow.transparentize(70%), inset: 14pt)[$#val$]) + } else { + row.push(rect(stroke: gray, inset: 14pt)[$#val$]) + } + } + + rows.push(grid(columns: row.len() * (30pt,), rows: 14pt, align: center + horizon, ..row)) + } + + grid(align: center, ..rows) + } + + mapcode-viz( + rho, F(inst_dimvecs), pi(inst_dimvecs), + I_h: I_h, + X_h: x_h, + F_name: [$F_(w,v)$], + pi_name: [$\pi_(w,v,C)$], + group-size: calc.min(3, inst_dimvecs.len()), + cell-size: 60mm, scale-fig: 75% + )(inst_dimvecs) +}$) + From 1566012065e789b1499a14c32d057e941aaa0b35 Mon Sep 17 00:00:00 2001 From: ateium munol Date: Sat, 15 Nov 2025 20:56:54 +0530 Subject: [PATCH 4/6] finished matrix chain dp --- .gitignore | 1 + ...hain.typ => OptimalMatrixChainProduct.typ} | 12 +- algorithms/matrix_mul_chain.bak.typ | 148 ------------------ main.typ | 2 + 4 files changed, 10 insertions(+), 153 deletions(-) rename algorithms/{matrix_mul_chain.typ => OptimalMatrixChainProduct.typ} (91%) delete mode 100644 algorithms/matrix_mul_chain.bak.typ diff --git a/.gitignore b/.gitignore index 2f702b6..9474994 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ algorithms/mergggee.typ algorithms/evenodd.typ algorithms/01-Knapsack.typ +algorithms/matrix_mul_chain.bak.typ # General .vscode .idea diff --git a/algorithms/matrix_mul_chain.typ b/algorithms/OptimalMatrixChainProduct.typ similarity index 91% rename from algorithms/matrix_mul_chain.typ rename to algorithms/OptimalMatrixChainProduct.typ index f29c09f..6be3ded 100644 --- a/algorithms/matrix_mul_chain.typ +++ b/algorithms/OptimalMatrixChainProduct.typ @@ -4,8 +4,8 @@ == Optimal Matrix Chain Multiplication #set math.equation(numbering: none) -Given a sequence of matrices $A_(n_1 times n_2),A_(n_2 times n_3),..,A_(n_(q-1) times q_i)$, Compute the minimum number of scalar multiplication required to multiply all of them. -The algorithm takes in vector $d = (n_1,..,n_q)$ and returns an integer. +Given a sequence of matrices $A_(n_0 times n_1),A_(n_1 times n_2),..,A_(n_(q-1) times q_i)$, Compute the minimum number of scalar multiplication required to multiply all of them. +The algorithm takes in vector $d = (n_0,..,n_q)$ and returns an integer. Formal definition: $"num_mul"(d) := T_d (0,|d|-2)$ where @@ -20,13 +20,15 @@ Examples: *As mapcode:* -_primitives_: `mod`($mod$) is strict. i.e operation on $bot$ is undefined. +_primitives_: $"min",+,<,<=$. \ +Non Comparitive Operations on $bot$ return $bot$. (For example: $4+bot=bot$ , $min({3,2,bot,10})=bot$) $ - I = "vec"[NN] quad quad quad X & = NN times NN -> NN_bot quad quad quad + k in NN \ + I = NN^k quad quad quad X & = NN times NN -> NN_bot quad quad quad A = NN \ rho(d) & = {(i,j) -> bot | i,j in NN} \ - F_d (x) & = cases( + F_d (x)(i,j) & = cases( 0 & "if " i = j, min { x(i,k)+ x(k+1,j)+d(i) dot d(j+1) dot d(k+1) |i<=k 38000 $ -- $"num_mul"(13, 5, 89, 3, 34) -> 2856$ - -*As mapcode:* - -_primitives_: `mod`($mod$) is strict. i.e operation on $bot$ is undefined. - -$ - I = "vec"[NN] quad quad quad X & = NN times NN -> NN_bot quad quad quad - A = NN \ - rho(d) & = {(i,j) -> bot | i,j in NN} \ - F_d (x) & = cases( - 0 & "if " i = j, - min { x(i,k)+ x(k+1,j)+d(i) dot d(j+1) dot d(k+1) |i<=k { - let x = () - for i in range(0, inst_dimvecs.len() - 1) { - let row = () - for w in range(0, inst_dimvecs.len() - 1) { - row.push(none) - } - x.push(row) - } - x - } - - let F_i(d) = (x) => ((i, j)) => { - if i == j { - 0 - } else { - let mut = none - let min_val = none - for k in range(i, j) { - let term1 = x.at(i).at(k) - let term2 = x.at(k+1).at(j) - let product = d.at(i) * d.at(j+1) * d.at(k+1) - - // If any component is none, the result is none - if term1 == none or term2 == none { - // Continue to check other k values, but min_val becomes none - min_val = none - } else if min_val != none { - let current = term1 + term2 + product - if current < min_val { - min_val = current - } - } - } - min_val - } - } - - - let F = (inst_dimvecs) => map_tensor(F_i(inst_dimvecs), dim: 2) - - let pi = ((dimvec)) => (x) => { - let m = dimvec.len() - x.at(0).at(m - 2) - } - - // (2, 3, 4, 5), (3, 4, 5, 6), 5) - let I_h(inst_dimvecs) = { - [ - $d: vec(..#inst_dimvecs.map(i => [#i]), delim: "[")_(#inst_dimvecs.len())$ - ] - } - - - let x_h(x, diff_mask:none) = { - set text(weight: "bold") - let rows = () - - - let header_cells = () - header_cells.push(rect(fill: green.transparentize(70%), inset: 14pt)[$id$]) - - - for w in range(0, x.at(0).len()) { - header_cells.push(rect(fill: orange.transparentize(70%), inset: 14pt)[$#w$]) - } - rows.push(grid(columns: header_cells.len() * (14pt,), rows: 14pt, align: center + horizon, ..header_cells)) - - for i in range(0, x.len()) { - let row = () - - if i == 0 { - row.push(rect(fill: green.transparentize(70%), inset: 14pt)[$0$]) - }else{ - row.push(rect(fill: green.transparentize(70%), inset: 14pt)[$#i$]) - } - - for w in range(0, x.at(i).len()) { - let val = if x.at(i).at(w) != none {[$#x.at(i).at(w)$]} else {[$bot$]} - if diff_mask != none and diff_mask.at(i).at(w) { - row.push(rect(stroke: gray, fill: yellow.transparentize(70%), inset: 14pt)[$#val$]) - } else { - row.push(rect(stroke: gray, inset: 14pt)[$#val$]) - } - } - - rows.push(grid(columns: row.len() * (30pt,), rows: 14pt, align: center + horizon, ..row)) - } - - grid(align: center, ..rows) - } - - mapcode-viz( - rho, F(inst_dimvecs), pi(inst_dimvecs), - I_h: I_h, - X_h: x_h, - F_name: [$F_(w,v)$], - pi_name: [$\pi_(w,v,C)$], - group-size: calc.min(3, inst_dimvecs.len()), - cell-size: 60mm, scale-fig: 75% - )(inst_dimvecs) -}$) - diff --git a/main.typ b/main.typ index 9952d9b..4bfdfc6 100644 --- a/main.typ +++ b/main.typ @@ -52,3 +52,5 @@ All primitives are _strict_ meaning they do not allow for undefined values (i.e. #include "algorithms/LongestCommonSubsequence.typ" #pagebreak() #include "algorithms/leetcode/P2_add-two-numbers.typ" +#pagebreak() +#include "algorithms/OptimalMatrixChainProduct.typ" \ No newline at end of file From b0666dfc08f72383e77e1c7f1e19286fe3bb88a2 Mon Sep 17 00:00:00 2001 From: ateium munol Date: Sat, 15 Nov 2025 21:07:24 +0530 Subject: [PATCH 5/6] link ms --- algorithms/MegeSort.typ | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/algorithms/MegeSort.typ b/algorithms/MegeSort.typ index 4b8241b..a3791d8 100644 --- a/algorithms/MegeSort.typ +++ b/algorithms/MegeSort.typ @@ -14,10 +14,10 @@ m(a) := cases( $ Example: -- C(5, 2) = 10 -- C(5, 0) = 1 -- C(5, 5) = 1 -- C(10, 3) = 120 +- m(5, 2, 4, 2, 8) = (2, 2, 4, 5, 8) +- m(5, 0) = (0, 5) +- m(9, 6, 5, 3, 1, 8, 7, 2, 4) = (1, 2, 3, 4, 5, 6, 7, 8, 9) + /* ddc */ *As mapcode:* @@ -46,3 +46,8 @@ F(x("arr")) & = cases( pi_(a) (x) & = x(a) $ + +#link("https://github.com/mayank3135432/recreational-programming-stuff/blob/main/merge_sort.ipynb")[ + Link to Python Implementation (See cell 11) +] + From d998268cfc9f73c80e3251632af6530bf9d00705 Mon Sep 17 00:00:00 2001 From: ateium munol Date: Sat, 15 Nov 2025 21:16:02 +0530 Subject: [PATCH 6/6] add ms to main --- main.typ | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.typ b/main.typ index 4bfdfc6..23173cc 100644 --- a/main.typ +++ b/main.typ @@ -53,4 +53,6 @@ All primitives are _strict_ meaning they do not allow for undefined values (i.e. #pagebreak() #include "algorithms/leetcode/P2_add-two-numbers.typ" #pagebreak() -#include "algorithms/OptimalMatrixChainProduct.typ" \ No newline at end of file +#include "algorithms/OptimalMatrixChainProduct.typ" +#pagebreak() +#include "algorithms/MegeSort.typ" \ No newline at end of file