DaYan 大衍
大衍之数五十,其用四十有九。 — The I Ching's Great Expansion generates structured hexagram states through a formal derivation procedure. DaYan does the same for LLM reasoning: it turns the reasoning process into structured data — a Thought Graph — and then analyzes it.
DaYan is a toolkit for modeling, evaluating, and enhancing LLM reasoning as data. Where standard evaluation only checks final answers, DaYan answers how the model reasoned — and feeds the findings back as improvements.
reasoning program (your code calling an LLM)
→ @analysis instrumentation (sys.settrace, no source changes)
→ program trace → data-flow graph → Thought Graph
(nodes = LLM outputs "thoughts", edges = data dependencies)
→ process evaluation: 5 metrics beyond accuracy
→ pattern mining: frequent thinking patterns (successful vs. failed)
→ enhancement: prompt rules / verifiable RL process rewards
An auxiliary subpackage, dayan.augment, provides symbolically verified
data augmentation (Logical DA): LLM-generated samples whose labels are
checked by Z3 / Prover9 / rule / CSP solvers before they enter your training
set.
Quickstart
from dayan import analysis, query, set_backend, AnalysisOutput
# Inject any LLM: (context, instruction, temperature) -> str
set_backend(my_llm_fn)
@analysis(output_type=AnalysisOutput.THOUGHT)
def solve(nums):
step = query("Add the numbers in {} and get [total]", nums) # LLM step
return int(step) * 2
result, thought_graph = solve([4, 4])
print(result) # program output
print(thought_graph.print_summary()) # nodes/edges of the reasoning process
Evaluate a cohort of reasoning runs:
from dayan import ThoughtSample, mine_frequent_patterns, reasoning_efficiency, stepwise_consistency
patterns = mine_frequent_patterns([g1, g2, g3], length=3, min_support=2)
print(reasoning_efficiency(patterns)) # κ (branching) / λ (first layer)
print(stepwise_consistency(ThoughtSample(g1, success=True, step_matches={...})))
Mine patterns from successful vs. failed runs and turn them into prompt rules or RL process rewards:
from dayan import contrastive_patterns, patterns_to_prompt_rules, PatternProcessReward
good, bad = contrastive_patterns(success_graphs, failure_graphs)
rules = patterns_to_prompt_rules(good, bad) # inject into prompts
reward_fn = PatternProcessReward(good, bad) # per-step RL reward
reward = reward_fn(label_sequence_of_a_trajectory)
Verified data augmentation
dayan augment --dataset records.json --output augmented.json --solver z3
The pipeline (attribute extraction → diversity filtering → label-flipped
generation → symbolic verification → reflection) runs on any OpenAI-compatible
endpoint; DAYAN_API_KEY / DAYAN_BASE_URL / DAYAN_MODEL configure it
(falling back to OPENAI_*). An Anthropic-messages endpoint (e.g. K3) works
via DAYAN_BACKEND=anthropic. Solvers: z3, prover9, rules, csp
(auto-detected), with an llm fallback.
Measured end-to-end (K3 endpoint)
| Suite | Result |
|---|---|
| Instrumented reasoning smoke | program → 4-node Thought Graph, correct answer, metrics on the real trace |
| Game24 thought mining (6 puzzles, single-shot) | 0.83 accuracy; multipath reliability gain +0.17; SCS 1.00 |
| Metric discrimination (synthetic) | branched κ=3.00 vs linear κ=1.00 — efficiency metric separates backtracking from chains |
| Logical DA on RTE-style samples | 4 inputs → 11 generated, 7/11 verified by Z3 (symbolic), 5 rejected |
Installation
pip install -e . # core is dependency-free
pip install -e ".[llm]" # optional OpenAI SDK backend (stdlib works too)
pip install -e ".[augment]" # z3-solver for label verification
pip install -e ".[dev]" # tests + lint
Research lineage
- Thought Mining for Large Language Model Reasoning — the Thought Graph data model, the five process metrics, and both enhancement strategies.
- Logical DA (ACL 2025 Findings) — multi-agent data augmentation with symbolic label verification.
If you use DaYan, please cite these works (see CITATION.cff).
License
Apache-2.0 (see LICENSE).
Metadata
Release files for dayan 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dayan-0.2.0.tar.gz | 67.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dayan-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 135.1 kB
Release files / dayan-0.2.0.tar.gz
| Download URL | dayan-0.2.0.tar.gz |
|---|---|
| Size | 67.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3c34135e7ecddd2ee81dadb226e6dd1b96bfa11295559156d4d153f922faa903
|
|
BLAKE2b-256 checksum How to use checksums |
efe4517b27f4c273e64f7264e501257406c8490ca1db524b580340159cc4339f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.
Transparency logRelease files / dayan-0.2.0-py3-none-any.whl
| Download URL | dayan-0.2.0-py3-none-any.whl |
|---|---|
| Size | 67.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
06100a257945636adb224e90dcb67be5ed061542b4e19b86788f83204dd9a2ad
|
|
BLAKE2b-256 checksum How to use checksums |
8027e5f7d5a896578533d4e730569b436833b78573ca74d1de2e2b03f80eed09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.
Transparency log