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