@bgicli/bgicli 2.2.8 → 2.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/skills/anthropic-algorithmic-art/SKILL.md +405 -0
- package/data/skills/anthropic-canvas-design/SKILL.md +130 -0
- package/data/skills/anthropic-claude-api/SKILL.md +243 -0
- package/data/skills/anthropic-doc-coauthoring/SKILL.md +375 -0
- package/data/skills/anthropic-docx/SKILL.md +590 -0
- package/data/skills/anthropic-frontend-design/SKILL.md +42 -0
- package/data/skills/anthropic-internal-comms/SKILL.md +32 -0
- package/data/skills/anthropic-mcp-builder/SKILL.md +236 -0
- package/data/skills/anthropic-pdf/SKILL.md +314 -0
- package/data/skills/anthropic-pptx/SKILL.md +232 -0
- package/data/skills/anthropic-skill-creator/SKILL.md +485 -0
- package/data/skills/anthropic-webapp-testing/SKILL.md +96 -0
- package/data/skills/anthropic-xlsx/SKILL.md +292 -0
- package/data/skills/arxiv-database/SKILL.md +362 -0
- package/data/skills/astropy/SKILL.md +329 -0
- package/data/skills/ctx-advanced-evaluation/SKILL.md +402 -0
- package/data/skills/ctx-bdi-mental-states/SKILL.md +311 -0
- package/data/skills/ctx-context-compression/SKILL.md +272 -0
- package/data/skills/ctx-context-degradation/SKILL.md +206 -0
- package/data/skills/ctx-context-fundamentals/SKILL.md +201 -0
- package/data/skills/ctx-context-optimization/SKILL.md +195 -0
- package/data/skills/ctx-evaluation/SKILL.md +251 -0
- package/data/skills/ctx-filesystem-context/SKILL.md +287 -0
- package/data/skills/ctx-hosted-agents/SKILL.md +260 -0
- package/data/skills/ctx-memory-systems/SKILL.md +225 -0
- package/data/skills/ctx-multi-agent-patterns/SKILL.md +257 -0
- package/data/skills/ctx-project-development/SKILL.md +291 -0
- package/data/skills/ctx-tool-design/SKILL.md +271 -0
- package/data/skills/dhdna-profiler/SKILL.md +162 -0
- package/data/skills/generate-image/SKILL.md +183 -0
- package/data/skills/geomaster/SKILL.md +365 -0
- package/data/skills/get-available-resources/SKILL.md +275 -0
- package/data/skills/hamelsmu-build-review-interface/SKILL.md +96 -0
- package/data/skills/hamelsmu-error-analysis/SKILL.md +164 -0
- package/data/skills/hamelsmu-eval-audit/SKILL.md +183 -0
- package/data/skills/hamelsmu-evaluate-rag/SKILL.md +177 -0
- package/data/skills/hamelsmu-generate-synthetic-data/SKILL.md +131 -0
- package/data/skills/hamelsmu-validate-evaluator/SKILL.md +212 -0
- package/data/skills/hamelsmu-write-judge-prompt/SKILL.md +144 -0
- package/data/skills/hf-cli/SKILL.md +174 -0
- package/data/skills/hf-mcp/SKILL.md +178 -0
- package/data/skills/hugging-face-dataset-viewer/SKILL.md +121 -0
- package/data/skills/hugging-face-datasets/SKILL.md +542 -0
- package/data/skills/hugging-face-evaluation/SKILL.md +651 -0
- package/data/skills/hugging-face-jobs/SKILL.md +1042 -0
- package/data/skills/hugging-face-model-trainer/SKILL.md +717 -0
- package/data/skills/hugging-face-paper-pages/SKILL.md +239 -0
- package/data/skills/hugging-face-paper-publisher/SKILL.md +624 -0
- package/data/skills/hugging-face-tool-builder/SKILL.md +110 -0
- package/data/skills/hugging-face-trackio/SKILL.md +115 -0
- package/data/skills/hugging-face-vision-trainer/SKILL.md +593 -0
- package/data/skills/huggingface-gradio/SKILL.md +245 -0
- package/data/skills/matlab/SKILL.md +376 -0
- package/data/skills/modal/SKILL.md +381 -0
- package/data/skills/openai-cloudflare-deploy/SKILL.md +224 -0
- package/data/skills/openai-develop-web-game/SKILL.md +149 -0
- package/data/skills/openai-doc/SKILL.md +80 -0
- package/data/skills/openai-figma/SKILL.md +42 -0
- package/data/skills/openai-figma-implement-design/SKILL.md +264 -0
- package/data/skills/openai-gh-address-comments/SKILL.md +25 -0
- package/data/skills/openai-gh-fix-ci/SKILL.md +69 -0
- package/data/skills/openai-imagegen/SKILL.md +174 -0
- package/data/skills/openai-jupyter-notebook/SKILL.md +107 -0
- package/data/skills/openai-linear/SKILL.md +87 -0
- package/data/skills/openai-netlify-deploy/SKILL.md +247 -0
- package/data/skills/openai-notion-knowledge-capture/SKILL.md +56 -0
- package/data/skills/openai-notion-meeting-intelligence/SKILL.md +60 -0
- package/data/skills/openai-notion-research-documentation/SKILL.md +59 -0
- package/data/skills/openai-notion-spec-to-implementation/SKILL.md +58 -0
- package/data/skills/openai-openai-docs/SKILL.md +69 -0
- package/data/skills/openai-pdf/SKILL.md +67 -0
- package/data/skills/openai-playwright/SKILL.md +147 -0
- package/data/skills/openai-render-deploy/SKILL.md +479 -0
- package/data/skills/openai-screenshot/SKILL.md +267 -0
- package/data/skills/openai-security-best-practices/SKILL.md +86 -0
- package/data/skills/openai-security-ownership-map/SKILL.md +206 -0
- package/data/skills/openai-security-threat-model/SKILL.md +81 -0
- package/data/skills/openai-sentry/SKILL.md +123 -0
- package/data/skills/openai-sora/SKILL.md +178 -0
- package/data/skills/openai-speech/SKILL.md +144 -0
- package/data/skills/openai-spreadsheet/SKILL.md +145 -0
- package/data/skills/openai-transcribe/SKILL.md +81 -0
- package/data/skills/openai-vercel-deploy/SKILL.md +77 -0
- package/data/skills/openai-yeet/SKILL.md +28 -0
- package/data/skills/pennylane/SKILL.md +224 -0
- package/data/skills/polars-bio/SKILL.md +374 -0
- package/data/skills/primekg/SKILL.md +97 -0
- package/data/skills/pymatgen/SKILL.md +689 -0
- package/data/skills/qiskit/SKILL.md +273 -0
- package/data/skills/qutip/SKILL.md +316 -0
- package/data/skills/recursive-decomposition/SKILL.md +185 -0
- package/data/skills/rowan/SKILL.md +427 -0
- package/data/skills/scholar-evaluation/SKILL.md +298 -0
- package/data/skills/sentry-create-alert/SKILL.md +210 -0
- package/data/skills/sentry-fix-issues/SKILL.md +126 -0
- package/data/skills/sentry-pr-code-review/SKILL.md +105 -0
- package/data/skills/sentry-python-sdk/SKILL.md +317 -0
- package/data/skills/sentry-setup-ai-monitoring/SKILL.md +217 -0
- package/data/skills/stable-baselines3/SKILL.md +297 -0
- package/data/skills/sympy/SKILL.md +498 -0
- package/data/skills/trailofbits-ask-questions-if-underspecified/SKILL.md +85 -0
- package/data/skills/trailofbits-audit-context-building/SKILL.md +302 -0
- package/data/skills/trailofbits-differential-review/SKILL.md +220 -0
- package/data/skills/trailofbits-insecure-defaults/SKILL.md +117 -0
- package/data/skills/trailofbits-modern-python/SKILL.md +333 -0
- package/data/skills/trailofbits-property-based-testing/SKILL.md +123 -0
- package/data/skills/trailofbits-semgrep-rule-creator/SKILL.md +172 -0
- package/data/skills/trailofbits-sharp-edges/SKILL.md +292 -0
- package/data/skills/trailofbits-variant-analysis/SKILL.md +142 -0
- package/data/skills/transformers.js/SKILL.md +637 -0
- package/data/skills/writing/SKILL.md +419 -0
- package/dist/bgi.js +66 -2
- package/package.json +1 -1
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sympy
|
|
3
|
+
description: Use this skill when working with symbolic mathematics in Python. This skill should be used for symbolic computation tasks including solving equations algebraically, performing calculus operations (derivatives, integrals, limits), manipulating algebraic expressions, working with matrices symbolically, physics calculations, number theory problems, geometry computations, and generating executable code from mathematical expressions. Apply this skill when the user needs exact symbolic results rather than numerical approximations, or when working with mathematical formulas that contain variables and parameters.
|
|
4
|
+
license: https://github.com/sympy/sympy/blob/master/LICENSE
|
|
5
|
+
metadata:
|
|
6
|
+
skill-author: K-Dense Inc.
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# SymPy - Symbolic Mathematics in Python
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
SymPy is a Python library for symbolic mathematics that enables exact computation using mathematical symbols rather than numerical approximations. This skill provides comprehensive guidance for performing symbolic algebra, calculus, linear algebra, equation solving, physics calculations, and code generation using SymPy.
|
|
14
|
+
|
|
15
|
+
## When to Use This Skill
|
|
16
|
+
|
|
17
|
+
Use this skill when:
|
|
18
|
+
- Solving equations symbolically (algebraic, differential, systems of equations)
|
|
19
|
+
- Performing calculus operations (derivatives, integrals, limits, series)
|
|
20
|
+
- Manipulating and simplifying algebraic expressions
|
|
21
|
+
- Working with matrices and linear algebra symbolically
|
|
22
|
+
- Doing physics calculations (mechanics, quantum mechanics, vector analysis)
|
|
23
|
+
- Number theory computations (primes, factorization, modular arithmetic)
|
|
24
|
+
- Geometric calculations (2D/3D geometry, analytic geometry)
|
|
25
|
+
- Converting mathematical expressions to executable code (Python, C, Fortran)
|
|
26
|
+
- Generating LaTeX or other formatted mathematical output
|
|
27
|
+
- Needing exact mathematical results (e.g., `sqrt(2)` not `1.414...`)
|
|
28
|
+
|
|
29
|
+
## Core Capabilities
|
|
30
|
+
|
|
31
|
+
### 1. Symbolic Computation Basics
|
|
32
|
+
|
|
33
|
+
**Creating symbols and expressions:**
|
|
34
|
+
```python
|
|
35
|
+
from sympy import symbols, Symbol
|
|
36
|
+
x, y, z = symbols('x y z')
|
|
37
|
+
expr = x**2 + 2*x + 1
|
|
38
|
+
|
|
39
|
+
# With assumptions
|
|
40
|
+
x = symbols('x', real=True, positive=True)
|
|
41
|
+
n = symbols('n', integer=True)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Simplification and manipulation:**
|
|
45
|
+
```python
|
|
46
|
+
from sympy import simplify, expand, factor, cancel
|
|
47
|
+
simplify(sin(x)**2 + cos(x)**2) # Returns 1
|
|
48
|
+
expand((x + 1)**3) # x**3 + 3*x**2 + 3*x + 1
|
|
49
|
+
factor(x**2 - 1) # (x - 1)*(x + 1)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**For detailed basics:** See `references/core-capabilities.md`
|
|
53
|
+
|
|
54
|
+
### 2. Calculus
|
|
55
|
+
|
|
56
|
+
**Derivatives:**
|
|
57
|
+
```python
|
|
58
|
+
from sympy import diff
|
|
59
|
+
diff(x**2, x) # 2*x
|
|
60
|
+
diff(x**4, x, 3) # 24*x (third derivative)
|
|
61
|
+
diff(x**2*y**3, x, y) # 6*x*y**2 (partial derivatives)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Integrals:**
|
|
65
|
+
```python
|
|
66
|
+
from sympy import integrate, oo
|
|
67
|
+
integrate(x**2, x) # x**3/3 (indefinite)
|
|
68
|
+
integrate(x**2, (x, 0, 1)) # 1/3 (definite)
|
|
69
|
+
integrate(exp(-x), (x, 0, oo)) # 1 (improper)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Limits and Series:**
|
|
73
|
+
```python
|
|
74
|
+
from sympy import limit, series
|
|
75
|
+
limit(sin(x)/x, x, 0) # 1
|
|
76
|
+
series(exp(x), x, 0, 6) # 1 + x + x**2/2 + x**3/6 + x**4/24 + x**5/120 + O(x**6)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**For detailed calculus operations:** See `references/core-capabilities.md`
|
|
80
|
+
|
|
81
|
+
### 3. Equation Solving
|
|
82
|
+
|
|
83
|
+
**Algebraic equations:**
|
|
84
|
+
```python
|
|
85
|
+
from sympy import solveset, solve, Eq
|
|
86
|
+
solveset(x**2 - 4, x) # {-2, 2}
|
|
87
|
+
solve(Eq(x**2, 4), x) # [-2, 2]
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Systems of equations:**
|
|
91
|
+
```python
|
|
92
|
+
from sympy import linsolve, nonlinsolve
|
|
93
|
+
linsolve([x + y - 2, x - y], x, y) # {(1, 1)} (linear)
|
|
94
|
+
nonlinsolve([x**2 + y - 2, x + y**2 - 3], x, y) # (nonlinear)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Differential equations:**
|
|
98
|
+
```python
|
|
99
|
+
from sympy import Function, dsolve, Derivative
|
|
100
|
+
f = symbols('f', cls=Function)
|
|
101
|
+
dsolve(Derivative(f(x), x) - f(x), f(x)) # Eq(f(x), C1*exp(x))
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**For detailed solving methods:** See `references/core-capabilities.md`
|
|
105
|
+
|
|
106
|
+
### 4. Matrices and Linear Algebra
|
|
107
|
+
|
|
108
|
+
**Matrix creation and operations:**
|
|
109
|
+
```python
|
|
110
|
+
from sympy import Matrix, eye, zeros
|
|
111
|
+
M = Matrix([[1, 2], [3, 4]])
|
|
112
|
+
M_inv = M**-1 # Inverse
|
|
113
|
+
M.det() # Determinant
|
|
114
|
+
M.T # Transpose
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Eigenvalues and eigenvectors:**
|
|
118
|
+
```python
|
|
119
|
+
eigenvals = M.eigenvals() # {eigenvalue: multiplicity}
|
|
120
|
+
eigenvects = M.eigenvects() # [(eigenval, mult, [eigenvectors])]
|
|
121
|
+
P, D = M.diagonalize() # M = P*D*P^-1
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Solving linear systems:**
|
|
125
|
+
```python
|
|
126
|
+
A = Matrix([[1, 2], [3, 4]])
|
|
127
|
+
b = Matrix([5, 6])
|
|
128
|
+
x = A.solve(b) # Solve Ax = b
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**For comprehensive linear algebra:** See `references/matrices-linear-algebra.md`
|
|
132
|
+
|
|
133
|
+
### 5. Physics and Mechanics
|
|
134
|
+
|
|
135
|
+
**Classical mechanics:**
|
|
136
|
+
```python
|
|
137
|
+
from sympy.physics.mechanics import dynamicsymbols, LagrangesMethod
|
|
138
|
+
from sympy import symbols
|
|
139
|
+
|
|
140
|
+
# Define system
|
|
141
|
+
q = dynamicsymbols('q')
|
|
142
|
+
m, g, l = symbols('m g l')
|
|
143
|
+
|
|
144
|
+
# Lagrangian (T - V)
|
|
145
|
+
L = m*(l*q.diff())**2/2 - m*g*l*(1 - cos(q))
|
|
146
|
+
|
|
147
|
+
# Apply Lagrange's method
|
|
148
|
+
LM = LagrangesMethod(L, [q])
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Vector analysis:**
|
|
152
|
+
```python
|
|
153
|
+
from sympy.physics.vector import ReferenceFrame, dot, cross
|
|
154
|
+
N = ReferenceFrame('N')
|
|
155
|
+
v1 = 3*N.x + 4*N.y
|
|
156
|
+
v2 = 1*N.x + 2*N.z
|
|
157
|
+
dot(v1, v2) # Dot product
|
|
158
|
+
cross(v1, v2) # Cross product
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Quantum mechanics:**
|
|
162
|
+
```python
|
|
163
|
+
from sympy.physics.quantum import Ket, Bra, Commutator
|
|
164
|
+
psi = Ket('psi')
|
|
165
|
+
A = Operator('A')
|
|
166
|
+
comm = Commutator(A, B).doit()
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**For detailed physics capabilities:** See `references/physics-mechanics.md`
|
|
170
|
+
|
|
171
|
+
### 6. Advanced Mathematics
|
|
172
|
+
|
|
173
|
+
The skill includes comprehensive support for:
|
|
174
|
+
|
|
175
|
+
- **Geometry:** 2D/3D analytic geometry, points, lines, circles, polygons, transformations
|
|
176
|
+
- **Number Theory:** Primes, factorization, GCD/LCM, modular arithmetic, Diophantine equations
|
|
177
|
+
- **Combinatorics:** Permutations, combinations, partitions, group theory
|
|
178
|
+
- **Logic and Sets:** Boolean logic, set theory, finite and infinite sets
|
|
179
|
+
- **Statistics:** Probability distributions, random variables, expectation, variance
|
|
180
|
+
- **Special Functions:** Gamma, Bessel, orthogonal polynomials, hypergeometric functions
|
|
181
|
+
- **Polynomials:** Polynomial algebra, roots, factorization, Groebner bases
|
|
182
|
+
|
|
183
|
+
**For detailed advanced topics:** See `references/advanced-topics.md`
|
|
184
|
+
|
|
185
|
+
### 7. Code Generation and Output
|
|
186
|
+
|
|
187
|
+
**Convert to executable functions:**
|
|
188
|
+
```python
|
|
189
|
+
from sympy import lambdify
|
|
190
|
+
import numpy as np
|
|
191
|
+
|
|
192
|
+
expr = x**2 + 2*x + 1
|
|
193
|
+
f = lambdify(x, expr, 'numpy') # Create NumPy function
|
|
194
|
+
x_vals = np.linspace(0, 10, 100)
|
|
195
|
+
y_vals = f(x_vals) # Fast numerical evaluation
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Generate C/Fortran code:**
|
|
199
|
+
```python
|
|
200
|
+
from sympy.utilities.codegen import codegen
|
|
201
|
+
[(c_name, c_code), (h_name, h_header)] = codegen(
|
|
202
|
+
('my_func', expr), 'C'
|
|
203
|
+
)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**LaTeX output:**
|
|
207
|
+
```python
|
|
208
|
+
from sympy import latex
|
|
209
|
+
latex_str = latex(expr) # Convert to LaTeX for documents
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**For comprehensive code generation:** See `references/code-generation-printing.md`
|
|
213
|
+
|
|
214
|
+
## Working with SymPy: Best Practices
|
|
215
|
+
|
|
216
|
+
### 1. Always Define Symbols First
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
from sympy import symbols
|
|
220
|
+
x, y, z = symbols('x y z')
|
|
221
|
+
# Now x, y, z can be used in expressions
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### 2. Use Assumptions for Better Simplification
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
x = symbols('x', positive=True, real=True)
|
|
228
|
+
sqrt(x**2) # Returns x (not Abs(x)) due to positive assumption
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Common assumptions: `real`, `positive`, `negative`, `integer`, `rational`, `complex`, `even`, `odd`
|
|
232
|
+
|
|
233
|
+
### 3. Use Exact Arithmetic
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
from sympy import Rational, S
|
|
237
|
+
# Correct (exact):
|
|
238
|
+
expr = Rational(1, 2) * x
|
|
239
|
+
expr = S(1)/2 * x
|
|
240
|
+
|
|
241
|
+
# Incorrect (floating-point):
|
|
242
|
+
expr = 0.5 * x # Creates approximate value
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### 4. Numerical Evaluation When Needed
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
from sympy import pi, sqrt
|
|
249
|
+
result = sqrt(8) + pi
|
|
250
|
+
result.evalf() # 5.96371554103586
|
|
251
|
+
result.evalf(50) # 50 digits of precision
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### 5. Convert to NumPy for Performance
|
|
255
|
+
|
|
256
|
+
```python
|
|
257
|
+
# Slow for many evaluations:
|
|
258
|
+
for x_val in range(1000):
|
|
259
|
+
result = expr.subs(x, x_val).evalf()
|
|
260
|
+
|
|
261
|
+
# Fast:
|
|
262
|
+
f = lambdify(x, expr, 'numpy')
|
|
263
|
+
results = f(np.arange(1000))
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### 6. Use Appropriate Solvers
|
|
267
|
+
|
|
268
|
+
- `solveset`: Algebraic equations (primary)
|
|
269
|
+
- `linsolve`: Linear systems
|
|
270
|
+
- `nonlinsolve`: Nonlinear systems
|
|
271
|
+
- `dsolve`: Differential equations
|
|
272
|
+
- `solve`: General purpose (legacy, but flexible)
|
|
273
|
+
|
|
274
|
+
## Reference Files Structure
|
|
275
|
+
|
|
276
|
+
This skill uses modular reference files for different capabilities:
|
|
277
|
+
|
|
278
|
+
1. **`core-capabilities.md`**: Symbols, algebra, calculus, simplification, equation solving
|
|
279
|
+
- Load when: Basic symbolic computation, calculus, or solving equations
|
|
280
|
+
|
|
281
|
+
2. **`matrices-linear-algebra.md`**: Matrix operations, eigenvalues, linear systems
|
|
282
|
+
- Load when: Working with matrices or linear algebra problems
|
|
283
|
+
|
|
284
|
+
3. **`physics-mechanics.md`**: Classical mechanics, quantum mechanics, vectors, units
|
|
285
|
+
- Load when: Physics calculations or mechanics problems
|
|
286
|
+
|
|
287
|
+
4. **`advanced-topics.md`**: Geometry, number theory, combinatorics, logic, statistics
|
|
288
|
+
- Load when: Advanced mathematical topics beyond basic algebra and calculus
|
|
289
|
+
|
|
290
|
+
5. **`code-generation-printing.md`**: Lambdify, codegen, LaTeX output, printing
|
|
291
|
+
- Load when: Converting expressions to code or generating formatted output
|
|
292
|
+
|
|
293
|
+
## Common Use Case Patterns
|
|
294
|
+
|
|
295
|
+
### Pattern 1: Solve and Verify
|
|
296
|
+
|
|
297
|
+
```python
|
|
298
|
+
from sympy import symbols, solve, simplify
|
|
299
|
+
x = symbols('x')
|
|
300
|
+
|
|
301
|
+
# Solve equation
|
|
302
|
+
equation = x**2 - 5*x + 6
|
|
303
|
+
solutions = solve(equation, x) # [2, 3]
|
|
304
|
+
|
|
305
|
+
# Verify solutions
|
|
306
|
+
for sol in solutions:
|
|
307
|
+
result = simplify(equation.subs(x, sol))
|
|
308
|
+
assert result == 0
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Pattern 2: Symbolic to Numeric Pipeline
|
|
312
|
+
|
|
313
|
+
```python
|
|
314
|
+
# 1. Define symbolic problem
|
|
315
|
+
x, y = symbols('x y')
|
|
316
|
+
expr = sin(x) + cos(y)
|
|
317
|
+
|
|
318
|
+
# 2. Manipulate symbolically
|
|
319
|
+
simplified = simplify(expr)
|
|
320
|
+
derivative = diff(simplified, x)
|
|
321
|
+
|
|
322
|
+
# 3. Convert to numerical function
|
|
323
|
+
f = lambdify((x, y), derivative, 'numpy')
|
|
324
|
+
|
|
325
|
+
# 4. Evaluate numerically
|
|
326
|
+
results = f(x_data, y_data)
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### Pattern 3: Document Mathematical Results
|
|
330
|
+
|
|
331
|
+
```python
|
|
332
|
+
# Compute result symbolically
|
|
333
|
+
integral_expr = Integral(x**2, (x, 0, 1))
|
|
334
|
+
result = integral_expr.doit()
|
|
335
|
+
|
|
336
|
+
# Generate documentation
|
|
337
|
+
print(f"LaTeX: {latex(integral_expr)} = {latex(result)}")
|
|
338
|
+
print(f"Pretty: {pretty(integral_expr)} = {pretty(result)}")
|
|
339
|
+
print(f"Numerical: {result.evalf()}")
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## Integration with Scientific Workflows
|
|
343
|
+
|
|
344
|
+
### With NumPy
|
|
345
|
+
|
|
346
|
+
```python
|
|
347
|
+
import numpy as np
|
|
348
|
+
from sympy import symbols, lambdify
|
|
349
|
+
|
|
350
|
+
x = symbols('x')
|
|
351
|
+
expr = x**2 + 2*x + 1
|
|
352
|
+
|
|
353
|
+
f = lambdify(x, expr, 'numpy')
|
|
354
|
+
x_array = np.linspace(-5, 5, 100)
|
|
355
|
+
y_array = f(x_array)
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### With Matplotlib
|
|
359
|
+
|
|
360
|
+
```python
|
|
361
|
+
import matplotlib.pyplot as plt
|
|
362
|
+
import numpy as np
|
|
363
|
+
from sympy import symbols, lambdify, sin
|
|
364
|
+
|
|
365
|
+
x = symbols('x')
|
|
366
|
+
expr = sin(x) / x
|
|
367
|
+
|
|
368
|
+
f = lambdify(x, expr, 'numpy')
|
|
369
|
+
x_vals = np.linspace(-10, 10, 1000)
|
|
370
|
+
y_vals = f(x_vals)
|
|
371
|
+
|
|
372
|
+
plt.plot(x_vals, y_vals)
|
|
373
|
+
plt.show()
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### With SciPy
|
|
377
|
+
|
|
378
|
+
```python
|
|
379
|
+
from scipy.optimize import fsolve
|
|
380
|
+
from sympy import symbols, lambdify
|
|
381
|
+
|
|
382
|
+
# Define equation symbolically
|
|
383
|
+
x = symbols('x')
|
|
384
|
+
equation = x**3 - 2*x - 5
|
|
385
|
+
|
|
386
|
+
# Convert to numerical function
|
|
387
|
+
f = lambdify(x, equation, 'numpy')
|
|
388
|
+
|
|
389
|
+
# Solve numerically with initial guess
|
|
390
|
+
solution = fsolve(f, 2)
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
## Quick Reference: Most Common Functions
|
|
394
|
+
|
|
395
|
+
```python
|
|
396
|
+
# Symbols
|
|
397
|
+
from sympy import symbols, Symbol
|
|
398
|
+
x, y = symbols('x y')
|
|
399
|
+
|
|
400
|
+
# Basic operations
|
|
401
|
+
from sympy import simplify, expand, factor, collect, cancel
|
|
402
|
+
from sympy import sqrt, exp, log, sin, cos, tan, pi, E, I, oo
|
|
403
|
+
|
|
404
|
+
# Calculus
|
|
405
|
+
from sympy import diff, integrate, limit, series, Derivative, Integral
|
|
406
|
+
|
|
407
|
+
# Solving
|
|
408
|
+
from sympy import solve, solveset, linsolve, nonlinsolve, dsolve
|
|
409
|
+
|
|
410
|
+
# Matrices
|
|
411
|
+
from sympy import Matrix, eye, zeros, ones, diag
|
|
412
|
+
|
|
413
|
+
# Logic and sets
|
|
414
|
+
from sympy import And, Or, Not, Implies, FiniteSet, Interval, Union
|
|
415
|
+
|
|
416
|
+
# Output
|
|
417
|
+
from sympy import latex, pprint, lambdify, init_printing
|
|
418
|
+
|
|
419
|
+
# Utilities
|
|
420
|
+
from sympy import evalf, N, nsimplify
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
## Getting Started Examples
|
|
424
|
+
|
|
425
|
+
### Example 1: Solve Quadratic Equation
|
|
426
|
+
```python
|
|
427
|
+
from sympy import symbols, solve, sqrt
|
|
428
|
+
x = symbols('x')
|
|
429
|
+
solution = solve(x**2 - 5*x + 6, x)
|
|
430
|
+
# [2, 3]
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
### Example 2: Calculate Derivative
|
|
434
|
+
```python
|
|
435
|
+
from sympy import symbols, diff, sin
|
|
436
|
+
x = symbols('x')
|
|
437
|
+
f = sin(x**2)
|
|
438
|
+
df_dx = diff(f, x)
|
|
439
|
+
# 2*x*cos(x**2)
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
### Example 3: Evaluate Integral
|
|
443
|
+
```python
|
|
444
|
+
from sympy import symbols, integrate, exp
|
|
445
|
+
x = symbols('x')
|
|
446
|
+
integral = integrate(x * exp(-x**2), (x, 0, oo))
|
|
447
|
+
# 1/2
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
### Example 4: Matrix Eigenvalues
|
|
451
|
+
```python
|
|
452
|
+
from sympy import Matrix
|
|
453
|
+
M = Matrix([[1, 2], [2, 1]])
|
|
454
|
+
eigenvals = M.eigenvals()
|
|
455
|
+
# {3: 1, -1: 1}
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
### Example 5: Generate Python Function
|
|
459
|
+
```python
|
|
460
|
+
from sympy import symbols, lambdify
|
|
461
|
+
import numpy as np
|
|
462
|
+
x = symbols('x')
|
|
463
|
+
expr = x**2 + 2*x + 1
|
|
464
|
+
f = lambdify(x, expr, 'numpy')
|
|
465
|
+
f(np.array([1, 2, 3]))
|
|
466
|
+
# array([ 4, 9, 16])
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
## Troubleshooting Common Issues
|
|
470
|
+
|
|
471
|
+
1. **"NameError: name 'x' is not defined"**
|
|
472
|
+
- Solution: Always define symbols using `symbols()` before use
|
|
473
|
+
|
|
474
|
+
2. **Unexpected numerical results**
|
|
475
|
+
- Issue: Using floating-point numbers like `0.5` instead of `Rational(1, 2)`
|
|
476
|
+
- Solution: Use `Rational()` or `S()` for exact arithmetic
|
|
477
|
+
|
|
478
|
+
3. **Slow performance in loops**
|
|
479
|
+
- Issue: Using `subs()` and `evalf()` repeatedly
|
|
480
|
+
- Solution: Use `lambdify()` to create a fast numerical function
|
|
481
|
+
|
|
482
|
+
4. **"Can't solve this equation"**
|
|
483
|
+
- Try different solvers: `solve`, `solveset`, `nsolve` (numerical)
|
|
484
|
+
- Check if the equation is solvable algebraically
|
|
485
|
+
- Use numerical methods if no closed-form solution exists
|
|
486
|
+
|
|
487
|
+
5. **Simplification not working as expected**
|
|
488
|
+
- Try different simplification functions: `simplify`, `factor`, `expand`, `trigsimp`
|
|
489
|
+
- Add assumptions to symbols (e.g., `positive=True`)
|
|
490
|
+
- Use `simplify(expr, force=True)` for aggressive simplification
|
|
491
|
+
|
|
492
|
+
## Additional Resources
|
|
493
|
+
|
|
494
|
+
- Official Documentation: https://docs.sympy.org/
|
|
495
|
+
- Tutorial: https://docs.sympy.org/latest/tutorials/intro-tutorial/index.html
|
|
496
|
+
- API Reference: https://docs.sympy.org/latest/reference/index.html
|
|
497
|
+
- Examples: https://github.com/sympy/sympy/tree/master/examples
|
|
498
|
+
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ask-questions-if-underspecified
|
|
3
|
+
description: Clarify requirements before implementing. Use when serious doubts arise.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Ask Questions If Underspecified
|
|
7
|
+
|
|
8
|
+
## When to Use
|
|
9
|
+
|
|
10
|
+
Use this skill when a request has multiple plausible interpretations or key details (objective, scope, constraints, environment, or safety) are unclear.
|
|
11
|
+
|
|
12
|
+
## When NOT to Use
|
|
13
|
+
|
|
14
|
+
Do not use this skill when the request is already clear, or when a quick, low-risk discovery read can answer the missing details.
|
|
15
|
+
|
|
16
|
+
## Goal
|
|
17
|
+
|
|
18
|
+
Ask the minimum set of clarifying questions needed to avoid wrong work; do not start implementing until the must-have questions are answered (or the user explicitly approves proceeding with stated assumptions).
|
|
19
|
+
|
|
20
|
+
## Workflow
|
|
21
|
+
|
|
22
|
+
### 1) Decide whether the request is underspecified
|
|
23
|
+
|
|
24
|
+
Treat a request as underspecified if after exploring how to perform the work, some or all of the following are not clear:
|
|
25
|
+
- Define the objective (what should change vs stay the same)
|
|
26
|
+
- Define "done" (acceptance criteria, examples, edge cases)
|
|
27
|
+
- Define scope (which files/components/users are in/out)
|
|
28
|
+
- Define constraints (compatibility, performance, style, deps, time)
|
|
29
|
+
- Identify environment (language/runtime versions, OS, build/test runner)
|
|
30
|
+
- Clarify safety/reversibility (data migration, rollout/rollback, risk)
|
|
31
|
+
|
|
32
|
+
If multiple plausible interpretations exist, assume it is underspecified.
|
|
33
|
+
|
|
34
|
+
### 2) Ask must-have questions first (keep it small)
|
|
35
|
+
|
|
36
|
+
Ask 1-5 questions in the first pass. Prefer questions that eliminate whole branches of work.
|
|
37
|
+
|
|
38
|
+
Make questions easy to answer:
|
|
39
|
+
- Optimize for scannability (short, numbered questions; avoid paragraphs)
|
|
40
|
+
- Offer multiple-choice options when possible
|
|
41
|
+
- Suggest reasonable defaults when appropriate (mark them clearly as the default/recommended choice; bold the recommended choice in the list, or if you present options in a code block, put a bold "Recommended" line immediately above the block and also tag defaults inside the block)
|
|
42
|
+
- Include a fast-path response (e.g., reply `defaults` to accept all recommended/default choices)
|
|
43
|
+
- Include a low-friction "not sure" option when helpful (e.g., "Not sure - use default")
|
|
44
|
+
- Separate "Need to know" from "Nice to know" if that reduces friction
|
|
45
|
+
- Structure options so the user can respond with compact decisions (e.g., `1b 2a 3c`); restate the chosen options in plain language to confirm
|
|
46
|
+
|
|
47
|
+
### 3) Pause before acting
|
|
48
|
+
|
|
49
|
+
Until must-have answers arrive:
|
|
50
|
+
- Do not run commands, edit files, or produce a detailed plan that depends on unknowns
|
|
51
|
+
- Do perform a clearly labeled, low-risk discovery step only if it does not commit you to a direction (e.g., inspect repo structure, read relevant config files)
|
|
52
|
+
|
|
53
|
+
If the user explicitly asks you to proceed without answers:
|
|
54
|
+
- State your assumptions as a short numbered list
|
|
55
|
+
- Ask for confirmation; proceed only after they confirm or correct them
|
|
56
|
+
|
|
57
|
+
### 4) Confirm interpretation, then proceed
|
|
58
|
+
|
|
59
|
+
Once you have answers, restate the requirements in 1-3 sentences (including key constraints and what success looks like), then start work.
|
|
60
|
+
|
|
61
|
+
## Question templates
|
|
62
|
+
|
|
63
|
+
- "Before I start, I need: (1) ..., (2) ..., (3) .... If you don't care about (2), I will assume ...."
|
|
64
|
+
- "Which of these should it be? A) ... B) ... C) ... (pick one)"
|
|
65
|
+
- "What would you consider 'done'? For example: ..."
|
|
66
|
+
- "Any constraints I must follow (versions, performance, style, deps)? If none, I will target the existing project defaults."
|
|
67
|
+
- Use numbered questions with lettered options and a clear reply format
|
|
68
|
+
|
|
69
|
+
```text
|
|
70
|
+
1) Scope?
|
|
71
|
+
a) Minimal change (default)
|
|
72
|
+
b) Refactor while touching the area
|
|
73
|
+
c) Not sure - use default
|
|
74
|
+
2) Compatibility target?
|
|
75
|
+
a) Current project defaults (default)
|
|
76
|
+
b) Also support older versions: <specify>
|
|
77
|
+
c) Not sure - use default
|
|
78
|
+
|
|
79
|
+
Reply with: defaults (or 1a 2a)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Anti-patterns
|
|
83
|
+
|
|
84
|
+
- Don't ask questions you can answer with a quick, low-risk discovery read (e.g., configs, existing patterns, docs).
|
|
85
|
+
- Don't ask open-ended questions if a tight multiple-choice or yes/no would eliminate ambiguity faster.
|