Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Global options for elements set by their parents
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Nicolas M. Thiery  
View profile  
 More options Oct 27 2012, 11:37 am
From: "Nicolas M. Thiery" <Nicolas.Thi...@u-psud.fr>
Date: Sat, 27 Oct 2012 17:37:54 +0200
Local: Sat, Oct 27 2012 11:37 am
Subject: Re: [sage-combinat-devel] Global options for elements set by their parents
        Hi Andrew!

On Sat, Oct 27, 2012 at 05:43:08AM -0700, Andrew Mathas wrote:
> Travis has is writing a nice patch #13605 which implements global options for
> partitions. Among other things, these options determine how partitions are
> printed (as lists, using exponential notation, compactly, ...), whether
> diagrams follow the English or French conventions, whether the default ordering
> is the lexicographic or dominance etc.

A big +1 on exploring this long desired feature set!

One caveat: setting options for a preexisting parent should *not*
affect its semantic. Otherwise, one is likely to break other pieces of
Sage which rely on a given semantic. In other words:

OK (that just affects the outputs in my own session):

        sage: Partitions().options(convention="french")

OK (I own P and can do what I want with it):

        sage: P = Partitions(cmp=dominance)

Not OK (this could break e.g. Symmetric Functions):

        sage: Partitions().options(cmp=dominance)

> As a result of these discussions I'd like to suggest a general
> framework for implementing global options for element classes which
> are controlled by their parents (being a parent myself I am of
> course advocating for parental control here!:).

I would want to extend the framework to also allow for setting options
for the parent itself. Things like Partitions(3, order=...) that would
change the enumeration order.

> The reason for this post is to ask whether need a general options mechanism for
> element classes and, if so, is anyone in favour of the approach described
> below.
> The main idea is that the parent inherits a generic method (see below) of the
> form:
> def options(self, *option, **options):
> r"""
> Print and set options for the element class of ``self``
> """"
> ....
> which is used to set and print the options for the element class. In the
> element_class the options to the method ``foo`` are methods of the form
> ``foo_option1``, ``foo_option2`` and so on. What the ``options`` method of the
> parent does is simply set ``self.element.foo`` equal to the desired option. The
> nice thing about this, is that the options do not add extra overhead to the
> methods and they can be added to the element class simply by adding appropriate
> methods:
> def _repr__fuzzy(self): return 'I am fuzzy'
> def _repr__focussed(self: return 'I am focussed'
> _repr_=_repr_focussed # the default
> and then you can set the option with
> sage: parentClass.options(_repr_='fuzzy')
> This will set _repr_ = _repr__fuzzy --- or raise a ValueError if this is not
> a valid option.
> As a test case, I have implemented a prototype for partitions, however, the
> code is completely general. Just as importantly, it seems to work quite well.
> For those who want to see the details I will upload a patch trac_13605?--
> generic_partition_options-am.patch to the queue shortly.
> ...
> Please let me know what you think.

I like the idea of something systematic! Some issues that could come
up though:

- Element classes may be shared between different parents. One needs
  to make sure that one does not affect by accident unrelated parents.

- Assigning methods to the class won't work with Cython classes (as
  far as I remember).

- To support options for both the parent and the elements, we probably
  want options names like "element_repr=...", which by the way would
  be nicely explicit.

- One often need to change several methods (repr/latex/...) at once,
  so manual handling will be needed in many (most?) cases anyway.

Also a comment: the result output methods like repr is meant to be
eventually read by a human; if such a method is called zillions of
times, then probably something got wrong. Thus, one should not worry
about optimizing away callbacks to the parent in such methods: "always
ask dad/mom what you should do" :-).

Cheers,
                                Nicolas
--
Nicolas M. Thi ry "Isil" <nthi...@users.sf.net>
http://Nicolas.Thiery.name/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.