2

I am reading about this in the context of the K semantic framework. I keep encountering terms such as rewrite-term and rewrite logic. My main aim is to understand what is K doing and how it works, so maybe this would be a bit off-topic.

yldm
  • 23
  • 3
  • 2
    Also the wikipedia page on this is probably a better explination than I can give now that I have read it. http://en.wikipedia.org/wiki/Rewriting – Jake Jan 16 '15 at 03:35

1 Answers1

3

I am assuming that you have some background in a functional programming language like Haskell or ML or OCaml because that is the easiest thing for me to explain this in terms of.

Haskell is, or can be viewed as, a rewrite system. When you simplify little expressions you are rewriting the expression in little steps until you get to the final result (normal form).

For instance a list like [1, 2, 3] can be denoted by the term (1 : (2 : (3 : [])))

Another term is a term like

(1 : (2 : [])) ++ (3 : [])

which can be reritten as

1 : ((2 : []) ++ (3 : []))

which can in tern be rewritten as

1 : (2 : ([] ++ (3 : [])))

which can (finally) be rewritten as

(1 : (2 : (3 : [])))

This was all based on the following rewrite rules

(x:xs) ++ ys -> x : (xs ++ ys)
[]     ++ ys -> ys

where x -> y can be thought of as "if you see 'x' replace it with 'y'"

So basically a rewrite system is a system that has a set of rules that explain how to rewrite certain subterms of a term in a system. Once there are no rules left that apply the term is in normal form. Some times terms have no normal form however, these are either errors or infinite loops in systems like Haskell.

example:

addLots x -> 1 + addLots x

addLots 0 (this expression has no normal form as we just have to keep adding 1s on)

Haskell also gives us some guarantees on the order that it will apply the rewrite rules (but does not fully define it). For instance

case 1 : (addLots 0) of {x : xs -> 2}

will evaluate to 2. If the order was either unspecified or chose to fully evaluate 1 : (addLots 0) then it would have not ever reached it's normal form.

A rewrite system does not in general have to have such an order however; it just has to say which rewrites are valid. Another example of a rewrite system is first order logic. You are given a set of rewrite rules called "inference rules" and a set of terms called "first order logic terms". You can derive tons of expressions from other expressions in just such a way. Like the following two rewrite rules.

~~x -> x
x -> ~~x

we could keep gong back and forth between these and we would get an infinite loop but a human knows how to apply these in just the write way to derive interesting theorems.

edit: It seems to me (from a brief look) that the K semantic framework is a system for defining what terms on in the language (quite like data expressions in Haskell but more advanced) and then it lets you define rewrite rules on these expressions (a bit like functions in Haskell). In the K semantic framework syntax and rules are totally separated where as in Haskell data expressions define the syntax of normal forms and function definitions define a new bit of syntax along with a reduction rule on that new syntax.

Jake
  • 3,810
  • 19
  • 35