Structure + Strategy based problem-solving framework for Lua.
Problem-solving can be fully modeled as Structure (immutable data skeleton) + Strategy IF (swappable algorithms).
Problem
├── KnownFact ... known facts with confidence (soft: 0.0-1.0)
├── Gap ... knowledge holes (information completeness)
├── Constraint ... conditions the solution must satisfy
├── Hypothesis ... solution candidates
│ └── Evidence ... support/contradict + independence group
├── Confidence ... value + volatility + basis
└── Solution ... synthesized solution + constraint results
| # | Strategy | Responsibility |
|---|---|---|
| 1 | GapDetection | Detect missing information |
| 2 | GapResolution | Resolve missing information |
| 3 | Decompose | Break into sub-problems |
| 4 | HypothesisGen | Generate hypotheses (Adversarial, DeltaAware, etc.) |
| 5 | EvidenceEval | Evaluate evidence (Selective, IndependenceWeighted, etc.) |
| 6 | ConstraintVerify | Check constraint satisfaction |
| 7 | Synthesize | Synthesize hypotheses into solution |
| 8 | Merge | Merge sub-solutions |
| 9 | Continuation | Continue/stop decision |
| 10 | ReEvaluate | Re-evaluate on information change |
| 11 | HypothesisSelection | Budget-limited evaluation (Greedy, UCB1, Thompson) |
luarocks install lua_solverOr clone directly:
git clone https://github.com/ynishi/lua-solver.git lua_solverNote: The directory must be named lua_solver (underscore) for require("lua_solver") to work. The -o target in the clone command handles this. If you already cloned, rename:
mv lua-solver lua_solverlocal solver = require("lua_solver")
-- Define a problem
local problem = solver.Problem {
statement = "Which database should we use?",
known = {
scale = solver.KnownFact { value = "10M users", confidence = 0.9 },
budget = "limited", -- auto-wrapped as KnownFact(confidence=0.9)
},
gaps = {
{ "read_write_ratio", "What is the read/write ratio?" },
{ "latency_req", "What is the latency requirement?" },
},
constraints = {
"Must handle 10M users",
"Budget under $1000/month",
},
}
-- Create engine with default strategies
local engine = solver.new()
-- Or swap strategies
local engine = solver.new({
hypothesis_gen = solver.strategies.hypothesis_gen.DeltaAware,
re_evaluate = solver.strategies.re_evaluate.DecayBased,
})Default implementation uses Claude Code CLI in Headless Mode (claude -p).
-- Configure the default backend
solver.llm.configure({
claude_path = "/usr/local/bin/claude",
model = "sonnet",
})
-- Or replace the call function entirely
solver.llm.call = function(prompt)
-- your custom LLM API call
return result, nil, "call-id"
endlua lua_solver/test.luaOver 100 unit tests, no LLM required.
MIT