# Student coding labs

Each program is independent and supplies its own imports, demo, input fixture or generator, and `--self-test` checks. Use Python 3.10 or newer.

## Setup

```sh
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
```

Windows PowerShell activation: `.venv\Scripts\Activate.ps1`.
Sixteen programs need only the standard library. Five use PyTorch; PINN also uses NumPy and Matplotlib. The ML demos work on CPU and generate their data locally.

## Commands

### Python 101 — Basics for a New Bee

```sh
python python_101.py
python python_101.py --self-test
```

How do we turn CSV records into a useful command-line summary?

### The Science of Programming — Explained Simply

```sh
python science_of_programming.py
python science_of_programming.py --self-test
```

How can a contract determine the loop we should write?

### Weakest Preconditions — Explained Simply

```sh
python weakest_preconditions.py
python weakest_preconditions.py --self-test
```

Which starting states let a program finish with the required result?

### The Science of Programming — A Practical Python Playbook

```sh
python science_of_programming_python.py
python science_of_programming_python.py --self-test
```

How do we implement and check loops with precise boundary behavior?

### PyTorch 101 — From Tensors to Training

```sh
python pytorch_101.py
python pytorch_101.py --self-test
```

Can gradients learn the unknown slope and intercept of a line?

### Neural Networks and CNNs — From First Principles

```sh
python cnn.py
python cnn.py --self-test
```

Can shared local filters learn to distinguish vertical and horizontal bars?

### How LLMs Work — A Tech Talk

```sh
python llm_tech_talk.py
python llm_tech_talk.py --self-test
```

Can a small model learn next-character prediction while being unable to see future targets?

### Adaptive Neural Infrastructure with Memory Accumulation

```sh
python adaptive_neural_infra.py
python adaptive_neural_infra.py --self-test
```

Can we select experts, accumulate state, and keep memory scoped to a user?

### Physics-Informed Neural Networks

```sh
python pinn_heat_equation.py --epochs 2500
python pinn_heat_equation.py --self-test
```

The PINN example creates synthetic heat-equation data if its CSV is absent, trains, saves a checkpoint, plots predictions/errors, and reports metrics.

### Automata Theory — DFA, NFA & Regular Expressions

```sh
python automata_theory.py
python automata_theory.py --self-test
```

Can a small state machine recognize a pattern one symbol at a time?

### Context-Free Grammars & Pushdown Automata

```sh
python cfg_pda.py
python cfg_pda.py --self-test
```

How does a stack or parsing table recognize nested structure?

### Turing Machines & Undecidability

```sh
python turing_machines.py
python turing_machines.py --self-test
```

How can a head and a transition table transform a binary number?

### P vs NP & NP-Completeness

```sh
python p_vs_np.py
python p_vs_np.py --self-test
```

How do we check a SAT witness and preserve satisfiability in a graph reduction?

### Lambda Calculus — Computation from Functions Alone

```sh
python lambda_calculus.py
python lambda_calculus.py --self-test
```

Can function application compute while preserving which binder a variable belongs to?

### Randomized Algorithms — Probability as a Tool

```sh
python randomized_algorithms.py
python randomized_algorithms.py --self-test
```

Which guarantees come from correctness, and which depend on random choices?

### Entropy & Shannon's Source Coding Theorem

```sh
python entropy_source_coding.py
python entropy_source_coding.py --self-test
```

Can a prefix code reduce the average bits needed for a skewed source?

### Channel Capacity & Error-Correcting Codes

```sh
python channel_capacity_codes.py
python channel_capacity_codes.py --self-test
```

How does structured redundancy correct a single flipped bit?

### KL Divergence, Cross-Entropy & Machine Learning

```sh
python kl_cross_entropy.py
python kl_cross_entropy.py --self-test
```

How do model probabilities turn into a stable loss and gradient?

### Kolmogorov Complexity — The Information in One Object

```sh
python kolmogorov_complexity.py
python kolmogorov_complexity.py --self-test
```

What can a short description show that a compressor's output length cannot?

### Compression in Practice — Arithmetic Coding, LZ & Beyond

```sh
python compression_in_practice.py
python compression_in_practice.py --self-test
```

Can we encode data compactly and decode it exactly?

### Monads in Python — With the Math

```sh
python monads_python.py
python monads_python.py --self-test
```

How can we compose successful steps while keeping missing values or errors explicit?

## Your own CSV

```sh
python python_101.py --csv expenses.csv
```

Use the header `category,amount`, nonempty category names, and nonnegative decimal amounts with at most two decimal places. A sample `expenses.csv` is included.

## PINN outputs and prediction

The default `output/` folder contains the trained checkpoint, two PNG plots, a loss-history CSV, and metrics JSON. Reusing this folder replaces generated outputs; choose a new `--output-dir` for each experiment.

```sh
python pinn_heat_equation.py --predict 0.5 0.5
python pinn_heat_equation.py --data-weight 0 --output-dir output-physics-only
```

Synthetic CSV data must match `--alpha`. Use a new data path when changing diffusivity, as shown in the PINN presentation.

## Verification

All 21 programs passed 6,220 checks and their demos ran from isolated temporary directories using Python 3.12 and PyTorch 2.14.1. Checks include exhaustive small-input enumeration, independent reference comparisons, codec round trips, shape contracts, numerical gradient checks, and training.

Floating-point digits, compression sizes, and training results can vary across versions and hardware. Finite tests do not establish universal proofs. Theory examples explicitly retain their mathematical limits: a simulation budget does not decide halting, finite SAT enumeration does not settle P vs NP, and compressor sizes do not compute true Kolmogorov complexity.
