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

class for flattening polynomial rings over polynomial rings #21106

Closed
bhutz opened this issue Jul 27, 2016 · 43 comments
Closed

class for flattening polynomial rings over polynomial rings #21106

bhutz opened this issue Jul 27, 2016 · 43 comments

Comments

@bhutz
Copy link

bhutz commented Jul 27, 2016

Given a polynomial ring QQ['a',b']['x','y'] construct a morphism and its inverse to the ring QQ['a','b','x','y']

CC: @videlec

Component: algebra

Author: Ben Hutz, Vincent Delecroix

Branch/Commit: 19cb171

Reviewer: Vincent Delecroix

Issue created by migration from https://trac.sagemath.org/ticket/21106

@bhutz bhutz added this to the sage-7.3 milestone Jul 27, 2016
@bhutz
Copy link
Author

bhutz commented Jul 27, 2016

Branch: u/bhutz/flatten

@bhutz
Copy link
Author

bhutz commented Jul 27, 2016

comment:2

Here is a first attempt to flesh this out. Please comment.


New commits:

cf97fed21106: create polynomial ring flattening class

@bhutz
Copy link
Author

bhutz commented Jul 27, 2016

Commit: cf97fed

@videlec
Copy link
Contributor

videlec commented Jul 27, 2016

comment:4
For example ``QQ['a','b'],['x','y']`` flattens to ``QQ['a','b','c','d']``.

should I read ``QQ['a', 'b', 'x', 'y']``?

@videlec
Copy link
Contributor

videlec commented Jul 27, 2016

comment:5

The error ValueError("clash in variable names") should be tested.

@videlec
Copy link
Contributor

videlec commented Jul 27, 2016

comment:6

I am not sure we want that FlatteningMorphism in the global namespace.

@bhutz
Copy link
Author

bhutz commented Jul 27, 2016

comment:7

Those are all simple enough. I also removed some terminating white space

@videlec
Copy link
Contributor

videlec commented Jul 27, 2016

comment:8

Here is a recursive version of _call_ that seems to be a little bit faster

    def _call2_(self, p):
        r"""
        TESTS::

            sage: R = QQ['x']['y']['s','t']
            sage: p = R('s*x + y*t + x^2*s + 1 + t')
            sage: f = FlatteningMorphism(R)
            sage: f._call2_(p)
            x^2*s + x*s + y*t + t + 1
        """
        p = {(): p}

        for ring in self._intermediate_rings:
            new_p = {}
            if is_PolynomialRing(ring):
                for mon,pp in p.iteritems():
                    assert pp.parent() == ring
                    for i,j in pp.dict().iteritems():
                        new_p[(i,)+(mon)] = j
            elif is_MPolynomialRing(ring):
                for mon,pp in p.iteritems():
                    assert pp.parent() == ring
                    for mmon,q in pp.dict().iteritems():
                        new_p[tuple(mmon)+mon] = q
            else:
                raise RuntimeError
            p = new_p

    return self.codomain()(p)

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 27, 2016

Changed commit from cf97fed to 957589f

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 27, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

957589f21106: minor fixes

@videlec
Copy link
Contributor

videlec commented Jul 27, 2016

comment:10

To use _call2_, the constructor needs to be modified with

        intermediate_rings = []
        ... # AS BEFORE
        while is_PolynomialRing(ring) or is_MPolynomialRing(ring):
            intermediate_rings.append(ring)
            ... # AS BEFORE
        ... # AS BEFORE
        self._intermediate_rings = intermediate_rings

@videlec
Copy link
Contributor

videlec commented Jul 27, 2016

comment:11

Do you think we want to support both version of _call_?

@bhutz
Copy link
Author

bhutz commented Jul 27, 2016

comment:12

None of the examples that I've tried fail for call2? The more constructive call2 sits better with me as it is not relying on iterpreting a string as a polynomial.

@videlec
Copy link
Contributor

videlec commented Jul 27, 2016

comment:13

Note that a similar _call_ can be implemented for the section morphism.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 27, 2016

Changed commit from 957589f to 8c22f75

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 27, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

8c22f7521106: new version of _call_

@bhutz
Copy link
Author

bhutz commented Jul 27, 2016

comment:15

changes made and a version of call2 for unflattening. Not quite as elegant as yours, but constructive.

@videlec
Copy link
Contributor

videlec commented Jul 27, 2016

comment:16

Is it faster than string?

@bhutz
Copy link
Author

bhutz commented Jul 27, 2016

comment:17

much faster for things like CC and str does not work for QQbar. It is slightly slower for QQ.

@videlec
Copy link
Contributor

videlec commented Jul 27, 2016

comment:18

Replying to @bhutz:

much faster for things like CC and str does not work for QQbar. It is slightly slower for QQ.

Would be good to add doctest for QQbar. By the way, the string method would also fail for something like the following (that would be good to doctest as well)

sage: K.<a> = NumberField(x^3 - 2)
sage: R = K['x','y']['a','b']

@videlec
Copy link
Contributor

videlec commented Jul 27, 2016

comment:19

Strings are also bad for floating point

sage: a = RR(1 / 2**30)
sage: RR(str(a)) == a
False

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 27, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

570d9ee21106: added doc tests

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 27, 2016

Changed commit from 8c22f75 to 570d9ee

@bhutz
Copy link
Author

bhutz commented Jul 27, 2016

comment:21

yes, those are good and caught an error in the codomain as well that I've corrected.

@videlec
Copy link
Contributor

videlec commented Jul 27, 2016

New commits:

f05f7db21106:cleaning

@videlec
Copy link
Contributor

videlec commented Jul 27, 2016

comment:26

problem with the file mode... it is -rwxr-xr-x instead of -rw-r--r--.

(incidentally I have another commit to propose)

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 27, 2016

Changed commit from f05f7db to 19cb171

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 27, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

6e5094221106: change file mode
19cb17121106: Python3 compatibility + more cleaning

@bhutz
Copy link
Author

bhutz commented Jul 27, 2016

comment:29

those changes are fine with me. I pulled it down to test just to be safe, and all still runs fine.

@videlec
Copy link
Contributor

videlec commented Jul 27, 2016

comment:30

Thanks!

I also think that in the future the FlatteningMorphism should support QQ['a','b']['a','b']['a']['b']. There is almost nothing to modify to make the target to be QQ['x0','x1','x2','x3','x4','x5'] (I guess only the constructor).

@bhutz
Copy link
Author

bhutz commented Jul 27, 2016

comment:31

You probably saw, I removed the original codomain argument. I was running into some difficulties there with _call_, but with the new version of _call_ it would probably actually be easy now.

@videlec
Copy link
Contributor

videlec commented Jul 27, 2016

comment:32

Yep. It might also be that for some operation it is good to try in QQ['a']['b']['c']['d']['e'] instead. In which case we might want to use UnflattenMorphism without using FlattenMorphism. See my recent post

https://groups.google.com/forum/#!topic/sage-devel/CDLCb6OX4ns

@bhutz
Copy link
Author

bhutz commented Jul 28, 2016

comment:33

unflatteningmorphism cannot be used by itself since _intermediate rings is defined through section. I'll fix that shortly.

@videlec
Copy link
Contributor

videlec commented Jul 28, 2016

comment:34

You are free to open a new ticket for that issue. Do not change a ticket in positive_review to needs_work. Moreover when it is in that state since a long time and that there are other tickets based on it.

@bhutz
Copy link
Author

bhutz commented Jul 28, 2016

comment:35

ok, so I should mark this back to positive, and then open a new ticket to fix the issue?

@videlec
Copy link
Contributor

videlec commented Jul 28, 2016

comment:36

better, yes.

@bhutz
Copy link
Author

bhutz commented Jul 28, 2016

comment:37

the issue is now #21113

@vbraun
Copy link
Member

vbraun commented Aug 10, 2016

Changed branch from public/21106 to 19cb171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants