Skip to content
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

add is_supergreedy() to linear extensions #34970

Merged
merged 24 commits into from
Mar 13, 2023

Conversation

Sandstorm831
Copy link
Contributor

This is my pull request originally created on trac, which I thought pushing on github.
Fixes #24700

@Sandstorm831
Copy link
Contributor Author

Hello everyone, I have created this pull request in view of changes committed by me in the open issue #24700 , I had a positive review on it. Please tell if anything else needs to be done to merge this pull request.

@Sandstorm831 Sandstorm831 changed the title U/gh sandstorm831/24700 add is_supergreedy() to linear extensions Feb 6, 2023
@dimpase dimpase self-requested a review February 6, 2023 12:05
Copy link
Member

@dimpase dimpase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@Sandstorm831 Sandstorm831 requested review from dimpase and removed request for dimpase February 6, 2023 12:17
@dimpase
Copy link
Member

dimpase commented Feb 6, 2023

for now, we keep the rule that only the release manager merges positively reviewed PRs.

@Sandstorm831
Copy link
Contributor Author

No problem, I will wait. ThankYou @dimpase for the information

@codecov-commenter
Copy link

codecov-commenter commented Feb 8, 2023

Codecov Report

Base: 88.57% // Head: 88.59% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (2c15778) compared to base (52a81cb).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #34970      +/-   ##
===========================================
+ Coverage    88.57%   88.59%   +0.01%     
===========================================
  Files         2140     2140              
  Lines       397273   397265       -8     
===========================================
+ Hits        351891   351945      +54     
+ Misses       45382    45320      -62     
Impacted Files Coverage Δ
src/sage/combinat/posets/linear_extensions.py 96.10% <100.00%> (+0.28%) ⬆️
src/sage/modular/local_comp/liftings.py 98.33% <0.00%> (-1.67%) ⬇️
src/sage/modular/modform/numerical.py 94.19% <0.00%> (-0.65%) ⬇️
...sage/geometry/hyperbolic_space/hyperbolic_model.py 88.95% <0.00%> (-0.62%) ⬇️
src/sage/doctest/forker.py 80.24% <0.00%> (-0.54%) ⬇️
src/sage/doctest/reporting.py 74.45% <0.00%> (-0.44%) ⬇️
src/sage/graphs/generators/random.py 92.29% <0.00%> (-0.18%) ⬇️
...e/combinat/cluster_algebra_quiver/mutation_type.py 52.01% <0.00%> (-0.12%) ⬇️
src/sage/combinat/tableau.py 96.11% <0.00%> (-0.05%) ⬇️
src/sage/quadratic_forms/ternary_qf.py 67.12% <0.00%> (ø)
... and 17 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are code style issues (see failing github check). Can you please fix them?

@Sandstorm831
Copy link
Contributor Author

Sandstorm831 commented Feb 8, 2023

Sir, can you tell what are the changes that I have to do.

@dimpase
Copy link
Member

dimpase commented Feb 8, 2023

Click on "Details" for the failing Lint/Code style check. You'll see https://github.com/sagemath/sage/actions/runs/4123554420/jobs/7121712300 pointing to what you have to fix (trailing whitespace in few lines in your code here)

@Sandstorm831
Copy link
Contributor Author

I have fixed the codestyle issues and now the test is passing, please tell if any other change needs to be done

@Sandstorm831
Copy link
Contributor Author

@mantepse, I have incorporated all the changes, on looking closely, your code seems easy to understand then mine, so I have updated the code. Please check and let me know if there are any more changes needs to be incorporated.

@mantepse
Copy link
Collaborator

One final thing: in the docstring, the definition is not very clear, in particular, the $x$ in $p(x)$ is unclear. I find the definition in Kierstead and Trotter quite good, it is reproduced at https://www.findstat.org/StatisticsDatabase/St001106. Maybe you could adapt it for the docstring.

@Sandstorm831
Copy link
Contributor Author

@mantepse , I have improved the definition in the docstrings. Please have a look and let me know if there any more changes needs to be done.

@Sandstorm831
Copy link
Contributor Author

2023-02-26T12:25:06.1327632Z File "doc/ca/intro/index.rst", line 492, in doc.ca.intro.index
2023-02-26T12:25:06.1327885Z Failed example:
2023-02-26T12:25:06.1328173Z     solve([x + y == 6, x - y == 4], x, y)
2023-02-26T12:25:06.1328411Z Exception raised:
2023-02-26T12:25:06.1328636Z     Traceback (most recent call last):
2023-02-26T12:25:06.1328952Z       File "/__w/sage/sage/src/sage/doctest/forker.py", line 695, in _run
2023-02-26T12:25:06.1329287Z         self.compile_and_execute(example, compiler, test.globs)
2023-02-26T12:25:06.1329646Z       File "/__w/sage/sage/src/sage/doctest/forker.py", line 1093, in compile_and_execute
2023-02-26T12:25:06.1329902Z         exec(compiled, globs)
2023-02-26T12:25:06.1330184Z       File "<doctest doc.ca.intro.index[1]>", line 1, in <module>
2023-02-26T12:25:06.1330561Z         solve([x + y == Integer(6), x - y == Integer(4)], x, y)
2023-02-26T12:25:06.1330873Z       File "/__w/sage/sage/src/sage/symbolic/relation.py", line 1137, in solve
2023-02-26T12:25:06.1331116Z         m = maxima(f)
2023-02-26T12:25:06.1331440Z       File "sage/misc/lazy_import.pyx", line 404, in sage.misc.lazy_import.LazyImport.__call__
2023-02-26T12:25:06.1331766Z         return self.get_object()(*args, **kwds)
2023-02-26T12:25:06.1332368Z       File "sage/misc/lazy_import.pyx", line 225, in sage.misc.lazy_import.LazyImport.get_object
2023-02-26T12:25:06.1332802Z         return self._get_object()
2023-02-26T12:25:06.1333144Z       File "sage/misc/lazy_import.pyx", line 261, in sage.misc.lazy_import.LazyImport._get_object
2023-02-26T12:25:06.1333519Z         self._object = getattr(__import__(self._module, {}, {}, [self._name]), self._name)
2023-02-26T12:25:06.1333881Z       File "/__w/sage/sage/src/sage/interfaces/maxima_lib.py", line 119, in <module>
2023-02-26T12:25:06.1334224Z         ecl_eval("(set-pathnames)")
2023-02-26T12:25:06.1334523Z       File "sage/libs/ecl.pyx", line 1350, in sage.libs.ecl.ecl_eval
2023-02-26T12:25:06.1334790Z         cpdef EclObject ecl_eval(str s):
2023-02-26T12:25:06.1335088Z       File "sage/libs/ecl.pyx", line 1373, in sage.libs.ecl.ecl_eval
2023-02-26T12:25:06.1335377Z         o=ecl_safe_eval(python_to_ecl(s, True))
2023-02-26T12:25:06.1335673Z       File "sage/libs/ecl.pyx", line 321, in sage.libs.ecl.ecl_safe_eval
2023-02-26T12:25:06.1335993Z         raise RuntimeError("ECL says: {}".format(message))
2023-02-26T12:25:06.1336378Z     RuntimeError: ECL says: Could not create directory "/github/home/.sage/maxima/binary/5_45_0/ecl/21_2_1"
2023-02-26T12:25:06.1336693Z     C library error: "File exists"
2023-02-26T12:25:11.1458396Z **********************************************************************
2023-02-26T12:25:11.1458869Z 1 item had failures:
2023-02-26T12:25:11.1459101Z    1 of 175 in doc.ca.intro.index

This test failed.

src/sage/combinat/posets/linear_extensions.py Outdated Show resolved Hide resolved
src/sage/combinat/posets/linear_extensions.py Outdated Show resolved Hide resolved
src/sage/combinat/posets/linear_extensions.py Outdated Show resolved Hide resolved
src/sage/combinat/posets/linear_extensions.py Outdated Show resolved Hide resolved
@Sandstorm831 Sandstorm831 requested review from mantepse and removed request for dimpase, tobiasdiez and mantepse February 26, 2023 16:41
@Sandstorm831
Copy link
Contributor Author

@mantepse, done the corrections

@mantepse
Copy link
Collaborator

Dear @Sandstorm831, please excuse my being pedantic, I noticed another slight simplification of the code. It is nothing spectacular, but I think it makes the intent clearer. Warning: we now need to produce L as a list, because otherwise we exhaust the iterator.

       if not self:
            return True
        H = self.poset().hasse_diagram()
        L = sources = H.sources()
        linext = []
        for e in self:
            if e not in L:
                return False
            linext.append(e)
            for y in reversed(linext):
                L = [x for x in H.neighbor_out_iterator(y)
                     if x not in linext
                     and all(low in linext for low in H.neighbor_in_iterator(x))]
                if L:
                    break
            else:
                L = sources = [x for x in sources if x not in linext]
        return True

@mantepse
Copy link
Collaborator

In principle we could remove the first two lines, checking whether self is empty, too. However, I guess that this is a valid optimization, we avoid computing the poset, its Hasse diagram and the sources thereof.

@Sandstorm831
Copy link
Contributor Author

Sandstorm831 commented Feb 26, 2023

@dimpase @mantepse sorry if I am missing something, but I want to ask how we avoided computing the poset, hasse diagram and sources. I can see that we have to calculate all poset, it's hasse diagram and all sources, on the contrary I can't see how this is optimization over the previous code, as I can notice that the check

if self[i+1] not in L:
    return False

which was previously present at the bottom, shifted above and L had been initialised earlier.

@mantepse
Copy link
Collaborator

mantepse commented Feb 26, 2023

I wasn't saying that is an optimization, except that the code is now shorter. Instead of checking if self[0] not in sources manually before the loop, it is now done in the loop.

@Sandstorm831
Copy link
Contributor Author

Ohk, sorry @mantepse I misunderstood your point, I will change the code asap.

@Sandstorm831
Copy link
Contributor Author

done! @mantepse
Also applied as suggested by @dimpase of first two lines, checking whether self is empty.

@github-actions
Copy link

Documentation preview for this PR is ready! 🎉
Built with commit: 2c15778

Copy link
Collaborator

@mantepse mantepse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@dimpase dimpase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@vbraun vbraun merged commit f526423 into sagemath:develop Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add is_supergreedy() to linear extension
8 participants