Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,57 @@ A not-equal written `<>` is read as `not (a = b)`, and printed that way.

## Unreleased — since 2.7.0

### A value for a variable a derivative is taken over goes into its answer

**Silent: a wrong value is corrected.** A derivative or an indefinite integral over an expression `u` of `x`, such as
`derivative(x^3, x^2)`, is taken by letting `x` move. `Substitute("x", 2)` put the value into the expression alone, which
asked another question: `derivative(8, x^2)`, which is 0. It now takes the derivative first and puts the value into the
answer, and where it cannot be taken holds the value outside, as `apply(lambda(x, ...), 2)`. Over a variable nothing
changes: `derivative(x * y, y)` at `x = 2` is `derivative(2 * y, y)`, as before
([#230](https://github.com/asc-community/AngouriMath/issues/230)). Substituted, then with `Simplify`:

| Input, at `x = 2` | Was (2.7.0) | Now |
|---|---|---|
| `derivative(x^3, x^2)` | `0` | `3` |
| `derivative(y * sin(x), cos(x))` | `0` | `-y * csc(2) * cos(2)` |
| `derivative(sin(x!), x^2)` | `0` | `cos(2) * (3/2 - eulergamma) / 2` |
| `integral(x, x^2)` | `C + 2 * x ^ 2` | `16/3 + C` |
| `derivative(x^2 + y, x + y)` | `derivative(4 + y, x + y)` | `apply(lambda(x, derivative(x ^ 2 + y, x + y)), 2)` |
| `derivative(x * apply(f, x)^2, apply(f, x))` | `derivative(2 * apply(f, 2) ^ 2, apply(f, x))` | `4 * apply(f, 2) + apply(f, 2) ^ 2 / apply(lambda(x, derivative(apply(f, x), x)), 2)` |

### The total derivative in an unknown function of a variable is answered

**Not silent: what was left unevaluated is answered.** `derivative(expr, u)` over an expression `u` that varies in
one variable `x` is the total derivative, `(d expr/dx) / (du/dx)`, and it declined where `u` was an unknown function
applied, `apply(f, x)`, or the derivative of one, and `expr` was not written in `u` alone. It is answered now, defined
where `du/dx ≠ 0`; an answer from before does not change, and over two variables, `derivative(x + y, x * y)`, it is
still left as written ([#230](https://github.com/asc-community/AngouriMath/issues/230)). With `Simplify`, `f` standing
for `apply(f, x)`:

| Input | Was (2.7.0) | Now |
|---|---|---|
| `derivative(x * f, f)` | `derivative(x * apply(f, x), apply(f, x))` | `apply(f, x) / derivative(apply(f, x), x) + x` |
| `derivative(f^2 + derivative(f, x)^2, f)` | left as written | `2 * (apply(f, x) + derivative(apply(f, x), x, 2)) provided not derivative(apply(f, x), x) = 0` |
| `derivative(f^2 * derivative(f, x), f)` | left as written | `apply(f, x) ^ 2 * derivative(apply(f, x), x, 2) / derivative(apply(f, x), x) + 2 * apply(f, x) * derivative(apply(f, x), x)` |
| `derivative(x * f, derivative(f, x))` | left as written | `(apply(f, x) + x * derivative(apply(f, x), x)) / derivative(apply(f, x), x, 2)` |

### A partial derivative: `partialderivative(expr, q)`

**Not silent: what was refused now parses.** `partialderivative(L, q)` and `partialderivative(L, q, n)` threw
`UnhandledParseException`, and `partialderivative(x)`, with one argument, was the product `partialderivative * x`. It
is now the node `PartialDerivativef`, the partial derivative `∂L/∂q`, built by `MathS.PartialDerivative(L, q)` and drawn
`\frac{\partial}{\partial q}`, and one argument throws `FunctionArgumentCountException`. Its `q` is a slot — a variable,
an unknown function applied, or a derivative of one — and the other slots are held fixed, as in the Euler–Lagrange
equation, where `derivative` is the total derivative; over a variable the two agree. Over anything else it is left as
written ([#230](https://github.com/asc-community/AngouriMath/issues/230)). With `Simplify`, `f` standing for
`apply(f, x)`:

| Input | Was (2.7.0) | Now |
|---|---|---|
| `partialderivative(f^2 + derivative(f, x)^2, f)` | throws `UnhandledParseException` | `2 * apply(f, x)` |
| `partialderivative(x * f, f)` | throws `UnhandledParseException` | `x` |
| `"partialderivative(x)".ToEntity()` | `partialderivative * x` | throws `FunctionArgumentCountException` |

### `gcd` and `lcm` compile at whole arguments

**Not silent: what was refused is compiled.** `gcd` and `lcm` were refused by both compilers with
Expand Down
3 changes: 3 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1132,3 +1132,6 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed

[Tests/UnitTests/Convenience/PrimeFactorizationNodeTest.cs]
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

[Tests/UnitTests/Calculus/DerivativeInAFunctionTest.cs]
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
29 changes: 29 additions & 0 deletions Sources/AngouriMath/Convenience/MathS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7764,6 +7764,35 @@ public static class Compute
/// </example>
public static Entity Derivative(Entity expr, Entity var, int power) => new Derivativef(expr, var, power);

/// <summary>
/// Hangs your <see cref="Entity"/> to a partial derivative node, <c>∂expr/∂slot</c>:
/// the derivative in <paramref name="slot"/> with everything else held fixed.
/// </summary>
/// <param name="expr">Expression to be hung</param>
/// <param name="slot">
/// What the derivative is taken in: a variable, an unknown function applied,
/// <c>apply(f, x)</c>, or a derivative of one, <c>derivative(apply(f, x), x)</c>
/// </param>
/// <remarks>
/// <see cref="Derivative(Entity, Entity)"/> is the total derivative. The two agree over a
/// variable, and differ over <c>f(x)</c>: the partial derivative of <c>f^2 + f'^2</c> in
/// <c>f</c> is <c>2f</c>, holding <c>f'</c> fixed as the Euler–Lagrange equation does,
/// and the total derivative is <c>2f + 2f''</c> where <c>f' ≠ 0</c>.
/// </remarks>
public static Entity PartialDerivative(Entity expr, Entity slot) => new PartialDerivativef(expr, slot, 1);

/// <summary>
/// Hangs your <see cref="Entity"/> to a partial derivative node taken
/// <paramref name="power"/> times; see <see cref="PartialDerivative(Entity, Entity)"/>.
/// </summary>
/// <param name="expr">Expression to be hung</param>
/// <param name="slot">What the derivative is taken in</param>
/// <param name="power">Number of times it is taken, at least 1</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="power"/> is less than 1.</exception>
public static Entity PartialDerivative(Entity expr, Entity slot, int power)
=> power >= 1 ? new PartialDerivativef(expr, slot, power)
: throw new ArgumentOutOfRangeException(nameof(power), power, "A partial derivative is taken at least once.");

/// <summary>
/// Hangs your entity to an integral node
/// (to evaluate instead use <see cref="Entity.Integrate(Entity.Variable)"/>)
Expand Down
14 changes: 14 additions & 0 deletions Sources/AngouriMath/Core/Antlr/AngouriMath.g
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,20 @@ atom returns[Entity value]
}
$value = body;
}
/* The partial derivative, beside derivative's total one.
https://github.com/asc-community/AngouriMath/issues/230 */
| 'partialderivative(' args = function_arguments ')'
{
if (Assert("partialderivative", (3, 2), $args.list.Count))
{
if ($args.list[2] is Integer { EInteger: var asEInt } && asEInt.Sign > 0)
$value = MathS.PartialDerivative($args.list[0], $args.list[1], asEInt.ToInt32Checked());
else
throw new InvalidArgumentParseException("Expected a positive integer for the third argument of partialderivative");
}
else
$value = MathS.PartialDerivative($args.list[0], $args.list[1]);
}
;

statement: expression EOF { Result = $expression.value; } ;
Expand Down
4 changes: 3 additions & 1 deletion Sources/AngouriMath/Core/Antlr/AngouriMath.interp

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions Sources/AngouriMath/Core/Antlr/AngouriMath.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,17 @@ T__235=236
T__236=237
T__237=238
T__238=239
NEWLINE=240
NUMBER=241
SPECIALSET=242
BOOLEAN=243
NAN=244
UNICODE_SYNONYM=245
SUPERSCRIPT=246
VARIABLE=247
COMMENT=248
WS=249
T__239=240
NEWLINE=241
NUMBER=242
SPECIALSET=243
BOOLEAN=244
NAN=245
UNICODE_SYNONYM=246
SUPERSCRIPT=247
VARIABLE=248
COMMENT=249
WS=250
'['=1
']'=2
'!'=3
Expand Down Expand Up @@ -486,4 +487,5 @@ WS=249
'piecewise('=237
'apply('=238
'lambda('=239
'NaN'=244
'partialderivative('=240
'NaN'=245
Loading
Loading