Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -422,8 +422,7 @@ STRICT REQUIREMENTS:
|
|
422 |
- Print variable values after they are computed
|
423 |
- Format numerical results using evalf() for decimal
|
424 |
9. When writing SymPy code to verify solutions:
|
425 |
-
- Start with
|
426 |
-
- Or use specific imports as needed: from sympy import Symbol, solve, limit, Abs, integrate, Function, diff, sin, cos
|
427 |
- DO NOT use NumPy, SciPy, or other libraries
|
428 |
- For numerical integration, use integrate() instead of scipy.integrate.quad()
|
429 |
- For any numerical computations, use native SymPy functions
|
@@ -518,12 +517,37 @@ def extract_and_run_sympy_code_simple(response_text):
|
|
518 |
# Set up basic SymPy environment
|
519 |
import io
|
520 |
import sympy
|
521 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
522 |
|
523 |
# Capture output
|
524 |
output_buffer = io.StringIO()
|
525 |
with redirect_stdout(output_buffer):
|
526 |
-
exec(sympy_code,
|
527 |
|
528 |
return output_buffer.getvalue().strip() or "No output produced"
|
529 |
|
|
|
422 |
- Print variable values after they are computed
|
423 |
- Format numerical results using evalf() for decimal
|
424 |
9. When writing SymPy code to verify solutions:
|
425 |
+
- Start with "from sympy import" and include eall necessary imports
|
|
|
426 |
- DO NOT use NumPy, SciPy, or other libraries
|
427 |
- For numerical integration, use integrate() instead of scipy.integrate.quad()
|
428 |
- For any numerical computations, use native SymPy functions
|
|
|
517 |
# Set up basic SymPy environment
|
518 |
import io
|
519 |
import sympy
|
520 |
+
from sympy import (Symbol, symbols, solve, limit, Abs, integrate,
|
521 |
+
Function, diff, sin, cos, exp, log, sqrt,
|
522 |
+
Matrix, Derivative, Integral, series)
|
523 |
+
|
524 |
+
# Create globals dict with all necessary imports
|
525 |
+
globals_dict = {
|
526 |
+
'sympy': sympy,
|
527 |
+
'Symbol': Symbol,
|
528 |
+
'symbols': symbols,
|
529 |
+
'solve': solve,
|
530 |
+
'limit': limit,
|
531 |
+
'Abs': Abs,
|
532 |
+
'integrate': integrate,
|
533 |
+
'Function': Function,
|
534 |
+
'diff': diff,
|
535 |
+
'sin': sin,
|
536 |
+
'cos': cos,
|
537 |
+
'exp': exp,
|
538 |
+
'log': log,
|
539 |
+
'sqrt': sqrt,
|
540 |
+
'Matrix': Matrix,
|
541 |
+
'Derivative': Derivative,
|
542 |
+
'Integral': Integral,
|
543 |
+
'series': series,
|
544 |
+
'print': print
|
545 |
+
}
|
546 |
|
547 |
# Capture output
|
548 |
output_buffer = io.StringIO()
|
549 |
with redirect_stdout(output_buffer):
|
550 |
+
exec(sympy_code, globals_dict)
|
551 |
|
552 |
return output_buffer.getvalue().strip() or "No output produced"
|
553 |
|