#21286 closed enhancement (fixed)
Improve printing of FDerivative by adapting the appropriate hook in PyNaC
Reported by: | Nils Bruin | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-7.4 |
Component: | symbolics | Keywords: | |
Cc: | Ralf Stephan, Bill Page, Eric Gourgoulhon | Merged in: | |
Authors: | Nils Bruin | Reviewers: | Bill Page, Eric Gourgoulhon, Ralf Stephan |
Report Upstream: | N/A | Work issues: | |
Branch: | 807d77d (Commits, GitHub, GitLab) | Commit: | |
Dependencies: | Stopgaps: |
Description
As Bill Page points out on:
https://github.com/pynac/pynac/issues/187
PyNaC does provide a special hook for printing FDerivative expressions. The relevant routine py_print_fderivative lives in src/sage/symbolic/pynac.pyx, on line 583 (or thereabouts).
It look likes an expression D[*params](f)(*args)
would get printed using a call of the form
py_print_fderivative(<id of f>,params,args)
so we'd have enough information to decide if args
consist of distinct simple variables, in which case we could print it as
diff(f(*args),[args[i] for i in params])
or something nicer.
Change History (21)
comment:1 Changed 6 years ago by
Branch: | → u/nbruin/improve_printing_of_fderivative_by_adapting_the_appropriate_hook_in_pynac |
---|
comment:2 Changed 6 years ago by
Commit: | → 81ded03488eacfd2b4ba4c797a76351b9b2e00fc |
---|
comment:3 Changed 6 years ago by
Cc: | Ralf Stephan added |
---|
comment:4 Changed 6 years ago by
Cc: | Bill Page added |
---|
comment:5 Changed 6 years ago by
Cc: | Eric Gourgoulhon added |
---|
comment:6 Changed 6 years ago by
Commit: | 81ded03488eacfd2b4ba4c797a76351b9b2e00fc → bce16a263458e5cbb363a058182ffd5642d68c7a |
---|
comment:7 Changed 6 years ago by
Status: | new → needs_review |
---|
OK, I think this is a reasonable start that's ready to be merged. In many common cases, expressions containing an FDerivative operator will be printed in a way that's valid input (an appropriate "diff" expression). The latex should look nice in those cases as well.
Other options can be tried and bikeshedded later on follow-up tickets. This at least should alleviate the worst complaints about printing derivatives.
comment:8 Changed 6 years ago by
Thank you! I checked out this ticket and am just starting to look at it... already I like it. Great work.
comment:9 Changed 6 years ago by
Authors: | → nbruin |
---|
comment:10 Changed 6 years ago by
Authors: | nbruin → Nils Bruin |
---|
comment:11 follow-up: 13 Changed 6 years ago by
I also gave a look at it; it looks very good (in particular I've checked the LaTeX output in this jupyter notebook). Thanks for this improvement! There remains to replace \partial by \mathrm{d} in the LaTeX output for the univariate case, but this might be deferred to some follow-up ticket.
A question: shouldn't the change be documentated by some doctest in src/sage/symbolic/pynac.pyx
?
comment:12 Changed 6 years ago by
Reviewers: | → Bill Page, Eric Gourgoulhon |
---|
comment:13 Changed 6 years ago by
Reviewers: | Bill Page, Eric Gourgoulhon → Bill Page, Eric Gourgoulhon, Ralf Stephan |
---|---|
Status: | needs_review → positive_review |
Replying to egourgoulhon:
A question: shouldn't the change be documentated by some doctest in
src/sage/symbolic/pynac.pyx
?
The changed doctests with the new output suffice absolutely.
As the output is deemed satisfactory by reviewers, the pynac.pyx
looks good, and make ptestlong
passes, I'll set positive now. Thanks for the work.
comment:14 Changed 6 years ago by
Thanks for the quick review. Once this is merged, we can close #6344 and possibly some other tickets.
Concerning printing a "\mathrm{d}" rather than "\partial": yes, I think that's a nice refinement to make in a follow-up ticket. That might also be a place to start thinking about when function names can be safely put in the numerator and whether such behaviour should be subject to some global state.
comment:15 Changed 6 years ago by
Status: | positive_review → needs_work |
---|
Have you noticed that the patchbot next_method
plugin failed on src/sage/symbolic/pynac.pyx
? Probably the builtin function next
should be used instead of .next()
in line 653.
comment:16 Changed 6 years ago by
While I doubt it will make a difference, it would be good to check that there are no conflicts with #21369.
comment:17 Changed 6 years ago by
Commit: | bce16a263458e5cbb363a058182ffd5642d68c7a → 807d77dcf20bf563b7efaffd2e19ebea23988cff |
---|
comment:18 follow-up: 19 Changed 6 years ago by
Status: | needs_work → positive_review |
---|
OK, let's see if this fares better.
comment:19 Changed 6 years ago by
comment:20 Changed 6 years ago by
Branch: | u/nbruin/improve_printing_of_fderivative_by_adapting_the_appropriate_hook_in_pynac → 807d77dcf20bf563b7efaffd2e19ebea23988cff |
---|---|
Resolution: | → fixed |
Status: | positive_review → closed |
comment:21 Changed 6 years ago by
Commit: | 807d77dcf20bf563b7efaffd2e19ebea23988cff |
---|
Excellent. Thanks.
After finally tracking down where the hook for this exists, the actual change only requires a few lines. With the attached POC branch:
so we get more intuitive printing when argument positions are easily determined by variable names, and revert to unambiguous notation if not. For univariate we do have:
of course, actual printing styles can be adapted.
New commits:
trac 21286: Improved adaptive printing of FDerivative expressions