Module Transform.
Definition basic (op: Instruction) : bool :=
match op with
| (([], [a], _), ([b], [], _)) => true
| (([a], [], _), ([], [b], _)) => true
| _ => false
end.
Definition weight_Instruction (op: Instruction) : nat :=
if basic op then 0 else
match op with
| ((l, r, _), (l', _, _)) => 1 + length (l ++ l' ++ l ++ r)
end.
Definition weight (M: SMN) : nat :=
fold_right (fun op w => w + weight_Instruction op) 0 M.
Fixpoint fresh_State (M: SMN) : State :=
match M with
| [] => 1
| ((_, _, x), (_, _, y)) :: M => 1 + x + y + fresh_State M
end.
End Transform.
(* basic instructions are of shape xa -> by or ax -> yb *)
Inductive basic : Instruction -> Prop :=
| basic_r a b x y : basic (([], [a], x), ([b], [], y))
| basic_l a b x y : basic (([a], [], x), ([], [b], y)).

(* from any confluent and length preserving SMN construct a boundedness-equivalent, confluent, SMN with only basic instructions *)
Theorem construct_basic_SMN (M: SMN) :
confluent M -> length_preserving M ->
{ M' : SMN | Forall basic M' /\ (confluent M' /\ ((exists NM, bounded M NM) <-> (exists NM', bounded M' NM'))) }.