Get the FREE Ultimate OpenClaw Setup Guide →

Logic Convert

npx machina-cli add skill NewJerseyStyle/plugin-logic-llm/logic-convert --openclaw
Files (1)
SKILL.md
5.9 KB

/logic-convert

Convert natural language documents into symbolic logic programs.

Description

This skill translates natural language text, rules, regulations, or knowledge bases into formal logic programs that can be used for automated reasoning. It follows the Logic-LLM methodology with enhancements for persistent storage and code reuse.

Supported Formats

FormatSolverBest For
prologprolog-mcpDeductive reasoning, Horn clauses
clingoclingo-mcpConstraints, optimization, ASP
z3z3smt-mcpArithmetic, SMT, satisfiability
folfolprover-mcpFirst-order logic with quantifiers
pykepyke-mcpForward/backward chaining, Python

Usage

/logic-convert [options] <source>

Options

  • --format <prolog|clingo|z3|fol|pyke> - Target format (default: auto-detect)
  • --output <path> - Output file path for generated logic program
  • --append - Append to existing knowledge base instead of creating new
  • --register - Auto-register predicates in the registry
  • --domain <name> - Domain name for organizing predicates (e.g., "legal", "medical")
  • --validate - Validate generated code with solver before saving
  • --dmn-compatible - Generate DMN-compatible Prolog (only with --format prolog)
  • --test - Generate and run test cases using MCP server

Examples

/logic-convert --format prolog ./contracts/terms.txt
/logic-convert --format clingo --domain legal ./regulations/
/logic-convert --format z3 ./scheduling-constraints.txt
/logic-convert --format fol --register ./logical-premises.md
/logic-convert --format pyke ./inference-rules.txt
/logic-convert --append --register ./new-rules.md

# DMN-compatible Prolog with validation
/logic-convert --format prolog --dmn-compatible --test ./decision-table.txt
/logic-convert --format prolog --dmn-compatible --validate --output ./dmn_rules.pl ./rules.md

Format Selection Guide

Choose format based on problem type:

Problem TypeRecommended Format
Deductive reasoning (if-then chains)prolog or pyke
Constraints with optimizationclingo
Arithmetic constraintsz3
Full first-order logic (∀, ∃)fol
Analytical reasoning (LSAT)z3
Legal/policy with exceptionsclingo or prolog
Python integration neededpyke

Behavior

  1. Document Analysis: Read and parse the input document(s)
  2. Problem Classification: Determine best solver if format not specified
  3. Predicate Extraction: Identify entities, relationships, and rules
  4. Registry Check: Look up existing predicates to ensure consistency
  5. Code Generation: Generate code following Logic-LLM methodology
  6. Self-Refinement: Fix errors using solver feedback (up to 3 attempts)
  7. Registration: Register new predicates, facts, and rules in the registry
  8. Validation: Syntax-check the generated code using the appropriate solver

Output

The skill generates:

  • Logic program file(s) in the specified format
  • Registry entries for new predicates and rules
  • Conversion report with mapping from natural language to logic

Integration

This skill uses:

  • prolog-mcp for Prolog validation
  • clingo-mcp for Clingo/ASP validation
  • z3smt-mcp for Z3/SMT validation
  • folprover-mcp for FOL validation
  • pyke-mcp for Pyke validation
  • logic-registry MCP server for predicate registration
  • Stored prompt templates from prompts/ directory

DMN Compatibility Mode

When using --dmn-compatible with Prolog, the generator follows Decision Model and Notation (DMN) constraints:

DMN Constraints

  1. Horn Clauses Only: No negation-as-failure (+, not)
  2. Deterministic Rules: Single solution per input (uses cuts)
  3. Simple Data Types: Atoms, numbers, strings only
  4. Decision Table Structure: Rules map to decision table rows
  5. Limited Recursion: Maximum depth of 3 levels
  6. FEEL Compatibility: Compatible with FEEL expression language

DMN Validation Checks

The --dmn-compatible flag enforces:

  • ✓ All rules are Horn clauses
  • ✓ No NAF predicates
  • ✓ Deterministic output (cut placement)
  • ✓ Simple data types
  • ✓ Recursion depth ≤ 3

Testing with prolog-mcp

When --test is specified, the skill:

  1. Generates test cases for all rules
  2. Loads program into prolog-mcp
  3. Verifies determinism (single solution per input)
  4. Checks for NAF usage
  5. Validates recursion depth
  6. Reports any DMN compliance violations

Example: DMN-Compatible Credit Approval

Input Document:

Approve credit if:
- Credit score >= 700 and income >= 50000
- Credit score >= 650 and income >= 75000 and employment >= 3 years
Otherwise reject.

Generated Prolog:

% Decision Table: Credit Approval
approve_credit(Score, Income, _) :- Score >= 700, Income >= 50000.
approve_credit(Score, Income, Years) :- Score >= 650, Income >= 75000, Years >= 3.

credit_decision(Score, Income, Years, approved) :- approve_credit(Score, Income, Years), !.
credit_decision(_, _, _, rejected).

Test Output:

✓ DMN Compliance: PASS
✓ Determinism: PASS (1 solution per input)
✓ No NAF: PASS
✓ Recursion: PASS (no recursion)
✓ Data Types: PASS (numbers, atoms only)

Test Cases:
  credit_decision(750, 60000, 2, approved) - PASS
  credit_decision(680, 80000, 4, approved) - PASS
  credit_decision(550, 40000, 1, rejected) - PASS

Notes

  • For documents exceeding context limits, the skill processes in chunks and maintains consistency through the registry
  • Generated code follows naming conventions from the registry to avoid duplicates
  • Use --append when adding to an existing knowledge base to maintain referential integrity
  • Auto-detection analyzes problem for quantifiers, arithmetic, constraints to choose best format
  • DMN compatibility is only available for Prolog format
  • Testing with --test requires the appropriate MCP server to be enabled and running

Source

git clone https://github.com/NewJerseyStyle/plugin-logic-llm/blob/main/skills/logic-convert/SKILL.mdView on GitHub

Overview

Logic Convert translates natural language documents—rules, regulations, or knowledge bases—into formal logic programs for automated reasoning. It follows the Logic-LLM methodology with enhancements for persistent storage, code reuse, and registry integration.

How This Skill Works

The system performs document analysis, problem classification, predicate extraction, and registry checks, then generates a format-specific logic program using the Logic-LLM approach. It can self-refine with solver feedback (up to three attempts) and optionally validate, register, and store the results for reuse.

When to Use It

  • You need to turn contractual terms, policies, or knowledge-base text into formal rules (Prolog, Clingo, Z3, etc.) for automated reasoning.
  • You require constraints and optimization expressed as logic programs (Clingo) or DMN-ready Prolog.
  • You want to build a reusable knowledge base with persistent storage and predicate registration.
  • You are dealing with first-order logic (∀, ∃) or arithmetic constraints and want corresponding formats (Fol/Z3).
  • You need Python integration or forward/backward chaining with Pyke, or standard logic formats.

Quick Start

  1. Step 1: Prepare a natural language document and select a target format (prolog, clingo, z3, fol, or pyke).
  2. Step 2: Run /logic-convert --format <format> <source> (optionally add --domain, --register, --validate).
  3. Step 3: Validate the output, register new predicates, and review the generated logic and report.

Best Practices

  • Define a domain with --domain to scope predicates and keep mappings organized.
  • Use --validate to catch solver errors before saving the generated code.
  • Use --register to auto-register new predicates in the registry for reuse.
  • Give predicates expressive, human-readable names that map clearly to NL phrases.
  • Iterate with self-refinement (up to 3 solver-driven fixes) to improve correctness.

Example Use Cases

  • Convert contract terms into Prolog Horn clauses for deductive legal reasoning.
  • Translate regulations into Clingo rules to express constraints and policy checks.
  • Encode scheduling or arithmetic constraints into Z3 for SMT solving.
  • Express full first-order logic statements with FOL prover rules in Fol.
  • Generate Python-based inference rules for Pyke to enable forward/backward chaining.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers