Theory Part 6

End-to-End Reasoning Flow

How CNL text becomes a compiled KB, rule plans, and explainable results.

Pipeline Diagram

The pipeline is deterministic: each stage produces a single output or a single error. The diagram below shows the canonical flow used by all pragmatics.

CNL-PL pipeline CNL text is tokenized, parsed into an AST, compiled into a KB and plans, and executed by pragmatics to produce results. CNL Text Tokens AST KB + Plans Pragmatics Results

Scenario: packages, weight, and priority

The example below includes numeric attributes, a rule, and a query. It shows how the same AST leads to both KB inserts and rule plans, and how explain uses provenance.

Every package whose weight is greater than 500 is heavy.
Every package that is heavy and that is assigned to a route is priority.

Package_1 has a weight of 600.
Package_2 has a weight of 300.
Package_1 is assigned to Route_9.
Package_2 is assigned to Route_9.

Command: Return the name of every package that is priority.
Command: Explain why Package_1 is priority.

Scenario: planning and solving

This example mixes an action block with a planning goal and a solve-style query. The goal is to assign a driver to a route using a simple action description.

Action: assign a driver to a route.
Agent: a dispatcher.
Precondition: a driver is available and the route is unassigned.
Effect: the driver is assigned to the route.

Driver_1 is available.
Driver_2 is available.
Route_9 is unassigned.

Command: Plan to achieve Route_9 is assigned to a driver.
Command: Find a driver such that the driver is available and the driver is assigned to Route_9.

The plan command compiles into a search over actions, while the find command compiles into a constraint-style selection over the KB state.

Expected outputs: the plan returns an ordered list of actions, while the find command returns the matching entities or bindings that satisfy the condition.

Scenario: optimize and simulate

This example shows an optimization goal and a short simulation. The optimization chooses the best feasible route, while simulation applies transition rules over steps.

Route_1 has a cost of 120.
Route_2 has a cost of 90.
Route_3 has a cost of 140.

Rule: A route is feasible if the route is available.
Route_1 is available.
Route_2 is available.

Command: Minimize the cost of the route such that the route is feasible.

Rule: When a delay occurs, then the route is delayed.
Command: Simulate 3 steps.

The minimize command compiles into a numeric objective over the feasible set. The simulate command applies the transition rule for three steps over the current state overlay.

Expected outputs: minimize returns the chosen route and its objective value, while simulate returns the state snapshots or final state after the requested steps.

What compilation produces

Compilation splits the input into ground facts and non-ground plans. The facts update the KB immediately, while the rules and commands compile into executable plans.

  • Numeric facts insert into the NumericIndex for the attribute weight.
  • The rule on heavy compiles into a numeric filter plan using a comparator.
  • The rule on priority compiles into a join between heavy and assigned to.
  • The return command compiles into a SetPlan that filters packages by priority.
  • The explain command targets the justification chain for priority(Package_1).

State and overlays

Planning and simulation operate on a state overlay rather than mutating the base KB. Each step produces a delta of added or removed facts, which can be committed or discarded.

  • Base state: the compiled KB facts and indexes.
  • Delta layer: temporary inserts/removals for a plan or simulation step.
  • Overlay: the logical union of base plus delta, used for queries and preconditions.

Reasoning steps

During reasoning, the runtime uses bitsets for speed and determinism:

  • Compute Heavy by filtering packages where weight > 500.
  • Compute Priority by intersecting Heavy with the preimage of assigned to.
  • Return the resulting entity set, then project the name field for output.
  • For explain, walk the justification DAG that records the rule and its premises.