Skip to content

Conversation

@Hardik1106
Copy link

@Hardik1106 Hardik1106 commented Nov 14, 2025

Description

This PR adds two new algorithm modules implemented in the project’s mapcode style and integrates them into the main document so they render with the existing mapcode-viz visualizer.

What’s Included

  1. New Algorithm Modules
  • algorithms/editdistance.typ

    • Formal DP recurrence definition.
    • Mapcode-style specification (rho, F, pi).
    • Concrete DP computation for a sample instance.
    • Full DP-table visualization using the project’s mapcode-viz framework.
    • Structured layout for item metadata, tensor updates, and stepwise evaluation.
  • algorithms/catalannumbers.typ

    • Formal DP recurrence definition.
    • Mapcode-style specification (rho, F, pi).
    • Concrete DP computation for a sample instance.
    • Full DP-table visualization using the project’s mapcode-viz framework.
    • Structured layout for item metadata, tensor updates, and stepwise evaluation.
  1. Documentation Integration
  • Updated main.typ:
    • Added "#include "algorithms/editdistance.typ" and "algorithms/catalannumbers.typ" directly after the add-two-numbers section.

Why this matters

  • Adds representative DP examples (1D convolution-like DP and 2D DP table) to the mapcode corpus.
  • Exercises both vector and tensor visualizers and helps validate DP-history/fixed-point visualization logic.
  • Three-way dependency for Edit Distance Problem: Each DP cell depends on (i-1,j), (i,j-1), (i-1,j-1) (delete, insert, substitute) a simultaneous 3‑way recursion per non‑base cell.
  • Convolutional dependency: Cat(n) = Σ_{k=0..n-1} Cat(k)·Cat(n-1-k) - each new index depends on all strictly smaller indices (a full convolution), not just a fixed small window.

Files Changed

  • algorithms/editdistance.typ - 141 lines added
  • algorithms/catalannumbers.typ - 108 lines added
  • main.typ - 4 lines added
  • No existing code modified; additions are isolated and non-breaking

Implementation notes

  • catalannumbers.typ:

    • Defines I = n:NN, X = [0..n] -> NN_bot, A = NN.
    • rho(n) initializes the DP vector to bot (none), F fills Cat(0)=1 and computes Cat(i) = sum_{k=0}^{i-1} Cat(k) * Cat(i-1-k) when dependencies are ready.
    • pi(n) returns x[n].
    • X_h visualizes the DP vector and highlights updated entries per iteration (consistent with fibonacci.typ / factorial.typ).
  • editdistance.typ:

    • Defines I = S × T, X = [0..|S|] × [0..|T|] -> NN_bot, A = NN.
    • rho(S,T) initializes the full DP table to bot (none).
    • F implements the standard Levenshtein DP update:
      • base rows/columns: i if j=0, j if i=0
      • match: x[i-1,j-1]
      • mismatch: 1 + min(x[i-1,j], x[i,j-1], x[i-1,j-1])
    • pi returns x[|S|, |T|].
    • x_h renders the DP table with labeled row/column characters and highlights changed cells per iteration (consistent with LongestCommonSubsequence.typ).

    Traces Generated:

image image

@Hardik1106 Hardik1106 closed this Nov 14, 2025
@Hardik1106 Hardik1106 reopened this Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant