Skip to content

Commit 0e11fd0

Browse files
arnogclaude
andauthored
Add cyclic integration patterns for e^x with trigonometric functions (#276)
* feat: add cyclic e^x*trig integration patterns Add support for integrating e^x*sin(x), e^x*cos(x), and their linear argument variants e^x*sin(ax), e^x*cos(ax), e^x*sin(ax+b), e^x*cos(ax+b). These patterns require the "solve for the integral" technique as standard integration by parts leads to infinite recursion. - Add tryCyclicExpTrigIntegral() function for direct detection - Add INTEGRATION_RULES patterns for matching various forms - Add tests for e^x*sin(x), e^x*cos(x), e^x*sin(2x), e^x*cos(2x) - Add tests for x^2*e^x, x*ln(x), sec(x), csc(x) https://claude.ai/code/session_01PpXCWRd3awYVikU5ErVA68 * build: update generated files https://claude.ai/code/session_01PpXCWRd3awYVikU5ErVA68 * Delete src/api.md * feat(logic): implement comprehensive boolean simplification rules - Added absorption rules for conjunction and disjunction: - A ∧ (A ∨ B) → A - A ∨ (A ∧ B) → A - Implemented idempotence, complementation, identity, domination, and double negation simplifications. - Updated logic-utils.ts with new functions for absorption. - Enhanced logic.test.ts with extensive tests for all new simplification rules. * feat(logic): implement Quine-McCluskey algorithm for prime implicants and implicates with minimal DNF/CNF conversion * chore --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9fae900 commit 0e11fd0

10 files changed

Lines changed: 1700 additions & 9297 deletions

File tree

CHANGELOG.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,47 @@
312312
This uses u-substitution: since `1/x = d/dx(ln(x))`, the integral becomes
313313
`∫ h'(x)/h(x) dx = ln|h(x)|`.
314314

315+
#### Logic
316+
317+
- **Boolean Simplification Rules**: Added absorption laws and improved boolean
318+
expression simplification:
319+
- **Absorption**: `A ∧ (A ∨ B) → A` and `A ∨ (A ∧ B) → A`
320+
- **Idempotence**: `A ∧ A → A` and `A ∨ A → A`
321+
- **Complementation**: `A ∧ ¬A → False` and `A ∨ ¬A → True`
322+
- **Identity**: `A ∧ True → A` and `A ∨ False → A`
323+
- **Domination**: `A ∧ False → False` and `A ∨ True → True`
324+
- **Double negation**: `¬¬A → A`
325+
326+
These rules are applied automatically during simplification:
327+
```javascript
328+
ce.box(['And', 'A', ['Or', 'A', 'B']]).simplify(); // → A
329+
ce.box(['Or', 'A', ['And', 'A', 'B']]).simplify(); // → A
330+
```
331+
332+
- **Prime Implicants and Minimal Normal Forms**: Added Quine-McCluskey algorithm
333+
for finding prime implicants/implicates and computing minimal CNF/DNF:
334+
- `PrimeImplicants(expr)` - Find all prime implicants (minimal product terms)
335+
- `PrimeImplicates(expr)` - Find all prime implicates (minimal sum clauses)
336+
- `MinimalDNF(expr)` - Convert to minimal DNF using prime implicant cover
337+
- `MinimalCNF(expr)` - Convert to minimal CNF using prime implicate cover
338+
339+
```javascript
340+
// Find prime implicants (terms that can't be further simplified)
341+
ce.box(['PrimeImplicants', ['Or', ['And', 'A', 'B'], ['And', 'A', ['Not', 'B']]]]).evaluate();
342+
// → [A] (AB and A¬B combine to just A)
343+
344+
// Compute minimal DNF
345+
ce.box(['MinimalDNF', ['Or',
346+
['And', 'A', 'B'],
347+
['And', 'A', ['Not', 'B']],
348+
['And', ['Not', 'A'], 'B']
349+
]]).evaluate();
350+
// → A ∨ B (simplified from 3 terms to 2)
351+
```
352+
353+
Limited to 12 variables to prevent exponential blowup; larger expressions
354+
return unevaluated.
355+
315356
#### Linear Algebra
316357

317358
- **Matrix Decompositions**: Added four matrix decomposition functions for

requirements/DONE.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,108 @@ ce.box(['Eigen', ['List', ['List', 4, 2], ['List', 1, 3]]]).evaluate();
435435

436436
---
437437

438+
## Logic Enhancements (Completed)
439+
440+
### L-1. Logic Simplification Rules ✅
441+
442+
**IMPLEMENTED:** Added comprehensive boolean simplification rules:
443+
444+
1. **Absorption** (NEW):
445+
- `A ∧ (A ∨ B) → A`
446+
- `A ∨ (A ∧ B) → A`
447+
448+
2. **Idempotence** (already implemented):
449+
- `A ∧ A → A`
450+
- `A ∨ A → A`
451+
452+
3. **Complementation** (already implemented):
453+
- `A ∧ ¬A → False`
454+
- `A ∨ ¬A → True`
455+
456+
4. **Identity** (already implemented):
457+
- `A ∧ True → A`
458+
- `A ∨ False → A`
459+
460+
5. **Domination** (already implemented):
461+
- `A ∧ False → False`
462+
- `A ∨ True → True`
463+
464+
6. **Double negation** (already implemented via involution):
465+
- `¬¬A → A`
466+
467+
**Examples:**
468+
```typescript
469+
ce.box(['And', 'A', ['Or', 'A', 'B']]).simplify(); // → A
470+
ce.box(['Or', 'A', ['And', 'A', 'B']]).simplify(); // → A
471+
ce.box(['And', 'A', 'A']).simplify(); // → A
472+
ce.box(['And', 'A', ['Not', 'A']]).simplify(); // → False
473+
ce.box(['Or', 'A', ['Not', 'A']]).simplify(); // → True
474+
ce.box(['Not', ['Not', 'A']]).simplify(); // → A
475+
```
476+
477+
**Files modified:**
478+
- `src/compute-engine/library/logic-utils.ts` - Added `applyAbsorptionAnd` and `applyAbsorptionOr` functions
479+
- `test/compute-engine/logic.test.ts` - Added "Logic Simplification Rules" describe block with 18 new tests
480+
481+
---
482+
483+
### L-2. Prime Implicants/Implicates (Quine-McCluskey) ✅
484+
485+
**IMPLEMENTED:** Added functions for finding prime implicants/implicates and
486+
computing minimal normal forms using the Quine-McCluskey algorithm:
487+
488+
1. **`PrimeImplicants(expr)`** - Find all prime implicants (minimal product terms):
489+
```typescript
490+
ce.box(['PrimeImplicants', ['Or', ['And', 'A', 'B'], ['And', 'A', ['Not', 'B']]]]).evaluate();
491+
// → [A] (AB and A¬B combine to just A)
492+
493+
ce.box(['PrimeImplicants', ['Or', 'A', 'B']]).evaluate();
494+
// → [A, B] (two prime implicants)
495+
```
496+
497+
2. **`PrimeImplicates(expr)`** - Find all prime implicates (minimal sum clauses):
498+
```typescript
499+
ce.box(['PrimeImplicates', ['And', 'A', 'B']]).evaluate();
500+
// → [A, B] (the expression implies both A and B)
501+
502+
ce.box(['PrimeImplicates', ['Or', 'A', 'B']]).evaluate();
503+
// → [A ∨ B] (single prime implicate)
504+
```
505+
506+
3. **`MinimalDNF(expr)`** - Convert to minimal Disjunctive Normal Form:
507+
```typescript
508+
ce.box(['MinimalDNF', ['Or',
509+
['And', 'A', 'B'],
510+
['And', 'A', ['Not', 'B']],
511+
['And', ['Not', 'A'], 'B']
512+
]]).evaluate();
513+
// → A ∨ B (simplified from 3 terms to 2 prime implicants)
514+
```
515+
516+
4. **`MinimalCNF(expr)`** - Convert to minimal Conjunctive Normal Form:
517+
```typescript
518+
ce.box(['MinimalCNF', ['And', ['Or', 'A', 'B'], ['Or', 'A', ['Not', 'B']]]]).evaluate();
519+
// → A (simplified to single literal)
520+
```
521+
522+
**Algorithm:** Quine-McCluskey with greedy covering:
523+
1. Generate minterms (for DNF) or maxterms (for CNF) from truth table
524+
2. Iteratively combine terms differing in exactly one variable
525+
3. Identify essential prime implicants
526+
4. Use greedy algorithm to find minimal cover
527+
528+
**Performance:**
529+
- O(3^n) worst case complexity
530+
- Limited to 12 variables to prevent exponential blowup
531+
- Expressions with more variables return unevaluated
532+
533+
**Files modified:**
534+
- `src/compute-engine/library/logic-analysis.ts` - Implemented Quine-McCluskey algorithm
535+
- `src/compute-engine/library/logic.ts` - Added 4 new function definitions
536+
- `test/compute-engine/logic.test.ts` - Added 17 new tests in "Prime Implicants and Minimal Forms" describe block
537+
538+
---
539+
438540
## Medium Priority (Completed)
439541

440542
### 9. Implicit Multiplication Between `\exp` Function Calls ✅

0 commit comments

Comments
 (0)