Skip to content

Instantly share code, notes, and snippets.

@karino2
Last active September 1, 2019 06:37
Show Gist options
  • Save karino2/132b249314d250eb85ee198992f8825f to your computer and use it in GitHub Desktop.
Save karino2/132b249314d250eb85ee198992f8825f to your computer and use it in GitHub Desktop.
mathbbrId = sym2id["\\mathbb{R}"]
char_names = ["\\sigma", "\\pi", "H", "L", "P", "T", "x", "d", "h", "l", "p", "t",
"X", "\\gamma", "\\theta", "C", "G", "S", "c", "z", "g", "k", "o",
"s", "w", "\\alpha", "\\lambda", "B", "F", "N", "R", "V", "b", "f",
"j", "n", "r", "v", "\\phi","A", "E", "\\beta", "I", "M", "Y", "\\mu",
"a", "e", "i", "m", "q", "u", "y"]
binop_names = ["+", "-", "\\times", "\\div", "\\pm"]
eqop_names = ["\\geq", ">", "\\leq", "<", "="]
nonzero_num_names = [str(i) for i in range(1, 10)]
num_names = [str(i) for i in range(0, 10)]
SubS = SubscF(CharS, NumCharS)
SupS = SupscF(CharS, NumCharS)
TwoTermS = TwoTermF(NumCharS, CharS)
MathbbrS = OneOfNamesF(["\\mathbb{R}"])
SupOfRnS = OneOfNamesF(nonzero_num_names+ ["n", "m"])
RnS = SupscF(MathbbrS, SupOfRnS)
OneSymbolS = OneOfIdsF(list(set(catids.num + catids.char + catids.eqop + [mathbbrId])))
normalBinOpS = OneOfNamesF(['+', '-', '\\times'])
rareBinOpS = OneOfNamesF(['\\div', '\\pm'])
BinopRawS = OrF([0.9, normalBinOpS],
[0.1, rareBinOpS])
otherEqOpNames = list(set(eqop_names).difference(set(["="])))
equalEqOpS = OneOfNamesF(["="])
otherEqOpS = OneOfNamesF(otherEqOpNames)
EqopRawS = OrF([0.5, equalEqOpS],
[0.5, otherEqOpS])
BinopS = ScaleF(BinopRawS, 0.6)
EqopS = ScaleF(EqopRawS, 0.6)
termBaseS = OrF(
[0.33, CharS],
[0.33, SupS],
[0.33, SubS]
)
oneTermS = OrF(
[0.3, TwoTermF(NonzeroNumS, termBaseS)],
[0.7, termBaseS]
)
OneBinopOneS = HoriF(oneTermS, BinopS, oneTermS)
EqExpS = HoriF(oneTermS, BinopS, oneTermS, MoveLeftF(EqopS, 1000))
Pattern2S = OrF(
[0.15, OneSymbolS],
[0.025, RnS],
[0.1, SubS],
[0.1, SupS],
[0.1, TwoTermS],
[0.2, OneBinopOneS],
[0.3, EqExpS]
)
# train: generate_samples(Pattern2S, 500000)
# valid: generate_samples(Pattern2S, 50000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment