<commit_before># SLO = Simplify Linear Operator.
#
#  This assumes that the input is the output of Language.Hakaru.Syntax.tester
# No checking is done that this is actually the case.
#
# SLO : simplifier
# AST : takes simplified form and transform to AST
# Print: (ToDo) print an AST back to Haskell
#

SLO := module ()
  export ModuleApply, AST, c; # very important: this c is "global".
  local ToAST;

  # right now, simplification means just evaluate!
  ModuleApply := proc(inp::anything) 
    try
      inp(c);
    catch "Wrong kind of parameters in piecewise":
      error "Bug in Hakaru -> Maple translation, piecewise used incorrectly.";
    end try;
  end proc;

  # AST transforms the Maple to a representation of the mochastic AST
  AST := proc(inp::anything)
    local cs;
    cs := indets(inp, 'specfunc'(anything,c));
    # deal with trivial input first
    if inp=0 then
        0
    # then deal with 'bad' input
    elif nops(cs) = 0 then
      error "the constant", inp, " is not a measure."
    elif nops(cs) > 1 then <commit_msg>handle sums of measures<commit_after># SLO = Simplify Linear Operator.
#
#  This assumes that the input is the output of Language.Hakaru.Syntax.tester
# No checking is done that this is actually the case.
#
# SLO : simplifier
# AST : takes simplified form and transform to AST
# Print: (ToDo) print an AST back to Haskell
#

SLO := module ()
  export ModuleApply, AST, c; # very important: this c is "global".
  local ToAST;

  # right now, simplification means just evaluate!
  ModuleApply := proc(inp::anything) 
    try
      inp(c);
    catch "Wrong kind of parameters in piecewise":
      error "Bug in Hakaru -> Maple translation, piecewise used incorrectly.";
    end try;
  end proc;

  # AST transforms the Maple to a representation of the mochastic AST
  AST := proc(inp::anything)
    local cs;
    cs := indets(inp, 'specfunc'(anything,c));
    # deal with trivial input first
    if inp=0 then
        0
    # then deal with 'bad' input
    elif nops(cs) = 0 then
      error "the constant", inp, " is not a measure."
    elif type(inp, `+`) then
      map(AST, SUM(op(inp)))
    elif nops(cs) > 1 then 
{'fraction_non_alphanumeric': 0.0956561922365989, 'fraction_numerical': 0.0036968576709796672, 'mean_word_length': 3.100378787878788, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7184553', 'n_tokens_mistral': 714, 'n_tokens_neox': 657, 'n_words': 278}