private void ToHTMLColoredEnglishStringInt(HashSet<PDL> renamed, HashSet<PDL> deleted, PDL term, string delColor, string renColor, TreeEditScript editScript, StringBuilder sb, string varName)
        {
            bool negate = false;
            var notterm = term as PDLNot;
            if (notterm != null)
            {
                term = notterm.phi;
                negate = true;
            }

            Pattern.Match(term).
                Case<PDLAllPos>(() => TermCase(renamed, deleted, term, delColor, renColor, "the set of all positions", sb)).

                Case<PDLAtPos, char, PDLPos>((label, pos) =>
                {
                    ToHTMLColoredEnglishStringInt(renamed, deleted, pos, delColor, renColor, editScript, sb, varName);
                    if (negate)
                        TermCase(renamed, deleted, term, "", delColor, renColor, " doesn't have label ", editScript, sb);
                    else
                        TermCase(renamed, deleted, term, "", delColor, renColor, " has label ", editScript, sb);
                    TermCase(renamed, deleted, term, "label", delColor, renColor, label.ToString(), editScript, sb);
                }).

                Case<PDLAtSet, char, PDLSet>((label, set) =>
                {
                    Pattern.Match(set).
                        Case<PDLAllPos>(() =>
                        {
                            if (negate)
                                TermCase(renamed, deleted, set, delColor, renColor, string.Format("not every symbol in <i>{0}</i>", varName), sb);
                            else
                                TermCase(renamed, deleted, set, delColor, renColor, string.Format("every symbol in <i>{0}</i>", varName), sb);
                            TermCase(renamed, deleted, term, "", delColor, renColor, " is a '", editScript, sb);
                            TermCase(renamed, deleted, term, "label", delColor, renColor, label.ToString(), editScript, sb);
                            TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("'"), editScript, sb);
                        }).
                        Case<PDLSetCmpPos, PDLPos, PDLComparisonOperator>((pos, op) =>
                        {
                            if (negate)
                                TermCase(renamed, deleted, set, "", delColor, renColor, "not every symbol ", editScript, sb);
                            else
                                TermCase(renamed, deleted, set, "", delColor, renColor, "every symbol ", editScript, sb);
                            switch (op)
                            {
                                case PDLComparisonOperator.Ge: TermCase(renamed, deleted, set, delColor, renColor, "after ", sb); break;
                                case PDLComparisonOperator.Geq: TermCase(renamed, deleted, set, delColor, renColor, "after and including ", sb); break;
                                case PDLComparisonOperator.Le: TermCase(renamed, deleted, set, delColor, renColor, "before ", sb); break;
                                case PDLComparisonOperator.Leq: TermCase(renamed, deleted, set, delColor, renColor, "before and including ", sb); break;
                                default: throw new PDLException("undefined operator");
                            }
                            Pattern.Match(pos).
                                Case<PDLFirst>(() =>
                                {
                                    TermCase(renamed, deleted, pos, delColor, renColor, "the first one", sb);
                                }).
                                Case<PDLLast>(() =>
                                {
                                    TermCase(renamed, deleted, pos, delColor, renColor, "the last one", sb);
                                }).
                                Default(() =>
                                {
                                    ToHTMLColoredEnglishStringInt(renamed, deleted, pos, delColor, renColor, editScript, sb, varName);
                                });
                            TermCase(renamed, deleted, term, "", delColor, renColor, " has label ", editScript, sb);
                            TermCase(renamed, deleted, term, delColor, renColor, string.Format("'"), sb);
                            TermCase(renamed, deleted, term, "label", delColor, renColor, label.ToString(), editScript, sb);
                            TermCase(renamed, deleted, term, delColor, renColor, string.Format("'"), sb);
                        }).
                        Case<PDLPredSet, string, PDLPred>((var, phi) =>
                            {
                                Pattern.Match(phi).
                                    Case<PDLModSetEq, PDLSet, int, int>((set1, m, n) =>
                                    {
                                        var cast = set1 as PDLAllPosUpto;
                                        if (m == 2 && cast != null && cast.pos is PDLPosVar)
                                        {
                                            if (negate)
                                                TermCase(renamed, deleted, set, "", delColor, renColor, "not every ", editScript, sb);
                                            else
                                                TermCase(renamed, deleted, set, "", delColor, renColor, "every ", editScript, sb);
                                            TermCase(renamed, deleted, phi, "n", delColor, renColor, (n == 1 ? "odd" : "even"), editScript, sb);
                                            TermCase(renamed, deleted, set, "", delColor, renColor, " position", editScript, sb);
                                            TermCase(renamed, deleted, term, "", delColor, renColor, " has label '", editScript, sb);
                                            TermCase(renamed, deleted, term, "label", delColor, renColor, label.ToString(), editScript, sb);
                                            TermCase(renamed, deleted, term, delColor, renColor, string.Format("'"), sb);
                                        }
                                        else
                                        {
                                            if (negate)
                                                TermCase(renamed, deleted, set, "", delColor, renColor, "not every position " + var + " such that ", editScript, sb);
                                            else
                                                TermCase(renamed, deleted, set, "", delColor, renColor, "every position " + var + " such that ", editScript, sb);
                                            ToHTMLColoredEnglishStringInt(renamed, deleted, phi, delColor, renColor, editScript, sb, varName);
                                            TermCase(renamed, deleted, term, "", delColor, renColor, " has label '", editScript, sb);
                                            TermCase(renamed, deleted, term, "label", delColor, renColor, label.ToString(), editScript, sb);
                                            TermCase(renamed, deleted, term, delColor, renColor, string.Format("'"), sb);
                                        }
                                    }).
                                    Default(() =>
                                    {
                                        if (negate)
                                            TermCase(renamed, deleted, set, "", delColor, renColor, "not every position " + var + " such that ", editScript, sb);
                                        else
                                            TermCase(renamed, deleted, set, "", delColor, renColor, "every position " + var + " such that ", editScript, sb);
                                        ToHTMLColoredEnglishStringInt(renamed, deleted, phi, delColor, renColor, editScript, sb, varName);
                                        TermCase(renamed, deleted, term, "", delColor, renColor, " has label '", editScript, sb);
                                        TermCase(renamed, deleted, term, "label", delColor, renColor, label.ToString(), editScript, sb);
                                        TermCase(renamed, deleted, term, delColor, renColor, string.Format("'"), sb);
                                    });
                            }).
                        Default(() =>
                        {
                            if (negate)
                                TermCase(renamed, deleted, term, "", delColor, renColor, "not every position in ", editScript, sb);
                            else
                                TermCase(renamed, deleted, term, "", delColor, renColor, "every position in ", editScript, sb);
                            ToHTMLColoredEnglishStringInt(renamed, deleted, set, delColor, renColor, editScript, sb, varName);
                            TermCase(renamed, deleted, term, "", delColor, renColor, " has label '", editScript, sb);
                            TermCase(renamed, deleted, term, "label", delColor, renColor, label.ToString(), editScript, sb);
                            TermCase(renamed, deleted, term, delColor, renColor, string.Format("'"), sb);
                        });
                }).


                Case<PDLBelongs, PDLPos, PDLSet>((pos, set) =>
                {
                    ToHTMLColoredEnglishStringInt(renamed, deleted, pos, delColor, renColor, editScript, sb, varName);
                    if (negate)
                        TermCase(renamed, deleted, term, delColor, renColor, " doesn't belong to ", sb);
                    else
                        TermCase(renamed, deleted, term, delColor, renColor, " belongs to ", sb);
                    ToHTMLColoredEnglishStringInt(renamed, deleted, set, delColor, renColor, editScript, sb, varName);
                }).

                Case<PDLBinaryFormula, PDLPred, PDLPred, PDLLogicalOperator>((phi1, phi2, op) =>
                {
                    if (negate)
                        TermCase(renamed, deleted, notterm, delColor, renColor, "it is not the case that ", sb);

                    switch (op)
                    {
                        case PDLLogicalOperator.And:
                            {
                                ToHTMLColoredEnglishStringInt(renamed, deleted, phi1, delColor, renColor, editScript, sb, varName);
                                sb.Append(", ");
                                TermCase(renamed, deleted, term, delColor, renColor, "and ", sb);
                                break;
                            }
                        case PDLLogicalOperator.If:
                            {
                                TermCase(renamed, deleted, term, delColor, renColor, "if ", sb);
                                ToHTMLColoredEnglishStringInt(renamed, deleted, phi1, delColor, renColor, editScript, sb, varName);
                                sb.Append(", ");
                                TermCase(renamed, deleted, term, delColor, renColor, "then ", sb);
                                break;
                            }
                        case PDLLogicalOperator.Iff:
                            {
                                ToHTMLColoredEnglishStringInt(renamed, deleted, phi1, delColor, renColor, editScript, sb, varName);
                                sb.Append(", ");
                                TermCase(renamed, deleted, term, delColor, renColor, "if and only if ", sb);
                                break;
                            }
                        case PDLLogicalOperator.Or:
                            {
                                ToHTMLColoredEnglishStringInt(renamed, deleted, phi1, delColor, renColor, editScript, sb, varName);
                                sb.Append(", ");
                                TermCase(renamed, deleted, term, delColor, renColor, "or ", sb);
                                break;
                            }
                        default: throw new PDLException("undefined operator");
                    }

                    ToHTMLColoredEnglishStringInt(renamed, deleted, phi2, delColor, renColor, editScript, sb, varName);
                }).

                Case<PDLBinaryPosFormula, PDLPos, PDLPos, PDLPosComparisonOperator>((pos1, pos2, op) =>
                {
                    ToHTMLColoredEnglishStringInt(renamed, deleted, pos1, delColor, renColor, editScript, sb, varName);
                    switch (op)
                    {
                        case PDLPosComparisonOperator.Eq:
                            {
                                if (negate)
                                    TermCase(renamed, deleted, term, delColor, renColor, " isn't the same as ", sb); 
                                else
                                    TermCase(renamed, deleted, term, delColor, renColor, " is the same as ", sb); 
                                break;
                            }

                        case PDLPosComparisonOperator.Ge:
                            {
                                if (negate)
                                    TermCase(renamed, deleted, term, delColor, renColor, " isn't after ", sb); 
                                else
                                    TermCase(renamed, deleted, term, delColor, renColor, " is after ", sb); 
                                break;                                
                            }

                        case PDLPosComparisonOperator.Geq:
                            {
                                if(negate)
                                    TermCase(renamed, deleted, term, delColor, renColor, " isn't after or the same as ", sb); 
                                else
                                    TermCase(renamed, deleted, term, delColor, renColor, " is after or the same as ", sb); 
                                break;
                            }

                        case PDLPosComparisonOperator.Le:
                            {
                                if (negate)
                                    TermCase(renamed, deleted, term, delColor, renColor, " isn't before ", sb); 
                                else
                                    TermCase(renamed, deleted, term, delColor, renColor, " is before ", sb); 
                                break;                                
                            }

                        case PDLPosComparisonOperator.Leq:
                            {
                                if (negate)
                                    TermCase(renamed, deleted, term, delColor, renColor, " isn't before or the same as ", sb);
                                else
                                    TermCase(renamed, deleted, term, delColor, renColor, " is before or is the same as ", sb);
                                break; 
                            }

                        case PDLPosComparisonOperator.Pred:
                            {
                                if (negate)
                                    TermCase(renamed, deleted, term, delColor, renColor, " isn't right before ", sb); 
                                else
                                    TermCase(renamed, deleted, term, delColor, renColor, " is right before ", sb); 
                                break;
                            }

                        case PDLPosComparisonOperator.Succ:
                            {
                                if (negate)
                                    TermCase(renamed, deleted, term, delColor, renColor, " isn't right after ", sb); 
                                else
                                    TermCase(renamed, deleted, term, delColor, renColor, " is right after ", sb);
                                break;
                            }

                        default: throw new PDLException("Undefined operator");
                    }
                    ToHTMLColoredEnglishStringInt(renamed, deleted, pos2, delColor, renColor, editScript, sb, varName);
                }).

                Case<PDLEmptyString>(() =>
                {
                    if(negate)
                        TermCase(renamed, deleted, term, delColor, renColor, string.Format("<i>s</i> isn't the empty string", varName), sb);
                    else
                        TermCase(renamed, deleted, term, delColor, renColor, string.Format("<i>s</i> is the empty string", varName), sb);
                }).

                Case<PDLFalse>(() => TermCase(renamed, deleted, term, delColor, renColor, "false", sb)).

                Case<PDLIndicesOf, string>((str) =>
                {
                    TermCase(renamed, deleted, term, "", delColor, renColor, "the set of positions where a substring '", editScript, sb);
                    TermCase(renamed, deleted, term, "str", delColor, renColor, str, editScript, sb);
                    TermCase(renamed, deleted, term, "", delColor, renColor, "' starts", editScript, sb);
                }).

                Case<PDLQuantifiedFormula, PDLPred, String, PDLQuantifier>((phi, var, q) =>
                {
                    switch (q)
                    {
                        case PDLQuantifier.ExistsFO:
                            {
                                Pattern.Match(phi).
                                    Case<PDLAtPos, char, PDLPos>((label, pos) =>
                                    {
                                        if(negate)
                                            TermCase(renamed, deleted, term, delColor, renColor, string.Format("<i>{0}</i> doesn't contain at least one '", varName), sb);
                                        else
                                            TermCase(renamed, deleted, term, delColor, renColor, string.Format("<i>{0}</i> contains at least one '", varName), sb);
                                        TermCase(renamed, deleted, phi, "label", delColor, renColor, label.ToString(), editScript, sb);
                                        TermCase(renamed, deleted, term, delColor, renColor, string.Format("'"), sb);
                                    }).
                                    Default(() =>
                                    {
                                        if(negate)
                                            TermCase(renamed, deleted, term, delColor, renColor, string.Format("there doesn't exist a position <i>{0}</i> in <i>{1}</i>, ", var, varName), sb);
                                        else
                                            TermCase(renamed, deleted, term, delColor, renColor, string.Format("there exists a position <i>{0}</i> in <i>{1}</i>, ", var, varName), sb);
                                        ToHTMLColoredEnglishStringInt(renamed, deleted, phi, delColor, renColor, editScript, sb, varName);
                                    });
                                break;
                            }
                        case PDLQuantifier.ExistsSO:
                            {
                                if(negate)
                                    TermCase(renamed, deleted, term, delColor, renColor, string.Format("there doesn't exist a set of positions <i>{0}</i> in <i>{1}</i>, ", var, varName), sb);
                                else
                                    TermCase(renamed, deleted, term, delColor, renColor, string.Format("there exists a set of positions <i>{0}</i> in <i>{1}</i>, ", var, varName), sb);
                                ToHTMLColoredEnglishStringInt(renamed, deleted, phi, delColor, renColor, editScript, sb, varName);
                                break;
                            }
                        case PDLQuantifier.ForallFO:
                            {
                                Pattern.Match(phi).
                                    Case<PDLAtPos, char, PDLPos>((label, pos) =>
                                    {
                                        if(negate)
                                            TermCase(renamed, deleted, term, delColor, renColor, string.Format("not every symbol in <i>{0}</i> is a '", varName), sb);
                                        else
                                            TermCase(renamed, deleted, term, delColor, renColor, string.Format("every symbol in <i>{0}</i> is a '", varName), sb);
                                        TermCase(renamed, deleted, phi, "label", delColor, renColor, label.ToString(), editScript, sb);
                                        TermCase(renamed, deleted, term, delColor, renColor, string.Format("'"), sb);
                                    }).
                                    Default(() =>
                                    {
                                        if(negate)
                                            TermCase(renamed, deleted, term, delColor, renColor, string.Format("not every position <i>{0}</i> in <i>{1}</i>, ", var, varName), sb);
                                        else
                                            TermCase(renamed, deleted, term, delColor, renColor, string.Format("for every position <i>{0}</i> in <i>{1}</i>, ", var, varName), sb);
                                        ToHTMLColoredEnglishStringInt(renamed, deleted, phi, delColor, renColor, editScript, sb, varName);
                                    });
                                break;
                            }
                        case PDLQuantifier.ForallSO:
                            {
                                if(negate)
                                    TermCase(renamed, deleted, term, delColor, renColor, string.Format("not every set of positions <i>{0}</i> in <i>{1}</i>, ", var, varName), sb);
                                else
                                    TermCase(renamed, deleted, term, delColor, renColor, string.Format("for every set of positions <i>{0}</i> in <i>{1}</i>, ", var, varName), sb);
                                ToHTMLColoredEnglishStringInt(renamed, deleted, phi, delColor, renColor, editScript, sb, varName);
                                break;
                            }
                        default: throw new PDLException("Quantifier undefined");
                    }
                }).

                Case<PDLSetCardinality, PDLSet, int, PDLComparisonOperator>((set, n, op) =>
                {
                    Pattern.Match(set).
                        Case<PDLAllPos>(() =>
                        {
                            if (negate)
                                TermCase(renamed, deleted, term, delColor, renColor, string.Format("<i>{0}</i> doesn't have length", varName), sb);
                            else
                                TermCase(renamed, deleted, term, delColor, renColor, string.Format("<i>{0}</i> has length", varName), sb);
                            switch (op)
                            {
                                case PDLComparisonOperator.Eq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" exactly "), editScript, sb); break;
                                case PDLComparisonOperator.Ge: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" greater than "), editScript, sb); break;
                                case PDLComparisonOperator.Geq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" greater or equal than "), editScript, sb); break;
                                case PDLComparisonOperator.Le: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" samller than "), editScript, sb); break;
                                case PDLComparisonOperator.Leq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" smaller or equal than "), editScript, sb); break;
                                default: throw new PDLException("Undefined operator");
                            }
                            TermCase(renamed, deleted, term, "n", delColor, renColor, n.ToString(), editScript, sb);
                        }).
                        Case<PDLIndicesOf, string>((str) =>
                        {
                            if (str.Length == 1)
                            {
                                if (negate)
                                    TermCase(renamed, deleted, set, "", delColor, renColor, string.Format("<i>{0}</i> doesn't contain", varName), editScript, sb);
                                else
                                    TermCase(renamed, deleted, set, "", delColor, renColor, string.Format("<i>{0}</i> contains", varName), editScript, sb);

                                switch (op)
                                {
                                    case PDLComparisonOperator.Eq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" exactly "), editScript, sb); break;
                                    case PDLComparisonOperator.Ge: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" more than "), editScript, sb); break;
                                    case PDLComparisonOperator.Geq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" at least "), editScript, sb); break;
                                    case PDLComparisonOperator.Le: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" less than "), editScript, sb); break;
                                    case PDLComparisonOperator.Leq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" at most "), editScript, sb); break;
                                    default: throw new PDLException("Undefined operator");
                                }
                                if (n == 1)
                                    TermCase(renamed, deleted, term, "n", delColor, renColor, "one ", editScript, sb);
                                else
                                    if (n == 2)
                                        TermCase(renamed, deleted, term, "n", delColor, renColor, "two ", editScript, sb);
                                    else
                                        if (n == 3)
                                            TermCase(renamed, deleted, term, "n", delColor, renColor, "three ", editScript, sb);
                                        else
                                            TermCase(renamed, deleted, term, "n", delColor, renColor, n.ToString()+" ", editScript, sb);                                
                                TermCase(renamed, deleted, set, "str", delColor, renColor, str, editScript, sb);
                                TermCase(renamed, deleted, term, "", delColor, renColor, " ", editScript, sb);
                                if (n > 1 || n == 0)
                                    TermCase(renamed, deleted, set, "", delColor, renColor, "'s", editScript, sb);
                            }
                            else
                            {
                                TermCase(renamed, deleted, set, "str", delColor, renColor, str, editScript, sb);
                                if (negate)
                                    TermCase(renamed, deleted, set, "", delColor, renColor, string.Format(" doesn't appear in <i>{0}</i>", varName), editScript, sb);
                                else
                                    TermCase(renamed, deleted, set, "", delColor, renColor, string.Format(" appears in <i>{0}</i> ", varName), editScript, sb);

                                switch (op)
                                {
                                    case PDLComparisonOperator.Eq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" exactly "), editScript, sb); break;
                                    case PDLComparisonOperator.Ge: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" more than "), editScript, sb); break;
                                    case PDLComparisonOperator.Geq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" at least "), editScript, sb); break;
                                    case PDLComparisonOperator.Le: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" less than "), editScript, sb); break;
                                    case PDLComparisonOperator.Leq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" at most "), editScript, sb); break;
                                    default: throw new PDLException("Undefined operator");
                                }
                                if (n == 1)
                                    TermCase(renamed, deleted, term, "n", delColor, renColor, "once", editScript, sb);
                                else
                                    if (n == 2)
                                        TermCase(renamed, deleted, term, "n", delColor, renColor, "twice", editScript, sb);
                                    else
                                        TermCase(renamed, deleted, term, "n", delColor, renColor, n.ToString() +" times", editScript, sb);                               
                            }
                        }).
                        Case<PDLUnion, PDLSet, PDLSet>((set1, set2) =>
                        {
                            if (set1 is PDLIndicesOf && set2 is PDLIndicesOf)
                            {
                                var phi1cast = set1 as PDLIndicesOf;
                                var phi2cast = set2 as PDLIndicesOf;
                                TermCase(renamed, deleted, set, "", delColor, renColor, string.Format("' the total number of occurences of "), editScript, sb);
                                TermCase(renamed, deleted, set, "", delColor, renColor, string.Format("'"), editScript, sb);
                                TermCase(renamed, deleted, set1, "str", delColor, renColor, phi1cast.str, editScript, sb);
                                TermCase(renamed, deleted, set, "", delColor, renColor, string.Format("' and '"), editScript, sb);
                                TermCase(renamed, deleted, set2, "str", delColor, renColor, phi2cast.str, editScript, sb);
                                TermCase(renamed, deleted, set, "", delColor, renColor, string.Format("'"), editScript, sb);
                                if(negate)
                                    TermCase(renamed, deleted, set, "", delColor, renColor, string.Format("' in <i>{0}</i> isn't", varName), editScript, sb);
                                else
                                    TermCase(renamed, deleted, set, "", delColor, renColor, string.Format("' in <i>{0}</i> is", varName), editScript, sb);
                                switch (op)
                                {
                                    case PDLComparisonOperator.Eq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" exactly "), editScript, sb); break;
                                    case PDLComparisonOperator.Ge: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" greater than "), editScript, sb); break;
                                    case PDLComparisonOperator.Geq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" at least "), editScript, sb); break;
                                    case PDLComparisonOperator.Le: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" less than "), editScript, sb); break;
                                    case PDLComparisonOperator.Leq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" at most "), editScript, sb); break;
                                    default: throw new PDLException("Undefined operator");
                                }
                                TermCase(renamed, deleted, term, "n", delColor, renColor, n.ToString(), editScript, sb);
                            }
                            else
                            {
                                ToHTMLColoredEnglishStringInt(renamed, deleted, set, delColor, renColor, editScript, sb, varName);
                                if(negate)
                                    TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" doesn't have"), editScript, sb);
                                else
                                    TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" has"), editScript, sb);
                               switch (op)
                                    {
                                        case PDLComparisonOperator.Eq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" exactly "), editScript, sb); break;
                                        case PDLComparisonOperator.Ge: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" size greater than "), editScript, sb); break;
                                        case PDLComparisonOperator.Geq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" size greater or equal than "), editScript, sb); break;
                                        case PDLComparisonOperator.Le: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" size smaller than "), editScript, sb); break;
                                        case PDLComparisonOperator.Leq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" size smaller or equal than "), editScript, sb); break;
                                        default: throw new PDLException("Undefined operator");
                                    }
                                TermCase(renamed, deleted, term, "n", delColor, renColor, n.ToString(), editScript, sb);
                                TermCase(renamed, deleted, term, "", delColor, renColor, " elements ", editScript, sb);
                            }
                        }).
                        Default(() =>
                        {
                            ToHTMLColoredEnglishStringInt(renamed, deleted, set, delColor, renColor, editScript, sb, varName);
                            if (negate)
                                TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" doesn't have"), editScript, sb);
                            else
                                TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" has"), editScript, sb);
                            switch (op)
                            {
                                case PDLComparisonOperator.Eq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" exactly "), editScript, sb); break;
                                case PDLComparisonOperator.Ge: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" size greater than "), editScript, sb); break;
                                case PDLComparisonOperator.Geq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" size greater or equal than "), editScript, sb); break;
                                case PDLComparisonOperator.Le: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" size smaller than "), editScript, sb); break;
                                case PDLComparisonOperator.Leq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" size smaller or equal than "), editScript, sb); break;
                                default: throw new PDLException("Undefined operator");
                            }
                            TermCase(renamed, deleted, term, "n", delColor, renColor, n.ToString(), editScript, sb);
                            TermCase(renamed, deleted, term, "", delColor, renColor, " elements ", editScript, sb);
                        });
                }).

                Case<PDLNot, PDLPred>((phi) =>
                {
                    if(!negate)
                        TermCase(renamed, deleted, term, delColor, renColor, "it is not the case that ", sb);                    
                    ToHTMLColoredEnglishStringInt(renamed, deleted, phi, delColor, renColor, editScript, sb, varName);
                }).

                Case<PDLPosConstant, PDLPosConstantName>((op) =>
                {
                    switch (op)
                    {
                        case PDLPosConstantName.First: TermCase(renamed, deleted, term, delColor, renColor, "the first position", sb); break;
                        case PDLPosConstantName.Last: TermCase(renamed, deleted, term, delColor, renColor, "the last position", sb); break;
                        default: throw new PDLException("undefined operator");
                    }
                }).

                Case<PDLPosUnary, PDLPos, PDLPosUnaryConstructor>((pos, op) =>
                {
                    switch (op)
                    {
                        case PDLPosUnaryConstructor.Pred: TermCase(renamed, deleted, term, delColor, renColor, "the position before ", sb); break;
                        case PDLPosUnaryConstructor.Succ: TermCase(renamed, deleted, term, delColor, renColor, "the position after ", sb); break;
                        default: throw new PDLException("undefined operator");
                    }
                    ToHTMLColoredEnglishStringInt(renamed, deleted, pos, delColor, renColor, editScript, sb, varName);
                }).

                Case<PDLPosVar, string>((var) => TermCase(renamed, deleted, term, delColor, renColor, var, sb)).

                Case<PDLPredSet, string, PDLPred>((var, phi) =>
                {
                    Pattern.Match(phi).
                        Case<PDLModSetEq, PDLSet, int, int>((set, m, n) =>
                        {
                            var cast = set as PDLAllPosUpto;
                            if (m == 2 && cast != null && cast.pos is PDLPosVar)
                            {
                                TermCase(renamed, deleted, set, delColor, renColor, "the set of ", sb);
                                TermCase(renamed, deleted, term, "n", delColor, renColor, (n == 1 ? "odd" : "even"), editScript, sb);
                                TermCase(renamed, deleted, set, delColor, renColor, "positions", sb);
                            }
                            else
                            {
                                TermCase(renamed, deleted, term, delColor, renColor, "the set {" + var + " | such that ", sb);
                                ToHTMLColoredEnglishStringInt(renamed, deleted, phi, delColor, renColor, editScript, sb, varName);
                                TermCase(renamed, deleted, term, delColor, renColor, "}", sb);
                            }
                        }).
                        Default(() =>
                        {
                            TermCase(renamed, deleted, term, delColor, renColor, "the set {" + var + " | such that ", sb);
                            ToHTMLColoredEnglishStringInt(renamed, deleted, phi, delColor, renColor, editScript, sb, varName);
                            TermCase(renamed, deleted, term, delColor, renColor, "}", sb);
                        });
                }).

                Case<PDLSetBinary, PDLSet, PDLSet, PDLBinarySetOperator>((set1, set2, op) =>
                {
                    switch (op)
                    {
                        case PDLBinarySetOperator.Intersection:
                            {
                                TermCase(renamed, deleted, term, delColor, renColor, "the intersection of ", sb); break;
                            }
                        case PDLBinarySetOperator.Union:
                            {
                                TermCase(renamed, deleted, term, delColor, renColor, "the union of ", sb); break;
                            }
                        default: throw new PDLException("undefined operator");
                    }
                    ToHTMLColoredEnglishStringInt(renamed, deleted, set1, delColor, renColor, editScript, sb, varName);
                    TermCase(renamed, deleted, term, delColor, renColor, ", and ", sb);
                    ToHTMLColoredEnglishStringInt(renamed, deleted, set2, delColor, renColor, editScript, sb, varName);
                    TermCase(renamed, deleted, term, delColor, renColor, ", ", sb);

                }).

                Case<PDLSetCmpPos, PDLPos, PDLComparisonOperator>((pos1, op) =>
                {
                    switch (op)
                    {
                        case PDLComparisonOperator.Ge: TermCase(renamed, deleted, term, delColor, renColor, "the set of positions after ", sb); break;
                        case PDLComparisonOperator.Geq: TermCase(renamed, deleted, term, delColor, renColor, "the set of positions from ", sb); break;
                        case PDLComparisonOperator.Le: TermCase(renamed, deleted, term, delColor, renColor, "the set of positions before ", sb); break;
                        case PDLComparisonOperator.Leq: TermCase(renamed, deleted, term, delColor, renColor, "the set of positions up to ", sb); break;
                        default: throw new PDLException("undefined operator");
                    }
                    ToHTMLColoredEnglishStringInt(renamed, deleted, pos1, delColor, renColor, editScript, sb, varName);
                }).

                Case<PDLSetVar, string>((var) => TermCase(renamed, deleted, term, delColor, renColor, var, sb)).

                Case<PDLSetModuleComparison, PDLSet, int, int, PDLComparisonOperator>((set, m, n, op) =>
                {
                    if (m == 2)
                    {
                        //CASE mod 2
                        Pattern.Match(set).
                            Case<PDLAllPos>(() =>
                            {
                                switch (op)
                                {
                                    case PDLComparisonOperator.Eq:
                                        {
                                            if(negate)
                                                TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("<i>{0}</i> doesn't have ", varName), editScript, sb);
                                            else
                                                TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("<i>{0}</i> has ", varName), editScript, sb);
                                            TermCase(renamed, deleted, term, "n", delColor, renColor, (n == 1 ? "odd" : "even"), editScript, sb);
                                            TermCase(renamed, deleted, set, "", delColor, renColor, string.Format(" length", varName), editScript, sb);
                                            break;
                                        }
                                    default: throw new PDLException("This formula shouldn't be enumerated with this operator and value 2");
                                }
                            }).
                            Case<PDLIndicesOf, string>((str) =>
                            {
                                TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("'"), editScript, sb);
                                TermCase(renamed, deleted, set, "str", delColor, renColor, str, editScript, sb);
                                if(negate)
                                    TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("' doesn't appear in <i>{0}</i> an ", varName), editScript, sb);
                                else
                                    TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("' appears in <i>{0}</i> an ", varName), editScript, sb);

                                TermCase(renamed, deleted, term, "n", delColor, renColor, (n == 1 ? "odd" : "even"), editScript, sb);
                                TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" number of times"), editScript, sb);
                            }).
                            Default(() =>
                            {
                                switch (op)
                                {
                                    case PDLComparisonOperator.Eq:
                                        {
                                            ToHTMLColoredEnglishStringInt(renamed, deleted, set, delColor, renColor, editScript, sb, varName);
                                            if(negate)
                                                TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" doesn't have an ", varName), editScript, sb);
                                            else
                                                TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" has an ", varName), editScript, sb);

                                            TermCase(renamed, deleted, term, "n", delColor, renColor, (n == 1 ? "odd" : "even"), editScript, sb);
                                            TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" number of elements", varName), editScript, sb);
                                            break;
                                        }
                                    default: throw new PDLException("This formula shouldn't be enumerated with this operator and value 2");
                                }
                            });
                    }
                    else
                    {
                        if (n == 0 && op == PDLComparisonOperator.Eq)
                        {
                            //CASE % m = 0
                            Pattern.Match(set).
                                Case<PDLAllPos>(() =>
                                {
                                    TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("the "), editScript, sb);
                                    TermCase(renamed, deleted, set, "", delColor, renColor, string.Format("length", varName), editScript, sb);
                                    if (negate)
                                        TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" of <i>{0}</i> is not divisible by ", varName), editScript, sb);
                                    else
                                        TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" of <i>{0}</i> is divisible by ", varName), editScript, sb);
                                    TermCase(renamed, deleted, term, "m", delColor, renColor, m.ToString(), editScript, sb);
                                }).
                                Case<PDLIndicesOf, string>((str) =>
                                {
                                    TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("the number of times "), editScript, sb);
                                    TermCase(renamed, deleted, set, "", delColor, renColor, string.Format("the substring '"), editScript, sb);
                                    TermCase(renamed, deleted, set, "str", delColor, renColor, str, editScript, sb);
                                    TermCase(renamed, deleted, set, "", delColor, renColor, string.Format("' appears in <i>{0}</i> ", varName), editScript, sb);
                                    if (negate)
                                        TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("is not divisible by ", varName), editScript, sb);
                                    else
                                        TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("is divisible by ", varName), editScript, sb);
                                    TermCase(renamed, deleted, term, "m", delColor, renColor, m.ToString(), editScript, sb);
                                }).
                                Default(() =>
                                {
                                    TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("the size of "), editScript, sb);
                                    ToHTMLColoredEnglishStringInt(renamed, deleted, set, delColor, renColor, editScript, sb, varName);
                                    if (negate)
                                        TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" is not divisible by "), editScript, sb);
                                    else
                                        TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" is divisible by ", varName), editScript, sb);
                                    TermCase(renamed, deleted, term, "m", delColor, renColor, m.ToString(), editScript, sb);
                                });
                        }
                        else
                        {
                            // m!=2 and n!=0 and op not equality
                            Pattern.Match(set).
                                Case<PDLAllPos>(() =>
                                {
                                    TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("dividing ", varName), editScript, sb);
                                    TermCase(renamed, deleted, set, "", delColor, renColor, string.Format("the length of <i>{0}</i> by ", varName), editScript, sb);
                                    TermCase(renamed, deleted, term, "m", delColor, renColor, m.ToString(), editScript, sb);
                                }).
                                Case<PDLIndicesOf, string>((str) =>
                                {
                                    TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("dividing "), editScript, sb);
                                    TermCase(renamed, deleted, set, "", delColor, renColor, string.Format("the number of times the substring '"), editScript, sb);
                                    TermCase(renamed, deleted, set, "str", delColor, renColor, str, editScript, sb);
                                    TermCase(renamed, deleted, set, "", delColor, renColor, string.Format("' appears in <i>{0}</i> ", varName), editScript, sb);
                                    TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("by "), editScript, sb);
                                    TermCase(renamed, deleted, term, "m", delColor, renColor, m.ToString(), editScript, sb);
                                }).
                                Default(() =>
                                {
                                    TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("dividing the size of "), editScript, sb);
                                    ToHTMLColoredEnglishStringInt(renamed, deleted, set, delColor, renColor, editScript, sb, varName);
                                    TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" by "), editScript, sb);
                                    TermCase(renamed, deleted, term, "m", delColor, renColor, m.ToString(), editScript, sb);
                                });

                            if (negate)
                                TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" doesn't give remainder "), editScript, sb);
                            else
                                TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" gives remainder "), editScript, sb);
                            switch (op)
                            {
                                case PDLComparisonOperator.Eq: break;
                                case PDLComparisonOperator.Ge: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" greater than "), editScript, sb); break;
                                case PDLComparisonOperator.Geq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" greater or equal than "), editScript, sb); break;
                                case PDLComparisonOperator.Le: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" smaller than "), editScript, sb); break;
                                case PDLComparisonOperator.Leq: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format(" smaller or equal than "), editScript, sb); break;
                                default: throw new PDLException("Undefined operator");
                            }
                            TermCase(renamed, deleted, term, "n", delColor, renColor, n.ToString(), editScript, sb);
                        }
                    }
                }).

                Case<PDLStringPos, string, PDLStringPosOperator>((str, op) =>
                {
                    switch (op)
                    {
                        case PDLStringPosOperator.FirstOcc: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("the first occurence of ", str), editScript, sb); break;
                        case PDLStringPosOperator.LastOcc: TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("the last occurence of ", str), editScript, sb); break;
                        default: throw new PDLException("undefined operator");
                    }
                    TermCase(renamed, deleted, term, "", delColor, renColor, "'", editScript, sb);
                    TermCase(renamed, deleted, term, "str", delColor, renColor, str, editScript, sb);
                    TermCase(renamed, deleted, term, "", delColor, renColor, "'", editScript, sb);
                }).

                Case<PDLStringQuery, string, PDLStringQueryOp>((str, op) =>
                {
                    TermCase(renamed, deleted, term, "", delColor, renColor, string.Format("s "), editScript, sb);
                    switch (op)
                    {
                        case PDLStringQueryOp.Contains: 
                            if(negate)
                                TermCase(renamed, deleted, term, "", delColor, renColor, "doesn't contain ", editScript, sb); 
                            else
                                TermCase(renamed, deleted, term, "", delColor, renColor, "contains '", editScript, sb); 
                            break;

                        case PDLStringQueryOp.EndsWith: 
                            if(negate)
                                TermCase(renamed, deleted, term, "", delColor, renColor, "doesn't end with ", editScript, sb); 
                            else
                                TermCase(renamed, deleted, term, "", delColor, renColor, "ends with ", editScript, sb); 
                            break;
                        case PDLStringQueryOp.IsString: 
                            if(negate)
                                TermCase(renamed, deleted, term, "", delColor, renColor, "isn't the string ", editScript, sb); 
                            else
                                TermCase(renamed, deleted, term, "", delColor, renColor, "is the string ", editScript, sb); 
                            break;
                        case PDLStringQueryOp.StartsWith: 
                            if(negate)
                                TermCase(renamed, deleted, term, "", delColor, renColor, "doesn't start with ", editScript, sb); 
                            else
                                TermCase(renamed, deleted, term, "", delColor, renColor, "starts with ", editScript, sb); 
                            break;
                        default: throw new PDLException("undefined operator");
                    }
                    TermCase(renamed, deleted, term, "", delColor, renColor, "'", editScript, sb);
                    TermCase(renamed, deleted, term, "str", delColor, renColor, str, editScript, sb);
                    TermCase(renamed, deleted, term, "", delColor, renColor, "'", editScript, sb);
                }).

                Case<PDLTrue>(() => TermCase(renamed, deleted, term, delColor, renColor, "true", sb));
        }
 private void ToHTMLColoredEnglishStringExt(HashSet<PDL> renamed, HashSet<PDL> deleted, PDL term, string delColor, string renColor, TreeEditScript editScript, StringBuilder sb, string varName)
 {
     Pattern.Match(term).
         Case<PDLFalse>(() => TermCase(renamed, deleted, term, delColor, renColor, "no string", sb)).
         Case<PDLTrue>(() => TermCase(renamed, deleted, term, delColor, renColor, "every input string", sb)).
         Case<PDLEmptyString>(() => TermCase(renamed, deleted, term, delColor, renColor, "the empty string", sb)).
         Default(() => {
              sb.Append("{ <i>s</i> | ");
             ToHTMLColoredEnglishStringInt(renamed, deleted, term, delColor, renColor, editScript, sb, varName);
              sb.Append(" }");
         });           
 }
 public void ToEnglishString(PDL term, StringBuilder sb)
 {
     ToHTMLColoredEnglishStringExt(new HashSet<PDL>(), new HashSet<PDL>(), term, "black", "black", editScriptAtoB, sb,"s");
 }
 public string ToEnglishString(PDL term)
 {
     StringBuilder sb = new StringBuilder();
     ToEnglishString(term,sb);
     return sb.ToString();
 }
        private void TermCase(HashSet<PDL> renamed, HashSet<PDL> deleted, PDL phi, string tag, string delColor, string renColor, string message, TreeEditScript editScript, StringBuilder sb)
        {
            var isDel = deleted.Contains(phi);
            var isRen = renamed.Contains(phi);
            foreach (var edit in editScript.script)
            {
                if (edit.getCost() > 0)
                {
                    if (isDel && edit is Delete)
                    {
                        var tmp = edit as Delete;
                        if (tmp.pdlA.First == phi && tmp.pdlA.Second == tag)
                        {
                            if(tag== "")
                                sb.AppendFormat("<font color='{0}'><b>{1}</b></font>", delColor, message);
                            else
                                sb.AppendFormat("<i><font color='{0}'><b>{1}</b></font></i>", delColor, message);
                            return;
                        }
                    }
                    else
                        if (isRen && edit is Rename)
                        {
                            var tmp = edit as Rename;
                            if (tmp.pdlA.First == phi && tmp.pdlA.Second == tag)
                            {
                                if (tag == "")
                                    sb.AppendFormat("<font color='{0}'><b>{1}</b></font>", renColor, message);
                                else
                                    sb.AppendFormat("<i><font color='{0}'><b>{1}</b></font></i>", renColor, message);                                
                                return;
                            }
                        }
                }

            }
            if (tag == "")
                sb.AppendFormat("{0}", message);
            else
                sb.AppendFormat("<i>{0}</i>", message);   
        }
 private void TermCase(HashSet<PDL> renamed, HashSet<PDL> deleted, PDL phi, string delColor, string renColor, string message, StringBuilder sb)
 {
     if (renamed.Contains(phi))
         sb.AppendFormat("<font color='{0}'><b>{1}</b></font>", renColor, message);
     else
         if (deleted.Contains(phi))
             sb.AppendFormat("<i><font color='{0}'><b>{1}</b></font></i>", delColor, message);
         else
             sb.Append(message);
 }