[syllabus] | [lecture notes] | [HW1-6,Q1] | [HW7-10,Q2,F] | [project]
[simulators/parsers] | [language definitions] | [automata definitions] | [computable definitions]
The files referenced on this page are all available on UMBC9 (gl) for copying to your directory using a command such as: cp /afs/umbc.edu/users/s/q/squire/pub/download/tm.cpp .
The C++ source code is tm.cpp Sample input is add.tm Sample output is add.chk command line: tm < add.tm > add.chk This simulator works as a language recognizer and accepts or rejects the contents of the input tape. (final mode) This simulator also works as a function computer using the initial contents of the tape as the input and the final contents of the tape as the output. (halt mode) A Turing machine M = (Q, Sigma, Gamma, delta, q0, B, F) where Q is finite set of states including q0 Sigma is a finite set of input symbols not including B Gamma is a finite set of tape symbols including Sigma and B delta is a transitions mapping Q X Gamma to Q X Gamma X {L,R,N} q0 is the initial state B is blank tape symbol F is a finite set of final states Input Conventions: The file name extension is typically .tm free form plain text input file typical execution is tm < your_input.tm > your_output.out A comment line has "// " as the first three characters A line may end with a comment using whitespace "//" Anything after whitespace after last expected input is a comment There are only a few keywords: start, final, halt, trace, limit, enddef and tape any line not starting with these keywords is a transition 'enddef' is only needed when more than one 'tape' is to be read only 'tape' lines may follow an 'enddef' line there is no such thing as a continuation line. A transition is a five tuple: from-state input-symbol to-state symbol-to-write move at least one transition is required a typical dummy transition is phi #b phi ## N special input-symbol #b for the blank character, #[ for beginning of tape #] for end of tape #e for epsilon transition special symbol-to-write #b for blank character ## for no character to write move is L or l for left one space on the tape R or r for right one space on the tape N or n for do not move the tape head anything else becomes "R" Anything after the required field(s) is a comment if symbol-to-write is "// " then the rest of the line is a comment and symbol-to-write becomes ## and move becomes R, as in a DFA subset of a TM. if move is "// " then move becomes "N" and and the rest of the line is treated as a comment The input and output tape may contain only printable characters Use #b to input a blank (space) character on the input tape If you want a blank on each end of your tape, use #byour-stuff#b The initial position will point to your first tape character #] will be appended as a right_end character #[ will be appended as a left_end character Final states are entered as: final state-name The default mode is language (string) recognition. Computation mode is specified using: halt or halt state-name A full trace can be obtained using: trace all or a partial trace can be obtained by one or more trace lines with the name of a state to be traced: trace state-name The staring state is specified using: start state-name Examples: There are a number of examples in the download directory with file extension .tm In particular, a very simple unary adder add.tm and associated output add.chk A simple unary proper subtraction sub.tm and associated output sub.chk A language recognizer for L = { a^n b^n c^n | n>0 } labc.tm and associated full trace output labc.chk A more complex binary number addition program b_add.tm and associated output b_add.chk
The C++ source code is ntm.cpp Sample input is exntm.ntm Sample output is exntm.chk command line: ntm < exntm.ntm > exntm.chk See TM above for input preparation. The only additional feature of NTM is that nondeterministic transitions are allowed. For example the delta transition table below has nondeterministic transitions from state q0. delta 0 1 q0 {(q0,1,R), (q3,0,L)} {q0,0,L), (q1,0,R)} q1 phi {q2,0,R} is coded as input: q0 0 q0 1 R q0 0 q3 0 L q0 1 q0 0 L q0 1 q1 0 R q1 1 q2 0 R The classic SAT recognizer using a NTM is sat.ntm and associated output sat.chk
The C++ source code is dfa.cpp Sample input is ab_b_all.dfa Sample output is ab_b_all.chk command line: dfa < ab_b_all.dfa > ab_b_all.chk Machine definition of a DFA M = (Q, Sigma, alpha, q0, F) where Q is set of states Sigma is input tape alphabet alpha is transition table q0 is the starting state F is the set of final states Input Conventions: The file name extension is typically .dfa free form plain text input file typical execution is dfa < your_input.dfa > your_output.out A comment line has "// " as the first three characters A line may end with a comment using whitespace "//" Anything after whitespace after last expected input is a comment There are only a few keywords: start, final, halt, trace, limit, enddef and tape any line not starting with these keywords is a transition 'enddef' is only needed when more than one 'tape' is to be read only 'tape' lines may follow an 'enddef' line there is no such thing as a continuation line A transition is a three tuple: from-state input-symbol to-state special input-symbol #b for the blank character, #e for epsilon transition at least one transition is required, the typical dummy transition is phi #b phi Anything after the required field(s) is a comment Use #b to input a blank (space) character on the input tape If you want a blank on the end of your tape, use your-stuff#b The initial position will point to your first tape character #] will be appended as a right_end character #[ will be appended as a left_end character Final states are entered as: final state-name The default mode is language (string) recognition when in a final state and the tape head is over the right_end termination symbol. Halt mode stops the simulation as soon as the DFA enters a state designated as a halt state, specified using: halt or halt state-name A full trace can be obtained using: trace all or a partial trace can be obtained by one or more trace lines with the name of a state to be traced: trace state-name The staring state is specified using: start state-name Other input data and output examples: reg.dfa reg.out
The C++ source code is nfa.cpp Sample input is fig2_7.nfa Sample output is fig2_7.chk command line: nfa < fig2_7.nfa > fig2_7.chk See DFA above for input preparation. The only additional feature of NFA is that nondeterministic transitions are allowed. For example the delta transition table below has nondeterministic transitions from state q0. delta 0 1 q0 {q0, q3} {q0, q1} q1 phi {q2} is coded as input: q0 0 q0 q0 0 q3 q0 1 q0 q0 1 q1 q1 1 q2 Another example for recognizing 0*1*2* is fig2_9.nfa and associated output fig2_9.chk
The C++ source code is myhill.cpp The input data format is given above in DFA. This program takes a DFA as input and uses the Myhill-Nerode Theorem to minimize the number of states. The output file is the minimized DFA. Execute the program using the command line: myhill initial_out.dfa < initial.dfa > initial.out A sample input file is initial.dfa The information output file is initial.out The minimized DFA is initial_out.dfa DO NOT use the same name for the input and output file! A simulation of the minimized DFA is initial_out_sim.out
Similar to the minimization of the number of states in a DFA using Myhill Nerode, combinational logic can be minimized to a sum of products. Sum of products represents two levels of digital logic, "and" gates followed by one "or" gate. The Quine McClusky algorithm requires NP time. For every number of digital inputs there is at least one function that requires a number of "and" "or" "not" gates that is exponential in the number of inputs when represented as a sum of products. The same exponential size is true for a product of sums representation, e.g. SAT. The source code for Quine McClusky is quine_mcclusky.c Also required, is calc_eqn.tab.c which can be built from calc_eqn.y using bison. All related files are in qm.tgz including Makefile_qm and examples qm -n 4 -t -i tt4.dat -o tt4.out tt4.dat tt4.out qm -n 4 -e -i eqn4.dat -o eqn4.out eqn4.dat eqn4.out qm -n 4 -m -i minterm4.dat -o minterm4.out minterm4.dat minterm4.out The input data may be any of: A truth table. (see tt4.dat above) A set of minterms. (see minterm4.dat above) A VHDL equation. (see eqn4.dat above) A Verilog equartion. (see eqn4.dat and eqn4.out above) The output is the set of prime implicants and the VHDL equation and the Verilog equation. For example, the output tt4.out is: Quine McClusky digital circuit minimization V1.0 initial minterms gr a b c d cv 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 1 1 1 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 0 0 1 1 1 1 0 final prime implicants gr a b c d cv 0 - 0 1 0 0 0 1 - 1 0 0 0 1 1 1 - 0 0 - 1 - 1 0 0 0 0 - 0 0 out <= ( not b and c and not d ) or ( a and c and not d ) or ( a and b and c ) or ( b and d ) or (not a and not b and not d ); out = ( ~b & c & ~d ) | ( a & c & ~d ) | ( a & b & c ) | ( b & d ) | (~a & ~b & ~d ); The executable program is called "qm" and the examples are run: qm -n 4 -t -i tt4.dat > tt4.out qm -n 4 -e -i eqn4.dat -o eqn4.out qm -n 4 -m -i minterm4.dat -o minterm4.out The standard format man page is qm.1
The C++ source code is cykp.cpp and other files including the Makefile_cykp cykp.h cyk_eliminate.cpp cyk_chomsky.cpp cyk_greibach.cpp cyk_parse.cpp Sample input is g_220v.g Sample output is g_220v.out command line: cykp < g_220v.g > g_220v.out The purpose of this program is not specifically to parse grammars, but rather to be able to output the "simplification" steps in Hopcroft and Ullman book. It does implement the CYK algorithm. There is also an output of Chomsky Normal Form and Greibach Normal Form. The Context Free Grammar G = ( V, T, P, S ) is input: variable A xyz any-name ; // end with space semicolon terminal 0 1 ; // single characters A -> 0 A 1 xyz ; // or A := 0 A 1 xyz // comment in place of ";" B := C D | B A ; // variables automatically found start A // required starting symbol enddef // end of grammar, start of strings 00110101 // input to parse 1100110 // more input to parse Minimum printout is obtained by not having a "verbose" in the input. verbose 3 // generates maximal useful output verbose 6 // generates debug printout (full trace) Enter epsilon as the two characters #e Enter the blank or space character as #b Other input data and output: g_140v.g g_140v.out g_97v.g g_97v.out g_90v.g g_90v.out g_paren.g g_paren.out g_reg.g g_reg.out A regular, right linear grammar, from a DFA. g_grei.g g_grei.out greibach.pda Greibach test
Report bugs or requests for additional features to squire@umbc.edu Last updated 1/25/2021