Upload folder using huggingface_hub (part 16)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- README.mdAdded+119
- SCHEMA.mdAdded+95
- math-dataset.tar.zstAdded+3
- math/math-0157.jsonlAdded+4
- math/math-0158.jsonlAdded+4
- math/math-0159.jsonlAdded+4
- math/math-0160.jsonlAdded+4
- math/math-0161.jsonlAdded+4
- math/math-0162.jsonlAdded+4
- math/math-0163.jsonlAdded+4
- math/math-0164.jsonlAdded+4
- math/math-0165.jsonlAdded+4
- math/math-0166.jsonlAdded+4
- math/math-0167.jsonlAdded+4
- math/math-0168.jsonlAdded+4
- math/math-0169.jsonlAdded+4
- math/math-0170.jsonlAdded+4
- math/math-0171.jsonlAdded+4
- math/math-0172.jsonlAdded+4
- math/math-0173.jsonlAdded+4
- math/math-0174.jsonlAdded+4
- math/math-0175.jsonlAdded+4
- math/math-0176.jsonlAdded+4
- math/math-0177.jsonlAdded+4
- math/math-0178.jsonlAdded+4
- math/math-0179.jsonlAdded+4
- math/math-0180.jsonlAdded+4
- math/math-0181.jsonlAdded+4
- math/math-0182.jsonlAdded+4
- math/math-0183.jsonlAdded+4
- math/math-0184.jsonlAdded+4
- math/math-0185.jsonlAdded+4
- math/math-0186.jsonlAdded+4
- math/math-0187.jsonlAdded+4
- math/math-0188.jsonlAdded+4
- math/math-0189.jsonlAdded+4
- math/math-0190.jsonlAdded+4
- math/math-0191.jsonlAdded+4
- math/math-0192.jsonlAdded+4
- math/math-0193.jsonlAdded+4
- math/math-0194.jsonlAdded+4
- math/math-0195.jsonlAdded+4
- math/math-0196.jsonlAdded+4
- math/math-0197.jsonlAdded+4
- math/math-0198.jsonlAdded+4
- math/math-0199.jsonlAdded+4
- math/math-0200.jsonlAdded+4
- math/math-0201.jsonlAdded+4
- math/math-0202.jsonlAdded+4
- math/math-0203.jsonlAdded+4
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119---
language:
- en
- de
- fr
- es
- ru
- ja
- zh
- it
- pt
- pl
- ar
- fa
- nl
- id
- vi
- tr
- uk
- he
- sv
- cs
- ko
- hu
- fi
- ca
- no
- sr
- ro
- da
- bg
- el
- th
- hi
- ta
- te
- ml
- ur
- ms
- sk
- hr
- lt
- sl
- et
- lv
- be
- ka
- az
- uz
- kk
- mk
- sq
- af
- sw
- tl
- gl
- eu
- hy
- bs
- mn
- ne
- si
- km
- lo
- my
- ky
- tg
- tk
- ps
- ku
- ckb
- sd
- pa
- gu
- kn
- mr
- or
- as
- am
- yo
- ig
- ha
- zu
- xh
- st
- sn
- so
- rw
- mg
- war
- ceb
- jv
- su
- min
- ban
- nn
- lb
- is
- ga
- cy
- gd
tags:
- code
- sft
- reasoning
- multilingual
- web
pretty_name: tiny coding language model
size_categories:
- 100K<n<1M
license: mit
---
# tinycodinglm
A collection of single-turn sessions, long-form web/text recall traces, Wikipedia article
recall rows, OpenThoughts reasoning traces, agentic tool traces, and competitive-programming
problems, formatted as one JSONL session per file.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495# tinycodinglm dataset schema
TL;DR: https://huggingface.co/docs/hub/session-traces-formatOne JSONL session per file, UTF-8. **Line endings vary** (most files CRLF; `cp/` and`agentic/` are LF) — parsers must accept both. Six layouts are defined here; web-searchand web-research layouts are defined in `WEB_SCHEMA.md`.
## 1. Single-turn SFT Q&A (`ai`, `asm`, `career`, `cf`, `chess`, `code`, `cpp`, `doc`, `eng`, `i18n`, `lang`, `life`, `lmstudio`, `math`, `mc`, `misc`, `polyglot`, `reason`, `sci`, `sec`, `sys`, `tok`, `cp`)
Exactly 4 lines per file:
1. `{"type":"session","harness":"<harness>","id":"<file-stem>","name":"<title>", "tools": [openai-compatible tools declarations (responses api)]}`2. `{"type":"message","message":{"role":"system","content":"..."}}`3. `{"type":"message","message":{"role":"user","content":"..."}}`4. `{"type":"message","message":{"role":"assistant","content":"..."}}`
`harness` is one of `opencode`, `deepseek-harness`, `copilot-cli`, `my-agent`,`llama.cpp`. Assistant `content` is the final answer; curated coding answers areexpected to be syntactically valid code.
## 2. URL/text recall layout (`c4`, `fineweb`, `fineweb-edu`, `openwebmath`, ...)
Line 1 is a `session` record, followed by exactly 2 `message` records:
1. `{"type":"message","message":{"role":"user","content":"<URL>"}}`2. `{"type":"message","message":{"role":"assistant","content":"<extracted page text>"}}`
There is **no system message** by design: the user turn is a URL and the assistantturn is the extracted page text. Session fields:
- `c4`: `source`, `config`, `url`, `timestamp`, `truncated`.- `fineweb`: `source`, `config`, `source_id`, `url`, `dump`, `date`, `language`, `language_score`, `token_count`, `truncated`.- `fineweb-edu`: `source`, `config`, `source_id`, `url`, `dump`, `language`, `language_score`, `token_count`, `score`, `int_score`, `truncated`.- `openwebmath`: `source`, `config`, `url`, `date`, `metadata`, `truncated`.
This is a recall/pretraining layout, not conversational-assistant SFT. `truncated:true`marks a hard character cap only; it does **not** capture dangling/mid-sentenceextraction endings, which are common.
## 6. OpenThoughts (`ot/`)
4 lines: `session`, `system`, `user`, `assistant`. The assistant message has twofields:
- `reasoningContent`: the chain of thought.- `content`: the final solution.
The system prompt is the neutral OT3 prompt("You are an expert problem solver. Think step by step before giving the final answer.").Raw `<|begin_of_thought|>` / `<|end_of_thought|>` / `<|begin_of_solution|>` /`<|end_of_solution|>` sentinels were stripped and split into the two fields.
Two subsets: `ot-000001`..`ot-113957` from OpenThoughts-114k (113 957 rows) and`ot-113958`..`ot-143957` from OpenThoughts3-1.2M code rows (30 000 rows). Importedcontent is third-party distilled data (Apache-2.0): keep attribution onredistribution and do not apply the first-party invariants about prompt leakage orexploit gadgets to it without review. Assistant answers are long (median ~15-58 KB,max ~200 KB) by design.
## Harness values
`c4`, `fineweb`, `fineweb-edu`, `openwebmath`, `openwebtext`, `mimo`,`wikipedia`, `openthoughts`, `opencode`, `deepseek-harness`, `copilot-cli`,`my-agent`, `llama.cpp`.
## Invariants (enforced on every record)
- Filename stem equals session `id` (e.g. `sec/sec-0625.jsonl` has `id: sec-0625`). Descriptive agentic stems carry the full id.- Line 1 is a `session` record.- Role sequence matches the layout of the directory (§1-§6).- UTF-8; line endings vary (mostly CRLF; `cp/` and `agentic/` are LF).- No C0 control characters in decoded content (outside `\n`, `\t`).- Assistant `content` is non-empty except for agentic turns (tool-call placeholders or incomplete imported turns), web turns that carry `toolCalls` (the tool call is the response), and reasoning-only OpenThoughts traces (where `reasoningContent` holds the full trace).- If `reasoningContent` is present, it is a non-empty string, `content` holds the final answer, and no `<|begin_of_thought|>` / `<|end_of_thought|>` / `<|begin_of_solution|>` / `<|end_of_solution|>` sentinel remains.- Curated coding answers (§1) must be syntactically valid code and must not echo harness instructions ("following the best practices … Reply with the fixed optimized code" is prompt leakage, never an answer).- `truncated:true` marks a hard character cap, not extraction damage.
## Quick validation
Parse every line as JSON, assert the role sequence for the directory's layout,assert `stem == session id`, assert non-empty assistant `content` (except agenticplaceholders), and scan `ot/` assistant text for the fused-token sentinels above.For `fineweb`/`fineweb-edu`, also check `date`/`dump` ranges and language scores;for Wikipedia, key on `(language, source_id)`.123version https://git-lfs.github.com/spec/v1oid sha256:90c29e7651d44539d4159319a5aab97b880e7b6504dc6d7d413de4e71f09012csize 239896251234{"type": "session", "harness": "opencode", "id": "math-0157", "name": "Dynamic Programming Mathematical Foundations"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain DP math foundations"}}
{"type": "message", "message": {"role": "assistant", "content": "Optimal substructure: optimal solution contains optimal solutions to subproblems.\nOverlapping subproblems: same subproblems solved repeatedly, memoize.\n\nKnapsack: dp[i][w] = max value using items 1..i with capacity w. O(nW). Space optimize to O(W).\ndp[j] = max(dp[j], dp[j-w_i]+v_i) iterating j backward (0-1) or forward (unbounded).\n\nLongest common subsequence: dp[i][j] = dp[i-1][j-1]+1 if s[i]==t[j], else max(dp[i-1][j],dp[i][j-1]).\nEdit distance: dp[i][j] = min operations to transform s[1..i] to t[1..j]. Insert/delete/replace.\n\nPartition problems: dp[sum] = true if subset sums to total/2.\nBitmask DP: dp[mask] for subset {0..n-1} represented by bitmask. TSP: O(n*2^n).\n\nMatrix chain multiplication: dp[i][j] = min cost to multiply matrices i..j. O(n^3).\nOptimal BST: dp[i][j] = min cost tree for keys i..j with probabilities.\n\nInterval DP: dp[i][j] = best for range [i,j]. Merge: dp[i][j] = min(dp[i][k]+dp[k+1][j]) for split k."}}1234{"type": "session", "harness": "opencode", "id": "math-0158", "name": "Euler Totient Function"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain Euler totient and applications"}}
{"type": "message", "message": {"role": "assistant", "content": "phi(n) = count of integers 1..n coprime to n. Formula: n * product(1-1/p) for prime factors p.\n\nTotient sieve O(n log log n): phi[i]=i, for each prime p: for j=p..n step p: phi[j] -= phi[j]/p.\n\nEuler theorem: a^{phi(n)} = 1 (mod n) when gcd(a,n)=1. Generalizes Fermat.\n\nApplications: RSA (e*d = 1 mod phi(n)), exponent reduction a^b mod n = a^{b mod phi(n)} mod n, necklace counting."}}1234{"type": "session", "harness": "opencode", "id": "math-0159", "name": "Extended Euclidean Algorithm Applications"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "What are the applications of the extended Euclidean algorithm?"}}
{"type": "message", "message": {"role": "assistant", "content": "1. MODULAR INVERSE: Find x such that a*x = 1 (mod m). Compute ext_gcd(a, m) -> (g, x, y). If g != 1, inverse doesn't exist. If g == 1, x is the inverse (reduce mod m).\n\n2. LINEAR DIOPHANTINE EQUATIONS: Solve ax + by = c. Has solution iff gcd(a,b) | c. Find particular solution (x0, y0) via ext_gcd, then general: x = x0 + k*(b/g), y = y0 - k*(a/g).\n\n3. FRACTION SIMPLIFICATION: Given p/q, compute g = gcd(p,q), return (p/g, q/g). Ext_gcd gives both the gcd and the Bezout coefficients.\n\n4. CHINESE REMAINDER THEOREM: Solve system x = a1 (mod m1), x = a2 (mod m2). Compute M = m1*m2, M1 = M/m1, M2 = M/m2. Find M1^{-1} mod m1 and M2^{-1} mod m2 via ext_gcd. Solution: x = a1*M1*M1^{-1} + a2*M2*M2^{-1} mod M.\n\n5. MODULAR ARITHMETIC: Compute a^{-1} mod p for prime p: ext_gcd(a, p) gives inverse directly.\n\n6. CONTINUED FRACTIONS: Ext_gcd coefficients relate to convergents of a/b.\n\n7. LATTICE REDUCTION: Ext_gcd is the 2D case of finding short vectors in lattices.\n\n8. RSA KEY GENERATION: Compute d = e^{-1} mod phi(n) using ext_gcd."}}1234{"type": "session", "harness": "opencode", "id": "math-0160", "name": "Extended Euclidean Algorithm Implementations"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Show extended Euclidean algorithm implementations"}}
{"type": "message", "message": {"role": "assistant", "content": "Recursive C++:\ntuple<long long, long long, long long> extgcd(long long a, long long b) {\n if (b == 0) return {a, 1, 0};\n auto [g, x, y] = extgcd(b, a % b);\n return {g, y, x - (a/b)*y};\n}\n\nIterative C++ (preferred, no stack overflow):\nlong long extgcd(long long a, long long b, long long &x, long long &y) {\n long long old_r = a, r = b;\n long long old_s = 1, s = 0;\n long long old_t = 0, t = 1;\n while (r != 0) {\n long long q = old_r / r;\n tie(old_r, r) = make_pair(r, old_r - q * r);\n tie(old_s, s) = make_pair(s, old_s - q * s);\n tie(old_t, t) = make_pair(t, old_t - q * t);\n }\n x = old_s; y = old_t;\n return old_r; // gcd\n}\n\nModular inverse:\nlong long modinv(long long a, long long m) {\n long long x, y;\n long long g = extgcd(a, m, x, y);\n if (g != 1) return -1; // no inverse\n return (x % m + m) % m;\n}\n\nLinear Diophantine:\nbool diophantine(long long a, long long b, long long c, long long &x, long long &y) {\n long long g = extgcd(a, b, x, y);\n if (c % g != 0) return false;\n x *= c/g; y *= c/g;\n return true;\n}"}}1234{"type": "session", "harness": "opencode", "id": "math-0161", "name": "Extended Euclidean Algorithm Deep Dive"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain the extended Euclidean algorithm in full detail"}}
{"type": "message", "message": {"role": "assistant", "content": "The Extended Euclidean Algorithm computes integers x, y such that ax + by = gcd(a, b).\n\nBASIS: When b = 0, gcd(a, 0) = a, and a*1 + 0*0 = a. So x=1, y=0.\n\nRECURSIVE STEP: Given gcd(b, a mod b) returns (g, x', y') where b*x' + (a mod b)*y' = g.\nSubstitute a mod b = a - floor(a/b)*b:\n b*x' + (a - floor(a/b)*b)*y' = g\n a*y' + b*(x' - floor(a/b)*y') = g\nSo x = y', y = x' - floor(a/b)*y'.\n\nIterative version (avoids recursion stack):\n old_r = a, r = b; old_s = 1, s = 0; old_t = 0, t = 1\n while r != 0:\n q = old_r / r\n (old_r, r) = (r, old_r - q*r)\n (old_s, s) = (s, old_s - q*s)\n (old_t, t) = (t, old_t - q*t)\n return old_r, old_s, old_t // gcd, x, y\n\nExample: a=35, b=15\n 35 = 2*15 + 5, 15 = 3*5 + 0. gcd=5.\n Back-substitute: 5 = 35 - 2*15. So x=1, y=-2.\n Verify: 35*1 + 15*(-2) = 35 - 30 = 5. Correct.\n\nSIGN PROPERTY: gcd(a,b) = a*x + b*y. x can be negative (y positive or vice versa). To get positive x: x += b/g, y -= a/g.\n\nUNIQUENESS: Solutions form a family: x' = x + k*(b/g), y' = y - k*(a/g) for any integer k. The algorithm returns the solution with |x| <= b/(2g) and |y| <= a/(2g) (nearly minimal).\n\nCOMPLEXITY: O(log(min(a,b))) steps. Each step is O(1) arithmetic on machine words. For big integers, O(M(n) * log(min(a,b))) where M(n) is multiplication time."}}1234{"type": "session", "harness": "opencode", "id": "math-0162", "name": "FFT and Number Theoretic Transform"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain FFT for competitive programming"}}
{"type": "message", "message": {"role": "assistant", "content": "FFT: multiply two degree-n polynomials in O(n log n) instead of O(n^2).\nIdea: evaluate at n-th roots of unity (O(n log n) via divide and conquer), multiply pointwise, interpolate back.\nCooley-Tukey: split by even/odd indices, recurse.\nIterative: bit-reverse permutation, then butterfly operations.\n\nNTT: FFT mod prime. Use primitive root g of prime p (e.g., 998244353, g=3). Replace complex roots with g^k mod p.\nAdvantage: exact integer arithmetic, no floating point errors.\n\nApplications:\n- Polynomial multiplication (coefficients = product of input polynomials)\n- String matching: pattern in text via convolution\n- Subset convolution\n- Multiplying large integers\n- Counting problems: ways to sum to target"}}1234{"type": "session", "harness": "opencode", "id": "math-0163", "name": "Network Flow Algorithms"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain max flow algorithms"}}
{"type": "message", "message": {"role": "assistant", "content": "Ford-Fulkerson: augmenting paths in residual graph. O(E*|max_flow|).\nEdmonds-Karp: BFS shortest augmenting path. O(VE^2).\nDinic's: blocking flow with BFS level graph + DFS. O(V^2*E), O(V*E) unit capacities.\nPush-relabel: O(V^2*E) worst, often faster. Preflow + push + relabel.\nMin-cut = max-flow theorem.\nApplications: bipartite matching (source->left, right->sink, cap=1), vertex cover, project selection, image segmentation."}}1234{"type": "session", "harness": "opencode", "id": "math-0164", "name": "Gaussian Elimination"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain Gaussian elimination"}}
{"type": "message", "message": {"role": "assistant", "content": "Solve Ax=b in O(n^3).\n\n1. Forward elimination: for each column, find pivot (largest abs for stability), swap rows, eliminate below.\n2. Back substitution: solve from last row upward.\n\nPartial pivoting: largest |A_{kk}| in column. Prevents div-by-zero, reduces error.\nFor determinant: elimination to upper triangular, det = product of diagonal (sign from swaps).\nFor inverse: [A|I] -> [I|A^{-1}] via elimination.\n\nModular: use modular inverse for division. Works over any field.\nO(n^3) time, O(n^2) space. Sparse matrices use iterative methods.\n\nApplications: solve equations, matrix rank, 2-SAT, inverse mod prime, determinant."}}1234{"type": "session", "harness": "opencode", "id": "math-0165", "name": "GCD Extended Euclidean Bezout"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain GCD algorithms and applications"}}
{"type": "message", "message": {"role": "assistant", "content": "Euclidean: gcd(a,b) = gcd(b, a mod b). O(log(min(a,b))).\n\nExtended Euclidean: find x,y with ax+by=gcd(a,b). Base: a*1+b*0=a when b=0. Recursive back-substitution.\n\nLCM: a/gcd(a,b)*b.\n\nApplications: modular inverse (ax+my=1), Diophantine equations (ax+by=c solvable iff gcd(a,b)|c), Bezout identity, coprimality check, fraction simplification."}}1234{"type": "session", "harness": "opencode", "id": "math-0166", "name": "Computational Geometry: 3D Operations"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain 3D computational geometry"}}
{"type": "message", "message": {"role": "assistant", "content": "3D point/vector: (x, y, z).\n\nCross product: a x b = (a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x). Magnitude = area of parallelogram.\n\nDot product: a.b = a.x*b.x + a.y*b.y + a.z*b.z.\n\nVolume of tetrahedron: |dot(a, cross(b, c))| / 6.\n\nPlane: ax+by+cz=d. Normal (a,b,c). Point-normal: dot(n, p-p0)=0.\n\nLine-plane intersection: substitute parametric line into plane equation.\n\nRay-triangle intersection: Moller-Trumbore algorithm. Uses barycentric coordinates.\n\nSphere: center + radius. Point in sphere: dist <= r.\n\n3D convex hull: gift wrapping O(n^2) or incremental O(n log n). Commonly used: QuickHull.\n\nAABB (axis-aligned bounding box): min/max corners. Fast intersection test.\n\nOBB (oriented bounding box): center + 3 axes + extents. SAT (separating axis theorem) for collision.\n\nBarycentric coordinates: point = u*A + v*B + w*C where u+v+w=1. For triangles: u,v,w >= 0 means inside."}}1234{"type": "session", "harness": "opencode", "id": "math-0167", "name": "Computational Geometry: Circles"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain circle algorithms for computational geometry"}}
{"type": "message", "message": {"role": "assistant", "content": "Circle: center (cx, cy), radius r.\n\nPoint in circle: distance(center, p) <= r.\nCircle-circle intersection: distance(c1,c2) compared to r1+r2 and |r1-r2|. Two intersection points if |r1-r2| < d < r1+r2.\n\nTangent lines from point to circle:\n- Point outside: two tangent lines. Compute angle to center, offset by arccos(r/d).\n- Point on circle: one tangent line perpendicular to radius.\n- Point inside: no tangent lines.\n\nInscribed circle (incircle): intersection of angle bisectors. For triangle with sides a,b,c: inradius r = area/s where s=(a+b+c)/2.\n\nCircumscribed circle (circumcircle): perpendicular bisectors of edges. For triangle: circumradius R = abc/(4*area).\n\nMinimum enclosing circle: Welzl's algorithm O(n) expected. Randomized incremental.\n\nCircle packing: arrange circles to maximize density. Hexagonal close packing: density pi/sqrt(12) ~ 0.9069."}}1234{"type": "session", "harness": "opencode", "id": "math-0168", "name": "Computational Geometry: Lines and Segments"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain lines and segments for computational geometry"}}
{"type": "message", "message": {"role": "assistant", "content": "Line representation:\n1. Point-slope: point p + direction d. p + t*d for t real.\n2. Implicit: ax + by = c. Normal vector (a,b). For points p1,p2: a=p2.y-p1.y, b=p1.x-p2.x, c=a*p1.x+b*p1.y.\n3. Segment: two endpoints [a,b]. Parameter t in [0,1].\n\nLine-line intersection: solve a1*x+b1*y=c1 and a2*x+b2*y=c2. Det = a1*b2-a2*b1. If det=0: parallel/coincident. Else: x=(c1*b2-c2*b1)/det, y=(a1*c2-a2*c1)/det.\n\nSegment intersection: check bounding boxes overlap, then cross products for proper intersection. Handle collinear cases.\n\nPoint on segment: cross(p-a, b-a)=0 and dot(p-a, p-b) <= 0.\n\nDistance from point to line: |cross(b-a, p-a)| / |b-a|.\nDistance from point to segment: project onto line, clamp to [0,1].\n\nPerpendicular bisector: midpoint of a,b, perpendicular to (b-a)."}}1234{"type": "session", "harness": "opencode", "id": "math-0169", "name": "Computational Geometry: Points and Vectors"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain point and vector operations for computational geometry"}}
{"type": "message", "message": {"role": "assistant", "content": "Point: (x, y). Vector: (dx, dy). Same representation, different semantics.\n\nOperations:\n- Addition: (a.x+b.x, a.y+b.y)\n- Subtraction: (a.x-b.x, a.y-b.y) gives vector from b to a\n- Scalar multiply: (a.x*c, a.y*c)\n- Dot product: a.x*b.x + a.y*b.y = |a||b|cos(theta). 0=perpendicular, >0=acute, <0=obtuse.\n- Cross product: a.x*b.y - a.y*b.x = |a||b|sin(theta). >0=b left of a, <0=b right of a, 0=collinear.\n- Length: sqrt(dot(a,a)). Squared length: dot(a,a) (avoids sqrt for comparisons).\n- Distance: sqrt(dot(a-b, a-b)).\n- Normalize: divide by length. Zero vector: special case.\n- Rotate 90 deg CCW: (-y, x). CW: (y, -x).\n- Angle between vectors: atan2(cross(a,b), dot(a,b)).\n- Projection of a onto b: (dot(a,b)/dot(b,b)) * b."}}1234{"type": "session", "harness": "opencode", "id": "math-0170", "name": "Computational Geometry: Polygons"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain polygon algorithms for computational geometry"}}
{"type": "message", "message": {"role": "assistant", "content": "Polygon: list of vertices in order (CW or CCW).\n\nArea (shoelace formula): A = 0.5 * |sum(x_i * y_{i+1} - x_{i+1} * y_i)|. Positive=CCW, negative=CW.\n\nPerimeter: sum of edge lengths.\n\nPoint in polygon:\n- Ray casting: shoot ray from point, count edge crossings. Odd=inside, even=outside.\n- Winding number: count signed angle traversed around point. Non-zero=inside.\n\nConvex hull:\n- Graham scan: sort by angle from lowest point, maintain stack, pop on right turn. O(n log n).\n- Monotone chain: sort by x then y, build upper/lower hull. O(n log n). Simpler.\n- Jarvis march: gift wrapping. O(nh) where h=hull size. Good when h is small.\n\nPolygon triangulation: ear clipping O(n^2). For convex: fan from vertex 0.\n\nRotating calipers: find diameter, width, minimum bounding rectangle of convex polygon in O(n).\n\nMinkowski sum: sum of two convex polygons. O(n+m). Used for collision detection."}}1234{"type": "session", "harness": "opencode", "id": "math-0171", "name": "Computational Geometry"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain computational geometry for competitive programming"}}
{"type": "message", "message": {"role": "assistant", "content": "Point/vector: struct with x,y. Operations: +, -, dot (a.x*b.x+a.y*b.y), cross (a.x*b.y-a.y*b.x).\nCross product: |a||b|sin(theta). Positive=left turn, negative=right, zero=collinear.\nDot product: |a||b|cos(theta). Zero=perpendicular.\n\nConvex hull: Graham scan O(n log n). Sort by angle, maintain stack, pop on right turn.\nLine intersection: solve 2x2 system. Two forms: point-slope or parametric.\nPolygon area: shoelace formula. Area = 0.5*|sum(x_i*y_{i+1} - x_{i+1}*y_i)|.\nPoint in polygon: ray casting or winding number.\nClosest pair: divide and conquer O(n log n).\nRotating calipers: diameter, width, min bounding rectangle of convex polygon.\nHalf-plane intersection: intersect n half-planes, O(n log n).\nCircle-circle intersection: up to 2 points.\nLine-circle intersection: substitute line into circle equation."}}1234{"type": "session", "harness": "opencode", "id": "math-0172", "name": "Geometric Primitives and Operations"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain geometric primitives for programming"}}
{"type": "message", "message": {"role": "assistant", "content": "struct Point { double x,y; };\ndot = a.x*b.x+a.y*b.y; cross = a.x*b.y-a.y*b.x;\nlen = sqrt(dot(a,a)); dist = sqrt(dot(a-b,a-b));\n\nLines: ax+by=c. Two-point form: cross(b-a,p-a)=0 for point p on line through a,b.\nIntersection of two lines (a1,b1,c1) and (a2,b2,c2): det=a1*b2-a2*b1. x=(c1*b2-c2*b1)/det, y=(a1*c2-a2*c1)/det.\n\nSegment intersection: check bounding boxes overlap, then cross products for proper intersection.\nPoint on segment: collinear and within bounding box.\n\nPolygon: vector of points. Area via shoelace. Contains point: ray casting (count crossings with ray from point).\n\nConvex polygon: all left turns. Binary search for point inside (monotone chain).\n\nCircle: center (cx,cy), radius r. Area = pi*r^2. Point in circle: dist <= r.\nInscribed circle: intersection of angle bisectors.\n\nEpsilon comparisons: fabs(a-b) < 1e-9 for floating point equality."}}1234{"type": "session", "harness": "opencode", "id": "math-0173", "name": "Graph Matrices and Spectral Theory"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain graph matrices and spectral graph theory"}}
{"type": "message", "message": {"role": "assistant", "content": "Adjacency matrix A: A[i][j]=1 if edge i-j. A^k[i][j] = number of paths length k from i to j.\n\nDegree matrix D: diagonal, D[i][i] = degree of vertex i.\n\nLaplacian L = D - A. Properties: L has eigenvalue 0 with multiplicity = number of connected components.\n\nFiedler vector: eigenvector for second-smallest eigenvalue of L. Used for graph partitioning (spectral bisection).\n\nKirchhoff's matrix tree theorem: number of spanning trees = any cofactor of L (delete row i, column i, take determinant).\n\nIncidence matrix B: B[i][j] = 1 if edge j starts at vertex i, -1 if it ends there. L = B*B^T.\n\nAlgebraic connectivity: second-smallest eigenvalue of L. Measures how well-connected the graph is.\n\nNormalized Laplacian: L_norm = D^{-1/2} L D^{-1/2}. Eigenvalues in [0,2]. Related to random walks.\n\nApplications: graph partitioning, clustering, connectivity analysis, spanning tree counting."}}1234{"type": "session", "harness": "opencode", "id": "math-0174", "name": "Graph Theory Algorithms"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain graph theory algorithms for competitive programming"}}
{"type": "message", "message": {"role": "assistant", "content": "BFS: shortest path unweighted. O(V+E). Queue-based layer-by-layer.\nDFS: cycle detection, connected components, topological sort, articulation points, bridges.\nDijkstra: shortest path non-negative weights. O((V+E) log V) with min-heap.\nBellman-Ford: shortest path with negative weights. O(VE). Relax all edges V-1 times.\nFloyd-Warshall: all-pairs shortest paths. O(V^3). dp[k][i][j] = min path i to j using 1..k.\nKruskal: MST. Sort edges O(E log E), union-find. Prim: MST. O((V+E) log V) with PQ.\nTopological sort: Kahn's BFS with in-degree or DFS post-order reverse.\nSCC: Tarjan's or Kosaraju's O(V+E)."}}1234{"type": "session", "harness": "opencode", "id": "math-0175", "name": "Linear Algebra for Programming"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain linear algebra for programming"}}
{"type": "message", "message": {"role": "assistant", "content": "Vector operations: dot, cross, norm, normalize, projection, reflection.\n\nMatrix operations: multiply O(n^3), transpose, determinant, inverse.\nMatrix-vector: Ax = linear combination of columns of A with weights x.\n\nDeterminant: |A| = 0 means singular (non-invertible). For 2x2: ad-bc. For nxn: cofactor expansion or Gaussian elimination.\n\nEigenvalues: Av = lambda*v. Characteristic polynomial det(A-lambda*I)=0.\nPower method: find dominant eigenvalue by iterating x_{k+1} = Ax_k / ||Ax_k||.\n\nSVD: A = U*Sigma*V^T. Sigma has singular values on diagonal. Rank = count of non-zero singular values.\n\nApplications:\n- Rotation matrices: 2D: [[cos,-sin],[sin,cos]]. 3D: Euler angles, quaternions.\n- PCA: eigendecomposition of covariance matrix. Dimensionality reduction.\n- Least squares: x = (A^T A)^{-1} A^T b. Normal equations.\n- Graph Laplacian: L = D - A. Eigenvalues relate to connectivity, spectral clustering.\n- PageRank: power iteration on modified adjacency matrix."}}1234{"type": "session", "harness": "opencode", "id": "math-0176", "name": "Matrix Operations and Exponentiation"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain matrix operations for programming"}}
{"type": "message", "message": {"role": "assistant", "content": "Matrix mult: (AB)_{ij} = sum(A_{ik}*B_{kj}). O(n^3).\nMatrix exponentiation: A^n in O(n^3 log n) via binary exponentiation.\n\nFibonacci O(log n): [[1,1],[1,0]]^n = [[F(n+1),F(n)],[F(n),F(n-1)]].\nGeneral: linear recurrence a_n = c1*a_{n-1}+...+ck*a_{n-k} uses k x k companion matrix.\n\nGaussian elimination O(n^3): solve Ax=b, find determinant. Row reduce to upper triangular, back-substitute.\n\nApplications: linear recurrences, graph paths (A^k[i][j] = paths i to j length k), Markov chains, system of equations, determinant (matrix tree theorem)."}}1234{"type": "session", "harness": "opencode", "id": "math-0177", "name": "Miller-Rabin Primality Test"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain Miller-Rabin primality testing"}}
{"type": "message", "message": {"role": "assistant", "content": "Based on Fermat: if n prime, a^{n-1} = 1 (mod n). But Carmichael numbers fool Fermat.\n\nMiller-Rabin enhancement: write n-1 = 2^r * d. Compute a^d mod n. If result is 1 or n-1, probably prime. Otherwise square r times: if any result is n-1, probably prime. If none, composite.\n\nWhy it works: if n is prime, the only square roots of 1 mod n are +1 and -1. Finding a non-trivial square root of 1 proves compositeness.\n\nDeterministic versions with known bases:\n- n < 2,047: test a=2\n- n < 1,373,653: test a=2,3\n- n < 9,080,191: test a=31,73\n- n < 25,326,001: test a=2,3,5\n- n < 3,215,031,751: test a=2,3,5,7\n- n < 3.3e24: test a=2,3,5,7,11,13\n\nImplementation: modular exponentiation with __int128 to avoid overflow.\n\nApplications: generate random large primes for RSA, verify primality in O(k log^2 n) with k tests."}}1234{"type": "session", "harness": "opencode", "id": "math-0178", "name": "Modular Arithmetic"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain modular arithmetic for competitive programming"}}
{"type": "message", "message": {"role": "assistant", "content": "Modular arithmetic: a = b (mod m) means m divides (a-b).\n\nOperations: (a+b) mod m = ((a mod m)+(b mod m)) mod m. Same for sub and mult.\nDivision: a/b mod m = a * b^{-1} mod m.\n\nModular inverse: b^{-1} mod m exists iff gcd(b,m)=1. Extended Euclidean: find x,y with bx+my=1, then x=b^{-1} mod m. O(log m).\n\nFermat: if p prime, a^{p-1} = 1 (mod p), so a^{-1} = a^{p-2} (mod p). Fast exponentiation O(log p).\n\nCRT: x = a_i (mod m_i) pairwise coprime -> unique solution mod M=product(m_i).\nx = sum(a_i * M_i * M_i^{-1}) mod M, M_i = M/m_i.\n\nApplications: counting mod 10^9+7, hashing, overflow avoidance."}}1234{"type": "session", "harness": "opencode", "id": "math-0179", "name": "Advanced Modular Arithmetic"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain advanced modular arithmetic techniques"}}
{"type": "message", "message": {"role": "assistant", "content": "Montgomery multiplication: convert a to Montgomery form a*R mod m where R=2^k. Multiplication in Montgomery form: REDC(a*b). Conversion back: REDC(a). Avoids expensive division by m.\n\nBarrett reduction: precompute mu = floor(2^k/m). q = floor(a*mu >> k). r = a - q*m. Adjust if r >= m.\n\nGarner's algorithm: reconstruct number from CRT residues without computing large product.\n\nHensel lifting: lift solutions mod p to mod p^k. If f(x)=0 mod p and f'(x)!=0 mod p, unique lift to mod p^2, etc.\n\nDiscrete logarithm: find x such that g^x = h (mod p). Baby-step giant-step: O(sqrt(p)) time and space.\n\nPrimitive root: generator g of (Z/pZ)*. Exists for all primes. Find by testing g^{(p-1)/q} != 1 for each prime factor q of p-1.\n\nQuadratic residues: x^2 = a (mod p) solvable iff a^{(p-1)/2} = 1 (mod p). Tonelli-Shanks algorithm for square roots mod p.\n\nApplications: Diffie-Hellman, ElGamal, discrete log crypto, quadratic residue proofs."}}1234{"type": "session", "harness": "opencode", "id": "math-0180", "name": "Modular Exponentiation and Multiplication"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain modular exponentiation and multiplication in detail"}}
{"type": "message", "message": {"role": "assistant", "content": "Modular exponentiation: compute a^b mod m.\n\nBinary method: result=1; a=a%m; while(b>0) { if(b&1) result=result*a%m; a=a*a%m; b>>=1; } O(log b) multiplications.\n\nModular multiplication: (a*b)%m. Naive: a*b may overflow 64-bit.\n\nMethods to avoid overflow:\n1. __int128: compiler extension. result = (__int128)a*b % m. Fastest on x86-64.\n2. Russian peasant: double-and-add. while(b>0) { if(b&1) result=(result+a)%m; a=(a+a)%m; b>>=1; } O(log b).\n3. Montgomery multiplication: convert to Montgomery form, multiply, convert back. Batch operations: efficient for many multiplications.\n4. Barrett reduction: precompute floor(2^k/m), use approximation to avoid division.\n\nModular inverse: a^{-1} mod m. Extended Euclidean: O(log m). Or a^{m-2} mod m when m prime (Fermat).\n\nChinese Remainder Theorem: combine results from multiple moduli.\n\nApplications: RSA encryption/decryption, fast hashing, competitive programming modular arithmetic."}}1234{"type": "session", "harness": "opencode", "id": "math-0181", "name": "Modular Inverse Computation"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain modular inverse computation methods"}}
{"type": "message", "message": {"role": "assistant", "content": "Modular inverse: a^{-1} mod m exists iff gcd(a,m)=1.\n\nMethods:\n1. Extended Euclidean: solve ax+my=1. x = a^{-1} mod m. O(log m). Works for any m.\n\n2. Fermat's little theorem: a^{-1} = a^{p-2} mod p when p prime. Uses fast exponentiation. O(log p). Only works for prime modulus.\n\n3. Euler's theorem: a^{phi(m)-1} = a^{-1} mod m when gcd(a,m)=1. More general than Fermat but slower to compute.\n\n4. Precomputation: for problems requiring many inverses mod p (prime), compute factorial[0..n], then inv_factorial[n] = factorial[n]^{p-2} mod p, work backwards: inv_factorial[i] = inv_factorial[i+1]*(i+1) mod p. O(n + log p).\n\n5. Batch: for inverses of 1..n mod p, use inv[i] = -(p/i)*inv[p%i] mod p. O(n) total.\n\nPerformance: method 1 is fastest for single inverse. Method 5 is fastest for batch. Method 2 is cleanest when p prime."}}1234{"type": "session", "harness": "opencode", "id": "math-0182", "name": "Numerical Methods"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain numerical methods for programming"}}
{"type": "message", "message": {"role": "assistant", "content": "Binary search: find x where f(x)=target. O(log n). Must have monotonic property. Watch overflow: mid = lo + (hi-lo)/2.\nTernary search: find extremum of unimodal function. O(log n). Compare f(mid1) and f(mid2) to narrow range.\nNewton's method: x_{n+1} = x_n - f(x_n)/f'(x_n). Quadratic convergence. Good for sqrt, inverse sqrt.\nIntegration: trapezoidal rule, Simpson's rule. Numerical derivatives.\nLinear algebra: Gaussian elimination O(n^3), LU decomposition for multiple solves.\nEigendecomposition: power iteration for dominant eigenvalue, QR algorithm for all.\nSVD: singular value decomposition for dimensionality reduction, least squares."}}1234{"type": "session", "harness": "opencode", "id": "math-0183", "name": "Number Theory Functions"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain number theory functions for programming"}}
{"type": "message", "message": {"role": "assistant", "content": "Divisor function sigma(n) = sum of divisors. sigma_0(n) = count of divisors. Compute by factoring: if n = p1^a1 * p2^a2, sigma_0 = (a1+1)(a2+1), sigma = product((p_i^{a_i+1}-1)/(p_i-1)).\n\nMobius function: mu(n) = 0 if n has squared prime factor, (-1)^k if k distinct primes, 1 if n=1. Sieve: mu[1]=1, for each prime p: mu[i*p] = -mu[i] if i%p!=0, 0 if i%p==0.\n\nMobius inversion: if g(n) = sum_{d|n} f(d), then f(n) = sum_{d|n} mu(d)*g(n/d).\n\nDirichlet convolution: (f*g)(n) = sum_{d|n} f(d)*g(n/d). Euler totient phi = mu * Id where Id(n)=n.\n\nSum of totients: sum_{i=1}^{n} phi(i) approx 3n^2/pi^2. Used in Euler's totient summatory function.\n\nCarmichael function: lambda(n) = smallest m such that a^m = 1 (mod n) for all coprime a. lambda(p^k) = phi(p^k) for odd p, 2^{k-2} for p=2 k>=3.\n\nApplications: competitive programming, RSA analysis, totient sums, divisor sums."}}1234{"type": "session", "harness": "opencode", "id": "math-0184", "name": "Numerical Methods for Programming"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain numerical methods"}}
{"type": "message", "message": {"role": "assistant", "content": "Binary search: find x where f(x)=target. O(log n). Must be monotonic. Handle overflow: mid = lo + (hi-lo)/2.\n\nTernary search: find extremum of unimodal function. Compare f(m1) and f(m2) where m1=lo+(hi-lo)/3, m2=hi-(hi-lo)/3.\n\nNewton's method: x_{n+1} = x_n - f(x_n)/f'(x_n). Quadratic convergence. Good for sqrt, inverse sqrt.\n\nIntegration: trapezoidal (error O(h^2)), Simpson's (error O(h^4)). Adaptive refinement.\n\nNumerical derivatives: forward: (f(x+h)-f(x))/h. Central: (f(x+h)-f(x-h))/(2h). Error O(h) vs O(h^2).\n\nEigendecomposition: power iteration, QR algorithm. For symmetric matrices: Jacobi method.\n\nSVD: for dimensionality reduction, least squares, pseudo-inverse.\n\nApplications: optimization, root finding, signal processing, machine learning."}}1234{"type": "session", "harness": "opencode", "id": "math-0185", "name": "Prime Counting and Distribution"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain prime counting functions and prime distribution"}}
{"type": "message", "message": {"role": "assistant", "content": "pi(n) = number of primes <= n. Prime number theorem: pi(n) ~ n/ln(n). More precise: li(n) = integral of dt/ln(t).\n\nMeissel-Lehmer algorithm: compute pi(n) in O(n^{2/3}/log^2(n)) time, O(n^{1/3} log^3 n) space. Uses combinatorial decomposition.\n\nLagarias-Miller-Odlyzko: O(n^{2/3}/log^2 n) time.\n\nPrime gaps: difference between consecutive primes. g_n = p_{n+1} - p_n. Average gap ~ ln(p_n). Twin prime conjecture: infinitely many primes with gap 2.\n\nBertrand's postulate: for n > 3, there's always a prime between n and 2n.\n\nChebyshev's theorem: there exist constants c1, c2 such that c1*n/ln(n) < pi(n) < c2*n/ln(n).\n\nDirichlet's theorem: for coprime a,d, there are infinitely many primes of form a + k*d.\n\nApplications: competitive programming (prime counting queries), cryptographic key generation, number theory research."}}1234{"type": "session", "harness": "opencode", "id": "math-0186", "name": "Prime Numbers and Sieves"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain prime number algorithms"}}
{"type": "message", "message": {"role": "assistant", "content": "Sieve of Eratosthenes O(n log log n): bool[] is_prime, for i=2..sqrt(n) if prime mark multiples.\n\nLinear sieve O(n): each composite marked once by smallest prime factor.\n\nPrime factorization: trial division O(sqrt(n)). Precompute SPF via sieve, factorize in O(log n).\n\nMiller-Rabin: deterministic for n < 3.3e24 with bases {2,3,5,7,11,13}. Uses modular exponentiation.\n\nApplications: sieve for SPF factorization, counting primes, Euler totient via sieve."}}1234{"type": "session", "harness": "opencode", "id": "math-0187", "name": "Expected Value and Linearity"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain expected value and linearity of expectation"}}
{"type": "message", "message": {"role": "assistant", "content": "Expected value E[X] = sum of x_i * P(X=x_i). For continuous: integral of x*f(x) dx.\n\nLinearity: E[aX+bY] = aE[X]+bE[Y] always (no independence needed). This is the most powerful property.\n\nCommon distributions:\n- Uniform on {1..n}: E = (n+1)/2\n- Bernoulli(p): E = p\n- Binomial(n,p): E = np\n- Geometric(p): E = 1/p (trials until first success)\n- Poisson(lambda): E = lambda\n\nIndicator random variables: I_A = 1 if event A occurs, 0 otherwise. E[I_A] = P(A). Use to convert probability to expectation.\n\nExample: expected edges in random graph G(n,p) = C(n,2)*p. By linearity, sum E[I_edge_exists] over all edges.\n\nVariance: Var(X) = E[X^2] - (E[X])^2. Var(aX) = a^2*Var(X). For independent X,Y: Var(X+Y) = Var(X)+Var(Y).\nStandard deviation = sqrt(Var(X))."}}1234{"type": "session", "harness": "opencode", "id": "math-0188", "name": "Monte Carlo and Randomized Algorithms"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain Monte Carlo methods and randomized algorithms"}}
{"type": "message", "message": {"role": "assistant", "content": "Monte Carlo integration: estimate integral by averaging f(x) for random x. Error O(1/sqrt(n)).\n\nRandomized algorithms:\n- Las Vegas: always correct, random runtime. Example: randomized quicksort O(n log n) expected.\n- Monte Carlo: fixed runtime, possibly wrong with small probability. Example: Miller-Rabin primality.\n\nApplications:\n- Random pivots for quicksort avoid worst-case O(n^2)\n- Random hashing for expected O(1) hash table operations\n- Bloom filters: false positive probability (1-e^{-kn/m})^k\n- HyperLogLog: cardinality estimation via harmonic mean\n- MinHash: Jaccard similarity estimation\n- Random projections: Johnson-Lindenstrauss for dimensionality reduction"}}1234{"type": "session", "harness": "opencode", "id": "math-0189", "name": "Probability and Expected Value"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain probability for programming"}}
{"type": "message", "message": {"role": "assistant", "content": "P(A) = favorable/total. P(A|B) = P(A and B)/P(B). Bayes: P(A|B) = P(B|A)*P(A)/P(B).\nLinearity of expectation: E[X+Y] = E[X]+E[Y] always (independent or not).\nGeometric distribution: expected trials until first success = 1/p.\nCoupon collector: expected draws to collect all n coupons = n*H_n = n*(ln n + gamma).\nMonte Carlo: estimate by sampling. Confidence interval shrinks as O(1/sqrt(n)).\nMarkov chain: state transitions with fixed probabilities. Steady state via eigenvector of transition matrix.\nRandom walks: expected steps to cover grid, Gambler's ruin problem."}}1234{"type": "session", "harness": "opencode", "id": "math-0190", "name": "Sieve of Eratosthenes"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain Sieve of Eratosthenes"}}
{"type": "message", "message": {"role": "assistant", "content": "Basic: bool is_prime[n+1] = true. For i=2..sqrt(n): if is_prime[i], mark multiples starting from i*i. O(n log log n) time, O(n) space.\n\nMemory optimization: bitset. 1 bit per number = n/8 bytes. For n=10^8, ~12MB.\n\nCache-friendly: segmented sieve. Process in blocks fitting L1/L2 cache. For n=10^10, process 1MB blocks.\n\nWheel optimization: skip multiples of 2,3,5. 8/30 wheel eliminates 73% of candidates. For primes up to 30: factors are 2,3,5. Residues mod 30 that are coprime: 1,7,11,13,17,19,23,29. Only check these offsets.\n\nPrefix-sum trick: after sieve, compute prefix sum pi(i) = count of primes up to i. Query count of primes in [l,r] in O(1).\n\nApplications: prime counting, generating prime list, precomputing for factorization, SPF sieve."}}1234{"type": "session", "harness": "opencode", "id": "math-0191", "name": "Linear Sieve and Variants"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain linear sieve and its variants"}}
{"type": "message", "message": {"role": "assistant", "content": "Linear sieve O(n): each composite marked exactly once by smallest prime factor (SPF).\n\nint primes[N], cnt, spf[N]; bool vis[N];\nfor(int i=2; i<=n; i++) {\n if(!vis[i]) { primes[cnt++]=i; spf[i]=i; }\n for(int j=0; j<cnt && i*primes[j]<=n; j++) {\n vis[i*primes[j]]=true; spf[i*primes[j]]=primes[j];\n if(i%primes[j]==0) break; // key: primes[j] is SPF of i\n }\n}\n\nWhy it works: when i%primes[j]==0, primes[j] divides i, so primes[j] is SPF of i*primes[j]. Breaking ensures we only mark each composite once.\n\nApplications of SPF: factorize any number in O(log n) by dividing by SPF repeatedly.\n\nPritchard sieve: O(n) time, O(sqrt(n)) space. Uses wheel + segmented approach. Complex but space-efficient for very large n.\n\nSundaram sieve: odd composite numbers. Numbers of form 4ij+2i+2j are composite. Sieve up to (n-2)/4.\n\nAtkin sieve: O(n/log log n) theoretically. Uses quadratic forms to identify primes. Not faster in practice than optimized Eratosthenes.\n\nSegmented sieve: process range [low, high] using primes up to sqrt(high). O((high-low) * log log(high)) + O(sqrt(high) log log(high))."}}1234{"type": "session", "harness": "opencode", "id": "math-0192", "name": "String Mathematics"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain string mathematics algorithms"}}
{"type": "message", "message": {"role": "assistant", "content": "KMP: pattern matching in O(n+m). Precompute failure function (longest proper prefix=suffix).\nZ-array: z[i] = longest substring starting at i matching prefix. O(n). Used for pattern matching.\n\nManacher: longest palindromic substring in O(n). Expand around centers with symmetry optimization.\n\nHashing: polynomial hash h(s) = s[0]*p^0 + s[1]*p^1 + ... mod m. Double hash for fewer collisions.\nSubstring hash: h[l..r] = (h[r] - h[l-1]*p^{r-l+1}) mod m.\n\nSuffix array: sort all suffixes in O(n log n) with radix sort or O(n log^2 n) with comparison.\nLCP array: longest common prefix between consecutive suffixes. Kasai's algorithm O(n).\nApplications: longest repeated substring, longest common substring, pattern matching.\n\nAho-Corasick: multiple pattern matching in O(n+m+k) where k=total pattern length.\nBuild trie + failure links (like KMP on trie)."}}1234{"type": "session", "harness": "opencode", "id": "math-0193", "name": "Topological Sort and DAG DP"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain topological sort and DAG dynamic programming"}}
{"type": "message", "message": {"role": "assistant", "content": "Kahn's: compute in-degree, enqueue all in-degree-0, dequeue and decrement neighbors, enqueue if 0. Detects cycles if count < n.\nDAG shortest path: process topological order, relax edges. O(V+E).\nDAG longest path: same with max.\nDAG DP: dp[v] = best reaching v, process in topo order, dp[v] = max(dp[v], dp[u]+w).\nApplications: build systems, course scheduling, critical path, package managers."}}1234{"type": "session", "harness": "deepseek-harness", "id": "math-0194", "name": "Graph algorithms"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}}
{"type": "message", "message": {"role": "user", "content": "What are the common graph algorithms?"}}
{"type": "message", "message": {"role": "assistant", "content": "```python\nfrom collections import defaultdict, deque\nimport heapq\n\n# BFS - shortest path (unweighted)\ndef bfs(graph, start, end):\n queue = deque([(start, [start])])\n visited = {start}\n while queue:\n node, path = queue.popleft()\n if node == end:\n return path\n for neighbor in graph[node]:\n if neighbor not in visited:\n visited.add(neighbor)\n queue.append((neighbor, path + [neighbor]))\n return None\n\n# DFS - cycle detection, topological sort\ndef dfs(graph, node, visited):\n visited.add(node)\n for neighbor in graph[node]:\n if neighbor not in visited:\n dfs(graph, neighbor, visited)\n\n# Dijkstra - shortest path (weighted)\ndef dijkstra(graph, start):\n distances = {node: float('inf') for node in graph}\n distances[start] = 0\n pq = [(0, start)]\n while pq:\n dist, node = heapq.heappop(pq)\n if dist > distances[node]:\n continue\n for neighbor, weight in graph[node]:\n new_dist = dist + weight\n if new_dist < distances[neighbor]:\n distances[neighbor] = new_dist\n heapq.heappush(pq, (new_dist, neighbor))\n return distances\n\n# Topological sort (Kahn's)\ndef topological_sort(graph):\n in_degree = {node: 0 for node in graph}\n for node in graph:\n for neighbor in graph[node]:\n in_degree[neighbor] += 1\n queue = deque([n for n in in_degree if in_degree[n] == 0])\n result = []\n while queue:\n node = queue.popleft()\n result.append(node)\n for neighbor in graph[node]:\n in_degree[neighbor] -= 1\n if in_degree[neighbor] == 0:\n queue.append(neighbor)\n return result\n```"}}1234{"type": "session", "harness": "deepseek-harness", "id": "math-0195", "name": "Dynamic programming patterns"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}}
{"type": "message", "message": {"role": "user", "content": "What are the common dynamic programming patterns?"}}
{"type": "message", "message": {"role": "assistant", "content": "```python\n# Fibonacci (memoization)\ndef fib(n, memo={}):\n if n in memo: return memo[n]\n if n <= 1: return n\n memo[n] = fib(n-1, memo) + fib(n-2, memo)\n return memo[n]\n\n# Knapsack (0/1)\ndef knapsack(weights, values, capacity):\n n = len(weights)\n dp = [[0] * (capacity + 1) for _ in range(n + 1)]\n for i in range(1, n + 1):\n for w in range(capacity + 1):\n dp[i][w] = dp[i-1][w]\n if weights[i-1] <= w:\n dp[i][w] = max(dp[i][w], dp[i-1][w-weights[i-1]] + values[i-1])\n return dp[n][capacity]\n\n# Longest Common Subsequence\ndef lcs(s1, s2):\n m, n = len(s1), len(s2)\n dp = [[0] * (n + 1) for _ in range(m + 1)]\n for i in range(1, m + 1):\n for j in range(1, n + 1):\n if s1[i-1] == s2[j-1]:\n dp[i][j] = dp[i-1][j-1] + 1\n else:\n dp[i][j] = max(dp[i-1][j], dp[i][j-1])\n return dp[m][n]\n\n# Coin change\ndef coin_change(coins, amount):\n dp = [float('inf')] * (amount + 1)\n dp[0] = 0\n for coin in coins:\n for i in range(coin, amount + 1):\n dp[i] = min(dp[i], dp[i - coin] + 1)\n return dp[amount] if dp[amount] != float('inf') else -1\n\n# Longest Increasing Subsequence\ndef lis(arr):\n tails = []\n for num in arr:\n if not tails or num > tails[-1]:\n tails.append(num)\n else:\n idx = bisect_left(tails, num)\n tails[idx] = num\n return len(tails)\n```"}}1234{"type": "session", "harness": "deepseek-harness", "id": "math-0196", "name": "Cryptography fundamentals"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}}
{"type": "message", "message": {"role": "user", "content": "What are the fundamentals of cryptography?"}}
{"type": "message", "message": {"role": "assistant", "content": "```\nSymmetric Encryption:\n- AES-256-GCM: authenticated encryption\n- ChaCha20-Poly1305: fast, constant-time\n- Use for: data at rest, bulk encryption\n\nAsymmetric Encryption:\n- RSA-2048+ or ECDSA (P-256, Ed25519)\n- Use for: key exchange, digital signatures\n\nHashing:\n- SHA-256, SHA-3: integrity verification\n- bcrypt/scrypt/Argon2: password storage\n- HMAC: message authentication\n\nKey Exchange:\n- Diffie-Hellman: secure key agreement\n- ECDH: elliptic curve variant\n\nDigital Signatures:\n- RSA-PSS, Ed25519: authenticity + non-repudiation\n\nPython examples:\n```python\nfrom cryptography.fernet import Fernet\nfrom cryptography.hazmat.primitives.asymmetric import rsa, padding\nfrom cryptography.hazmat.primitives import hashes\n\n# Symmetric encryption\nkey = Fernet.generate_key()\nf = Fernet(key)\nencrypted = f.encrypt(b\"secret message\")\ndecrypted = f.decrypt(encrypted)\n\n# RSA key pair\nprivate_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)\npublic_key = private_key.public_key()\n\n# Sign\nsignature = private_key.sign(data, padding.PKCS1v15(), hashes.SHA256())\n\n# Verify\npublic_key.verify(signature, data, padding.PKCS1v15(), hashes.SHA256())\n```\n```"}}1234{"type": "session", "harness": "deepseek-harness", "id": "math-0197", "name": "Statistics for data analysis"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}}
{"type": "message", "message": {"role": "user", "content": "What statistics do I need for data analysis?"}}
{"type": "message", "message": {"role": "assistant", "content": "```python\nimport numpy as np\nfrom scipy import stats\n\n# Descriptive statistics\ndata = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\nmean = np.mean(data)\nmedian = np.median(data)\nstd = np.std(data, ddof=1)\nvariance = np.var(data, ddof=1)\nskewness = stats.skew(data)\nkurtosis = stats.kurtosis(data)\n\n# Probability distributions\nnormal = stats.norm(loc=0, scale=1)\nnormal.pdf(0) # probability density\nnormal.cdf(1.96) # cumulative probability\nnormal.ppf(0.975) # inverse CDF\n\n# Hypothesis testing\n# t-test (compare two groups)\nt_stat, p_value = stats.ttest_ind(group1, group2)\n\n# Chi-square test (categorical)\nchi2, p_value, dof, expected = stats.chi2_contingency(observed_table)\n\n# ANOVA (compare multiple groups)\nf_stat, p_value = stats.f_oneway(group1, group2, group3)\n\n# Correlation\ncorr, p_value = stats.pearsonr(x, y)\nspearman_corr, p_value = stats.spearmanr(x, y)\n\n# Linear regression\nslope, intercept, r_value, p_value, std_err = stats.linregress(x, y)\n\n# Confidence intervals\nci = stats.t.interval(0.95, df=len(data)-1, loc=mean, scale=stats.sem(data))\n\n# Bootstrap\ndef bootstrap_ci(data, n_bootstrap=10000, ci=0.95):\n means = [np.mean(np.random.choice(data, len(data))) for _ in range(n_bootstrap)]\n return np.percentile(means, [(1-ci)/2*100, (1+ci)/2*100])\n```"}}1234{"type": "session", "harness": "deepseek-harness", "id": "math-0198", "name": "better pi series"}
{"type": "message", "message": {"role": "system", "content": "You're a helpful assistant"}}
{"type": "message", "message": {"role": "user", "content": "find a even more efficient way to calculate pi than the chudnovsky algorithm"}}
{"type": "message", "message": {"role": "assistant", "content": "Yes. There is a genuine higher-convergence alternative to Chudnovsky.\n\nThe **Berndt–Chan \\(m=3315\\) Ramanujan-type series** gives about **75.3178 decimal digits per term**, versus about **14.1816 digits/term** for Chudnovsky, so it needs about **5.31× fewer terms** for the same number of digits. \n\nA later Campbell preprint extends this family to about **153.8732 digits/term**, but that construction is substantially more complicated. ([arXiv][1])\n\nThat does **not** automatically mean it is 5× faster in wall-clock time. Chudnovsky's binary splitting and highly optimized multiplication are extremely effective, which is why record computations still use it. The latest y-cruncher record listed through 2025 was computed with its Chudnovsky machinery. ([Number World][2])\n\nAlso: **Gauss–Legendre / Brent–Salamin is much faster in convergence per iteration than Chudnovsky**, but there is an important catch: an iteration becomes substantially more expensive as the precision grows.\n\nThe algorithm is\n\n$$\na_0=1,\\qquad\nb_0=\\frac1{\\sqrt2},\\qquad\nt_0=\\frac14,\\qquad\np_0=1,\n$$\n\nand\n\n$$\na_{n+1}=\\frac{a_n+b_n}{2},\n$$\n\n$$\nb_{n+1}=\\sqrt{a_nb_n},\n$$\n\n$$\nt_{n+1}=t_n-p_n(a_n-a_{n+1})^2,\n$$\n\n$$\np_{n+1}=2p_n.\n$$\n\nThen\n\n$$\n\\boxed{\n\\pi=\\lim_{n\\to\\infty}\n\\frac{(a_n+b_n)^2}{4t_n}\n}\n$$\n\nand it has **quadratic convergence**. ([MathWorld][3])\n\n### Why it looks ridiculously fast\n\nThe AGM satisfies\n\n$$\na_{n+1}-b_{n+1}\n=O\\!\\left((a_n-b_n)^2\\right),\n$$\n\nso the error essentially squares every iteration.\n\nThus, roughly,\n\n$$\nD_{n+1}\\approx 2D_n,\n$$\n\nwhere \\(D_n\\) is the number of correct decimal digits.\n\nFor example, the first few approximations are\n\n$$\n3.1405792505221686\\ldots\n$$\n\n$$\n3.141592646213543\\ldots\n$$\n\n$$\n3.141592653589794\\ldots\n$$\n\nso only a handful of iterations already reaches ordinary floating-point precision.\n\n---\n\n## A useful proof of the quadratic convergence\n\nPut\n\n$$\nc_n=\\frac{a_n-b_n}{2}.\n$$\n\nSince\n\n$$\na_{n+1}=\\frac{a_n+b_n}{2},\n\\qquad\nb_{n+1}=\\sqrt{a_nb_n},\n$$\n\nwe have\n\n$$\na_{n+1}^2-b_{n+1}^2\n=\n\\left(\\frac{a_n+b_n}{2}\\right)^2-a_nb_n\n=\n\\frac{(a_n-b_n)^2}{4}\n=c_n^2.\n$$\n\nTherefore\n\n$$\na_{n+1}-b_{n+1}\n=\n\\frac{c_n^2}{a_{n+1}+b_{n+1}}.\n$$\n\nSince \\(a_n,b_n\\to M\\), where\n\n$$\nM=\\operatorname{AGM}\n\\left(1,\\frac1{\\sqrt2}\\right),\n$$\n\nwe obtain asymptotically\n\n$$\na_{n+1}-b_{n+1}\n\\sim\n\\frac{(a_n-b_n)^2}{8M}.\n$$\n\nHence\n\n$$\n\\boxed{\n|a_{n+1}-b_{n+1}|\n=\nO(|a_n-b_n|^2)\n}\n$$\n\nwhich is quadratic convergence.\n\nThe Brent–Salamin identity then gives\n\n$$\n\\boxed{\n\\pi\n=\n\\frac{4M^2}\n{1-\\displaystyle\\sum_{j=1}^{\\infty}2^{j+1}c_j^2}\n}\n$$\n\nwith\n\n$$\nM=\\operatorname{AGM}\n\\left(1,\\frac1{\\sqrt2}\\right).\n$$\n\nThis is equivalent to the \\(t_n\\) formulation above. ([MathWorld][3])\n\n---\n\n## But is it actually faster than Chudnovsky?\n\nFor **moderate precision**, AGM is extremely attractive.\n\nFor **huge precision**, not necessarily.\n\n| Algorithm | Convergence | Main expensive operation |\n| --------------- | ------------------------------------------: | ------------------------------------------ |\n| Chudnovsky | ~14.18 decimal digits/term | Large integer multiplication |\n| Gauss–Legendre | quadratic, roughly doubles digits/iteration | High-precision square root |\n| Borwein quartic | quartic | Several high-precision operations |\n| Borwein quintic | quintic | More complicated high-precision operations |\n\nThe amusing part is that **Chudnovsky has terrible-looking convergence by iteration count but excellent computational structure**. Binary splitting turns its series into large integer arithmetic that modern multiplication algorithms handle extremely well.\n\nSo:\n\n$$\n\\boxed{\\text{fewer iterations} \\neq \\text{faster computation}}\n$$\n\nwhich is one of those irritating cases where asymptotic convergence politely refuses to tell you the whole story.\n\nFor example, to obtain \\(10^6\\) digits, Gauss–Legendre only needs on the order of\n\n$$\n\\log_2(10^6)\\approx 20\n$$\n\niterations, but those iterations involve million-digit square roots. Chudnovsky needs roughly\n\n$$\n\\frac{10^6}{14.18}\\approx 70\\,500\n$$\n\nseries terms, but binary splitting makes those terms dramatically cheaper to aggregate.\n\nFor very large record computations, Chudnovsky-style binary splitting therefore remains highly competitive despite its lower convergence order.\n\n### One important terminology point\n\nThe **Gauss–Legendre algorithm for \\(\\pi\\)** is not the same thing as **Gauss–Legendre quadrature**. Here \"Gauss–Legendre\" refers to the AGM-based π algorithm, also called the **Brent–Salamin algorithm**. ([MathWorld][3])\n\nAnd if the actual goal is **\"find something genuinely better than Chudnovsky for arbitrary huge precision\"**, then the interesting direction is not Gauss–Legendre. It is the **quartic/quintic/high-order Borwein algorithms**, or the more recent higher-order modular identities. ([MathWorld][4])\n\n[1]: https://arxiv.org/abs/2403.07291 \"[2403.07291] An extension of the Chudnovsky algorithm\"\n[2]: https://www.numberworld.org/y-cruncher/?utm_source=chatgpt.com \"y-cruncher - A Multi-Threaded Pi Program\"\n\n[3]: https://mathworld.wolfram.com/Brent-SalaminFormula.html?utm_source=chatgpt.com \"Brent-Salamin Formula -- from Wolfram MathWorld\"\n[4]: https://mathworld.wolfram.com/PiIterations.html?utm_source=chatgpt.com \"Pi Iterations -- from Wolfram MathWorld\"\n"}}1234{"type": "session", "harness": "opencode", "id": "math-0199", "name": "Quadratic Formula"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain the quadratic formula and when to use it"}}
{"type": "message", "message": {"role": "assistant", "content": "For ax^2 + bx + c = 0 with a != 0, the solutions are x = (-b +- sqrt(b^2 - 4ac)) / (2a).\n\nDerivation: divide by a, complete the square on x^2 + (b/a)x, isolate the squared term, take square roots.\n\nExample: x^2 - 5x + 6 = 0 gives x = (5 +- sqrt(25 - 24)) / 2 = (5 +- 1)/2, so x = 3 or x = 2.\n\nUse it when factoring is not obvious. The quantity b^2 - 4ac is the discriminant: positive means two real roots, zero means one repeated root, negative means two complex roots."}}1234{"type": "session", "harness": "opencode", "id": "math-0200", "name": "Pythagorean Theorem"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain the Pythagorean theorem with an example"}}
{"type": "message", "message": {"role": "assistant", "content": "In a right triangle with legs a, b and hypotenuse c: a^2 + b^2 = c^2.\n\nExample: legs 3 and 4 give c = sqrt(9 + 16) = sqrt(25) = 5.\n\nConverse: if a^2 + b^2 = c^2 holds for a triangle's sides, the angle opposite c is a right angle. This is how builders check square corners (3-4-5 triangles).\n\nDistance formula connection: the distance between (x1,y1) and (x2,y2) is sqrt((x2-x1)^2 + (y2-y1)^2), which is the hypotenuse of the right triangle with those differences as legs."}}1234{"type": "session", "harness": "opencode", "id": "math-0201", "name": "Completing the Square"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain completing the square"}}
{"type": "message", "message": {"role": "assistant", "content": "Completing the square rewrites x^2 + bx as (x + b/2)^2 - (b/2)^2.\n\nExample: x^2 + 6x + 5 = 0 becomes (x + 3)^2 - 9 + 5 = 0, so (x + 3)^2 = 4, x + 3 = +-2, x = -1 or x = -5.\n\nUses: solving quadratics without the formula, converting to vertex form y = a(x - h)^2 + k to read off the vertex (h, k), and deriving the quadratic formula itself."}}1234{"type": "session", "harness": "opencode", "id": "math-0202", "name": "Factoring Quadratics"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain how to factor quadratics and special products"}}
{"type": "message", "message": {"role": "assistant", "content": "For x^2 + bx + c, find two numbers with product c and sum b. Example: x^2 + 7x + 12 = (x + 3)(x + 4).\n\nSpecial products:\n- Difference of squares: a^2 - b^2 = (a - b)(a + b). Example: x^2 - 9 = (x - 3)(x + 3).\n- Perfect square trinomial: a^2 + 2ab + b^2 = (a + b)^2.\n- Sum/difference of cubes: a^3 +- b^3 = (a +- b)(a^2 -+ ab + b^2).\n\nFor ax^2 + bx + c with a != 1, use grouping (ac method): multiply a*c, split bx accordingly, factor by grouping."}}1234{"type": "session", "harness": "opencode", "id": "math-0203", "name": "Exponent Rules"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain the rules of exponents"}}
{"type": "message", "message": {"role": "assistant", "content": "Core rules (a, b nonzero, m, n integers):\n- Product: a^m * a^n = a^(m+n)\n- Quotient: a^m / a^n = a^(m-n)\n- Power of power: (a^m)^n = a^(mn)\n- Power of product: (ab)^n = a^n b^n\n- Zero exponent: a^0 = 1\n- Negative exponent: a^(-n) = 1/a^n\n- Fractional: a^(1/n) = nth root of a; a^(m/n) = (nth root of a)^m\n\nExample: (2x^3)^2 * x^(-1) = 4x^6 / x = 4x^5.\n\nPitfall: (a + b)^2 is a^2 + 2ab + b^2, not a^2 + b^2."}}README.mdAdded+119
SCHEMA.mdAdded+95
math-dataset.tar.zstAdded+3
math/math-0157.jsonlAdded+4
math/math-0158.jsonlAdded+4
math/math-0159.jsonlAdded+4
math/math-0160.jsonlAdded+4
math/math-0161.jsonlAdded+4
math/math-0162.jsonlAdded+4
math/math-0163.jsonlAdded+4
math/math-0164.jsonlAdded+4
math/math-0165.jsonlAdded+4
math/math-0166.jsonlAdded+4
math/math-0167.jsonlAdded+4
math/math-0168.jsonlAdded+4
math/math-0169.jsonlAdded+4
math/math-0170.jsonlAdded+4
math/math-0171.jsonlAdded+4
math/math-0172.jsonlAdded+4
math/math-0173.jsonlAdded+4
math/math-0174.jsonlAdded+4
math/math-0175.jsonlAdded+4
math/math-0176.jsonlAdded+4
math/math-0177.jsonlAdded+4
math/math-0178.jsonlAdded+4
math/math-0179.jsonlAdded+4
math/math-0180.jsonlAdded+4
math/math-0181.jsonlAdded+4
math/math-0182.jsonlAdded+4
math/math-0183.jsonlAdded+4
math/math-0184.jsonlAdded+4
math/math-0185.jsonlAdded+4
math/math-0186.jsonlAdded+4
math/math-0187.jsonlAdded+4
math/math-0188.jsonlAdded+4
math/math-0189.jsonlAdded+4
math/math-0190.jsonlAdded+4
math/math-0191.jsonlAdded+4
math/math-0192.jsonlAdded+4
math/math-0193.jsonlAdded+4
math/math-0194.jsonlAdded+4
math/math-0195.jsonlAdded+4
math/math-0196.jsonlAdded+4
math/math-0197.jsonlAdded+4
math/math-0198.jsonlAdded+4
math/math-0199.jsonlAdded+4
math/math-0200.jsonlAdded+4
math/math-0201.jsonlAdded+4
math/math-0202.jsonlAdded+4
math/math-0203.jsonlAdded+4