/* * 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.*; /** * The regular pumping lemma for L = * {anbn : n ≥ 0}. * * @author Jinghui Lim & Chris Morgan */ public class AnBn extends RegularPumpingLemma { public String getTitle() { return "a^n b^n : n >= 0"; } public String getHTMLTitle() { return "anbn : n " + GREATER_OR_EQ + " 0"; } public void setDescription() { partitionIsValid = false; explanation = "For any m value, a possible value for w is \"am" + "bm\". The y value thus would be a multiple of \"a\". " + "For any i "+ NOT_EQUAL +" 1, na "+ NOT_EQUAL +" nb, giving a string " + "which is not in the language. Thus, the language is not regular."; } protected void chooseW() { w = pumpString("a", m) + pumpString("b", m); } public void chooseI() { i = LemmaMath.flipCoin(); } protected void setRange() { myRange = new int[]{4, 18}; } public boolean isInLang(String s) { int a, b; char[] list = new char[]{'a','b'}; if (LemmaMath.isMixture(s, list)) return false; a = LemmaMath.countInstances(s, 'a'); b = LemmaMath.countInstances(s, 'b'); if (a==b) return true; return false; } }