Opened 5 years ago

Last modified 5 years ago

#17559 new defect

Incorrect caching of variables' latex_name attribute

Reported by: wonder Owned by:
Priority: major Milestone: sage-6.5
Component: symbolics Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by wonder)

Saving and loading variables apparently doesn't reload the latex_name attribute:

┌────────────────────────────────────────────────────────────────────┐
│ Sage Version 6.4.1, Release Date: 2014-11-23                       │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
sage: xhat = SR.symbol( 'xhat', latex_name='\hat{x}' )
sage: latex(xhat)
\hat{x}
sage: save_session( 'xhat' )
sage: l = load( 'xhat.sobj' )
sage: latex( l['xhat'] )
\hat{x}
sage: 
Exiting Sage (CPU time 0m0.20s, Wall time 2m49.25s).
┌────────────────────────────────────────────────────────────────────┐
│ Sage Version 6.4.1, Release Date: 2014-11-23                       │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
sage: l = load( 'xhat.sobj' )
sage: latex( l['xhat'] )
\mathit{xhat}

It looks as if it tries to keep these objects unique, and load() will leave an existing variable's latex_name in place, but won't set it when creating a variable.

I can see arguments for and against considering SR.symbol('x', latex_name='y') a different variable from SR.symbol('x'). It seems reasonable to consider them the same, in which case the latex name should be discarded if there's already a variable of the same name. But it should use the saved latex name when loading a variable that isn't already defined.

Seems possibly related: #5466

Update: I think this report, posted to sage-support today, is the same issue:

If you do something like this

sage: a = var('a',latex_name='BLAH')

and then sage: a = var('a')  sage: latex(a)  BLAH  So the first a=var(...) did have an impact on the second one, no?

Change History (5)

comment:1 Changed 5 years ago by wonder

  • Summary changed from load_session loses variable's latex_name to load() loses variable's latex_name

comment:2 Changed 5 years ago by wonder

  • Summary changed from load() loses variable's latex_name to Incorrect caching of variables' latex_name attribute

comment:3 Changed 5 years ago by wonder

  • Description modified (diff)

comment:4 Changed 5 years ago by wonder

  • Component changed from pickling to symbolics
  • Description modified (diff)

comment:5 Changed 5 years ago by kcrisman

According to the sage-support thread in question, perhaps the more recent bug is different

The problem above is caused by sage reusing 
"already existing variables" in the symbol function 
in sage/symbolic/ring.pyx. This "fixes" the above bug: 

diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx 
index f87f622..6972018 100644 
--- a/src/sage/symbolic/ring.pyx 
+++ b/src/sage/symbolic/ring.pyx 
@@ -555,7 +555,7 @@ cdef class SymbolicRing(CommutativeRing): 
         e = pynac_symbol_registry.get(name) 

         # fast path to get an already existing variable 
-        if e is not None: 
+        if False: # e is not None: 
             if domain is None: 
                 if latex_name is None: 
                     return e 
Note: See TracTickets for help on using tickets.