RewritingSystem
struct RewritingSystem<Term> : Sendable where Term : RewritingTerm
A set of rewriting rules describing some equational equivalences.
-
The identifier of a rule in a rewriting system.
Declaration
Swift
typealias RuleID = Int -
The rules in the system, including those that may have been simplified.
Declaration
Swift
private(set) var rules: [RewritingRule<Term>] { get } -
A map from terms to the rule of which they are the left-hand side.
Declaration
Swift
private var termToRule: Trie<Term, RuleID> -
Creates an empty system.
Declaration
Swift
init() -
Rewrites
uwith the rules inselfuntil a normal form is reached.The rewriting process is notionally nondeterministic unless
selfis confluent.Declaration
Swift
func reduce(_ u: Term) -> Term -
Inserts the given rule using
compareOrderto order pairs of terms.A rule u => v is notionally contained in a rewriting system if that system contains a set of rules capable of rewriting u to v. This set may not contain u => v itself.
The return value is
(true, new)ifris not already notionally contained in the system, wherenewis the identifier of a newly inserted rule that is encodingr. Otherwise, the return value is(false, old)whereoldis the identifier of a rule encodingr.Precondition
The source of the rule is ordered after its target.Declaration
Swift
@discardableResult mutating func insert( _ r: RewritingRule<Term>, orderingTermsWith compareOrder: (Term, Term) -> StrictOrdering ) -> (inserted: Bool, ruleAfterInsertion: RuleID) -
Turns
selfinto a terminating and confluent rewriting system, usingcompareOrderto order pairs of terms.This method uses Knuth-Bendix completion algorithm to transform
selfinto a terminating confluent system. The completion procedure is semi-decidable: it returnstrueif it succeeds orfalseif it suspects that it won’t terminate.Declaration
Swift
mutating func complete(orderingTermsWith compareOrder: (Term, Term) -> StrictOrdering) -> Bool -
Calls
actionon each overlap between two rules of the system. -
Calls
actionon each overlap involvingi.Declaration
-
Calls
actionon each identifier intermsdenoting a rule having an overlap between its left-hand side andsuffix.If the key/value pair
(t, i)is contained interms, thentis the suffix of some termlandiidentifies a rewriting rulel => r.Declaration
-
Returns the critical pair formed by the rules
lhsandrhs, which overlap at thei-th position oflhs‘s source.Declaration
Swift
private func formCriticalPair( _ lhs: RuleID, _ rhs: RuleID, overlappingAt i: Int ) -> CriticalPair -
Adds a rule rewritng
p‘s first element to its second, or vice versa, usingcompareOrderto order pairs of terms.Declaration
Swift
private func resolveCriticalPair( _ p: CriticalPair, orderingTermsWith compareOrder: (Term, Term) -> StrictOrdering ) -> RewritingRule<Term>? -
Removes the rules in
selfwhose left hand side can be reduced by a simpler rule.Declaration
Swift
private mutating func leftSimplify() -
Removes
ifromselfif the suffix of its left-hand side starting frompcontains a subterm that can be reduced by another rule.Declaration
Swift
private mutating func simplify(_ i: RuleID, lookingForTermsInSuffixFrom p: Term.Index) -> Bool -
The rewritings of a term by two different rules or the same rule at two different positions.
See moreDeclaration
Swift
private struct CriticalPair : Sendable -
The identifier of an overlap between rewriting rules.
See moreDeclaration
Swift
private struct OverlapIdentifier : Hashable, Sendable
View on GitHub