Arithmetic Expressions - CMUCTAT/CTAT GitHub Wiki

algEquiv, algEquivalent

algEquiv(expression1, expression2[, sameOrder]) or algEquivalent(expression1, expression2[, sameOrder])

  • Arguments:
    • expression1 - <String> An algebraic expression
    • expression2 - <String> An algebraic expression
    • sameOrder - <Boolean> Whether to require terms to be in the same order [optional, default is false]
  • Returns: <Boolean> - TRUE or FALSE
  • Description: Determine whether 2 algebraic expressions are equivalent when fully simplified.

Example Usage

algEquiv(input, "4x+9")

returns true if the student input is "9 + 4x" or "9+2x+2x"

More examples of behavior, where == and != indicate that the function returns true or false, respectively:

expression1 expression2
2x + x - 3 + 5 == 2*x + x + (-3) + 5
2x + x - 3 + 5 == x*2 + 1x + 5 - 3
2x + x - 3 + 5 == 3x + 2
2(x + x - 3) + 5*2 == 2(x + 1x - 3) + 2*5
2(x + x - 3) + 5*2 == (x + 1x - 3)2 + 2*5
2(x + x - 3) + 5*2 == (x + x*1 - 3*1)2 + 2*5
2(x + x - 3) + 5*2 == 5*2 + (x + x + (-3))2

algEquivTerms

algEquivTerms(expression1, expression2)

  • Arguments:
    • expression1 - <String> An algebraic expression
    • expression2 - <String> An algebraic expression
  • Returns: <Boolean> - TRUE or FALSE
  • Description: Determine whether 2 algebraic expressions are equivalent when simplified to discrete terms. This function will declare 2 expressions equivalent if their differences are limited to order of commutative operands, redundant parentheses and notational variants (2*x and 2x).

Example Usage

algEquivTerms(input, "4x+9")

returns true if the student input is "9 + 4x" but false if it's "9+2x+2x".

More examples of behavior, where == and != indicate that the function returns true or false, respectively:

expression1 expression2
2x + x - 3 + 5 == 2*x + x + (-3) + 5
2x + x - 3 + 5 == x*2 + 1x + 5 - 3
2x + x - 3 + 5 != 3x + 2
2(x + x - 3) + 5*2 == 2(x + 1x - 3) + 2*5
2(x + x - 3) + 5*2 == (x + 1x - 3)2 + 2*5
2(x + x - 3) + 5*2 == (x + x*1 - 3*1)2 + 2*5
2(x + x - 3) + 5*2 == 5*2 + (x + x + (-3))2

algEquivTermsSameOrder

algEquivTermsSameOrder(expression1, expression2)

  • Arguments:
    • expression1 - <String> An algebraic expression
    • expression2 - <String> An algebraic expression
  • Returns: <Boolean> - TRUE or FALSE
  • Description: Determine whether 2 algebraic expressions are equivalent when simplified to discrete terms. This function will declare 2 expressions equivalent if their differences are limited to order of commutative factor, redundant parentheses and notational variants (2*x and 2x). Unlike algEquivTerms, it will require that addends be in the same order.

Example Usage

algEquivTermsSameOrder(input, "4x+9")

returns true if the student input is "x*4 + 9" but false if it's "9+4x" or "2x+2x+9"

More examples of behavior, where == and != indicate that the function returns true or false, respectively:

expression1 expression2
2x + x - 3 + 5 == 2*x + x + (-3) + 5
2x + x - 3 + 5 != x*2 + 1x + 5 - 3
2x + x - 3 + 5 != 3x + 2
2(x + x - 3) + 5*2 == 2(x + 1x - 3) + 2*5
2(x + x - 3) + 5*2 == (x + 1x - 3)2 + 2*5
2(x + x - 3) + 5*2 == (x + x*1 - 3*1)2 + 2*5
2(x + x - 3) + 5*2 != 5*2 + (x + x + (-3))2

algEval

algEval(expression1)

  • Arguments:
    • expression1 - <String> An algebraic expression
  • Returns: <Number> - Result of evaluating the expression
  • Description: Attempt to evaluate an expression given the variable table and BRD-specific settings.

Example Usage

algEval("4x+9")

returns 41 if x=8 in the variable table.

eval

Simplify an expression.

In most cases, it is unnecessary to use the eval function explicitly in formulas. Instead, you can use the expression itself as the formula, e.g., "input/2".

Example Usage

eval(input/2)

returns 5 if the student input is 10.

expressionMatches

Same as algEquivalent(expression1, expression2, true); see algequiv, algEquivalent

isAlgValid

isAlgValid(expression)

  • Arguments:
    • expression - <String> An algebraic expression
  • Returns: <Boolean> - TRUE or FALSE
  • Description: Determine whether the argument is a valid algebraic expression.

Example Usage

isAlgValid(input) 

returns true if the student input is "3y+2x+4"; returns false if the student input is "3y*+2x+4".

⚠️ **GitHub.com Fallback** ⚠️