type phrase = Str of string | Opts of phrase array array let _ = Random.self_init () let randelt a = a.(Random.int (Array.length a)) let rec print phr = match phr with Str s -> print_string s | Opts options -> let parts = randelt options in Array.iter print parts (* Grammar definitions *) let rec top = Opts [| [| theorem;|]; [| theorem;|]; [| theorem;|]; [| theorem;|]; |] and theorem = Opts [| [| Str "\\begin{theorem}["; thname; Str "]"; thmstatement; Str ". \\end{theorem} \\begin{proof} "; proof; Str " \\end{proof}";|]; |] and proof = Opts [| [| statement; Str ". "; conclusion; Str ".";|]; [| Str "See "; citation; Str ".";|]; [| statement; Str ". "; conclusion; Str ".";|]; [| statement; Str ". "; conclusion; Str ".";|]; |] and conclusion = Opts [| [| Str "The result follows by d\\'evissage";|]; [| Str "The theorem follows trivially";|]; [| Str "The conclusion is self-evident";|]; [| Str "Clearly, the theorem holds";|]; [| Str "We leave the rest as an exercise";|]; [| Str "This is the desired result";|]; [| Str "The rest follows from "; citation;|]; [| Str "QED";|]; [| Str "A simple application of "; famoustheorem; Str " completes the proof";|]; |] and famoustheorem = Opts [| [| mathguy; Str "'s theorem";|]; [| Str "Hilbert's problem "; nzdigit; zdigit;|]; [| Str "the Riemann Hypothesis";|]; [| Str "Perelman's theorem (formerly the Poincar\\'e Conjecture)";|]; [| Str "horizontal Iwasawa theory";|]; [| Str "Kummer theory";|]; [| Str "the different";|]; [| Str "Dynkin diagrams";|]; [| Str "Gegenbauer polynomials";|]; [| Str "trichotomy";|]; |] and thmstatement = Opts [| [| subject; Str " "; connection; Str " "; claim;|]; [| Str "If "; claim; Str " then "; claim;|]; |] and thname = Opts [| [| Str "The "; mathguypart; Str " "; mathnoun; Str " "; theoremtype;|]; [| mathguy; Str "'s "; modifier; Str " "; mathnoun; Str " "; theoremtype;|]; [| Str "The "; modifier; Str " "; mathnoun; Str " "; theoremtype;|]; |] and mathguypart = Opts [| [| mathguy;|]; [| mathguy; Str "-"; mathguypart;|]; |] and mathguy = Opts [| [| Str "Weierstrass";|]; [| Str "Thurston";|]; [| Str "K\\\"och";|]; [| Str "Kronecker";|]; [| Str "Lagrange";|]; [| Str "Cramer";|]; [| Str "Gauss";|]; [| Str "Euler";|]; [| Str "Euclid";|]; [| Str "Mazur";|]; [| Str "Elkies";|]; [| Str "Zorn";|]; [| Str "Bowditch";|]; [| Str "Russell";|]; [| Str "Cantor";|]; [| Str "Godel";|]; [| Str "de Moivre";|]; [| Str "Galois";|]; [| Str "Schwarz";|]; [| Str "Erd\\H{o}s";|]; [| Str "Laplace";|]; [| Str "Boltzmann";|]; [| Str "Kantorovich";|]; [| Str "Abel";|]; [| Str "Poincar\\'e";|]; [| Str "Peano";|]; [| Str "Riemann";|]; [| Str "Stokes";|]; [| Str "Lebesgue";|]; [| Str "Lipschitz";|]; [| Str "Bunyakovsky";|]; [| Str "Fermat";|]; [| Str "Urys\\\"ohn";|]; [| Str "Arzela";|]; [| Str "Ascoli";|]; [| Str "Ramanujan";|]; [| Str "Wiles";|]; [| Str "Lobachevsky";|]; [| Str "Sokhotskii";|]; [| Str "Bertrand";|]; [| Str "Fubini";|]; [| Str "Frobenius";|]; [| Str "Dynkin";|]; [| Str "Bieberbach";|]; [| Str "Gegenbauer";|]; [| Str "Swinnerton-Dyer";|]; [| Str "Stone";|]; [| Str "Pythagoras";|]; |] and bookadj = Opts [| [| Str "Algebraic";|]; [| Str "Geometric";|]; [| Str "Complex";|]; [| Str "Metrizable";|]; [| Str "Analytic";|]; [| Str "Non-Standard";|]; [| bookadj; Str " "; bookadj;|]; [| Str "Advanced "; bookadj;|]; [| Str "Non-Metrizable";|]; |] and booksubj = Opts [| [| Str "Number Theory";|]; [| Str "Topology";|]; [| Str "Analysis";|]; [| Str "Algebra";|]; [| Str "Manifolds";|]; [| Str "K-Theory";|]; [| Str "Constructions";|]; |] and booktitle = Opts [| [| mathguy; Str "'s {\\it "; bookadj; Str " "; booksubj; Str "}";|]; [| mathguy; Str "'s {\\it "; bookadj; Str " "; booksubj; Str "}, "; ordinal; Str " Edition";|]; [| mathguy; Str " and "; mathguy; Str "'s {\\it "; bookadj; Str " "; booksubj; Str "}";|]; [| Str "["; nzdigit; Str "]";|]; [| Str "["; mathguy; Str "]";|]; [| Str "{\\it "; bookadj; Str " "; booksubj; Str " Revisited}";|]; [| mathguy; Str "'s {\\it "; booksubj; Str " Revisited}";|]; |] and citation = Opts [| [| booktitle;|]; [| booktitle; Str ", page "; biginteger;|]; [| booktitle; Str ", "; bookthmtype; Str " "; smallinteger;|]; [| booktitle; Str ", "; bookthmtype; Str " "; nzdigit; Str "."; nzdigit; Str "."; nzdigit;|]; |] and modifier = Opts [| [| Str "first";|]; [| Str "second";|]; [| Str "third";|]; [| Str "implicit";|]; [| Str "inverse";|]; [| Str "normalizable";|]; [| Str "last";|]; [| Str "mean";|]; [| Str "average";|]; |] and ordinal = Opts [| [| Str "1st";|]; [| Str "2nd";|]; [| Str "3rd";|]; [| Str "4th";|]; |] and mathnoun = Opts [| [| Str "openness";|]; [| Str "completeness";|]; [| Str "function";|]; [| Str "isomorphism";|]; [| Str "diffeomorphism";|]; [| Str "homeomorphism";|]; [| Str "linearity";|]; [| Str "orthogonality";|]; [| Str "dimensionality";|]; [| Str "diagonalizability";|]; [| Str "symmetry";|]; [| Str "discreteness";|]; [| Str "asymmetry";|]; [| Str "boundary";|]; [| Str "value";|]; [| Str "covering";|]; [| Str "inequality";|]; [| Str "category";|]; [| Str "compactness";|]; [| Str "mapping";|]; [| Str "contraction";|]; [| Str "metrization";|]; [| Str "quantization";|]; [| Str "multiplier";|]; |] and bookthmtype = Opts [| [| Str "Theorem";|]; [| Str "Lemma";|]; [| Str "Corollary";|]; [| Str "Proposition";|]; [| Str "Definition";|]; [| Str "Exercise";|]; |] and theoremtype = Opts [| [| Str "theorem";|]; [| Str "lemma";|]; [| Str "conjecture";|]; [| Str "hypothesis";|]; |] and subject = Opts [| [| prefix; Str " "; vobject; Str ",";|]; [| prefix; Str " "; cobject; Str ",";|]; [| statement; Str ". then";|]; [| prefix; Str " "; variable; Str " "; comparison; Str " "; constant; Str ",";|]; |] and statement = Opts [| [| Str "let "; variable; Str " be a "; cobject;|]; [| Str "let "; variable; Str " be an "; vobject;|]; [| Str "suppose "; variable; Str " is a "; cobject;|]; [| Str "suppose "; variable; Str " is an "; vobject;|]; [| Str "suppose "; variable; Str " is a "; cobject; Str " and "; statement;|]; [| Str "suppose "; variable; Str " is an "; vobject; Str " and "; statement;|]; |] and thing = Opts [| [| Str "a "; cobject;|]; [| Str "an "; vobject;|]; [| variable; Str " "; comparison; Str " "; constant;|]; [| thing; Str " and "; thing;|]; [| Str "a unique "; cobject;|]; [| Str "a unique "; vobject;|]; |] and ergo = Opts [| [| Str "therefore";|]; [| Str "now";|]; [| Str "hence";|]; [| Str "consequently";|]; [| Str "thus";|]; [| Str "ergo";|]; |] and connection = Opts [| [| Str "there exists "; thing; Str " such that";|]; [| Str "if "; claim; Str " then";|]; |] and prefix = Opts [| [| Str "given some";|]; [| Str "given any";|]; [| Str "for any";|]; [| Str "for every";|]; [| Str "for an arbitrary";|]; |] and cobject = Opts [| [| Str "vector "; variable;|]; [| Str "tensor "; variable;|]; [| cspacemodifier; Str " "; setbit;|]; [| csequencemodifier; Str " "; seriesbit;|]; [| cfunctionmodifier; Str " "; afunction;|]; [| afunction; Str " "; funname; Str " of "; variable;|]; |] and funname = Opts [| [| Str "$"; texfun; Str "$";|]; |] and texfun = Opts [| [| Str "\\zeta";|]; [| Str "\\Gamma";|]; [| Str "p";|]; [| Str "f";|]; [| Str "g";|]; [| Str "y";|]; [| Str "h";|]; [| Str "y'";|]; [| Str "f'";|]; [| Str "\\xi";|]; [| Str "f^{-1}";|]; [| Str "\\phi";|]; [| Str "\\psi";|]; |] and vobject = Opts [| [| vspacemodifier; Str " "; setbit;|]; [| vsequencemodifier; Str " "; seriesbit;|]; [| vfunctionmodifier; Str " "; afunction;|]; |] and setbit = Opts [| [| Str "subspace of "; field;|]; [| Str "vector space over "; field;|]; [| Str "subset of "; field;|]; [| Str "group in "; field;|]; [| Str "manifold locally resembling "; field;|]; [| Str "polytope in "; field;|]; [| Str "tangent space of "; field; Str " at "; variable;|]; [| Str "irreducible representation of "; field;|]; [| nzdigit; Str "-dimensional Riemann surface";|]; |] and seriesbit = Opts [| [| Str "series in "; field;|]; [| Str "series";|]; [| Str "sequence in "; field;|]; [| Str "sequence";|]; |] and cspacemodifier = Opts [| [| Str "bounded";|]; [| Str "non-empty";|]; [| Str "closed";|]; [| Str "compact";|]; [| Str "trivial";|]; [| Str "non-trivial";|]; [| Str "connected";|]; [| Str "disjoint";|]; [| Str "finite";|]; [| Str "discrete";|]; [| Str "Euclidean";|]; |] and vspacemodifier = Opts [| [| Str "open";|]; [| Str "unbounded";|]; [| Str "infinite";|]; [| Str "isotropic";|]; |] and csequencemodifier = Opts [| [| Str "convergent";|]; [| Str "divergent";|]; [| Str "bounded";|]; [| Str "finite";|]; [| Str "Cauchy";|]; [| Str "square-summable";|]; |] and vsequencemodifier = Opts [| [| Str "infinite";|]; [| Str "alternating";|]; [| Str "unbounded";|]; [| Str "absolutely convergent";|]; |] and vfunctionmodifier = Opts [| [| Str "even";|]; [| Str "odd";|]; [| Str "antisymmetric";|]; [| Str "integrable";|]; |] and cfunctionmodifier = Opts [| [| Str "continuous";|]; [| Str "smooth";|]; [| Str "differentiable";|]; [| Str "positive";|]; [| Str "negative";|]; [| Str "non-degenerate";|]; [| Str "skew-symmetric";|]; [| Str "linear";|]; [| Str "multilinear";|]; [| Str "nonlinear";|]; [| Str "differential";|]; [| Str "quadratic";|]; [| Str "symmetric";|]; [| Str "positive-definite";|]; [| Str "bilinear";|]; [| Str "sesquilinear";|]; [| Str "piecewise "; cfunctionmodifier;|]; |] and variable = Opts [| [| Str "$\\lambda$";|]; [| Str "$\\alpha$";|]; [| Str "$\\beta$";|]; [| Str "$\\gamma$";|]; [| Str "$\\epsilon$";|]; [| Str "$\\delta$";|]; [| Str "$\\mu$";|]; [| Str "$\\rho$";|]; [| Str "$\\nu$";|]; [| Str "$\\psi$";|]; [| Str "$a_n$";|]; [| Str "$x_n$";|]; [| Str "$x_i$";|]; [| Str "$\\theta$";|]; [| Str "$v$";|]; [| Str "$u$";|]; [| Str "$w$";|]; [| Str "$x$";|]; [| Str "$y$";|]; [| Str "$z$";|]; [| Str "$b$";|]; [| Str "$\\omega$";|]; [| Str "$\\phi$";|]; |] and nzdigit = Opts [| [| Str "1";|]; [| Str "2";|]; [| Str "3";|]; [| Str "4";|]; [| Str "5";|]; [| Str "6";|]; [| Str "7";|]; [| Str "8";|]; [| Str "9";|]; |] and zdigit = Opts [| [| Str "0";|]; [| Str "1";|]; [| Str "2";|]; [| Str "3";|]; [| Str "4";|]; [| Str "5";|]; [| Str "6";|]; [| Str "7";|]; [| Str "8";|]; [| Str "9";|]; |] and smallinteger = Opts [| [| nzdigit;|]; [| nzdigit;|]; [| nzdigit; zdigit;|]; |] and biginteger = Opts [| [| zdigit;|]; [| nzdigit; biginteger;|]; |] and pninteger = Opts [| [| Str "0";|]; [| smallinteger;|]; [| Str "$-"; smallinteger; Str "$";|]; |] and constant = Opts [| [| Str "$\\pi$";|]; [| Str "$e$";|]; [| Str "$\\kappa$";|]; [| Str "$0$";|]; [| Str "$1$";|]; [| Str "$\\epsilon$";|]; [| Str "$\\delta$";|]; [| pninteger;|]; |] and texfield = Opts [| [| Str "\\Z";|]; [| Str "\\Q";|]; [| Str "\\R";|]; [| Str "\\C";|]; [| Str "\\Q_p";|]; [| Str "\\Z/p\\Z";|]; [| Str "\\mathbb{H}";|]; |] and texgroup = Opts [| [| texfield;|]; [| texfield; Str "^"; n;|]; [| Str "H";|]; [| Str "G";|]; |] and n = Opts [| [| Str "n";|]; [| Str "n";|]; [| nzdigit;|]; [| Str "m";|]; |] and field = Opts [| [| Str "$"; texfield; Str "$";|]; [| Str "$"; texgroup; Str "$";|]; [| Str "$"; texgroup; Str "$";|]; [| Str "$\\mathcal{C}("; texfield; Str ")$";|]; [| Str "$"; texfield; Str "[x]$";|]; [| Str "$\\mathrm{GL}_"; n; Str "("; texfield; Str ")$";|]; [| Str "$\\mathrm{SU}("; nzdigit; Str ")$";|]; [| Str "$\\mathrm{M}_n("; texfield; Str ")$";|]; [| Str "$\\mathrm{Hom}("; texgroup; Str ","; texgroup; Str ")$";|]; [| Str "$\\mathrm{Ker}(T)$";|]; [| Str "$H^"; n; Str "("; texgroup; Str ","; texgroup; Str ")$";|]; [| Str "$"; texgroup; Str " \\otimes "; texgroup; Str "$";|]; [| Str "the $p$-adics";|]; [| Str "$\\mathrm{Im}(T)$";|]; [| Str "$\\mathrm{Ker}(\\phi)$";|]; |] and comparison = Opts [| [| Str "$\\lt$";|]; [| Str "$\\gt$";|]; [| Str "$\\geq$";|]; [| Str "$\\leq$";|]; |] and claim = Opts [| [| claimstart; Str " an "; vspacemodifier; Str " "; setbit; Str " "; spaceaction;|]; [| claimstart; Str " a "; cspacemodifier; Str " "; setbit; Str " "; spaceaction;|]; [| claimstart; Str " a "; cfunctionmodifier; Str " "; afunction; Str " "; funcaction;|]; [| claimstart; Str " an "; vfunctionmodifier; Str " "; afunction; Str " "; funcaction;|]; [| claimstart; Str " a "; csequencemodifier; Str " "; seriesbit; Str " "; seriesaction;|]; [| claimstart; Str " an "; vsequencemodifier; Str " "; seriesbit; Str " "; seriesaction;|]; [| claimstart; Str " some vector "; variable; Str " "; vecaction;|]; [| funname; Str " is a well-defined "; mapping; Str " from "; field; Str " to "; field;|]; [| Str "the following diagram commutes: "; commdiagram;|]; [| Str "the sequence \\begin{eqnarray}"; texexactsequence; Str "\\end{eqnarray} is exact";|]; |] and commdiagram = Opts [| [| Str "\\begin{eqnarray}"; heightonediagram; Str "\\end{eqnarray}";|]; [| Str "\\begin{eqnarray}"; heightonediagram; Str "\\end{eqnarray}";|]; [| Str "\\begin{eqnarray}"; heighttwodiagram; Str "\\end{eqnarray}";|]; |] and heightonediagram = Opts [| [| onediagleft; onediagmiddle; onediagright;|]; |] and onediagleft = Opts [| [| Str "\\onebyone"; fourgroups; fourfuns;|]; [| Str "\\onebyone"; fourgroups; fourfuns;|]; [| Str "\\oneldots\\rightaddone{"; texfun; Str "}{"; texgroup; Str "}{"; texfun; Str "}{"; texfun; Str "}{"; texgroup; Str "}";|]; |] and onediagright = Opts [| [| Str "\\nothing";|]; [| Str "\\rightaddone{"; texfun; Str "}{"; texgroup; Str "}{"; texfun; Str "}{"; texfun; Str "}{"; texgroup; Str "}";|]; [| Str "\\rightaddonedots{"; texfun; Str "}{"; texfun; Str "}";|]; |] and onediagmiddle = Opts [| [| Str "\\rightaddone{"; texfun; Str "}{"; texgroup; Str "}{"; texfun; Str "}{"; texfun; Str "}{"; texgroup; Str "}";|]; [| Str "\\nothing";|]; [| Str "\\rightaddone{"; texfun; Str "}{"; texgroup; Str "}{"; texfun; Str "}{"; texfun; Str "}{"; texgroup; Str "}"; onediagmiddle;|]; |] and heighttwodiagram = Opts [| [| twodiagleft; twodiagmiddle; twodiagright;|]; |] and twodiagleft = Opts [| [| Str "\\begin{diagram} \\squarecode"; fourgroups; fourfuns; Str " \\bottomadd{"; texfun; Str "}{"; texfun; Str "}{"; texgroup; Str "}{"; texfun; Str "}{"; texgroup; Str "} \\end{diagram}";|]; [| Str "\\begin{diagram} \\squarecode"; fourgroups; fourfuns; Str " \\bottomadd{"; texfun; Str "}{"; texfun; Str "}{"; texgroup; Str "}{"; texfun; Str "}{"; texgroup; Str "} \\end{diagram}";|]; [| Str "\\twoldots\\rightaddtwo{"; texfun; Str "}{"; texgroup; Str "}{"; texfun; Str "}{"; texfun; Str "}{"; texgroup; Str "} {"; texfun; Str "}{"; texfun; Str "}{"; texgroup; Str "}";|]; |] and twodiagmiddle = Opts [| [| Str "\\nothing";|]; [| Str "\\rightaddtwo{"; texfun; Str "}{"; texgroup; Str "}{"; texfun; Str "}{"; texfun; Str "}{"; texgroup; Str "} {"; texfun; Str "}{"; texfun; Str "}{"; texgroup; Str "}";|]; [| Str "\\rightaddtwo{"; texfun; Str "}{"; texgroup; Str "}{"; texfun; Str "}{"; texfun; Str "}{"; texgroup; Str "} {"; texfun; Str "}{"; texfun; Str "}{"; texgroup; Str "}"; twodiagmiddle;|]; |] and twodiagright = Opts [| [| Str "\\nothing";|]; [| Str "\\rightaddtwo{"; texfun; Str "}{"; texgroup; Str "}{"; texfun; Str "}{"; texfun; Str "}{"; texgroup; Str "} {"; texfun; Str "}{"; texfun; Str "}{"; texgroup; Str "}";|]; [| Str "\\rightaddtwodots{"; texfun; Str "}{"; texfun; Str "}{"; texfun; Str "}";|]; |] and fourgroups = Opts [| [| Str "{"; texgroup; Str "}{"; texgroup; Str "}{"; texgroup; Str "}{"; texgroup; Str "}";|]; |] and fourfuns = Opts [| [| Str "{"; texfun; Str "}{"; texfun; Str "}{"; texfun; Str "}{"; texfun; Str "}";|]; |] and texexactsequence = Opts [| [| texgroup; Str " \\rTo^{"; texfun; Str "} "; texseqmid;|]; [| Str "0 \\rTo "; texseqmid;|]; [| Str "\\dots \\rTo "; texgroup; Str " \\rTo^{"; texfun; Str "} "; texgroup; Str " \\rTo^{"; texfun; Str "} "; texseqmid;|]; |] and texseqmid = Opts [| [| texgroup; Str " \\rTo "; texseqend;|]; [| texgroup; Str " \\rTo^{"; texfun; Str "} "; texseqend;|]; |] and texseqend = Opts [| [| texgroup;|]; [| texgroup; Str " \\rTo 0";|]; [| texgroup; Str " \\rTo^{"; texfun; Str "} "; texgroup; Str " \\rTo \\dots";|]; [| texgroup; Str " \\rTo^{"; texfun; Str "} "; texseqend;|]; [| texgroup; Str " \\rTo^{"; texfun; Str "} "; texseqend;|]; |] and mapping = Opts [| [| Str "function";|]; [| Str "mapping";|]; [| Str "homomorphism";|]; [| Str "homeomorphism";|]; [| Str "isomorphism";|]; [| Str "surjective "; mapping;|]; [| Str "injective "; mapping;|]; [| Str "holomorphism";|]; [| Str "biholomorphism";|]; [| Str "isometry";|]; |] and claimstart = Opts [| [| Str "there is";|]; [| Str "we can construct";|]; |] and spaceaction = Opts [| [| Str "isomorphic to "; field;|]; [| Str "contained within "; field;|]; [| Str "containing "; thing;|]; [| Str "diffeomorphic to "; field;|]; [| Str "homeomorphic to a "; setbit;|]; [| Str "in the "; intersection;|]; [| Str "not in the "; intersection;|]; |] and funcaction = Opts [| [| Str "that diverges";|]; [| Str "whose "; alimit; Str " is "; constant;|]; [| Str "that is Lipschitz";|]; |] and seriesaction = Opts [| [| Str "that diverges";|]; [| Str "that converges to "; constant;|]; [| Str "that contains "; constant;|]; [| Str "whose terms are all "; comparison; Str " "; constant;|]; [| Str "containing "; thing;|]; |] and vecaction = Opts [| [| Str "contained within "; field;|]; [| Str "not in the "; intersection;|]; [| Str "in the "; intersection;|]; |] and alimit = Opts [| [| Str "limit as "; variable; Str " approaches "; constant;|]; |] and intersection = Opts [| [| Str "intersection of "; field; Str " and "; field;|]; [| Str "union of "; field; Str " with "; field;|]; [| Str "quotient of "; field; Str " and "; field;|]; |] and afunction = Opts [| [| Str "$k$-form";|]; [| Str "function";|]; [| Str "mapping";|]; [| Str "transformation";|]; [| Str "relation";|]; [| Str "form ";|]; |] let _ = print top let _ = print_string "\n"