/*
* 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.reg;
import pumping.LemmaMath;
import pumping.RegularPumpingLemma;
/**
* The regular pumping lemma for L =
* {w ∈ {a, b}* : na
* (w) < nb (w)}.
*
* @author Jinghui Lim & Chris Morgan
*/
public class NaNb extends RegularPumpingLemma
{
public String getHTMLTitle()
{
return "w " + ELEMENT_OF + " " + AB_STAR + " : na (w) " +
LESS_THAN + " nb (w)";
}
public String getTitle()
{
return "w element_of {ab}* : na(w) < nb(w)";
}
public void setDescription()
{
partitionIsValid = false;
explanation = "For any m value, a possible value for w is \"am" +
"bm+1\". The y value thus would be a multiple of \"a\". " +
"For any i " + GREATER_THAN + " 1, na " + GREATER_OR_EQ + " nb, " +
"giving a string which is not in the language. Thus, the language is not regular.";
}
protected void chooseW()
{
w = pumpString("a", getM()) + pumpString("b", getM() + 1);
}
public void chooseDecomposition()
{
setDecomposition(new int[] {Math.min(m-1, w.indexOf('b')), 1});
}
public void chooseI()
{
i = 2;
}
protected void setRange()
{
myRange = new int[]{2, 17};
}
public boolean isInLang(String s)
{
int a, b;
char[] list = new char[]{'a', 'b'};
if (LemmaMath.otherCharactersFound(s, list))
return false;
a = LemmaMath.countInstances(s, 'a');
b = LemmaMath.countInstances(s, 'b');
if (a < b)
return true;
return false;
}
}