Skip to content

Commit ff7ca73

Browse files
m-messerclaude
andauthored
Bug/fix inappropriate symbol and ! for factorial (#255)
* Updated to Python 3.12 * Handle infinity Unicode symbol and fix infinite value comparison Added ∞ as an alias for oo so students can use the Unicode infinity symbol as input. Fixed comparison of infinite expressions by using direct sympy comparison instead of subtraction, since oo - oo yields nan rather than 0. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Handled exceptions for is_infinite checks during symbolic expression comparison * Updated sympy to 1.13 * Updated sympy to 1.14 and mpath to 1.4.1 * Added parametric factorial and double factorial tests; implemented warning for unsupported triple factorial notation * Update CI to use Python 3.12 * Changed mpmath version * Switched Dockerfile base image to apt package manager for Git installation. * Switched to use dnf * Added find to installed requirements * Set PYTHONPATH in Dockerfile and updated CMD entrypoint format --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b6d8685 commit ff7ca73

3 files changed

Lines changed: 46 additions & 4 deletions

File tree

app/evaluation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ def evaluation_function(response, answer, params, include_test_data=False) -> di
294294
if "!" in response:
295295
evaluation_result.add_feedback(("NOTATION_WARNING_FACTORIAL", symbolic_comparison_internal_messages("NOTATION_WARNING_FACTORIAL")(dict())))
296296

297+
if "!!!" in response:
298+
evaluation_result.add_feedback(
299+
("NOTATION_WARNING_TRIPLE_FACTORIAL", symbolic_comparison_internal_messages("NOTATION_WARNING_TRIPLE_FACTORIAL")(dict())))
300+
297301
reserved_expressions_success, reserved_expressions = parse_reserved_expressions(reserved_expressions_strings, parameters, evaluation_result)
298302
if reserved_expressions_success is False:
299303
return evaluation_result.serialise(include_test_data)

app/feedback/symbolic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"PARSE_ERROR": f"`{inputs.get('x','')}` could not be parsed as a valid mathematical expression. Ensure that correct codes for input symbols are used, correct notation is used, that the expression is unambiguous and that all parentheses are closed.",
2222
"NOTATION_WARNING_EXPONENT": "Note that `^` cannot be used to denote exponentiation, use `**` instead.",
2323
"NOTATION_WARNING_FACTORIAL": "Note that `!` cannot be used to denote factorial, use `factorial(...)` instead.",
24+
"NOTATION_WARNING_TRIPLE_FACTORIAL": "Note that `!!!` is not supported.",
2425
"EXPRESSION_NOT_EQUALITY": "The response was an expression but was expected to be an equality.",
2526
"EQUALITY_NOT_EXPRESSION": "The response was an equality but was expected to be an expression.",
2627
"EQUALITIES_EQUIVALENT": None,

app/tests/symbolic_evaluation_test.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,15 +1883,52 @@ def test_sum_in_answer(self, response, answer, value):
18831883
result = evaluation_function(response, answer, params)
18841884
assert result["is_correct"] is value
18851885

1886-
def test_exclamation_mark_for_factorial(self):
1887-
response = "3!"
1888-
answer = "factorial(3)"
1886+
@pytest.mark.parametrize(
1887+
"response, answer, value",
1888+
[
1889+
("3!", "factorial(3)", True),
1890+
("(n+1)!", "factorial(n+1)", True),
1891+
("n!", "factorial(n)", True),
1892+
("a!=b", "factorial(3)", False),
1893+
("2*n!", "2*factorial(n)", True),
1894+
("3!", "3!", True),
1895+
("3*sin(n)!", "3*factorial(sin(n))", True)
1896+
]
1897+
)
1898+
def test_exclamation_mark_for_factorial(self, response, answer, value):
18891899
params = {
18901900
"strict_syntax": False,
18911901
"elementary_functions": True,
18921902
}
18931903
result = evaluation_function(response, answer, params)
1894-
assert result["is_correct"] is True
1904+
assert result["is_correct"] is value
1905+
1906+
@pytest.mark.parametrize(
1907+
"response, answer, value",
1908+
[
1909+
("3!!", "factorial2(3)", True),
1910+
("(n+1)!!", "factorial2(n+1)", True),
1911+
("n!!", "factorial2(n)", True),
1912+
("a!=b", "factorial2(3)", False),
1913+
("2*n!!", "2*factorial2(n)", True),
1914+
("3!!", "3!!", True),
1915+
]
1916+
)
1917+
def test_double_exclamation_mark_for_factorial(self, response, answer, value):
1918+
params = {
1919+
"strict_syntax": False,
1920+
"elementary_functions": True,
1921+
}
1922+
result = evaluation_function(response, answer, params)
1923+
assert result["is_correct"] is value
1924+
1925+
def test_warning_for_triple_factorial(self):
1926+
answer = '2^4!'
1927+
response = '2^4!!!'
1928+
params = {'strict_syntax': False}
1929+
result = evaluation_function(response, answer, params, include_test_data=True)
1930+
assert result["is_correct"] is False
1931+
assert "NOTATION_WARNING_TRIPLE_FACTORIAL" in result["tags"]
18951932

18961933
def test_alternatives_to_input_symbols_takes_priority_over_elementary_function_alternatives(self):
18971934
answer = "Ef*exp(x)"

0 commit comments

Comments
 (0)