Opened 4 years ago

Closed 4 years ago

#19336 closed defect (fixed)

typo in lambert_w._print_latex_()

Reported by: rws Owned by:
Priority: minor Milestone: sage-6.10
Component: symbolics Keywords: beginner
Cc: kcrisman Merged in:
Authors: Frédéric Chapoton Reviewers: Ralf Stephan
Report Upstream: N/A Work issues:
Branch: a87b149 (Commits) Commit: a87b14961e31957410948c8225febed4d66c8107
Dependencies: Stopgaps:

Description

From https://groups.google.com/forum/?hl=en#!topic/sage-support/bjrk5270wEE

LaTeX output is defect.

this is probably

diff --git a/src/sage/functions/log.py b/src/sage/functions/log.py
index cc59437..17241ad 100644
--- a/src/sage/functions/log.py
+++ b/src/sage/functions/log.py
@@ -766,8 +766,8 @@ class Function_lambert_w(BuiltinFunction):
             \operatorname{W_{1}}(x)
         """
         if n == 0:
-            return r"\operatorname{W_0}(%s)" % z
+            return r"\operatorname{W_0}({%s})" % z
         else:
-            return r"\operatorname{W_{%s}}(%s)" % (n, z)
+            return r"\operatorname{W_{%s}}({%s})" % (n, z)
 
 lambert_w = Function_lambert_w()

Change History (14)

comment:1 Changed 4 years ago by rws

  • Keywords beginner added

comment:2 Changed 4 years ago by kcrisman

  • Cc kcrisman added

comment:3 follow-up: Changed 4 years ago by vdelecroix

What is the point of having a separate n==0 case?

comment:4 Changed 4 years ago by chapoton

  • Authors set to Frédéric Chapoton
  • Branch set to public/19336
  • Commit set to 6a9b8ea4e2af1b89194237bd53ab3929684c7fa4
  • Status changed from new to needs_review

New commits:

6a9b8eatrac #19336 fixing custom latex of Lambert W function

comment:5 Changed 4 years ago by nbruin

  • Status changed from needs_review to needs_work

Inserting the braces is a nice start, but it doesn't fix the entire problem. Compare:

sage: var("a1,a2")
(a1, a2)
sage:  latex(log( (a1+a1*a2)/a2))
\log\left(\frac{a_{1} a_{2} + a_{1}}{a_{2}}\right)
sage:  latex(lambert_w( (a1+a1*a2)/a2))
\operatorname{W_0}({(a1*a2 + a1)/a2})

As you can see a function like "log" processes its arguments further for latex. Just inserting braces doesn't cut it.

In bessel.py, the latex-ing of the arguments is done explicitly:

    def _print_latex_(self, n, z):
        return r"\operatorname{J_{%s}}(%s)" % (latex(n), latex(z))

That's probably the thing to do for lambert_w too.

Last edited 4 years ago by nbruin (previous) (diff)

comment:6 in reply to: ↑ 3 Changed 4 years ago by nbruin

Replying to vdelecroix:

What is the point of having a separate n==0 case?

There's a case split for normal printing, suppressing a zero argument:

sage: lambert_w(0,x)
lambert_w(x)
sage: lambert_w(1,x)
lambert_w(1, x)

Possibly the same was done for latex at some point. I agree that with the current code, the case split can be removed in the latex code.

comment:7 Changed 4 years ago by git

  • Commit changed from 6a9b8ea4e2af1b89194237bd53ab3929684c7fa4 to 70d9d5158e99e59566b4f4508f40c1dac0d99672

Branch pushed to git repo; I updated commit sha1. New commits:

b7620a2Merge branch 'public/19336' into 6.9.rc3
70d9d51trac #19336 latex of lambert_w again, plus a few local enhancements

comment:8 Changed 4 years ago by chapoton

  • Status changed from needs_work to needs_review

Here is a version with latex applied to the argument.

I have also taken the opportunity to enhance the link with maxima, which now has the other branches of LambertW.

comment:9 Changed 4 years ago by chapoton

ping ?

comment:10 Changed 4 years ago by rws

  • Reviewers set to Ralf Stephan

Could you please add doctests for the Maxima additions? When done you can set positive since patchbot is already ok with it.

comment:11 Changed 4 years ago by git

  • Commit changed from 70d9d5158e99e59566b4f4508f40c1dac0d99672 to a87b14961e31957410948c8225febed4d66c8107

Branch pushed to git repo; I updated commit sha1. New commits:

d7c946eMerge branch 'public/19336' into 6.9
a87b149trac #19336 some more doctest for maxima lambert_w

comment:12 Changed 4 years ago by chapoton

  • Status changed from needs_review to positive_review

ok, I have added some doctests, hopefully corresponding to what you asked.

I set to positive review.

comment:13 Changed 4 years ago by chapoton

  • Milestone changed from sage-6.9 to sage-6.10

comment:14 Changed 4 years ago by vbraun

  • Branch changed from public/19336 to a87b14961e31957410948c8225febed4d66c8107
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.