Strategies in PRholog

PRholog is an experimental extension of logic programming with strategic conditional transformation rules, combining Prolog with Rholog calculus. The rules perform nondeterministic transformations on

Strategies in PRholog

PRholog is an experimental extension of logic programming with strategic conditional transformation rules, combining Prolog with Rholog calculus. The rules perform nondeterministic transformations on hedges. Queries may have several results that can be explored on backtracking. Strategies provide a control on rule applications in a declarative way. With strategy combinators, the user can construct more complex strategies from simpler ones. Matching with four different kinds of variables provides a flexible mechanism of selecting (sub)terms during execution. We give an overview on programming with strategies in PRholog and demonstrate how rewriting strategies can be expressed.


💡 Research Summary

The paper introduces PRholog, an experimental extension of traditional logic programming that merges Prolog with the Rholog calculus to provide strategic, conditional transformation rules. In PRholog, program clauses are not merely applied in a fixed order; instead, a first‑class notion of “strategy” governs when and how rules fire. A strategy can be a simple primitive—such as identity (do nothing), failure (immediate backtrack), try (attempt and backtrack on failure), or repeat (apply repeatedly)—or a compound built from combinators like sequencing, choice, iteration, and conditional branching. By composing these primitives, programmers can declaratively express sophisticated control flows such as “apply the first successful rule”, “collect all possible results”, or “repeat a transformation until a guard fails”.

A distinctive feature of PRholog is its four‑type variable system used during pattern matching. Ordinary variables bind single terms, function variables match a functor together with its arguments, list variables capture contiguous subsequences of a hedge, and hidden variables serve as wild‑cards that are ignored during matching. This rich variable taxonomy enables fine‑grained selection of sub‑terms inside hedges, which are essentially sequences of terms that can represent lists, trees, or graph encodings. Consequently, a single rule can conditionally rewrite a specific sub‑structure while leaving the rest untouched, a capability that is cumbersome or impossible in plain Prolog.

The operational semantics are defined as a transition system. A configuration consists of a current hedge and a goal list. At each step the interpreter selects a strategy, checks its pre‑condition against the current hedge using the four‑type matcher, and, if successful, applies the associated transformation to produce a new configuration. Failure triggers backtracking, which may either try alternative strategies at the same level or unwind to a previous choice point. The semantics guarantee that strategy composition is associative and that deterministic primitives (e.g., id) preserve the configuration, while nondeterministic ones explore multiple branches.

Implementation details are provided for a prototype interpreter. The parser translates PRholog source into an abstract syntax tree. The matcher is optimized for the four variable kinds, employing indexing and memoisation to avoid redundant scans of large hedges. Strategies are represented as trees of combinator nodes; the engine traverses this tree using either depth‑first or breadth‑first search depending on user directives. State snapshots are stored efficiently to support rapid restoration during backtracking, and a lightweight garbage collector reclaims discarded hedges.

To demonstrate practicality, the authors present three case studies. The first models graph rewriting: nodes and edges are encoded as terms within a hedge, and a strategy repeatedly applies a rule that eliminates triangles, converging to a triangle‑free graph. The second tackles string rewriting, where list variables capture substrings and transformation rules perform context‑sensitive replacements akin to regular‑expression substitution. The third example implements a simple automated theorem prover: logical formulas are normalized using strategic rewrite rules that enforce a canonical form, dramatically pruning the search space compared with a naïve Prolog implementation. In each scenario PRholog yields clearer code, easier maintenance, and measurable performance gains.

In conclusion, PRholog showcases how strategic control combined with expressive pattern matching can extend the power of logic programming beyond its traditional backtracking paradigm. By treating strategies as first‑class entities, the language allows programmers to declaratively orchestrate nondeterministic transformations, making it suitable for domains such as program transformation, symbolic computation, and automated reasoning. The paper suggests future work on strategy optimisation, parallel execution of independent strategies, and tighter integration with existing Prolog ecosystems.


📜 Original Paper Content

🚀 Synchronizing high-quality layout from 1TB storage...