/*
* JFLAP - Formal Languages and Automata Package
*
*
* Susan H. Rodger
* Computer Science Department
* Duke University
* August 27, 2009
* Copyright (c) 2002-2009
* All rights reserved.
* JFLAP is open source software. Please see the LICENSE for terms.
*
*/
package pumping.cf;
import pumping.*;
/**
* The context-free pumping lemma for L =
* {ww : w ∈ {a, b}*}.
*
* @author Jinghui Lim & Chris Morgan
*
*/
public class WW extends ContextFreePumpingLemma
{
public String getTitle()
{
return "ww : w element_of {ab}*";
}
public String getHTMLTitle()
{
return "ww : w " + ELEMENT_OF + " " + AB_STAR;
}
public void setDescription()
{
partitionIsValid = false;
explanation = "For any m value, a possible value for w is \"am" +
"bmambm\". To be in the language with " +
"this example, v & y together cannot possess identical letters that are from separate " +
"blocks of alike letters (ex: v has \"b\"s from the first set of \"b\"s, " +
"while y has \"b\"s from the second set of \"b\"s. Because of this, any increase or decrease in " +
"\"a\"s or \"b\"s will not be matched by any corresponding change in the other blocks of similar letters, " +
"resulting in an inequality that prevents the decomposition from working. Thus, this language is " +
"not context-free.";
}
protected void chooseW()
{
w = pumpString("a", getM()) + pumpString("b", getM()) +
pumpString("a", getM()) + pumpString("b", getM());
}
public void chooseDecomposition()
{
int x, half;
half = w.length()/2;
String first, last;
//If possible, just set the first characters in the w strings.
if (m > half) {
setDecomposition(new int[] {0, 1, half-1, 1});
return;
}
//Otherwise, check to see if there is a pattern.
for (int i=half-m+1; i -1 && v.indexOf("b") == -1 &&
y.indexOf("a") > -1 && y.indexOf("b") == -1)
return true;
return false;
}
public String description()
{
return "v is a string of \"a\"s and y is a string of \"a\"s";
}
public int[] getPreset()
{
return new int[]{0, 1, 0, 1};
}
});
/*
* v is string of a's and y is string of a's followed by b's
*/
myAllCases.add(new Case()
{
public boolean isCase(String v, String y)
{
if(v.indexOf("a") > -1 && v.indexOf("b") == -1 &&
y.indexOf("a") > -1 && y.indexOf("b") > -1 &&
y.indexOf("a") < y.indexOf("b"))
return true;
return false;
}
public String description()
{
return "v is a string of \"a\"s and y is a string of \"a\"s followed by \"b\"s";
}
public int[] getPreset()
{
return new int[]{1, 1, 0, m-1};
}
});
/*
* v is string of a's and y is string of b's
*/
myAllCases.add(new Case()
{
public boolean isCase(String v, String y)
{
if(v.indexOf("a") > -1 && v.indexOf("b") == -1 &&
y.indexOf("a") == -1 && y.indexOf("b") > -1)
return true;
return false;
}
public String description()
{
return "v is a string of \"a\"s and y is a string of \"b\"s";
}
public int[] getPreset()
{
return new int[]{m - 1, 1, 0, 1};
}
});
/*
* v is string of a's followed by b's and y is string of b's
*/
myAllCases.add(new Case()
{
public boolean isCase(String v, String y)
{
if(v.indexOf("a") > -1 && v.indexOf("b") > -1 &&
v.indexOf("a") < v.indexOf("b") &&
y.indexOf("a") == -1 && y.indexOf("b") > -1)
return true;
return false;
}
public String description()
{
return "v is a string of \"a\"s followed by \"b\"s and y is a string of \"b\"s";
}
public int[] getPreset()
{
return new int[]{m - 1, 2, 0, 1};
}
});
/*
* v is a string of b's and y is a string of b's
*/
myAllCases.add(new Case()
{
public boolean isCase(String v, String y)
{
if(v.indexOf("a") == -1 && v.indexOf("b") > -1 &&
y.indexOf("a") == -1 && y.indexOf("b") > -1)
return true;
return false;
}
public String description()
{
return "v is a string of \"b\"s and y is a string of \"b\"s";
}
public int[] getPreset()
{
return new int[]{m, 1, 0, 1};
}
});
/*
* v is a string of b's and y is a string of b's followed by a's
*/
myAllCases.add(new Case()
{
public boolean isCase(String v, String y)
{
if(v.indexOf("a") == -1 && v.indexOf("b") > -1 &&
y.indexOf("a") > -1 && y.indexOf("b") > -1 &&
y.indexOf("a") > y.indexOf("b"))
return true;
return false;
}
public String description()
{
return "v is a string of \"b\"s and y is a string of \"b\"s followed by \"a\"s";
}
public int[] getPreset()
{
return new int[]{2 * m - 2, 1, 0, 2};
}
});
/*
* v is a string of b's and y is a string of a's
*/
myAllCases.add(new Case()
{
public boolean isCase(String v, String y)
{
if(v.indexOf("a") == -1 && v.indexOf("b") > -1 &&
y.indexOf("a") > -1 && y.indexOf("b") == -1)
return true;
return false;
}
public String description()
{
return "v is a string of \"b\"s and y is a string of \"a\"s";
}
public int[] getPreset()
{
return new int[]{2 * m - 1, 1, 0, 1};
}
});
/*
* v is a string of b'a followed by a's and y is a string of a's
*/
myAllCases.add(new Case()
{
public boolean isCase(String v, String y)
{
if(v.indexOf("a") > -1 && v.indexOf("b") > -1 &&
v.indexOf("a") > v.indexOf("b") &&
y.indexOf("a") > -1 && y.indexOf("b") > -1 )
return true;
return false;
}
public String description()
{
return "v is a string of \"b\"s followed by \"a\"s and y is a string of \"a\"s";
}
public int[] getPreset()
{
return new int[]{2 * m - 1, 2, 0, 1};
}
});
/*
* v is an empty string and y is a non-empty string
*/
myAllCases.add(new Case()
{
public boolean isCase(String v, String y)
{
if(v.length() == 0 && y.length() > 0)
return true;
return false;
}
public String description()
{
return "v is an empty string and y is a non-empty string";
}
public int[] getPreset()
{
return new int[]{2 * m, 0, 1, 1};
}
});
/*
* v is a non-empty string and y is an empty string
*/
myAllCases.add(new Case()
{
public boolean isCase(String v, String y)
{
if(v.length() > 0 && y.length() == 0)
return true;
return false;
}
public String description()
{
return "v is a non-empty string and y is an empty string";
}
public int[] getPreset()
{
return new int[]{2 * m, 1, 0, 0};
}
});
}
public boolean isInLang(String s)
{
int a, b;
char[] list = new char[]{'a','b'};
if (LemmaMath.otherCharactersFound(s, list))
return false;
String first, last;
int halfSize = s.length() / 2;
first = s.substring(0, halfSize);
last = s.substring(halfSize);
if (first.equals(last))
return true;
return false;
}
}