feat(std/gradient): add Dual for forward-mode differentiation #454
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/83-std-gradient"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #83
What
New package
std/gradientwithDual<Scalar: Real = Float>(forward-mode automatic differentiation) andderivative(of:at:). Pure TorbScript, no foreign function, no dependency onstd/tensor; no change tostd/number,std/linear, the compiler or the VM.DualisSigned,Real,ShowandTryFrom<String>, so any function generic overRealis differentiated unchanged.==,<andcomparelook at the primal part only. Rules, layout and pitfalls are recorded indocs/design/COMPUTE.mdsection 4; the ROADMAP item namesDualas built.Two commits:
feat(std/gradient)anddocs(compute).Deviations from the design in #83 (please check)
rate, nottangent.Realhas a memberfn tangent()and a type has one namespace of members (tangent is already declared in Dual).primalstays. Recorded in COMPUTE.md.From<Scalar>. The checker rejects it as overlapping the blanketFrom<Never>(Dual<Scalar> already implements From<Scalar>).Dual.constant(value)is the conversion; recorded in COMPUTE.md. Filed as #455.Powerwith a constant exponent of zero has rate zero (instead of0 * f ** -1, which isnanatf == 0).nby doubling, sinceRealhas no conversion fromInt.Both optional integration tests of the acceptance criteria work, so nothing is dropped:
Vector2<Dual<Float>>.length()has the expected rate, andDual<Dual<Float>>gives6xforx ** 3(and-sinfor the second derivative ofsin).Test
torb(interpreter):torb test std/gradient28 passed,torb format --check std/gradientclean,torb docs skill docs skills --checkup to date (docs are not part of the skills,skills/unchanged),tools/check-commits.sh origin/main HEADclean.tools/gates.sh a, compiled binary): see the checks of this PR.From<Scalar>on a generic type is refused as overlapping the blanketFrom<Never>#455Dualnumbers (forward mode) #83Dualnumbers (forward mode) #83Approved. CI is green on
bc989f0(gates, pdisc, commit messages).FloatandFixedthrough genericRealfunctions,==/</compare,Show/TryFrom,Vector2<Dual<Float>>.length()and nested duals. I re-derived the remainder,x ** x,logarithmwith a changing base,arcTangentDividedand the nestedx ** 3cases by hand and they hold.Poweravoids the logarithm of a negative base, and then == 0case is handled.rateinstead oftangent, noFrom<Scalar>, tracked in #455) are stated in the PR body and recorded in COMPUTE.md.Non-blocking: none.