Skip to content

Commit 3049a37

Browse files
Rafael-SOWNetclaude
andcommitted
The Laplacian, the Jacobian and the Hessian
laplacian, jacobian and hessian were reserved by name in #2184 and are now computed when they are parsed, as det is. Each is made of derivative nodes and needs no node of its own. laplacian(f, [x, y, z]) is the sum of the second derivatives of a scalar f. jacobian(F, [x, y]) is the matrix of the first derivatives of F's components, with a row for each component and a column for each variable; a scalar F is one row. hessian(f, [x, y]) is the matrix of the second derivatives of a scalar f, the entry in row i and column j being the derivative in x_i of the derivative in x_j, as the definition writes it. The variables are a vector of distinct names written out, or a single name. A set is refused, having no order to give the columns, and so are a constant, a repeated name, and a vector or matrix as the function of a Laplacian or a Hessian. det(jacobian([r cos(t), r sin(t)], [r, t])) simplifies to r, and the Laplacian of 1/r vanishes in space. The syntax page and the MCP server's syntax document describe them, and the native smoke test evaluates two of them. Part of #2182. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent 5e7731f commit 3049a37

15 files changed

Lines changed: 457 additions & 250 deletions

‎BREAKING-CHANGES.md‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ products.** An unknown name followed by a bracket is a product, so `zeta(2)` was
442442
`2 * zeta`. The long names of the functions the library is to have are refused until each is implemented, as `trunc`
443443
is: `zeta`, `riemannzeta`, `hurwitzzeta`, `lambertw`, `productlog`, `mobius`, `moebiusmu`, `divisorsigma`, `primenu`,
444444
`primeomega`, `primepi`, `harmonicnumber`, `catalannumber`, `multinomial`, `fallingfactorial`, `factorialpower`,
445-
`risingfactorial`, `forwarddifference`, `laplacian`, `jacobian` and `hessian`. Names that will not be functions,
445+
`risingfactorial` and `forwarddifference`. Names that will not be functions,
446446
because what they mean differs between sources or is already written exactly, are refused with the spelling to use:
447447
`heaviside`, `unitstep`, `isprime`, `pochhammer`, `doublefactorial`, `factorial2`, `fractionalpart` and `quotient`.
448448
Each name without a bracket is still a variable, and short names such as `beta` and `norm` are still read as products
@@ -455,6 +455,23 @@ Each name without a bracket is still a variable, and short names such as `beta`
455455
| `"isprime(7)".ToEntity()` | `isprime * 7` | throws `UnrecognizedFunctionParseException`: write `n in PP` |
456456
| `"heaviside(x)".ToEntity()` | `heaviside * x` | throws `UnrecognizedFunctionParseException`: write `iverson(x > 0)`, `iverson(x >= 0)` or `(1 + sgn(x))/2` |
457457
| `"divisorsigma(k, n)".ToEntity()` | throws `UnhandledParseException` | throws `UnrecognizedFunctionParseException` |
458+
### The Laplacian, the Jacobian and the Hessian
459+
460+
**Not silent: `laplacian(f, x)`, `jacobian(F, x)` and `hessian(f, x)` are now computed into derivatives, where they were
461+
read as products or, with two arguments, were a parse error.** They are taken in the variables listed as a vector,
462+
`[x, y, z]`, or in one variable. `laplacian` is the sum of the second derivatives of a scalar function. `jacobian` is the
463+
matrix with a row for each component of `F` and a column for each variable. `hessian` is the matrix of the second
464+
derivatives, the entry in row `i` and column `j` being the derivative in `x_i` of the derivative in `x_j`. Like `det`
465+
they are computed when parsed and have no node: the result is made of `derivative` nodes, evaluated as any derivative
466+
is ([#2182](https://github.com/asc-community/AngouriMath/issues/2182)).
467+
468+
| Input | Was (2.6.0) | Now |
469+
|---|---|---|
470+
| `"laplacian(x^2 y + y^3, [x, y])".ToEntity().Simplify()` | throws `UnhandledParseException` | `8 * y` |
471+
| `"jacobian([x y, x + y], [x, y])".ToEntity().Simplify()` | throws `UnhandledParseException` | `[[y, x], [1, 1]]` |
472+
| `"hessian(x^3 y^2, [x, y])".ToEntity().Simplify()` | throws `UnhandledParseException` | `[[6 * x * y ^ 2, 6 * x ^ 2 * y], [6 * x ^ 2 * y, 2 * x ^ 3]]` |
473+
| `"jacobian(x y, {x, y})".ToEntity()` | throws `UnhandledParseException` | throws `InvalidArgumentParseException`: a set has no order for the columns |
474+
458475
### A subscript may have a subscript
459476

460477
**Not silent: what was a parse error is a name.** A name took at most one `_`, so `x_1_2` and `X_a_beta` were lexer

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,3 +805,6 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
805805

806806
[Tests/UnitTests/Common/SimplifyOverASymbolicCommonDenominatorTest.cs]
807807
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
808+
809+
[Tests/UnitTests/Convenience/VectorCalculusTest.cs]
810+
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

‎Sources/AngouriMath/Core/Antlr/AngouriMath.g‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,9 @@ atom returns[Entity value]
647647
| 'transpose(' args = function_arguments ')' { Assert("transpose", 1, $args.list.Count); $value = ParsingHelpers.Transposed($args.list[0]); }
648648
| 'dot(' args = function_arguments ')' { Assert("dot", 2, $args.list.Count); $value = ParsingHelpers.Dot($args.list[0], $args.list[1]); }
649649
| 'cross(' args = function_arguments ')' { Assert("cross", (1, 2), $args.list.Count); $value = ParsingHelpers.Cross($args.list); }
650+
| 'laplacian(' args = function_arguments ')' { Assert("laplacian", 2, $args.list.Count); $value = ParsingHelpers.Laplacian($args.list[0], $args.list[1]); }
651+
| 'jacobian(' args = function_arguments ')' { Assert("jacobian", 2, $args.list.Count); $value = ParsingHelpers.Jacobian($args.list[0], $args.list[1]); }
652+
| 'hessian(' args = function_arguments ')' { Assert("hessian", 2, $args.list.Count); $value = ParsingHelpers.Hessian($args.list[0], $args.list[1]); }
650653
| 'resultant(' args = function_arguments ')' { Assert("resultant", 3, $args.list.Count); $value = ParsingHelpers.Resultant($args.list[0], $args.list[1], $args.list[2]); }
651654
/* The complex conjugate, by its name and by the shorter one other systems use.
652655
https://github.com/asc-community/AngouriMath/issues/2145 */
@@ -694,9 +697,6 @@ atom returns[Entity value]
694697
| 'factorialpower(' args = function_arguments ')' { $value = NotImplementedFunction("factorialpower", "falling factorial yet"); }
695698
| 'risingfactorial(' args = function_arguments ')' { $value = NotImplementedFunction("risingfactorial", "rising factorial yet"); }
696699
| 'forwarddifference(' args = function_arguments ')' { $value = NotImplementedFunction("forwarddifference", "forward difference yet"); }
697-
| 'laplacian(' args = function_arguments ')' { $value = NotImplementedFunction("laplacian", "Laplacian yet"); }
698-
| 'jacobian(' args = function_arguments ')' { $value = NotImplementedFunction("jacobian", "Jacobian yet"); }
699-
| 'hessian(' args = function_arguments ')' { $value = NotImplementedFunction("hessian", "Hessian yet"); }
700700
/* Names that will not be functions, refused with the spelling to use: what they mean is
701701
ambiguous between sources, or is already written exactly another way. */
702702
| 'heaviside(' args = function_arguments ')' { $value = NotAFunctionHere("heaviside", "its value at 0 is 0, 1/2 or 1 by source; write iverson(x > 0), iverson(x >= 0) or (1 + sgn(x))/2"); }

‎Sources/AngouriMath/Core/Antlr/AngouriMath.interp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ null
185185
'transpose('
186186
'dot('
187187
'cross('
188+
'laplacian('
189+
'jacobian('
190+
'hessian('
188191
'resultant('
189192
'conjugate('
190193
'conj('
@@ -214,9 +217,6 @@ null
214217
'factorialpower('
215218
'risingfactorial('
216219
'forwarddifference('
217-
'laplacian('
218-
'jacobian('
219-
'hessian('
220220
'heaviside('
221221
'unitstep('
222222
'isprime('

‎Sources/AngouriMath/Core/Antlr/AngouriMath.tokens‎

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -420,38 +420,38 @@ WS=237
420420
'transpose('=183
421421
'dot('=184
422422
'cross('=185
423-
'resultant('=186
424-
'conjugate('=187
425-
'conj('=188
426-
'arg('=189
427-
'Re('=190
428-
'Im('=191
429-
're('=192
430-
'real('=193
431-
'im('=194
432-
'imag('=195
433-
'trunc('=196
434-
'zeta('=197
435-
'riemannzeta('=198
436-
'hurwitzzeta('=199
437-
'lambertw('=200
438-
'productlog('=201
439-
'mobius('=202
440-
'moebiusmu('=203
441-
'divisorsigma('=204
442-
'primenu('=205
443-
'primeomega('=206
444-
'primepi('=207
445-
'harmonicnumber('=208
446-
'catalannumber('=209
447-
'multinomial('=210
448-
'fallingfactorial('=211
449-
'factorialpower('=212
450-
'risingfactorial('=213
451-
'forwarddifference('=214
452-
'laplacian('=215
453-
'jacobian('=216
454-
'hessian('=217
423+
'laplacian('=186
424+
'jacobian('=187
425+
'hessian('=188
426+
'resultant('=189
427+
'conjugate('=190
428+
'conj('=191
429+
'arg('=192
430+
'Re('=193
431+
'Im('=194
432+
're('=195
433+
'real('=196
434+
'im('=197
435+
'imag('=198
436+
'trunc('=199
437+
'zeta('=200
438+
'riemannzeta('=201
439+
'hurwitzzeta('=202
440+
'lambertw('=203
441+
'productlog('=204
442+
'mobius('=205
443+
'moebiusmu('=206
444+
'divisorsigma('=207
445+
'primenu('=208
446+
'primeomega('=209
447+
'primepi('=210
448+
'harmonicnumber('=211
449+
'catalannumber('=212
450+
'multinomial('=213
451+
'fallingfactorial('=214
452+
'factorialpower('=215
453+
'risingfactorial('=216
454+
'forwarddifference('=217
455455
'heaviside('=218
456456
'unitstep('=219
457457
'isprime('=220

0 commit comments

Comments
 (0)