Skip to content

A value put in for a derivative's variable is where it is evaluated - #2199

Merged
Rafael-SOWNet merged 3 commits into
masterfrom
a-derivative-is-evaluated-at-the-value-put-in-for-its-variable
Oct 29, 2026
Merged

Rafael-SOWNet merged 3 commits into
masterfrom
a-derivative-is-evaluated-at-the-value-put-in-for-its-variable

Conversation

@Rafael-SOWNet

@Rafael-SOWNet Rafael-SOWNet commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Fixes #2189. A value put in for the variable of a derivative or an indefinite integral was dropped. That variable is free, since the derivative is a function of it, so substituting and then evaluating gave a different answer from evaluating and then substituting.

Input Was (2.6.0) Now
"derivative(x^3, x)".ToEntity().Substitute("x", 1).Evaled 3 * x ^ 2 3
"integral(x^2, x)".ToEntity().Substitute("x", 1).Evaled x ^ 3 / 3 + C 1/3 + C
"derivative(a x^2, x)".ToEntity().Substitute("a", "x").Evaled 2 * x_1 * x 2 * x * x
"derivative(x^3, x)".ToEntity().Substitute("x", 1) derivative(x ^ 3, x) apply(lambda(x, derivative(x ^ 3, x)), 1)

What changes:

  • Substitute writes a value for that variable as apply(lambda(x, …), v), the derivative evaluated at v. It still computes nothing.
  • A variable the body does not hold is a renaming, and renames the derivative's variable: derivative(x^3, x) with x := y is derivative(y^3, y). A lambda renaming its own parameter substitutes exactly such a variable, so wrapping it in another apply would never terminate.
  • Values that hold the variable go in under a fresh variable, and the derivative is evaluated at that variable. Before, the renamed variable was left free.
  • Application takes a derivative or indefinite integral in the lambda's parameter before putting the argument in. Every other body is still substituted first, as Applying a lambda to a vector treats the vector as a number #2132 needs. That order had also made apply(lambda(x, derivative(x^3, x)), 1) give 3 x^2 on master, where 2.6.0 gave 3.
  • A derivative the library cannot take, such as that of primepi(x), keeps the application unevaluated.

The definite integral, sum, product and limit bind their variable and are unchanged. Two rows of SubstituteTest pinned the dropped value, and now read 1 * apply(lambda(x, derivative(x + 2, x)), 1).

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

Substitute treated the variable of a derivative and of an indefinite integral as bound, and a value
put in for it was dropped: derivative(x^3, x) at x = 1 evaluated to 3 x^2, and integral(x^2, x) at
x = 1 to x^3/3 + C. That variable is free, the derivative being a function of it, as FreeVariables
already counted it since #1045. Substituting and evaluating did not commute.

A value for it now makes apply(lambda(x, derivative(f, x)), v), the derivative evaluated at v, in
syntax the library already has, so Substitute still computes nothing. Applying a lambda whose body
is a derivative or an indefinite integral in its parameter takes that body first and then puts the
argument in. Every other body is substituted before it is simplified, as #2132 needs. That order had
made apply(lambda(x, derivative(x^3, x)), 1) 3 x^2 as well, where 2.6.0 gave 3. A derivative the
library does not take, such as that of primepi(x), keeps the application unevaluated rather than
being taken again.

A value that holds the variable, a := x in derivative(a x^2, x), was put in under a renamed variable
that was then left free: derivative(x x_1^2, x_1), which is 2 x_1 x. It now goes in under a fresh
variable at which the derivative is evaluated, and comes to 2 x^2, the derivative 2 a x with a put
in. A definite integral, a sum, a product and a limit bind their variable, and are unchanged.

Two rows of SubstituteTest pinned the dropped value, x * derivative(x + 2, x) at x = 1 as
1 * derivative(x + 2, x); they now read 1 * apply(lambda(x, derivative(x + 2, x)), 1).

Fixes #2189.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
@Rafael-SOWNet Rafael-SOWNet moved this from Todo to In review in AngouriMath Oct 29, 2026
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.55%. Comparing base (c05a452) to head (8e85a00).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2199      +/-   ##
==========================================
- Coverage   86.55%   86.55%   -0.01%     
==========================================
  Files         298      298              
  Lines       66529    66554      +25     
  Branches    19300    19308       +8     
==========================================
+ Hits        57582    57603      +21     
- Misses       4872     4876       +4     
  Partials     4075     4075              
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.10% <100.00%> (-0.01%) ⬇️
fsharp 32.97% <ø> (ø)
interactive 40.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...luation/Evaluation.Omni/Evaluation.Omni.Classes.cs 89.63% <100.00%> (+0.48%) ⬆️
Sources/AngouriMath/Functions/Substitute.cs 84.32% <100.00%> (+1.58%) ⬆️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Rafael-SOWNet and others added 2 commits October 29, 2026 11:45
A variable the body does not hold is a renaming, and renames the derivative's variable:
derivative(x^3, x) with x := y is derivative(y^3, y). That is what a lambda renaming its parameter
puts in, and wrapped in a lambda over the old name instead it would be renamed again without end.

Part of #2189.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
…luated-at-the-value-put-in-for-its-variable

# Conflicts:
#	Sources/.editorconfig
@Rafael-SOWNet
Rafael-SOWNet merged commit 533ee4f into master Oct 29, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Oct 29, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the a-derivative-is-evaluated-at-the-value-put-in-for-its-variable branch October 29, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Substituting for a derivative's variable is dropped: derivative(x^3, x) at x = 1 evaluates to 3 x^2

1 participant