(**************************************************************)
(*   Copyright Dominique Larchey-Wendling [*]                 *)
(*                                                            *)
(*                             [*] Affiliation LORIA -- CNRS  *)
(**************************************************************)
(*      This file is distributed under the terms of the       *)
(*         CeCILL v2 FREE SOFTWARE LICENSE AGREEMENT          *)
(**************************************************************)
(* A Coq computable reduction from n-registers MM termination to 2-registers MMA termination. Beware that the semantics of MMA is a bit different than the semantics of MM:  the DEC instruction jumps when not zero instead of when zero  Compare mm_sss  (ILL/Mm/mm_defs.v) and     mma_sss (MM/mma_defs.v)  The reduction goes via regular FRACTRAN termination *)
From Undecidability.Shared.Libs.DLW Require Import Utils.utils Vec.pos Vec.vec.
From Undecidability.Shared.Libs.DLW.Code Require Import sss.
From Undecidability.MinskyMachines Require Import MM FRACTRAN_to_MMA2.
From Undecidability.FRACTRAN Require Import FRACTRAN MM_FRACTRAN.
Set Implicit Arguments.
Check MM_MMA2_HALTING.
From Undecidability.MinskyMachines Require Import mm_defs mma_defs fractran_mma.
From Undecidability.FRACTRAN Require Import fractran_utils prime_seq mm_fractran.
(* This is somewhat for direct proof that does not involve testing for (0,_) in the intermediate Fractran program *)
Local Notation "P /MM/ s ↓" := (sss_terminates (@mm_sss _) P s) (at level 70, no associativity).
Local Notation "P /MMA/ s ↓" := (sss_terminates (@mma_sss 2) P s) (at level 70, no associativity).

Theorem mm_mma2 n (P : list (mm_instr (pos n))) :
{   Q : list (mm_instr (pos 2))
& { f : vec nat n -> vec nat 2
| forall v, (1,P) /MM/ (1,v) ↓ <-> (1,Q) /MMA/ (1,f v) ↓ } }.