public override MSOFormula ToMSO(FreshGen fg, string V)
        {
            int    c = fg.get();
            string x = "_x_" + c.ToString();
            string y = "_y_" + c.ToString();
            string X = "_X_" + c.ToString();


            int        i = str.Length - 1;
            string     z_i, z_im;
            MSOFormula phi = null;

            phi = new MSOLabel("z0", str[0]);

            while (i > 0)
            {
                z_i  = "z" + i.ToString();
                z_im = "z" + (i - 1).ToString();
                phi  = new MSOExistsFO(z_i, new MSOAnd(new MSOSucc(z_im, z_i),
                                                       new MSOAnd(new MSOLabel(z_i, str[i]), phi)));
                i--;
            }

            return(new MSOForallFO("z0", new MSOIff(new MSOBelong("z0", V), phi)));
        }
        public override MSOFormula ToMSO(FreshGen fg, string v)
        {
            switch (op)
            {
            case PDLStringPosOperator.FirstOcc:
            {
                int        i = str.Length - 1;
                string     z_i, z_im;
                MSOFormula phi = null;        //new MSOForallFO("x", new MSOEqual("x", "x"));

                //TODO make sure input string is non empty that is i/=0

                phi = new MSOLabel("z0", str[0]);

                while (i > 0)
                {
                    z_i  = "z" + i.ToString();
                    z_im = "z" + (i - 1).ToString();
                    phi  = new MSOExistsFO(z_i, new MSOAnd(new MSOSucc(z_im, z_i),
                                                           new MSOAnd(new MSOLabel(z_i, str[i]), phi)));
                    i--;
                }

                return(new MSOAnd(new MSOForallFO("z0", new MSOIf(phi, new MSOLessEq(v, "z0"))),
                                  new MSOExistsFO("z0", new MSOAnd(phi, new MSOEqual(v, "z0")))));
            }

            case PDLStringPosOperator.LastOcc:
            {
                int        i = str.Length - 1;
                string     z_i, z_im;
                MSOFormula phi = null;        //new MSOForallFO("x", new MSOEqual("x", "x"));

                //TODO make sure input string is non empty that is i/=0

                phi = new MSOLabel("z0", str[0]);

                while (i > 0)
                {
                    z_i  = "z" + i.ToString();
                    z_im = "z" + (i - 1).ToString();
                    phi  = new MSOExistsFO(z_i, new MSOAnd(new MSOSucc(z_im, z_i),
                                                           new MSOAnd(new MSOLabel(z_i, str[i]), phi)));
                    i--;
                }

                return(new MSOAnd(new MSOForallFO("z0", new MSOIf(phi, new MSOLessEq("z0", v))),
                                  new MSOExistsFO("z0", new MSOAnd(phi, new MSOEqual(v, "z0")))));
            }

            default: throw new PDLException("undefined operator");
            }
        }