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.

Lemma minimize_weight_lhs {M: SMN} {a l r l' r' x y} :
In (a :: l, r, x, (l', r', y)) M ->
weight_Instruction (a :: l, r, x, (l', r', y)) <> 0 ->
confluent M -> length_preserving M ->
{ M' : SMN | weight M' < weight M /\
(confluent M' /\ length_preserving M' /\ ((exists NM, bounded M NM) <-> (exists NM', bounded M' NM'))) }.