Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -30,15 +30,48 @@ request_history = deque(maxlen=1000)
|
|
30 |
SYMPY_GUIDELINES = """
|
31 |
When writing SymPy code to verify solutions:
|
32 |
|
33 |
-
1. Variable Declaration and
|
34 |
-
-
|
35 |
```python
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
38 |
```
|
39 |
-
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
2. Solving and Computing:
|
43 |
- Never use strings in solve() or other SymPy functions:
|
44 |
CORRECT: solve(eq, x)
|
|
|
30 |
SYMPY_GUIDELINES = """
|
31 |
When writing SymPy code to verify solutions:
|
32 |
|
33 |
+
1. Variable Declaration and Expressions:
|
34 |
+
- ALWAYS create symbolic expressions instead of literal numbers when working with mathematical operations:
|
35 |
```python
|
36 |
+
# CORRECT:
|
37 |
+
x = Symbol('x')
|
38 |
+
expr = x + 1 # Creates a symbolic expression
|
39 |
+
|
40 |
+
# INCORRECT:
|
41 |
+
expr = 1 # This is just a number, can't be differentiated
|
42 |
```
|
43 |
+
- For polynomials and functions:
|
44 |
+
```python
|
45 |
+
# CORRECT:
|
46 |
+
x = Symbol('x')
|
47 |
+
p = x**2 + 2*x + 1 # Creates a polynomial expression
|
48 |
+
|
49 |
+
# INCORRECT:
|
50 |
+
p = 1 # This won't work for operations like diff()
|
51 |
+
```
|
52 |
+
- When verifying operator actions:
|
53 |
+
```python
|
54 |
+
# CORRECT:
|
55 |
+
x = Symbol('x')
|
56 |
+
def verify_operator(p):
|
57 |
+
x = Symbol('x') # Always use Symbol inside functions too
|
58 |
+
return p.subs(x, 1) # Substitute values after creating expression
|
59 |
+
|
60 |
+
# INCORRECT:
|
61 |
+
def verify_operator(p):
|
62 |
+
return p # Passing raw numbers won't work
|
63 |
+
```
|
64 |
+
- For integration bounds:
|
65 |
+
```python
|
66 |
+
# CORRECT:
|
67 |
+
t = Symbol('t')
|
68 |
+
expr = t**2
|
69 |
+
result = integrate(expr, (t, 0, 1))
|
70 |
+
|
71 |
+
# INCORRECT:
|
72 |
+
result = integrate(2, (t, 0, 1)) # Can't integrate a number
|
73 |
+
```
|
74 |
+
|
75 |
2. Solving and Computing:
|
76 |
- Never use strings in solve() or other SymPy functions:
|
77 |
CORRECT: solve(eq, x)
|