#11316: Weighted degree term orders added
--------------------------------+-------------------------------------------
   Reporter:  klee              |          Owner:  AlexGhitza  
       Type:  enhancement       |         Status:  needs_review
   Priority:  minor             |      Milestone:  sage-4.7.1  
  Component:  basic arithmetic  |       Keywords:              
Work_issues:                    |       Upstream:  N/A         
   Reviewer:                    |         Author:  Kwankyu Lee 
     Merged:                    |   Dependencies:              
--------------------------------+-------------------------------------------

Comment(by SimonKing):

 Concerning unpickling of old pickles, I think the following holds in this
 case:

 The pickling of a `TermOrder` is actually quite simple, standard Python.
 It is an object with a `__dict__`, and a new un-initialised instance can
 be created with `__new__`.

 '''Example'''

 First, we obtain an order:
 {{{
 sage: P.<x,y>=QQ[]
 sage: T = P.term_order()
 }}}

 Now, if I am not mistaken, `S=loads(dumps(T))` essentially boils down to
 the following.
 First, we create a new instance of the class:
 {{{
 sage: S = T.__new__(T.__class__)
 }}}
 And then, we provide the new instance with a copy of the old
 instance's `__dict__`:
 {{{
 sage: S.__dict__ = copy(T.__dict__)
 }}}

 As a result, we have a copy of T:
 {{{
   sage: S
   Degree reverse lexicographic term order
   sage: S == T
   True
   sage: S is T
   False
 }}}

 If I understand correctly, the problem here is that your patch
 introduces a new attribute `_weights`, that has a default value for
 trivial degree weights. So, if `__dict__` was taken from an old pickle,
 then it lacks the key `'_weights'`. Hence, requesting `S._weights` would
 fail.

 Two solutions were suggested:

  1. Introduce a `__getattr__` method, that returns the default weights and
 puts them into `S.__dict__['_weights']`. That ensures that
 `S.__getattr__('_weights')` is called at most once: `__getattr__` is only
 called if an attribute can not be found in the `__dict__` and not as a
 class attribute.

  2. Introduce the default `_weights` as a class attribute. If a term order
 has non-default weights then they are put into `__dict__` (this is what
 happens if you do `T._weights = [1,2,3]`). But attributes found in
 `__dict__` have precedence over class attributes. Hence, the class
 attribute will only be considered if `_weights` is not in `__dict__`.

 It seems to me that in both cases unpickling of old pickles should just
 work. One should test, though, whether one of the solutions has a speed
 penalty. I reckon that introducing `__getattr__` may slow things down. How
 often are attributes of a term order called when you do polynomial
 arithmetic?

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11316#comment:15>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to