<commit_before>#= require lib/logger

ttm.define "lib/math/expression_evaluation",
  ['lib/class_mixer', 'lib/object_refinement', 'logger'],
  (class_mixer, object_refinement, logger_builder)->

    logger = logger_builder.build(stringify_objects: false)

    MalformedExpressionError = (message)->
      @name = 'MalformedExpressionError'
      @message = message
      @stack = (new Error()).stack
    MalformedExpressionError.prototype = new Error;

    comps = ttm.require("lib/math/expression_components")
    refinement = object_refinement.build()
    refinement.forType(comps.number,
      {
        eval: ->
          @  # a number returns itself when it evaluates
      });

    refinement.forType(comps.exponentiation,
      {
        eval: (evaluation, pass)->
          return if pass != "exponentiation"
          if @base() && @power()
            comps.number.build(value: Math.pow(@base().toCalculable(), @power().toCalculable()))
          else
            throw new MalformedExpressionError("Invalid Expression")
      });

<commit_msg>updates exponentiation to wrap base and power in expressions<commit_after>#= require lib/logger

ttm.define "lib/math/expression_evaluation",
  ['lib/class_mixer', 'lib/object_refinement', 'logger'],
  (class_mixer, object_refinement, logger_builder)->

    logger = logger_builder.build(stringify_objects: false)

    MalformedExpressionError = (message)->
      @name = 'MalformedExpressionError'
      @message = message
      @stack = (new Error()).stack
    MalformedExpressionError.prototype = new Error;

    comps = ttm.require("lib/math/expression_components")
    refinement = object_refinement.build()
    refinement.forType(comps.number,
      {
        eval: ->
          @  # a number returns itself when it evaluates
      });

    refinement.forType(comps.exponentiation,
      {
        eval: (evaluation, pass)->
          return if pass != "exponentiation"
          if @base() && @power()
            base = refinement.refine(@base()).eval().toCalculable()
            power = refinement.refine(@power()).eval().toCalculable()
            logger.info("exponentiation", base, power)
            comps.number.build(value: Math.pow(base, power))
          else
            throw new MalformedExpressionError("Invalid Expression")
      });

{'fraction_non_alphanumeric': 0.12418866291648636, 'fraction_numerical': 0.0, 'mean_word_length': 2.972508591065292, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7242771', 'n_tokens_mistral': 653, 'n_tokens_neox': 644, 'n_words': 131}