bbkdevops's picture
download
raw
2.55 kB
"""Deterministic logic core for TinyMind tool-augmented reasoning."""
from __future__ import annotations
from dataclasses import dataclass
import json
import re
@dataclass(frozen=True)
class LogicResult:
ok: bool
answer: str
rule: str
confidence: float
proof_steps: list[str]
def to_dict(self) -> dict:
return {
"ok": self.ok,
"answer": self.answer,
"rule": self.rule,
"confidence": self.confidence,
"proof_steps": self.proof_steps,
}
class TinyLogicCore:
"""Small symbolic reasoner for high-precision logic gates."""
def solve(self, question: str) -> dict:
q = question.lower()
if "p implies q" in q and "p is true" in q:
return LogicResult(
True,
"Q is true",
"modus_ponens",
1.0,
["Premise: P -> Q", "Premise: P", "By modus ponens, Q follows."],
).to_dict()
if "equivalent" in q and "if p then q" in q:
return LogicResult(
True,
"if not Q then not P",
"contrapositive_equivalence",
1.0,
["Original: P -> Q", "Contrapositive: not Q -> not P", "These are logically equivalent."],
).to_dict()
if "evidence is missing" in q and ("answer only" in q or "policy" in q):
return LogicResult(
True,
"Refuse or ask for evidence",
"evidence_policy",
1.0,
["Rule: answer only when evidence exists.", "Fact: evidence is missing.", "Therefore do not assert; refuse or request evidence."],
).to_dict()
if "cannot both be true" in q or "contradiction" in q:
return LogicResult(
True,
"Find the minimal conflicting pair",
"contradiction_repair",
0.95,
["Contradiction means at least two claims conflict.", "Repair begins by locating the minimal conflicting pair."],
).to_dict()
return LogicResult(
False,
"insufficient formal pattern",
"no_rule_matched",
0.0,
["No deterministic rule matched the question; route to source-grounded research or model reasoning."],
).to_dict()
def solve_logic_json(question: str) -> str:
return json.dumps(TinyLogicCore().solve(question), ensure_ascii=False, sort_keys=True)

Xet Storage Details

Size:
2.55 kB
·
Xet hash:
1a13942e975aea82d35f142eae74378161931060e6a03447a161b04cfbf9dc27

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.