Skip to content

Commit b8b520e

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 7bb72a6 commit b8b520e

15 files changed

Lines changed: 500 additions & 292 deletions

‎BREAKING-CHANGES.md‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ the right shape, written out or once its operations are carried out, throws `Inv
451451
products.** An unknown name followed by a bracket is a product, so `zeta(2)` was `zeta * 2` and simplified to
452452
`2 * zeta`. The long names of the functions the library is to have are refused until each is implemented, as `trunc`
453453
is: `zeta`, `riemannzeta`, `hurwitzzeta`, `lambertw`, `productlog`, `harmonicnumber`, `catalannumber`, `multinomial`, `fallingfactorial`, `factorialpower`,
454-
`risingfactorial`, `forwarddifference`, `laplacian`, `jacobian` and `hessian`. Names that will not be functions,
454+
`risingfactorial` and `forwarddifference`. Names that will not be functions,
455455
because what they mean differs between sources or is already written exactly, are refused with the spelling to use:
456456
`heaviside`, `unitstep`, `isprime`, `pochhammer`, `doublefactorial`, `factorial2`, `fractionalpart` and `quotient`.
457457
Each name without a bracket is still a variable, and short names such as `beta` and `norm` are still read as products
@@ -481,6 +481,24 @@ elsewhere. `primepi(x)` counts the primes at most the real number `x`
481481
| `"primeomega(12)".ToEntity().Simplify()` | `12 * primeomega` | `3` |
482482
| `"primepi(10)".ToEntity().Evaled` | `primepi * 10` | `4` |
483483
| `"mobius(0)".ToEntity().Simplify()` | `0` | `NaN` |
484+
485+
### The Laplacian, the Jacobian and the Hessian
486+
487+
**Not silent: `laplacian(f, x)`, `jacobian(F, x)` and `hessian(f, x)` are now computed into derivatives, where they were
488+
read as products or, with two arguments, were a parse error.** They are taken in the variables listed as a vector,
489+
`[x, y, z]`, or in one variable. `laplacian` is the sum of the second derivatives of a scalar function. `jacobian` is the
490+
matrix with a row for each component of `F` and a column for each variable. `hessian` is the matrix of the second
491+
derivatives, the entry in row `i` and column `j` being the derivative in `x_i` of the derivative in `x_j`. Like `det`
492+
they are computed when parsed and have no node: the result is made of `derivative` nodes, evaluated as any derivative
493+
is ([#2182](https://github.com/asc-community/AngouriMath/issues/2182)).
494+
495+
| Input | Was (2.6.0) | Now |
496+
|---|---|---|
497+
| `"laplacian(x^2 y + y^3, [x, y])".ToEntity().Simplify()` | throws `UnhandledParseException` | `8 * y` |
498+
| `"jacobian([x y, x + y], [x, y])".ToEntity().Simplify()` | throws `UnhandledParseException` | `[[y, x], [1, 1]]` |
499+
| `"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]]` |
500+
| `"jacobian(x y, {x, y})".ToEntity()` | throws `UnhandledParseException` | throws `InvalidArgumentParseException`: a set has no order for the columns |
501+
484502
### A subscript may have a subscript
485503

486504
**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
@@ -808,3 +808,6 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
808808

809809
[Tests/UnitTests/Convenience/NumberTheoryFunctionsTest.cs]
810810
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
811+
812+
[Tests/UnitTests/Convenience/VectorCalculusTest.cs]
813+
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
@@ -653,6 +653,9 @@ atom returns[Entity value]
653653
| 'transpose(' args = function_arguments ')' { Assert("transpose", 1, $args.list.Count); $value = ParsingHelpers.Transposed($args.list[0]); }
654654
| 'dot(' args = function_arguments ')' { Assert("dot", 2, $args.list.Count); $value = ParsingHelpers.Dot($args.list[0], $args.list[1]); }
655655
| 'cross(' args = function_arguments ')' { Assert("cross", (1, 2), $args.list.Count); $value = ParsingHelpers.Cross($args.list); }
656+
| 'laplacian(' args = function_arguments ')' { Assert("laplacian", 2, $args.list.Count); $value = ParsingHelpers.Laplacian($args.list[0], $args.list[1]); }
657+
| 'jacobian(' args = function_arguments ')' { Assert("jacobian", 2, $args.list.Count); $value = ParsingHelpers.Jacobian($args.list[0], $args.list[1]); }
658+
| 'hessian(' args = function_arguments ')' { Assert("hessian", 2, $args.list.Count); $value = ParsingHelpers.Hessian($args.list[0], $args.list[1]); }
656659
| 'resultant(' args = function_arguments ')' { Assert("resultant", 3, $args.list.Count); $value = ParsingHelpers.Resultant($args.list[0], $args.list[1], $args.list[2]); }
657660
/* The complex conjugate, by its name and by the shorter one other systems use.
658661
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
@@ -191,6 +191,9 @@ null
191191
'transpose('
192192
'dot('
193193
'cross('
194+
'laplacian('
195+
'jacobian('
196+
'hessian('
194197
'resultant('
195198
'conjugate('
196199
'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: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -426,32 +426,32 @@ WS=237
426426
'transpose('=189
427427
'dot('=190
428428
'cross('=191
429-
'resultant('=192
430-
'conjugate('=193
431-
'conj('=194
432-
'arg('=195
433-
'Re('=196
434-
'Im('=197
435-
're('=198
436-
'real('=199
437-
'im('=200
438-
'imag('=201
439-
'trunc('=202
440-
'zeta('=203
441-
'riemannzeta('=204
442-
'hurwitzzeta('=205
443-
'lambertw('=206
444-
'productlog('=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
429+
'laplacian('=192
430+
'jacobian('=193
431+
'hessian('=194
432+
'resultant('=195
433+
'conjugate('=196
434+
'conj('=197
435+
'arg('=198
436+
'Re('=199
437+
'Im('=200
438+
're('=201
439+
'real('=202
440+
'im('=203
441+
'imag('=204
442+
'trunc('=205
443+
'zeta('=206
444+
'riemannzeta('=207
445+
'hurwitzzeta('=208
446+
'lambertw('=209
447+
'productlog('=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)