-
-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partition options and cleanup partitions documentation #13605
Comments
comment:1
Thanks for opening this ticket, and even better working on it :-) For the syntax, I would prefer something like:
in order to not polute the global namespace. It's relatively consistent with what's done in a couple other places (e.g. CombinatorialFreeModule). Of course, PermutationOptions should be renamed to Permutations.options as well (and by the way the l2r option of PermutationOptions should be deprecated because global options should not change the semantic). Some places use Cheers, |
comment:2
Hi Travis, I like the concept of various methods being controlled by global options, however, I think that it would be much better if all of the methods provided by the options were also accessible directly as methods to the class. In fact, for me this is vital. The reason I introduced the Consider the following:
The elements of this Specht module are indexed, as usual, by standard tableaux which are compactly printed here inbetween brackets The way your partition options code is currently written many of the individual options are coded "inline" inside the optionable methods. This means that the only way for external code to access the different variants of an optionable method is to artificially tweak It would be more useful, I think, if each optionable variant was directly accessible and accessible in a systematic way. This would allow external code, which might have its own options, to easily access the different variants of the method. Perhaps the best way of doing this would be something like the following: def _repr_(self):
try:
repr=getattr(self, '_repr_'+ self.parent().options['display'])
except AttributeError:
raise ValueError, "Invalid display option"
return repr()
def _repr_list(self):
return '[%s]' % ', '.join('%s'%m for m in self)
def _repr_exp(self):
exp = self.to_exp()
return '%s' % ', '.join('%s%s' % (m+1, '' if e==1 else '^%s'%e)
for (m,e) in enumerate(exp) if e > 0)
def _repr_diagram(self):
return self.ferrers_diagram()
def _repr_compact(self):
exp=self.to_exp()[::-1] # reversed list of exponents
M=max(self)
return '%s' % ','.join('%s%s' % (M-m, '' if e==1 else '^%s'%e)
for (m,e) in enumerate(exp) if e>0) This model has the advantage of being easy to read and very easy to extend: you simply add another def _repr_(self):
'''
It's probably essential to give documentation describing
possible global options.
'''
return optionable_method(self, '_repr_', option_name='display') where As a final note, can there please be an honest compact variant of Cheers, Andrew ps I am happy to help in getting all of this to work if you think these ideas are reasonable |
comment:3
I will separate them out into separate functions. This is probably a cleaner/more flexable way of doing things (and I believe the extra function call is relatively small compared to the actual cost of printing). I will also add a compact option to the display output options with no spaces. Best, Travis |
comment:4
Thanks Travis! I was thinking that the extra overhead wouldn't be significant, however, I was thinking of methods like I am really thinking of a general options framework for parent/element classes here. In the parents, there would be a generic method which looks something like this: def options(self, *option, **options):
# print the current settings for the options in ``option``
for opt in option:
try:
print getattr(self.element_class,opt).__name__
except AttributeError:
raise ValueError, '%s is not a valid option' % opt
# change the option settings for the options in ``options``
for opt in options:
new_opt=option+'_'+options[opt]
if hasattr(self.element_class,new_opt):
self.element_class.__setattr__(opt, new_opt)
else:
raise ValueError, '%s is not a valid option for %s' % (options[opt], opt) and, in the element classes, the different options would be coded something like this: def _repr__list(self):
return '[%s]' % ', '.join('%s'%m for m in self)
def _repr__exp(self):
exp = self.to_exp()
return '%s' % ', '.join('%s%s' % (m+1, '' if e==1 else '^%s'%e)
for (m,e) in enumerate(exp) if e > 0)
def _repr__diagram(self):
return self.ferrers_diagram()
_repr_= _repr__list # default option for _repr_ Why don't I try and implement this and see how it works for a few different examples? Perhaps it's safer to discuss this first on sage-combinat. What do you think? |
comment:5
I like the concept, however how would you change the option function on those elements which have already been created? I currently don't see a way to make this feasible. This probably would be best discussed on sage-combinat-devel. Best, Travis |
comment:6
This will also incorporate |
This comment has been minimized.
This comment has been minimized.
comment:7
I meant |
comment:8
This will be based on #13762. |
comment:9
Almost ready for review. |
This comment has been minimized.
This comment has been minimized.
Reviewer: Andew Mathas |
comment:11
For the record, the large size of this patch is due to changes in doctests in symmetric functions because the terms were reorderd. If #10193 is not finished soon, I can commute this patch past. |
This comment has been minimized.
This comment has been minimized.
comment:12
Hi Travis, Could you please tell what the rationale is for having partition_options and tableau_options defined in their own files. In the long term, we need to be careful about "polluting" the file space so I don't think it is a good idea to have these little code snippets in their own files. Similarly, I'm not convinced that it is a good idea to give the partition options their own page/index entry in the manual (btw, tableau_options doesn't seem to have a manual entry yet). I think that it would be better to have the partition options discussed in a new section at the top of partitions.rst. Andrew |
comment:13
Hi Travis, Here are some more questions/issues. Consider
This is correct, of course, but it is potentially confusing because a and b look exactly the same when printed, I think that it would be better if the ordering ordering on the class was returned by
Continuing this example:
This, to me, just looks wrong: the default ordering should correspond to the order in which the partitions are generated by the iterator. That is, the default really should be 'rev_lex' or the iterator should change. A second related issue is that in calling Partitions(4)[:], via a[:], we have created the list of all partitions of 4 BUT b does not know about this:
In this particular example this is not important because generating the list of partitions of 4 is very quick, but if instead we were looking at the partitions of 50 or 100 then this starts to become an issue. The reason, of course, is that Another possibility would be to make I think that Nicolas objected to doing it this way on the basis that it might break code which implicitly assumed a particular order on the partitions. I don't like this argument as it encourages bad coding: if a particular ordering is required by the code then this should be explicit in the code. (Up until now it hasn't been possible to easily change the ordering being used, but now that it is becoming possible the algorithms which require a particular ordering should be updated to make this explicit.) I think that moving On the other hand, if you think it better to have honestly different classes for each ordering then I think that the iterator should be modified to produce the partitions in the correct order. This would be annoying to do properly but could be done by first constructing the list of all partitions and then sorting. This is potentially time consuming, but if some one honestly needs a class for the poset with a particular order then they probably need all of its elements(?). Andrew |
comment:14
Short version: by making the order option part of the definition of the element and parent classes for partitions you loose the benefits of caching for partitions and for Partitions._list. Is this worth it? I am not sure that I see the benefit especially as, in practice, the order "option" is processed in the code in exactly the same way as the "real" options. |
comment:15
Hey Andrew, Sorry for the delay. I'm in Burma right now and while I can generally get stable internet, some things work better than others. Replying to @AndrewAtLarge:
My main thought was because it is not something strictly related to partitions, but partition like objects (partition tuples and rigged configurations, there might be others). Also because Replying to @AndrewAtLarge:
Agreed. I think this is done in a few other places too.
This smells like a bug since I would think (Although this might also be why their doesn't seem to be a good ordering in the symmetric functions (if that is, oh-joy-of-joys, I have to change a lot of doctests again).)
I don't think direct subclasses will work since I don't see how the data be actually communicated (without breaking into U.R.'s cache). Unless you mean they are to act like proxy classes and have a link back to the common data (which I believe would only consist of the list of partitions)? Actually, this discussion is somewhat of a red herring since we need a second list of all of the partitions because their parent would have changed. The actual generation of the partitions I believe is amortized For example, suppose we had shared data, then we'd have the following behavior:
For example, every time you do
I strongly don't think having a subclass with the desired order is a good idea. Way too much maintenance and the problems above would likely still exist. That's all the time I have right now to reply with. Again, thank you for reviewing this! Best, Travis |
comment:16
#12313 introduces a speed regression related with the fact that currently Partitions are not unique parents. This is dealt with at #13991. If I understand correctly, you intend to make partitions unique parents. Hence, it would probably solve the speed regression. But how soon do you expect this ticket to be ready for being merged (given that one dependency does not have a positive review yet)? At #13991, I have attached a patch that turns |
comment:17
Hey Simon, Replying to @simon-king-jena:
As soon as possible. I might move this past the #10193 dependency since it is more of a semantic rather than a functional dependency.
Hey Andrew, As I recall, Nicolas' main reason was suppose you did something like the following:
and you depended on this being dominance ordering. Somewhere along the way, you set the ordering back to "lex", and then needed to recreate End of the day, I'm really starting to think that deciding an ordering is more trouble than it's worth. At the very least, given #13991, should we separate this feature out to another ticket? Last thing for now, are there any other major issues currently with this patch? I really appreciate you reviewing this. Thank you, Edit/PS - I'm back in the US. |
Changed reviewer from Andrew Mathas, Nicolas Thiery to Andrew Mathas, Nicolas M. Thiéry |
comment:53
Minor remark: In diff --git a/sage/combinat/sf/k_dual.py b/sage/combinat/sf/k_dual.py
--- a/sage/combinat/sf/k_dual.py
+++ b/sage/combinat/sf/k_dual.py
@@ -39,7 +39,7 @@ from sage.misc.cachefunc import cached_m
from sage.categories.magmas import Magmas
from sage.misc.constant_function import ConstantFunction
from sage.categories.graded_hopf_algebras_with_basis import GradedHopfAlgebrasWithBasis
-from sage.combinat.partition import Partition, Partitions, Partition_class
+from sage.combinat.partition import Partition, Partitions, Partition
from sage.rings.all import Integer
from sage.combinat.combinat import InfiniteAbstractCombinatorialClass
import sage.combinat.sf.sfa as sfa (But AFAICS this is the only instance of a redundant import of it, at least regarding the patch.) |
Merged: sage-5.8.beta3 |
comment:55
Framework for global options is awesome, although I want to complain that it was hidden in a big patch instead of being a clear little ticket... Anyway, why "values of all options are forced to be in lower case"? |
comment:56
For standardness, ex. so "English" would be interpreted the same as "english" and the user wouldn't have to care about capitalization. There's a followup patch #14248 which gives the option to be case-strict or enforce only upper or lower. |
Adding a
Partitions.global_options()
method which (globally) sets options for partitions as noted in #5439 - http://wiki.sagemath.org/combinat/Weirdness similar toPermutationOptions()
. This will also affect tableau classes and friends. Additionally this will also clean up some of the documentation/code in the respective files.Here's what is included in the patch:
Partition_class
toPartition
Partitions*
(exceptPartitionsRestricted
) into the category frameworkIntegerListsLex
into the category framework with element class ofClonableArray
from_*
toPartitions().from_*
.dominate()
todominated_partitions()
inPartition
.Apply attachment: trac_13605-partition_options-ts.patch
Depends on #14065
Depends on #6495
Depends on #14063
Depends on #13688
Depends on #14138
CC: @sagetrac-sage-combinat
Component: combinatorics
Keywords: partition, options, output, days45
Author: Travis Scrimshaw
Reviewer: Andrew Mathas, Nicolas M. Thiéry
Merged: sage-5.8.beta3
Issue created by migration from https://trac.sagemath.org/ticket/13605
The text was updated successfully, but these errors were encountered: