slangmath 1.0.0 โ 1.0.2
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/.env +0 -0
- package/README.md +374 -629
- package/logo.png +0 -0
- package/package.json +23 -23
- package/slang-extended.js +433 -1
- package/slang-math.js +11 -3
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# ๐ SLaNg Math Library
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
### Saad's Language for Analytical Numerics and Geometry
|
|
3
4
|
|
|
4
5
|
๐ฏ **Advanced Symbolic Mathematics with Comprehensive LaTeX Conversion & Extended Function Support**
|
|
5
6
|
|
|
6
|
-
A powerful, dependency-free JavaScript library for symbolic and numerical calculus with **complete polynomial denominator support**, **bidirectional LaTeX conversion**,
|
|
7
|
+
A powerful, dependency-free JavaScript library for symbolic and numerical calculus with **complete polynomial denominator support**, **bidirectional LaTeX conversion**, **extended mathematical functions**, and **advanced multivariable calculus**. Compute derivatives, integrals, rational functions, Taylor series, optimize functions, analyze surfaces, and solve complex multivariable problemsโall with clean, readable code and professional-grade error handling.
|
|
7
8
|
|
|
8
9
|
```javascript
|
|
9
|
-
import { createFraction, createTerm,
|
|
10
|
+
import { createFraction, createTerm, gradient, tangentPlane } from './slang-math.js';
|
|
10
11
|
import { slangToLatex, latexToSlang } from './slang-convertor.js';
|
|
11
12
|
|
|
12
13
|
//: Full polynomial denominator support with LaTeX conversion!
|
|
@@ -19,10 +20,10 @@ const f = createFraction(
|
|
|
19
20
|
const latex = slangToLatex(f);
|
|
20
21
|
console.log(latex); // "\\frac{2x}{x^{2} + 1}"
|
|
21
22
|
|
|
22
|
-
//
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
23
|
+
// Advanced multivariable calculus
|
|
24
|
+
const surface = { terms: [createTerm(1, {x: 2}), createTerm(1, {y: 2})] }; // z = xยฒ + yยฒ
|
|
25
|
+
const tangent = tangentPlane(surface, 1, 2);
|
|
26
|
+
console.log(tangentToLatex(tangent)); // "z = 5 + 2x + 4y + -5"
|
|
26
27
|
|
|
27
28
|
// Parse LaTeX back to SLaNg
|
|
28
29
|
const parsed = latexToSlang('\\frac{x^{2} + 1}{x - 1}');
|
|
@@ -32,46 +33,44 @@ const parsed = latexToSlang('\\frac{x^{2} + 1}{x - 1}');
|
|
|
32
33
|
|
|
33
34
|
---
|
|
34
35
|
|
|
35
|
-
## ๐ What
|
|
36
|
+
## ๐ What This Package Does
|
|
37
|
+
|
|
38
|
+
### โจ Core Capabilities
|
|
36
39
|
|
|
37
|
-
|
|
40
|
+
1. **๐งฎ Advanced Mathematical Functions**
|
|
41
|
+
- Tangent plane and line analysis
|
|
42
|
+
- Gradient and Hessian matrix computation
|
|
43
|
+
- Critical point detection and classification
|
|
44
|
+
- Directional derivatives and steepest directions
|
|
45
|
+
- Surface normal vectors
|
|
46
|
+
- Lagrange multipliers for constrained optimization
|
|
47
|
+
- Local and global extrema finding
|
|
38
48
|
|
|
39
|
-
|
|
40
|
-
-
|
|
49
|
+
2. **๐ Multivariable Calculus**
|
|
50
|
+
- Complete surface analysis capabilities
|
|
51
|
+
- Vector calculus operations
|
|
52
|
+
- Optimization algorithms
|
|
53
|
+
- Constrained optimization with Lagrange multipliers
|
|
54
|
+
|
|
55
|
+
3. **๐ LaTeX Integration**
|
|
56
|
+
- Bidirectional LaTeX conversion
|
|
41
57
|
- Support for complex mathematical expressions
|
|
42
58
|
- Advanced parsing with error recovery
|
|
43
|
-
-
|
|
59
|
+
- Validation system
|
|
44
60
|
|
|
45
|
-
|
|
61
|
+
4. **๐งฎ Extended Mathematical Functions**
|
|
46
62
|
- Trigonometric functions (sin, cos, tan, etc.)
|
|
47
63
|
- Inverse trigonometric functions
|
|
48
64
|
- Hyperbolic functions
|
|
49
65
|
- Logarithmic and exponential functions
|
|
50
66
|
- Function evaluation and differentiation
|
|
51
67
|
|
|
52
|
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
|
|
58
|
-
4. **๐ก๏ธ Advanced Error Handling**
|
|
59
|
-
- Comprehensive error classification
|
|
60
|
-
- Error recovery suggestions
|
|
61
|
-
- Detailed validation system
|
|
62
|
-
- Graceful fallback strategies
|
|
63
|
-
|
|
64
|
-
5. **๐งช Comprehensive Testing Suite**
|
|
65
|
-
- Unit tests with 95%+ coverage
|
|
66
|
-
- Performance benchmarks
|
|
67
|
-
- Integration tests
|
|
68
|
-
- Automated CI/CD ready
|
|
69
|
-
|
|
70
|
-
6. **๐ Enhanced Documentation**
|
|
71
|
-
- Function-by-function explanations
|
|
72
|
-
- Usage examples and best practices
|
|
73
|
-
- API reference with TypeScript support
|
|
74
|
-
- Interactive examples
|
|
68
|
+
5. **๐ Core Calculus Operations**
|
|
69
|
+
- Symbolic differentiation and integration
|
|
70
|
+
- Numerical integration with Simpson's rule
|
|
71
|
+
- Polynomial arithmetic
|
|
72
|
+
- Rational function operations
|
|
73
|
+
- Taylor series expansion
|
|
75
74
|
|
|
76
75
|
---
|
|
77
76
|
|
|
@@ -104,64 +103,115 @@ const expr = createFraction(
|
|
|
104
103
|
const latex = slangToLatex(expr);
|
|
105
104
|
console.log(latex); // "\\frac{x^{2} - 1}{x^{2} + 1}"
|
|
106
105
|
|
|
107
|
-
// Validate LaTeX
|
|
108
|
-
const validation = validateLatex(latex);
|
|
109
|
-
console.log(validation.valid); // true
|
|
110
|
-
|
|
111
106
|
// Parse back from LaTeX
|
|
112
107
|
const parsed = latexToSlang(latex);
|
|
113
108
|
```
|
|
114
109
|
|
|
115
|
-
#### Example 2:
|
|
110
|
+
#### Example 2: Advanced Multivariable Calculus
|
|
116
111
|
```javascript
|
|
117
|
-
import {
|
|
112
|
+
import { gradient, hessian, tangentPlane, findCriticalPoints } from './slang-extended.js';
|
|
118
113
|
|
|
119
|
-
//
|
|
120
|
-
const
|
|
114
|
+
// Surface: z = xยฒ + yยฒ
|
|
115
|
+
const surface = { terms: [createTerm(1, {x: 2}), createTerm(1, {y: 2})] };
|
|
121
116
|
|
|
122
|
-
//
|
|
123
|
-
const
|
|
124
|
-
console.log(
|
|
117
|
+
// Calculate gradient
|
|
118
|
+
const grad = gradient(surface, ['x', 'y']);
|
|
119
|
+
console.log('โf =', grad); // {x: 2x, y: 2y}
|
|
120
|
+
|
|
121
|
+
// Find tangent plane at (1, 2)
|
|
122
|
+
const tangent = tangentPlane(surface, 1, 2);
|
|
123
|
+
console.log('Tangent plane:', tangentToLatex(tangent));
|
|
125
124
|
|
|
126
|
-
//
|
|
127
|
-
const
|
|
128
|
-
console.log(result); // 1
|
|
125
|
+
// Find critical points
|
|
126
|
+
const critical = findCriticalPoints(surface, ['x', 'y']);
|
|
129
127
|
```
|
|
130
128
|
|
|
131
|
-
#### Example 3:
|
|
129
|
+
#### Example 3: Optimization
|
|
132
130
|
```javascript
|
|
133
|
-
import {
|
|
131
|
+
import { findExtrema, classifyCriticalPoint, lagrangeMultipliers } from './slang-extended.js';
|
|
134
132
|
|
|
135
|
-
//
|
|
136
|
-
const
|
|
137
|
-
const latexResults = batchConvertToLatex(expressions);
|
|
133
|
+
// Function: f(x,y) = xยฒ - yยฒ (saddle point)
|
|
134
|
+
const saddle = { terms: [createTerm(1, {x: 2}), createTerm(-1, {y: 2})] };
|
|
138
135
|
|
|
139
|
-
//
|
|
140
|
-
const
|
|
141
|
-
|
|
136
|
+
// Find and classify critical points
|
|
137
|
+
const points = findCriticalPoints(saddle, ['x', 'y']);
|
|
138
|
+
points.forEach(point => {
|
|
139
|
+
const classification = classifyCriticalPoint(saddle, point.variables);
|
|
140
|
+
console.log(`Point: ${JSON.stringify(point.variables)}, Type: ${classification}`);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Constrained optimization with Lagrange multipliers
|
|
144
|
+
const objective = { terms: [createTerm(1, {x: 1}), createTerm(1, {y: 1})] }; // x + y
|
|
145
|
+
const constraint = { terms: [createTerm(1, {x: 2}), createTerm(1, {y: 2}), createTerm(-1)] }; // xยฒ + yยฒ = 1
|
|
146
|
+
const constrained = lagrangeMultipliers(objective, [constraint], ['x', 'y']);
|
|
142
147
|
```
|
|
143
148
|
|
|
144
|
-
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## ๐ Complete Feature List
|
|
152
|
+
|
|
153
|
+
### ๐งฎ Advanced Mathematical Functions
|
|
154
|
+
|
|
155
|
+
#### Tangent Analysis
|
|
145
156
|
```javascript
|
|
146
|
-
import {
|
|
157
|
+
import { tangentPlane, tangentLine, surfaceNormal } from './slang-extended.js';
|
|
147
158
|
|
|
148
|
-
//
|
|
149
|
-
const
|
|
159
|
+
// Tangent plane to surface z = f(x,y) at point (x0, y0)
|
|
160
|
+
const plane = tangentPlane(surface, 1, 2);
|
|
161
|
+
console.log('Point:', plane.point);
|
|
162
|
+
console.log('Normal:', plane.normal);
|
|
163
|
+
console.log('Equation:', tangentToLatex(plane));
|
|
150
164
|
|
|
151
|
-
//
|
|
152
|
-
const
|
|
153
|
-
console.log(
|
|
165
|
+
// Tangent line to curve y = f(x) at point x0
|
|
166
|
+
const line = tangentLine(curve, 1);
|
|
167
|
+
console.log('Slope:', line.slope);
|
|
168
|
+
console.log('Equation:', tangentToLatex(line));
|
|
169
|
+
|
|
170
|
+
// Surface normal vector
|
|
171
|
+
const normal = surfaceNormal(surface, {x: 1, y: 0, z: 0});
|
|
154
172
|
```
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
173
|
+
|
|
174
|
+
#### Optimization
|
|
175
|
+
```javascript
|
|
176
|
+
import { findCriticalPoints, classifyCriticalPoint, findExtrema, findGlobalExtrema } from './slang-extended.js';
|
|
177
|
+
|
|
178
|
+
// Find critical points
|
|
179
|
+
const critical = findCriticalPoints(function, ['x', 'y']);
|
|
180
|
+
|
|
181
|
+
// Classify critical points (minimum, maximum, saddle)
|
|
182
|
+
const classification = classifyCriticalPoint(function, point);
|
|
183
|
+
|
|
184
|
+
// Find local extrema
|
|
185
|
+
const extrema = findExtrema(function, ['x', 'y'], bounds);
|
|
186
|
+
|
|
187
|
+
// Find global extrema in bounded region
|
|
188
|
+
const global = findGlobalExtrema(function, ['x', 'y'], bounds);
|
|
160
189
|
```
|
|
161
190
|
|
|
162
|
-
|
|
191
|
+
#### Multivariable Calculus
|
|
192
|
+
```javascript
|
|
193
|
+
import { gradient, hessian, directionalDerivative, steepestDirections } from './slang-extended.js';
|
|
163
194
|
|
|
164
|
-
|
|
195
|
+
// Gradient vector
|
|
196
|
+
const grad = gradient(function, ['x', 'y', 'z']);
|
|
197
|
+
|
|
198
|
+
// Hessian matrix
|
|
199
|
+
const hess = hessian(function, ['x', 'y']);
|
|
200
|
+
|
|
201
|
+
// Directional derivative
|
|
202
|
+
const dirDeriv = directionalDerivative(function, point, direction);
|
|
203
|
+
|
|
204
|
+
// Steepest ascent/descent directions
|
|
205
|
+
const steepest = steepestDirections(function, point);
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### Constrained Optimization
|
|
209
|
+
```javascript
|
|
210
|
+
import { lagrangeMultipliers } from './slang-extended.js';
|
|
211
|
+
|
|
212
|
+
// Solve constrained optimization problems
|
|
213
|
+
const result = lagrangeMultipliers(objective, constraints, variables);
|
|
214
|
+
```
|
|
165
215
|
|
|
166
216
|
### ๐ LaTeX Conversion System
|
|
167
217
|
|
|
@@ -182,19 +232,6 @@ const validation = validateLatex(latex);
|
|
|
182
232
|
console.log(validation.valid); // true
|
|
183
233
|
```
|
|
184
234
|
|
|
185
|
-
#### Advanced Formatting
|
|
186
|
-
```javascript
|
|
187
|
-
import { formatDisplayMode, batchConvertToLatex } from './slang-convertor.js';
|
|
188
|
-
|
|
189
|
-
// Display mode formatting
|
|
190
|
-
const inline = formatDisplayMode(latex, { preferInline: true }); // $...$
|
|
191
|
-
const display = formatDisplayMode(latex, { forceDisplay: true }); // $$...$$
|
|
192
|
-
|
|
193
|
-
// Batch processing
|
|
194
|
-
const expressions = [expr1, expr2, expr3];
|
|
195
|
-
const results = batchConvertToLatex(expressions, { includeErrors: true });
|
|
196
|
-
```
|
|
197
|
-
|
|
198
235
|
### ๐งฎ Extended Mathematical Functions
|
|
199
236
|
|
|
200
237
|
#### Trigonometric Functions
|
|
@@ -222,67 +259,6 @@ console.log(evaluateFunction(cosExpr, { x: 0 })); // 1
|
|
|
222
259
|
- **Exponential**: exp, sqrt
|
|
223
260
|
- **Other**: abs, floor, ceil
|
|
224
261
|
|
|
225
|
-
### โก Performance & Caching
|
|
226
|
-
|
|
227
|
-
#### Caching System
|
|
228
|
-
```javascript
|
|
229
|
-
import { cachedLatexToSlang, getPerformanceStats, clearAllCaches } from './slang-cache.js';
|
|
230
|
-
|
|
231
|
-
// Use cached conversions
|
|
232
|
-
const result = cachedLatexToSlang(latex);
|
|
233
|
-
|
|
234
|
-
// Monitor performance
|
|
235
|
-
const stats = getPerformanceStats();
|
|
236
|
-
console.log(`Cache hit rate: ${stats.caches.latexToSlang.hitRate}`);
|
|
237
|
-
console.log(`Average operation time: ${stats.operations.averageTime}ms`);
|
|
238
|
-
|
|
239
|
-
// Clear caches if needed
|
|
240
|
-
clearAllCaches();
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
#### Performance Monitoring
|
|
244
|
-
```javascript
|
|
245
|
-
import { withPerformanceMonitoring } from './slang-cache.js';
|
|
246
|
-
|
|
247
|
-
// Wrap functions with performance monitoring
|
|
248
|
-
const monitoredConvert = withPerformanceMonitoring(slangToLatex, 'slangToLatex');
|
|
249
|
-
const result = monitoredConvert(expression); // Automatically tracked
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
### ๐ก๏ธ Error Handling & Validation
|
|
253
|
-
|
|
254
|
-
#### Advanced Error System
|
|
255
|
-
```javascript
|
|
256
|
-
import { ParseError, ValidationError, handleError, attemptRecovery } from './slang-errors.js';
|
|
257
|
-
|
|
258
|
-
try {
|
|
259
|
-
const result = latexToSlang(invalidLatex);
|
|
260
|
-
} catch (error) {
|
|
261
|
-
// Handle with custom strategies
|
|
262
|
-
const handled = handleError(error, {
|
|
263
|
-
logErrors: true,
|
|
264
|
-
returnNull: false
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
// Attempt recovery
|
|
268
|
-
const recovery = attemptRecovery(error, originalInput);
|
|
269
|
-
if (recovery.success) {
|
|
270
|
-
console.log('Recovered with:', recovery.result);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
#### Validation System
|
|
276
|
-
```javascript
|
|
277
|
-
import { validateLatex, validateErrorContext } from './slang-convertor.js';
|
|
278
|
-
|
|
279
|
-
// Comprehensive validation
|
|
280
|
-
const validation = validateLatex(latex, { strictMode: true });
|
|
281
|
-
if (!validation.valid) {
|
|
282
|
-
console.log('Errors:', validation.errors);
|
|
283
|
-
}
|
|
284
|
-
```
|
|
285
|
-
|
|
286
262
|
### ๐ Core Operations
|
|
287
263
|
|
|
288
264
|
#### Expression Creation
|
|
@@ -305,7 +281,7 @@ const frac = createFraction(
|
|
|
305
281
|
|
|
306
282
|
#### Calculus Operations
|
|
307
283
|
```javascript
|
|
308
|
-
import { differentiateFraction, numericalIntegrateFraction } from './slang-
|
|
284
|
+
import { differentiateFraction, numericalIntegrateFraction } from './slang-basic.js';
|
|
309
285
|
import { partialDerivative } from './slang-helpers.js';
|
|
310
286
|
|
|
311
287
|
// Differentiation
|
|
@@ -319,216 +295,93 @@ const pdY = partialDerivative(expr, 'y');
|
|
|
319
295
|
const integral = numericalIntegrateFraction(frac, 0, 1, 'x', 1000);
|
|
320
296
|
```
|
|
321
297
|
|
|
322
|
-
#### โซ Integration
|
|
323
|
-
|
|
324
|
-
**Symbolic Integration**
|
|
325
|
-
```javascript
|
|
326
|
-
import { integrateFraction } from './slang-math.js';
|
|
327
|
-
|
|
328
|
-
// Works for polynomial / constant
|
|
329
|
-
const F = integrateFraction(
|
|
330
|
-
createFraction([createTerm(2, {x: 1})], 1),
|
|
331
|
-
'x'
|
|
332
|
-
); // xยฒ
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
**Numerical Integration (NEW: Simpson's Rule)**
|
|
336
|
-
```javascript
|
|
337
|
-
import { numericalIntegrateFraction } from './slang-math.js';
|
|
338
|
-
|
|
339
|
-
// For complex rational functions
|
|
340
|
-
const area = numericalIntegrateFraction(
|
|
341
|
-
complexRational,
|
|
342
|
-
0, // lower
|
|
343
|
-
1, // upper
|
|
344
|
-
'x',
|
|
345
|
-
1000 // steps (even number for Simpson's rule)
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
// Uses Simpson's rule: h/3[f(xโ) + 4f(xโ) + 2f(xโ) + ...]
|
|
349
|
-
// Much more accurate than rectangle method!
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
**Definite Integration**
|
|
353
|
-
```javascript
|
|
354
|
-
import { definiteIntegrateFraction } from './slang-math.js';
|
|
355
|
-
|
|
356
|
-
const result = definiteIntegrateFraction(
|
|
357
|
-
fraction,
|
|
358
|
-
0, // lower bound
|
|
359
|
-
2, // upper bound
|
|
360
|
-
'x'
|
|
361
|
-
);
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
**Double/Triple Integrals**
|
|
365
|
-
```javascript
|
|
366
|
-
import { integralValue } from './slang-helpers.js';
|
|
367
|
-
|
|
368
|
-
// โซโซ xy dx dy over [0,2] ร [0,3]
|
|
369
|
-
const volume = integralValue(
|
|
370
|
-
createFraction([createTerm(1, {x:1, y:1})], 1),
|
|
371
|
-
{ x: [0, 2], y: [0, 3] }
|
|
372
|
-
); // 9
|
|
373
|
-
```
|
|
374
|
-
|
|
375
298
|
---
|
|
376
299
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
#### ๐ฏ Product & Quotient Rules
|
|
380
|
-
|
|
381
|
-
```javascript
|
|
382
|
-
import { productRuleDifferentiate, quotientRuleDifferentiate } from './slang-advanced.js';
|
|
383
|
-
|
|
384
|
-
// Product rule: d/dx[fยทg] = f'ยทg + fยทg'
|
|
385
|
-
const derivative1 = productRuleDifferentiate([f, g], 'x');
|
|
386
|
-
|
|
387
|
-
// Quotient rule: d/dx[f/g] = (f'ยทg - fยทg')/gยฒ
|
|
388
|
-
const derivative2 = quotientRuleDifferentiate(f, g, 'x');
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
#### ๐ Chain Rule
|
|
392
|
-
|
|
393
|
-
```javascript
|
|
394
|
-
import { chainRuleDifferentiate } from './slang-advanced.js';
|
|
395
|
-
|
|
396
|
-
// For compositions like f(g(x))
|
|
397
|
-
const result = chainRuleDifferentiate(outer, inner, 'x');
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
#### ๐ Taylor Series
|
|
401
|
-
|
|
402
|
-
```javascript
|
|
403
|
-
import { taylorSeries } from './slang-advanced.js';
|
|
404
|
-
|
|
405
|
-
// Expand f(x) around x = 0 to order 5
|
|
406
|
-
const taylor = taylorSeries(f, 'x', 0, 5);
|
|
407
|
-
// f(x) โ f(0) + f'(0)x + f''(0)xยฒ/2! + ...
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
#### ๐ฒ Optimization
|
|
411
|
-
|
|
412
|
-
**Critical Points**
|
|
413
|
-
```javascript
|
|
414
|
-
import { findCriticalPoints, secondDerivativeTest } from './slang-advanced.js';
|
|
415
|
-
|
|
416
|
-
// Find where f'(x) = 0
|
|
417
|
-
const critical = findCriticalPoints(f, 'x', [-10, 10]);
|
|
418
|
-
|
|
419
|
-
// Classify each point
|
|
420
|
-
for (let point of critical.criticalPoints) {
|
|
421
|
-
const test = secondDerivativeTest(f, 'x', point);
|
|
422
|
-
console.log(`x = ${point}: ${test.type}`);
|
|
423
|
-
// "local minimum", "local maximum", or "inconclusive"
|
|
424
|
-
}
|
|
425
|
-
```
|
|
426
|
-
|
|
427
|
-
**Curve Analysis**
|
|
428
|
-
```javascript
|
|
429
|
-
import { analyzeCurve } from './slang-advanced.js';
|
|
430
|
-
|
|
431
|
-
const analysis = analyzeCurve(f, 'x', [-5, 5]);
|
|
432
|
-
// Returns: {
|
|
433
|
-
// criticalPoints: [...],
|
|
434
|
-
// extrema: [...],
|
|
435
|
-
// inflectionPoints: [...],
|
|
436
|
-
// firstDerivative: {...},
|
|
437
|
-
// secondDerivative: {...}
|
|
438
|
-
// }
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
#### ๐ Geometry
|
|
442
|
-
|
|
443
|
-
**Arc Length**
|
|
444
|
-
```javascript
|
|
445
|
-
import { arcLength } from './slang-advanced.js';
|
|
446
|
-
|
|
447
|
-
// Length of curve y = f(x) from a to b
|
|
448
|
-
const L = arcLength(f, 'x', 0, 2);
|
|
449
|
-
// Uses: L = โซโ(1 + (dy/dx)ยฒ) dx
|
|
450
|
-
```
|
|
451
|
-
|
|
452
|
-
**Surface Area of Revolution**
|
|
453
|
-
```javascript
|
|
454
|
-
import { surfaceAreaOfRevolution } from './slang-advanced.js';
|
|
300
|
+
## ๐๏ธ Architecture
|
|
455
301
|
|
|
456
|
-
|
|
457
|
-
const SA = surfaceAreaOfRevolution(f, 'x', 0, 1);
|
|
458
|
-
// Uses: SA = 2ฯ โซ yโ(1 + (dy/dx)ยฒ) dx
|
|
302
|
+
### Module Structure
|
|
459
303
|
```
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
304
|
+
slang-math.js (central exports)
|
|
305
|
+
โโ slang-basic.js
|
|
306
|
+
โ โโ Core term/fraction creation
|
|
307
|
+
โ โโ Polynomial arithmetic
|
|
308
|
+
โ โโ Differentiation & integration
|
|
309
|
+
โ โโ GCD simplification
|
|
310
|
+
โโ slang-extended.js (Advanced functions)
|
|
311
|
+
โ โโ Tangent plane/line analysis
|
|
312
|
+
โ โโ Gradient & Hessian computation
|
|
313
|
+
โ โโ Critical points & optimization
|
|
314
|
+
โ โโ Directional derivatives
|
|
315
|
+
โ โโ Surface normals
|
|
316
|
+
โ โโ Lagrange multipliers
|
|
317
|
+
โ โโ Extended mathematical functions
|
|
318
|
+
โโ slang-convertor.js
|
|
319
|
+
โ โโ LaTeX conversion system
|
|
320
|
+
โ โโ Bidirectional parsing
|
|
321
|
+
โโ slang-helpers.js
|
|
322
|
+
โ โโ Easy builders
|
|
323
|
+
โ โโ Common formulas
|
|
324
|
+
โโ slang-advanced.js
|
|
325
|
+
โโ Product/quotient rules
|
|
326
|
+
โโ Taylor series
|
|
327
|
+
โโ Advanced algorithms
|
|
467
328
|
```
|
|
468
329
|
|
|
469
|
-
|
|
330
|
+
---
|
|
470
331
|
|
|
471
|
-
|
|
472
|
-
```javascript
|
|
473
|
-
import { gradient } from './slang-advanced.js';
|
|
332
|
+
## ๐งช Testing & Quality Assurance
|
|
474
333
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
334
|
+
### Comprehensive Test Suite
|
|
335
|
+
```bash
|
|
336
|
+
# Run all tests
|
|
337
|
+
npm test
|
|
478
338
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
import { directionalDerivative } from './slang-advanced.js';
|
|
339
|
+
# Run extended functions test
|
|
340
|
+
node experiments/slang-extended-test.js
|
|
482
341
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
['x', 'y'],
|
|
486
|
-
{x: 1, y: 1}, // point
|
|
487
|
-
{x: 1, y: 0} // direction
|
|
488
|
-
);
|
|
489
|
-
// Rate of change in given direction
|
|
342
|
+
# Run converter test
|
|
343
|
+
node experiments/test-converter.js
|
|
490
344
|
```
|
|
491
345
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
346
|
+
### Test Coverage
|
|
347
|
+
- **Unit Tests**: 95%+ code coverage
|
|
348
|
+
- **Integration Tests**: End-to-end functionality
|
|
349
|
+
- **Advanced Functions**: All features tested
|
|
350
|
+
- **Error Handling**: Comprehensive error scenarios
|
|
351
|
+
|
|
352
|
+
### Test Categories
|
|
353
|
+
1. Basic Function Creation and Evaluation
|
|
354
|
+
2. Gradient and Hessian Matrices
|
|
355
|
+
3. Tangent Plane and Line Analysis
|
|
356
|
+
4. Critical Points and Optimization
|
|
357
|
+
5. Directional Derivatives and Gradient Analysis
|
|
358
|
+
6. Surface Normals
|
|
359
|
+
7. Lagrange Multipliers
|
|
360
|
+
8. Function Evaluation Edge Cases
|
|
361
|
+
9. LaTeX Conversion
|
|
362
|
+
10. Supported Functions Registry
|
|
503
363
|
|
|
504
364
|
---
|
|
505
365
|
|
|
506
|
-
##
|
|
507
|
-
|
|
508
|
-
```javascript
|
|
509
|
-
import {
|
|
510
|
-
addPolynomials,
|
|
511
|
-
subtractPolynomials,
|
|
512
|
-
multiplyPolynomials,
|
|
513
|
-
simplifyPolynomial
|
|
514
|
-
} from './slang-math.js';
|
|
515
|
-
|
|
516
|
-
// Addition
|
|
517
|
-
const sum = addPolynomials(poly1, poly2);
|
|
518
|
-
|
|
519
|
-
// Subtraction
|
|
520
|
-
const diff = subtractPolynomials(poly1, poly2);
|
|
521
|
-
|
|
522
|
-
// Multiplication
|
|
523
|
-
const product = multiplyPolynomials(poly1, poly2);
|
|
524
|
-
|
|
525
|
-
// Simplification (combines like terms)
|
|
526
|
-
const simplified = simplifyPolynomial(polynomial);
|
|
527
|
-
```
|
|
366
|
+
## ๐ Complete API Reference
|
|
528
367
|
|
|
529
|
-
|
|
368
|
+
### Advanced Functions
|
|
530
369
|
|
|
531
|
-
|
|
370
|
+
| Function | Purpose | Example |
|
|
371
|
+
|----------|---------|---------|
|
|
372
|
+
| `gradient(func, vars)` | Calculate gradient vector | `gradient(f, ['x', 'y'])` |
|
|
373
|
+
| `hessian(func, vars)` | Calculate Hessian matrix | `hessian(f, ['x', 'y'])` |
|
|
374
|
+
| `tangentPlane(func, x0, y0)` | Tangent plane to surface | `tangentPlane(f, 1, 2)` |
|
|
375
|
+
| `tangentLine(func, x0)` | Tangent line to curve | `tangentLine(f, 1)` |
|
|
376
|
+
| `surfaceNormal(func, point)` | Surface normal vector | `surfaceNormal(f, {x:1,y:0,z:0})` |
|
|
377
|
+
| `findCriticalPoints(func, vars)` | Find critical points | `findCriticalPoints(f, ['x', 'y'])` |
|
|
378
|
+
| `classifyCriticalPoint(func, point)` | Classify critical point | `classifyCriticalPoint(f, point)` |
|
|
379
|
+
| `findExtrema(func, vars, bounds)` | Find local extrema | `findExtrema(f, ['x'], bounds)` |
|
|
380
|
+
| `findGlobalExtrema(func, vars, bounds)` | Find global extrema | `findGlobalExtrema(f, ['x'], bounds)` |
|
|
381
|
+
| `lagrangeMultipliers(func, constraints, vars)` | Constrained optimization | `lagrangeMultipliers(f, [g], ['x', 'y'])` |
|
|
382
|
+
| `directionalDerivative(func, point, direction)` | Directional derivative | `directionalDerivative(f, point, dir)` |
|
|
383
|
+
| `steepestDirections(func, point)` | Steepest ascent/descent | `steepestDirections(f, point)` |
|
|
384
|
+
| `tangentToLatex(tangent)` | Convert tangent to LaTeX | `tangentToLatex(tangent)` |
|
|
532
385
|
|
|
533
386
|
### Core Functions
|
|
534
387
|
|
|
@@ -543,230 +396,92 @@ const simplified = simplifyPolynomial(polynomial);
|
|
|
543
396
|
| `numericalIntegrateFraction(...)` | Numeric integration | Simpson's rule |
|
|
544
397
|
| `simplifyFraction(frac)` | Simplify | Combines terms, GCD |
|
|
545
398
|
|
|
546
|
-
### Helper Functions
|
|
547
|
-
|
|
548
|
-
| Function | Purpose | Example |
|
|
549
|
-
|----------|---------|---------|
|
|
550
|
-
| `sum(terms)` | Build expression | See creation section |
|
|
551
|
-
| `integralValue(expr, bounds)` | Integrate & evaluate | One-liner |
|
|
552
|
-
| `volumeUnderSurface(f, xb, yb)` | 3D volume | Double integral |
|
|
553
|
-
| `partialDerivative(f, var)` | Partial derivative | Multivariable |
|
|
554
|
-
|
|
555
|
-
### Advanced Functions
|
|
556
|
-
|
|
557
|
-
| Function | Purpose | Example |
|
|
558
|
-
|----------|---------|---------|
|
|
559
|
-
| `productRuleDifferentiate(fs, var)` | Product rule | d/dx[fยทgยทh] |
|
|
560
|
-
| `quotientRuleDifferentiate(f, g, var)` | Quotient rule | d/dx[f/g] |
|
|
561
|
-
| `taylorSeries(f, var, center, order)` | Taylor expansion | Approximate f |
|
|
562
|
-
| `findCriticalPoints(f, var, range)` | Find extrema | Optimization |
|
|
563
|
-
| `gradient(f, vars)` | Gradient vector | โf |
|
|
564
|
-
| `arcLength(f, var, a, b)` | Curve length | Geometry |
|
|
565
|
-
|
|
566
399
|
---
|
|
567
400
|
|
|
568
401
|
## ๐ก Usage Patterns
|
|
569
402
|
|
|
570
|
-
### Pattern 1:
|
|
403
|
+
### Pattern 1: Multivariable Surface Analysis
|
|
571
404
|
```javascript
|
|
572
|
-
//
|
|
573
|
-
const
|
|
574
|
-
const critical = findCriticalPoints(f[0][0], 'x', [-5, 5]);
|
|
575
|
-
const fPrime = differentiateFraction(f[0][0], 'x');
|
|
576
|
-
|
|
577
|
-
console.log('f(x) =', fractionToString(f[0][0]));
|
|
578
|
-
console.log('f\'(x) =', fractionToString(fPrime));
|
|
579
|
-
console.log('Critical points:', critical.criticalPoints);
|
|
580
|
-
```
|
|
405
|
+
// Analyze surface z = xยฒ + yยฒ
|
|
406
|
+
const surface = { terms: [createTerm(1, {x: 2}), createTerm(1, {y: 2})] };
|
|
581
407
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
const f = createFraction(
|
|
586
|
-
[createTerm(1, {x:2}), createTerm(-1)],
|
|
587
|
-
[createTerm(1, {x:2}), createTerm(1)]
|
|
588
|
-
);
|
|
408
|
+
// Find tangent plane at point
|
|
409
|
+
const tangent = tangentPlane(surface, 1, 2);
|
|
410
|
+
console.log('Tangent plane:', tangentToLatex(tangent));
|
|
589
411
|
|
|
590
|
-
|
|
591
|
-
const
|
|
412
|
+
// Calculate gradient
|
|
413
|
+
const grad = gradient(surface, ['x', 'y']);
|
|
414
|
+
console.log('Gradient:', grad);
|
|
592
415
|
|
|
593
|
-
|
|
594
|
-
|
|
416
|
+
// Find critical points
|
|
417
|
+
const critical = findCriticalPoints(surface, ['x', 'y']);
|
|
595
418
|
```
|
|
596
419
|
|
|
597
|
-
### Pattern
|
|
420
|
+
### Pattern 2: Optimization Problem
|
|
598
421
|
```javascript
|
|
599
|
-
//
|
|
600
|
-
const
|
|
601
|
-
|
|
602
|
-
[createTerm(1, {x:1}), createTerm(1, {y:1})]
|
|
603
|
-
);
|
|
604
|
-
|
|
605
|
-
const grad = gradient(f, ['x', 'y']);
|
|
606
|
-
console.log('โf =', grad);
|
|
422
|
+
// Optimize f(x,y) = xยฒ - yยฒ subject to xยฒ + yยฒ = 1
|
|
423
|
+
const objective = { terms: [createTerm(1, {x: 2}), createTerm(-1, {y: 2})] };
|
|
424
|
+
const constraint = { terms: [createTerm(1, {x: 2}), createTerm(1, {y: 2}), createTerm(-1)] };
|
|
607
425
|
|
|
608
|
-
//
|
|
609
|
-
const
|
|
610
|
-
|
|
611
|
-
y: evaluateFraction(grad.gradient.y, {x:1, y:1})
|
|
612
|
-
};
|
|
613
|
-
console.log('โf(1,1) =', gradAt);
|
|
426
|
+
// Use Lagrange multipliers
|
|
427
|
+
const result = lagrangeMultipliers(objective, [constraint], ['x', 'y']);
|
|
428
|
+
console.log('Constrained extrema:', result);
|
|
614
429
|
```
|
|
615
430
|
|
|
616
|
-
### Pattern
|
|
431
|
+
### Pattern 3: Directional Analysis
|
|
617
432
|
```javascript
|
|
618
|
-
//
|
|
619
|
-
const
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
433
|
+
// Analyze directional derivatives of f(x,y) = xยฒ + yยฒ
|
|
434
|
+
const func = { terms: [createTerm(1, {x: 2}), createTerm(1, {y: 2})] };
|
|
435
|
+
const point = { x: 1, y: 1 };
|
|
436
|
+
const direction = { x: 1, y: 1 };
|
|
437
|
+
|
|
438
|
+
// Calculate directional derivative
|
|
439
|
+
const dirDeriv = directionalDerivative(func, point, direction);
|
|
623
440
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
441
|
+
// Find steepest directions
|
|
442
|
+
const steepest = steepestDirections(func, point);
|
|
443
|
+
console.log('Steepest ascent:', steepest.steepest_ascent);
|
|
444
|
+
console.log('Steepest descent:', steepest.steepest_descent);
|
|
627
445
|
```
|
|
628
446
|
|
|
629
447
|
---
|
|
630
448
|
|
|
631
449
|
## ๐ฏ Real-World Applications
|
|
632
450
|
|
|
633
|
-
### Physics:
|
|
451
|
+
### Physics: Surface Analysis
|
|
634
452
|
```javascript
|
|
635
|
-
|
|
636
|
-
const
|
|
637
|
-
const a = differentiateFraction(v, 't'); // a(t) = v'(t)
|
|
453
|
+
// Analyze temperature distribution T(x,y) = xยฒ + 2xy + yยฒ
|
|
454
|
+
const temperature = { terms: [createTerm(1, {x: 2}), createTerm(2, {x: 1, y: 1}), createTerm(1, {y: 2})] };
|
|
638
455
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
```
|
|
456
|
+
// Find heat flux (gradient)
|
|
457
|
+
const heatFlux = gradient(temperature, ['x', 'y']);
|
|
642
458
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
// Average cost: C(x) = (xยฒ + 100x + 1000)/x
|
|
646
|
-
const AC = createFraction(
|
|
647
|
-
[createTerm(1, {x:2}), createTerm(100, {x:1}), createTerm(1000)],
|
|
648
|
-
[createTerm(1, {x:1})]
|
|
649
|
-
);
|
|
650
|
-
|
|
651
|
-
const minCost = findCriticalPoints({numi: AC.numi, deno: 1}, 'x', [1, 100]);
|
|
459
|
+
// Find hottest/coldest points
|
|
460
|
+
const extrema = findExtrema(temperature, ['x', 'y']);
|
|
652
461
|
```
|
|
653
462
|
|
|
654
|
-
### Engineering:
|
|
463
|
+
### Engineering: Optimization
|
|
655
464
|
```javascript
|
|
656
|
-
// Minimize surface area of cylinder with volume
|
|
657
|
-
//
|
|
658
|
-
|
|
659
|
-
|
|
465
|
+
// Minimize surface area of cylinder with volume constraint
|
|
466
|
+
// Use Lagrange multipliers to solve constrained optimization
|
|
467
|
+
const surfaceArea = { terms: [createTerm(2, {r: 2}), createTerm(2, {r: 1, h: 1})] };
|
|
468
|
+
const volumeConstraint = { terms: [createTerm(1, {r: 2, h: 1}), createTerm(-V)] };
|
|
469
|
+
const result = lagrangeMultipliers(surfaceArea, [volumeConstraint], ['r', 'h']);
|
|
660
470
|
```
|
|
661
471
|
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
## ๐๏ธ Architecture
|
|
665
|
-
|
|
666
|
-
### Module Structure
|
|
667
|
-
```
|
|
668
|
-
slang-math.js (exports all)
|
|
669
|
-
โโ slang-basic.js ( )
|
|
670
|
-
โ โโ Core term/fraction creation
|
|
671
|
-
โ โโ Polynomial arithmetic
|
|
672
|
-
โ โโ Quotient rule differentiation
|
|
673
|
-
โ โโ Simpson's rule integration
|
|
674
|
-
โ โโ GCD simplification
|
|
675
|
-
โโ slang-helpers.js
|
|
676
|
-
โ โโ Easy builders
|
|
677
|
-
โ โโ Common formulas
|
|
678
|
-
โ โโ Verification tools
|
|
679
|
-
โโ slang-advanced.js
|
|
680
|
-
โโ Product/quotient rules
|
|
681
|
-
โโ Taylor series
|
|
682
|
-
โโ Optimization
|
|
683
|
-
โโ Multivariable calculus
|
|
684
|
-
```
|
|
685
|
-
|
|
686
|
-
### Data Structure (Enhanced)
|
|
472
|
+
### Economics: Multivariable Optimization
|
|
687
473
|
```javascript
|
|
688
|
-
//
|
|
689
|
-
{
|
|
690
|
-
numi: {
|
|
691
|
-
terms: [
|
|
692
|
-
{ coeff: 2, var: { x: 2 } }, // 2xยฒ
|
|
693
|
-
{ coeff: 3, var: { x: 1 } } // 3x
|
|
694
|
-
]
|
|
695
|
-
},
|
|
696
|
-
deno: { //: Can be polynomial!
|
|
697
|
-
terms: [
|
|
698
|
-
{ coeff: 1, var: { x: 1 } }, // x
|
|
699
|
-
{ coeff: 1 } // 1
|
|
700
|
-
]
|
|
701
|
-
}
|
|
702
|
-
// OR simple: deno: 5
|
|
703
|
-
}
|
|
704
|
-
```
|
|
705
|
-
|
|
706
|
-
---
|
|
707
|
-
|
|
708
|
-
## ๐งช Testing & Quality Assurance
|
|
474
|
+
// Maximize profit P(x,y) = 10x + 8y - xยฒ - yยฒ - xy
|
|
475
|
+
const profit = { terms: [createTerm(10, {x: 1}), createTerm(8, {y: 1}), createTerm(-1, {x: 2}), createTerm(-1, {y: 2}), createTerm(-1, {x: 1, y: 1})] };
|
|
709
476
|
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
npm run test:coverage
|
|
717
|
-
|
|
718
|
-
# Run tests in watch mode
|
|
719
|
-
npm run test:watch
|
|
720
|
-
|
|
721
|
-
# Run specific test suites
|
|
722
|
-
node tests/unit/converter.test.js
|
|
723
|
-
node experiments/test-converter.js
|
|
477
|
+
// Find optimal production levels
|
|
478
|
+
const critical = findCriticalPoints(profit, ['x', 'y']);
|
|
479
|
+
critical.forEach(point => {
|
|
480
|
+
const classification = classifyCriticalPoint(profit, point.variables);
|
|
481
|
+
console.log(`Production levels: ${JSON.stringify(point.variables)}, Type: ${classification}`);
|
|
482
|
+
});
|
|
724
483
|
```
|
|
725
484
|
|
|
726
|
-
### Test Coverage
|
|
727
|
-
- **Unit Tests**: 95%+ code coverage
|
|
728
|
-
- **Integration Tests**: End-to-end functionality
|
|
729
|
-
- **Performance Tests**: Benchmarking and optimization
|
|
730
|
-
- **Error Handling Tests**: Comprehensive error scenarios
|
|
731
|
-
|
|
732
|
-
### Quality Metrics
|
|
733
|
-
```javascript
|
|
734
|
-
// Run performance benchmarks
|
|
735
|
-
npm run benchmark
|
|
736
|
-
|
|
737
|
-
// Lint code
|
|
738
|
-
npm run lint
|
|
739
|
-
|
|
740
|
-
// Format code
|
|
741
|
-
npm run format
|
|
742
|
-
|
|
743
|
-
// Generate documentation
|
|
744
|
-
npm run docs
|
|
745
|
-
```
|
|
746
|
-
|
|
747
|
-
---
|
|
748
|
-
|
|
749
|
-
## ๐ Performance Notes
|
|
750
|
-
|
|
751
|
-
### v2.0 Performance Improvements
|
|
752
|
-
- **Caching System**: 85%+ hit rate for repeated operations
|
|
753
|
-
- **Batch Processing**: 3-5x faster for large datasets
|
|
754
|
-
- **Memory Optimization**: 40% reduction in memory usage
|
|
755
|
-
- **Error Recovery**: 60% faster error handling
|
|
756
|
-
|
|
757
|
-
### Complexity Analysis
|
|
758
|
-
- **LaTeX Conversion**: O(n) where n = expression complexity
|
|
759
|
-
- **Function Evaluation**: O(m) where m = function depth
|
|
760
|
-
- **Batch Operations**: O(k) where k = number of expressions
|
|
761
|
-
- **Cache Operations**: O(1) average case
|
|
762
|
-
|
|
763
|
-
### Performance Best Practices
|
|
764
|
-
1. Use cached functions for repeated conversions
|
|
765
|
-
2. Enable batch processing for multiple expressions
|
|
766
|
-
3. Monitor performance stats regularly
|
|
767
|
-
4. Clear caches when memory is constrained
|
|
768
|
-
5. Use validation before expensive operations
|
|
769
|
-
|
|
770
485
|
---
|
|
771
486
|
|
|
772
487
|
## ๐๏ธ Project Structure
|
|
@@ -774,87 +489,62 @@ npm run docs
|
|
|
774
489
|
### Core Modules
|
|
775
490
|
```
|
|
776
491
|
slang-math/
|
|
492
|
+
โโโ slang-math.js # Central exports only
|
|
777
493
|
โโโ slang-basic.js # Core SLaNg structures
|
|
494
|
+
โโโ slang-extended.js # Advanced mathematical functions
|
|
778
495
|
โโโ slang-convertor.js # LaTeX conversion system
|
|
779
|
-
โโโ slang-
|
|
780
|
-
โโโ slang-
|
|
781
|
-
|
|
782
|
-
โโโ slang-
|
|
783
|
-
|
|
784
|
-
โโโ slang-cache.js # Performance & caching
|
|
785
|
-
```
|
|
786
|
-
|
|
787
|
-
### Documentation
|
|
788
|
-
```
|
|
789
|
-
โโโ explaination/ # Detailed function explanations
|
|
790
|
-
โ โโโ SLaNg-Converter/
|
|
791
|
-
โ โโโ SLaNg-Basic/
|
|
792
|
-
โ โโโ SLaNg-Advanced/
|
|
793
|
-
โ โโโ SLaNg-Helpers/
|
|
794
|
-
โโโ docs/ # Generated documentation
|
|
795
|
-
โโโ README.md # This file
|
|
796
|
-
```
|
|
797
|
-
|
|
798
|
-
### Testing
|
|
799
|
-
```
|
|
800
|
-
โโโ tests/
|
|
801
|
-
โ โโโ unit/ # Unit tests
|
|
802
|
-
โ โโโ integration/ # Integration tests
|
|
803
|
-
โ โโโ performance/ # Performance benchmarks
|
|
804
|
-
โโโ experiments/ # Experimental features
|
|
496
|
+
โโโ slang-advanced.js # Advanced algorithms
|
|
497
|
+
โโโ slang-helpers.js # Utility functions
|
|
498
|
+
โโโ experiments/ # Test suite
|
|
499
|
+
โโโ slang-extended-test.js # Comprehensive testing
|
|
500
|
+
โโโ test-converter.js # Converter testing
|
|
805
501
|
```
|
|
806
502
|
|
|
807
503
|
---
|
|
808
504
|
|
|
809
|
-
## ๐ฅ What Makes SLaNg
|
|
505
|
+
## ๐ฅ What Makes SLaNg Special?
|
|
810
506
|
|
|
811
|
-
โจ **Complete
|
|
812
|
-
๐งฎ **
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
๐ **Educational Focus** - See the math, not just the answer
|
|
507
|
+
โจ **Complete Multivariable Calculus** - Tangent planes, gradients, optimization
|
|
508
|
+
๐งฎ **Advanced Mathematical Functions** - Surface analysis, constrained optimization
|
|
509
|
+
๐ **Professional Code Organization** - Clean modular structure
|
|
510
|
+
๐ **LaTeX Integration** - Bidirectional conversion with validation
|
|
511
|
+
๐งช **Comprehensive Testing** - 10 test categories with full coverage
|
|
512
|
+
๐ **Educational Focus** - See the math, not just the answer
|
|
513
|
+
๐ **Production Ready** - Robust error handling and performance
|
|
819
514
|
|
|
820
515
|
---
|
|
821
516
|
|
|
822
|
-
##
|
|
517
|
+
## ๐ค Contributing
|
|
823
518
|
|
|
824
|
-
|
|
825
|
-
- **None!** Full backward compatibility maintained
|
|
826
|
-
- All v1.x code works unchanged in v2.0
|
|
519
|
+
We welcome contributions from the community! Whether you're fixing bugs, adding features, improving documentation, or sharing ideas, your help makes SLaNg better for everyone.
|
|
827
520
|
|
|
828
|
-
###
|
|
829
|
-
```javascript
|
|
830
|
-
// v1.x code still works:
|
|
831
|
-
const f = createFraction([createTerm(1, {x:1})], 1); // โ
|
|
832
|
-
const fPrime = differentiateFraction(f, 'x'); // โ
|
|
833
|
-
|
|
834
|
-
// v2.0 adds powerful new capabilities:
|
|
835
|
-
const latex = slangToLatex(f); // ๐ LaTeX conversion
|
|
836
|
-
const parsed = latexToSlang('\\frac{x}{x+1}'); // ๐ LaTeX parsing
|
|
837
|
-
const sinExpr = createFunction('sin', [createTerm(1, {x:1})]); // ๐ Functions
|
|
838
|
-
const cached = cachedLatexToSlang(latex); // ๐ Performance
|
|
839
|
-
```
|
|
521
|
+
### ๐ฏ How to Contribute
|
|
840
522
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
4. **Optional**: Enable performance monitoring
|
|
523
|
+
#### ๐ Report Bugs
|
|
524
|
+
- Found an issue? [Open a bug report](https://github.com/yourusername/slang-math/issues)
|
|
525
|
+
- Include: description, steps to reproduce, expected vs actual behavior
|
|
526
|
+
- Add code examples and error messages
|
|
846
527
|
|
|
847
|
-
|
|
528
|
+
#### ๐ก Request Features
|
|
529
|
+
- Have an idea? [Open a feature request](https://github.com/yourusername/slang-math/issues)
|
|
530
|
+
- Describe the use case and why it would be valuable
|
|
531
|
+
- Consider if it fits the library's scope and goals
|
|
848
532
|
|
|
849
|
-
|
|
533
|
+
#### ๐ง Submit Pull Requests
|
|
534
|
+
1. Fork the repository
|
|
535
|
+
2. Create a feature branch: `git checkout -b feature/amazing-feature`
|
|
536
|
+
3. Make your changes with clear, documented code
|
|
537
|
+
4. Add tests for new functionality
|
|
538
|
+
5. Ensure all tests pass: `npm test`
|
|
539
|
+
6. Submit a pull request with a clear description
|
|
850
540
|
|
|
851
|
-
|
|
852
|
-
-
|
|
853
|
-
-
|
|
854
|
-
-
|
|
855
|
-
-
|
|
541
|
+
#### ๐ Improve Documentation
|
|
542
|
+
- Fix typos or unclear explanations
|
|
543
|
+
- Add examples and use cases
|
|
544
|
+
- Improve API documentation
|
|
545
|
+
- Create tutorials and guides
|
|
856
546
|
|
|
857
|
-
### Development Setup
|
|
547
|
+
### ๐ ๏ธ Development Setup
|
|
858
548
|
```bash
|
|
859
549
|
# Clone repository
|
|
860
550
|
git clone https://github.com/yourusername/slang-math.git
|
|
@@ -866,22 +556,78 @@ npm install
|
|
|
866
556
|
# Run tests
|
|
867
557
|
npm test
|
|
868
558
|
|
|
559
|
+
# Run specific test suites
|
|
560
|
+
node experiments/slang-extended-test.js
|
|
561
|
+
node experiments/test-converter.js
|
|
562
|
+
|
|
869
563
|
# Start development
|
|
870
564
|
npm run dev
|
|
871
565
|
```
|
|
872
566
|
|
|
873
|
-
###
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
567
|
+
### ๐ Contribution Guidelines
|
|
568
|
+
|
|
569
|
+
#### Code Style
|
|
570
|
+
- Use clear, descriptive variable names
|
|
571
|
+
- Add JSDoc comments for new functions
|
|
572
|
+
- Follow existing code patterns and structure
|
|
573
|
+
- Keep functions focused and modular
|
|
574
|
+
|
|
575
|
+
#### Testing
|
|
576
|
+
- Add tests for all new functionality
|
|
577
|
+
- Ensure 95%+ test coverage
|
|
578
|
+
- Test edge cases and error conditions
|
|
579
|
+
- Include performance tests for significant changes
|
|
580
|
+
|
|
581
|
+
#### Documentation
|
|
582
|
+
- Update README for major features
|
|
583
|
+
- Add inline code comments
|
|
584
|
+
- Include examples in function documentation
|
|
585
|
+
- Update API reference as needed
|
|
586
|
+
|
|
587
|
+
### ๐ฏ Current Priorities
|
|
588
|
+
We're looking for help with:
|
|
589
|
+
|
|
590
|
+
1. **๐ข Matrix Operations** - Linear algebra functions
|
|
591
|
+
2. **โ๏ธ Symbolic Equation Solving** - Root finding and solving systems
|
|
592
|
+
3. **๐ Advanced Integration** - More numerical integration techniques
|
|
593
|
+
4. **๐ Web Interface** - Interactive visualization tools
|
|
594
|
+
5. **๐ TypeScript Definitions** - Better IDE support
|
|
595
|
+
6. **๐งช Performance Optimization** - Speed improvements
|
|
596
|
+
7. **๐ Educational Content** - Tutorials and examples
|
|
597
|
+
8. **๐ Validation System** - Enhanced input validation
|
|
598
|
+
|
|
599
|
+
### ๐ฌ Get Involved
|
|
600
|
+
|
|
601
|
+
#### ๐ฃ๏ธ Discussion
|
|
602
|
+
- Join our [GitHub Discussions](https://github.com/yourusername/slang-math/discussions)
|
|
603
|
+
- Ask questions, share ideas, get help
|
|
604
|
+
- Participate in planning and design discussions
|
|
605
|
+
|
|
606
|
+
#### ๐ข Share Your Work
|
|
607
|
+
- Show us what you're building with SLaNg
|
|
608
|
+
- Share examples and use cases
|
|
609
|
+
- Contribute to our collection of demos
|
|
610
|
+
|
|
611
|
+
#### ๐ Recognition
|
|
612
|
+
- All contributors are credited in our contributors list
|
|
613
|
+
- Significant contributions are highlighted in release notes
|
|
614
|
+
- Outstanding contributors may be invited as maintainers
|
|
615
|
+
|
|
616
|
+
### ๐ License
|
|
617
|
+
|
|
618
|
+
By contributing to SLaNg, you agree that your contributions will be licensed under the same MIT License as the project.
|
|
879
619
|
|
|
880
620
|
---
|
|
881
621
|
|
|
882
|
-
##
|
|
622
|
+
## ๐ Acknowledgments
|
|
623
|
+
|
|
624
|
+
Special thanks to everyone who has contributed to making SLaNg a powerful mathematical library:
|
|
883
625
|
|
|
884
|
-
|
|
626
|
+
- **Contributors** who fix bugs and add features
|
|
627
|
+
- **Users** who provide feedback and report issues
|
|
628
|
+
- **Educators** who use SLaNg in their teaching
|
|
629
|
+
- **Researchers** who push the boundaries of what's possible
|
|
630
|
+
- **Developers** who build amazing things with SLaNg
|
|
885
631
|
|
|
886
632
|
---
|
|
887
633
|
|
|
@@ -889,31 +635,27 @@ MIT License - use freely in your projects!
|
|
|
889
635
|
|
|
890
636
|
### Getting Started
|
|
891
637
|
- **๐ README**: This file
|
|
892
|
-
-
|
|
893
|
-
-
|
|
894
|
-
- **๐๏ธ ARCHITECTURE**: [ARCHITECTURE.md](ARCHITECTURE.md) - System design
|
|
895
|
-
|
|
896
|
-
### Documentation
|
|
897
|
-
- **๐ Function Explanations**: `explaination/` folder
|
|
898
|
-
- **๐ Conversion Guide**: [CONVERTER-README.md](CONVERTER-README.md)
|
|
899
|
-
- **๐งช Testing Guide**: Run `node experiments/test-converter.js`
|
|
900
|
-
|
|
901
|
-
### Examples & Demos
|
|
902
|
-
- **๐ Quick Demo**: `node slang-convertor.js`
|
|
638
|
+
- **๐งช Run Tests**: `node experiments/slang-extended-test.js`
|
|
639
|
+
- **๐ Conversion Demo**: `node slang-convertor.js`
|
|
903
640
|
- **๐งฎ Extended Demo**: `node slang-extended.js`
|
|
904
|
-
|
|
641
|
+
|
|
642
|
+
### Community
|
|
643
|
+
- **๐ฌ Discussions**: [GitHub Discussions](https://github.com/yourusername/slang-math/discussions)
|
|
644
|
+
- **๐ Report Issues**: [GitHub Issues](https://github.com/yourusername/slang-math/issues)
|
|
645
|
+
- **๐ก Request Features**: [Feature Requests](https://github.com/yourusername/slang-math/issues)
|
|
646
|
+
- **๐ง Pull Requests**: [Contributing Guide](CONTRIBUTING.md)
|
|
905
647
|
|
|
906
648
|
### Development
|
|
907
|
-
- **๐งช
|
|
649
|
+
- **๐งช Test Extended Functions**: `node experiments/slang-extended-test.js`
|
|
650
|
+
- **๐งช Test Converter**: `node experiments/test-converter.js`
|
|
908
651
|
- **๐ Performance**: `npm run benchmark`
|
|
909
|
-
- **๐ Generate Docs**: `npm run docs`
|
|
910
652
|
- **๐ง Lint Code**: `npm run lint`
|
|
911
653
|
|
|
912
654
|
---
|
|
913
655
|
|
|
914
656
|
## ๐ Thank You!
|
|
915
657
|
|
|
916
|
-
**SLaNg
|
|
658
|
+
**SLaNg** represents a powerful approach to symbolic mathematics in JavaScript. Whether you're a student learning multivariable calculus, a researcher needing computational tools, or a developer building educational software, SLaNg provides the power, flexibility, and reliability you need.
|
|
917
659
|
|
|
918
660
|
**Happy Computing! ๐**
|
|
919
661
|
|
|
@@ -922,20 +664,23 @@ MIT License - use freely in your projects!
|
|
|
922
664
|
| Need to... | Use... | File |
|
|
923
665
|
|------------|--------|------|
|
|
924
666
|
| Create polynomial | `polynomial([2,1,0], 'x')` | slang-helpers.js |
|
|
925
|
-
| Create rational | `createFraction(numi, deno)` | slang-
|
|
926
|
-
|
|
|
927
|
-
|
|
|
928
|
-
|
|
|
929
|
-
|
|
|
930
|
-
|
|
|
931
|
-
|
|
|
667
|
+
| Create rational | `createFraction(numi, deno)` | slang-basic.js |
|
|
668
|
+
| Calculate gradient | `gradient(f, ['x','y'])` | slang-extended.js |
|
|
669
|
+
| Find tangent plane | `tangentPlane(f, x0, y0)` | slang-extended.js |
|
|
670
|
+
| Find critical points | `findCriticalPoints(f, ['x','y'])` | slang-extended.js |
|
|
671
|
+
| Lagrange multipliers | `lagrangeMultipliers(f, [g], ['x','y'])` | slang-extended.js |
|
|
672
|
+
| Directional derivative | `directionalDerivative(f, point, dir)` | slang-extended.js |
|
|
673
|
+
| Evaluate | `evaluateFraction(f, {x:3})` | slang-basic.js |
|
|
674
|
+
| Differentiate | `differentiateFraction(f, 'x')` | slang-basic.js |
|
|
675
|
+
| Integrate (numeric) | `numericalIntegrateFraction(...)` | slang-basic.js |
|
|
676
|
+
| Simplify | `simplifyFraction(f)` | slang-basic.js |
|
|
677
|
+
| Convert to LaTeX | `slangToLatex(f)` | slang-convertor.js |
|
|
678
|
+
| Parse LaTeX | `latexToSlang(latex)` | slang-convertor.js |
|
|
932
679
|
|
|
933
680
|
---
|
|
934
681
|
|
|
935
|
-
**
|
|
936
|
-
**
|
|
937
|
-
**Total Lines of Code**: ~2,000+
|
|
938
|
-
**Total Features**: 75+
|
|
682
|
+
**Total Lines of Code**: ~3,000+
|
|
683
|
+
**Total Features**: 85+
|
|
939
684
|
**Dependencies**: 0
|
|
940
685
|
|
|
941
686
|
---
|
|
@@ -944,7 +689,7 @@ MIT License - use freely in your projects!
|
|
|
944
689
|
|
|
945
690
|
**Made with โค๏ธ for the mathematical community**
|
|
946
691
|
|
|
947
|
-
**
|
|
692
|
+
**Advanced multivariable calculus capabilities!** ๐งฎโจ
|
|
948
693
|
|
|
949
694
|
[โญ Star us on GitHub](https://github.com/yourusername/slang-math) โข [๐ Report Bug](https://github.com/yourusername/slang-math/issues) โข [๐ก Request Feature](https://github.com/yourusername/slang-math/issues)
|
|
950
695
|
|