Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -136,13 +136,11 @@ def enhance_prompt_with_proofs(system_prompt, subject, topic):
|
|
136 |
|
137 |
# Add specific instructions for using the examples
|
138 |
enhanced_prompt = f"""{system_prompt}
|
139 |
-
|
140 |
ADDITIONAL PROOF GUIDELINES:
|
141 |
1. Consider the following proof examples from established textbooks
|
142 |
2. Maintain similar level of rigor and detail
|
143 |
3. Use similar proof techniques where applicable
|
144 |
4. Follow similar notation and presentation style
|
145 |
-
|
146 |
{proof_examples}"""
|
147 |
|
148 |
return enhanced_prompt
|
@@ -264,7 +262,6 @@ The application question MUST:
|
|
264 |
2. Translate the practical problem into mathematical terms
|
265 |
3. Solve using appropriate mathematical techniques
|
266 |
4. Interpret the results in the context of the original problem
|
267 |
-
|
268 |
Example contexts might include:
|
269 |
- Physics applications (motion, forces, work)
|
270 |
- Engineering scenarios (optimization, rates of change)
|
@@ -280,7 +277,6 @@ The proof question MUST:
|
|
280 |
- Focus on demonstrating logical reasoning
|
281 |
- Require justification for each step
|
282 |
- Emphasize theoretical understanding
|
283 |
-
|
284 |
The proof question MAY NOT:
|
285 |
- Include Real-world applications or scenarios
|
286 |
- Include Pure computation problems
|
@@ -292,7 +288,6 @@ The computation question MUST:
|
|
292 |
- Focus on mathematical techniques
|
293 |
- Have concrete answers in the form of algebraic expressions (about half of questions) or numbers (about half of questions)
|
294 |
- Test procedural knowledge
|
295 |
-
|
296 |
The computation question MAY NOT:
|
297 |
- Include extended real-world applications or scenarios
|
298 |
- Ask for a proof
|
@@ -354,7 +349,6 @@ STRICT REQUIREMENTS:
|
|
354 |
{chr(10).join(f' - {c}' for c in difficulty_params['constraints'])}
|
355 |
|
356 |
{problem_type_addition}
|
357 |
-
|
358 |
3. Style Reference:
|
359 |
Question should be {difficulty_params['example_style']}
|
360 |
4. The question MUST:
|
@@ -400,7 +394,6 @@ STRICT REQUIREMENTS:
|
|
400 |
{chr(10).join(f' - {c}' for c in difficulty_params['constraints'])}
|
401 |
|
402 |
{problem_type_addition}
|
403 |
-
|
404 |
3. Style Reference:
|
405 |
Question should be {difficulty_params['example_style']}
|
406 |
4. For LaTeX formatting:
|
@@ -422,7 +415,8 @@ 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 |
- 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
|
@@ -518,37 +512,11 @@ def extract_and_run_sympy_code_simple(response_text):
|
|
518 |
import io
|
519 |
import sympy
|
520 |
from contextlib import redirect_stdout
|
521 |
-
from sympy import (Symbol, symbols, solve, limit, Abs, integrate,
|
522 |
-
Function, diff, sin, cos, exp, log, sqrt,
|
523 |
-
Matrix, Derivative, Integral, series)
|
524 |
-
|
525 |
-
# Create globals dict with all necessary imports
|
526 |
-
globals_dict = {
|
527 |
-
'sympy': sympy,
|
528 |
-
'Symbol': Symbol,
|
529 |
-
'symbols': symbols,
|
530 |
-
'solve': solve,
|
531 |
-
'limit': limit,
|
532 |
-
'Abs': Abs,
|
533 |
-
'integrate': integrate,
|
534 |
-
'Function': Function,
|
535 |
-
'diff': diff,
|
536 |
-
'sin': sin,
|
537 |
-
'cos': cos,
|
538 |
-
'exp': exp,
|
539 |
-
'log': log,
|
540 |
-
'sqrt': sqrt,
|
541 |
-
'Matrix': Matrix,
|
542 |
-
'Derivative': Derivative,
|
543 |
-
'Integral': Integral,
|
544 |
-
'series': series,
|
545 |
-
'print': print
|
546 |
-
}
|
547 |
|
548 |
# Capture output
|
549 |
output_buffer = io.StringIO()
|
550 |
with redirect_stdout(output_buffer):
|
551 |
-
exec(sympy_code,
|
552 |
|
553 |
return output_buffer.getvalue().strip() or "No output produced"
|
554 |
|
@@ -569,17 +537,13 @@ def check_and_resolve_discrepancy(initial_response, sympy_output):
|
|
569 |
then please say that they are consistent and briefly explain why.
|
570 |
|
571 |
If the two answers are inconsistent with each other then please:
|
572 |
-
|
573 |
1. Identify which solution is correct
|
574 |
2. Explain the error in the incorrect solution
|
575 |
3. Provide a revised complete solution that fixes any errors
|
576 |
-
|
577 |
Original solution:
|
578 |
{initial_response}
|
579 |
-
|
580 |
SymPy Verification Results:
|
581 |
{sympy_output}
|
582 |
-
|
583 |
Please maintain the same LaTeX formatting as the original solution."""
|
584 |
|
585 |
# Make API call for resolution
|
|
|
136 |
|
137 |
# Add specific instructions for using the examples
|
138 |
enhanced_prompt = f"""{system_prompt}
|
|
|
139 |
ADDITIONAL PROOF GUIDELINES:
|
140 |
1. Consider the following proof examples from established textbooks
|
141 |
2. Maintain similar level of rigor and detail
|
142 |
3. Use similar proof techniques where applicable
|
143 |
4. Follow similar notation and presentation style
|
|
|
144 |
{proof_examples}"""
|
145 |
|
146 |
return enhanced_prompt
|
|
|
262 |
2. Translate the practical problem into mathematical terms
|
263 |
3. Solve using appropriate mathematical techniques
|
264 |
4. Interpret the results in the context of the original problem
|
|
|
265 |
Example contexts might include:
|
266 |
- Physics applications (motion, forces, work)
|
267 |
- Engineering scenarios (optimization, rates of change)
|
|
|
277 |
- Focus on demonstrating logical reasoning
|
278 |
- Require justification for each step
|
279 |
- Emphasize theoretical understanding
|
|
|
280 |
The proof question MAY NOT:
|
281 |
- Include Real-world applications or scenarios
|
282 |
- Include Pure computation problems
|
|
|
288 |
- Focus on mathematical techniques
|
289 |
- Have concrete answers in the form of algebraic expressions (about half of questions) or numbers (about half of questions)
|
290 |
- Test procedural knowledge
|
|
|
291 |
The computation question MAY NOT:
|
292 |
- Include extended real-world applications or scenarios
|
293 |
- Ask for a proof
|
|
|
349 |
{chr(10).join(f' - {c}' for c in difficulty_params['constraints'])}
|
350 |
|
351 |
{problem_type_addition}
|
|
|
352 |
3. Style Reference:
|
353 |
Question should be {difficulty_params['example_style']}
|
354 |
4. The question MUST:
|
|
|
394 |
{chr(10).join(f' - {c}' for c in difficulty_params['constraints'])}
|
395 |
|
396 |
{problem_type_addition}
|
|
|
397 |
3. Style Reference:
|
398 |
Question should be {difficulty_params['example_style']}
|
399 |
4. For LaTeX formatting:
|
|
|
415 |
- Print variable values after they are computed
|
416 |
- Format numerical results using evalf() for decimal
|
417 |
9. When writing SymPy code to verify solutions:
|
418 |
+
- Start with essential imports: from sympy import *
|
419 |
+
- Or use specific imports as needed: from sympy import Symbol, solve, limit, Abs, integrate, Function, diff, sin, cos
|
420 |
- DO NOT use NumPy, SciPy, or other libraries
|
421 |
- For numerical integration, use integrate() instead of scipy.integrate.quad()
|
422 |
- For any numerical computations, use native SymPy functions
|
|
|
512 |
import io
|
513 |
import sympy
|
514 |
from contextlib import redirect_stdout
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
515 |
|
516 |
# Capture output
|
517 |
output_buffer = io.StringIO()
|
518 |
with redirect_stdout(output_buffer):
|
519 |
+
exec(sympy_code, {"sympy": sympy, "print": print})
|
520 |
|
521 |
return output_buffer.getvalue().strip() or "No output produced"
|
522 |
|
|
|
537 |
then please say that they are consistent and briefly explain why.
|
538 |
|
539 |
If the two answers are inconsistent with each other then please:
|
|
|
540 |
1. Identify which solution is correct
|
541 |
2. Explain the error in the incorrect solution
|
542 |
3. Provide a revised complete solution that fixes any errors
|
|
|
543 |
Original solution:
|
544 |
{initial_response}
|
|
|
545 |
SymPy Verification Results:
|
546 |
{sympy_output}
|
|
|
547 |
Please maintain the same LaTeX formatting as the original solution."""
|
548 |
|
549 |
# Make API call for resolution
|