From faf2b23e9fa2d925b30e61ce8cf8717335eaf972 Mon Sep 17 00:00:00 2001 From: EnderWannabe Date: Thu, 5 Aug 2021 15:35:21 -0700 Subject: [PATCH 01/98] 32338: initial commit --- .../arithmetic_dynamics/projective_ds.py | 52 ++++++++++++++++--- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py index 7b53546f1ee..308c83ed845 100644 --- a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py +++ b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py @@ -5380,15 +5380,45 @@ def _is_preperiodic(self, P, err=0.1, return_period=False): sage: Q = P.point([a,1]) sage: Q.is_preperiodic(f) True + + :: + + sage: P. = ProjectiveSpace(QQ, 2) + sage: X = P.subscheme(z) + sage: f = DynamicalSystem([x^2 - y^2, y^2, z^2], domain=X) + sage: p = X((-1, 1, 0)) + sage: f._is_preperiodic(p, return_period=True) + (0, 2) + + :: + + sage: R. = QQ[] + sage: K. = NumberField(t^2 - t - 1) + sage: P. = ProjectiveSpace(K, 2) + sage: X = P.subscheme(z) + sage: f = DynamicalSystem([x^2 - y^2, y^2, z^2], domain=X) + sage: p = X((-a + 1, 1, 0)) + sage: f._is_preperiodic(p) + True """ - if not is_ProjectiveSpace(self.codomain()): - raise NotImplementedError("must be over projective space") - if not self.is_morphism(): - raise TypeError("must be a morphism") + codomain = self.codomain() + if not is_ProjectiveSpace(codomain): + # in order to calculate the canonical height, we need + # this map to be a morphism of projective space + ambient_space = codomain.ambient_space() + f = DynamicalSystem(self.defining_polynomials(), domain=ambient_space) + if not f.is_morphism(): + raise ValueError('must be a morphism of projective space') + else: + f = self + if not f.is_morphism(): + raise TypeError("must be a morphism") if not P.codomain() == self.domain(): raise TypeError("point must be in domain of map") - h = self.canonical_height(P, error_bound = err) + # we calculate the canonical height without considering + # if the domain is a subscheme + h = f.canonical_height(P, error_bound = err) # we know canonical height 0 if and only if preperiodic # however precision issues can occur so we can only tell *not* preperiodic # if the value is larger than the error @@ -5398,14 +5428,20 @@ def _is_preperiodic(self, P, err=0.1, return_period=False): # either we can find the cycle or the height is # larger than the difference between the canonical height # and the height, so the canonical height cannot be 0 - B = self.height_difference_bound() + B = f.height_difference_bound() orbit = [P] n = 1 # to compute period - Q = self(P) + try: + Q = self(P) + except TypeError: + raise ValueError('orbit of point leaves domain') H = Q.global_height() while Q not in orbit and H <= B: orbit.append(Q) - Q = self(Q) + try: + Q = self(Q) + except TypeError: + raise ValueError('orbit of point leaves domain') H = Q.global_height() n += 1 if H <= B: #it must have been in the cycle From 5107d3bb209e8499ed19e542d8f9d8b2ce433a7c Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 22 Feb 2023 18:43:06 +0100 Subject: [PATCH 02/98] sync_labels initial --- .github/sync_labels.py | 563 ++++++++++++++++++++++++++++++ .github/workflows/sync_labels.yml | 42 +++ 2 files changed, 605 insertions(+) create mode 100755 .github/sync_labels.py create mode 100644 .github/workflows/sync_labels.yml diff --git a/.github/sync_labels.py b/.github/sync_labels.py new file mode 100755 index 00000000000..f70bc58d45f --- /dev/null +++ b/.github/sync_labels.py @@ -0,0 +1,563 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +r""" +Python script to sync labels that are migrated from Trac selection lists. +""" + +############################################################################## +# Copyright (C) 2023 Sebastian Oehms +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# http://www.gnu.org/licenses/ +############################################################################## + +import os +import sys +from logging import info, warning, getLogger, INFO +from json import loads +from enum import Enum + +class SelectionList(Enum): + """ + Abstract Enum for selection lists. + """ + def succ(self): + """ + Return the successor of `self`. + """ + l = list(self.__class__) + i = l.index(self) + 1 + if i >= len(l): + return None + return l[i] + +class ReviewDecision(Enum): + """ + Enum for `gh pr view` results for `reviewDecision`. + """ + changes_requested = 'CHANGES_REQUESTED' + approved = 'APPROVED' + unclear = 'COMMENTED' + +class Priority(SelectionList): + """ + Enum for priority lables. + """ + blocker = 'p: blocker /1' + critical = 'p: critical /2' + major = 'p: major /3' + minor = 'p: minor /4' + trivial = 'p: trivial /5' + +class State(SelectionList): + """ + Enum for state lables. + """ + positive_review = 's: positive review' + needs_work = 's: needs work' + needs_review = 's: needs review' + needs_info = 's: needs info' + + +def selection_list(label): + """ + Return the selection list to which `label` belongs to. + """ + for sel_list in [Priority, State]: + for item in sel_list: + if label == item.value: + return sel_list + return None + +class GhLabelSynchronizer: + """ + Handler for access to GitHub issue via the `gh` in the bash command line + of the GitHub runner. + """ + def __init__(self, url, actor): + """ + Python constructor sets the issue / PR url and list of active labels. + """ + self._url = url + self._actor = actor + self._labels = None + self._author = None + self._draft = None + self._open = None + self._review_decision = None + self._reviews = None + self._commits = None + + number = os.path.basename(url) + self._pr = True + self._issue = 'pull request #%s' % number + if url.rfind('issue') != -1: + self._issue = 'issue #%s' % number + self._pr = False + info('Create label handler for %s and actor %s' % (self._issue, self._actor)) + + def is_pull_request(self): + """ + Return if we are treating a pull request. + """ + return self._pr + + def view(self, key): + """ + Return data obtained from `gh` command `view`. + """ + issue = 'issue' + if self._pr: + issue = 'pr' + cmd = 'gh %s view %s --json %s' % (issue, self._url, key) + from subprocess import check_output + return loads(check_output(cmd, shell=True))[key] + + def is_open(self): + """ + Return if the issue res. PR is open. + """ + if self._open is not None: + return self._open + if self.view('state') == 'OPEN': + self._open = True + else: + self._open = False + info('Issue %s is open %s' % (self._issue, self._open)) + return self._open + + def is_draft(self): + """ + Return if the PR is a draft. + """ + if self._draft is not None: + return self._draft + if self.is_pull_request(): + self._draft = self.view('isDraft') + else: + self._draft = False + info('Issue %s is draft %s' % (self._issue, self._draft)) + return self._draft + + def get_labels(self): + """ + Return the list of labels of the issue resp. PR. + """ + if self._labels is not None: + return self._labels + data = self.view('labels') + self._labels = [l['name'] for l in data] + info('List of labels for %s: %s' % (self._issue, self._labels)) + return self._labels + + def get_author(self): + """ + Return the author of the issue resp. PR. + """ + if self._author is not None: + return self._author + data = self.view('author') + self._author = self.view('author')['login'] + info('Author of %s: %s' % (self._issue, self._author)) + return self._author + + def get_review_decision(self): + """ + Return the reviewDecision of the PR. + """ + if not self.is_pull_request(): + return None + + if self._review_decision is not None: + return self._review_decision + + data = self.view('reviewDecision') + if data: + self._review_decision = ReviewDecision(data) + else: + self._review_decision = ReviewDecision.unclear + info('Review decision for %s: %s' % (self._issue, self._review_decision.value)) + return self._review_decision + + def get_reviews(self): + """ + Return the list of reviews of the PR. + """ + if not self.is_pull_request(): + return None + + if self._reviews is not None: + return self._reviews + + self._reviews = self.view('reviews') + info('Reviews for %s: %s' % (self._issue, self._reviews)) + return self._reviews + + def get_commits(self): + """ + Return the list of commits of the PR. + """ + if not self.is_pull_request(): + return None + + if self._commits is not None: + return self._commits + + self._commits = self.view('commits') + info('Commits for %s: %s' % (self._issue, self._commits)) + return self._commits + + def gh_cmd(self, cmd, arg, option): + """ + Perform a system call to `gh` for `cmd` to an isuue resp. PR. + """ + issue = 'issue' + if self._pr: + issue = 'pr' + cmd_str = 'gh %s %s %s %s "%s"' % (issue, cmd, self._url, option, arg) + os.system(cmd_str) + + def edit(self, arg, option): + """ + Perform a system call to `gh` to edit an issue resp. PR. + """ + self.gh_cmd('edit', arg, option) + + def review(self, arg, text): + """ + Perform a system call to `gh` to review a PR. + """ + self.gh_cmd('review', arg, '-b %s' % text) + + def active_partners(self, item): + """ + Return the list of other labels from the selection list + of the given one that are already present on the issue / PR. + """ + sel_list = type(item) + partners = [i for i in sel_list if i != item and i.value in self.get_labels()] + info('Active partners of %s: %s' % (item, partners)) + return partners + + def needs_work(self, only_actor=True): + """ + Return `True` if the PR needs work. This is the case if + the review decision requests changes or if there is any + review reqesting changes. + """ + ch_req = ReviewDecision.changes_requested + rev_dec = self.get_review_decision() + if rev_dec: + if rev_dec == ch_req: + info('PR %s needs work (by decision)' % self._issue) + return True + else: + info('PR %s doesn\'t need work (by decision)' % self._issue) + return False + + revs = self.get_reviews() + if only_actor: + revs = [rev for rev in revs if rev['author']['login'] == self._actor] + if any(rev['state'] == ch_req.value for rev in revs): + info('PR %s needs work' % self._issue) + return True + info('PR %s doesn\'t need work' % self._issue) + return False + + def positive_review(self, only_actor=True): + """ + Return `True` if the PR has positive review. This is the + case if the review decision is approved or if there is any + approved review but no changes requesting one. + """ + appr = ReviewDecision.approved + rev_dec = self.get_review_decision() + if rev_dec: + if rev_dec == appr: + info('PR %s has positve review (by decision)' % self._issue) + return True + else: + info('PR %s doesn\'t have positve review (by decision)' % self._issue) + return False + + if self.needs_work(): + info('PR %s doesn\'t have positve review (needs work)' % self._issue) + return False + + revs = self.get_reviews() + if only_actor: + revs = [rev for rev in revs if rev['author']['login'] == self._actor] + if any(rev['state'] == appr.value for rev in revs): + info('PR %s has positve review (by decision)' % self._issue) + return True + info('PR %s doesn\'t have positve review (needs work)' % self._issue) + return False + + def approve_allowed(self): + """ + Return if the actor has permission to approve this PR. + """ + author = self.get_author() + revs = self.get_reviews() + if not any(rev['author']['authorAssociation'] == 'MEMBER' for rev in revs): + info('PR %s can\'t be approved because of missing member review' % (self._issue)) + return False + + revs = [rev for rev in revs if rev['author']['login'] != self._actor] + ch_req = ReviewDecision.changes_requested + if any(rev['state'] == ch_req.value for rev in revs): + info('PR %s can\'t be approved by %s since others reqest changes' % (self._issue, self._actor)) + return False + + if author != self._actor: + info('PR %s can be approved by %s' % (self._issue, self._actor)) + return True + + revs = [rev for rev in revs if rev['author']['login'] != 'github-actions'] + if not revs: + info('PR %s can\'t be approved by the author %s since no other person reviewed it' % (self._issue, self._actor)) + return False + + comts = self.get_commits() + authors = sum(com['authors'] for com in comts) + authors = [auth for auth in authors if not auth['login'] in (self._actor, 'github-actions')] + if not authors: + info('PR %s can\'t be approved by the author %s since no other person commited to it' % (self._issue, self._actor)) + return False + + info('PR %s can be approved by the author %s as co-author' % (self._issue, self._actor)) + return True + + def approve(self): + """ + Approve the PR by the actor. + """ + self.review('--approve', '%s approved this PR' % self._actor) + info('PR %s approved by %s' % (self._issue, self._actor)) + + def request_changes(self): + """ + Request changes for this PR by the actor. + """ + self.review('--request-changes', '%s requested changes for this PR' % self._actor) + info('Changes requested for PR %s by %s' % (self._issue, self._actor)) + + def add_comment(self, text): + """ + Perform a system call to `gh` to add a comment to an issue or PR. + """ + + self.gh_cmd('comment', text, '-b') + info('Add comment to %s: %s' % (self._issue, text)) + + def add_label(self, label): + """ + Add the given label to the issue or PR. + """ + if not label in self.get_labels(): + self.edit(label, '--add-label') + info('Add label to %s: %s' % (self._issue, label)) + + def add_default_label(self, item): + """ + Add the given label if there is no active partner. + """ + if not self.active_partners(item): + self.add_label(item.value) + + def on_label_add(self, label): + """ + Check if the given label belongs to a selection list. If so, remove + all other labels of that list. In case of a state label reviews are + booked accordingly. + """ + sel_list = selection_list(label) + if not sel_list: + return + + item = sel_list(label) + if label not in self.get_labels(): + # this is possible if two labels of the same selection list + # have been added in one step (via multiple selection in the + # pull down menue). In this case `label` has been removed + # on the `on_label_add` of the first of the two labels + partn = self.active_partners(item) + if partn: + self.add_comment('Label *%s* can not be added due to *%s*!' % (label, partn[0].value)) + else: + warning('Label %s of %s not found!' % (label, self._issue)) + return + + if sel_list is State: + if not self.is_pull_request(): + if item != State.needs_info: + self.add_comment('Label *%s* can not be added to an issue. Please use it on the corresponding PR' % label) + self.remove_label(label) + return + + if item == State.positive_review: + if self.approve_allowed(): + self.approve() + elif self.needs_work(): + # PR still needs work + self.add_comment('Label *%s* can not be added. Please use the corresponding functionality of GitHub' % label) + self.select_label(State.needs_work) + return + else: + # PR still needs review + self.add_comment('Label *%s* can not be added. Please use the corresponding functionality of GitHub' % label) + if self.is_draft(): + self.remove_label(label) + else: + self.select_label(State.needs_review) + return + + if item == State.needs_work: + self.request_changes() + if not self.needs_work(): + # change request of actor could not be set + self.add_comment('Label *%s* can not be added. Please use the corresponding functionality of GitHub' % label) + if self.is_draft(): + self.remove_label(label) + else: + self.select_label(State.needs_review) + return + + for other in sel_list: + if other != item: + self.remove_label(other.value) + + def select_label(self, item): + """ + Add the given label and remove all others. + """ + self.add_label(item.value) + sel_list = type(item) + for other in sel_list: + if other != item: + self.remove_label(other.value) + + def remove_label(self, label): + """ + Remove the given label from the issue or PR of the handler. + """ + if label in self.get_labels(): + self.edit(label, '--remove-label') + info('Remove label from %s: %s' % (self._issue, label)) + + def on_label_remove(self, label): + """ + Check if the given label belongs to a selection list. If so, the + successor of the label is added except there is none or there + exists another label of the corresponding list. In case of a + state label reviews are booked accordingly. + """ + sel_list = selection_list(label) + if not sel_list: + return + + item = sel_list(label) + if label in self.get_labels(): + # this is possible if two labels of the same selection list + # have been removed in one step (via multiple selection in the + # pull down menue). In this case `label` has been added + # on the `on_label_remove` of the first of the two labels. + partn = self.active_partners(item) + if partn: + self.on_label_add(partn[0].value) + return + + if sel_list is State: + if not self.is_pull_request(): + return + if item == State.positive_review: + if self.positive_review(): + self.request_changes() + self.select_label(State.needs_work) + elif self.positive_review(only_actor=False): + self.add_comment('Label *%s* can not be removed. Please use the corresponding functionality of GitHub' % label) + self.select_label(item) + elif not self.is_draft(): + self.select_label(State.needs_review) + return + elif item == State.needs_work: + if self.needs_work(only_actor=False): + self.add_comment('Label *%s* can not be removed. Please use the corresponding functionality of GitHub' % label) + self.select_label(item) + elif not self.is_draft(): + self.select_label(State.needs_review) + return + + if not self.active_partners(item): + # if there is no other in the same selection list + # add the next weaker label if it exists + succ = sel_list(label).succ() + if succ: + self.select_label(succ) + + def on_converted_to_draft(self): + """ + Remove all state labels. + """ + for item in State: + self.remove_label(item.value) + + +############################################################################### +# Main +############################################################################### +cmdline_args = sys.argv[1:] + +getLogger().setLevel(INFO) +info('cmdline_args (%s) %s' % (len(cmdline_args), cmdline_args)) + +if len(cmdline_args) < 4: + print('Need 5 arguments: action, url, actor, label, rev_state' ) + exit +else: + action, url, actor, label, rev_state = cmdline_args + +info('action: %s' % action) +info('url: %s' % url) +info('label: %s' % label) +info('actor: %s' % actor) +info('rev_state: %s' % rev_state) + +gh = GhLabelSynchronizer(url, actor) + +if action in ('opened', 'reopened'): + if gh.is_pull_request(): + if not gh.is_draft(): + gh.add_default_label(State.needs_review) + +if action in ('closed', 'reopened'): + for lab in State: + gh.remove_label(lab.value) + +if action == 'labeled': + gh.on_label_add(label) + +if action == 'unlabeled': + gh.on_label_remove(label) + +if action == 'ready_for_review': + gh.select_label(State.needs_review) + +if action == 'converted_to_draft': + gh.on_converted_to_draft() + +if action == 'submitted': + if rev_state == 'approved': + if gh.positive_review(): + gh.select_label(State.positive_review) + + if rev_state == 'changes_requested': + if gh.needs_work(): + gh.select_label(State.needs_work) + +if action in ('review_requested', 'ready_for_review'): + gh.select_label(State.needs_review) diff --git a/.github/workflows/sync_labels.yml b/.github/workflows/sync_labels.yml new file mode 100644 index 00000000000..4e11a94277d --- /dev/null +++ b/.github/workflows/sync_labels.yml @@ -0,0 +1,42 @@ +# This workflow synchronizes groups of labels that correspond +# to items of selection list in Trac. It controls that in each +# such case there is just one label of the list present. +# Furthermore in the case of the state it checks the labels +# to coincide with the corresponding review state. + +name: Synchronize selection list lables + +on: + pull_request_review: + types: [submitted] + issues: + types: [opened, reopened, closed, labeled, unlabeled] + pull_request: + types: [opened, reopened, closed, ready_for_review, converted_to_draft, labeled, unlabeled] + pull_request_target: + types: [opened, reopened, closed, ready_for_review, converted_to_draft, labeled, unlabeled] + +jobs: + synchronize: + runs-on: ubuntu-latest + steps: + # Download the Python script + - name: Download script + id: download + run: | + curl -L -O "https://raw.githubusercontent.com/"$REPO"/master/.github/sync_labels.py" + chmod a+x sync_labels.py + env: + REPO: ${{ github.repository }} + + # Perform synchronization + - name: Call script + run: ./sync_labels.py $ACTION $ISSUE_URL $PR_URL $ACTOR "$LABEL" "$REV_STATE" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ACTION: ${{ github.event.action }} + ISSUE_URL: ${{ github.event.issue.html_url }} + PR_URL: ${{ github.event.pull_request.html_url }} + ACTOR: ${{ github.actor }} + LABEL: ${{ github.event.label.name }} + REV_STATE: ${{ github.event.review.state }} From a150e2ee293cadb1998d34f9fd3fd3da0594a0d7 Mon Sep 17 00:00:00 2001 From: Cyril Bouvier Date: Tue, 7 Mar 2023 17:27:00 +0100 Subject: [PATCH 03/98] GenericGraph.adjacency_matrix: using sort=True when getting vertices --- src/sage/graphs/generic_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 38e1f8d5751..2f9a5929378 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -1926,7 +1926,7 @@ def adjacency_matrix(self, sparse=None, vertices=None, *, base_ring=None, **kwds sparse = False if vertices is None: - vertices = self.vertices(sort=True) + vertices = self.vertices(sort=False) elif (len(vertices) != n or set(vertices) != set(self.vertex_iterator())): raise ValueError("``vertices`` must be a permutation of the vertices") From 17bea0a1b2f92d4312e86319df743644dab3c1bf Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 8 Mar 2023 07:57:49 +0100 Subject: [PATCH 04/98] sync_labels refactoring and extension --- .github/sync_labels.py | 484 ++++++++++++++++++------------ .github/workflows/sync_labels.yml | 4 +- 2 files changed, 295 insertions(+), 193 deletions(-) diff --git a/.github/sync_labels.py b/.github/sync_labels.py index f70bc58d45f..7d64ca4526e 100755 --- a/.github/sync_labels.py +++ b/.github/sync_labels.py @@ -21,31 +21,46 @@ from json import loads from enum import Enum -class SelectionList(Enum): +class Action(Enum): """ - Abstract Enum for selection lists. + Enum for GitHub event ``action``. """ - def succ(self): - """ - Return the successor of `self`. - """ - l = list(self.__class__) - i = l.index(self) + 1 - if i >= len(l): - return None - return l[i] + opened = 'opened' + reopened = 'reopened' + closed = 'closed' + labeled = 'labeled' + unlabeled = 'unlabeled' + ready_for_review = 'ready_for_review' + synchronize = 'synchronize' + review_requested = 'review_requested' + converted_to_draft = 'converted_to_draft' + submitted = 'submitted' + +class RevState(Enum): + """ + Enum for GitHub event ``review_state``. + """ + commented = 'commented' + approved = 'approved' + changes_requested = 'changes_requested' class ReviewDecision(Enum): """ - Enum for `gh pr view` results for `reviewDecision`. + Enum for ``gh pr view`` results for ``reviewDecision``. """ changes_requested = 'CHANGES_REQUESTED' approved = 'APPROVED' unclear = 'COMMENTED' +class SelectionList(Enum): + """ + Abstract Enum for selection lists. + """ + pass + class Priority(SelectionList): """ - Enum for priority lables. + Enum for priority labels. """ blocker = 'p: blocker /1' critical = 'p: critical /2' @@ -55,7 +70,7 @@ class Priority(SelectionList): class State(SelectionList): """ - Enum for state lables. + Enum for state labels. """ positive_review = 's: positive review' needs_work = 's: needs work' @@ -91,6 +106,7 @@ def __init__(self, url, actor): self._review_decision = None self._reviews = None self._commits = None + self._commit_date = None number = os.path.basename(url) self._pr = True @@ -100,6 +116,9 @@ def __init__(self, url, actor): self._pr = False info('Create label handler for %s and actor %s' % (self._issue, self._actor)) + # ------------------------------------------------------------------------- + # methods to obtain properties of the issue + # ------------------------------------------------------------------------- def is_pull_request(self): """ Return if we are treating a pull request. @@ -165,6 +184,21 @@ def get_author(self): info('Author of %s: %s' % (self._issue, self._author)) return self._author + def get_commits(self): + """ + Return the list of commits of the PR. + """ + if not self.is_pull_request(): + return None + + if self._commits is not None: + return self._commits + + self._commits = self.view('commits') + self._commit_date = max( com['committedDate'] for com in self._commits ) + info('Commits until %s for %s: %s' % (self._commit_date, self._issue, self._commits)) + return self._commits + def get_review_decision(self): """ Return the reviewDecision of the PR. @@ -183,55 +217,29 @@ def get_review_decision(self): info('Review decision for %s: %s' % (self._issue, self._review_decision.value)) return self._review_decision - def get_reviews(self): + def get_reviews(self, complete=False): """ - Return the list of reviews of the PR. + Return the list of reviews of the PR. Per default only those reviews + are returned which have been submitted after the youngest commit. + Use keyword ``complete`` to get them all. """ if not self.is_pull_request(): return None - if self._reviews is not None: - return self._reviews - - self._reviews = self.view('reviews') - info('Reviews for %s: %s' % (self._issue, self._reviews)) - return self._reviews - - def get_commits(self): - """ - Return the list of commits of the PR. - """ - if not self.is_pull_request(): - return None + if self._reviews is None: + self._reviews = self.view('reviews') + info('Reviews for %s: %s' % (self._issue, self._reviews)) - if self._commits is not None: - return self._commits + if complete or not self._reviews: + return self._reviews - self._commits = self.view('commits') - info('Commits for %s: %s' % (self._issue, self._commits)) - return self._commits + if self._commit_date is None: + self.get_commits() - def gh_cmd(self, cmd, arg, option): - """ - Perform a system call to `gh` for `cmd` to an isuue resp. PR. - """ - issue = 'issue' - if self._pr: - issue = 'pr' - cmd_str = 'gh %s %s %s %s "%s"' % (issue, cmd, self._url, option, arg) - os.system(cmd_str) - - def edit(self, arg, option): - """ - Perform a system call to `gh` to edit an issue resp. PR. - """ - self.gh_cmd('edit', arg, option) - - def review(self, arg, text): - """ - Perform a system call to `gh` to review a PR. - """ - self.gh_cmd('review', arg, '-b %s' % text) + date = self._commit_date + new_revs = [rev for rev in self._reviews if rev['submittedAt'] > date] + info('Reviews for %s: %s after %s' % (self._issue, self._reviews, date)) + return new_revs def active_partners(self, item): """ @@ -243,7 +251,10 @@ def active_partners(self, item): info('Active partners of %s: %s' % (item, partners)) return partners - def needs_work(self, only_actor=True): + # ------------------------------------------------------------------------- + # methods to validate the issue state + # ------------------------------------------------------------------------- + def needs_work_valid(self): """ Return `True` if the PR needs work. This is the case if the review decision requests changes or if there is any @@ -260,15 +271,14 @@ def needs_work(self, only_actor=True): return False revs = self.get_reviews() - if only_actor: - revs = [rev for rev in revs if rev['author']['login'] == self._actor] + revs = [rev for rev in revs if rev['author']['login'] == self._actor] if any(rev['state'] == ch_req.value for rev in revs): info('PR %s needs work' % self._issue) return True info('PR %s doesn\'t need work' % self._issue) return False - def positive_review(self, only_actor=True): + def positive_review_valid(self): """ Return `True` if the PR has positive review. This is the case if the review decision is approved or if there is any @@ -284,46 +294,73 @@ def positive_review(self, only_actor=True): info('PR %s doesn\'t have positve review (by decision)' % self._issue) return False - if self.needs_work(): + if self.needs_work_valid(): info('PR %s doesn\'t have positve review (needs work)' % self._issue) return False revs = self.get_reviews() - if only_actor: - revs = [rev for rev in revs if rev['author']['login'] == self._actor] - if any(rev['state'] == appr.value for rev in revs): - info('PR %s has positve review (by decision)' % self._issue) - return True - info('PR %s doesn\'t have positve review (needs work)' % self._issue) + revs = [rev for rev in revs if rev['author']['login'] == self._actor] + if any(rev['state'] == appr.value for rev in revs): + info('PR %s has positve review' % self._issue) + return True + info('PR %s doesn\'t have positve review' % self._issue) return False + def needs_review_valid(self): + """ + Return ``True`` if the PR needs review. This is the case if + all proper reviews are older than the youngest commit. + """ + if self.is_draft(): + return False + + if self.needs_work_valid(): + info('PR %s already under review (needs work)' % self._issue) + return False + + if self.positive_review_valid(): + info('PR %s already reviewed' % self._issue) + return False + + info('PR %s needs review' % self._issue) + return True + def approve_allowed(self): """ Return if the actor has permission to approve this PR. """ - author = self.get_author() - revs = self.get_reviews() - if not any(rev['author']['authorAssociation'] == 'MEMBER' for rev in revs): + revs = self.get_reviews(complete=True) + if not any(rev['authorAssociation'] in ('MEMBER', 'OWNER') for rev in revs): info('PR %s can\'t be approved because of missing member review' % (self._issue)) return False + revs = self.get_reviews() revs = [rev for rev in revs if rev['author']['login'] != self._actor] ch_req = ReviewDecision.changes_requested if any(rev['state'] == ch_req.value for rev in revs): info('PR %s can\'t be approved by %s since others reqest changes' % (self._issue, self._actor)) return False + return self.actor_valid() + + def actor_valid(self): + """ + Return if the actor has permission to approve this PR. + """ + author = self.get_author() + if author != self._actor: info('PR %s can be approved by %s' % (self._issue, self._actor)) return True + revs = self.get_reviews() revs = [rev for rev in revs if rev['author']['login'] != 'github-actions'] if not revs: info('PR %s can\'t be approved by the author %s since no other person reviewed it' % (self._issue, self._actor)) return False - comts = self.get_commits() - authors = sum(com['authors'] for com in comts) + coms = self.get_commits() + authors = sum(com['authors'] for com in coms) authors = [auth for auth in authors if not auth['login'] in (self._actor, 'github-actions')] if not authors: info('PR %s can\'t be approved by the author %s since no other person commited to it' % (self._issue, self._actor)) @@ -332,6 +369,34 @@ def approve_allowed(self): info('PR %s can be approved by the author %s as co-author' % (self._issue, self._actor)) return True + # ------------------------------------------------------------------------- + # methods to change the issue + # ------------------------------------------------------------------------- + def gh_cmd(self, cmd, arg, option): + """ + Perform a system call to `gh` for `cmd` to an isuue resp. PR. + """ + issue = 'issue' + if self._pr: + issue = 'pr' + cmd_str = 'gh %s %s %s %s "%s"' % (issue, cmd, self._url, option, arg) + info('Execute command: %s' % cmd_str) + ex_code = os.system(cmd_str) + if ex_code: + warning('Execution of %s failed with exit code: %s' % (cmd_str, ex_code)) + + def edit(self, arg, option): + """ + Perform a system call to `gh` to edit an issue resp. PR. + """ + self.gh_cmd('edit', arg, option) + + def review(self, arg, text): + """ + Perform a system call to `gh` to review a PR. + """ + self.gh_cmd('review', arg, '-b \"%s\"' % text) + def approve(self): """ Approve the PR by the actor. @@ -369,6 +434,52 @@ def add_default_label(self, item): if not self.active_partners(item): self.add_label(item.value) + def select_label(self, item): + """ + Add the given label and remove all others. + """ + self.add_label(item.value) + sel_list = type(item) + for other in sel_list: + if other != item: + self.remove_label(other.value) + + def remove_label(self, label): + """ + Remove the given label from the issue or PR of the handler. + """ + if label in self.get_labels(): + self.edit(label, '--remove-label') + info('Remove label from %s: %s' % (self._issue, label)) + + def reject_label_addition(self, item): + """ + Post a comment that the given label can not be added and select + a corresponding other one. + """ + if self.is_pull_request(): + self.add_comment('Label *%s* can not be added. Please use the corresponding functionality of GitHub' % item.value) + else: + self.add_comment('Label *%s* can not be added to an issue. Please use it on the corresponding PR' % label) + self.remove_label(label) + return + + def reject_label_removal(self, item): + """ + Post a comment that the given label can not be removed and select + a corresponding other one. + """ + if type(item) == State: + sel_list = 'state' + else: + sel_list = 'priority' + self.add_comment('Label *%s* can not be removed. Please add the %s-label which should replace it' % (label, sel_list)) + self.add_label(item.value) + return + + # ------------------------------------------------------------------------- + # methods to act on events + # ------------------------------------------------------------------------- def on_label_add(self, label): """ Check if the given label belongs to a selection list. If so, remove @@ -395,169 +506,160 @@ def on_label_add(self, label): if sel_list is State: if not self.is_pull_request(): if item != State.needs_info: - self.add_comment('Label *%s* can not be added to an issue. Please use it on the corresponding PR' % label) - self.remove_label(label) + self.reject_label_addition(item) + return + + if item == State.needs_review: + if not self.needs_review_valid(): + self.reject_label_addition(item) return if item == State.positive_review: if self.approve_allowed(): self.approve() - elif self.needs_work(): - # PR still needs work - self.add_comment('Label *%s* can not be added. Please use the corresponding functionality of GitHub' % label) - self.select_label(State.needs_work) - return else: - # PR still needs review - self.add_comment('Label *%s* can not be added. Please use the corresponding functionality of GitHub' % label) - if self.is_draft(): - self.remove_label(label) - else: - self.select_label(State.needs_review) + self.reject_label_addition(item) return if item == State.needs_work: - self.request_changes() - if not self.needs_work(): - # change request of actor could not be set - self.add_comment('Label *%s* can not be added. Please use the corresponding functionality of GitHub' % label) - if self.is_draft(): - self.remove_label(label) - else: - self.select_label(State.needs_review) + if self.needs_review_valid(): + self.request_changes() + else: + self.reject_label_addition(item) return for other in sel_list: if other != item: self.remove_label(other.value) - def select_label(self, item): - """ - Add the given label and remove all others. - """ - self.add_label(item.value) - sel_list = type(item) - for other in sel_list: - if other != item: - self.remove_label(other.value) - - def remove_label(self, label): - """ - Remove the given label from the issue or PR of the handler. - """ - if label in self.get_labels(): - self.edit(label, '--remove-label') - info('Remove label from %s: %s' % (self._issue, label)) - - def on_label_remove(self, label): + def on_label_removal(self, label): """ Check if the given label belongs to a selection list. If so, the - successor of the label is added except there is none or there - exists another label of the corresponding list. In case of a - state label reviews are booked accordingly. + removement is rejected and a comment is posted to instead add a + replacement for ``label`` from the list. Exceptions are State labels + on issues and State.needs_info on a PR. """ sel_list = selection_list(label) if not sel_list: return item = sel_list(label) - if label in self.get_labels(): - # this is possible if two labels of the same selection list - # have been removed in one step (via multiple selection in the - # pull down menue). In this case `label` has been added - # on the `on_label_remove` of the first of the two labels. - partn = self.active_partners(item) - if partn: - self.on_label_add(partn[0].value) - return - if sel_list is State: - if not self.is_pull_request(): - return - if item == State.positive_review: - if self.positive_review(): - self.request_changes() - self.select_label(State.needs_work) - elif self.positive_review(only_actor=False): - self.add_comment('Label *%s* can not be removed. Please use the corresponding functionality of GitHub' % label) - self.select_label(item) - elif not self.is_draft(): - self.select_label(State.needs_review) - return - elif item == State.needs_work: - if self.needs_work(only_actor=False): - self.add_comment('Label *%s* can not be removed. Please use the corresponding functionality of GitHub' % label) - self.select_label(item) - elif not self.is_draft(): - self.select_label(State.needs_review) - return - - if not self.active_partners(item): - # if there is no other in the same selection list - # add the next weaker label if it exists - succ = sel_list(label).succ() - if succ: - self.select_label(succ) + if self.is_pull_request(): + if item != State.needs_info: + self.reject_label_removal(item) + elif sel_list is Priority: + self.reject_label_removal(item) + return - def on_converted_to_draft(self): + def remove_all_state_labels(self): """ Remove all state labels. """ for item in State: self.remove_label(item.value) + def run(self, action, label=None, rev_state=None): + """ + Run the given action. + """ + if action is Action.opened and self.is_pull_request(): + if not self.is_draft(): + self.add_default_label(State.needs_review) + + if action in (Action.closed, Action.reopened, Action.converted_to_draft): + self.remove_all_state_labels() + + if action is Action.labeled: + self.on_label_add(label) + + if action is Action.unlabeled: + self.on_label_removal(label) + + if action in (Action.ready_for_review, Action.synchronize): + if self.needs_review_valid(): + self.select_label(State.needs_review) + + if action is Action.review_requested: + self.select_label(State.needs_review) + + if action is Action.submitted: + if rev_state is RevState.approved: + if self.positive_review_valid(): + self.select_label(State.positive_review) + + if rev_state is RevState.changes_requested: + if self.needs_work_valid(): + self.select_label(State.needs_work) + + def run_tests(self): + """ + Simulative run over all posibble events. + + This is not intended to validate all functionality. It just + tests for bugs on invoking the methods. The result in the + issue or PR depends on timing. Note that the GitHub action runner + may run in parallel on the triggered events possibly on an other + version of the code. + """ + self.add_comment('Starting tests for sync_labels') + for action in Action: + self.add_comment('Test action %s' % action.value) + if action in (Action.labeled, Action.unlabeled): + for stat in State: + if action is Action.labeled: + self.add_label(stat.value) + else: + self.remove_label(stat.value) + self.run(action, label=stat) + for prio in Priority: + if action is Action.labeled: + self.add_label(prio.value) + else: + self.remove_label(prio.value) + self.run(action, label=prio) + elif action == Action.submitted and self.is_pull_request(): + for stat in RevState: + if stat is RevState.approved: + self.approve() + elif stat is RevState.changes_requested: + self.request_changes() + self.run(action, rev_state=stat) + elif self.is_pull_request(): + self.run(action) + ############################################################################### # Main ############################################################################### cmdline_args = sys.argv[1:] +num_args = len(cmdline_args) getLogger().setLevel(INFO) -info('cmdline_args (%s) %s' % (len(cmdline_args), cmdline_args)) +info('cmdline_args (%s) %s' % (num_args, cmdline_args)) -if len(cmdline_args) < 4: - print('Need 5 arguments: action, url, actor, label, rev_state' ) - exit -else: +if num_args == 5: action, url, actor, label, rev_state = cmdline_args + action = Action(action) -info('action: %s' % action) -info('url: %s' % url) -info('label: %s' % label) -info('actor: %s' % actor) -info('rev_state: %s' % rev_state) - -gh = GhLabelSynchronizer(url, actor) + info('action: %s' % action) + info('url: %s' % url) + info('actor: %s' % actor) + info('label: %s' % label) + info('rev_state: %s' % rev_state) -if action in ('opened', 'reopened'): - if gh.is_pull_request(): - if not gh.is_draft(): - gh.add_default_label(State.needs_review) + gh = GhLabelSynchronizer(url, actor) + gh.run(action, label=label, rev_state=rev_state) -if action in ('closed', 'reopened'): - for lab in State: - gh.remove_label(lab.value) +elif num_args == 2: + url, actor = cmdline_args -if action == 'labeled': - gh.on_label_add(label) + info('url: %s' % url) + info('actor: %s' % actor) -if action == 'unlabeled': - gh.on_label_remove(label) + gh = GhLabelSynchronizer(url, actor) + gh.run_tests() -if action == 'ready_for_review': - gh.select_label(State.needs_review) - -if action == 'converted_to_draft': - gh.on_converted_to_draft() - -if action == 'submitted': - if rev_state == 'approved': - if gh.positive_review(): - gh.select_label(State.positive_review) - - if rev_state == 'changes_requested': - if gh.needs_work(): - gh.select_label(State.needs_work) - -if action in ('review_requested', 'ready_for_review'): - gh.select_label(State.needs_review) +else: + print('Need 5 arguments: action, url, actor, label, rev_state' ) + print('Running tests is possible with 2 arguments: url, actor' ) diff --git a/.github/workflows/sync_labels.yml b/.github/workflows/sync_labels.yml index 4e11a94277d..84250589297 100644 --- a/.github/workflows/sync_labels.yml +++ b/.github/workflows/sync_labels.yml @@ -12,9 +12,9 @@ on: issues: types: [opened, reopened, closed, labeled, unlabeled] pull_request: - types: [opened, reopened, closed, ready_for_review, converted_to_draft, labeled, unlabeled] + types: [opened, reopened, closed, ready_for_review, converted_to_draft, synchronize, labeled, unlabeled] pull_request_target: - types: [opened, reopened, closed, ready_for_review, converted_to_draft, labeled, unlabeled] + types: [opened, reopened, closed, ready_for_review, converted_to_draft, synchronize, labeled, unlabeled] jobs: synchronize: From 094b50056c7330803700608934d1bd5e91993ffa Mon Sep 17 00:00:00 2001 From: Cyril Bouvier Date: Thu, 9 Mar 2023 09:50:34 +0100 Subject: [PATCH 05/98] GenericGraph.adjacency_matrix: revert + better error message + tests and doc --- src/sage/graphs/generic_graph.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 2f9a5929378..a040e6d45c8 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -1799,6 +1799,8 @@ def adjacency_matrix(self, sparse=None, vertices=None, *, base_ring=None, **kwds the vertices defining how they should appear in the matrix. By default, the ordering given by :meth:`GenericGraph.vertices` with ``sort=True`` is used. + If the vertices are not comparable, the keyword ``vertices`` must be + used to specify an ordering, or a TypeError exception will be raised. - ``base_ring`` -- a ring (default: ``ZZ``); the base ring of the matrix space to use. @@ -1918,6 +1920,14 @@ def adjacency_matrix(self, sparse=None, vertices=None, *, base_ring=None, **kwds Traceback (most recent call last): ... ValueError: ``vertices`` must be a permutation of the vertices + sage: Graph ([[0, 42, 'John'], [(42, 'John')]]).adjacency_matrix() + Traceback (most recent call last): + ... + TypeError: Vertices are not comparable, you must used the ``vertices`` parameter of the ``adjacency_matrix`` method to specify an ordering + sage: Graph ([[0, 42, 'John'], [(42, 'John')]]).adjacency_matrix(vertices=['John', 42, 0]) + [0 1 0] + [1 0 0] + [0 0 0] """ n = self.order() if sparse is None: @@ -1926,7 +1936,10 @@ def adjacency_matrix(self, sparse=None, vertices=None, *, base_ring=None, **kwds sparse = False if vertices is None: - vertices = self.vertices(sort=False) + try: + vertices = self.vertices(sort=True) + except TypeError: + raise TypeError ("Vertices are not comparable, you must used the ``vertices`` parameter of the ``adjacency_matrix`` method to specify an ordering") elif (len(vertices) != n or set(vertices) != set(self.vertex_iterator())): raise ValueError("``vertices`` must be a permutation of the vertices") From 96e8e7dd6ae752a54b50003a5ce7e1311bac378f Mon Sep 17 00:00:00 2001 From: Sebastian Oehms Date: Fri, 10 Mar 2023 08:54:23 +0100 Subject: [PATCH 06/98] sync_labels: add reset_view and typos --- .github/sync_labels.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/.github/sync_labels.py b/.github/sync_labels.py index 7d64ca4526e..036e1147472 100755 --- a/.github/sync_labels.py +++ b/.github/sync_labels.py @@ -125,6 +125,19 @@ def is_pull_request(self): """ return self._pr + def reset_view(self): + """ + Reset cache of ``gh view`` results. + """ + self._labels = None + self._author = None + self._draft = None + self._open = None + self._review_decision = None + self._reviews = None + self._commits = None + self._commit_date = None + def view(self, key): """ Return data obtained from `gh` command `view`. @@ -460,8 +473,8 @@ def reject_label_addition(self, item): if self.is_pull_request(): self.add_comment('Label *%s* can not be added. Please use the corresponding functionality of GitHub' % item.value) else: - self.add_comment('Label *%s* can not be added to an issue. Please use it on the corresponding PR' % label) - self.remove_label(label) + self.add_comment('Label *%s* can not be added to an issue. Please use it on the corresponding PR' % item.value) + self.remove_label(item.value) return def reject_label_removal(self, item): @@ -473,7 +486,7 @@ def reject_label_removal(self, item): sel_list = 'state' else: sel_list = 'priority' - self.add_comment('Label *%s* can not be removed. Please add the %s-label which should replace it' % (label, sel_list)) + self.add_comment('Label *%s* can not be removed. Please add the %s-label which should replace it' % (item.value, sel_list)) self.add_label(item.value) return @@ -563,6 +576,8 @@ def run(self, action, label=None, rev_state=None): """ Run the given action. """ + self.reset_view() # this is just needed for run_tests + if action is Action.opened and self.is_pull_request(): if not self.is_draft(): self.add_default_label(State.needs_review) @@ -611,20 +626,20 @@ def run_tests(self): self.add_label(stat.value) else: self.remove_label(stat.value) - self.run(action, label=stat) + self.run(action, label=stat.value) for prio in Priority: if action is Action.labeled: self.add_label(prio.value) else: self.remove_label(prio.value) - self.run(action, label=prio) + self.run(action, label=prio.value) elif action == Action.submitted and self.is_pull_request(): for stat in RevState: if stat is RevState.approved: self.approve() elif stat is RevState.changes_requested: self.request_changes() - self.run(action, rev_state=stat) + self.run(action, rev_state=stat.value) elif self.is_pull_request(): self.run(action) From 9abdff3b9586f690be94dbdc2b67601f7d65fbb2 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 13 Mar 2023 08:03:02 +0100 Subject: [PATCH 07/98] sync_labels_checkout_files initial --- .github/workflows/sync_labels.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/sync_labels.yml b/.github/workflows/sync_labels.yml index 84250589297..3708e1c0a4b 100644 --- a/.github/workflows/sync_labels.yml +++ b/.github/workflows/sync_labels.yml @@ -20,18 +20,17 @@ jobs: synchronize: runs-on: ubuntu-latest steps: - # Download the Python script - - name: Download script - id: download - run: | - curl -L -O "https://raw.githubusercontent.com/"$REPO"/master/.github/sync_labels.py" - chmod a+x sync_labels.py - env: - REPO: ${{ github.repository }} + # Checkout the Python script + - name: Checkout files + uses: Bhacaz/checkout-files@v2 + with: + files: .github/sync_labels.py # Perform synchronization - name: Call script - run: ./sync_labels.py $ACTION $ISSUE_URL $PR_URL $ACTOR "$LABEL" "$REV_STATE" + run: | + chmod a+x .github/sync_labels.py + .github/sync_labels.py $ACTION $ISSUE_URL $PR_URL $ACTOR "$LABEL" "$REV_STATE" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ACTION: ${{ github.event.action }} From 53999c3f81248c70320031409ccd61a0396a3db9 Mon Sep 17 00:00:00 2001 From: Sebastian Oehms Date: Mon, 13 Mar 2023 20:28:39 +0100 Subject: [PATCH 08/98] sync_labels_resolution initial --- .github/sync_labels.py | 136 ++++++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 63 deletions(-) diff --git a/.github/sync_labels.py b/.github/sync_labels.py index 036e1147472..3be4cde5fff 100755 --- a/.github/sync_labels.py +++ b/.github/sync_labels.py @@ -3,6 +3,7 @@ r""" Python script to sync labels that are migrated from Trac selection lists. +For more information see https://github.com/sagemath/sage/pull/35172 """ ############################################################################## @@ -22,7 +23,7 @@ from enum import Enum class Action(Enum): - """ + r""" Enum for GitHub event ``action``. """ opened = 'opened' @@ -37,7 +38,7 @@ class Action(Enum): submitted = 'submitted' class RevState(Enum): - """ + r""" Enum for GitHub event ``review_state``. """ commented = 'commented' @@ -45,21 +46,15 @@ class RevState(Enum): changes_requested = 'changes_requested' class ReviewDecision(Enum): - """ + r""" Enum for ``gh pr view`` results for ``reviewDecision``. """ changes_requested = 'CHANGES_REQUESTED' approved = 'APPROVED' unclear = 'COMMENTED' -class SelectionList(Enum): - """ - Abstract Enum for selection lists. - """ - pass - -class Priority(SelectionList): - """ +class Priority(Enum): + r""" Enum for priority labels. """ blocker = 'p: blocker /1' @@ -68,8 +63,8 @@ class Priority(SelectionList): minor = 'p: minor /4' trivial = 'p: trivial /5' -class State(SelectionList): - """ +class State(Enum): + r""" Enum for state labels. """ positive_review = 's: positive review' @@ -77,24 +72,32 @@ class State(SelectionList): needs_review = 's: needs review' needs_info = 's: needs info' +class Resolution(Enum): + r""" + Enum for resolution labels. + """ + duplicate = 'r: duplicate' + invalid = 'r: invalid' + wontfix = 'r: wontfix' + worksforme = 'r: worksforme' def selection_list(label): + r""" + Return the selection list to which ``label`` belongs to. """ - Return the selection list to which `label` belongs to. - """ - for sel_list in [Priority, State]: + for sel_list in [Priority, State, Resolution]: for item in sel_list: if label == item.value: return sel_list return None class GhLabelSynchronizer: - """ - Handler for access to GitHub issue via the `gh` in the bash command line + r""" + Handler for access to GitHub issue via the ``gh`` in the bash command line of the GitHub runner. """ def __init__(self, url, actor): - """ + r""" Python constructor sets the issue / PR url and list of active labels. """ self._url = url @@ -120,13 +123,13 @@ def __init__(self, url, actor): # methods to obtain properties of the issue # ------------------------------------------------------------------------- def is_pull_request(self): - """ + r""" Return if we are treating a pull request. """ return self._pr def reset_view(self): - """ + r""" Reset cache of ``gh view`` results. """ self._labels = None @@ -139,8 +142,8 @@ def reset_view(self): self._commit_date = None def view(self, key): - """ - Return data obtained from `gh` command `view`. + r""" + Return data obtained from ``gh`` command ``view``. """ issue = 'issue' if self._pr: @@ -150,7 +153,7 @@ def view(self, key): return loads(check_output(cmd, shell=True))[key] def is_open(self): - """ + r""" Return if the issue res. PR is open. """ if self._open is not None: @@ -163,7 +166,7 @@ def is_open(self): return self._open def is_draft(self): - """ + r""" Return if the PR is a draft. """ if self._draft is not None: @@ -176,7 +179,7 @@ def is_draft(self): return self._draft def get_labels(self): - """ + r""" Return the list of labels of the issue resp. PR. """ if self._labels is not None: @@ -187,7 +190,7 @@ def get_labels(self): return self._labels def get_author(self): - """ + r""" Return the author of the issue resp. PR. """ if self._author is not None: @@ -198,7 +201,7 @@ def get_author(self): return self._author def get_commits(self): - """ + r""" Return the list of commits of the PR. """ if not self.is_pull_request(): @@ -213,7 +216,7 @@ def get_commits(self): return self._commits def get_review_decision(self): - """ + r""" Return the reviewDecision of the PR. """ if not self.is_pull_request(): @@ -231,7 +234,7 @@ def get_review_decision(self): return self._review_decision def get_reviews(self, complete=False): - """ + r""" Return the list of reviews of the PR. Per default only those reviews are returned which have been submitted after the youngest commit. Use keyword ``complete`` to get them all. @@ -255,7 +258,7 @@ def get_reviews(self, complete=False): return new_revs def active_partners(self, item): - """ + r""" Return the list of other labels from the selection list of the given one that are already present on the issue / PR. """ @@ -268,8 +271,8 @@ def active_partners(self, item): # methods to validate the issue state # ------------------------------------------------------------------------- def needs_work_valid(self): - """ - Return `True` if the PR needs work. This is the case if + r""" + Return ``True`` if the PR needs work. This is the case if the review decision requests changes or if there is any review reqesting changes. """ @@ -292,8 +295,8 @@ def needs_work_valid(self): return False def positive_review_valid(self): - """ - Return `True` if the PR has positive review. This is the + r""" + Return ``True`` if the PR has positive review. This is the case if the review decision is approved or if there is any approved review but no changes requesting one. """ @@ -320,7 +323,7 @@ def positive_review_valid(self): return False def needs_review_valid(self): - """ + r""" Return ``True`` if the PR needs review. This is the case if all proper reviews are older than the youngest commit. """ @@ -339,7 +342,7 @@ def needs_review_valid(self): return True def approve_allowed(self): - """ + r""" Return if the actor has permission to approve this PR. """ revs = self.get_reviews(complete=True) @@ -357,7 +360,7 @@ def approve_allowed(self): return self.actor_valid() def actor_valid(self): - """ + r""" Return if the actor has permission to approve this PR. """ author = self.get_author() @@ -386,8 +389,8 @@ def actor_valid(self): # methods to change the issue # ------------------------------------------------------------------------- def gh_cmd(self, cmd, arg, option): - """ - Perform a system call to `gh` for `cmd` to an isuue resp. PR. + r""" + Perform a system call to ``gh`` for ``cmd`` to an isuue resp. PR. """ issue = 'issue' if self._pr: @@ -399,41 +402,41 @@ def gh_cmd(self, cmd, arg, option): warning('Execution of %s failed with exit code: %s' % (cmd_str, ex_code)) def edit(self, arg, option): - """ - Perform a system call to `gh` to edit an issue resp. PR. + r""" + Perform a system call to ``gh`` to edit an issue resp. PR. """ self.gh_cmd('edit', arg, option) def review(self, arg, text): - """ - Perform a system call to `gh` to review a PR. + r""" + Perform a system call to ``gh`` to review a PR. """ self.gh_cmd('review', arg, '-b \"%s\"' % text) def approve(self): - """ + r""" Approve the PR by the actor. """ self.review('--approve', '%s approved this PR' % self._actor) info('PR %s approved by %s' % (self._issue, self._actor)) def request_changes(self): - """ + r""" Request changes for this PR by the actor. """ self.review('--request-changes', '%s requested changes for this PR' % self._actor) info('Changes requested for PR %s by %s' % (self._issue, self._actor)) def add_comment(self, text): - """ - Perform a system call to `gh` to add a comment to an issue or PR. + r""" + Perform a system call to ``gh`` to add a comment to an issue or PR. """ self.gh_cmd('comment', text, '-b') info('Add comment to %s: %s' % (self._issue, text)) def add_label(self, label): - """ + r""" Add the given label to the issue or PR. """ if not label in self.get_labels(): @@ -441,14 +444,14 @@ def add_label(self, label): info('Add label to %s: %s' % (self._issue, label)) def add_default_label(self, item): - """ + r""" Add the given label if there is no active partner. """ if not self.active_partners(item): self.add_label(item.value) def select_label(self, item): - """ + r""" Add the given label and remove all others. """ self.add_label(item.value) @@ -458,7 +461,7 @@ def select_label(self, item): self.remove_label(other.value) def remove_label(self, label): - """ + r""" Remove the given label from the issue or PR of the handler. """ if label in self.get_labels(): @@ -466,7 +469,7 @@ def remove_label(self, label): info('Remove label from %s: %s' % (self._issue, label)) def reject_label_addition(self, item): - """ + r""" Post a comment that the given label can not be added and select a corresponding other one. """ @@ -478,7 +481,7 @@ def reject_label_addition(self, item): return def reject_label_removal(self, item): - """ + r""" Post a comment that the given label can not be removed and select a corresponding other one. """ @@ -494,7 +497,7 @@ def reject_label_removal(self, item): # methods to act on events # ------------------------------------------------------------------------- def on_label_add(self, label): - """ + r""" Check if the given label belongs to a selection list. If so, remove all other labels of that list. In case of a state label reviews are booked accordingly. @@ -541,12 +544,15 @@ def on_label_add(self, label): self.reject_label_addition(item) return + if sel_list is Resolution: + self.remove_all_labels_of_sel_list(Priority) + for other in sel_list: if other != item: self.remove_label(other.value) def on_label_removal(self, label): - """ + r""" Check if the given label belongs to a selection list. If so, the removement is rejected and a comment is posted to instead add a replacement for ``label`` from the list. Exceptions are State labels @@ -565,15 +571,15 @@ def on_label_removal(self, label): self.reject_label_removal(item) return - def remove_all_state_labels(self): - """ - Remove all state labels. + def remove_all_labels_of_sel_list(self, sel_list): + r""" + Remove all labels of given selection list. """ - for item in State: + for item in sel_list: self.remove_label(item.value) def run(self, action, label=None, rev_state=None): - """ + r""" Run the given action. """ self.reset_view() # this is just needed for run_tests @@ -583,7 +589,7 @@ def run(self, action, label=None, rev_state=None): self.add_default_label(State.needs_review) if action in (Action.closed, Action.reopened, Action.converted_to_draft): - self.remove_all_state_labels() + self.remove_all_labels_of_sel_list(State) if action is Action.labeled: self.on_label_add(label) @@ -608,7 +614,7 @@ def run(self, action, label=None, rev_state=None): self.select_label(State.needs_work) def run_tests(self): - """ + r""" Simulative run over all posibble events. This is not intended to validate all functionality. It just @@ -633,6 +639,10 @@ def run_tests(self): else: self.remove_label(prio.value) self.run(action, label=prio.value) + res = Resolution.worksforme + if action is Action.labeled: + self.add_label(res.value) + self.run(action, label=prio.value) elif action == Action.submitted and self.is_pull_request(): for stat in RevState: if stat is RevState.approved: From 631daf44b5ca55a5430d32cd3a253f84d1a71d04 Mon Sep 17 00:00:00 2001 From: Sebastian Oehms <47305845+soehms@users.noreply.github.com> Date: Mon, 20 Mar 2023 20:31:33 +0100 Subject: [PATCH 09/98] sync_labels_add_on_review_comment initial (#6) --- .github/sync_labels.py | 129 ++++++++++++++++++++++++++++++++--------- 1 file changed, 100 insertions(+), 29 deletions(-) diff --git a/.github/sync_labels.py b/.github/sync_labels.py index 3be4cde5fff..2b6297723f0 100755 --- a/.github/sync_labels.py +++ b/.github/sync_labels.py @@ -235,9 +235,9 @@ def get_review_decision(self): def get_reviews(self, complete=False): r""" - Return the list of reviews of the PR. Per default only those reviews - are returned which have been submitted after the youngest commit. - Use keyword ``complete`` to get them all. + Return the list of reviews of the PR. Per default only those proper reviews + are returned which have been submitted after the most recent commit. Use + keyword ``complete`` to get them all. """ if not self.is_pull_request(): return None @@ -253,9 +253,11 @@ def get_reviews(self, complete=False): self.get_commits() date = self._commit_date + no_rev = ReviewDecision.unclear.value new_revs = [rev for rev in self._reviews if rev['submittedAt'] > date] - info('Reviews for %s: %s after %s' % (self._issue, self._reviews, date)) - return new_revs + proper_new_revs = [rev for rev in new_revs if rev['state'] != no_rev] + info('Proper reviews after %s for %s: %s' % (date, self._issue, proper_new_revs)) + return proper_new_revs def active_partners(self, item): r""" @@ -270,12 +272,34 @@ def active_partners(self, item): # ------------------------------------------------------------------------- # methods to validate the issue state # ------------------------------------------------------------------------- + def review_comment_to_state(self): + r""" + Return a State label if the most recent review comment + starts with its value. + """ + revs = self.get_reviews(complete=True) + date = max(rev['submittedAt'] for rev in revs) + + for rev in revs: + if rev['submittedAt'] == date: + for stat in State: + body = rev['body'] + if body.startswith(stat.value): + return stat + return None + def needs_work_valid(self): r""" Return ``True`` if the PR needs work. This is the case if - the review decision requests changes or if there is any - review reqesting changes. + there are reviews more recent than any commit and the review + decision requests changes or if there is any review reqesting + changes. """ + revs = self.get_reviews() + if not revs: + # no proper review since most recent commit. + return False + ch_req = ReviewDecision.changes_requested rev_dec = self.get_review_decision() if rev_dec: @@ -286,8 +310,6 @@ def needs_work_valid(self): info('PR %s doesn\'t need work (by decision)' % self._issue) return False - revs = self.get_reviews() - revs = [rev for rev in revs if rev['author']['login'] == self._actor] if any(rev['state'] == ch_req.value for rev in revs): info('PR %s needs work' % self._issue) return True @@ -297,9 +319,15 @@ def needs_work_valid(self): def positive_review_valid(self): r""" Return ``True`` if the PR has positive review. This is the - case if the review decision is approved or if there is any - approved review but no changes requesting one. + case if there are reviews more recent than any commit and the + review decision is approved or if there is any approved review + but no changes requesting one. """ + revs = self.get_reviews() + if not revs: + # no proper review since most recent commit. + return False + appr = ReviewDecision.approved rev_dec = self.get_review_decision() if rev_dec: @@ -310,13 +338,7 @@ def positive_review_valid(self): info('PR %s doesn\'t have positve review (by decision)' % self._issue) return False - if self.needs_work_valid(): - info('PR %s doesn\'t have positve review (needs work)' % self._issue) - return False - - revs = self.get_reviews() - revs = [rev for rev in revs if rev['author']['login'] == self._actor] - if any(rev['state'] == appr.value for rev in revs): + if all(rev['state'] == appr.value for rev in revs): info('PR %s has positve review' % self._issue) return True info('PR %s doesn\'t have positve review' % self._issue) @@ -407,6 +429,12 @@ def edit(self, arg, option): """ self.gh_cmd('edit', arg, option) + def mark_as_ready(self): + r""" + Perform a system call to ``gh`` to mark a PR as ready for review. + """ + self.gh_cmd('ready', '', '') + def review(self, arg, text): r""" Perform a system call to ``gh`` to review a PR. @@ -427,6 +455,13 @@ def request_changes(self): self.review('--request-changes', '%s requested changes for this PR' % self._actor) info('Changes requested for PR %s by %s' % (self._issue, self._actor)) + def review_comment(self, text): + r""" + Add a review comment. + """ + self.review('--comment', text) + info('Add review comment for PR %s: %s' % (self._issue, text)) + def add_comment(self, text): r""" Perform a system call to ``gh`` to add a comment to an issue or PR. @@ -526,20 +561,34 @@ def on_label_add(self, label): return if item == State.needs_review: - if not self.needs_review_valid(): + if self.needs_review_valid(): + # here we come for example after a sequence: + # needs review -> needs info -> needs review + pass + elif self.is_draft(): + self.mark_as_ready() + else: self.reject_label_addition(item) return - if item == State.positive_review: - if self.approve_allowed(): - self.approve() + if item == State.needs_work: + if self.needs_work_valid(): + # here we come for example after a sequence: + # needs work -> needs info -> needs work + pass + elif not self.is_draft(): + self.request_changes() else: self.reject_label_addition(item) return - if item == State.needs_work: - if self.needs_review_valid(): - self.request_changes() + if item == State.positive_review: + if self.positive_review_valid(): + # here we come for example after a sequence: + # positive review -> needs info -> positive review + pass + elif self.approve_allowed(): + self.approve() else: self.reject_label_addition(item) return @@ -570,6 +619,19 @@ def on_label_removal(self, label): elif sel_list is Priority: self.reject_label_removal(item) return + + def on_review_comment(self): + r""" + Check if the text of the most recent review begins with a + specific label name. In this case, simulate the corresponding + label addition. This feature is needed for people who don't + have permission to add labels (i.e. aren't a member of the + Triage team). + """ + rev_state = self.review_comment_to_state() + if rev_state in (State.needs_info, State.needs_review): + self.select_label(rev_state) + self.run(Action.labeled, label=rev_state.value) def remove_all_labels_of_sel_list(self, sel_list): r""" @@ -605,6 +667,7 @@ def run(self, action, label=None, rev_state=None): self.select_label(State.needs_review) if action is Action.submitted: + rev_state = RevState(rev_state) if rev_state is RevState.approved: if self.positive_review_valid(): self.select_label(State.positive_review) @@ -613,6 +676,9 @@ def run(self, action, label=None, rev_state=None): if self.needs_work_valid(): self.select_label(State.needs_work) + if rev_state is RevState.commented: + self.on_review_comment() + def run_tests(self): r""" Simulative run over all posibble events. @@ -644,12 +710,17 @@ def run_tests(self): self.add_label(res.value) self.run(action, label=prio.value) elif action == Action.submitted and self.is_pull_request(): - for stat in RevState: - if stat is RevState.approved: + for rev_stat in RevState: + if rev_stat is RevState.approved: self.approve() - elif stat is RevState.changes_requested: + self.run(action, rev_state=rev_stat.value) + elif rev_stat is RevState.changes_requested: self.request_changes() - self.run(action, rev_state=stat.value) + self.run(action, rev_state=rev_stat.value) + elif rev_stat is RevState.commented: + for stat in State: + self.review_comment(stat.value) + self.run(action, rev_state=rev_stat.value) elif self.is_pull_request(): self.run(action) From c8295256708d9fb19086e86e409ef32865ad8892 Mon Sep 17 00:00:00 2001 From: Sebastian Oehms <47305845+soehms@users.noreply.github.com> Date: Sun, 26 Mar 2023 11:58:07 +0200 Subject: [PATCH 10/98] Cleaning of warning comments (#7) * clean_warning_comments initial * clean_warning_comments remove pull_request trigger from workflow --- .github/sync_labels.py | 103 ++++++++++++++++++++++++++---- .github/workflows/sync_labels.yml | 6 +- 2 files changed, 94 insertions(+), 15 deletions(-) diff --git a/.github/sync_labels.py b/.github/sync_labels.py index 2b6297723f0..ba4b3cc743d 100755 --- a/.github/sync_labels.py +++ b/.github/sync_labels.py @@ -18,9 +18,14 @@ import os import sys -from logging import info, warning, getLogger, INFO +from logging import info, warning, debug, getLogger, INFO, DEBUG from json import loads from enum import Enum +from datetime import datetime, timedelta +from subprocess import check_output, CalledProcessError + +datetime_format = '%Y-%m-%dT%H:%M:%SZ' + class Action(Enum): r""" @@ -102,6 +107,7 @@ def __init__(self, url, actor): """ self._url = url self._actor = actor + self._warning_prefix = 'Label Sync Warning:' self._labels = None self._author = None self._draft = None @@ -118,6 +124,7 @@ def __init__(self, url, actor): self._issue = 'issue #%s' % number self._pr = False info('Create label handler for %s and actor %s' % (self._issue, self._actor)) + self.clean_warnings() # ------------------------------------------------------------------------- # methods to obtain properties of the issue @@ -141,6 +148,21 @@ def reset_view(self): self._commits = None self._commit_date = None + def rest_api(self, path_args, method=None, query=''): + r""" + Return data obtained from ``gh`` command ``api``. + """ + s = self._url.split('/') + owner = s[3] + repo = s[4] + meth = '-X GET' + if method: + meth='-X %s' % method + cmd = 'gh api %s -H \"Accept: application/vnd.github+json\" /repos/%s/%s/%s %s' % (meth, owner, repo, path_args, query) + if method: + return check_output(cmd, shell=True) + return loads(check_output(cmd, shell=True)) + def view(self, key): r""" Return data obtained from ``gh`` command ``view``. @@ -149,7 +171,6 @@ def view(self, key): if self._pr: issue = 'pr' cmd = 'gh %s view %s --json %s' % (issue, self._url, key) - from subprocess import check_output return loads(check_output(cmd, shell=True))[key] def is_open(self): @@ -178,6 +199,49 @@ def is_draft(self): info('Issue %s is draft %s' % (self._issue, self._draft)) return self._draft + def clean_warnings(self): + r""" + Remove all warnings that have been posted by ``GhLabelSynchronizer`` + more than ``warning_lifetime`` ago. + """ + warning_lifetime = timedelta(minutes=5) + time_frame = timedelta(hours=12) # timedelta to search for comments + per_page = 100 + today = datetime.today() + since = today - time_frame + query = '-F per_page=%s -F page={} -f since=%s' % (per_page, since.strftime(datetime_format)) + path = 'issues/comments' + page = 1 + comments = [] + while True: + comments_page = self.rest_api(path, query=query.format(page)) + comments += comments_page + if len(comments_page) < per_page: + break + page += 1 + + info('Cleaning warning comments since %s (total found %s)' % (since, len(comments))) + + for c in comments: + login = c['user']['login'] + body = c['body'] + comment_id = c['id'] + issue = c['issue_url'].split('/').pop() + created_at = c['created_at'] + if login.startswith('github-actions'): + debug('github-actions comment %s created at %s on issue %s found' % (comment_id, created_at, issue)) + if body.startswith(self._warning_prefix): + created = datetime.strptime(created_at, datetime_format) + lifetime = today - created + debug('github-actions %s %s is %s old' % (self._warning_prefix, comment_id, lifetime)) + if lifetime > warning_lifetime: + try: + self.rest_api('%s/%s' % (path, comment_id), method='DELETE') + info('Comment %s on issue %s deleted' % (comment_id, issue)) + except CalledProcessError: + # the comment may have been deleted by a bot running in parallel + info('Comment %s on issue %s has been deleted already' % (comment_id, issue)) + def get_labels(self): r""" Return the list of labels of the issue resp. PR. @@ -244,7 +308,7 @@ def get_reviews(self, complete=False): if self._reviews is None: self._reviews = self.view('reviews') - info('Reviews for %s: %s' % (self._issue, self._reviews)) + debug('Reviews for %s: %s' % (self._issue, self._reviews)) if complete or not self._reviews: return self._reviews @@ -418,7 +482,7 @@ def gh_cmd(self, cmd, arg, option): if self._pr: issue = 'pr' cmd_str = 'gh %s %s %s %s "%s"' % (issue, cmd, self._url, option, arg) - info('Execute command: %s' % cmd_str) + debug('Execute command: %s' % cmd_str) ex_code = os.system(cmd_str) if ex_code: warning('Execution of %s failed with exit code: %s' % (cmd_str, ex_code)) @@ -466,10 +530,15 @@ def add_comment(self, text): r""" Perform a system call to ``gh`` to add a comment to an issue or PR. """ - self.gh_cmd('comment', text, '-b') info('Add comment to %s: %s' % (self._issue, text)) + def add_warning(self, text): + r""" + Perform a system call to ``gh`` to add a warning to an issue or PR. + """ + self.add_comment('%s %s' % (self._warning_prefix, text)) + def add_label(self, label): r""" Add the given label to the issue or PR. @@ -508,10 +577,12 @@ def reject_label_addition(self, item): Post a comment that the given label can not be added and select a corresponding other one. """ - if self.is_pull_request(): - self.add_comment('Label *%s* can not be added. Please use the corresponding functionality of GitHub' % item.value) + if not self.is_pull_request(): + self.add_warning('Label *%s* can not be added to an issue. Please use it on the corresponding PR' % item.value) + elif item is State.needs_review: + self.add_warning('Label *%s* can not be added, since there are unresolved reviews' % item.value) else: - self.add_comment('Label *%s* can not be added to an issue. Please use it on the corresponding PR' % item.value) + self.add_warning('Label *%s* can not be added. Please use the GitHub review functionality' % item.value) self.remove_label(item.value) return @@ -524,7 +595,7 @@ def reject_label_removal(self, item): sel_list = 'state' else: sel_list = 'priority' - self.add_comment('Label *%s* can not be removed. Please add the %s-label which should replace it' % (item.value, sel_list)) + self.add_warning('Label *%s* can not be removed. Please add the %s-label which should replace it' % (item.value, sel_list)) self.add_label(item.value) return @@ -549,7 +620,7 @@ def on_label_add(self, label): # on the `on_label_add` of the first of the two labels partn = self.active_partners(item) if partn: - self.add_comment('Label *%s* can not be added due to *%s*!' % (label, partn[0].value)) + self.add_warning('Label *%s* can not be added due to *%s*!' % (label, partn[0].value)) else: warning('Label %s of %s not found!' % (label, self._issue)) return @@ -731,7 +802,9 @@ def run_tests(self): cmdline_args = sys.argv[1:] num_args = len(cmdline_args) -getLogger().setLevel(INFO) +# getLogger().setLevel(INFO) +getLogger().setLevel(DEBUG) + info('cmdline_args (%s) %s' % (num_args, cmdline_args)) if num_args == 5: @@ -756,6 +829,14 @@ def run_tests(self): gh = GhLabelSynchronizer(url, actor) gh.run_tests() +elif num_args == 1: + url, = cmdline_args + + info('url: %s' % url) + + gh = GhLabelSynchronizer(url, 'sagetrac-github-bot') + else: print('Need 5 arguments: action, url, actor, label, rev_state' ) print('Running tests is possible with 2 arguments: url, actor' ) + print('Cleaning warning comments is possible with 1 argument: url' ) diff --git a/.github/workflows/sync_labels.yml b/.github/workflows/sync_labels.yml index 3708e1c0a4b..71ff7eb2161 100644 --- a/.github/workflows/sync_labels.yml +++ b/.github/workflows/sync_labels.yml @@ -7,12 +7,10 @@ name: Synchronize selection list lables on: - pull_request_review: - types: [submitted] issues: types: [opened, reopened, closed, labeled, unlabeled] - pull_request: - types: [opened, reopened, closed, ready_for_review, converted_to_draft, synchronize, labeled, unlabeled] + pull_request_review: + types: [submitted] pull_request_target: types: [opened, reopened, closed, ready_for_review, converted_to_draft, synchronize, labeled, unlabeled] From aa449ef876d8ffe8f95dee9550e76ad74ace179c Mon Sep 17 00:00:00 2001 From: Sebastian Oehms <47305845+soehms@users.noreply.github.com> Date: Mon, 10 Apr 2023 07:54:31 +0200 Subject: [PATCH 11/98] sync_labels_actor_authorized initial (#8) --- .github/sync_labels.py | 119 +++++++++++++++++++++++------- .github/workflows/sync_labels.yml | 21 +++++- 2 files changed, 110 insertions(+), 30 deletions(-) diff --git a/.github/sync_labels.py b/.github/sync_labels.py index ba4b3cc743d..05fa1459b5e 100755 --- a/.github/sync_labels.py +++ b/.github/sync_labels.py @@ -18,7 +18,7 @@ import os import sys -from logging import info, warning, debug, getLogger, INFO, DEBUG +from logging import info, warning, debug, getLogger, INFO, DEBUG, WARNING from json import loads from enum import Enum from datetime import datetime, timedelta @@ -152,13 +152,11 @@ def rest_api(self, path_args, method=None, query=''): r""" Return data obtained from ``gh`` command ``api``. """ - s = self._url.split('/') - owner = s[3] - repo = s[4] meth = '-X GET' if method: meth='-X %s' % method - cmd = 'gh api %s -H \"Accept: application/vnd.github+json\" /repos/%s/%s/%s %s' % (meth, owner, repo, path_args, query) + cmd = 'gh api %s -H \"Accept: application/vnd.github+json\" %s %s' % (meth, path_args, query) + debug('Execute command: %s' % cmd) if method: return check_output(cmd, shell=True) return loads(check_output(cmd, shell=True)) @@ -171,11 +169,12 @@ def view(self, key): if self._pr: issue = 'pr' cmd = 'gh %s view %s --json %s' % (issue, self._url, key) + debug('Execute command: %s' % cmd) return loads(check_output(cmd, shell=True))[key] def is_open(self): r""" - Return if the issue res. PR is open. + Return ``True`` if the issue res. PR is open. """ if self._open is not None: return self._open @@ -188,7 +187,7 @@ def is_open(self): def is_draft(self): r""" - Return if the PR is a draft. + Return ``True`` if the PR is a draft. """ if self._draft is not None: return self._draft @@ -199,22 +198,55 @@ def is_draft(self): info('Issue %s is draft %s' % (self._issue, self._draft)) return self._draft + def is_auth_team_member(self, login): + r""" + Return ``True`` if the user with given login belongs to an authorized + team. + """ + def verify_membership(team): + path_args = '/orgs/sagemath/teams/%s/memberships/%s' % (team, login) + try: + res = self.rest_api(path_args) + if res['state'] == 'active' and res['role'] == 'member': + info('User %s is a member of %s' % (login, team)) + return True + except CalledProcessError: + pass + + info('User %s is not a member of %s' % (login, team)) + return False + + # check for the Triage team + if verify_membership('triage'): + return True + + return False + + def actor_authorized(self): + r""" + Return ``True`` if the actor belongs to an authorized team. + """ + return self.is_auth_team_member(self._actor) + def clean_warnings(self): r""" Remove all warnings that have been posted by ``GhLabelSynchronizer`` more than ``warning_lifetime`` ago. """ warning_lifetime = timedelta(minutes=5) - time_frame = timedelta(hours=12) # timedelta to search for comments + time_frame = timedelta(minutes=730) # timedelta to search for comments including 10 minutes overlap with cron-cycle per_page = 100 today = datetime.today() since = today - time_frame query = '-F per_page=%s -F page={} -f since=%s' % (per_page, since.strftime(datetime_format)) - path = 'issues/comments' + s = self._url.split('/') + owner = s[3] + repo = s[4] + path_args = '/repos/%s/%s/issues/comments' % (owner, repo) page = 1 comments = [] while True: - comments_page = self.rest_api(path, query=query.format(page)) + comments_page = self.rest_api(path_args, query=query.format(page)) comments += comments_page if len(comments_page) < per_page: break @@ -236,7 +268,7 @@ def clean_warnings(self): debug('github-actions %s %s is %s old' % (self._warning_prefix, comment_id, lifetime)) if lifetime > warning_lifetime: try: - self.rest_api('%s/%s' % (path, comment_id), method='DELETE') + self.rest_api('%s/%s' % (path_args, comment_id), method='DELETE') info('Comment %s on issue %s deleted' % (comment_id, issue)) except CalledProcessError: # the comment may have been deleted by a bot running in parallel @@ -740,7 +772,7 @@ def run(self, action, label=None, rev_state=None): if action is Action.submitted: rev_state = RevState(rev_state) if rev_state is RevState.approved: - if self.positive_review_valid(): + if self.actor_authorized() and self.positive_review_valid(): self.select_label(State.positive_review) if rev_state is RevState.changes_requested: @@ -799,44 +831,75 @@ def run_tests(self): ############################################################################### # Main ############################################################################### +last_arg = None +run_tests = False +default_actor = 'sagetrac-github-bot' cmdline_args = sys.argv[1:] num_args = len(cmdline_args) -# getLogger().setLevel(INFO) -getLogger().setLevel(DEBUG) +if num_args: + last_arg = cmdline_args[num_args-1] + +if last_arg in ('-t', '--test'): + getLogger().setLevel(DEBUG) + cmdline_args.pop() + run_tests = True +elif last_arg in ('-d', '--debug'): + getLogger().setLevel(DEBUG) + cmdline_args.pop() +elif last_arg in ('-i', '--info'): + getLogger().setLevel(INFO) + cmdline_args.pop() +elif last_arg in ('-w', '--warning'): + getLogger().setLevel(INFO) + info('cmdline_args (%s) %s' % (num_args, cmdline_args)) + getLogger().setLevel(WARNING) + cmdline_args.pop() +else: + getLogger().setLevel(DEBUG) +num_args = len(cmdline_args) info('cmdline_args (%s) %s' % (num_args, cmdline_args)) -if num_args == 5: - action, url, actor, label, rev_state = cmdline_args - action = Action(action) +if run_tests and num_args in (1,2): + if num_args == 2: + url, actor = cmdline_args + else: + url, = cmdline_args + actor = default_actor - info('action: %s' % action) info('url: %s' % url) info('actor: %s' % actor) - info('label: %s' % label) - info('rev_state: %s' % rev_state) gh = GhLabelSynchronizer(url, actor) - gh.run(action, label=label, rev_state=rev_state) + gh.run_tests() -elif num_args == 2: - url, actor = cmdline_args +elif num_args == 5: + action, url, actor, label, rev_state = cmdline_args + action = Action(action) + info('action: %s' % action) info('url: %s' % url) info('actor: %s' % actor) + info('label: %s' % label) + info('rev_state: %s' % rev_state) gh = GhLabelSynchronizer(url, actor) - gh.run_tests() + gh.run(action, label=label, rev_state=rev_state) elif num_args == 1: url, = cmdline_args info('url: %s' % url) - gh = GhLabelSynchronizer(url, 'sagetrac-github-bot') + gh = GhLabelSynchronizer(url, default_actor) else: - print('Need 5 arguments: action, url, actor, label, rev_state' ) - print('Running tests is possible with 2 arguments: url, actor' ) - print('Cleaning warning comments is possible with 1 argument: url' ) + print('Need 5 arguments to synchronize: action, url, actor, label, rev_state') + print('Need 1 argument to clean warning comments: url') + print('Need 1 argument to run tests: url') + print('The following options may be appended:') + print(' -t --test to run the test suite') + print(' -i --info to set the log-level to INFO') + print(' -d --debug to set the log-level to DEBUG (default)') + print(' -w --warning to set the log-level to WARNING') diff --git a/.github/workflows/sync_labels.yml b/.github/workflows/sync_labels.yml index 71ff7eb2161..4a406a5b72f 100644 --- a/.github/workflows/sync_labels.yml +++ b/.github/workflows/sync_labels.yml @@ -13,9 +13,13 @@ on: types: [submitted] pull_request_target: types: [opened, reopened, closed, ready_for_review, converted_to_draft, synchronize, labeled, unlabeled] + schedule: + # run cleaning of warning comments twice a day + - cron: '00 6,18 * * *' jobs: synchronize: + if: vars.SYNC_LABELS_ACTIVE == 'yes' # variable from repository settings to suspend the job runs-on: ubuntu-latest steps: # Checkout the Python script @@ -25,10 +29,11 @@ jobs: files: .github/sync_labels.py # Perform synchronization - - name: Call script + - name: Call script for synchronization + if: github.event.schedule == '' run: | chmod a+x .github/sync_labels.py - .github/sync_labels.py $ACTION $ISSUE_URL $PR_URL $ACTOR "$LABEL" "$REV_STATE" + .github/sync_labels.py $ACTION $ISSUE_URL $PR_URL $ACTOR "$LABEL" "$REV_STATE" $LOG_LEVEL env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ACTION: ${{ github.event.action }} @@ -37,3 +42,15 @@ jobs: ACTOR: ${{ github.actor }} LABEL: ${{ github.event.label.name }} REV_STATE: ${{ github.event.review.state }} + LOG_LEVEL: ${{ vars.SYNC_LABELS_LOG_LEVEL }} # variable from repository settings, values can be "--debug", "--info" or "--warning" + + # Perform cleaning + - name: Call script for cleaning + if: github.event.schedule != '' + run: | + chmod a+x .github/sync_labels.py + .github/sync_labels.py $REPO_URL $LOG_LEVEL + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO_URL: ${{ github.event.repository.html_url }} + LOG_LEVEL: ${{ vars.SYNC_LABELS_LOG_LEVEL }} # variable from repository settings, values can be "--debug", "--info" or "--warning" From 9246bb1471c0acb1513bccbfc1c304ff893ff724 Mon Sep 17 00:00:00 2001 From: Sebastian Oehms Date: Mon, 10 Apr 2023 22:44:04 +0200 Subject: [PATCH 12/98] sync_labels: introduce vars.SYNC_LABELS_BIDIRECT --- .github/workflows/sync_labels.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sync_labels.yml b/.github/workflows/sync_labels.yml index 4a406a5b72f..0171fdb427b 100644 --- a/.github/workflows/sync_labels.yml +++ b/.github/workflows/sync_labels.yml @@ -19,7 +19,11 @@ on: jobs: synchronize: - if: vars.SYNC_LABELS_ACTIVE == 'yes' # variable from repository settings to suspend the job + if: | # check variables from repository settings to suspend the job + vars.SYNC_LABELS_ACTIVE == 'yes' && ( + vars.SYNC_LABELS_BIDIRECT == 'yes' || + github.event.action != 'labeled' && + github.event.action != 'unlabeled') runs-on: ubuntu-latest steps: # Checkout the Python script From 3b50dd3b5a249af699bd49ff10dcc7a115e0b764 Mon Sep 17 00:00:00 2001 From: Dang Date: Tue, 11 Apr 2023 16:44:29 -0700 Subject: [PATCH 13/98] 32338: added documentation --- .../dynamics/arithmetic_dynamics/projective_ds.py | 15 +++++++++++---- src/sage/schemes/projective/projective_point.py | 11 ++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py index f262d902240..0e308403c04 100644 --- a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py +++ b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py @@ -6226,10 +6226,6 @@ def _is_preperiodic(self, P, err=0.1, return_period=False): Determine if the point is preperiodic with respect to this dynamical system. - .. NOTE:: - - This is only implemented for projective space (not subschemes). - ALGORITHM: We know that a point is preperiodic if and only if it has @@ -6294,6 +6290,17 @@ def _is_preperiodic(self, P, err=0.1, return_period=False): sage: f._is_preperiodic(p, return_period=True) (0, 2) + :: + + sage: P. = ProjectiveSpace(QQ, 2) + sage: X = P.subscheme(x) + sage: f = DynamicalSystem([x^2 - y^2, y^2, z^2], domain=X) + sage: p = X((0, 1, 0)) + sage: f._is_preperiodic(p, return_period=True) + Traceback (most recent call last): + ... + ValueError: orbit of point leaves domain + :: sage: R. = QQ[] diff --git a/src/sage/schemes/projective/projective_point.py b/src/sage/schemes/projective/projective_point.py index d7441f0f463..25a009625f0 100644 --- a/src/sage/schemes/projective/projective_point.py +++ b/src/sage/schemes/projective/projective_point.py @@ -876,7 +876,7 @@ def is_preperiodic(self, f, err=0.1, return_period=False): r""" Determine if the point is preperiodic with respect to the map ``f``. - This is only implemented for projective space (not subschemes). + This is implemented for both projective space and subschemes. There are two optional keyword arguments: ``error_bound`` sets the error_bound used in the canonical height computation and ``return_period`` a boolean which controls if the period is returned if the @@ -922,6 +922,15 @@ def is_preperiodic(self, f, err=0.1, return_period=False): sage: Q.is_preperiodic(f) True + :: + + sage: P. = ProjectiveSpace(QQ, 2) + sage: X = P.subscheme(z) + sage: f = DynamicalSystem([x^2 - y^2, y^2, z^2], domain=X) + sage: p = X((-1, 1, 0)) + sage: p.is_preperiodic(f, return_period=True) + (0, 2) + :: sage: P. = ProjectiveSpace(QQ,1) From 168e9b422afc6ad1ed2064c5e05d39b273a7228e Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Fri, 21 Apr 2023 22:46:50 +0900 Subject: [PATCH 14/98] Add informational: true --- .codecov.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.codecov.yml b/.codecov.yml index 879a7e5a64f..1da1161f548 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -11,6 +11,7 @@ coverage: target: auto threshold: 0% base: auto + informational: true patch: default: target: auto From f10c1efe1eaf286f5d60b8416b573aded49e1ddd Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 19 Apr 2023 18:41:31 -0700 Subject: [PATCH 15/98] sage.rings: Modularization fixes for Laurent polynomials, series --- src/sage/rings/big_oh.py | 32 +- src/sage/rings/laurent_series_ring.py | 6 +- .../rings/polynomial/laurent_polynomial.pxd | 12 - .../rings/polynomial/laurent_polynomial.pyx | 1909 +---------------- .../polynomial/laurent_polynomial_ring.py | 7 +- 5 files changed, 84 insertions(+), 1882 deletions(-) diff --git a/src/sage/rings/big_oh.py b/src/sage/rings/big_oh.py index 64ce5562f2c..1df61a39dc0 100644 --- a/src/sage/rings/big_oh.py +++ b/src/sage/rings/big_oh.py @@ -9,11 +9,24 @@ - `polynomials <../../../polynomial_rings/index.html>`_ """ -import sage.arith.all as arith -from . import laurent_series_ring_element -from sage.rings.puiseux_series_ring_element import PuiseuxSeries -import sage.rings.padics.factory as padics_factory -import sage.rings.padics.padic_generic_element as padic_generic_element +from sage.arith.misc import factor + +try: + from .laurent_series_ring_element import LaurentSeries +except ImportError: + LaurentSeries = () + +try: + from sage.rings.puiseux_series_ring_element import PuiseuxSeries +except ImportError: + PuiseuxSeries = () + +try: + import sage.rings.padics.factory as padics_factory + from sage.rings.padics.padic_generic_element.padic_generic_element import pAdicGenericElement +except ImportError: + pAdicGenericElement = () + from . import power_series_ring_element from . import integer from . import rational @@ -137,9 +150,8 @@ def O(*x, **kwds): "for the maximal ideal (x)") return x.parent().completion(x.parent().gen())(0, x.degree(), **kwds) - elif isinstance(x, laurent_series_ring_element.LaurentSeries): - return laurent_series_ring_element.LaurentSeries(x.parent(), 0).\ - add_bigoh(x.valuation(), **kwds) + elif isinstance(x, LaurentSeries): + return LaurentSeries(x.parent(), 0).add_bigoh(x.valuation(), **kwds) elif isinstance(x, PuiseuxSeries): return x.add_bigoh(x.valuation(), **kwds) @@ -148,7 +160,7 @@ def O(*x, **kwds): # p-adic number if x <= 0: raise ArithmeticError("x must be a prime power >= 2") - F = arith.factor(x) + F = factor(x) if len(F) != 1: raise ArithmeticError("x must be prime power") p, r = F[0] @@ -159,7 +171,7 @@ def O(*x, **kwds): return padics_factory.Qp(p, prec=max(r, 20), type='capped-rel')(0, absprec=r, **kwds) - elif isinstance(x, padic_generic_element.pAdicGenericElement): + elif isinstance(x, pAdicGenericElement): return x.parent()(0, absprec=x.valuation(), **kwds) elif hasattr(x, 'O'): return x.O(**kwds) diff --git a/src/sage/rings/laurent_series_ring.py b/src/sage/rings/laurent_series_ring.py index 56551b50a55..d034b416a50 100644 --- a/src/sage/rings/laurent_series_ring.py +++ b/src/sage/rings/laurent_series_ring.py @@ -47,6 +47,11 @@ from sage.rings.integer_ring import ZZ +try: + from sage.libs.pari.all import pari_gen +except ImportError: + pari_gen = () + def is_LaurentSeriesRing(x): """ @@ -469,7 +474,6 @@ def _element_constructor_(self, x, n=0, prec=infinity): from sage.rings.polynomial.polynomial_element import Polynomial from sage.rings.polynomial.multi_polynomial import MPolynomial from sage.structure.element import parent - from sage.libs.pari.all import pari_gen P = parent(x) if isinstance(x, self.element_class) and n == 0 and P is self: diff --git a/src/sage/rings/polynomial/laurent_polynomial.pxd b/src/sage/rings/polynomial/laurent_polynomial.pxd index cb0a4ab4ea0..3648d6d1ed1 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pxd +++ b/src/sage/rings/polynomial/laurent_polynomial.pxd @@ -1,6 +1,4 @@ from sage.structure.element cimport CommutativeAlgebraElement, ModuleElement, RingElement, Element -from sage.rings.polynomial.polydict cimport ETuple, PolyDict -from sage.rings.polynomial.multi_polynomial cimport MPolynomial cdef class LaurentPolynomial(CommutativeAlgebraElement): @@ -17,13 +15,3 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): cpdef __normalize(self) cpdef _unsafe_mutate(self, i, value) -cdef class LaurentPolynomial_mpair(LaurentPolynomial): - cdef ETuple _mon - cdef MPolynomial _poly - cdef PolyDict _prod - cdef _compute_polydict(self) - cdef _normalize(self, i=*) - cpdef rescale_vars(self, dict d, h=*, new_ring=*) - cpdef toric_coordinate_change(self, M, h=*, new_ring=*) - cpdef toric_substitute(self, v, v1, a, h=*, new_ring=*) - diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index b597397c9e5..0604b0f0111 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -19,7 +19,6 @@ from sage.rings.polynomial.polydict cimport monomial_exponent from sage.rings.polynomial.polynomial_element import Polynomial from sage.rings.polynomial.polynomial_ring import is_PolynomialRing from sage.structure.richcmp cimport richcmp, rich_to_bool -from sage.matrix.matrix0 cimport Matrix cdef class LaurentPolynomial(CommutativeAlgebraElement): """ @@ -179,14 +178,14 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement): sage: R. = LaurentPolynomialRing(QQ) sage: a = x^2 + 3*x^3 + 5*x^-1 - sage: a.change_ring(GF(3)) + sage: a.change_ring(GF(3)) # optional - sage.rings.finite_rings 2*x^-1 + x^2 Check that :trac:`22277` is fixed:: sage: R. = LaurentPolynomialRing(QQ) sage: a = 2*x^2 + 3*x^3 + 4*x^-1 - sage: a.change_ring(GF(3)) + sage: a.change_ring(GF(3)) # optional - sage.rings.finite_rings -x^2 + x^-1 """ return self._parent.change_ring(R)(self) @@ -255,38 +254,40 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement): EXAMPLES:: - sage: k. = GF(9) - sage: R. = LaurentPolynomialRing(k) - sage: f = x*a + a - sage: f.map_coefficients(lambda a : a + 1) + sage: k. = GF(9) # optional - sage.rings.finite_rings + sage: R. = LaurentPolynomialRing(k) # optional - sage.rings.finite_rings + sage: f = x*a + a # optional - sage.rings.finite_rings + sage: f.map_coefficients(lambda a: a + 1) # optional - sage.rings.finite_rings (a + 1) + (a + 1)*x - sage: R. = LaurentPolynomialRing(k, 2) - sage: f = x*a + 2*x^3*y*a + a - sage: f.map_coefficients(lambda a : a + 1) + sage: R. = LaurentPolynomialRing(k, 2) # optional - sage.rings.finite_rings + sage: f = x*a + 2*x^3*y*a + a # optional - sage.rings.finite_rings + sage: f.map_coefficients(lambda a: a + 1) # optional - sage.rings.finite_rings (2*a + 1)*x^3*y + (a + 1)*x + a + 1 Examples with different base ring:: - sage: R. = GF(9); S. = GF(81) - sage: h = Hom(R,S)[0]; h + sage: R. = GF(9); S. = GF(81) # optional - sage.rings.finite_rings + sage: h = Hom(R, S)[0]; h # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in r of size 3^2 To: Finite Field in s of size 3^4 Defn: r |--> 2*s^3 + 2*s^2 + 1 - sage: T. = LaurentPolynomialRing(R, 2) - sage: f = r*X+Y - sage: g = f.map_coefficients(h); g + sage: T. = LaurentPolynomialRing(R, 2) # optional - sage.rings.finite_rings + sage: f = r*X + Y # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(h); g # optional - sage.rings.finite_rings (2*s^3 + 2*s^2 + 1)*X + Y - sage: g.parent() - Multivariate Laurent Polynomial Ring in X, Y over Finite Field in s of size 3^4 - sage: h = lambda x: x.trace() - sage: g = f.map_coefficients(h); g + sage: g.parent() # optional - sage.rings.finite_rings + Multivariate Laurent Polynomial Ring in X, Y + over Finite Field in s of size 3^4 + sage: h = lambda x: x.trace() # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(h); g # optional - sage.rings.finite_rings X - Y - sage: g.parent() - Multivariate Laurent Polynomial Ring in X, Y over Finite Field in r of size 3^2 - sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g + sage: g.parent() # optional - sage.rings.finite_rings + Multivariate Laurent Polynomial Ring in X, Y + over Finite Field in r of size 3^2 + sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g # optional - sage.rings.finite_rings X - Y - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Multivariate Laurent Polynomial Ring in X, Y over Finite Field of size 3 """ @@ -331,13 +332,13 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): :: - sage: S. = LaurentPolynomialRing(GF(5)) - sage: T. = PolynomialRing(pAdicRing(5)) - sage: S(t) + sage: S. = LaurentPolynomialRing(GF(5)) # optional - sage.rings.finite_rings sage.rings.padics + sage: T. = PolynomialRing(pAdicRing(5)) # optional - sage.rings.finite_rings sage.rings.padics + sage: S(t) # optional - sage.rings.finite_rings sage.rings.padics s - sage: parent(S(t)) + sage: parent(S(t)) # optional - sage.rings.finite_rings sage.rings.padics Univariate Laurent Polynomial Ring in s over Finite Field of size 5 - sage: parent(S(t)[1]) + sage: parent(S(t)[1]) # optional - sage.rings.finite_rings sage.rings.padics Finite Field of size 5 :: @@ -387,7 +388,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: Pxy = PolynomialRing(QQ, "x,y") sage: Paxb = PolynomialRing(QQ, "a,x,b") sage: Qx = PolynomialRing(ZZ, "x") - sage: Rx = PolynomialRing(GF(2), "x") + sage: Rx = PolynomialRing(GF(2), "x") # optional - sage.rings.finite_rings sage: p1 = Lx.gen() sage: p2 = Lx.zero() sage: p3 = Lx.one() @@ -395,8 +396,10 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: p5 = Lx.gen()**3 + 2*Lx.gen()**2 sage: p6 = Lx.gen() >> 2 - sage: for P,x in [(Px, Px.gen()), (Qx, Qx.gen()), (Rx, Rx.gen()), - ....: (Pxy, Pxy.gen(0)), (Paxb, Paxb.gen(1))]: + sage: Pxes = [(Px, Px.gen()), (Qx, Qx.gen()), + ....: (Pxy, Pxy.gen(0)), (Paxb, Paxb.gen(1))] + sage: Pxes += [(Rx, Rx.gen())] # optional - sage.rings.finite_rings + sage: for P, x in Pxes: ....: assert P(p1) == x and parent(P(p1)) is P ....: assert P(p2) == P.zero() and parent(P(p2)) is P ....: assert P(p3) == P.one() and parent(P(p3)) is P @@ -511,12 +514,12 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): You can specify a map on the base ring:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: R. = LaurentPolynomialRing(K) - sage: H = Hom(R, R) - sage: phi = H([t^-2], base_map=cc) - sage: phi(i*t) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: R. = LaurentPolynomialRing(K) # optional - sage.rings.number_field + sage: H = Hom(R, R) # optional - sage.rings.number_field + sage: phi = H([t^-2], base_map=cc) # optional - sage.rings.number_field + sage: phi(i*t) # optional - sage.rings.number_field -i*t^-2 """ x = im_gens[0] @@ -605,9 +608,9 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): Verify that :trac:`6656` has been fixed:: - sage: R.=PolynomialRing(QQ) - sage: T.=LaurentPolynomialRing(R) - sage: y = a*x+b*x + sage: R. = PolynomialRing(QQ) + sage: T. = LaurentPolynomialRing(R) + sage: y = a*x + b*x sage: y._latex_() '\\left(a + b\\right)x' sage: latex(y) @@ -813,20 +816,20 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: R. = LaurentPolynomialRing(QQ) sage: f = x^3 + 2/x - sage: g = f._symbolic_(SR); g + sage: g = f._symbolic_(SR); g # optional - sage.symbolic (x^4 + 2)/x - sage: g(x=2) + sage: g(x=2) # optional - sage.symbolic 9 - sage: g = SR(f) - sage: g(x=2) + sage: g = SR(f) # optional - sage.symbolic + sage: g(x=2) # optional - sage.symbolic 9 Since :trac:`24072` the symbolic ring does not accept positive characteristic:: - sage: R. = LaurentPolynomialRing(GF(7)) - sage: SR(2*w^3 + 1) + sage: R. = LaurentPolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: SR(2*w^3 + 1) # optional - sage.rings.finite_rings sage.symbolic Traceback (most recent call last): ... TypeError: positive characteristic not allowed in symbolic computations @@ -1046,10 +1049,10 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): """ EXAMPLES:: - sage: R. = LaurentPolynomialRing(GF(2)) - sage: f = 1/x^3 + x + x^2 + 3*x^4 - sage: g = 1 - x + x^2 - x^4 - sage: f*g + sage: R. = LaurentPolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: f = 1/x^3 + x + x^2 + 3*x^4 # optional - sage.rings.finite_rings + sage: g = 1 - x + x^2 - x^4 # optional - sage.rings.finite_rings + sage: f*g # optional - sage.rings.finite_rings x^-3 + x^-2 + x^-1 + x^8 """ cdef LaurentPolynomial_univariate right = right_r @@ -1961,1809 +1964,3 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): 0 """ return self.__u[-self.__n] - - -cdef class LaurentPolynomial_mpair(LaurentPolynomial): - """ - Multivariate Laurent polynomials. - """ - def __init__(self, parent, x, mon=None, reduce=True): - """ - Currently, one can only create LaurentPolynomials out of dictionaries - and elements of the base ring. - - INPUT: - - - ``parent`` -- a SageMath parent - - - ``x`` -- an element or dictionary or anything the underlying - polynomial ring accepts - - - ``mon`` -- (default: ``None``) a tuple specifying the shift - in the exponents - - - ``reduce`` -- (default: ``True``) a boolean - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = L({(-1,-1):1}); f - w^-1*z^-1 - sage: f = L({(1,1):1}); f - w*z - sage: f = L({(-1,-1):1, (1,3):4}); f - 4*w*z^3 + w^-1*z^-1 - sage: L(1/2) - 1/2 - - TESTS: - - Check that :trac:`19538` is fixed:: - - sage: R = LaurentPolynomialRing(QQ,'x2,x0') - sage: S = LaurentPolynomialRing(QQ,'x',3) - sage: f = S.coerce_map_from(R) - sage: f(R.gen(0) + R.gen(1)^2) - x0^2 + x2 - sage: _.parent() - Multivariate Laurent Polynomial Ring in x0, x1, x2 over Rational Field - - :: - - sage: from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial_mpair - sage: LaurentPolynomial_mpair(L, {(1,2): 1/42}, mon=(-3, -3)) - 1/42*w^-2*z^-1 - - :trac:`22398`:: - - sage: LQ = LaurentPolynomialRing(QQ, 'x0, x1, x2, y0, y1, y2, y3, y4, y5') - sage: LZ = LaurentPolynomialRing(ZZ, 'x0, x1, x2, y0, y1, y2, y3, y4, y5') - sage: LQ.inject_variables() - Defining x0, x1, x2, y0, y1, y2, y3, y4, y5 - sage: x2^-1*y0*y1*y2*y3*y4*y5 + x1^-1*x2^-1*y0*y1*y3*y4 + x0^-1 in LZ - True - sage: x2^-1*y0*y1*y2*y3*y4*y5 + x1^-1*x2^-1*y0*y1*y3*y4 + x0^-1*x1^-1*y0*y3 + x0^-1 in LZ - True - - Check that input is not modified:: - - sage: LQ. = LaurentPolynomialRing(QQ) - sage: D = {(-1, 1): 1} - sage: k = tuple(D)[0] - sage: v = D[k] - sage: type(k), type(v) - (<... 'tuple'>, ) - sage: LQ(D) - x^-1*y - sage: tuple(D)[0] is k - True - sage: D[k] is v - True - """ - if isinstance(x, PolyDict): - x = x.dict() - if mon is not None: - if isinstance(mon, ETuple): - self._mon = mon - else: - self._mon = ETuple(mon) - else: - if isinstance(x, dict): - self._mon = ETuple({}, int(parent.ngens())) - D = {} - for k, x_k in x.iteritems(): # ETuple-ize keys, set _mon - if not isinstance(k, (tuple, ETuple)) or len(k) != parent.ngens(): - self._mon = ETuple({}, int(parent.ngens())) - break - if isinstance(k, tuple): - k = ETuple(k) - D[k] = x_k - self._mon = self._mon.emin(k) # point-wise min of _mon and k - else: - x = D - if not self._mon.is_constant(): # factor out _mon - x = {k.esub(self._mon): x_k for k, x_k in x.iteritems()} - elif (isinstance(x, LaurentPolynomial_mpair) and - parent.variable_names() == x.parent().variable_names()): - self._mon = (x)._mon - x = (x)._poly - else: # since x should coerce into parent, _mon should be (0,...,0) - self._mon = ETuple({}, int(parent.ngens())) - self._poly = parent._R(x) - CommutativeAlgebraElement.__init__(self, parent) - - def __reduce__(self): - """ - TESTS:: - - sage: R = LaurentPolynomialRing(QQ,2,'x') - sage: R. = LaurentPolynomialRing(QQ) - sage: loads(dumps(x1)) == x1 # indirect doctest - True - sage: z = x1/x2 - sage: loads(dumps(z)) == z - True - """ - return self._parent, (self._poly, self._mon) - - def __hash__(self): - r""" - TESTS: - - Test that the hash is non-constant (see also :trac:`27914`):: - - sage: L. = LaurentPolynomialRing(QQ) - sage: len({hash(w^i*z^j) for i in [-2..2] for j in [-2..2]}) - 25 - - Check that :trac:`20490` is fixed:: - - sage: R. = LaurentPolynomialRing(ZZ) - sage: p = a*~a - sage: p._fraction_pair() - (a, a) - sage: p == R.one() - True - sage: hash(p) - 1 - - Check that :trac:`23864` is fixed (compatibility with integers, rationals - and polynomial rings):: - - sage: L = LaurentPolynomialRing(QQ, 'x0,x1,x2') - sage: hash(L.zero()) - 0 - sage: hash(L.one()) - 1 - sage: hash(-L.one()) - -2 - sage: hash(L(1/2)) == hash(1/2) - True - - sage: R = PolynomialRing(QQ, 'x0,x1,x2') - sage: x0,x1,x2 = R.gens() - sage: hash(x0) == hash(L(x0)) - True - sage: hash(1 - 7*x0 + x1*x2) == hash(L(1 - 7*x0 + x1*x2)) - True - - Check that :trac:`27914` is fixed:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: Lw = LaurentPolynomialRing(QQ, 'w') - sage: Lz = LaurentPolynomialRing(QQ, 'z') - sage: all(hash(w^k) == hash(Lw(w^k)) - ....: and hash(z^k) == hash(Lz(z^k)) for k in (-5..5)) - True - sage: p = w^-1 + 2 + w - sage: hash(p) == hash(Lw(p)) - True - """ - # we reimplement the hash from multipolynomial to handle negative exponents - # (see multi_polynomial.pyx) - cdef long result = 0 - cdef long exponent - cdef list var_name_hash = [hash(v) for v in self._parent.variable_names()] - cdef int p - cdef int n = len(var_name_hash) - cdef long c_hash - for m, c in self._poly.iterator_exp_coeff(): - c_hash = hash(c) - if c_hash != 0: - for p in range(n): - exponent = m[p] + self._mon[p] - if exponent > 0: - c_hash = (1000003 * c_hash) ^ var_name_hash[p] - c_hash = (1000003 * c_hash) ^ exponent - elif exponent < 0: - c_hash = (1000003 * c_hash) ^ var_name_hash[p] - c_hash = (700005 * c_hash) ^ exponent - result += c_hash - - return result - - def _im_gens_(self, codomain, im_gens, base_map=None): - """ - Return the image of ``self`` under the morphism defined by - ``im_gens`` in ``codomain``. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(ZZ) - sage: M. = LaurentPolynomialRing(ZZ) - sage: phi = L.hom([u,v]) - sage: phi(x^2*~y -5*y**3) # indirect doctest - -5*v^3 + u^2*v^-1 - - TESTS: - - check compatibility with :trac:`26105`:: - - sage: F. = GF(4) - sage: LF. = LaurentPolynomialRing(F) - sage: rho = LF.hom([b,a], base_map=F.frobenius_endomorphism()) - sage: s = t*~a + b +~t*(b**-3)*a**2; rs = rho(s); rs - a + (t + 1)*b^-1 + t*a^-3*b^2 - sage: s == rho(rs) - True - """ - p = self._poly - m = self._mon - if base_map is not None: - p = p.map_coefficients(base_map) - from sage.misc.misc_c import prod - return codomain(p(im_gens) * prod(ig**m[im_gens.index(ig)] for ig in im_gens)) - - cdef _normalize(self, i=None): - r""" - Remove the common monomials from ``self._poly`` and store - them in ``self._mon``. - - INPUT: - - - ``i`` -- an integer - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = x*y + 2*y*x^2 + y # indirect doctest - sage: f.factor() # Notice the y has been factored out. - (y) * (2*x^2 + x + 1) - - Check that :trac:`23864` has been fixed:: - - sage: hash(L.zero()) - 0 - """ - if not self._poly: - self._mon = ETuple({}, int(self._parent.ngens())) - return - - #cdef dict D = self._poly._mpoly_dict_recursive( - # self._parent.variable_names(), - # self._parent.base_ring() - # ) - cdef dict D = self._poly.dict() - - cdef ETuple e - if i is None: - e = None - for k in D: - if e is None: - e = k - else: - e = e.emin(k) - if not e.is_constant(): - self._poly = (self._poly // self._poly._parent({e: 1})) - self._mon = self._mon.eadd(e) - else: - e = None - for k in D: - if e is None or k[i] < e: - e = k[i] - if e > 0: - self._poly = (self._poly // self._poly._parent.gen(i)) - self._mon = self._mon.eadd_p(e, i) - - cdef _compute_polydict(self): - """ - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: a = w^2*z^-1 +3 - sage: a.dict() # indirect doctest - {(0, 0): 3, (2, -1): 1} - """ - #cdef dict D = self._poly._mpoly_dict_recursive(self._parent.variable_names(), - # self._parent.base_ring()) - cdef dict D = self._poly.dict() - cdef dict DD - if self._mon.is_constant(): - self._prod = PolyDict(D) - return - DD = {} - for k in D: - DD[k.eadd(self._mon)] = D[k] - self._prod = PolyDict(DD) - - def is_unit(self): - """ - Return ``True`` if ``self`` is a unit. - - The ground ring is assumed to be an integral domain. - - This means that the Laurent polynomial is a monomial - with unit coefficient. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: (x*y/2).is_unit() - True - sage: (x + y).is_unit() - False - sage: (L.zero()).is_unit() - False - sage: (L.one()).is_unit() - True - - sage: L. = LaurentPolynomialRing(ZZ) - sage: (2*x*y).is_unit() - False - """ - coeffs = self.coefficients() - if len(coeffs) != 1: - return False - return coeffs[0].is_unit() - - def _repr_(self): - """ - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = x^2 + x*y/2 + 2*y^-1 - sage: f._repr_() - 'x^2 + 1/2*x*y + 2*y^-1' - """ - if self._prod is None: - self._compute_polydict() - try: - key = self.parent().term_order().sortkey - except AttributeError: - key = None - atomic = self.parent().base_ring()._repr_option('element_is_atomic') - return self._prod.poly_repr(self.parent().variable_names(), - atomic_coefficients=atomic, sortkey=key) - - def _latex_(self): - r""" - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: a = w^2*z^-1+3; a - w^2*z^-1 + 3 - sage: latex(a) - w^{2} z^{-1} + 3 - - TESTS:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: latex(1/lambda2 + y2^(-3)) - \lambda_{2}^{-1} + y_{2}^{-3} - """ - if self._prod is None: - self._compute_polydict() - try: - key = self.parent().term_order().sortkey - except AttributeError: - key = None - atomic = self.parent().base_ring()._repr_option('element_is_atomic') - return self._prod.latex(self.parent().latex_variable_names(), - atomic_coefficients=atomic, sortkey=key) - - cpdef long number_of_terms(self) except -1: - """ - Return the number of non-zero coefficients of ``self``. - - Also called weight, hamming weight or sparsity. - - EXAMPLES:: - - sage: R. = LaurentPolynomialRing(ZZ) - sage: f = x^3 - y - sage: f.number_of_terms() - 2 - sage: R(0).number_of_terms() - 0 - sage: f = (x+1/y)^100 - sage: f.number_of_terms() - 101 - - The method :meth:`hamming_weight` is an alias:: - - sage: f.hamming_weight() - 101 - """ - return self._poly.number_of_terms() - - def __invert__(LaurentPolynomial_mpair self): - """ - Return the inverse of ``self``. - - This treats monomials specially so they remain Laurent - polynomials; the inverse of any other polynomial is an element - of the rational function field. - - TESTS:: - - sage: L. = LaurentPolynomialRing(ZZ) - sage: f = ~x - sage: parent(f) - Multivariate Laurent Polynomial Ring in x, y over Integer Ring - sage: parent(f.coefficients()[0]) is parent(f).base_ring() - True - sage: g = ~(2*x) - sage: parent(g) - Multivariate Laurent Polynomial Ring in x, y over Rational Field - sage: parent(g.coefficients()[0]) is parent(g).base_ring() - True - """ - cdef ETuple e - if self._poly.is_term(): - (e, c), = self.dict().items() - e = e.emul(-1) - P = self._parent - try: - c = c.inverse_of_unit() - except (AttributeError, ZeroDivisionError, ArithmeticError): - c = ~c - if c.parent() is not P.base_ring(): - P = P.change_ring(c.parent()) - return P({e: c}) - return super().__invert__() - - def __pow__(LaurentPolynomial_mpair self, n, m): - """ - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = x + y - sage: f^2 - x^2 + 2*x*y + y^2 - sage: f^(-1) - 1/(x + y) - - TESTS: - - Check that :trac:`2952` is fixed:: - - sage: R. = QQ[] - sage: L. = LaurentPolynomialRing(R) - sage: f = (x+y+z^-1)^2 - sage: f.substitute(z=1) - x^2 + 2*x*y + y^2 + 2*x + 2*y + 1 - """ - cdef LaurentPolynomial_mpair ans - if n < 0: - return ~(self ** -n) - ans = self._new_c() - ans._poly = self._poly ** n - ans._mon = self._mon.emul(n) - return ans - - def __getitem__(self, n): - r""" - Return the coefficient of `x^n = x_1^{n_1} \cdots x_k^{n_k}` where - `n` is a tuple of length `k` and `k` is the number of variables. - - If the number of inputs is not equal to the number of variables, this - raises a ``TypeError``. - - EXAMPLES:: - - sage: P. = LaurentPolynomialRing(QQ) - sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3 + x*z; f - -x^6 + x*z - 7*x^-2*y^3 + 5*x^-2*y + x^-3*y^2 - sage: f[6,0,0] - -1 - sage: f[-2,3,0] - -7 - sage: f[-1,4,2] - 0 - sage: f[1,0,1] - 1 - sage: f[6] - Traceback (most recent call last): - ... - TypeError: must have exactly 3 inputs - sage: f[6,0] - Traceback (most recent call last): - ... - TypeError: must have exactly 3 inputs - sage: f[6,0,0,0] - Traceback (most recent call last): - ... - TypeError: must have exactly 3 inputs - """ - if isinstance(n, slice): - raise TypeError("multivariate Laurent polynomials are not iterable") - if not isinstance(n, tuple) or len(n) != self._parent.ngens(): - raise TypeError("must have exactly %s inputs" % - self.parent().ngens()) - cdef ETuple t = ETuple(n) - if self._prod is None: - self._compute_polydict() - try: - return self._prod[t] - except KeyError: - return self._parent.base_ring().zero() - - def __iter__(self): - """ - Iterate through all terms by returning a list of the coefficient and - the corresponding monomial. - - EXAMPLES:: - - sage: P. = LaurentPolynomialRing(QQ) - sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3 - sage: sorted(f) # indirect doctest - [(-7, x^-2*y^3), (-1, x^6), (1, x^-3*y^2), (5, x^-2*y)] - """ - P = self._parent - one = P._R.one() - if self._mon.is_constant(): - for exp, coeff in self._poly.iterator_exp_coeff(): - yield (coeff, P.element_class(P, one, exp)) - else: - for exp, coeff in self._poly.iterator_exp_coeff(): - yield (coeff, P.element_class(P, one, exp.eadd(self._mon))) - - def iterator_exp_coeff(self): - """ - Iterate over ``self`` as pairs of (ETuple, coefficient). - - EXAMPLES:: - - sage: P. = LaurentPolynomialRing(QQ) - sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3 - sage: list(f.iterator_exp_coeff()) - [((6, 0), -1), ((-2, 3), -7), ((-2, 1), 5), ((-3, 2), 1)] - """ - for exp, coeff in self._poly.iterator_exp_coeff(): - yield (exp.eadd(self._mon), coeff) - - def monomials(self): - """ - Return the list of monomials in ``self``. - - EXAMPLES:: - - sage: P. = LaurentPolynomialRing(QQ) - sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3 - sage: sorted(f.monomials()) - [x^-3*y^2, x^-2*y, x^-2*y^3, x^6] - """ - return [mon for coeff, mon in self] - - def monomial_coefficient(self, mon): - """ - Return the coefficient in the base ring of the monomial ``mon`` in - ``self``, where ``mon`` must have the same parent as ``self``. - - This function contrasts with the function :meth:`coefficient()` - which returns the coefficient of a monomial viewing this - polynomial in a polynomial ring over a base ring having fewer - variables. - - INPUT: - - - ``mon`` -- a monomial - - .. SEEALSO:: - - For coefficients in a base ring of fewer variables, see - :meth:`coefficient()`. - - EXAMPLES:: - - sage: P. = LaurentPolynomialRing(QQ) - sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3 - sage: f.monomial_coefficient(x^-2*y^3) - -7 - sage: f.monomial_coefficient(x^2) - 0 - - TESTS:: - - sage: P. = LaurentPolynomialRing(QQ) - sage: f = y^2 * x^-2 - sage: f.monomial_coefficient(x + y) - Traceback (most recent call last): - ... - ValueError: not a monomial - """ - if parent(mon) != self._parent: - raise TypeError("input must have the same parent") - cdef LaurentPolynomial_mpair m = mon - if m._prod is None: - m._compute_polydict() - if self._prod is None: - self._compute_polydict() - exp = monomial_exponent(m._prod) - zero = self._parent.base_ring().zero() - return self._prod.get(exp, zero) - - def constant_coefficient(self): - """ - Return the constant coefficient of ``self``. - - EXAMPLES:: - - sage: P. = LaurentPolynomialRing(QQ) - sage: f = (y^2 - x^9 - 7*x*y^2 + 5*x*y)*x^-3; f - -x^6 - 7*x^-2*y^2 + 5*x^-2*y + x^-3*y^2 - sage: f.constant_coefficient() - 0 - sage: f = (x^3 + 2*x^-2*y+y^3)*y^-3; f - x^3*y^-3 + 1 + 2*x^-2*y^-2 - sage: f.constant_coefficient() - 1 - """ - return self[(0,)*self._parent.ngens()] - - def coefficient(self, mon): - r""" - Return the coefficient of ``mon`` in ``self``, where ``mon`` must - have the same parent as ``self``. - - The coefficient is defined as follows. If `f` is this polynomial, then - the coefficient `c_m` is sum: - - .. MATH:: - - c_m := \sum_T \frac{T}{m} - - where the sum is over terms `T` in `f` that are exactly divisible - by `m`. - - A monomial `m(x,y)` 'exactly divides' `f(x,y)` if `m(x,y) | f(x,y)` - and neither `x \cdot m(x,y)` nor `y \cdot m(x,y)` divides `f(x,y)`. - - INPUT: - - - ``mon`` -- a monomial - - OUTPUT: - - Element of the parent of ``self``. - - .. NOTE:: - - To get the constant coefficient, call - :meth:`constant_coefficient()`. - - EXAMPLES:: - - sage: P. = LaurentPolynomialRing(QQ) - - The coefficient returned is an element of the parent of ``self``; in - this case, ``P``. :: - - sage: f = 2 * x * y - sage: c = f.coefficient(x*y); c - 2 - sage: c.parent() - Multivariate Laurent Polynomial Ring in x, y over Rational Field - - sage: P. = LaurentPolynomialRing(QQ) - sage: f = (y^2 - x^9 - 7*x*y^2 + 5*x*y)*x^-3; f - -x^6 - 7*x^-2*y^2 + 5*x^-2*y + x^-3*y^2 - sage: f.coefficient(y) - 5*x^-2 - sage: f.coefficient(y^2) - -7*x^-2 + x^-3 - sage: f.coefficient(x*y) - 0 - sage: f.coefficient(x^-2) - -7*y^2 + 5*y - sage: f.coefficient(x^-2*y^2) - -7 - sage: f.coefficient(1) - -x^6 - 7*x^-2*y^2 + 5*x^-2*y + x^-3*y^2 - """ - if mon.parent() is not self._parent: - mon = self._parent(mon) - cdef LaurentPolynomial_mpair m = mon - if self._prod is None: - self._compute_polydict() - if m._prod is None: - m._compute_polydict() - return self._parent(self._prod.coefficient(m.dict())) - - def coefficients(self): - """ - Return the nonzero coefficients of ``self`` in a list. - - The returned list is decreasingly ordered by the term ordering - of ``self.parent()``. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ,order='degrevlex') - sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 - sage: f.coefficients() - [4, 3, 2, 1] - sage: L. = LaurentPolynomialRing(QQ,order='lex') - sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 - sage: f.coefficients() - [4, 1, 2, 3] - """ - return self._poly.coefficients() - - def variables(self, sort=True): - """ - Return a tuple of all variables occurring in ``self``. - - INPUT: - - - ``sort`` -- specifies whether the indices shall be sorted - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 - sage: f.variables() - (z, y, x) - sage: f.variables(sort=False) #random - (y, z, x) - """ - cdef dict d = self.dict() - cdef tuple g = self._parent.gens() - cdef Py_ssize_t nvars = len(g) - cdef set vars = set() - for k in d: - vars.update(k.nonzero_positions()) - if len(vars) == nvars: - break - cdef list v = [g[i] for i in vars] - if sort: - v.sort() - return tuple(v) - - cpdef dict dict(self): - """ - Return ``self`` represented as a ``dict``. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 - sage: sorted(f.dict().items()) - [((3, 1, 0), 3), ((4, 0, -2), 2), ((6, -7, 0), 1), ((7, 0, -1), 4)] - """ - if self._prod is None: - self._compute_polydict() - return self._prod.dict() - - def _fraction_pair(self): - """ - Return one representation of ``self`` as a pair - ``(numerator, denominator)``. - - Here both the numerator and the denominator are polynomials. - - This is used for coercion into the fraction field. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 - sage: f._fraction_pair() - (4*x^7*y^7*z + 3*x^3*y^8*z^2 + 2*x^4*y^7 + x^6*z^2, y^7*z^2) - """ - ring = self._parent._R - numer = self._poly - denom = ring.one() - var = ring.gens() - for i, j in enumerate(self._mon): - if j > 0: - numer *= var[i] ** j - else: - denom *= var[i] ** (-j) - return (numer, denom) - - cpdef _add_(self, _right): - """ - Return the Laurent polynomial ``self + right``. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = x + y^-1 - sage: g = y + z - sage: f + g - x + y + z + y^-1 - """ - cdef LaurentPolynomial_mpair ans = self._new_c() - cdef LaurentPolynomial_mpair right = _right - ans._mon, a, b = self._mon.combine_to_positives(right._mon) - if not a.is_constant(): - ans._poly = self._poly * self._poly._parent({a: 1}) - else: - ans._poly = self._poly - if not b.is_constant(): - ans._poly += right._poly * self._poly._parent({b: 1}) - else: - ans._poly += right._poly - return ans - - cpdef _sub_(self, _right): - """ - Return the Laurent polynomial ``self - right``. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = x + y^-1 - sage: g = y + z + x - sage: f - g - -y - z + y^-1 - """ - cdef LaurentPolynomial_mpair ans = self._new_c() - cdef LaurentPolynomial_mpair right = _right - cdef ETuple a, b - ans._mon, a, b = self._mon.combine_to_positives(right._mon) - if not a.is_constant(): - ans._poly = self._poly * self._poly._parent({a: 1}) - else: - ans._poly = self._poly - if not b.is_constant(): - ans._poly -= right._poly * self._poly._parent({b: 1}) - else: - ans._poly -= right._poly - return ans - - cpdef _div_(self, rhs): - """ - Return the division of ``self`` by ``rhs``. - - If the denominator is not a unit, - the result will be given in the fraction field. - - EXAMPLES:: - - sage: R. = LaurentPolynomialRing(QQ) - sage: 1/s - s^-1 - sage: 1/(s*q) - s^-1*q^-1 - sage: 1/(s+q) - 1/(s + q) - sage: (1/(s+q)).parent() - Fraction Field of Multivariate Polynomial Ring in s, q, t over Rational Field - sage: (1/(s*q)).parent() - Multivariate Laurent Polynomial Ring in s, q, t over Rational Field - sage: (s+q)/(q^2*t^(-2)) - s*q^-2*t^2 + q^-1*t^2 - """ - cdef LaurentPolynomial_mpair right = rhs - if right.is_zero(): - raise ZeroDivisionError - if right._poly.is_term(): - return self * ~right - else: - return RingElement._div_(self, rhs) - - def is_monomial(self): - """ - Return ``True`` if ``self`` is a monomial. - - EXAMPLES:: - - sage: k. = LaurentPolynomialRing(QQ) - sage: z.is_monomial() - True - sage: k(1).is_monomial() - True - sage: (z+1).is_monomial() - False - sage: (z^-2909).is_monomial() - True - sage: (38*z^-2909).is_monomial() - False - """ - return self._poly.is_monomial() - - cpdef _neg_(self): - """ - Return ``-self``. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = x + y^-1 - sage: -f - -x - y^-1 - """ - cdef LaurentPolynomial_mpair ans = self._new_c() - ans._mon = self._mon - ans._poly = -self._poly - return ans - - cpdef _lmul_(self, Element right): - """ - Return ``self * right`` where ``right`` is in ``self``'s base ring. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = x + y^-1 - sage: f*(1/2) - 1/2*x + 1/2*y^-1 - """ - cdef LaurentPolynomial_mpair ans = self._new_c() - ans._mon = self._mon - ans._poly = self._poly * right - return ans - - cpdef _rmul_(self, Element left): - """ - Return ``left * self`` where ``left`` is in ``self``'s base ring. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = x + y^-1 - sage: (1/2)*f - 1/2*x + 1/2*y^-1 - """ - cdef LaurentPolynomial_mpair ans = self._new_c() - ans._mon = self._mon - ans._poly = left * self._poly - return ans - - cpdef _mul_(self, right): - """ - Return ``self * right``. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = x + y^-1 - sage: g = y + z - sage: f*g - x*y + x*z + 1 + y^-1*z - """ - cdef LaurentPolynomial_mpair ans = self._new_c() - ans._mon = self._mon.eadd((right)._mon) - ans._poly = self._poly * (right)._poly - return ans - - cpdef _floordiv_(self, right): - """ - Perform division with remainder and return the quotient. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = x^3 + y^-3 - sage: g = y + x - sage: f // g - x^5*y^-3 - x^4*y^-2 + x^3*y^-1 - - sage: h = x + y^(-1) - sage: f // h - x^2 - x*y^-1 + y^-2 - sage: h * (f // h) == f - True - sage: f // 1 - x^3 + y^-3 - sage: 1 // f - 0 - - TESTS: - - Check that :trac:`19357` is fixed:: - - sage: x // y - x*y^-1 - - Check that :trac:`21999` is fixed:: - - sage: L. = LaurentPolynomialRing(QQbar) - sage: (a+a*b) // a - b + 1 - """ - cdef LaurentPolynomial_mpair ans = self._new_c() - cdef LaurentPolynomial_mpair rightl = right - self._normalize() - rightl._normalize() - ans._mon = self._mon.esub(rightl._mon) - ans._poly = self._poly // rightl._poly - return ans - - @coerce_binop - def quo_rem(self, right): - """ - Divide this Laurent polynomial by ``right`` and return a quotient and - a remainder. - - INPUT: - - - ``right`` -- a Laurent polynomial - - OUTPUT: - - A pair of Laurent polynomials. - - EXAMPLES:: - - sage: R. = LaurentPolynomialRing(QQ) - sage: (s^2-t^2).quo_rem(s-t) - (s + t, 0) - sage: (s^-2-t^2).quo_rem(s-t) - (s + t, -s^2 + s^-2) - sage: (s^-2-t^2).quo_rem(s^-1-t) - (t + s^-1, 0) - - TESTS: - - Verify that :trac:`31257` is fixed:: - - sage: R. = LaurentPolynomialRing(QQ) - sage: q, r = (1/x).quo_rem(y) - sage: q, r - (x^-1*y^-1, 0) - sage: q*y + r == 1/x - True - sage: q,r = (x^-2 - y^2).quo_rem(x - y) - sage: q*(x - y) + r == x^-2 - y^2 - True - """ - # make copies of self and right so that the input can be normalized - # without affecting the objects that were passed to the method - cdef LaurentPolynomial_mpair selfl = self._new_c() - selfl._poly = self._poly - selfl._mon = self._mon - cdef LaurentPolynomial_mpair rightl = self._new_c() - rightl._poly = ( right)._poly - rightl._mon = ( right)._mon - - selfl._normalize() - rightl._normalize() - q, r = selfl._poly.quo_rem(rightl._poly) - ql = LaurentPolynomial_mpair(self._parent, q, - mon=selfl._mon.esub(rightl._mon)) - rl = LaurentPolynomial_mpair(self._parent, r, - mon=selfl._mon) - ql._normalize() - rl._normalize() - return (ql, rl) - - cpdef _richcmp_(self, right, int op): - """ - Compare two polynomials in a `LaurentPolynomialRing` based on the term - order from the parent ring. If the parent ring does not specify a term - order then only comparison by equality is supported. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = x + y^-1 - sage: g = y + z - sage: f == f - True - sage: f == g - False - sage: f == 2 - False - """ - if self._prod is None: - self._compute_polydict() - if ( right)._prod is None: - ( right)._compute_polydict() - - try: - sortkey = self._parent.term_order().sortkey - except AttributeError: - sortkey = None - - return self._prod.rich_compare((right)._prod, - op, sortkey) - - def exponents(self): - """ - Return a list of the exponents of ``self``. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: a = w^2*z^-1+3; a - w^2*z^-1 + 3 - sage: e = a.exponents() - sage: e.sort(); e - [(0, 0), (2, -1)] - - """ - return [a.eadd(self._mon) for a in self._poly.exponents()] - - def degree(self, x=None): - """ - Return the degree of ``x`` in ``self``. - - EXAMPLES:: - - sage: R. = LaurentPolynomialRing(QQ) - sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 - sage: f.degree(x) - 7 - sage: f.degree(y) - 1 - sage: f.degree(z) - 0 - """ - if not x: - return self._poly.total_degree() + sum(self._mon) - - cdef tuple g = self._parent.gens() - cdef Py_ssize_t i - cdef bint no_generator_found = True - for i in range(len(g)): - if g[i] is x: - no_generator_found = False - break - if no_generator_found: - raise TypeError("x must be a generator of parent") - return self._poly.degree(self._parent._R.gens()[i]) + self._mon[i] - - def has_inverse_of(self, i): - """ - INPUT: - - - ``i`` -- The index of a generator of ``self.parent()`` - - OUTPUT: - - Returns True if self contains a monomial including the inverse of - ``self.parent().gen(i)``, False otherwise. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 - sage: f.has_inverse_of(0) - False - sage: f.has_inverse_of(1) - True - sage: f.has_inverse_of(2) - True - """ - if (not isinstance(i, (int, Integer))) or (i < 0) or (i >= self._parent.ngens()): - raise TypeError("argument is not the index of a generator") - if self._mon[i] < 0: - self._normalize(i) - if self._mon[i] < 0: - return True - return False - return False - - def has_any_inverse(self): - """ - Returns True if self contains any monomials with a negative exponent, False otherwise. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 - sage: f.has_any_inverse() - True - sage: g = x^2 + y^2 - sage: g.has_any_inverse() - False - """ - for m in self._mon.nonzero_values(sort=False): - if m < 0: - return True - return False - - def __call__(self, *x, **kwds): - """ - Compute value of ``self`` at ``x``. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = x + 2*y + 3*z - sage: f(1,1,1) - 6 - sage: f = x^-1 + y + z - sage: f(0,1,1) - Traceback (most recent call last): - ... - ZeroDivisionError - - TESTS:: - - sage: f = x + 2*y + 3*z - sage: f(2) - Traceback (most recent call last): - ... - TypeError: number of arguments does not match the number of generators in parent - sage: f(2,0) - Traceback (most recent call last): - ... - TypeError: number of arguments does not match the number of generators in parent - sage: f( (1,1,1) ) - 6 - """ - if kwds: - f = self.subs(**kwds) - if x: # More than 1 non-keyword argument - return f(*x) - else: - return f - - cdef int l = len(x) - - if l == 1 and isinstance(x[0], (tuple, list)): - x = x[0] - l = len(x) - - if l != self._parent.ngens(): - raise TypeError("number of arguments does not match the number" - " of generators in parent") - - #Check to make sure that we aren't dividing by zero - cdef Py_ssize_t m - for m in range(l): - if x[m] == 0: - if self.has_inverse_of(m): - raise ZeroDivisionError - - ans = self._poly(*x) - if ans: - for m in self._mon.nonzero_positions(): - ans *= x[m]**self._mon[m] - - return ans - - def subs(self, in_dict=None, **kwds): - """ - Substitute some variables in this Laurent polynomial. - - Variable/value pairs for the substitution may be given - as a dictionary or via keyword-value pairs. If both are - present, the latter take precedence. - - INPUT: - - - ``in_dict`` -- dictionary (optional) - - - ``**kwargs`` -- keyword arguments - - OUTPUT: - - A Laurent polynomial. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = x + 2*y + 3*z - sage: f.subs(x=1) - 2*y + 3*z + 1 - sage: f.subs(y=1) - x + 3*z + 2 - sage: f.subs(z=1) - x + 2*y + 3 - sage: f.subs(x=1, y=1, z=1) - 6 - - sage: f = x^-1 - sage: f.subs(x=2) - 1/2 - sage: f.subs({x: 2}) - 1/2 - - sage: f = x + 2*y + 3*z - sage: f.subs({x: 1, y: 1, z: 1}) - 6 - sage: f.substitute(x=1, y=1, z=1) - 6 - - TESTS:: - - sage: f = x + 2*y + 3*z - sage: f(q=10) - x + 2*y + 3*z - - sage: x.subs({x: 2}, x=1) - 1 - """ - cdef list variables = list(self._parent.gens()) - cdef Py_ssize_t i - for i in range(len(variables)): - if str(variables[i]) in kwds: - variables[i] = kwds[str(variables[i])] - elif in_dict and variables[i] in in_dict: - variables[i] = in_dict[variables[i]] - return self(tuple(variables)) - - def is_constant(self): - r""" - Return whether this Laurent polynomial is constant. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: L(0).is_constant() - True - sage: L(42).is_constant() - True - sage: a.is_constant() - False - sage: (1/b).is_constant() - False - """ - return (self._mon == ETuple({}, int(self._parent.ngens())) and - self._poly.is_constant()) - - def _symbolic_(self, R): - """ - EXAMPLES:: - - sage: R. = LaurentPolynomialRing(QQ) - sage: f = x^3 + y/x - sage: g = f._symbolic_(SR); g - (x^4 + y)/x - sage: g(x=2,y=2) - 9 - - sage: g = SR(f) - sage: g(x=2,y=2) - 9 - """ - d = {repr(g): R.var(g) for g in self._parent.gens()} - return self.subs(**d) - - def derivative(self, *args): - r""" - The formal derivative of this Laurent polynomial, with respect - to variables supplied in args. - - Multiple variables and iteration counts may be supplied; see - documentation for the global :func:`derivative` function for more - details. - - .. SEEALSO:: - - :meth:`_derivative` - - EXAMPLES:: - - sage: R = LaurentPolynomialRing(ZZ,'x, y') - sage: x, y = R.gens() - sage: t = x**4*y+x*y+y+x**(-1)+y**(-3) - sage: t.derivative(x, x) - 12*x^2*y + 2*x^-3 - sage: t.derivative(y, 2) - 12*y^-5 - """ - return multi_derivative(self, args) - - # add .diff(), .differentiate() as aliases for .derivative() - diff = differentiate = derivative - - def _derivative(self, var=None): - """ - Computes formal derivative of this Laurent polynomial with - respect to the given variable. - - If var is among the generators of this ring, the derivative - is with respect to the generator. Otherwise, ``_derivative(var)`` is called - recursively for each coefficient of this polynomial. - - .. SEEALSO:: :meth:`derivative` - - EXAMPLES:: - - sage: R = LaurentPolynomialRing(ZZ,'x, y') - sage: x, y = R.gens() - sage: t = x**4*y+x*y+y+x**(-1)+y**(-3) - sage: t._derivative(x) - 4*x^3*y + y - x^-2 - sage: t._derivative(y) - x^4 + x + 1 - 3*y^-4 - - sage: R = LaurentPolynomialRing(QQ['z'],'x') - sage: z = R.base_ring().gen() - sage: x = R.gen() - sage: t = 33*z*x**4+x**(-1) - sage: t._derivative(z) - 33*x^4 - sage: t._derivative(x) - -x^-2 + 132*z*x^3 - """ - if var is None: - raise ValueError("must specify which variable to differentiate " - "with respect to") - P = self._parent - cdef list gens = list(P.gens()) - - # check if var is one of the generators - try: - index = gens.index(var) - except ValueError: - # call _derivative() recursively on coefficients - return P({m: c._derivative(var) - for (m, c) in self.dict().iteritems()}) - - # compute formal derivative with respect to generator - cdef dict d = {} - for m, c in self.dict().iteritems(): - if m[index] != 0: - new_m = [u for u in m] - new_m[index] += -1 - d[ETuple(new_m)] = m[index] * c - return P(d) - - def is_univariate(self): - """ - Return ``True`` if this is a univariate or constant Laurent polynomial, - and ``False`` otherwise. - - EXAMPLES:: - - sage: R. = LaurentPolynomialRing(QQ) - sage: f = (x^3 + y^-3)*z - sage: f.is_univariate() - False - sage: g = f(1,y,4) - sage: g.is_univariate() - True - sage: R(1).is_univariate() - True - """ - return len(self.variables()) < 2 - - def univariate_polynomial(self, R=None): - """ - Returns a univariate polynomial associated to this - multivariate polynomial. - - INPUT: - - - ``R`` - (default: ``None``) a univariate Laurent polynomial ring - - If this polynomial is not in at most one variable, then a - ``ValueError`` exception is raised. The new polynomial is over - the same base ring as the given ``LaurentPolynomial`` and in the - variable ``x`` if no ring ``R`` is provided. - - EXAMPLES:: - - sage: R. = LaurentPolynomialRing(ZZ) - sage: f = 3*x^2 - 2*y^-1 + 7*x^2*y^2 + 5 - sage: f.univariate_polynomial() - Traceback (most recent call last): - ... - TypeError: polynomial must involve at most one variable - sage: g = f(10,y); g - 700*y^2 + 305 - 2*y^-1 - sage: h = g.univariate_polynomial(); h - -2*y^-1 + 305 + 700*y^2 - sage: h.parent() - Univariate Laurent Polynomial Ring in y over Integer Ring - sage: g.univariate_polynomial(LaurentPolynomialRing(QQ,'z')) - -2*z^-1 + 305 + 700*z^2 - - Here's an example with a constant multivariate polynomial:: - - sage: g = R(1) - sage: h = g.univariate_polynomial(); h - 1 - sage: h.parent() - Univariate Laurent Polynomial Ring in x over Integer Ring - """ - from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing - v = self.variables() - if len(v) > 1: - raise TypeError("polynomial must involve at most one variable") - elif len(v) == 1: - x = v[0] - i = self._parent.gens().index(x) - x = str(x) - else: - x = 'x' - i = 0 - - #construct ring if none - if R is None: - R = LaurentPolynomialRing(self.base_ring(), x) - - return R({m[i]: c for m,c in self.dict().iteritems()}) - - def factor(self): - """ - Returns a Laurent monomial (the unit part of the factorization) and a factored multi-polynomial. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 - sage: f.factor() - (x^3*y^-7*z^-2) * (4*x^4*y^7*z + 3*y^8*z^2 + 2*x*y^7 + x^3*z^2) - - TESTS: - - Tests for :trac:`29173`:: - - sage: L. = LaurentPolynomialRing(ZZ, 'a, b') - sage: (a*b + a + b + 1).factor() - (b + 1) * (a + 1) - sage: ((a^-1)*(a*b + a + b + 1)).factor() - (a^-1) * (b + 1) * (a + 1) - sage: L(-12).factor() - -1 * 2^2 * 3 - """ - pf = self._poly.factor() - - if self._poly.degree() == 0: - # Factorization is broken for polynomials, see - # https://github.com/sagemath/sage/issues/20214 - return pf - - u = self.parent(pf.unit()) - - cdef tuple g = self._parent.gens() - for i in self._mon.nonzero_positions(): - u *= g[i] ** self._mon[i] - - cdef list f = [] - cdef dict d - for t in pf: - d = (t[0].dict()) - if len(d) == 1: # monomials are units - u *= self.parent(d) ** t[1] - else: - f.append((self.parent(d), t[1])) - - return Factorization(f, unit=u) - - def is_square(self, root=False): - r""" - Test whether this Laurent polynomial is a square. - - INPUT: - - - ``root`` - boolean (default ``False``) - if set to ``True`` - then return a pair ``(True, sqrt)`` with ``sqrt`` a square - root of this Laurent polynomial when it exists or - ``(False, None)``. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ) - sage: p = (1 + x*y + z^-3) - sage: (p**2).is_square() - True - sage: (p**2).is_square(root=True) - (True, x*y + 1 + z^-3) - - sage: x.is_square() - False - sage: x.is_square(root=True) - (False, None) - - sage: (x**-4 * (1 + z)).is_square(root=False) - False - sage: (x**-4 * (1 + z)).is_square(root=True) - (False, None) - """ - self._normalize() - if not self._mon.is_multiple_of(2): - return (False, None) if root else False - - cdef LaurentPolynomial_mpair ans - - if not root: - return self._poly.is_square(root=False) - else: - (pans, root) = self._poly.is_square(root=True) - if not pans: - return (False, None) - - mon = self._mon.escalar_div(2) - ans = self._new_c() - ans._mon = mon - ans._poly = root - return (True, ans) - - cpdef rescale_vars(self, dict d, h=None, new_ring=None): - r""" - Rescale variables in a Laurent polynomial. - - INPUT: - - - ``d`` -- a ``dict`` whose keys are the generator indices - and values are the coefficients; so a pair ``(i, v)`` - means `x_i \mapsto v x_i` - - ``h`` -- (optional) a map to be applied to coefficients - done after rescaling - - ``new_ring`` -- (optional) a new ring to map the result into - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ, 2) - sage: p = x^-2*y + x*y^-2 - sage: p.rescale_vars({0: 2, 1: 3}) - 2/9*x*y^-2 + 3/4*x^-2*y - sage: F = GF(2) - sage: p.rescale_vars({0: 3, 1: 7}, new_ring=L.change_ring(F)) - x*y^-2 + x^-2*y - - Test for :trac:`30331`:: - - sage: F. = CyclotomicField(3) - sage: p.rescale_vars({0: 2, 1: z}, new_ring=L.change_ring(F)) - 2*z*x*y^-2 + 1/4*z*x^-2*y - """ - cdef int i - cdef dict df - cdef ETuple v - cdef LaurentPolynomial_mpair ans - - if self._prod is None: - self._compute_polydict() - - df = dict(self._prod.__repn) # This makes a copy for us to manipulate - if new_ring is None: - R = self._parent._base - else: - R = new_ring._base - if h is None: - for v in df: - val = df[v] - for i in d: - val *= d[i]**v[i] - df[v] = val - else: - for v in df: - val = df[v] - for i in d: - val *= d[i]**v[i] - df[v] = R(h(val)) - - ans = self._new_c() - ans._prod = PolyDict(df) - ans._mon = self._mon - if new_ring is None: - S = self._poly._parent - else: - S = self._poly._parent.change_ring(R) - ans._poly = S({v.esub(ans._mon): df[v] for v in df}) - if new_ring is not None: - return new_ring(ans) - return ans - - cpdef toric_coordinate_change(self, M, h=None, new_ring=None): - r""" - Apply a matrix to the exponents in a Laurent polynomial. - - For efficiency, we implement this directly, rather than as a substitution. - - The optional argument ``h`` is a map to be applied to coefficients. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ, 2) - sage: p = 2*x^2 + y - x*y - sage: p.toric_coordinate_change(Matrix([[1,-3],[1,1]])) - 2*x^2*y^2 - x^-2*y^2 + x^-3*y - sage: F = GF(2) - sage: p.toric_coordinate_change(Matrix([[1,-3],[1,1]]), new_ring=L.change_ring(F)) - x^-2*y^2 + x^-3*y - - """ - cdef int n, i, j, x - cdef dict d, dr - cdef ETuple v - cdef LaurentPolynomial_mpair ans - cdef list L, mon, exp - cdef Matrix mat = M - - n = self._parent.ngens() - if mat.dimensions() != (n, n): - raise ValueError("the matrix M must be a {k} x {k} matrix".format(k=n)) - - if not self: - if new_ring is None: - return self._parent.zero() - else: - return new_ring.zero() - - if self._prod is None: - self._compute_polydict() - - d = self._prod.__repn - dr = {} - mon = [0] * n - for v in d: - # Make a copy of mon as this might be faster than creating the data from scratch. - # We will set every entry, so no need to clear the data. - exp = list(mon) - for j in range(n): - x = 0 - for i in range(n): - if not mat.get_is_zero_unsafe(j, i): - x += ( v[i]) * int(mat.get_unsafe(j, i)) - if x < ( mon[j]): - mon[j] = x - exp[j] = x - dr[ETuple(exp)] = d[v] - - if h is not None: - for v in dr: - dr[v] = self._parent._base(h(dr[v])) - - ans = self._new_c() - ans._prod = PolyDict(dr) - ans._mon = ETuple(mon) - ans._poly = self._poly._parent({v.esub(ans._mon): dr[v] for v in dr}) - if new_ring is not None: - return new_ring(ans) - return ans - - cpdef toric_substitute(self, v, v1, a, h=None, new_ring=None): - r""" - Perform a single-variable substitution up to a toric coordinate change. - - The optional argument ``h`` is a map to be applied to coefficients. - - EXAMPLES:: - - sage: L. = LaurentPolynomialRing(QQ, 2) - sage: p = x + y - sage: p.toric_substitute((2,3), (-1,1), 2) - 1/2*x^3*y^3 + 2*x^-2*y^-2 - sage: F = GF(5) - sage: p.toric_substitute((2,3), (-1,1), 2, new_ring=L.change_ring(F)) - 3*x^3*y^3 + 2*x^-2*y^-2 - - TESTS: - - Tests for :trac:`30331`:: - - sage: L. = LaurentPolynomialRing(QQ, 2) - sage: p = x + y - sage: F. = CyclotomicField(3) - sage: p.toric_substitute((2,3), (-1,1), z, new_ring=L.change_ring(F)) - (-z - 1)*x^3*y^3 + z*x^-2*y^-2 - - sage: P. = LaurentPolynomialRing(QQ, 1) - sage: u = x - 1 - sage: v = u.toric_substitute((-1,), (-1,), 1) - sage: v.is_zero() - True - """ - cdef dict d, dr - cdef ETuple ve, v1e, w, w1, mon - cdef LaurentPolynomial_mpair ans - cdef int t - - if self._prod is None: - self._compute_polydict() - - d = self._prod.__repn - dr = {} - ve = ETuple(v) - v1e = ETuple(v1) - mon = self._mon - if h is not None: - d = dict(d) # Make a copy so we can manipulate it - for w in d: - d[w] = h(d[w]) - for w in d: - x = d[w] - t = w.dotprod(v1e) - w1 = w.eadd_scaled(ve, -t) - if w1 in dr: - dr[w1] += x * a**t - else: - dr[w1] = x * a**t - mon = mon.emin(w1) - for v in tuple(dr.keys()): - if not dr[v]: - del dr[v] - - if new_ring is None: - S = self._poly._parent - else: - S = self._poly._parent.change_ring(new_ring._base) - ans = self._new_c() - ans._prod = PolyDict(dr) - ans._mon = mon - ans._poly = S({v.esub(ans._mon): dr[v] for v in dr}) - if new_ring is not None: - return new_ring(ans) - return ans diff --git a/src/sage/rings/polynomial/laurent_polynomial_ring.py b/src/sage/rings/polynomial/laurent_polynomial_ring.py index aaa1166b9d2..f56b911ad3b 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_ring.py +++ b/src/sage/rings/polynomial/laurent_polynomial_ring.py @@ -42,10 +42,11 @@ # https://www.gnu.org/licenses/ # **************************************************************************** -from sage.structure.element import parent -from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial_mpair, LaurentPolynomial_univariate +from sage.misc.lazy_import import LazyImport +from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial_univariate from sage.rings.polynomial.laurent_polynomial_ring_base import LaurentPolynomialRing_generic from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing +from sage.structure.element import parent def is_LaurentPolynomialRing(R): @@ -586,7 +587,7 @@ def __init__(self, R): raise ValueError("base ring must be an integral domain") LaurentPolynomialRing_generic.__init__(self, R) - Element = LaurentPolynomial_mpair + Element = LazyImport('sage.rings.polynomial.laurent_polynomial_mpair', 'LaurentPolynomial_mpair') def _repr_(self): """ From 21b23bfd96d646de42ed37d057a4f7df2dc5fd95 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 19 Apr 2023 18:54:40 -0700 Subject: [PATCH 16/98] sage.rings.polynomial.laurent_polynomial_mpair: Split out from laurent_polynomial --- .../polynomial/laurent_polynomial_mpair.pxd | 13 + .../polynomial/laurent_polynomial_mpair.pyx | 1828 +++++++++++++++++ 2 files changed, 1841 insertions(+) create mode 100644 src/sage/rings/polynomial/laurent_polynomial_mpair.pxd create mode 100644 src/sage/rings/polynomial/laurent_polynomial_mpair.pyx diff --git a/src/sage/rings/polynomial/laurent_polynomial_mpair.pxd b/src/sage/rings/polynomial/laurent_polynomial_mpair.pxd new file mode 100644 index 00000000000..eb31593dc77 --- /dev/null +++ b/src/sage/rings/polynomial/laurent_polynomial_mpair.pxd @@ -0,0 +1,13 @@ +from sage.rings.polynomial.multi_polynomial cimport MPolynomial +from sage.rings.polynomial.polydict cimport ETuple, PolyDict + + +cdef class LaurentPolynomial_mpair(LaurentPolynomial): + cdef ETuple _mon + cdef MPolynomial _poly + cdef PolyDict _prod + cdef _compute_polydict(self) + cdef _normalize(self, i=*) + cpdef rescale_vars(self, dict d, h=*, new_ring=*) + cpdef toric_coordinate_change(self, M, h=*, new_ring=*) + cpdef toric_substitute(self, v, v1, a, h=*, new_ring=*) diff --git a/src/sage/rings/polynomial/laurent_polynomial_mpair.pyx b/src/sage/rings/polynomial/laurent_polynomial_mpair.pyx new file mode 100644 index 00000000000..ceb64874f77 --- /dev/null +++ b/src/sage/rings/polynomial/laurent_polynomial_mpair.pyx @@ -0,0 +1,1828 @@ +r""" +Elements of multivariate Laurent polynomial rings +""" + +# **************************************************************************** +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# https://www.gnu.org/licenses/ +# **************************************************************************** + +from sage.rings.integer cimport Integer +from sage.categories.map cimport Map +from sage.structure.element import is_Element, coerce_binop, parent +from sage.structure.factorization import Factorization +from sage.misc.derivative import multi_derivative +from sage.rings.polynomial.polydict cimport monomial_exponent +from sage.rings.polynomial.polynomial_element import Polynomial +from sage.structure.richcmp cimport richcmp, rich_to_bool +from sage.matrix.matrix0 cimport Matrix + + +cdef class LaurentPolynomial_mpair(LaurentPolynomial): + """ + Multivariate Laurent polynomials. + """ + def __init__(self, parent, x, mon=None, reduce=True): + """ + Currently, one can only create LaurentPolynomials out of dictionaries + and elements of the base ring. + + INPUT: + + - ``parent`` -- a SageMath parent + + - ``x`` -- an element or dictionary or anything the underlying + polynomial ring accepts + + - ``mon`` -- (default: ``None``) a tuple specifying the shift + in the exponents + + - ``reduce`` -- (default: ``True``) a boolean + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = L({(-1,-1):1}); f + w^-1*z^-1 + sage: f = L({(1,1):1}); f + w*z + sage: f = L({(-1,-1):1, (1,3):4}); f + 4*w*z^3 + w^-1*z^-1 + sage: L(1/2) + 1/2 + + TESTS: + + Check that :trac:`19538` is fixed:: + + sage: R = LaurentPolynomialRing(QQ,'x2,x0') + sage: S = LaurentPolynomialRing(QQ,'x',3) + sage: f = S.coerce_map_from(R) + sage: f(R.gen(0) + R.gen(1)^2) + x0^2 + x2 + sage: _.parent() + Multivariate Laurent Polynomial Ring in x0, x1, x2 over Rational Field + + :: + + sage: from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial_mpair + sage: LaurentPolynomial_mpair(L, {(1,2): 1/42}, mon=(-3, -3)) + 1/42*w^-2*z^-1 + + :trac:`22398`:: + + sage: LQ = LaurentPolynomialRing(QQ, 'x0, x1, x2, y0, y1, y2, y3, y4, y5') + sage: LZ = LaurentPolynomialRing(ZZ, 'x0, x1, x2, y0, y1, y2, y3, y4, y5') + sage: LQ.inject_variables() + Defining x0, x1, x2, y0, y1, y2, y3, y4, y5 + sage: x2^-1*y0*y1*y2*y3*y4*y5 + x1^-1*x2^-1*y0*y1*y3*y4 + x0^-1 in LZ + True + sage: x2^-1*y0*y1*y2*y3*y4*y5 + x1^-1*x2^-1*y0*y1*y3*y4 + x0^-1*x1^-1*y0*y3 + x0^-1 in LZ + True + + Check that input is not modified:: + + sage: LQ. = LaurentPolynomialRing(QQ) + sage: D = {(-1, 1): 1} + sage: k = tuple(D)[0] + sage: v = D[k] + sage: type(k), type(v) + (<... 'tuple'>, ) + sage: LQ(D) + x^-1*y + sage: tuple(D)[0] is k + True + sage: D[k] is v + True + """ + if isinstance(x, PolyDict): + x = x.dict() + if mon is not None: + if isinstance(mon, ETuple): + self._mon = mon + else: + self._mon = ETuple(mon) + else: + if isinstance(x, dict): + self._mon = ETuple({}, int(parent.ngens())) + D = {} + for k, x_k in x.iteritems(): # ETuple-ize keys, set _mon + if not isinstance(k, (tuple, ETuple)) or len(k) != parent.ngens(): + self._mon = ETuple({}, int(parent.ngens())) + break + if isinstance(k, tuple): + k = ETuple(k) + D[k] = x_k + self._mon = self._mon.emin(k) # point-wise min of _mon and k + else: + x = D + if not self._mon.is_constant(): # factor out _mon + x = {k.esub(self._mon): x_k for k, x_k in x.iteritems()} + elif (isinstance(x, LaurentPolynomial_mpair) and + parent.variable_names() == x.parent().variable_names()): + self._mon = (x)._mon + x = (x)._poly + else: # since x should coerce into parent, _mon should be (0,...,0) + self._mon = ETuple({}, int(parent.ngens())) + self._poly = parent._R(x) + CommutativeAlgebraElement.__init__(self, parent) + + def __reduce__(self): + """ + TESTS:: + + sage: R = LaurentPolynomialRing(QQ, 2, 'x') + sage: R. = LaurentPolynomialRing(QQ) + sage: loads(dumps(x1)) == x1 # indirect doctest + True + sage: z = x1/x2 + sage: loads(dumps(z)) == z + True + """ + return self._parent, (self._poly, self._mon) + + def __hash__(self): + r""" + TESTS: + + Test that the hash is non-constant (see also :trac:`27914`):: + + sage: L. = LaurentPolynomialRing(QQ) + sage: len({hash(w^i*z^j) for i in [-2..2] for j in [-2..2]}) + 25 + + Check that :trac:`20490` is fixed:: + + sage: R. = LaurentPolynomialRing(ZZ) + sage: p = a*~a + sage: p._fraction_pair() + (a, a) + sage: p == R.one() + True + sage: hash(p) + 1 + + Check that :trac:`23864` is fixed (compatibility with integers, rationals + and polynomial rings):: + + sage: L = LaurentPolynomialRing(QQ, 'x0,x1,x2') + sage: hash(L.zero()) + 0 + sage: hash(L.one()) + 1 + sage: hash(-L.one()) + -2 + sage: hash(L(1/2)) == hash(1/2) + True + + sage: R = PolynomialRing(QQ, 'x0,x1,x2') + sage: x0,x1,x2 = R.gens() + sage: hash(x0) == hash(L(x0)) + True + sage: hash(1 - 7*x0 + x1*x2) == hash(L(1 - 7*x0 + x1*x2)) + True + + Check that :trac:`27914` is fixed:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: Lw = LaurentPolynomialRing(QQ, 'w') + sage: Lz = LaurentPolynomialRing(QQ, 'z') + sage: all(hash(w^k) == hash(Lw(w^k)) + ....: and hash(z^k) == hash(Lz(z^k)) for k in (-5..5)) + True + sage: p = w^-1 + 2 + w + sage: hash(p) == hash(Lw(p)) + True + """ + # we reimplement the hash from multipolynomial to handle negative exponents + # (see multi_polynomial.pyx) + cdef long result = 0 + cdef long exponent + cdef list var_name_hash = [hash(v) for v in self._parent.variable_names()] + cdef int p + cdef int n = len(var_name_hash) + cdef long c_hash + for m, c in self._poly.iterator_exp_coeff(): + c_hash = hash(c) + if c_hash != 0: + for p in range(n): + exponent = m[p] + self._mon[p] + if exponent > 0: + c_hash = (1000003 * c_hash) ^ var_name_hash[p] + c_hash = (1000003 * c_hash) ^ exponent + elif exponent < 0: + c_hash = (1000003 * c_hash) ^ var_name_hash[p] + c_hash = (700005 * c_hash) ^ exponent + result += c_hash + + return result + + def _im_gens_(self, codomain, im_gens, base_map=None): + """ + Return the image of ``self`` under the morphism defined by + ``im_gens`` in ``codomain``. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(ZZ) + sage: M. = LaurentPolynomialRing(ZZ) + sage: phi = L.hom([u,v]) + sage: phi(x^2*~y -5*y**3) # indirect doctest + -5*v^3 + u^2*v^-1 + + TESTS: + + check compatibility with :trac:`26105`:: + + sage: F. = GF(4) # optional - sage.rings.finite_rings + sage: LF. = LaurentPolynomialRing(F) # optional - sage.rings.finite_rings + sage: rho = LF.hom([b,a], base_map=F.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: s = t*~a + b +~t*(b**-3)*a**2; rs = rho(s); rs # optional - sage.rings.finite_rings + a + (t + 1)*b^-1 + t*a^-3*b^2 + sage: s == rho(rs) # optional - sage.rings.finite_rings + True + """ + p = self._poly + m = self._mon + if base_map is not None: + p = p.map_coefficients(base_map) + from sage.misc.misc_c import prod + return codomain(p(im_gens) * prod(ig**m[im_gens.index(ig)] for ig in im_gens)) + + cdef _normalize(self, i=None): + r""" + Remove the common monomials from ``self._poly`` and store + them in ``self._mon``. + + INPUT: + + - ``i`` -- an integer + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = x*y + 2*y*x^2 + y # indirect doctest + sage: f.factor() # Notice the y has been factored out. + (y) * (2*x^2 + x + 1) + + Check that :trac:`23864` has been fixed:: + + sage: hash(L.zero()) + 0 + """ + if not self._poly: + self._mon = ETuple({}, int(self._parent.ngens())) + return + + #cdef dict D = self._poly._mpoly_dict_recursive( + # self._parent.variable_names(), + # self._parent.base_ring() + # ) + cdef dict D = self._poly.dict() + + cdef ETuple e + if i is None: + e = None + for k in D: + if e is None: + e = k + else: + e = e.emin(k) + if not e.is_constant(): + self._poly = (self._poly // self._poly._parent({e: 1})) + self._mon = self._mon.eadd(e) + else: + e = None + for k in D: + if e is None or k[i] < e: + e = k[i] + if e > 0: + self._poly = (self._poly // self._poly._parent.gen(i)) + self._mon = self._mon.eadd_p(e, i) + + cdef _compute_polydict(self): + """ + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: a = w^2*z^-1 +3 + sage: a.dict() # indirect doctest + {(0, 0): 3, (2, -1): 1} + """ + #cdef dict D = self._poly._mpoly_dict_recursive(self._parent.variable_names(), + # self._parent.base_ring()) + cdef dict D = self._poly.dict() + cdef dict DD + if self._mon.is_constant(): + self._prod = PolyDict(D) + return + DD = {} + for k in D: + DD[k.eadd(self._mon)] = D[k] + self._prod = PolyDict(DD) + + def is_unit(self): + """ + Return ``True`` if ``self`` is a unit. + + The ground ring is assumed to be an integral domain. + + This means that the Laurent polynomial is a monomial + with unit coefficient. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: (x*y/2).is_unit() + True + sage: (x + y).is_unit() + False + sage: (L.zero()).is_unit() + False + sage: (L.one()).is_unit() + True + + sage: L. = LaurentPolynomialRing(ZZ) + sage: (2*x*y).is_unit() + False + """ + coeffs = self.coefficients() + if len(coeffs) != 1: + return False + return coeffs[0].is_unit() + + def _repr_(self): + """ + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = x^2 + x*y/2 + 2*y^-1 + sage: f._repr_() + 'x^2 + 1/2*x*y + 2*y^-1' + """ + if self._prod is None: + self._compute_polydict() + try: + key = self.parent().term_order().sortkey + except AttributeError: + key = None + atomic = self.parent().base_ring()._repr_option('element_is_atomic') + return self._prod.poly_repr(self.parent().variable_names(), + atomic_coefficients=atomic, sortkey=key) + + def _latex_(self): + r""" + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: a = w^2*z^-1+3; a + w^2*z^-1 + 3 + sage: latex(a) + w^{2} z^{-1} + 3 + + TESTS:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: latex(1/lambda2 + y2^(-3)) + \lambda_{2}^{-1} + y_{2}^{-3} + """ + if self._prod is None: + self._compute_polydict() + try: + key = self.parent().term_order().sortkey + except AttributeError: + key = None + atomic = self.parent().base_ring()._repr_option('element_is_atomic') + return self._prod.latex(self.parent().latex_variable_names(), + atomic_coefficients=atomic, sortkey=key) + + cpdef long number_of_terms(self) except -1: + """ + Return the number of non-zero coefficients of ``self``. + + Also called weight, hamming weight or sparsity. + + EXAMPLES:: + + sage: R. = LaurentPolynomialRing(ZZ) + sage: f = x^3 - y + sage: f.number_of_terms() + 2 + sage: R(0).number_of_terms() + 0 + sage: f = (x+1/y)^100 + sage: f.number_of_terms() + 101 + + The method :meth:`hamming_weight` is an alias:: + + sage: f.hamming_weight() + 101 + """ + return self._poly.number_of_terms() + + def __invert__(LaurentPolynomial_mpair self): + """ + Return the inverse of ``self``. + + This treats monomials specially so they remain Laurent + polynomials; the inverse of any other polynomial is an element + of the rational function field. + + TESTS:: + + sage: L. = LaurentPolynomialRing(ZZ) + sage: f = ~x + sage: parent(f) + Multivariate Laurent Polynomial Ring in x, y over Integer Ring + sage: parent(f.coefficients()[0]) is parent(f).base_ring() + True + sage: g = ~(2*x) + sage: parent(g) + Multivariate Laurent Polynomial Ring in x, y over Rational Field + sage: parent(g.coefficients()[0]) is parent(g).base_ring() + True + """ + cdef ETuple e + if self._poly.is_term(): + (e, c), = self.dict().items() + e = e.emul(-1) + P = self._parent + try: + c = c.inverse_of_unit() + except (AttributeError, ZeroDivisionError, ArithmeticError): + c = ~c + if c.parent() is not P.base_ring(): + P = P.change_ring(c.parent()) + return P({e: c}) + return super().__invert__() + + def __pow__(LaurentPolynomial_mpair self, n, m): + """ + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = x + y + sage: f^2 + x^2 + 2*x*y + y^2 + sage: f^(-1) + 1/(x + y) + + TESTS: + + Check that :trac:`2952` is fixed:: + + sage: R. = QQ[] + sage: L. = LaurentPolynomialRing(R) + sage: f = (x+y+z^-1)^2 + sage: f.substitute(z=1) + x^2 + 2*x*y + y^2 + 2*x + 2*y + 1 + """ + cdef LaurentPolynomial_mpair ans + if n < 0: + return ~(self ** -n) + ans = self._new_c() + ans._poly = self._poly ** n + ans._mon = self._mon.emul(n) + return ans + + def __getitem__(self, n): + r""" + Return the coefficient of `x^n = x_1^{n_1} \cdots x_k^{n_k}` where + `n` is a tuple of length `k` and `k` is the number of variables. + + If the number of inputs is not equal to the number of variables, this + raises a ``TypeError``. + + EXAMPLES:: + + sage: P. = LaurentPolynomialRing(QQ) + sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3 + x*z; f + -x^6 + x*z - 7*x^-2*y^3 + 5*x^-2*y + x^-3*y^2 + sage: f[6,0,0] + -1 + sage: f[-2,3,0] + -7 + sage: f[-1,4,2] + 0 + sage: f[1,0,1] + 1 + sage: f[6] + Traceback (most recent call last): + ... + TypeError: must have exactly 3 inputs + sage: f[6,0] + Traceback (most recent call last): + ... + TypeError: must have exactly 3 inputs + sage: f[6,0,0,0] + Traceback (most recent call last): + ... + TypeError: must have exactly 3 inputs + """ + if isinstance(n, slice): + raise TypeError("multivariate Laurent polynomials are not iterable") + if not isinstance(n, tuple) or len(n) != self._parent.ngens(): + raise TypeError("must have exactly %s inputs" % + self.parent().ngens()) + cdef ETuple t = ETuple(n) + if self._prod is None: + self._compute_polydict() + try: + return self._prod[t] + except KeyError: + return self._parent.base_ring().zero() + + def __iter__(self): + """ + Iterate through all terms by returning a list of the coefficient and + the corresponding monomial. + + EXAMPLES:: + + sage: P. = LaurentPolynomialRing(QQ) + sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3 + sage: sorted(f) # indirect doctest + [(-7, x^-2*y^3), (-1, x^6), (1, x^-3*y^2), (5, x^-2*y)] + """ + P = self._parent + one = P._R.one() + if self._mon.is_constant(): + for exp, coeff in self._poly.iterator_exp_coeff(): + yield (coeff, P.element_class(P, one, exp)) + else: + for exp, coeff in self._poly.iterator_exp_coeff(): + yield (coeff, P.element_class(P, one, exp.eadd(self._mon))) + + def iterator_exp_coeff(self): + """ + Iterate over ``self`` as pairs of (ETuple, coefficient). + + EXAMPLES:: + + sage: P. = LaurentPolynomialRing(QQ) + sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3 + sage: list(f.iterator_exp_coeff()) + [((6, 0), -1), ((-2, 3), -7), ((-2, 1), 5), ((-3, 2), 1)] + """ + for exp, coeff in self._poly.iterator_exp_coeff(): + yield (exp.eadd(self._mon), coeff) + + def monomials(self): + """ + Return the list of monomials in ``self``. + + EXAMPLES:: + + sage: P. = LaurentPolynomialRing(QQ) + sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3 + sage: sorted(f.monomials()) + [x^-3*y^2, x^-2*y, x^-2*y^3, x^6] + """ + return [mon for coeff, mon in self] + + def monomial_coefficient(self, mon): + """ + Return the coefficient in the base ring of the monomial ``mon`` in + ``self``, where ``mon`` must have the same parent as ``self``. + + This function contrasts with the function :meth:`coefficient()` + which returns the coefficient of a monomial viewing this + polynomial in a polynomial ring over a base ring having fewer + variables. + + INPUT: + + - ``mon`` -- a monomial + + .. SEEALSO:: + + For coefficients in a base ring of fewer variables, see + :meth:`coefficient()`. + + EXAMPLES:: + + sage: P. = LaurentPolynomialRing(QQ) + sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3 + sage: f.monomial_coefficient(x^-2*y^3) + -7 + sage: f.monomial_coefficient(x^2) + 0 + + TESTS:: + + sage: P. = LaurentPolynomialRing(QQ) + sage: f = y^2 * x^-2 + sage: f.monomial_coefficient(x + y) + Traceback (most recent call last): + ... + ValueError: not a monomial + """ + if parent(mon) != self._parent: + raise TypeError("input must have the same parent") + cdef LaurentPolynomial_mpair m = mon + if m._prod is None: + m._compute_polydict() + if self._prod is None: + self._compute_polydict() + exp = monomial_exponent(m._prod) + zero = self._parent.base_ring().zero() + return self._prod.get(exp, zero) + + def constant_coefficient(self): + """ + Return the constant coefficient of ``self``. + + EXAMPLES:: + + sage: P. = LaurentPolynomialRing(QQ) + sage: f = (y^2 - x^9 - 7*x*y^2 + 5*x*y)*x^-3; f + -x^6 - 7*x^-2*y^2 + 5*x^-2*y + x^-3*y^2 + sage: f.constant_coefficient() + 0 + sage: f = (x^3 + 2*x^-2*y+y^3)*y^-3; f + x^3*y^-3 + 1 + 2*x^-2*y^-2 + sage: f.constant_coefficient() + 1 + """ + return self[(0,)*self._parent.ngens()] + + def coefficient(self, mon): + r""" + Return the coefficient of ``mon`` in ``self``, where ``mon`` must + have the same parent as ``self``. + + The coefficient is defined as follows. If `f` is this polynomial, then + the coefficient `c_m` is sum: + + .. MATH:: + + c_m := \sum_T \frac{T}{m} + + where the sum is over terms `T` in `f` that are exactly divisible + by `m`. + + A monomial `m(x,y)` 'exactly divides' `f(x,y)` if `m(x,y) | f(x,y)` + and neither `x \cdot m(x,y)` nor `y \cdot m(x,y)` divides `f(x,y)`. + + INPUT: + + - ``mon`` -- a monomial + + OUTPUT: + + Element of the parent of ``self``. + + .. NOTE:: + + To get the constant coefficient, call + :meth:`constant_coefficient()`. + + EXAMPLES:: + + sage: P. = LaurentPolynomialRing(QQ) + + The coefficient returned is an element of the parent of ``self``; in + this case, ``P``. :: + + sage: f = 2 * x * y + sage: c = f.coefficient(x*y); c + 2 + sage: c.parent() + Multivariate Laurent Polynomial Ring in x, y over Rational Field + + sage: P. = LaurentPolynomialRing(QQ) + sage: f = (y^2 - x^9 - 7*x*y^2 + 5*x*y)*x^-3; f + -x^6 - 7*x^-2*y^2 + 5*x^-2*y + x^-3*y^2 + sage: f.coefficient(y) + 5*x^-2 + sage: f.coefficient(y^2) + -7*x^-2 + x^-3 + sage: f.coefficient(x*y) + 0 + sage: f.coefficient(x^-2) + -7*y^2 + 5*y + sage: f.coefficient(x^-2*y^2) + -7 + sage: f.coefficient(1) + -x^6 - 7*x^-2*y^2 + 5*x^-2*y + x^-3*y^2 + """ + if mon.parent() is not self._parent: + mon = self._parent(mon) + cdef LaurentPolynomial_mpair m = mon + if self._prod is None: + self._compute_polydict() + if m._prod is None: + m._compute_polydict() + return self._parent(self._prod.coefficient(m.dict())) + + def coefficients(self): + """ + Return the nonzero coefficients of ``self`` in a list. + + The returned list is decreasingly ordered by the term ordering + of ``self.parent()``. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ, order='degrevlex') + sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 + sage: f.coefficients() + [4, 3, 2, 1] + sage: L. = LaurentPolynomialRing(QQ,order='lex') + sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 + sage: f.coefficients() + [4, 1, 2, 3] + """ + return self._poly.coefficients() + + def variables(self, sort=True): + """ + Return a tuple of all variables occurring in ``self``. + + INPUT: + + - ``sort`` -- specifies whether the indices shall be sorted + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 + sage: f.variables() + (z, y, x) + sage: f.variables(sort=False) #random + (y, z, x) + """ + cdef dict d = self.dict() + cdef tuple g = self._parent.gens() + cdef Py_ssize_t nvars = len(g) + cdef set vars = set() + for k in d: + vars.update(k.nonzero_positions()) + if len(vars) == nvars: + break + cdef list v = [g[i] for i in vars] + if sort: + v.sort() + return tuple(v) + + cpdef dict dict(self): + """ + Return ``self`` represented as a ``dict``. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 + sage: sorted(f.dict().items()) + [((3, 1, 0), 3), ((4, 0, -2), 2), ((6, -7, 0), 1), ((7, 0, -1), 4)] + """ + if self._prod is None: + self._compute_polydict() + return self._prod.dict() + + def _fraction_pair(self): + """ + Return one representation of ``self`` as a pair + ``(numerator, denominator)``. + + Here both the numerator and the denominator are polynomials. + + This is used for coercion into the fraction field. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 + sage: f._fraction_pair() + (4*x^7*y^7*z + 3*x^3*y^8*z^2 + 2*x^4*y^7 + x^6*z^2, y^7*z^2) + """ + ring = self._parent._R + numer = self._poly + denom = ring.one() + var = ring.gens() + for i, j in enumerate(self._mon): + if j > 0: + numer *= var[i] ** j + else: + denom *= var[i] ** (-j) + return (numer, denom) + + cpdef _add_(self, _right): + """ + Return the Laurent polynomial ``self + right``. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = x + y^-1 + sage: g = y + z + sage: f + g + x + y + z + y^-1 + """ + cdef LaurentPolynomial_mpair ans = self._new_c() + cdef LaurentPolynomial_mpair right = _right + ans._mon, a, b = self._mon.combine_to_positives(right._mon) + if not a.is_constant(): + ans._poly = self._poly * self._poly._parent({a: 1}) + else: + ans._poly = self._poly + if not b.is_constant(): + ans._poly += right._poly * self._poly._parent({b: 1}) + else: + ans._poly += right._poly + return ans + + cpdef _sub_(self, _right): + """ + Return the Laurent polynomial ``self - right``. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = x + y^-1 + sage: g = y + z + x + sage: f - g + -y - z + y^-1 + """ + cdef LaurentPolynomial_mpair ans = self._new_c() + cdef LaurentPolynomial_mpair right = _right + cdef ETuple a, b + ans._mon, a, b = self._mon.combine_to_positives(right._mon) + if not a.is_constant(): + ans._poly = self._poly * self._poly._parent({a: 1}) + else: + ans._poly = self._poly + if not b.is_constant(): + ans._poly -= right._poly * self._poly._parent({b: 1}) + else: + ans._poly -= right._poly + return ans + + cpdef _div_(self, rhs): + """ + Return the division of ``self`` by ``rhs``. + + If the denominator is not a unit, + the result will be given in the fraction field. + + EXAMPLES:: + + sage: R. = LaurentPolynomialRing(QQ) + sage: 1/s + s^-1 + sage: 1/(s*q) + s^-1*q^-1 + sage: 1/(s+q) + 1/(s + q) + sage: (1/(s+q)).parent() + Fraction Field of Multivariate Polynomial Ring in s, q, t over Rational Field + sage: (1/(s*q)).parent() + Multivariate Laurent Polynomial Ring in s, q, t over Rational Field + sage: (s+q)/(q^2*t^(-2)) + s*q^-2*t^2 + q^-1*t^2 + """ + cdef LaurentPolynomial_mpair right = rhs + if right.is_zero(): + raise ZeroDivisionError + if right._poly.is_term(): + return self * ~right + else: + return RingElement._div_(self, rhs) + + def is_monomial(self): + """ + Return ``True`` if ``self`` is a monomial. + + EXAMPLES:: + + sage: k. = LaurentPolynomialRing(QQ) + sage: z.is_monomial() + True + sage: k(1).is_monomial() + True + sage: (z+1).is_monomial() + False + sage: (z^-2909).is_monomial() + True + sage: (38*z^-2909).is_monomial() + False + """ + return self._poly.is_monomial() + + cpdef _neg_(self): + """ + Return ``-self``. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = x + y^-1 + sage: -f + -x - y^-1 + """ + cdef LaurentPolynomial_mpair ans = self._new_c() + ans._mon = self._mon + ans._poly = -self._poly + return ans + + cpdef _lmul_(self, Element right): + """ + Return ``self * right`` where ``right`` is in ``self``'s base ring. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = x + y^-1 + sage: f*(1/2) + 1/2*x + 1/2*y^-1 + """ + cdef LaurentPolynomial_mpair ans = self._new_c() + ans._mon = self._mon + ans._poly = self._poly * right + return ans + + cpdef _rmul_(self, Element left): + """ + Return ``left * self`` where ``left`` is in ``self``'s base ring. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = x + y^-1 + sage: (1/2)*f + 1/2*x + 1/2*y^-1 + """ + cdef LaurentPolynomial_mpair ans = self._new_c() + ans._mon = self._mon + ans._poly = left * self._poly + return ans + + cpdef _mul_(self, right): + """ + Return ``self * right``. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = x + y^-1 + sage: g = y + z + sage: f*g + x*y + x*z + 1 + y^-1*z + """ + cdef LaurentPolynomial_mpair ans = self._new_c() + ans._mon = self._mon.eadd((right)._mon) + ans._poly = self._poly * (right)._poly + return ans + + cpdef _floordiv_(self, right): + """ + Perform division with remainder and return the quotient. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = x^3 + y^-3 + sage: g = y + x + sage: f // g + x^5*y^-3 - x^4*y^-2 + x^3*y^-1 + + sage: h = x + y^(-1) + sage: f // h + x^2 - x*y^-1 + y^-2 + sage: h * (f // h) == f + True + sage: f // 1 + x^3 + y^-3 + sage: 1 // f + 0 + + TESTS: + + Check that :trac:`19357` is fixed:: + + sage: x // y + x*y^-1 + + Check that :trac:`21999` is fixed:: + + sage: L. = LaurentPolynomialRing(QQbar) + sage: (a+a*b) // a + b + 1 + """ + cdef LaurentPolynomial_mpair ans = self._new_c() + cdef LaurentPolynomial_mpair rightl = right + self._normalize() + rightl._normalize() + ans._mon = self._mon.esub(rightl._mon) + ans._poly = self._poly // rightl._poly + return ans + + @coerce_binop + def quo_rem(self, right): + """ + Divide this Laurent polynomial by ``right`` and return a quotient and + a remainder. + + INPUT: + + - ``right`` -- a Laurent polynomial + + OUTPUT: + + A pair of Laurent polynomials. + + EXAMPLES:: + + sage: R. = LaurentPolynomialRing(QQ) + sage: (s^2 - t^2).quo_rem(s - t) + (s + t, 0) + sage: (s^-2 - t^2).quo_rem(s - t) + (s + t, -s^2 + s^-2) + sage: (s^-2 - t^2).quo_rem(s^-1 - t) + (t + s^-1, 0) + + TESTS: + + Verify that :trac:`31257` is fixed:: + + sage: R. = LaurentPolynomialRing(QQ) + sage: q, r = (1/x).quo_rem(y) + sage: q, r + (x^-1*y^-1, 0) + sage: q*y + r == 1/x + True + sage: q,r = (x^-2 - y^2).quo_rem(x - y) + sage: q*(x - y) + r == x^-2 - y^2 + True + """ + # make copies of self and right so that the input can be normalized + # without affecting the objects that were passed to the method + cdef LaurentPolynomial_mpair selfl = self._new_c() + selfl._poly = self._poly + selfl._mon = self._mon + cdef LaurentPolynomial_mpair rightl = self._new_c() + rightl._poly = ( right)._poly + rightl._mon = ( right)._mon + + selfl._normalize() + rightl._normalize() + q, r = selfl._poly.quo_rem(rightl._poly) + ql = LaurentPolynomial_mpair(self._parent, q, + mon=selfl._mon.esub(rightl._mon)) + rl = LaurentPolynomial_mpair(self._parent, r, + mon=selfl._mon) + ql._normalize() + rl._normalize() + return (ql, rl) + + cpdef _richcmp_(self, right, int op): + """ + Compare two polynomials in a `LaurentPolynomialRing` based on the term + order from the parent ring. If the parent ring does not specify a term + order then only comparison by equality is supported. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = x + y^-1 + sage: g = y + z + sage: f == f + True + sage: f == g + False + sage: f == 2 + False + """ + if self._prod is None: + self._compute_polydict() + if ( right)._prod is None: + ( right)._compute_polydict() + + try: + sortkey = self._parent.term_order().sortkey + except AttributeError: + sortkey = None + + return self._prod.rich_compare((right)._prod, + op, sortkey) + + def exponents(self): + """ + Return a list of the exponents of ``self``. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: a = w^2*z^-1 + 3; a + w^2*z^-1 + 3 + sage: e = a.exponents() + sage: e.sort(); e + [(0, 0), (2, -1)] + + """ + return [a.eadd(self._mon) for a in self._poly.exponents()] + + def degree(self, x=None): + """ + Return the degree of ``x`` in ``self``. + + EXAMPLES:: + + sage: R. = LaurentPolynomialRing(QQ) + sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 + sage: f.degree(x) + 7 + sage: f.degree(y) + 1 + sage: f.degree(z) + 0 + """ + if not x: + return self._poly.total_degree() + sum(self._mon) + + cdef tuple g = self._parent.gens() + cdef Py_ssize_t i + cdef bint no_generator_found = True + for i in range(len(g)): + if g[i] is x: + no_generator_found = False + break + if no_generator_found: + raise TypeError("x must be a generator of parent") + return self._poly.degree(self._parent._R.gens()[i]) + self._mon[i] + + def has_inverse_of(self, i): + """ + INPUT: + + - ``i`` -- The index of a generator of ``self.parent()`` + + OUTPUT: + + Returns True if ``self`` contains a monomial including the inverse of + ``self.parent().gen(i)``, False otherwise. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 + sage: f.has_inverse_of(0) + False + sage: f.has_inverse_of(1) + True + sage: f.has_inverse_of(2) + True + """ + if (not isinstance(i, (int, Integer))) or (i < 0) or (i >= self._parent.ngens()): + raise TypeError("argument is not the index of a generator") + if self._mon[i] < 0: + self._normalize(i) + if self._mon[i] < 0: + return True + return False + return False + + def has_any_inverse(self): + """ + Return True if ``self`` contains any monomials with a negative exponent, False otherwise. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 + sage: f.has_any_inverse() + True + sage: g = x^2 + y^2 + sage: g.has_any_inverse() + False + """ + for m in self._mon.nonzero_values(sort=False): + if m < 0: + return True + return False + + def __call__(self, *x, **kwds): + """ + Compute value of ``self`` at ``x``. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = x + 2*y + 3*z + sage: f(1,1,1) + 6 + sage: f = x^-1 + y + z + sage: f(0,1,1) + Traceback (most recent call last): + ... + ZeroDivisionError + + TESTS:: + + sage: f = x + 2*y + 3*z + sage: f(2) + Traceback (most recent call last): + ... + TypeError: number of arguments does not match the number of generators in parent + sage: f(2,0) + Traceback (most recent call last): + ... + TypeError: number of arguments does not match the number of generators in parent + sage: f( (1,1,1) ) + 6 + """ + if kwds: + f = self.subs(**kwds) + if x: # More than 1 non-keyword argument + return f(*x) + else: + return f + + cdef int l = len(x) + + if l == 1 and isinstance(x[0], (tuple, list)): + x = x[0] + l = len(x) + + if l != self._parent.ngens(): + raise TypeError("number of arguments does not match the number" + " of generators in parent") + + #Check to make sure that we aren't dividing by zero + cdef Py_ssize_t m + for m in range(l): + if x[m] == 0: + if self.has_inverse_of(m): + raise ZeroDivisionError + + ans = self._poly(*x) + if ans: + for m in self._mon.nonzero_positions(): + ans *= x[m]**self._mon[m] + + return ans + + def subs(self, in_dict=None, **kwds): + """ + Substitute some variables in this Laurent polynomial. + + Variable/value pairs for the substitution may be given + as a dictionary or via keyword-value pairs. If both are + present, the latter take precedence. + + INPUT: + + - ``in_dict`` -- dictionary (optional) + + - ``**kwargs`` -- keyword arguments + + OUTPUT: + + A Laurent polynomial. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = x + 2*y + 3*z + sage: f.subs(x=1) + 2*y + 3*z + 1 + sage: f.subs(y=1) + x + 3*z + 2 + sage: f.subs(z=1) + x + 2*y + 3 + sage: f.subs(x=1, y=1, z=1) + 6 + + sage: f = x^-1 + sage: f.subs(x=2) + 1/2 + sage: f.subs({x: 2}) + 1/2 + + sage: f = x + 2*y + 3*z + sage: f.subs({x: 1, y: 1, z: 1}) + 6 + sage: f.substitute(x=1, y=1, z=1) + 6 + + TESTS:: + + sage: f = x + 2*y + 3*z + sage: f(q=10) + x + 2*y + 3*z + + sage: x.subs({x: 2}, x=1) + 1 + """ + cdef list variables = list(self._parent.gens()) + cdef Py_ssize_t i + for i in range(len(variables)): + if str(variables[i]) in kwds: + variables[i] = kwds[str(variables[i])] + elif in_dict and variables[i] in in_dict: + variables[i] = in_dict[variables[i]] + return self(tuple(variables)) + + def is_constant(self): + r""" + Return whether this Laurent polynomial is constant. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: L(0).is_constant() + True + sage: L(42).is_constant() + True + sage: a.is_constant() + False + sage: (1/b).is_constant() + False + """ + return (self._mon == ETuple({}, int(self._parent.ngens())) and + self._poly.is_constant()) + + def _symbolic_(self, R): + """ + EXAMPLES:: + + sage: R. = LaurentPolynomialRing(QQ) + sage: f = x^3 + y/x + sage: g = f._symbolic_(SR); g # optional - sage.symbolic + (x^4 + y)/x + sage: g(x=2, y=2) # optional - sage.symbolic + 9 + + sage: g = SR(f) # optional - sage.symbolic + sage: g(x=2, y=2) # optional - sage.symbolic + 9 + """ + d = {repr(g): R.var(g) for g in self._parent.gens()} + return self.subs(**d) + + def derivative(self, *args): + r""" + The formal derivative of this Laurent polynomial, with respect + to variables supplied in args. + + Multiple variables and iteration counts may be supplied; see + documentation for the global :func:`derivative` function for more + details. + + .. SEEALSO:: + + :meth:`_derivative` + + EXAMPLES:: + + sage: R = LaurentPolynomialRing(ZZ,'x, y') + sage: x, y = R.gens() + sage: t = x**4*y + x*y + y + x**(-1) + y**(-3) + sage: t.derivative(x, x) + 12*x^2*y + 2*x^-3 + sage: t.derivative(y, 2) + 12*y^-5 + """ + return multi_derivative(self, args) + + # add .diff(), .differentiate() as aliases for .derivative() + diff = differentiate = derivative + + def _derivative(self, var=None): + """ + Computes formal derivative of this Laurent polynomial with + respect to the given variable. + + If var is among the generators of this ring, the derivative + is with respect to the generator. Otherwise, ``_derivative(var)`` is called + recursively for each coefficient of this polynomial. + + .. SEEALSO:: :meth:`derivative` + + EXAMPLES:: + + sage: R = LaurentPolynomialRing(ZZ,'x, y') + sage: x, y = R.gens() + sage: t = x**4*y+x*y+y+x**(-1)+y**(-3) + sage: t._derivative(x) + 4*x^3*y + y - x^-2 + sage: t._derivative(y) + x^4 + x + 1 - 3*y^-4 + + sage: R = LaurentPolynomialRing(QQ['z'],'x') + sage: z = R.base_ring().gen() + sage: x = R.gen() + sage: t = 33*z*x**4+x**(-1) + sage: t._derivative(z) + 33*x^4 + sage: t._derivative(x) + -x^-2 + 132*z*x^3 + """ + if var is None: + raise ValueError("must specify which variable to differentiate " + "with respect to") + P = self._parent + cdef list gens = list(P.gens()) + + # check if var is one of the generators + try: + index = gens.index(var) + except ValueError: + # call _derivative() recursively on coefficients + return P({m: c._derivative(var) + for (m, c) in self.dict().iteritems()}) + + # compute formal derivative with respect to generator + cdef dict d = {} + for m, c in self.dict().iteritems(): + if m[index] != 0: + new_m = [u for u in m] + new_m[index] += -1 + d[ETuple(new_m)] = m[index] * c + return P(d) + + def is_univariate(self): + """ + Return ``True`` if this is a univariate or constant Laurent polynomial, + and ``False`` otherwise. + + EXAMPLES:: + + sage: R. = LaurentPolynomialRing(QQ) + sage: f = (x^3 + y^-3)*z + sage: f.is_univariate() + False + sage: g = f(1, y, 4) + sage: g.is_univariate() + True + sage: R(1).is_univariate() + True + """ + return len(self.variables()) < 2 + + def univariate_polynomial(self, R=None): + """ + Return a univariate polynomial associated to this + multivariate polynomial. + + INPUT: + + - ``R`` - (default: ``None``) a univariate Laurent polynomial ring + + If this polynomial is not in at most one variable, then a + ``ValueError`` exception is raised. The new polynomial is over + the same base ring as the given ``LaurentPolynomial`` and in the + variable ``x`` if no ring ``R`` is provided. + + EXAMPLES:: + + sage: R. = LaurentPolynomialRing(ZZ) + sage: f = 3*x^2 - 2*y^-1 + 7*x^2*y^2 + 5 + sage: f.univariate_polynomial() + Traceback (most recent call last): + ... + TypeError: polynomial must involve at most one variable + sage: g = f(10, y); g + 700*y^2 + 305 - 2*y^-1 + sage: h = g.univariate_polynomial(); h + -2*y^-1 + 305 + 700*y^2 + sage: h.parent() + Univariate Laurent Polynomial Ring in y over Integer Ring + sage: g.univariate_polynomial(LaurentPolynomialRing(QQ,'z')) + -2*z^-1 + 305 + 700*z^2 + + Here's an example with a constant multivariate polynomial:: + + sage: g = R(1) + sage: h = g.univariate_polynomial(); h + 1 + sage: h.parent() + Univariate Laurent Polynomial Ring in x over Integer Ring + """ + from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing + v = self.variables() + if len(v) > 1: + raise TypeError("polynomial must involve at most one variable") + elif len(v) == 1: + x = v[0] + i = self._parent.gens().index(x) + x = str(x) + else: + x = 'x' + i = 0 + + #construct ring if none + if R is None: + R = LaurentPolynomialRing(self.base_ring(), x) + + return R({m[i]: c for m,c in self.dict().iteritems()}) + + def factor(self): + """ + Return a Laurent monomial (the unit part of the factorization) and a factored multi-polynomial. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 + sage: f.factor() + (x^3*y^-7*z^-2) * (4*x^4*y^7*z + 3*y^8*z^2 + 2*x*y^7 + x^3*z^2) + + TESTS: + + Tests for :trac:`29173`:: + + sage: L. = LaurentPolynomialRing(ZZ, 'a, b') + sage: (a*b + a + b + 1).factor() + (b + 1) * (a + 1) + sage: ((a^-1)*(a*b + a + b + 1)).factor() + (a^-1) * (b + 1) * (a + 1) + sage: L(-12).factor() + -1 * 2^2 * 3 + """ + pf = self._poly.factor() + + if self._poly.degree() == 0: + # Factorization is broken for polynomials, see + # https://github.com/sagemath/sage/issues/20214 + return pf + + u = self.parent(pf.unit()) + + cdef tuple g = self._parent.gens() + for i in self._mon.nonzero_positions(): + u *= g[i] ** self._mon[i] + + cdef list f = [] + cdef dict d + for t in pf: + d = (t[0].dict()) + if len(d) == 1: # monomials are units + u *= self.parent(d) ** t[1] + else: + f.append((self.parent(d), t[1])) + + return Factorization(f, unit=u) + + def is_square(self, root=False): + r""" + Test whether this Laurent polynomial is a square. + + INPUT: + + - ``root`` - boolean (default ``False``) - if set to ``True`` + then return a pair ``(True, sqrt)`` with ``sqrt`` a square + root of this Laurent polynomial when it exists or + ``(False, None)``. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ) + sage: p = 1 + x*y + z^-3 + sage: (p**2).is_square() + True + sage: (p**2).is_square(root=True) + (True, x*y + 1 + z^-3) + + sage: x.is_square() + False + sage: x.is_square(root=True) + (False, None) + + sage: (x**-4 * (1 + z)).is_square(root=False) + False + sage: (x**-4 * (1 + z)).is_square(root=True) + (False, None) + """ + self._normalize() + if not self._mon.is_multiple_of(2): + return (False, None) if root else False + + cdef LaurentPolynomial_mpair ans + + if not root: + return self._poly.is_square(root=False) + else: + (pans, root) = self._poly.is_square(root=True) + if not pans: + return (False, None) + + mon = self._mon.escalar_div(2) + ans = self._new_c() + ans._mon = mon + ans._poly = root + return (True, ans) + + cpdef rescale_vars(self, dict d, h=None, new_ring=None): + r""" + Rescale variables in a Laurent polynomial. + + INPUT: + + - ``d`` -- a ``dict`` whose keys are the generator indices + and values are the coefficients; so a pair ``(i, v)`` + means `x_i \mapsto v x_i` + - ``h`` -- (optional) a map to be applied to coefficients + done after rescaling + - ``new_ring`` -- (optional) a new ring to map the result into + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ, 2) + sage: p = x^-2*y + x*y^-2 + sage: p.rescale_vars({0: 2, 1: 3}) + 2/9*x*y^-2 + 3/4*x^-2*y + sage: F = GF(2) # optional - sage.rings.finite_rings + sage: p.rescale_vars({0: 3, 1: 7}, new_ring=L.change_ring(F)) # optional - sage.rings.finite_rings + x*y^-2 + x^-2*y + + Test for :trac:`30331`:: + + sage: F. = CyclotomicField(3) # optional - sage.rings.number_field + sage: p.rescale_vars({0: 2, 1: z}, new_ring=L.change_ring(F)) # optional - sage.rings.number_field + 2*z*x*y^-2 + 1/4*z*x^-2*y + """ + cdef int i + cdef dict df + cdef ETuple v + cdef LaurentPolynomial_mpair ans + + if self._prod is None: + self._compute_polydict() + + df = dict(self._prod.__repn) # This makes a copy for us to manipulate + if new_ring is None: + R = self._parent._base + else: + R = new_ring._base + if h is None: + for v in df: + val = df[v] + for i in d: + val *= d[i]**v[i] + df[v] = val + else: + for v in df: + val = df[v] + for i in d: + val *= d[i]**v[i] + df[v] = R(h(val)) + + ans = self._new_c() + ans._prod = PolyDict(df) + ans._mon = self._mon + if new_ring is None: + S = self._poly._parent + else: + S = self._poly._parent.change_ring(R) + ans._poly = S({v.esub(ans._mon): df[v] for v in df}) + if new_ring is not None: + return new_ring(ans) + return ans + + cpdef toric_coordinate_change(self, M, h=None, new_ring=None): + r""" + Apply a matrix to the exponents in a Laurent polynomial. + + For efficiency, we implement this directly, rather than as a substitution. + + The optional argument ``h`` is a map to be applied to coefficients. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ, 2) + sage: p = 2*x^2 + y - x*y + sage: p.toric_coordinate_change(Matrix([[1,-3], [1,1]])) + 2*x^2*y^2 - x^-2*y^2 + x^-3*y + sage: F = GF(2) # optional - sage.rings.finite_rings + sage: p.toric_coordinate_change(Matrix([[1,-3], [1,1]]), # optional - sage.rings.finite_rings + ....: new_ring=L.change_ring(F)) + x^-2*y^2 + x^-3*y + + """ + cdef int n, i, j, x + cdef dict d, dr + cdef ETuple v + cdef LaurentPolynomial_mpair ans + cdef list L, mon, exp + cdef Matrix mat = M + + n = self._parent.ngens() + if mat.dimensions() != (n, n): + raise ValueError("the matrix M must be a {k} x {k} matrix".format(k=n)) + + if not self: + if new_ring is None: + return self._parent.zero() + else: + return new_ring.zero() + + if self._prod is None: + self._compute_polydict() + + d = self._prod.__repn + dr = {} + mon = [0] * n + for v in d: + # Make a copy of mon as this might be faster than creating the data from scratch. + # We will set every entry, so no need to clear the data. + exp = list(mon) + for j in range(n): + x = 0 + for i in range(n): + if not mat.get_is_zero_unsafe(j, i): + x += ( v[i]) * int(mat.get_unsafe(j, i)) + if x < ( mon[j]): + mon[j] = x + exp[j] = x + dr[ETuple(exp)] = d[v] + + if h is not None: + for v in dr: + dr[v] = self._parent._base(h(dr[v])) + + ans = self._new_c() + ans._prod = PolyDict(dr) + ans._mon = ETuple(mon) + ans._poly = self._poly._parent({v.esub(ans._mon): dr[v] for v in dr}) + if new_ring is not None: + return new_ring(ans) + return ans + + cpdef toric_substitute(self, v, v1, a, h=None, new_ring=None): + r""" + Perform a single-variable substitution up to a toric coordinate change. + + The optional argument ``h`` is a map to be applied to coefficients. + + EXAMPLES:: + + sage: L. = LaurentPolynomialRing(QQ, 2) + sage: p = x + y + sage: p.toric_substitute((2,3), (-1,1), 2) + 1/2*x^3*y^3 + 2*x^-2*y^-2 + sage: F = GF(5) + sage: p.toric_substitute((2,3), (-1,1), 2, new_ring=L.change_ring(F)) + 3*x^3*y^3 + 2*x^-2*y^-2 + + TESTS: + + Tests for :trac:`30331`:: + + sage: L. = LaurentPolynomialRing(QQ, 2) + sage: p = x + y + sage: F. = CyclotomicField(3) + sage: p.toric_substitute((2,3), (-1,1), z, new_ring=L.change_ring(F)) + (-z - 1)*x^3*y^3 + z*x^-2*y^-2 + + sage: P. = LaurentPolynomialRing(QQ, 1) + sage: u = x - 1 + sage: v = u.toric_substitute((-1,), (-1,), 1) + sage: v.is_zero() + True + """ + cdef dict d, dr + cdef ETuple ve, v1e, w, w1, mon + cdef LaurentPolynomial_mpair ans + cdef int t + + if self._prod is None: + self._compute_polydict() + + d = self._prod.__repn + dr = {} + ve = ETuple(v) + v1e = ETuple(v1) + mon = self._mon + if h is not None: + d = dict(d) # Make a copy so we can manipulate it + for w in d: + d[w] = h(d[w]) + for w in d: + x = d[w] + t = w.dotprod(v1e) + w1 = w.eadd_scaled(ve, -t) + if w1 in dr: + dr[w1] += x * a**t + else: + dr[w1] = x * a**t + mon = mon.emin(w1) + for v in tuple(dr.keys()): + if not dr[v]: + del dr[v] + + if new_ring is None: + S = self._poly._parent + else: + S = self._poly._parent.change_ring(new_ring._base) + ans = self._new_c() + ans._prod = PolyDict(dr) + ans._mon = mon + ans._poly = S({v.esub(ans._mon): dr[v] for v in dr}) + if new_ring is not None: + return new_ring(ans) + return ans From f094cdc6db1baba4bdc0146e976cad0447968112 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 19 Apr 2023 20:42:19 -0700 Subject: [PATCH 17/98] sage.data_structures.stream, sage.rings.lazy_series: Modularization fixes --- src/sage/data_structures/stream.py | 4 +- src/sage/rings/lazy_series.py | 3 +- src/sage/rings/lazy_series_ring.py | 251 +++++++++++++++++------------ 3 files changed, 149 insertions(+), 109 deletions(-) diff --git a/src/sage/data_structures/stream.py b/src/sage/data_structures/stream.py index 4bffa84bfc9..b11a27318f5 100644 --- a/src/sage/data_structures/stream.py +++ b/src/sage/data_structures/stream.py @@ -99,10 +99,12 @@ from sage.arith.misc import divisors from sage.misc.misc_c import prod from sage.misc.lazy_attribute import lazy_attribute +from sage.misc.lazy_import import lazy_import from sage.combinat.integer_vector_weighted import iterator_fast as wt_int_vec_iter -from sage.combinat.sf.sfa import _variables_recursive, _raise_variables from sage.categories.hopf_algebras_with_basis import HopfAlgebrasWithBasis +lazy_import('sage.combinat.sf.sfa', ['_variables_recursive', '_raise_variables']) + class Stream(): """ diff --git a/src/sage/rings/lazy_series.py b/src/sage/rings/lazy_series.py index f31488d5354..581ceaac1ea 100644 --- a/src/sage/rings/lazy_series.py +++ b/src/sage/rings/lazy_series.py @@ -211,11 +211,10 @@ from sage.structure.element import Element, parent from sage.structure.richcmp import op_EQ, op_NE -from sage.functions.other import factorial from sage.misc.misc_c import prod from sage.arith.power import generic_power from sage.arith.functions import lcm -from sage.arith.misc import divisors, moebius +from sage.arith.misc import divisors, factorial, moebius from sage.combinat.partition import Partition, Partitions from sage.misc.derivative import derivative_parse from sage.categories.integral_domains import IntegralDomains diff --git a/src/sage/rings/lazy_series_ring.py b/src/sage/rings/lazy_series_ring.py index d8ba728a61b..89d4cd39127 100644 --- a/src/sage/rings/lazy_series_ring.py +++ b/src/sage/rings/lazy_series_ring.py @@ -52,6 +52,7 @@ CompleteDiscreteValuationRings) from sage.misc.cachefunc import cached_method +from sage.misc.lazy_attribute import lazy_attribute from sage.rings.integer_ring import ZZ from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing @@ -64,7 +65,6 @@ LazySymmetricFunction, LazyDirichletSeries) from sage.structure.global_options import GlobalOptions -from sage.symbolic.ring import SR from sage.data_structures.stream import ( Stream_zero, @@ -155,10 +155,10 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No If ``x`` can be converted into an element of the underlying Laurent polynomial ring, we do this:: - sage: L = LazyLaurentSeriesRing(GF(2), 'z') - sage: L(2) + sage: L = LazyLaurentSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings + sage: L(2) # optional - sage.rings.finite_rings 0 - sage: L(3) + sage: L(3) # optional - sage.rings.finite_rings 1 In particular, ``x`` can be a Laurent polynomial:: @@ -288,21 +288,21 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No Converting various series from a univariate power series:: - sage: L = LazyLaurentSeriesRing(GF(2), 'z') - sage: R = LazyPowerSeriesRing(ZZ, 'z') - sage: L.has_coerce_map_from(R) + sage: L = LazyLaurentSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings + sage: R = LazyPowerSeriesRing(ZZ, 'z') # optional - sage.rings.finite_rings + sage: L.has_coerce_map_from(R) # optional - sage.rings.finite_rings True - sage: L(R(lambda n: n)) + sage: L(R(lambda n: n)) # optional - sage.rings.finite_rings z + z^3 + z^5 + z^7 + O(z^8) - sage: L(R([2,4,6])) == L.zero() + sage: L(R([2,4,6])) == L.zero() # optional - sage.rings.finite_rings True - sage: L(R([2,4,6], valuation=2, constant=4)) == L.zero() + sage: L(R([2,4,6], valuation=2, constant=4)) == L.zero() # optional - sage.rings.finite_rings True - sage: L(R([2,4,6], valuation=2, constant=5)) + sage: L(R([2,4,6], valuation=2, constant=5)) # optional - sage.rings.finite_rings z^5 + z^6 + z^7 + O(z^8) - sage: L(R([2,3,4], valuation=2, constant=4)) + sage: L(R([2,3,4], valuation=2, constant=4)) # optional - sage.rings.finite_rings z^3 - sage: L(R([2,3,4], valuation=2, constant=5)) + sage: L(R([2,3,4], valuation=2, constant=5)) # optional - sage.rings.finite_rings z^3 + z^5 + z^6 + z^7 + O(z^8) Can only convert from known to be constant multivariate power series:: @@ -760,14 +760,14 @@ def characteristic(self): sage: L.characteristic() 0 - sage: R. = LazyLaurentSeriesRing(GF(11)); R + sage: R. = LazyLaurentSeriesRing(GF(11)); R # optional - sage.rings.finite_rings Lazy Laurent Series Ring in w over Finite Field of size 11 - sage: R.characteristic() + sage: R.characteristic() # optional - sage.rings.finite_rings 11 - sage: R. = LazyPowerSeriesRing(GF(7)); R + sage: R. = LazyPowerSeriesRing(GF(7)); R # optional - sage.rings.finite_rings Multivariate Lazy Taylor Series Ring in x, y over Finite Field of size 7 - sage: R.characteristic() + sage: R.characteristic() # optional - sage.rings.finite_rings 7 sage: L = LazyDirichletSeriesRing(ZZ, "s") @@ -782,13 +782,13 @@ def _coerce_map_from_(self, S): EXAMPLES:: - sage: L = LazyLaurentSeriesRing(GF(2), 'z') - sage: L.has_coerce_map_from(ZZ) + sage: L = LazyLaurentSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings + sage: L.has_coerce_map_from(ZZ) # optional - sage.rings.finite_rings True - sage: L.has_coerce_map_from(GF(2)) + sage: L.has_coerce_map_from(GF(2)) # optional - sage.rings.finite_rings True sage: R = LazyPowerSeriesRing(ZZ, 'z') - sage: L.has_coerce_map_from(R) + sage: L.has_coerce_map_from(R) # optional - sage.rings.finite_rings True sage: L = LazyLaurentSeriesRing(QQ, 'z') @@ -802,17 +802,17 @@ def _coerce_map_from_(self, S): sage: L.has_coerce_map_from(R) False - sage: L = LazyPowerSeriesRing(GF(2), 'z') - sage: L.has_coerce_map_from(ZZ) + sage: L = LazyPowerSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings + sage: L.has_coerce_map_from(ZZ) # optional - sage.rings.finite_rings True - sage: L.has_coerce_map_from(GF(2)) + sage: L.has_coerce_map_from(GF(2)) # optional - sage.rings.finite_rings True - sage: s = SymmetricFunctions(GF(2)).s() - sage: L = LazySymmetricFunctions(s) - sage: L.has_coerce_map_from(ZZ) + sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.rings.finite_rings + sage: L = LazySymmetricFunctions(s) # optional - sage.rings.finite_rings + sage: L.has_coerce_map_from(ZZ) # optional - sage.rings.finite_rings True - sage: L.has_coerce_map_from(GF(2)) + sage: L.has_coerce_map_from(GF(2)) # optional - sage.rings.finite_rings True """ if self.base_ring().has_coerce_map_from(S): @@ -845,11 +845,14 @@ def _coerce_map_from_base_ring(self): sage: L = LazyDirichletSeriesRing(QQ, 'z') sage: phi = L._coerce_map_from_base_ring() - sage: phi(2) + sage: m = phi(2) + sage: m # optional - sage.symbolic 2 - sage: phi(2, valuation=2) + sage: m = phi(2, valuation=2) + sage: m # optional - sage.symbolic 2/2^z - sage: phi(2, valuation=2, constant=4) + sage: m = phi(2, valuation=2, constant=4) + sage: m # optional - sage.symbolic 2/2^z + 4/3^z + 4/4^z + 4/5^z + O(1/(6^z)) """ # Return a DefaultConvertMap_unique; this can pass additional @@ -1048,12 +1051,12 @@ class LazyLaurentSeriesRing(LazySeriesRing): Lazy Laurent series ring over a finite field:: - sage: L. = LazyLaurentSeriesRing(GF(3)); L + sage: L. = LazyLaurentSeriesRing(GF(3)); L # optional - sage.rings.finite_rings Lazy Laurent Series Ring in z over Finite Field of size 3 - sage: e = 1 / (1 + z) - sage: e.coefficient(100) + sage: e = 1 / (1 + z) # optional - sage.rings.finite_rings + sage: e.coefficient(100) # optional - sage.rings.finite_rings 1 - sage: e.coefficient(100).parent() + sage: e.coefficient(100).parent() # optional - sage.rings.finite_rings Finite Field of size 3 Series can be defined by specifying a coefficient function @@ -1202,14 +1205,14 @@ def __init__(self, base_ring, names, sparse=True, category=None): (euclidean domains and infinite enumerated sets and metric spaces) and infinite sets) - sage: L = LazyLaurentSeriesRing(GF(5), 't') - sage: TestSuite(L).run() + sage: L = LazyLaurentSeriesRing(GF(5), 't') # optional - sage.rings.finite_rings + sage: TestSuite(L).run() # optional - sage.rings.finite_rings - sage: L = LazyLaurentSeriesRing(GF(5)['x'], 't') - sage: TestSuite(L).run() + sage: L = LazyLaurentSeriesRing(GF(5)['x'], 't') # optional - sage.rings.finite_rings + sage: TestSuite(L).run() # optional - sage.rings.finite_rings - sage: L = LazyLaurentSeriesRing(GF(5)['x, y'], 't') - sage: TestSuite(L).run() + sage: L = LazyLaurentSeriesRing(GF(5)['x, y'], 't') # optional - sage.rings.finite_rings + sage: TestSuite(L).run() # optional - sage.rings.finite_rings sage: L = LazyLaurentSeriesRing(Zmod(6), 't') sage: TestSuite(L).run(skip=['_test_revert']) @@ -1252,7 +1255,7 @@ def _repr_(self): EXAMPLES:: - sage: LazyLaurentSeriesRing(GF(2), 'z') + sage: LazyLaurentSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings Lazy Laurent Series Ring in z over Finite Field of size 2 """ return "Lazy Laurent Series Ring in {} over {}".format(self.variable_name(), self.base_ring()) @@ -1263,8 +1266,8 @@ def _latex_(self): EXAMPLES:: - sage: L = LazyLaurentSeriesRing(GF(2), 'z') - sage: latex(L) + sage: L = LazyLaurentSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings + sage: latex(L) # optional - sage.rings.finite_rings \Bold{F}_{2} (\!(z)\!) """ from sage.misc.latex import latex @@ -1349,16 +1352,16 @@ def some_elements(self): -2*z^-3 - 2*z^-2 + 4*z^-1 + 11 - z - 34*z^2 - 31*z^3 + O(z^4), 4*z^-2 + z^-1 + z + 4*z^2 + 9*z^3 + 16*z^4 + O(z^5)] - sage: L = LazyLaurentSeriesRing(GF(2), 'z') - sage: L.some_elements()[:7] + sage: L = LazyLaurentSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings + sage: L.some_elements()[:7] # optional - sage.rings.finite_rings [0, 1, z, z^-4 + z^-3 + z^2 + z^3, z^-2, 1 + z + z^3 + z^4 + z^6 + O(z^7), z^-1 + z + z^3 + O(z^5)] - sage: L = LazyLaurentSeriesRing(GF(3), 'z') - sage: L.some_elements()[:7] + sage: L = LazyLaurentSeriesRing(GF(3), 'z') # optional - sage.rings.finite_rings + sage: L.some_elements()[:7] # optional - sage.rings.finite_rings [0, 1, z, z^-3 + z^-1 + 2 + z + z^2 + z^3, z^-2, @@ -1666,11 +1669,11 @@ def __init__(self, base_ring, names, sparse=True, category=None): sage: L = LazyPowerSeriesRing(QQ, 's, t') sage: TestSuite(L).run(skip="_test_fraction_field") - sage: L = LazyPowerSeriesRing(GF(5), 't') - sage: TestSuite(L).run() + sage: L = LazyPowerSeriesRing(GF(5), 't') # optional - sage.rings.finite_rings + sage: TestSuite(L).run() # optional - sage.rings.finite_rings - sage: L = LazyPowerSeriesRing(GF(5), 's, t') - sage: TestSuite(L).run(skip=['_test_fraction_field']) + sage: L = LazyPowerSeriesRing(GF(5), 's, t') # optional - sage.rings.finite_rings + sage: TestSuite(L).run(skip=['_test_fraction_field']) # optional - sage.rings.finite_rings sage: L = LazyPowerSeriesRing(Zmod(6), 't') sage: TestSuite(L).run(skip=['_test_revert']) @@ -1752,7 +1755,7 @@ def _repr_(self): EXAMPLES:: - sage: LazyPowerSeriesRing(GF(2), 'z') + sage: LazyPowerSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings Lazy Taylor Series Ring in z over Finite Field of size 2 """ BR = self.base_ring() @@ -1767,8 +1770,8 @@ def _latex_(self): EXAMPLES:: - sage: L = LazyPowerSeriesRing(GF(2), 'z') - sage: latex(L) + sage: L = LazyPowerSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings + sage: latex(L) # optional - sage.rings.finite_rings \Bold{F}_{2} [\![z]\!] """ from sage.misc.latex import latex @@ -1866,10 +1869,10 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No EXAMPLES:: - sage: L = LazyPowerSeriesRing(GF(2), 'z') - sage: L(2) + sage: L = LazyPowerSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings + sage: L(2) # optional - sage.rings.finite_rings 0 - sage: L(3) + sage: L(3) # optional - sage.rings.finite_rings 1 sage: L = LazyPowerSeriesRing(ZZ, 'z') @@ -1883,7 +1886,7 @@ def _element_constructor_(self, x=None, valuation=None, constant=None, degree=No sage: X.valuation() 2 - sage: e = L(lambda n: n+1); e + sage: e = L(lambda n: n + 1); e 1 + 2*z + 3*z^2 + 4*z^3 + 5*z^4 + 6*z^5 + 7*z^6 + O(z^7) sage: f = e^-1; f 1 - 2*z + z^2 + O(z^7) @@ -2188,15 +2191,15 @@ def some_elements(self): 1 + z - 2*z^2 - 7*z^3 - z^4 + 20*z^5 + 23*z^6 + O(z^7), z + 4*z^2 + 9*z^3 + 16*z^4 + 25*z^5 + 36*z^6 + O(z^7)] - sage: L = LazyPowerSeriesRing(GF(3)["q"], 'z') - sage: L.some_elements()[:6] + sage: L = LazyPowerSeriesRing(GF(3)["q"], 'z') # optional - sage.rings.finite_rings + sage: L.some_elements()[:6] # optional - sage.rings.finite_rings [0, 1, z + q*z^2 + q*z^3 + q*z^4 + O(z^5), z + z^2 + z^3, 1 + z + z^2 + 2*z^3 + 2*z^4 + 2*z^5 + O(z^6), z + z^2 + z^4 + z^5 + O(z^7)] - sage: L = LazyPowerSeriesRing(GF(3), 'q, t') - sage: L.some_elements()[:6] + sage: L = LazyPowerSeriesRing(GF(3), 'q, t') # optional - sage.rings.finite_rings + sage: L.some_elements()[:6] # optional - sage.rings.finite_rings [0, 1, q, q + q^2 + q^3, 1 + q + q^2 + (-q^3) + (-q^4) + (-q^5) + (-q^6) + O(q,t)^7, @@ -2274,9 +2277,9 @@ def __init__(self, basis, sparse=True, category=None): sage: L = LazySymmetricFunctions(s) sage: TestSuite(L).run() - sage: p = SymmetricFunctions(GF(5)).p() - sage: L = LazySymmetricFunctions(p) - sage: TestSuite(L).run() + sage: p = SymmetricFunctions(GF(5)).p() # optional - sage.rings.finite_rings + sage: L = LazySymmetricFunctions(p) # optional - sage.rings.finite_rings + sage: TestSuite(L).run() # optional - sage.rings.finite_rings Reversion will only work when the base ring is a field:: @@ -2342,8 +2345,8 @@ def _repr_(self): EXAMPLES:: - sage: s = SymmetricFunctions(GF(2)).s() - sage: LazySymmetricFunctions(s) + sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.rings.finite_rings + sage: LazySymmetricFunctions(s) # optional - sage.rings.finite_rings Lazy completion of Symmetric Functions over Finite Field of size 2 in the Schur basis """ return "Lazy completion of {}".format(self._laurent_poly_ring) @@ -2354,9 +2357,9 @@ def _latex_(self): EXAMPLES:: - sage: s = SymmetricFunctions(GF(2)).s() - sage: L = LazySymmetricFunctions(s) - sage: latex(L) + sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.rings.finite_rings + sage: L = LazySymmetricFunctions(s) # optional - sage.rings.finite_rings + sage: latex(L) # optional - sage.rings.finite_rings \text{\texttt{Symmetric{ }Functions{ }over{ }Finite{ }Field{ }of{ }size{ }2{ }in{ }the{ }Schur{ }basis}} """ from sage.misc.latex import latex @@ -2393,11 +2396,11 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No EXAMPLES:: - sage: m = SymmetricFunctions(GF(2)).m() - sage: L = LazySymmetricFunctions(m) - sage: L(2) + sage: m = SymmetricFunctions(GF(2)).m() # optional - sage.rings.finite_rings + sage: L = LazySymmetricFunctions(m) # optional - sage.rings.finite_rings + sage: L(2) # optional - sage.rings.finite_rings 0 - sage: L(3) + sage: L(3) # optional - sage.rings.finite_rings m[] sage: m = SymmetricFunctions(ZZ).m() @@ -2577,9 +2580,9 @@ def some_elements(self): EXAMPLES:: - sage: m = SymmetricFunctions(GF(5)).m() - sage: L = LazySymmetricFunctions(m) - sage: L.some_elements()[:5] + sage: m = SymmetricFunctions(GF(5)).m() # optional - sage.rings.finite_rings + sage: L = LazySymmetricFunctions(m) # optional - sage.rings.finite_rings + sage: L.some_elements()[:5] # optional - sage.rings.finite_rings [0, m[], 2*m[] + 2*m[1] + 3*m[2], 2*m[1] + 3*m[2], 3*m[] + 2*m[1] + (m[1,1]+m[2]) + (2*m[1,1,1]+m[3]) @@ -2710,6 +2713,24 @@ class LazyDirichletSeriesRing(LazySeriesRing): # Follow the "generic" normalization __classcall_private__ = LazySeriesRing.__classcall_private__ + @lazy_attribute + def _laurent_poly_ring(self): + r""" + Return the symbolic ring. + + .. TODO:: + + It would be good to have something better than the symbolic ring. + + TESTS:: + + sage: L = LazyDirichletSeriesRing(ZZ, 't') + sage: L._laurent_poly_ring is SR # optional - sage.symbolic + True + """ + from sage.symbolic.ring import SR + return SR + def __init__(self, base_ring, names, sparse=True, category=None): r""" Initialize the ring. @@ -2733,7 +2754,6 @@ def __init__(self, base_ring, names, sparse=True, category=None): self._sparse = sparse self._minimal_valuation = 1 self._arity = 1 - self._laurent_poly_ring = SR # TODO: it would be good to have something better than the symbolic ring self._internal_poly_ring = PolynomialRing(base_ring, names, sparse=sparse) category = Algebras(base_ring.category()) @@ -2751,7 +2771,7 @@ def _repr_(self): EXAMPLES:: - sage: LazyDirichletSeriesRing(QQbar, 'z') + sage: LazyDirichletSeriesRing(QQbar, 'z') # optional - sage.rings.number_field Lazy Dirichlet Series Ring in z over Algebraic Field """ return "Lazy Dirichlet Series Ring in {} over {}".format(self.variable_name(), self.base_ring()) @@ -2764,9 +2784,9 @@ def one(self): EXAMPLES:: sage: L = LazyDirichletSeriesRing(ZZ, 'z') - sage: L.one() + sage: L.one() # optional - sage.symbolic 1 - sage: ~L.one() + sage: ~L.one() # optional - sage.symbolic 1 + O(1/(8^z)) """ R = self.base_ring() @@ -2804,25 +2824,32 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No EXAMPLES:: sage: L = LazyDirichletSeriesRing(ZZ, 'z') - sage: L(3) + sage: R = L(3) + sage: R # optional - sage.symbolic 3 - sage: L(lambda i: i, constant=1, degree=6) + sage: S = L(lambda i: i, constant=1, degree=6) + sage: S # optional - sage.symbolic 1 + 2/2^z + 3/3^z + 4/4^z + 5/5^z + 1/(6^z) + 1/(7^z) + 1/(8^z) + O(1/(9^z)) - sage: X = L(constant=5, degree=3); X + sage: X = L(constant=5, degree=3) + sage: X # optional - sage.symbolic 5/3^z + 5/4^z + 5/5^z + O(1/(6^z)) sage: X.valuation() log(3) - sage: e = L(moebius); e + sage: e = L(moebius) + sage: e # optional - sage.symbolic 1 - 1/(2^z) - 1/(3^z) - 1/(5^z) + 1/(6^z) - 1/(7^z) + O(1/(8^z)) - sage: L([0], constant=1) + sage: T = L([0], constant=1) + sage: T # optional - sage.symbolic 1/(2^z) + 1/(3^z) + 1/(4^z) + O(1/(5^z)) - sage: L(constant=1) + sage: U = L(constant=1) + sage: U # optional - sage.symbolic 1 + 1/(2^z) + 1/(3^z) + O(1/(4^z)) - sage: L(lambda i: i, valuation=3) + sage: V = L(lambda i: i, valuation=3) + sage: V # optional - sage.symbolic 3/3^z + 4/4^z + 5/5^z + 6/6^z + 7/7^z + 8/8^z + 9/9^z + O(1/(10^z)) Alternatively, ``x`` can be a list of elements of the base ring. @@ -2831,37 +2858,45 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No may be just an element of the base ring instead of a tuple or can be simply omitted if it is zero:: - sage: f = L([1,2,3,4], 4); f + sage: f = L([1,2,3,4], 4) + sage: f # optional - sage.symbolic 1/(4^z) + 2/5^z + 3/6^z + 4/7^z - sage: g = L([1,3,5,7,9], 6, constant=-1); g - 1/(6^z) + 3/7^z + 5/8^z + 7/9^z + 9/10^z - 1/(11^z) - 1/(12^z) - 1/(13^z) + O(1/(14^z)) + sage: g = L([1,3,5,7,9], 6, constant=-1) + sage: g # optional - sage.symbolic + 1/(6^z) + 3/7^z + 5/8^z + 7/9^z + 9/10^z - 1/(11^z) - 1/(12^z) + - 1/(13^z) + O(1/(14^z)) TESTS:: - sage: L = LazyDirichletSeriesRing(GF(2), 'z') + sage: L = LazyDirichletSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: positive characteristic not allowed for Dirichlet series sage: L. = LazyLaurentSeriesRing(QQ) sage: D = LazyDirichletSeriesRing(QQ, 't') - sage: D(L.one()) + sage: d = D(L.one()) + sage: d # optional - sage.symbolic 1 + 1/(2^t) + 1/(3^t) + 1/(4^t) + 1/(5^t) + 1/(6^t) + 1/(7^t) + O(1/(8^t)) sage: R. = LaurentPolynomialRing(QQ) sage: D = LazyDirichletSeriesRing(QQ, 't') - sage: D(coefficients=z+z^2) + sage: dd = D(coefficients=z + z^2) + sage: dd # optional - sage.symbolic 2 + 6/2^t + 12/3^t + 20/4^t + 30/5^t + 42/6^t + 56/7^t + O(1/(8^t)) sage: s = D(lambda n: n) - sage: D(s, valuation=2) + sage: d2 = D(s, valuation=2) + sage: d2 # optional - sage.symbolic 1/(2^t) + 2/3^t + 3/4^t + 4/5^t + 5/6^t + 6/7^t + 7/8^t + O(1/(9^t)) sage: Ds = LazyDirichletSeriesRing(ZZ, 's') - sage: m = Ds(moebius, valuation=2); m + sage: m = Ds(moebius, valuation=2) + sage: m # optional - sage.symbolic -1/(2^s) - 1/(3^s) - 1/(5^s) + 1/(6^s) - 1/(7^s) + O(1/(9^s)) sage: D = LazyDirichletSeriesRing(QQ, 't') - sage: D(m) + sage: dm = D(m) + sage: dm # optional - sage.symbolic -1/(2^t) - 1/(3^t) - 1/(5^t) + 1/(6^t) - 1/(7^t) + O(1/(9^t)) """ if isinstance(x, (list, tuple)): @@ -2906,7 +2941,8 @@ def _an_element_(self): EXAMPLES:: sage: L = LazyDirichletSeriesRing(ZZ, 'z') - sage: L.an_element() + sage: m = L.an_element() + sage: m # optional - sage.symbolic 1/(4^z) + 1/(5^z) + 1/(6^z) + O(1/(7^z)) """ c = self.base_ring().an_element() @@ -2919,7 +2955,8 @@ def some_elements(self): EXAMPLES:: sage: L = LazyDirichletSeriesRing(ZZ, 'z') - sage: L.some_elements() + sage: l = L.some_elements() + sage: l # optional - sage.symbolic [0, 1, 1/(4^z) + 1/(5^z) + 1/(6^z) + O(1/(7^z)), 1/(2^z) - 1/(3^z) + 2/4^z - 2/5^z + 3/6^z - 3/7^z + 4/8^z - 4/9^z, @@ -2927,7 +2964,8 @@ def some_elements(self): 1 + 4/2^z + 9/3^z + 16/4^z + 25/5^z + 36/6^z + 49/7^z + O(1/(8^z))] sage: L = LazyDirichletSeriesRing(QQ, 'z') - sage: L.some_elements() + sage: l = L.some_elements() + sage: l # optional - sage.symbolic [0, 1, 1/2/4^z + 1/2/5^z + 1/2/6^z + O(1/(7^z)), 1/2 - 1/2/2^z + 2/3^z - 2/4^z + 1/(6^z) - 1/(7^z) + 42/8^z + 2/3/9^z, @@ -2949,7 +2987,8 @@ def _monomial(self, c, n): EXAMPLES:: sage: L = LazyDirichletSeriesRing(ZZ, 'z') - sage: L._monomial(5, 3) + sage: m = L._monomial(5, 3) + sage: m # optional - sage.symbolic 5/3^z """ try: @@ -2969,11 +3008,11 @@ def _skip_leading_zeros(iterator): sage: [x for x, _ in zip(_skip_leading_zeros(it), range(10))] [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] - sage: it = map(GF(3), NN) - sage: [x for x, _ in zip(it, range(10))] + sage: it = map(GF(3), NN) # optional - sage.rings.finite_rings + sage: [x for x, _ in zip(it, range(10))] # optional - sage.rings.finite_rings [0, 1, 2, 0, 1, 2, 0, 1, 2, 0] - sage: it = map(GF(3), NN) - sage: [x for x, _ in zip(_skip_leading_zeros(it), range(10))] + sage: it = map(GF(3), NN) # optional - sage.rings.finite_rings + sage: [x for x, _ in zip(_skip_leading_zeros(it), range(10))] # optional - sage.rings.finite_rings [1, 2, 0, 1, 2, 0, 1, 2, 0, 1] """ while True: From eaef6e6d348347230589c1dbc9caa6907365fa3a Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 23 Apr 2023 15:56:24 -0700 Subject: [PATCH 18/98] Fix imports --- src/sage/rings/big_oh.py | 21 ++++++++----------- .../polynomial/laurent_polynomial_mpair.pxd | 1 + .../polynomial/laurent_polynomial_mpair.pyx | 3 ++- .../polynomial/laurent_polynomial_ring.py | 6 +++--- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/sage/rings/big_oh.py b/src/sage/rings/big_oh.py index 1df61a39dc0..19d02f94459 100644 --- a/src/sage/rings/big_oh.py +++ b/src/sage/rings/big_oh.py @@ -10,6 +10,10 @@ """ from sage.arith.misc import factor +from sage.misc.lazy_import import lazy_import +lazy_import('sage.rings.padics.factory', ['Qp', 'Zp']) +lazy_import('sage.rings.padics.padic_generic_element', 'pAdicGenericElement') +from sage.rings.polynomial.polynomial_element import Polynomial try: from .laurent_series_ring_element import LaurentSeries @@ -17,20 +21,13 @@ LaurentSeries = () try: - from sage.rings.puiseux_series_ring_element import PuiseuxSeries + from .puiseux_series_ring_element import PuiseuxSeries except ImportError: PuiseuxSeries = () -try: - import sage.rings.padics.factory as padics_factory - from sage.rings.padics.padic_generic_element.padic_generic_element import pAdicGenericElement -except ImportError: - pAdicGenericElement = () - from . import power_series_ring_element from . import integer from . import rational -from sage.rings.polynomial.polynomial_element import Polynomial from . import multi_power_series_ring_element @@ -165,11 +162,11 @@ def O(*x, **kwds): raise ArithmeticError("x must be prime power") p, r = F[0] if r >= 0: - return padics_factory.Zp(p, prec=max(r, 20), - type='capped-rel')(0, absprec=r, **kwds) + return Zp(p, prec=max(r, 20), + type='capped-rel')(0, absprec=r, **kwds) else: - return padics_factory.Qp(p, prec=max(r, 20), - type='capped-rel')(0, absprec=r, **kwds) + return Qp(p, prec=max(r, 20), + type='capped-rel')(0, absprec=r, **kwds) elif isinstance(x, pAdicGenericElement): return x.parent()(0, absprec=x.valuation(), **kwds) diff --git a/src/sage/rings/polynomial/laurent_polynomial_mpair.pxd b/src/sage/rings/polynomial/laurent_polynomial_mpair.pxd index eb31593dc77..79f09def6aa 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_mpair.pxd +++ b/src/sage/rings/polynomial/laurent_polynomial_mpair.pxd @@ -1,3 +1,4 @@ +from sage.rings.polynomial.laurent_polynomial cimport LaurentPolynomial from sage.rings.polynomial.multi_polynomial cimport MPolynomial from sage.rings.polynomial.polydict cimport ETuple, PolyDict diff --git a/src/sage/rings/polynomial/laurent_polynomial_mpair.pyx b/src/sage/rings/polynomial/laurent_polynomial_mpair.pyx index ceb64874f77..70bc5f4e023 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_mpair.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial_mpair.pyx @@ -12,6 +12,7 @@ Elements of multivariate Laurent polynomial rings from sage.rings.integer cimport Integer from sage.categories.map cimport Map +from sage.structure.element cimport CommutativeAlgebraElement, Element, ModuleElement, RingElement from sage.structure.element import is_Element, coerce_binop, parent from sage.structure.factorization import Factorization from sage.misc.derivative import multi_derivative @@ -68,7 +69,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): :: - sage: from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial_mpair + sage: from sage.rings.polynomial.laurent_polynomial_mpair import LaurentPolynomial_mpair sage: LaurentPolynomial_mpair(L, {(1,2): 1/42}, mon=(-3, -3)) 1/42*w^-2*z^-1 diff --git a/src/sage/rings/polynomial/laurent_polynomial_ring.py b/src/sage/rings/polynomial/laurent_polynomial_ring.py index f56b911ad3b..e3fb6e0992d 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_ring.py +++ b/src/sage/rings/polynomial/laurent_polynomial_ring.py @@ -43,7 +43,7 @@ # **************************************************************************** from sage.misc.lazy_import import LazyImport -from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial_univariate +from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial, LaurentPolynomial_univariate from sage.rings.polynomial.laurent_polynomial_ring_base import LaurentPolynomialRing_generic from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.structure.element import parent @@ -527,7 +527,7 @@ def _element_constructor_(self, x): if isinstance(x, Expression): return x.laurent_polynomial(ring=self) - elif isinstance(x, (LaurentPolynomial_univariate, LaurentPolynomial_mpair)): + elif isinstance(x, LaurentPolynomial): P = x.parent() if set(self.variable_names()) & set(P.variable_names()): if isinstance(x, LaurentPolynomial_univariate): @@ -743,7 +743,7 @@ def _element_constructor_(self, x, mon=None): elif isinstance(x, Expression): return x.laurent_polynomial(ring=self) - elif isinstance(x, (LaurentPolynomial_univariate, LaurentPolynomial_mpair)): + elif isinstance(x, LaurentPolynomial): if self.variable_names() == P.variable_names(): # No special processing needed here; # handled by LaurentPolynomial_mpair.__init__ From cdb4755a1efe82ae7370bbfd3980310a21dafaf3 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 23 Apr 2023 16:20:31 -0700 Subject: [PATCH 19/98] src/sage/rings/polynomial/laurent_polynomial_mpair.pyx: Docstring cosmetics --- .../polynomial/laurent_polynomial_mpair.pyx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sage/rings/polynomial/laurent_polynomial_mpair.pyx b/src/sage/rings/polynomial/laurent_polynomial_mpair.pyx index 70bc5f4e023..4597219b678 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_mpair.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial_mpair.pyx @@ -1164,8 +1164,8 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): OUTPUT: - Returns True if ``self`` contains a monomial including the inverse of - ``self.parent().gen(i)``, False otherwise. + Return ``True`` if ``self`` contains a monomial including the inverse of + ``self.parent().gen(i)``, ``False`` otherwise. EXAMPLES:: @@ -1189,7 +1189,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): def has_any_inverse(self): """ - Return True if ``self`` contains any monomials with a negative exponent, False otherwise. + Return ``True`` if ``self`` contains any monomials with a negative exponent, False otherwise. EXAMPLES:: @@ -1279,7 +1279,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): - ``in_dict`` -- dictionary (optional) - - ``**kwargs`` -- keyword arguments + - ``**kwds`` -- keyword arguments OUTPUT: @@ -1395,10 +1395,10 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): def _derivative(self, var=None): """ - Computes formal derivative of this Laurent polynomial with + Compute formal derivative of this Laurent polynomial with respect to the given variable. - If var is among the generators of this ring, the derivative + If ``var`` is among the generators of this ring, the derivative is with respect to the generator. Otherwise, ``_derivative(var)`` is called recursively for each coefficient of this polynomial. @@ -1475,8 +1475,8 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): - ``R`` - (default: ``None``) a univariate Laurent polynomial ring If this polynomial is not in at most one variable, then a - ``ValueError`` exception is raised. The new polynomial is over - the same base ring as the given ``LaurentPolynomial`` and in the + :class:`ValueError` exception is raised. The new polynomial is over + the same base ring as the given :class:`LaurentPolynomial` and in the variable ``x`` if no ring ``R`` is provided. EXAMPLES:: From e8df73013cdd36bdc944d7061c9b2ca06c0e350f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 23 Apr 2023 19:14:53 -0700 Subject: [PATCH 20/98] More # optional --- src/sage/rings/big_oh.py | 23 +- .../rings/laurent_series_ring_element.pyx | 4 +- src/sage/rings/lazy_series.py | 301 ++++++++++-------- .../rings/multi_power_series_ring_element.py | 34 +- .../rings/polynomial/laurent_polynomial.pyx | 58 ++-- .../polynomial/laurent_polynomial_ring.py | 201 ++++++------ src/sage/rings/power_series_ring_element.pyx | 6 +- 7 files changed, 327 insertions(+), 300 deletions(-) diff --git a/src/sage/rings/big_oh.py b/src/sage/rings/big_oh.py index 19d02f94459..386474cf653 100644 --- a/src/sage/rings/big_oh.py +++ b/src/sage/rings/big_oh.py @@ -57,41 +57,42 @@ def O(*x, **kwds): This is also useful to create `p`-adic numbers:: - sage: O(7^6) + sage: O(7^6) # optional - sage.rings.padics O(7^6) - sage: 1/3 + O(7^6) + sage: 1/3 + O(7^6) # optional - sage.rings.padics 5 + 4*7 + 4*7^2 + 4*7^3 + 4*7^4 + 4*7^5 + O(7^6) It behaves well with respect to adding negative powers of `p`:: - sage: a = O(11^-32); a + sage: a = O(11^-32); a # optional - sage.rings.padics O(11^-32) - sage: a.parent() + sage: a.parent() # optional - sage.rings.padics 11-adic Field with capped relative precision 20 There are problems if you add a rational with very negative valuation to an `O`-Term:: - sage: 11^-12 + O(11^15) + sage: 11^-12 + O(11^15) # optional - sage.rings.padics 11^-12 + O(11^8) The reason that this fails is that the constructor doesn't know the right precision cap to use. If you cast explicitly or use other means of element creation, you can get around this issue:: - sage: K = Qp(11, 30) - sage: K(11^-12) + O(11^15) + sage: K = Qp(11, 30) # optional - sage.rings.padics + sage: K(11^-12) + O(11^15) # optional - sage.rings.padics 11^-12 + O(11^15) - sage: 11^-12 + K(O(11^15)) + sage: 11^-12 + K(O(11^15)) # optional - sage.rings.padics 11^-12 + O(11^15) - sage: K(11^-12, absprec = 15) + sage: K(11^-12, absprec=15) # optional - sage.rings.padics 11^-12 + O(11^15) - sage: K(11^-12, 15) + sage: K(11^-12, 15) # optional - sage.rings.padics 11^-12 + O(11^15) We can also work with `asymptotic expansions`_:: - sage: A. = AsymptoticRing(growth_group='QQ^n * n^QQ * log(n)^QQ', coefficient_ring=QQ); A + sage: A. = AsymptoticRing(growth_group='QQ^n * n^QQ * log(n)^QQ', # optional - sage.symbolic + ....: coefficient_ring=QQ); A Asymptotic Ring over Rational Field sage: O(n) O(n) diff --git a/src/sage/rings/laurent_series_ring_element.pyx b/src/sage/rings/laurent_series_ring_element.pyx index b11989eafbe..a854bf3076a 100644 --- a/src/sage/rings/laurent_series_ring_element.pyx +++ b/src/sage/rings/laurent_series_ring_element.pyx @@ -1589,8 +1589,8 @@ cdef class LaurentSeries(AlgebraElement): TESTS:: - sage: y = var('y') - sage: f.derivative(y) + sage: y = var('y') # optional - sage.symbolic + sage: f.derivative(y) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to y diff --git a/src/sage/rings/lazy_series.py b/src/sage/rings/lazy_series.py index 581ceaac1ea..fdb2a3c0333 100644 --- a/src/sage/rings/lazy_series.py +++ b/src/sage/rings/lazy_series.py @@ -83,9 +83,9 @@ A similar statement is true for lazy symmetric functions:: - sage: h = SymmetricFunctions(QQ).h() - sage: L = LazySymmetricFunctions(h) - sage: 1 / (1-L(h[1])) + sage: h = SymmetricFunctions(QQ).h() # optional - sage.combinat + sage: L = LazySymmetricFunctions(h) # optional - sage.combinat + sage: 1 / (1-L(h[1])) # optional - sage.combinat h[] + h[1] + (h[1,1]) + (h[1,1,1]) + (h[1,1,1,1]) + (h[1,1,1,1,1]) + (h[1,1,1,1,1,1]) + O^7 We can change the base ring:: @@ -145,9 +145,9 @@ sage: check(L, z) sage: L. = LazyPowerSeriesRing(QQ) sage: check(L, z) - sage: p = SymmetricFunctions(QQ).p() - sage: L = LazySymmetricFunctions(p) - sage: check(L, L(p[1])) + sage: p = SymmetricFunctions(QQ).p() # optional - sage.combinat + sage: L = LazySymmetricFunctions(p) # optional - sage.combinat + sage: check(L, L(p[1])) # optional - sage.combinat We check that the elements in the cache of the stream of homogeneous components are in the correct ring:: @@ -171,30 +171,31 @@ ....: yield n ....: n += 1 - sage: L. = LazyLaurentSeriesRing(GF(2)) - sage: check(L, lambda n: n, valuation=-5) - sage: check(L, gen(), valuation=-5) + sage: L. = LazyLaurentSeriesRing(GF(2)) # optional - sage.rings.finite_rings + sage: check(L, lambda n: n, valuation=-5) # optional - sage.rings.finite_rings + sage: check(L, gen(), valuation=-5) # optional - sage.rings.finite_rings sage: L = LazyDirichletSeriesRing(QQbar, "s") sage: check(L, lambda n: n, valuation=2) sage: check(L, gen(), valuation=2) - sage: L. = LazyPowerSeriesRing(GF(2)) - sage: check(L, lambda n: n, valuation=0) - sage: check(L, gen(), valuation=0) + sage: L. = LazyPowerSeriesRing(GF(2)) # optional - sage.rings.finite_rings + sage: check(L, lambda n: n, valuation=0) # optional - sage.rings.finite_rings + sage: check(L, gen(), valuation=0) # optional - sage.rings.finite_rings - sage: L. = LazyPowerSeriesRing(GF(2)) - sage: check(L, lambda n: (x + y)^n, valuation=None) - sage: def gen(): + sage: L. = LazyPowerSeriesRing(GF(2)) # optional - sage.rings.finite_rings + sage: check(L, lambda n: (x + y)^n, valuation=None) # optional - sage.rings.finite_rings + sage: def gen(): # optional - sage.rings.finite_rings ....: n = 0 ....: while True: ....: yield (x+y)^n ....: n += 1 - sage: check(L, gen(), valuation=None) + sage: check(L, gen(), valuation=None) # optional - sage.rings.finite_rings - sage: s = SymmetricFunctions(GF(2)).s() - sage: L = LazySymmetricFunctions(s) - sage: check(L, lambda n: sum(k*s(la) for k, la in enumerate(Partitions(n))), valuation=0) + sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.combinat sage.rings.finite_rings + sage: L = LazySymmetricFunctions(s) # optional - sage.combinat sage.rings.finite_rings + sage: check(L, lambda n: sum(k*s(la) for k, la in enumerate(Partitions(n))), # optional - sage.combinat sage.rings.finite_rings + ....: valuation=0) """ # **************************************************************************** @@ -435,9 +436,9 @@ def coefficients(self, n=None): sage: f.coefficients() lazy list [1, 1, -1/6, ...] - sage: L. = LazyPowerSeriesRing(GF(2)) - sage: f = L(lambda n: n) - sage: f.coefficients(5) + sage: L. = LazyPowerSeriesRing(GF(2)) # optional - sage.rings.finite_rings + sage: f = L(lambda n: n) # optional - sage.rings.finite_rings + sage: f.coefficients(5) # optional - sage.rings.finite_rings [1, 1, 1, 1, 1] """ coeff_stream = self._coeff_stream @@ -494,9 +495,11 @@ def map_coefficients(self, f): Similarly for Dirichlet series:: sage: L = LazyDirichletSeriesRing(ZZ, "z") - sage: s = L(lambda n: n-1); s + sage: s = L(lambda n: n-1) + sage: s # optional - sage.symbolic 1/(2^z) + 2/3^z + 3/4^z + 4/5^z + 5/6^z + 6/7^z + O(1/(8^z)) - sage: s.map_coefficients(lambda c: c + 1) + sage: ms = s.map_coefficients(lambda c: c + 1) + sage: ms # optional - sage.symbolic 2/2^z + 3/3^z + 4/4^z + 5/5^z + 6/6^z + 7/7^z + 8/8^z + O(1/(9^z)) Similarly for multivariate power series:: @@ -517,12 +520,12 @@ def map_coefficients(self, f): Similarly for lazy symmetric functions:: - sage: p = SymmetricFunctions(QQ).p() - sage: L = LazySymmetricFunctions(p) - sage: f = 1/(1-2*L(p[1])); f + sage: p = SymmetricFunctions(QQ).p() # optional - sage.combinat + sage: L = LazySymmetricFunctions(p) # optional - sage.combinat + sage: f = 1/(1-2*L(p[1])); f # optional - sage.combinat p[] + 2*p[1] + (4*p[1,1]) + (8*p[1,1,1]) + (16*p[1,1,1,1]) + (32*p[1,1,1,1,1]) + (64*p[1,1,1,1,1,1]) + O^7 - sage: f.map_coefficients(lambda c: log(c, 2)) + sage: f.map_coefficients(lambda c: log(c, 2)) # optional - sage.combinat p[1] + (2*p[1,1]) + (3*p[1,1,1]) + (4*p[1,1,1,1]) + (5*p[1,1,1,1,1]) + (6*p[1,1,1,1,1,1]) + O^7 @@ -659,9 +662,11 @@ def shift(self, n): 2 + 3*z^2 + z^5 + z^6 + z^7 + O(z^8) sage: D = LazyDirichletSeriesRing(QQ, 't') - sage: f = D([0,1,2]); f + sage: f = D([0,1,2]) + sage: f # optional - sage.symbolic 1/(2^t) + 2/3^t - sage: f.shift(3) + sage: sf = f.shift(3) + sage: sf # optional - sage.symbolic 1/(5^t) + 2/6^t Examples with power series (where the minimal valuation is `0`):: @@ -1005,60 +1010,60 @@ def __bool__(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(GF(2)) - sage: bool(z-z) + sage: L. = LazyLaurentSeriesRing(GF(2)) # optional - sage.rings.finite_rings + sage: bool(z - z) # optional - sage.rings.finite_rings False - sage: f = 1/(1 - z) - sage: bool(f) + sage: f = 1/(1 - z) # optional - sage.rings.finite_rings + sage: bool(f) # optional - sage.rings.finite_rings True - sage: M = L(lambda n: n, valuation=0); M + sage: M = L(lambda n: n, valuation=0); M # optional - sage.rings.finite_rings z + z^3 + z^5 + O(z^7) - sage: M.is_zero() + sage: M.is_zero() # optional - sage.rings.finite_rings False - sage: M = L(lambda n: 2*n if n < 10 else 1, valuation=0); M + sage: M = L(lambda n: 2*n if n < 10 else 1, valuation=0); M # optional - sage.rings.finite_rings O(z^7) - sage: bool(M) + sage: bool(M) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: undecidable as lazy Laurent series - sage: M[15] + sage: M[15] # optional - sage.rings.finite_rings 1 - sage: bool(M) + sage: bool(M) # optional - sage.rings.finite_rings True - sage: L. = LazyLaurentSeriesRing(GF(2), sparse=True) - sage: M = L(lambda n: 2*n if n < 10 else 1, valuation=0); M + sage: L. = LazyLaurentSeriesRing(GF(2), sparse=True) # optional - sage.rings.finite_rings + sage: M = L(lambda n: 2*n if n < 10 else 1, valuation=0); M # optional - sage.rings.finite_rings O(z^7) - sage: bool(M) + sage: bool(M) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: undecidable as lazy Laurent series - sage: M[15] + sage: M[15] # optional - sage.rings.finite_rings 1 - sage: bool(M) + sage: bool(M) # optional - sage.rings.finite_rings True Uninitialized series:: - sage: g = L.undefined(valuation=0) - sage: bool(g) + sage: g = L.undefined(valuation=0) # optional - sage.rings.finite_rings + sage: bool(g) # optional - sage.rings.finite_rings True - sage: g.define(0) - sage: bool(g) + sage: g.define(0) # optional - sage.rings.finite_rings + sage: bool(g) # optional - sage.rings.finite_rings False - sage: g = L.undefined(valuation=0) - sage: bool(g) + sage: g = L.undefined(valuation=0) # optional - sage.rings.finite_rings + sage: bool(g) # optional - sage.rings.finite_rings True - sage: g.define(1 + z) - sage: bool(g) + sage: g.define(1 + z) # optional - sage.rings.finite_rings + sage: bool(g) # optional - sage.rings.finite_rings True - sage: g = L.undefined(valuation=0) - sage: bool(g) + sage: g = L.undefined(valuation=0) # optional - sage.rings.finite_rings + sage: bool(g) # optional - sage.rings.finite_rings True - sage: g.define(1 + z*g) - sage: bool(g) + sage: g.define(1 + z*g) # optional - sage.rings.finite_rings + sage: bool(g) # optional - sage.rings.finite_rings True """ if isinstance(self._coeff_stream, Stream_zero): @@ -1197,14 +1202,14 @@ def define(self, s): We can compute the Frobenius character of unlabeled trees:: - sage: m = SymmetricFunctions(QQ).m() - sage: s = SymmetricFunctions(QQ).s() - sage: L = LazySymmetricFunctions(m) - sage: E = L(lambda n: s[n], valuation=0) - sage: X = L(s[1]) - sage: A = L.undefined() - sage: A.define(X*E(A, check=False)) - sage: A[:6] + sage: m = SymmetricFunctions(QQ).m() # optional - sage.combinat + sage: s = SymmetricFunctions(QQ).s() # optional - sage.combinat + sage: L = LazySymmetricFunctions(m) # optional - sage.combinat + sage: E = L(lambda n: s[n], valuation=0) # optional - sage.combinat + sage: X = L(s[1]) # optional - sage.combinat + sage: A = L.undefined() # optional - sage.combinat + sage: A.define(X*E(A, check=False)) # optional - sage.combinat + sage: A[:6] # optional - sage.combinat [m[1], 2*m[1, 1] + m[2], 9*m[1, 1, 1] + 5*m[2, 1] + 2*m[3], @@ -1246,7 +1251,7 @@ def define(self, s): sage: g = D.undefined(valuation=2) sage: o = D(constant=1, valuation=2) sage: g.define(o * e(g)) - sage: g + sage: g # optional - sage.symbolic 1/(2^s) + 1/(3^s) + 2/4^s + 1/(5^s) + 3/6^s + 1/(7^s) + 9/2/8^s + O(1/(9^s)) For Laurent series there is no minimal valuation, so it has @@ -1271,7 +1276,7 @@ def define(self, s): sage: g = D([0, 1]) sage: f = D.undefined() sage: f.define(1 + ~f*g) - sage: f + sage: f # optional - sage.symbolic 1 + 1/(2^s) - 1/(4^s) + O(1/(8^s)) sage: oeis(f[:30]) # optional, internet @@ -1319,11 +1324,11 @@ def define(self, s): sage: f 1 + 2*t + 12*t^3 + 32*t^4 + 368*t^5 + 2192*t^6 + O(t^7) - sage: s = SymmetricFunctions(QQ).s() - sage: L = LazySymmetricFunctions(s) - sage: f = L.undefined() - sage: f.define(1+(s[1]*f).revert()) - sage: f + sage: s = SymmetricFunctions(QQ).s() # optional - sage.combinat + sage: L = LazySymmetricFunctions(s) # optional - sage.combinat + sage: f = L.undefined() # optional - sage.combinat + sage: f.define(1+(s[1]*f).revert()) # optional - sage.combinat + sage: f # optional - sage.combinat s[] + s[1] + (-s[1,1]-s[2]) + (3*s[1,1,1]+6*s[2,1]+3*s[3]) + (-13*s[1,1,1,1]-39*s[2,1,1]-26*s[2,2]-39*s[3,1]-13*s[4]) @@ -1331,7 +1336,7 @@ def define(self, s): + (-419*s[1,1,1,1,1,1]-2095*s[2,1,1,1,1]-3771*s[2,2,1,1]-2095*s[2,2,2]-4190*s[3,1,1,1]-6704*s[3,2,1]-2095*s[3,3]-4190*s[4,1,1]-3771*s[4,2]-2095*s[5,1]-419*s[6]) + O^7 - sage: (f*s[1]).revert() + 1 - f + sage: (f*s[1]).revert() + 1 - f # optional - sage.combinat O^7 """ @@ -1454,12 +1459,12 @@ def _ascii_art_(self): EXAMPLES:: - sage: e = SymmetricFunctions(QQ).e() - sage: L. = LazyLaurentSeriesRing(e) - sage: L.options.display_length = 3 - sage: ascii_art(1 / (1 - e[1]*z)) + sage: e = SymmetricFunctions(QQ).e() # optional - sage.combinat + sage: L. = LazyLaurentSeriesRing(e) # optional - sage.combinat + sage: L.options.display_length = 3 # optional - sage.combinat + sage: ascii_art(1 / (1 - e[1]*z)) # optional - sage.combinat e[] + e[1]*z + e[1, 1]*z^2 + O(e[]*z^3) - sage: L.options._reset() + sage: L.options._reset() # optional - sage.combinat """ from sage.typeset.ascii_art import ascii_art, AsciiArt if isinstance(self._coeff_stream, Stream_zero): @@ -1474,12 +1479,12 @@ def _unicode_art_(self): EXAMPLES:: - sage: e = SymmetricFunctions(QQ).e() - sage: L. = LazyLaurentSeriesRing(e) - sage: L.options.display_length = 3 - sage: unicode_art(1 / (1 - e[1]*z)) + sage: e = SymmetricFunctions(QQ).e() # optional - sage.combinat + sage: L. = LazyLaurentSeriesRing(e) # optional - sage.combinat + sage: L.options.display_length = 3 # optional - sage.combinat + sage: unicode_art(1 / (1 - e[1]*z)) # optional - sage.combinat e[] + e[1]*z + e[1, 1]*z^2 + O(e[]*z^3) - sage: L.options._reset() + sage: L.options._reset() # optional - sage.combinat """ from sage.typeset.unicode_art import unicode_art, UnicodeArt if isinstance(self._coeff_stream, Stream_zero): @@ -1533,7 +1538,8 @@ def change_ring(self, ring): sage: t = s.change_ring(QQ) sage: t.parent() Lazy Dirichlet Series Ring in z over Rational Field - sage: t^-1 + sage: it = t^-1 + sage: it # optional - sage.symbolic 1/2 - 1/2/2^z - 1/2/3^z - 1/2/5^z + 1/2/6^z - 1/2/7^z + O(1/(8^z)) A Taylor series example:: @@ -1600,23 +1606,29 @@ def _add_(self, other): Similarly for Dirichlet series:: sage: L = LazyDirichletSeriesRing(ZZ, "z") - sage: s = L(lambda n: n); s + sage: s = L(lambda n: n) + sage: s # optional - sage.symbolic 1 + 2/2^z + 3/3^z + 4/4^z + 5/5^z + 6/6^z + 7/7^z + O(1/(8^z)) - sage: t = L(constant=1); t + sage: t = L(constant=1) + sage: t # optional - sage.symbolic 1 + 1/(2^z) + 1/(3^z) + O(1/(4^z)) - sage: s + t + sage: st = s + t + sage: st # optional - sage.symbolic 2 + 3/2^z + 4/3^z + 5/4^z + 6/5^z + 7/6^z + 8/7^z + O(1/(8^z)) sage: r = L(constant=-1) - sage: r + t + sage: rt = r + t + sage: rt # optional - sage.symbolic 0 sage: r = L([1,2,3]) - sage: r + t + sage: rt = r + t + sage: rt # optional - sage.symbolic 2 + 3/2^z + 4/3^z + 1/(4^z) + 1/(5^z) + 1/(6^z) + O(1/(7^z)) sage: r = L([1,2,3], constant=-1) - sage: r + t + sage: rt = r + t + sage: rt # optional - sage.symbolic 2 + 3/2^z + 4/3^z """ P = self.parent() @@ -1811,15 +1823,16 @@ def _acted_upon_(self, scalar, self_on_left): sage: L = LazyDirichletSeriesRing(ZZ, "z") sage: g = L([0,1]) - sage: 2 * g + sage: 2 * g # optional - sage.symbolic 2/2^z - sage: -1 * g + sage: -1 * g # optional - sage.symbolic -1/(2^z) - sage: 0*g + sage: 0*g # optional - sage.symbolic 0 - sage: M = L(lambda n: n); M + sage: M = L(lambda n: n) + sage: M # optional - sage.symbolic 1 + 2/2^z + 3/3^z + 4/4^z + 5/5^z + 6/6^z + 7/7^z + O(1/(8^z)) - sage: 3 * M + sage: 3 * M # optional - sage.symbolic 3 + 6/2^z + 9/3^z + 12/4^z + 15/5^z + 18/6^z + 21/7^z + O(1/(8^z)) sage: 1 * M is M @@ -1942,7 +1955,7 @@ def exp(self): sage: L = LazyDirichletSeriesRing(QQ, "s") sage: Z = L(constant=1, valuation=2) - sage: exp(Z) + sage: exp(Z) # optional - sage.symbolic 1 + 1/(2^s) + 1/(3^s) + 3/2/4^s + 1/(5^s) + 2/6^s + 1/(7^s) + O(1/(8^s)) """ from .lazy_series_ring import LazyLaurentSeriesRing @@ -1958,7 +1971,7 @@ def log(self): sage: L = LazyDirichletSeriesRing(QQ, "s") sage: Z = L(constant=1) - sage: log(Z) + sage: log(Z) # optional - sage.symbolic 1/(2^s) + 1/(3^s) + 1/2/4^s + 1/(5^s) + 1/(7^s) + O(1/(8^s)) """ from .lazy_series_ring import LazyLaurentSeriesRing @@ -2611,14 +2624,14 @@ def __pow__(self, n): sage: D = LazyDirichletSeriesRing(QQ, 's') sage: Z = D(constant=1) - sage: Z^2 + sage: Z^2 # optional - sage.symbolic 1 + 2/2^s + 2/3^s + 3/4^s + 2/5^s + 4/6^s + 2/7^s + O(1/(8^s)) sage: f = Z^(1/3) - sage: f + sage: f # optional - sage.symbolic 1 + 1/3/2^s + 1/3/3^s + 2/9/4^s + 1/3/5^s + 1/9/6^s + 1/3/7^s + O(1/(8^s)) - sage: f^2 + sage: f^2 # optional - sage.symbolic 1 + 2/3/2^s + 2/3/3^s + 5/9/4^s + 2/3/5^s + 4/9/6^s + 2/3/7^s + O(1/(8^s)) - sage: f^3 - Z + sage: f^3 - Z # optional - sage.symbolic O(1/(8^s)) sage: L. = LazyLaurentSeriesRing(QQ) @@ -2675,9 +2688,9 @@ def sqrt(self): sage: D = LazyDirichletSeriesRing(SR, "s") sage: Z = D(constant=1) sage: f = sqrt(Z) - sage: f + sage: f # optional - sage.symbolic 1 + 1/2/2^s + 1/2/3^s + 3/8/4^s + 1/2/5^s + 1/4/6^s + 1/2/7^s + O(1/(8^s)) - sage: f*f - Z + sage: f*f - Z # optional - sage.symbolic O(1/(8^s)) """ return self ** QQ((1, 2)) # == 1/2 @@ -3489,17 +3502,16 @@ def _im_gens_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: Z. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: R. = LazyLaurentSeriesRing(K) - sage: f = R(lambda n: i^n, valuation=-2) - sage: f + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: R. = LazyLaurentSeriesRing(K) # optional - sage.rings.number_field + sage: f = R(lambda n: i^n, valuation=-2); f # optional - sage.rings.number_field -t^-2 - i*t^-1 + 1 + i*t - t^2 - i*t^3 + t^4 + O(t^5) - sage: f._im_gens_(R, [t + t^2]) + sage: f._im_gens_(R, [t + t^2]) # optional - sage.rings.number_field -t^-2 + (-i + 2)*t^-1 + (i - 2) + 4*t + (2*i - 6)*t^2 + (-2*i + 4)*t^3 + (-2*i - 7)*t^4 + O(t^5) - sage: cc = K.hom([-i]) - sage: f._im_gens_(R, [t + t^2], base_map=cc) + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: f._im_gens_(R, [t + t^2], base_map=cc) # optional - sage.rings.number_field -t^-2 + (i + 2)*t^-1 + (-i - 2) + 4*t + (-2*i - 6)*t^2 + (2*i + 4)*t^3 + (2*i - 7)*t^4 + O(t^5) """ @@ -3735,7 +3747,8 @@ def __call__(self, g, *, check=True): sage: L. = LazyLaurentSeriesRing(QQ) sage: e = L(lambda n: 1/factorial(n), 0) sage: D = LazyDirichletSeriesRing(QQ, "s") - sage: g = D(constant=1)-1; g + sage: g = D(constant=1)-1 + sage: g # optional - sage.symbolic 1/(2^s) + 1/(3^s) + 1/(4^s) + O(1/(5^s)) sage: e(g)[0:10] @@ -3744,7 +3757,8 @@ def __call__(self, g, *, check=True): sage: sum(g^k/factorial(k) for k in range(10))[0:10] [0, 1, 1, 1, 3/2, 1, 2, 1, 13/6, 3/2] - sage: g = D([0,1,0,1,1,2]); g + sage: g = D([0,1,0,1,1,2]) + sage: g # optional - sage.symbolic 1/(2^s) + 1/(4^s) + 1/(5^s) + 2/6^s sage: e(g)[0:10] [0, 1, 1, 0, 3/2, 1, 2, 0, 7/6, 0] @@ -3756,11 +3770,12 @@ def __call__(self, g, *, check=True): ... ValueError: can only compose with a positive valuation series - sage: e5 = L(e, degree=5); e5 + sage: e5 = L(e, degree=5) + sage: e5 # optional - sage.symbolic 1 + z + 1/2*z^2 + 1/6*z^3 + 1/24*z^4 - sage: e5(g) + sage: e5(g) # optional - sage.symbolic 1 + 1/(2^s) + 3/2/4^s + 1/(5^s) + 2/6^s + O(1/(8^s)) - sage: sum(e5[k] * g^k for k in range(5)) + sage: sum(e5[k] * g^k for k in range(5)) # optional - sage.symbolic 1 + 1/(2^s) + 3/2/4^s + 1/(5^s) + 2/6^s + O(1/(8^s)) The output parent is always the common parent between the base ring @@ -4531,24 +4546,27 @@ def __call__(self, *g, check=True): We perform the composition with a lazy Dirichlet series:: sage: D = LazyDirichletSeriesRing(QQ, "s") - sage: g = D(constant=1)-1; g + sage: g = D(constant=1)-1 + sage: g # optional - sage.symbolic 1/(2^s) + 1/(3^s) + 1/(4^s) + O(1/(5^s)) sage: f = 1 / (1 - x - y*z); f 1 + x + (x^2+y*z) + (x^3+2*x*y*z) + (x^4+3*x^2*y*z+y^2*z^2) + (x^5+4*x^3*y*z+3*x*y^2*z^2) + (x^6+5*x^4*y*z+6*x^2*y^2*z^2+y^3*z^3) + O(x,y,z)^7 - sage: fog = f(g, g, g); fog + sage: fog = f(g, g, g) + sage: fog # optional - sage.symbolic 1 + 1/(2^s) + 1/(3^s) + 3/4^s + 1/(5^s) + 5/6^s + O(1/(7^s)) - sage: fg = 1 / (1 - g - g*g); fg + sage: fg = 1 / (1 - g - g*g) + sage: fg # optional - sage.symbolic 1 + 1/(2^s) + 1/(3^s) + 3/4^s + 1/(5^s) + 5/6^s + 1/(7^s) + O(1/(8^s)) - sage: fog - fg + sage: fog - fg # optional - sage.symbolic O(1/(8^s)) sage: f = 1 / (1 - 2*a) - sage: f(g) + sage: f(g) # optional - sage.symbolic 1 + 2/2^s + 2/3^s + 6/4^s + 2/5^s + 10/6^s + 2/7^s + O(1/(8^s)) - sage: 1 / (1 - 2*g) + sage: 1 / (1 - 2*g) # optional - sage.symbolic 1 + 2/2^s + 2/3^s + 6/4^s + 2/5^s + 10/6^s + 2/7^s + O(1/(8^s)) The output parent is always the common parent between the base ring @@ -6318,7 +6336,8 @@ class LazyDirichletSeries(LazyModuleElement): EXAMPLES:: sage: L = LazyDirichletSeriesRing(ZZ, "z") - sage: f = L(constant=1)^2; f + sage: f = L(constant=1)^2 + sage: f # optional - sage.symbolic 1 + 2/2^z + 2/3^z + 3/4^z + 2/5^z + 4/6^z + 2/7^z + O(1/(8^z)) sage: f.coefficient(100) == number_of_divisors(100) True @@ -6326,7 +6345,7 @@ class LazyDirichletSeries(LazyModuleElement): Lazy Dirichlet series is picklable:: sage: g = loads(dumps(f)) - sage: g + sage: g # optional - sage.symbolic 1 + 2/2^z + 2/3^z + 3/4^z + 2/5^z + 4/6^z + 2/7^z + O(1/(8^z)) sage: g == f True @@ -6392,35 +6411,37 @@ def _mul_(self, other): TESTS:: sage: D = LazyDirichletSeriesRing(QQ, "s") - sage: zeta = D(constant=1); zeta + sage: zeta = D(constant=1) + sage: zeta # optional - sage.symbolic 1 + 1/(2^s) + 1/(3^s) + O(1/(4^s)) - sage: zeta * zeta + sage: zeta * zeta # optional - sage.symbolic 1 + 2/2^s + 2/3^s + 3/4^s + 2/5^s + 4/6^s + 2/7^s + O(1/(8^s)) sage: [number_of_divisors(n) for n in range(1, 8)] [1, 2, 2, 3, 2, 4, 2] - sage: mu = D(moebius); mu + sage: mu = D(moebius) + sage: mu # optional - sage.symbolic 1 - 1/(2^s) - 1/(3^s) - 1/(5^s) + 1/(6^s) - 1/(7^s) + O(1/(8^s)) - sage: zeta * mu + sage: zeta * mu # optional - sage.symbolic 1 + O(1/(8^s)) sage: D.one() * mu is mu True sage: mu * D.one() is mu True - sage: zeta*(2-zeta) + sage: zeta*(2-zeta) # optional - sage.symbolic 1 - 1/(4^s) - 2/6^s + O(1/(8^s)) sage: d1 = D([0,0,1,2,3]) sage: d2 = D([0,1,2,3]) - sage: d1 * d2 + sage: d1 * d2 # optional - sage.symbolic 1/(6^s) + 2/8^s + 2/9^s + 3/10^s + 7/12^s + O(1/(13^s)) - sage: d1 * d2 # not tested - exact result + sage: d1 * d2 # not tested - exact result # optional - sage.symbolic 1/(6^s) + 2/8^s + 2/9^s + 3/10^s + 7/12^s + 6/15^s + 6/16^s + 9/20^s sage: L. = LazyLaurentSeriesRing(D) - sage: 1/(1-t*zeta) + sage: 1/(1-t*zeta) # optional - sage.symbolic (1 + O(1/(8^s))) + (1 + 1/(2^s) + 1/(3^s) + 1/(4^s) + 1/(5^s) + 1/(6^s) + 1/(7^s) + O(1/(8^s)))*t + (1 + 2/2^s + 2/3^s + 3/4^s + 2/5^s + 4/6^s + 2/7^s + O(1/(8^s)))*t^2 @@ -6533,7 +6554,8 @@ def __call__(self, p, *, check=True): sage: Z(1) Infinity - sage: f = D([1,2,-3,-4], valuation=2); f + sage: f = D([1,2,-3,-4], valuation=2) + sage: f # optional - sage.symbolic 1/(2^s) + 2/3^s - 3/4^s - 4/5^s sage: f(2) 449/3600 @@ -6603,22 +6625,22 @@ def _format_series(self, formatter, format_strings=False): sage: L = LazyDirichletSeriesRing(QQ, "s") sage: f = L(constant=1) - sage: f._format_series(repr) + sage: f._format_series(repr) # optional - sage.symbolic '1 + 1/(2^s) + 1/(3^s) + O(1/(4^s))' - sage: f._format_series(unicode_art) + sage: f._format_series(unicode_art) # optional - sage.symbolic -s -s 1 + 2 + 3 + O(1/(4^s)) - sage: L([1,-1,1])._format_series(repr) + sage: L([1,-1,1])._format_series(repr) # optional - sage.symbolic '1 - 1/(2^s) + 1/(3^s)' - sage: L([1,-1,1])._format_series(ascii_art) + sage: L([1,-1,1])._format_series(ascii_art) # optional - sage.symbolic -s -s 1 + -2 + 3 sage: R. = QQ[] sage: L = LazyDirichletSeriesRing(R, "s") - sage: L([1,-1 + x,1/3])._format_series(ascii_art) + sage: L([1,-1 + x,1/3])._format_series(ascii_art) # optional - sage.symbolic ( -s) (3 ) ( -s ) (---) @@ -6626,9 +6648,10 @@ def _format_series(self, formatter, format_strings=False): sage: L. = LazyLaurentSeriesRing(QQ) sage: D = LazyDirichletSeriesRing(L, "s") - sage: f = D([2, 0, 1/(1-z), 3]); f + sage: f = D([2, 0, 1/(1-z), 3]) + sage: f # optional - sage.symbolic (2)/1^s + ((1+z+z^2+O(z^3))/3^s) + (3)/4^s - sage: f._format_series(ascii_art) + sage: f._format_series(ascii_art) # optional - sage.symbolic ((2)/1^s) + ((1 + z + z^2 + O(z^3))/3^s) + ((3)/4^s) """ P = self.parent() diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index 978de36ce2d..b3e902b9735 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -892,14 +892,14 @@ def quo_rem(self, other, precision=None): sage: R. = PowerSeriesRing(ZZ) sage: f = 1 + a + b - a*b + R.O(3) sage: g = 1 + 2*a - 3*a*b + R.O(3) - sage: q, r = f.quo_rem(g); q, r + sage: q, r = f.quo_rem(g); q, r # optional - sage.libs.singular (1 - a + b + 2*a^2 + O(a, b, c)^3, 0 + O(a, b, c)^3) - sage: f == q*g+r + sage: f == q*g + r # optional - sage.libs.singular True - sage: q, r = (a*f).quo_rem(g); q, r + sage: q, r = (a*f).quo_rem(g); q, r # optional - sage.libs.singular (a - a^2 + a*b + 2*a^3 + O(a, b, c)^4, 0 + O(a, b, c)^4) - sage: a*f == q*g+r + sage: a*f == q*g + r # optional - sage.libs.singular True sage: q, r = (a*f).quo_rem(a*g); q, r @@ -1897,9 +1897,9 @@ def exp(self, prec=infinity): sage: f = a + b + a*b + T.O(3) sage: exp(f) 1 + a + b + 1/2*a^2 + 2*a*b + 1/2*b^2 + O(a, b)^3 - sage: f.exp() + sage: f.exp() # optional - sage.symbolic 1 + a + b + 1/2*a^2 + 2*a*b + 1/2*b^2 + O(a, b)^3 - sage: f.exp(prec=2) + sage: f.exp(prec=2) # optional - sage.symbolic 1 + a + b + O(a, b)^2 sage: log(exp(f)) - f 0 + O(a, b)^3 @@ -1987,11 +1987,11 @@ def log(self, prec=infinity): sage: T. = PowerSeriesRing(ZZ,2) sage: f = 1 + a + b + a*b + T.O(5) - sage: f.log() + sage: f.log() # optional - sage.symbolic a + b - 1/2*a^2 - 1/2*b^2 + 1/3*a^3 + 1/3*b^3 - 1/4*a^4 - 1/4*b^4 + O(a, b)^5 - sage: log(f) + sage: log(f) # optional - sage.symbolic a + b - 1/2*a^2 - 1/2*b^2 + 1/3*a^3 + 1/3*b^3 - 1/4*a^4 - 1/4*b^4 + O(a, b)^5 - sage: exp(log(f)) - f + sage: exp(log(f)) - f # optional - sage.symbolic 0 + O(a, b)^5 If the power series has a constant coefficient `c` and @@ -1999,8 +1999,8 @@ def log(self, prec=infinity): power series over the :class:`~sage.symbolic.ring.SymbolicRing`. These are not yet implemented and therefore such cases raise an error:: - sage: g = 2+f - sage: log(g) + sage: g = 2 + f # optional - sage.symbolic + sage: log(g) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for -: 'Symbolic Ring' and 'Power @@ -2009,7 +2009,7 @@ def log(self, prec=infinity): Another workaround for this limitation is to change base ring to one which is closed under exponentiation, such as `\RR` or `\CC`:: - sage: log(g.change_ring(RDF)) + sage: log(g.change_ring(RDF)) # optional - sage.symbolic 1.09861228... + 0.333333333...*a + 0.333333333...*b - 0.0555555555...*a^2 + 0.222222222...*a*b - 0.0555555555...*b^2 + 0.0123456790...*a^3 - 0.0740740740...*a^2*b - 0.0740740740...*a*b^2 + 0.0123456790...*b^3 @@ -2018,17 +2018,17 @@ def log(self, prec=infinity): TESTS:: - sage: (1+a).log(prec=10).exp() + sage: (1+a).log(prec=10).exp() # optional - sage.symbolic 1 + a + O(a, b)^10 - sage: a.exp(prec=10).log() + sage: a.exp(prec=10).log() # optional - sage.symbolic a + O(a, b)^10 - sage: log(1+a) + sage: log(1+a) # optional - sage.symbolic a - 1/2*a^2 + 1/3*a^3 - 1/4*a^4 + 1/5*a^5 - 1/6*a^6 + 1/7*a^7 - 1/8*a^8 + 1/9*a^9 - 1/10*a^10 + 1/11*a^11 + O(a, b)^12 - sage: -log(1-a+T.O(5)) + sage: -log(1-a+T.O(5)) # optional - sage.symbolic a + 1/2*a^2 + 1/3*a^3 + 1/4*a^4 + O(a, b)^5 - sage: a.log(prec=10) + sage: a.log(prec=10) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: Can only take formal power series for non-zero constant term. diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index 0604b0f0111..e7b17b2cd32 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -30,8 +30,8 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement): EXAMPLES:: - sage: L. = LaurentPolynomialRing(QQ) # indirect doctest - sage: x*y + sage: L. = LaurentPolynomialRing(QQ) # indirect doctest # optional - sage.modules + sage: x*y # optional - sage.modules x*y """ cdef type t = type(self) @@ -113,18 +113,18 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement): :: - sage: L. = LaurentPolynomialRing(QQ) - sage: L(42)._integer_(ZZ) + sage: L. = LaurentPolynomialRing(QQ) # optional - sage.modules + sage: L(42)._integer_(ZZ) # optional - sage.modules 42 - sage: a._integer_(ZZ) + sage: a._integer_(ZZ) # optional - sage.modules Traceback (most recent call last): ... ValueError: a is not constant - sage: L(2/3)._integer_(ZZ) + sage: L(2/3)._integer_(ZZ) # optional - sage.modules Traceback (most recent call last): ... TypeError: no conversion of this rational to integer - sage: ZZ(L(42)) + sage: ZZ(L(42)) # optional - sage.modules 42 """ if not self.is_constant(): @@ -155,14 +155,14 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement): :: - sage: L. = LaurentPolynomialRing(QQ) - sage: L(42)._rational_() + sage: L. = LaurentPolynomialRing(QQ) # optional - sage.modules + sage: L(42)._rational_() # optional - sage.modules 42 - sage: a._rational_() + sage: a._rational_() # optional - sage.modules Traceback (most recent call last): ... ValueError: a is not constant - sage: QQ(L(2/3)) + sage: QQ(L(2/3)) # optional - sage.modules 2/3 """ if not self.is_constant(): @@ -272,22 +272,22 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement): From: Finite Field in r of size 3^2 To: Finite Field in s of size 3^4 Defn: r |--> 2*s^3 + 2*s^2 + 1 - sage: T. = LaurentPolynomialRing(R, 2) # optional - sage.rings.finite_rings - sage: f = r*X + Y # optional - sage.rings.finite_rings - sage: g = f.map_coefficients(h); g # optional - sage.rings.finite_rings + sage: T. = LaurentPolynomialRing(R, 2) # optional - sage.modules sage.rings.finite_rings + sage: f = r*X + Y # optional - sage.modules sage.rings.finite_rings + sage: g = f.map_coefficients(h); g # optional - sage.modules sage.rings.finite_rings (2*s^3 + 2*s^2 + 1)*X + Y - sage: g.parent() # optional - sage.rings.finite_rings + sage: g.parent() # optional - sage.modules sage.rings.finite_rings Multivariate Laurent Polynomial Ring in X, Y over Finite Field in s of size 3^4 - sage: h = lambda x: x.trace() # optional - sage.rings.finite_rings - sage: g = f.map_coefficients(h); g # optional - sage.rings.finite_rings + sage: h = lambda x: x.trace() + sage: g = f.map_coefficients(h); g # optional - sage.modules sage.rings.finite_rings X - Y - sage: g.parent() # optional - sage.rings.finite_rings + sage: g.parent() # optional - sage.modules sage.rings.finite_rings Multivariate Laurent Polynomial Ring in X, Y over Finite Field in r of size 3^2 - sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g # optional - sage.modules sage.rings.finite_rings X - Y - sage: g.parent() # optional - sage.rings.finite_rings + sage: g.parent() # optional - sage.modules sage.rings.finite_rings Multivariate Laurent Polynomial Ring in X, Y over Finite Field of size 3 """ @@ -442,7 +442,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): EXAMPLES:: sage: R. = LaurentPolynomialRing(QQ) - sage: (2+t).is_unit() + sage: (2 + t).is_unit() False sage: f = 2*t sage: f.is_unit() @@ -537,7 +537,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): EXAMPLES:: sage: R. = LaurentPolynomialRing(QQ) - sage: elt = t^2 + t^4 # indirect doctest + sage: elt = t^2 + t^4 # indirect doctest sage: elt.polynomial_construction() (t^2 + 1, 2) @@ -1628,10 +1628,10 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): The answer is dependent of the base ring:: - sage: S. = LaurentPolynomialRing(QQbar) - sage: (2 + 4*t + 2*t^2).is_square() + sage: S. = LaurentPolynomialRing(QQbar) # optional - sage.rings.number_field + sage: (2 + 4*t + 2*t^2).is_square() # optional - sage.rings.number_field False - sage: (2 + 4*u + 2*u^2).is_square() + sage: (2 + 4*u + 2*u^2).is_square() # optional - sage.rings.number_field True TESTS:: @@ -1756,10 +1756,10 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: R. = LaurentPolynomialRing(ZZ) sage: p = 1/x + 1 + x - sage: x,y = var("x, y") - sage: p._derivative(x) + sage: x,y = var("x, y") # optional - sage.symbolic + sage: p._derivative(x) # optional - sage.symbolic -x^-2 + 1 - sage: p._derivative(y) + sage: p._derivative(y) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to y @@ -1906,7 +1906,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: R. = LaurentPolynomialRing(ZZ) sage: f = 4*t^-7 + 3*t^3 + 2*t^4 + t^-6 - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari (t^-7) * (4 + t + 3*t^10 + 2*t^11) """ cdef LaurentPolynomial_univariate u, d diff --git a/src/sage/rings/polynomial/laurent_polynomial_ring.py b/src/sage/rings/polynomial/laurent_polynomial_ring.py index e3fb6e0992d..5ed4a096438 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_ring.py +++ b/src/sage/rings/polynomial/laurent_polynomial_ring.py @@ -20,7 +20,7 @@ sage: A. = QQ[] sage: R. = LaurentPolynomialRing(A) - sage: matrix(R,2,2,[X,0,0,1]) + sage: matrix(R,2,2,[X,0,0,1]) # optional - sage.modules [X 0] [0 1] @@ -64,8 +64,8 @@ def is_LaurentPolynomialRing(R): See https://github.com/sagemath/sage/issues/35229 for details. False - sage: R = LaurentPolynomialRing(QQ,3,'x') - sage: is_LaurentPolynomialRing(R) + sage: R = LaurentPolynomialRing(QQ,3,'x') # optional - sage.modules + sage: is_LaurentPolynomialRing(R) # optional - sage.modules True """ from sage.misc.superseded import deprecation @@ -121,9 +121,9 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): :: - sage: R. = LaurentPolynomialRing(QQ,2); R + sage: R. = LaurentPolynomialRing(QQ, 2); R # optional - sage.modules Multivariate Laurent Polynomial Ring in x, y over Rational Field - sage: f = x^2 - 2*y^-2 + sage: f = x^2 - 2*y^-2 # optional - sage.modules You can't just globally change the names of those variables. This is because objects all over Sage could have pointers to @@ -131,7 +131,7 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): :: - sage: R._assign_names(['z','w']) + sage: R._assign_names(['z','w']) # optional - sage.modules Traceback (most recent call last): ... ValueError: variable names cannot be changed after object creation. @@ -175,31 +175,31 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): :: - sage: R = LaurentPolynomialRing(QQ, 'a,b,c'); R + sage: R = LaurentPolynomialRing(QQ, 'a,b,c'); R # optional - sage.modules Multivariate Laurent Polynomial Ring in a, b, c over Rational Field - sage: S = LaurentPolynomialRing(QQ, ['a','b','c']); S + sage: S = LaurentPolynomialRing(QQ, ['a','b','c']); S # optional - sage.modules Multivariate Laurent Polynomial Ring in a, b, c over Rational Field - sage: T = LaurentPolynomialRing(QQ, ('a','b','c')); T + sage: T = LaurentPolynomialRing(QQ, ('a','b','c')); T # optional - sage.modules Multivariate Laurent Polynomial Ring in a, b, c over Rational Field All three rings are identical. :: - sage: (R is S) and (S is T) + sage: (R is S) and (S is T) # optional - sage.modules True There is a unique Laurent polynomial ring with each term order:: - sage: R = LaurentPolynomialRing(QQ, 'x,y,z', order='degrevlex'); R + sage: R = LaurentPolynomialRing(QQ, 'x,y,z', order='degrevlex'); R # optional - sage.modules Multivariate Laurent Polynomial Ring in x, y, z over Rational Field - sage: S = LaurentPolynomialRing(QQ, 'x,y,z', order='invlex'); S + sage: S = LaurentPolynomialRing(QQ, 'x,y,z', order='invlex'); S # optional - sage.modules Multivariate Laurent Polynomial Ring in x, y, z over Rational Field - sage: S is LaurentPolynomialRing(QQ, 'x,y,z', order='invlex') + sage: S is LaurentPolynomialRing(QQ, 'x,y,z', order='invlex') # optional - sage.modules True - sage: R == S + sage: R == S # optional - sage.modules False @@ -210,24 +210,27 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): :: - sage: LaurentPolynomialRing(QQ, 'x', 10) - Multivariate Laurent Polynomial Ring in x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 over Rational Field + sage: LaurentPolynomialRing(QQ, 'x', 10) # optional - sage.modules + Multivariate Laurent Polynomial Ring in x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 + over Rational Field - sage: LaurentPolynomialRing(GF(7), 'y', 5) - Multivariate Laurent Polynomial Ring in y0, y1, y2, y3, y4 over Finite Field of size 7 + sage: LaurentPolynomialRing(GF(7), 'y', 5) # optional - sage.modules sage.rings.finite_rings + Multivariate Laurent Polynomial Ring in y0, y1, y2, y3, y4 + over Finite Field of size 7 - sage: LaurentPolynomialRing(QQ, 'y', 3, sparse=True) + sage: LaurentPolynomialRing(QQ, 'y', 3, sparse=True) # optional - sage.modules Multivariate Laurent Polynomial Ring in y0, y1, y2 over Rational Field By calling the :meth:`~sage.structure.category_object.CategoryObject.inject_variables` method, all those variable names are available for interactive use:: - sage: R = LaurentPolynomialRing(GF(7),15,'w'); R - Multivariate Laurent Polynomial Ring in w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14 over Finite Field of size 7 - sage: R.inject_variables() + sage: R = LaurentPolynomialRing(GF(7), 15, 'w'); R # optional - sage.modules sage.rings.finite_rings + Multivariate Laurent Polynomial Ring in w0, w1, w2, w3, w4, w5, w6, w7, + w8, w9, w10, w11, w12, w13, w14 over Finite Field of size 7 + sage: R.inject_variables() # optional - sage.modules sage.rings.finite_rings Defining w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14 - sage: (w0 + 2*w8 + w13)^2 + sage: (w0 + 2*w8 + w13)^2 # optional - sage.modules sage.rings.finite_rings w0^2 + 4*w0*w8 + 4*w8^2 + 2*w0*w13 + 4*w8*w13 + w13^2 """ from sage.rings.polynomial.polynomial_ring import is_PolynomialRing @@ -350,12 +353,12 @@ def _split_laurent_polynomial_dict_(P, M, d): TESTS:: - sage: L. = LaurentPolynomialRing(ZZ) - sage: M = LaurentPolynomialRing(ZZ, 'c, d') - sage: N = LaurentPolynomialRing(M, 'a, b') - sage: M(c/d + 1/c) # indirect doctest + sage: L. = LaurentPolynomialRing(ZZ) # optional - sage.modules + sage: M = LaurentPolynomialRing(ZZ, 'c, d') # optional - sage.modules + sage: N = LaurentPolynomialRing(M, 'a, b') # optional - sage.modules + sage: M(c/d + 1/c) # indirect doctest # optional - sage.modules c*d^-1 + c^-1 - sage: N(a + b/c/d + 1/b) # indirect doctest + sage: N(a + b/c/d + 1/b) # indirect doctest # optional - sage.modules a + (c^-1*d^-1)*b + b^-1 """ vars_P = P.variable_names() @@ -407,10 +410,10 @@ def from_fraction_field(L, x): EXAMPLES:: sage: from sage.rings.polynomial.laurent_polynomial_ring import from_fraction_field - sage: L. = LaurentPolynomialRing(ZZ) - sage: F = L.fraction_field() - sage: xi = F(~x) - sage: from_fraction_field(L, xi) == ~x + sage: L. = LaurentPolynomialRing(ZZ) # optional - sage.modules + sage: F = L.fraction_field() # optional - sage.modules + sage: xi = F(~x) # optional - sage.modules + sage: from_fraction_field(L, xi) == ~x # optional - sage.modules True """ d = L(x.denominator()) @@ -477,22 +480,22 @@ def _element_constructor_(self, x): sage: U = LaurentPolynomialRing(QQ, 'a') sage: V = LaurentPolynomialRing(QQ, 'c') sage: L. = LaurentPolynomialRing(QQ) - sage: M = LaurentPolynomialRing(QQ, 'c, d') - sage: Mc, Md = M.gens() - sage: N = LaurentPolynomialRing(M, 'a, b') - sage: Na, Nb = N.gens() - sage: U(Na) + sage: M = LaurentPolynomialRing(QQ, 'c, d') # optional - sage.modules + sage: Mc, Md = M.gens() # optional - sage.modules + sage: N = LaurentPolynomialRing(M, 'a, b') # optional - sage.modules + sage: Na, Nb = N.gens() # optional - sage.modules + sage: U(Na) # optional - sage.modules a - sage: V(Mc) + sage: V(Mc) # optional - sage.modules c - sage: M(L(0)) + sage: M(L(0)) # optional - sage.modules 0 - sage: N(L(0)) + sage: N(L(0)) # optional - sage.modules 0 - sage: L(M(0)) + sage: L(M(0)) # optional - sage.modules 0 - sage: L(N(0)) + sage: L(N(0)) # optional - sage.modules 0 :: @@ -504,8 +507,8 @@ def _element_constructor_(self, x): sage: C. = LaurentPolynomialRing(B) sage: B(C(b)) b - sage: D. = LaurentPolynomialRing(B) - sage: B(D(b)) + sage: D. = LaurentPolynomialRing(B) # optional - sage.modules + sage: B(D(b)) # optional - sage.modules b TESTS: @@ -574,11 +577,11 @@ def __init__(self, R): """ EXAMPLES:: - sage: L = LaurentPolynomialRing(QQ,2,'x') - sage: type(L) + sage: L = LaurentPolynomialRing(QQ,2,'x') # optional - sage.modules + sage: type(L) # optional - sage.modules - sage: L == loads(dumps(L)) + sage: L == loads(dumps(L)) # optional - sage.modules True """ if R.ngens() <= 0: @@ -593,9 +596,9 @@ def _repr_(self): """ TESTS:: - sage: LaurentPolynomialRing(QQ,2,'x').__repr__() + sage: LaurentPolynomialRing(QQ,2,'x').__repr__() # optional - sage.modules 'Multivariate Laurent Polynomial Ring in x0, x1 over Rational Field' - sage: LaurentPolynomialRing(QQ,1,'x').__repr__() + sage: LaurentPolynomialRing(QQ,1,'x').__repr__() # optional - sage.modules 'Multivariate Laurent Polynomial Ring in x over Rational Field' """ return "Multivariate Laurent Polynomial Ring in %s over %s"%(", ".join(self._R.variable_names()), self._R.base_ring()) @@ -606,21 +609,21 @@ def monomial(self, *args): EXAMPLES:: - sage: L = LaurentPolynomialRing(QQ, 'x', 2) - sage: L.monomial(-3, 5) + sage: L = LaurentPolynomialRing(QQ, 'x', 2) # optional - sage.modules + sage: L.monomial(-3, 5) # optional - sage.modules x0^-3*x1^5 - sage: L.monomial(1, 1) + sage: L.monomial(1, 1) # optional - sage.modules x0*x1 - sage: L.monomial(0, 0) + sage: L.monomial(0, 0) # optional - sage.modules 1 - sage: L.monomial(-2, -3) + sage: L.monomial(-2, -3) # optional - sage.modules x0^-2*x1^-3 - sage: x0, x1 = L.gens() - sage: L.monomial(-1, 2) == x0^-1 * x1^2 + sage: x0, x1 = L.gens() # optional - sage.modules + sage: L.monomial(-1, 2) == x0^-1 * x1^2 # optional - sage.modules True - sage: L.monomial(1, 2, 3) + sage: L.monomial(1, 2, 3) # optional - sage.modules Traceback (most recent call last): ... TypeError: tuple key must have same length as ngens @@ -636,96 +639,96 @@ def _element_constructor_(self, x, mon=None): """ EXAMPLES:: - sage: L = LaurentPolynomialRing(QQ,2,'x') - sage: L(1/2) + sage: L = LaurentPolynomialRing(QQ,2,'x') # optional - sage.modules + sage: L(1/2) # optional - sage.modules 1/2 - sage: M = LaurentPolynomialRing(QQ, 'x, y') - sage: var('x, y') + sage: M = LaurentPolynomialRing(QQ, 'x, y') # optional - sage.modules + sage: var('x, y') # optional - sage.modules (x, y) - sage: M(x/y + 3/x) + sage: M(x/y + 3/x) # optional - sage.modules x*y^-1 + 3*x^-1 :: - sage: M(exp(x)) + sage: M(exp(x)) # optional - sage.modules Traceback (most recent call last): ... TypeError: unable to convert e^x to a rational :: - sage: L. = LaurentPolynomialRing(QQ) - sage: M = LaurentPolynomialRing(QQ, 'c, d') - sage: Mc, Md = M.gens() - sage: N = LaurentPolynomialRing(M, 'a, b') - sage: Na, Nb = N.gens() - sage: M(c/d) + sage: L. = LaurentPolynomialRing(QQ) # optional - sage.modules + sage: M = LaurentPolynomialRing(QQ, 'c, d') # optional - sage.modules + sage: Mc, Md = M.gens() # optional - sage.modules + sage: N = LaurentPolynomialRing(M, 'a, b') # optional - sage.modules + sage: Na, Nb = N.gens() # optional - sage.modules + sage: M(c/d) # optional - sage.modules c*d^-1 - sage: N(a*b/c/d) + sage: N(a*b/c/d) # optional - sage.modules (c^-1*d^-1)*a*b - sage: N(c/d) + sage: N(c/d) # optional - sage.modules c*d^-1 - sage: L(Mc) + sage: L(Mc) # optional - sage.modules c - sage: L(Nb) + sage: L(Nb) # optional - sage.modules b - sage: M(L(0)) + sage: M(L(0)) # optional - sage.modules 0 - sage: N(L(0)) + sage: N(L(0)) # optional - sage.modules 0 - sage: L(M(0)) + sage: L(M(0)) # optional - sage.modules 0 - sage: L(N(0)) + sage: L(N(0)) # optional - sage.modules 0 sage: U = LaurentPolynomialRing(QQ, 'a') sage: Ua = U.gen() sage: V = LaurentPolynomialRing(QQ, 'c') sage: Vc = V.gen() - sage: L(Ua) + sage: L(Ua) # optional - sage.modules a - sage: L(Vc) + sage: L(Vc) # optional - sage.modules c - sage: N(Ua) + sage: N(Ua) # optional - sage.modules a - sage: M(Vc) + sage: M(Vc) # optional - sage.modules c - sage: P = LaurentPolynomialRing(QQ, 'a, b') - sage: Q = LaurentPolynomialRing(P, 'c, d') - sage: Q(P.0) + sage: P = LaurentPolynomialRing(QQ, 'a, b') # optional - sage.modules + sage: Q = LaurentPolynomialRing(P, 'c, d') # optional - sage.modules + sage: Q(P.0) # optional - sage.modules a :: sage: A. = LaurentPolynomialRing(QQ) sage: B. = LaurentPolynomialRing(A) - sage: C = LaurentPolynomialRing(QQ, 'a, b') - sage: C(B({1: a})) + sage: C = LaurentPolynomialRing(QQ, 'a, b') # optional - sage.modules + sage: C(B({1: a})) # optional - sage.modules a*b - sage: D. = LaurentPolynomialRing(B) - sage: F. = LaurentPolynomialRing(D) - sage: D(F(d*e)) + sage: D. = LaurentPolynomialRing(B) # optional - sage.modules + sage: F. = LaurentPolynomialRing(D) # optional - sage.modules + sage: D(F(d*e)) # optional - sage.modules d*e :: sage: from sage.rings.polynomial.polydict import ETuple - sage: R. = LaurentPolynomialRing(QQ) - sage: mon = ETuple({}, int(3)) - sage: P = R.polynomial_ring() - sage: R(sum(P.gens()), mon) + sage: R. = LaurentPolynomialRing(QQ) # optional - sage.modules + sage: mon = ETuple({}, int(3)) # optional - sage.modules + sage: P = R.polynomial_ring() # optional - sage.modules + sage: R(sum(P.gens()), mon) # optional - sage.modules x + y + z - sage: R(sum(P.gens()), (-1,-1,-1)) + sage: R(sum(P.gens()), (-1,-1,-1)) # optional - sage.modules y^-1*z^-1 + x^-1*z^-1 + x^-1*y^-1 :: - sage: RL = R.localization(x+1) - sage: xi = RL(~x) - sage: R(xi) == ~x # indirect doctests + sage: RL = R.localization(x+1) # optional - sage.modules + sage: xi = RL(~x) # optional - sage.modules + sage: R(xi) == ~x # indirect doctests # optional - sage.modules True """ from sage.structure.element import Expression @@ -782,8 +785,8 @@ def __reduce__(self): EXAMPLES:: - sage: L = LaurentPolynomialRing(QQ, 2, 'x') - sage: loads(dumps(L)) == L + sage: L = LaurentPolynomialRing(QQ, 2, 'x') # optional - sage.modules + sage: loads(dumps(L)) == L # optional - sage.modules True """ return LaurentPolynomialRing_mpair, (self._R,) diff --git a/src/sage/rings/power_series_ring_element.pyx b/src/sage/rings/power_series_ring_element.pyx index 2422521fba8..cfac856258a 100644 --- a/src/sage/rings/power_series_ring_element.pyx +++ b/src/sage/rings/power_series_ring_element.pyx @@ -1416,7 +1416,7 @@ cdef class PowerSeries(AlgebraElement): Another example:: - sage: (exp(t)).stieltjes_continued_fraction() + sage: (exp(t)).stieltjes_continued_fraction() # optional - sage.symbolic (1, -1/2, 1/6, @@ -1866,7 +1866,7 @@ cdef class PowerSeries(AlgebraElement): one raises an error:: sage: g = 2+f - sage: cos(g) + sage: cos(g) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only apply cos to formal power series with zero constant term @@ -1951,7 +1951,7 @@ cdef class PowerSeries(AlgebraElement): one raises an error:: sage: g = 2+f - sage: sin(g) + sage: sin(g) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only apply sin to formal power series with zero constant term From 986e3b8a65d4b796df36868ffe21be053923039d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 23 Apr 2023 22:20:43 -0700 Subject: [PATCH 21/98] src/sage/combinat/root_system/root_lattice_realization_algebras.py: Update doctest output --- .../combinat/root_system/root_lattice_realization_algebras.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/combinat/root_system/root_lattice_realization_algebras.py b/src/sage/combinat/root_system/root_lattice_realization_algebras.py index 3e70a2e8fd9..71059e21548 100644 --- a/src/sage/combinat/root_system/root_lattice_realization_algebras.py +++ b/src/sage/combinat/root_system/root_lattice_realization_algebras.py @@ -1166,13 +1166,13 @@ def expand(self, alphabet): TESTS:: sage: type(p.expand(F.gens())) - + sage: p = KL.zero() sage: p.expand(F.gens()) 0 sage: type(p.expand(F.gens())) - + """ codomain = alphabet[0].parent() return codomain.sum(c * prod(X**int(n) From d77f384ee897d72511a11f80eb9004ce7506823f Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Tue, 25 Apr 2023 11:12:39 +0900 Subject: [PATCH 22/98] Edit ore polynomials --- .../polynomial/ore_polynomial_element.pyx | 132 +++++++++--------- 1 file changed, 65 insertions(+), 67 deletions(-) diff --git a/src/sage/rings/polynomial/ore_polynomial_element.pyx b/src/sage/rings/polynomial/ore_polynomial_element.pyx index 4db1a1652ff..9dc505736d5 100644 --- a/src/sage/rings/polynomial/ore_polynomial_element.pyx +++ b/src/sage/rings/polynomial/ore_polynomial_element.pyx @@ -13,7 +13,7 @@ The generic implementation of dense Ore polynomials is The classes :class:`~sage.rings.polynomial.ore_polynomial_element.ConstantOrePolynomialSection` and :class:`~sage.rings.polynomial.ore_polynomial_element.OrePolynomialBaseringInjection` -handle conversion from a Ore polynomial ring to its base ring and vice versa. +handle conversion from an Ore polynomial ring to its base ring and vice versa. AUTHORS: @@ -61,7 +61,7 @@ cdef class OrePolynomial(AlgebraElement): Let `R` be a commutative ring equipped with an automorphism `\sigma` and a `\sigma`-derivation `\partial`. - A Ore polynomial is given by the equation: + An Ore polynomial is given by the equation: .. MATH:: @@ -76,23 +76,23 @@ cdef class OrePolynomial(AlgebraElement): is equal to the sum of the degrees of the factors. Let `a` and `b` be two Ore polynomials in the same ring `S`. - The *left (resp. right) euclidean division* of `a` by `b` is a couple + The *right (resp. left) Euclidean division* of `a` by `b` is a couple `(q,r)` of elements in `S` such that - - `a = q b + r` (resp. `a = b q + r`) + - `a = q b + r` (resp. `a = b q + r`) - - the degree of `r` is less than the degree of `b` + - the degree of `r` is less than the degree of `b` `q` (resp. `r`) is called the *quotient* (resp. the remainder) - of this euclidean division. + of this Euclidean division. .. RUBRIC:: Properties Keeping the previous notation, if the leading coefficient of `b` is a unit (e.g. if `b` is monic) then the quotient and the remainder - in the *right* euclidean division exist and are unique. + in the *right* Euclidean division exist and are unique. - The same result holds for the *left* euclidean division if in addition + The same result holds for the *left* Euclidean division if in addition the twisting morphism defining the Ore polynomial ring is invertible. EXAMPLES: @@ -145,7 +145,7 @@ cdef class OrePolynomial(AlgebraElement): True The operators ``//`` and ``%`` give respectively the quotient - and the remainder of the *right* euclidean division:: + and the remainder of the *right* Euclidean division:: sage: q == c // b True @@ -177,7 +177,7 @@ cdef class OrePolynomial(AlgebraElement): sage: a == b*q + r True - Once we have euclidean divisions, we have for free gcd and lcm + Once we have Euclidean divisions, we have for free gcd and lcm (at least if the base ring is a field):: sage: a = (x + t) * (x + t^2)^2 @@ -348,7 +348,7 @@ cdef class OrePolynomial(AlgebraElement): def constant_coefficient(self): r""" - Return the constant coefficient (i.e. the coefficient of term + Return the constant coefficient (i.e., the coefficient of term of degree `0`) of ``self``. EXAMPLES:: @@ -393,7 +393,7 @@ cdef class OrePolynomial(AlgebraElement): r""" Return ``True`` if this Ore polynomial is a unit. - When the base ring `R` is an integral domain, then a Ore polynomial `f` + When the base ring `R` is an integral domain, then an Ore polynomial `f` is a unit if and only if degree of `f` is `0` and `f` is then a unit in `R`. @@ -478,7 +478,7 @@ cdef class OrePolynomial(AlgebraElement): Return the unique monic Ore polynomial `m` which divides this polynomial on the left and has the same degree. - Given a Ore polynomial `P` of degree `n`, its left monic is given by + Given an Ore polynomial `P` of degree `n`, its left monic is given by `P \cdot \sigma^{-n}(1/k)`, where `k` is the leading coefficient of `P` and `\sigma` is the twisting morphism. @@ -495,7 +495,7 @@ cdef class OrePolynomial(AlgebraElement): sage: b.degree() == a.degree() True - sage: b.is_left_divisible_by(a) + sage: a.is_left_divisible_by(b) True sage: twist = S.twisting_morphism(-a.degree()) sage: a == b * twist(a.leading_coefficient()) @@ -532,8 +532,8 @@ cdef class OrePolynomial(AlgebraElement): Return the unique monic Ore polynomial which divides this polynomial on the right and has the same degree. - Given a Ore polynomial `P` of degree `n`, its left monic is given by - `(1/k) \cdot P`, where `k` is the leading coefficient of `p`. + Given an Ore polynomial `P` of degree `n`, its right monic is given by + `(1/k) \cdot P`, where `k` is the leading coefficient of `P`. EXAMPLES:: @@ -548,7 +548,7 @@ cdef class OrePolynomial(AlgebraElement): sage: b.degree() == a.degree() True - sage: b.is_right_divisible_by(a) + sage: a.is_right_divisible_by(b) True sage: a == a.leading_coefficient() * b True @@ -578,7 +578,7 @@ cdef class OrePolynomial(AlgebraElement): cpdef _mod_(self, other): r""" - Return the remainder in the *right* euclidean division of + Return the remainder in the *right* Euclidean division of ``self`` by ``other```. TESTS:: @@ -600,7 +600,7 @@ cdef class OrePolynomial(AlgebraElement): cpdef _floordiv_(self, right): r""" - Return the quotient of the *right* euclidean division of + Return the quotient of the *right* Euclidean division of ``self`` by ``right``. The algorithm fails if the leading coefficient of the divisor @@ -631,7 +631,7 @@ cdef class OrePolynomial(AlgebraElement): INPUT: - - ``right`` -- a Ore polynomial + - ``right`` -- an Ore polynomial EXAMPLES:: @@ -653,7 +653,7 @@ cdef class OrePolynomial(AlgebraElement): INPUT: - - ``other`` -- a Ore polynomial in the same ring as ``self`` + - ``other`` -- an Ore polynomial in the same ring as ``self`` OUTPUT: @@ -688,7 +688,7 @@ cdef class OrePolynomial(AlgebraElement): INPUT: - - ``other`` -- a Ore polynomial in the same ring as ``self`` + - ``other`` -- an Ore polynomial in the same ring as ``self`` OUTPUT: @@ -737,7 +737,7 @@ cdef class OrePolynomial(AlgebraElement): INPUT: - - ``other`` -- a Ore polynomial in the same ring as ``self`` + - ``other`` -- an Ore polynomial in the same ring as ``self`` OUTPUT: @@ -750,7 +750,7 @@ cdef class OrePolynomial(AlgebraElement): sage: S. = k['x',Frob] sage: a = x^2 + t*x + t^2 + 3 sage: b = x^3 + (t + 1)*x^2 + 1 - sage: c = a*b + sage: c = a * b sage: a.left_divides(c) True sage: b.left_divides(c) @@ -772,7 +772,7 @@ cdef class OrePolynomial(AlgebraElement): INPUT: - - ``other`` -- a Ore polynomial in the same ring as ``self`` + - ``other`` -- an Ore polynomial in the same ring as ``self`` OUTPUT: @@ -785,7 +785,7 @@ cdef class OrePolynomial(AlgebraElement): sage: S. = k['x',Frob] sage: a = x^2 + t*x + t^2 + 3 sage: b = x^3 + (t + 1)*x^2 + 1 - sage: c = a*b + sage: c = a * b sage: a.right_divides(c) False sage: b.right_divides(c) @@ -827,14 +827,14 @@ cdef class OrePolynomial(AlgebraElement): INPUT: - - ``other`` -- a Ore polynomial in the same ring as ``self`` + - ``other`` -- an Ore polynomial in the same ring as ``self`` - ``monic`` -- boolean (default: ``True``); return whether the left gcd should be normalized to be monic OUTPUT: - - The left gcd of ``self`` and ``other``, that is a Ore polynomial + - The left gcd of ``self`` and ``other``, that is an Ore polynomial `g` with the following property: any Ore polynomial is divisible on the left by `g` iff it is divisible on the left by both ``self`` and ``other``. @@ -932,7 +932,7 @@ cdef class OrePolynomial(AlgebraElement): cdef _left_quo_rem(self, OrePolynomial other): r""" - Return the quotient and remainder of the left euclidean + Return the quotient and remainder of the left Euclidean division of ``self`` by ``other`` (C implementation). Must be implemented in subclasses. @@ -942,16 +942,16 @@ cdef class OrePolynomial(AlgebraElement): @coerce_binop def left_quo_rem(self, other): r""" - Return the quotient and remainder of the left euclidean + Return the quotient and remainder of the left Euclidean division of ``self`` by ``other``. INPUT: - - ``other`` -- a Ore polynomial in the same ring as ``self`` + - ``other`` -- an Ore polynomial in the same ring as ``self`` OUTPUT: - - the quotient and the remainder of the left euclidean + - the quotient and the remainder of the left Euclidean division of this Ore polynomial by ``other`` .. NOTE:: @@ -991,7 +991,7 @@ cdef class OrePolynomial(AlgebraElement): cdef _right_quo_rem(self, OrePolynomial other): r""" - Return the quotient and remainder of the right euclidean + Return the quotient and remainder of the right Euclidean division of ``self`` by ``other`` (C implementation). Must be implemented in subclasses. @@ -1001,16 +1001,16 @@ cdef class OrePolynomial(AlgebraElement): @coerce_binop def right_quo_rem(self, other): r""" - Return the quotient and remainder of the right euclidean + Return the quotient and remainder of the right Euclidean division of ``self`` by ``other``. INPUT: - - ``other`` -- a Ore polynomial in the same ring as ``self`` + - ``other`` -- an Ore polynomial in the same ring as ``self`` OUTPUT: - - the quotient and the remainder of the left euclidean + - the quotient and the remainder of the right Euclidean division of this Ore polynomial by ``other`` .. NOTE:: @@ -1061,14 +1061,14 @@ cdef class OrePolynomial(AlgebraElement): INPUT: - - ``other`` -- a Ore polynomial in the same ring as ``self`` + - ``other`` -- an Ore polynomial in the same ring as ``self`` - ``monic`` -- boolean (default: ``True``); return whether the right gcd should be normalized to be monic OUTPUT: - - The right gcd of ``self`` and ``other``, that is a Ore polynomial + - The right gcd of ``self`` and ``other``, that is an Ore polynomial `g` with the following property: any Ore polynomial is divisible on the right by `g` iff it is divisible on the right by both ``self`` and ``other``. @@ -1152,14 +1152,14 @@ cdef class OrePolynomial(AlgebraElement): INPUT: - - ``other`` -- a Ore polynomial in the same ring as ``self`` + - ``other`` -- an Ore polynomial in the same ring as ``self`` - ``monic`` -- boolean (default: ``True``); return whether the right gcd should be normalized to be monic OUTPUT: - The right gcd of ``self`` and ``other``, that is a Ore polynomial + The right gcd of ``self`` and ``other``, that is an Ore polynomial `g` with the following property: any Ore polynomial is divisible on the right by `g` iff it is divisible on the right by both ``self`` and ``other``. @@ -1217,14 +1217,14 @@ cdef class OrePolynomial(AlgebraElement): INPUT: - - ``other`` -- a Ore polynomial in the same ring as ``self`` + - ``other`` -- an Ore polynomial in the same ring as ``self`` - ``monic`` -- boolean (default: ``True``); return whether the left gcd should be normalized to be monic OUTPUT: - The left gcd of ``self`` and ``other``, that is a Ore polynomial + The left gcd of ``self`` and ``other``, that is an Ore polynomial `g` with the following property: any Ore polynomial is divisible on the left by `g` iff it is divisible on the left by both ``self`` and ``other``. @@ -1294,7 +1294,7 @@ cdef class OrePolynomial(AlgebraElement): cdef OrePolynomial _left_lcm_cofactor(self, OrePolynomial other): r""" - Return a Ore polynomial `U` such that `U P = c L` + Return an Ore polynomial `U` such that `U P = c L` where `P` is this Ore polynomial (``self``), `L` is the left lcm of `P` and ``other`` and `c` is a constant @@ -1372,7 +1372,7 @@ cdef class OrePolynomial(AlgebraElement): cdef OrePolynomial _right_lcm_cofactor(self, OrePolynomial other): r""" - Return a Ore polynomial `U` such that `P U = L c` + Return an Ore polynomial `U` such that `P U = L c` where `P` is this Ore polynomial (``self``), `L` is the right lcm of `P` and ``other`` and `c` is a constant @@ -1422,7 +1422,7 @@ cdef class OrePolynomial(AlgebraElement): INPUT: - - ``other`` -- a Ore polynomial in the same ring as ``self`` + - ``other`` -- an Ore polynomial in the same ring as ``self`` - ``monic`` -- a boolean (default: ``True``); whether the right lcm should be normalized to be monic @@ -1463,18 +1463,17 @@ cdef class OrePolynomial(AlgebraElement): INPUT: - - ``other`` -- a Ore polynomial in the same ring as ``self`` + - ``other`` -- an Ore polynomial in the same ring as ``self`` - ``monic`` -- boolean (default: ``True``); return whether the left lcm should be normalized to be monic OUTPUT: - The left lcm of ``self`` and ``other``, that is a Ore polynomial - `g` with the following property: any Ore polynomial divides - `g` on the *right* iff it divides both ``self`` and ``other`` - on the *right*. - If monic is ``True``, `g` is in addition monic. (With this + The left lcm of ``self`` and ``other``, that is an Ore polynomial + `l` with the following property: any Ore polynomial is a left multiple of `l` (right divisible by `l`) + iff it is left multiple of both ``self`` and ``other`` (right divisible by ``self`` and ``other``). + If monic is ``True``, `l` is in addition monic. (With this extra condition, it is uniquely determined.) .. NOTE:: @@ -1498,7 +1497,7 @@ cdef class OrePolynomial(AlgebraElement): sage: a.degree() + b.degree() == c.degree() + a.right_gcd(b).degree() True - Specifying ``monic=False``, we *can* get a nonmonic gcd:: + Specifying ``monic=False``, we *can* get a nonmonic lcm:: sage: a.left_lcm(b,monic=False) (t^2 + t)*x^5 + (4*t^2 + 4*t + 1)*x^4 + (t + 1)*x^3 + (t^2 + 2)*x^2 + (3*t + 4)*x @@ -1531,17 +1530,16 @@ cdef class OrePolynomial(AlgebraElement): INPUT: - - ``other`` -- a Ore polynomial in the same ring as ``self`` + - ``other`` -- an Ore polynomial in the same ring as ``self`` - ``monic`` -- boolean (default: ``True``); return whether the right lcm should be normalized to be monic OUTPUT: - The right lcm of ``self`` and ``other``, that is a Ore polynomial - `g` with the following property: any Ore polynomial divides - `g` on the *left* iff it divides both ``self`` and ``other`` - on the *left*. + The right lcm of ``self`` and ``other``, that is an Ore polynomial + `l` with the following property: any Ore polynomial is a right multiple of `g` (left divisible by `l`) + iff it is a right multiple of both ``self`` and ``other`` (left divisible by ``self`` and ``other``). If monic is ``True``, `g` is in addition monic. (With this extra condition, it is uniquely determined.) @@ -2173,7 +2171,7 @@ cdef class OrePolynomial(AlgebraElement): cdef void lmul_gen(list A, Morphism m, d): r""" - If ``A`` is the list of coefficients of a Ore polynomial ``P``, + If ``A`` is the list of coefficients of an Ore polynomial ``P``, replace it by the list of coefficients of ``X*P`` (where ``X`` is the variable in the Ore polynomial ring). @@ -2205,7 +2203,7 @@ cdef class OrePolynomial_generic_dense(OrePolynomial): """ def __init__(self, parent, x=None, int check=1, int construct=0, **kwds): r""" - Construct a Ore polynomial over the given parent with the given + Construct an Ore polynomial over the given parent with the given coefficients. INPUT: @@ -2224,7 +2222,7 @@ cdef class OrePolynomial_generic_dense(OrePolynomial): sage: sigma = R.hom([t+1]) sage: S. = R['x',sigma] - We create a Ore polynomial from a list:: + We create an Ore polynomial from a list:: sage: S([t,1]) x + t @@ -2716,7 +2714,7 @@ cdef class OrePolynomial_generic_dense(OrePolynomial): INPUT: - - ``right`` -- a Ore polynomial in the same ring as ``self`` + - ``right`` -- an Ore polynomial in the same ring as ``self`` EXAMPLES:: @@ -2751,7 +2749,7 @@ cdef class OrePolynomial_generic_dense(OrePolynomial): cdef _left_quo_rem(self, OrePolynomial other): r""" - Return the quotient and remainder of the left euclidean + Return the quotient and remainder of the left Euclidean division of ``self`` by ``other`` (C implementation). """ sig_check() @@ -2780,7 +2778,7 @@ cdef class OrePolynomial_generic_dense(OrePolynomial): cdef _right_quo_rem(self, OrePolynomial other): r""" - Return the quotient and remainder of the right euclidean + Return the quotient and remainder of the right Euclidean division of ``self`` by ``other`` (C implementation). """ sig_check() @@ -2932,7 +2930,7 @@ cdef class OrePolynomial_generic_dense(OrePolynomial): cdef class ConstantOrePolynomialSection(Map): r""" - Representation of the canonical homomorphism from the constants of a Ore + Representation of the canonical homomorphism from the constants of an Ore polynomial ring to the base ring. This class is necessary for automatic coercion from zero-degree Ore @@ -2984,7 +2982,7 @@ cdef class ConstantOrePolynomialSection(Map): cdef class OrePolynomialBaseringInjection(Morphism): r""" - Representation of the canonical homomorphism from a ring `R` into a Ore + Representation of the canonical homomorphism from a ring `R` into an Ore polynomial ring over `R`. This class is necessary for automatic coercion from the base ring to the Ore @@ -3012,7 +3010,7 @@ cdef class OrePolynomialBaseringInjection(Morphism): - ``domain`` -- a ring `R`. This will be the domain of the injection. - - ``codomain`` -- a Ore polynomial ring over ``domain``. This will be + - ``codomain`` -- an Ore polynomial ring over ``domain``. This will be the codomain. TESTS:: @@ -3086,7 +3084,7 @@ cdef class OrePolynomialBaseringInjection(Morphism): def section(self): r""" - Return the canonical homomorphism from the constants of a Ore + Return the canonical homomorphism from the constants of an Ore polynomial ring to the base ring according to ``self``. TESTS:: From 5d277167649309303a0c6664573d6405b6d3a02f Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Tue, 25 Apr 2023 12:40:17 +0900 Subject: [PATCH 23/98] Some more edits --- .../rings/polynomial/ore_polynomial_element.pyx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sage/rings/polynomial/ore_polynomial_element.pyx b/src/sage/rings/polynomial/ore_polynomial_element.pyx index 9dc505736d5..db75480bbc0 100644 --- a/src/sage/rings/polynomial/ore_polynomial_element.pyx +++ b/src/sage/rings/polynomial/ore_polynomial_element.pyx @@ -845,7 +845,7 @@ cdef class OrePolynomial(AlgebraElement): .. MATH:: - g = a * u + b * v, + g = a \cdot u + b \cdot v, where `s` is ``self`` and `b` is ``other``. @@ -1079,7 +1079,7 @@ cdef class OrePolynomial(AlgebraElement): .. MATH:: - g = u * a + v * b + g = u \cdot a + v \cdot b where `a` is ``self`` and `b` is ``other``. @@ -1353,9 +1353,9 @@ cdef class OrePolynomial(AlgebraElement): sage: L x^5 + (2*t^2 + t + 4)*x^4 + (3*t^2 + 4)*x^3 + (3*t^2 + 3*t + 2)*x^2 + (t^2 + t + 2)*x - sage: U*P == L + sage: U * P == L True - sage: V*Q == L + sage: V * Q == L True """ if self.base_ring() not in _Fields: @@ -1437,9 +1437,9 @@ cdef class OrePolynomial(AlgebraElement): sage: L, U, V = P.right_xlcm(Q) sage: L x^4 + (2*t^2 + t + 2)*x^3 + (3*t^2 + 4*t + 1)*x^2 + (3*t^2 + 4*t + 1)*x + t^2 + 4 - sage: P*U == L + sage: P * U == L True - sage: Q*V == L + sage: Q * V == L True """ if self.base_ring() not in _Fields: @@ -1472,7 +1472,7 @@ cdef class OrePolynomial(AlgebraElement): The left lcm of ``self`` and ``other``, that is an Ore polynomial `l` with the following property: any Ore polynomial is a left multiple of `l` (right divisible by `l`) - iff it is left multiple of both ``self`` and ``other`` (right divisible by ``self`` and ``other``). + iff it is a left multiple of both ``self`` and ``other`` (right divisible by ``self`` and ``other``). If monic is ``True``, `l` is in addition monic. (With this extra condition, it is uniquely determined.) From 99b2a442e8fa0f04518acf5b6a8facfd209e9073 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 17 May 2023 16:43:04 -0700 Subject: [PATCH 24/98] Remove abuse of predefined x in doctests --- .../n2_lie_conformal_algebra.py | 3 +- .../algebras/quatalg/quaternion_algebra.py | 5 +- .../quatalg/quaternion_algebra_element.pyx | 3 + src/sage/arith/misc.py | 16 +- src/sage/calculus/wester.py | 1 + src/sage/cpython/getattr.pyx | 3 +- .../hyperplane_arrangement/arrangement.py | 8 +- src/sage/geometry/polyhedron/backend_field.py | 12 +- .../polyhedron/backend_number_field.py | 11 +- src/sage/geometry/polyhedron/constructor.py | 20 +- src/sage/geometry/polyhedron/parent.py | 10 +- .../geometry/polyhedron/representation.py | 7 +- .../additive_abelian_wrapper.py | 7 +- src/sage/groups/galois_group.py | 3 + .../libs/linkages/padics/unram_shared.pxi | 1 + src/sage/libs/singular/singular.pyx | 4 +- src/sage/matrix/matrix1.pyx | 7 +- src/sage/matrix/matrix2.pyx | 94 ++++--- src/sage/matrix/matrix_space.py | 7 +- src/sage/matrix/matrix_sparse.pyx | 1 + src/sage/matrix/special.py | 4 +- src/sage/misc/functional.py | 10 +- src/sage/misc/sage_input.py | 6 +- .../modular/arithgroup/arithgroup_element.pyx | 1 + .../modular/arithgroup/congroup_gamma1.py | 1 + src/sage/modular/cusps_nf.py | 45 +++- src/sage/modular/modsym/p1list_nf.py | 34 +++ src/sage/modular/overconvergent/genus0.py | 26 +- src/sage/modules/free_module.py | 1 + src/sage/modules/free_module_integer.py | 9 +- src/sage/modules/matrix_morphism.py | 7 +- src/sage/quadratic_forms/quadratic_form.py | 1 + .../quadratic_form__equivalence_testing.py | 1 + .../quadratic_form__local_field_invariants.py | 2 + src/sage/rings/abc.pyx | 5 +- src/sage/rings/complex_arb.pyx | 6 +- src/sage/rings/complex_mpfr.pyx | 4 +- src/sage/rings/continued_fraction.py | 30 ++- src/sage/rings/finite_rings/integer_mod.pyx | 2 +- src/sage/rings/finite_rings/residue_field.pyx | 26 ++ .../finite_rings/residue_field_pari_ffelt.pyx | 5 +- src/sage/rings/function_field/valuation.py | 1 + src/sage/rings/ideal.py | 6 +- src/sage/rings/integer.pyx | 3 +- src/sage/rings/integer_ring.pyx | 3 +- src/sage/rings/morphism.pyx | 9 +- .../rings/multi_power_series_ring_element.py | 10 +- src/sage/rings/number_field/S_unit_solver.py | 75 ++++-- src/sage/rings/number_field/bdd_height.py | 4 + src/sage/rings/number_field/class_group.py | 62 +++-- src/sage/rings/number_field/galois_group.py | 56 +++- src/sage/rings/number_field/homset.py | 10 + src/sage/rings/number_field/maps.py | 51 +++- src/sage/rings/number_field/morphism.py | 21 +- src/sage/rings/number_field/number_field.py | 246 ++++++++++++++---- .../number_field/number_field_element.pyx | 143 ++++++++-- .../number_field_element_base.pyx | 5 +- .../number_field_element_quadratic.pyx | 105 +++++--- .../number_field/number_field_ideal_rel.py | 36 ++- .../number_field/number_field_morphisms.pyx | 26 +- .../rings/number_field/number_field_rel.py | 80 +++++- src/sage/rings/number_field/order.py | 89 ++++++- src/sage/rings/number_field/selmer_group.py | 4 + src/sage/rings/number_field/structure.py | 6 +- .../rings/number_field/totallyreal_rel.py | 3 +- .../padics/eisenstein_extension_generic.py | 2 + src/sage/rings/padics/morphism.pyx | 1 + src/sage/rings/padics/padic_ZZ_pX_element.pyx | 3 +- src/sage/rings/padics/padic_ext_element.pyx | 1 + .../rings/padics/padic_extension_generic.py | 4 +- .../rings/padics/padic_generic_element.pyx | 4 + src/sage/rings/padics/padic_valuation.py | 2 + .../padics/unramified_extension_generic.py | 2 + src/sage/rings/polynomial/flatten.py | 5 +- .../polynomial/multi_polynomial_element.py | 18 +- .../multi_polynomial_libsingular.pyx | 52 ++-- .../rings/polynomial/polynomial_element.pyx | 171 ++++++------ .../polynomial/polynomial_number_field.pyx | 49 ++-- .../polynomial/polynomial_quotient_ring.py | 86 +++--- .../polynomial_singular_interface.py | 12 +- src/sage/rings/qqbar.py | 14 +- src/sage/rings/rational.pyx | 8 +- src/sage/rings/rational_field.py | 3 +- src/sage/rings/real_arb.pyx | 2 +- src/sage/rings/real_double.pyx | 2 +- src/sage/rings/real_lazy.pyx | 3 +- src/sage/rings/ring.pyx | 48 ++-- src/sage/rings/ring_extension.pyx | 15 ++ src/sage/rings/ring_extension_element.pyx | 4 + src/sage/rings/ring_extension_morphism.pyx | 4 + src/sage/rings/tate_algebra.py | 5 +- src/sage/rings/tate_algebra_element.pyx | 2 + src/sage/schemes/elliptic_curves/cm.py | 3 + .../elliptic_curves/ell_curve_isogeny.py | 2 + src/sage/schemes/elliptic_curves/ell_field.py | 5 +- .../schemes/elliptic_curves/ell_generic.py | 4 + .../schemes/elliptic_curves/ell_local_data.py | 17 +- .../elliptic_curves/ell_number_field.py | 22 +- src/sage/schemes/elliptic_curves/ell_point.py | 7 + .../schemes/elliptic_curves/ell_torsion.py | 7 +- .../elliptic_curves/gal_reps_number_field.py | 20 ++ src/sage/schemes/elliptic_curves/height.py | 6 + src/sage/schemes/elliptic_curves/hom.py | 1 + .../schemes/elliptic_curves/hom_composite.py | 2 + .../elliptic_curves/isogeny_small_degree.py | 4 + src/sage/schemes/elliptic_curves/kraus.py | 42 ++- .../modular_parametrization.py | 5 +- .../schemes/elliptic_curves/period_lattice.py | 17 ++ src/sage/schemes/generic/homset.py | 1 + .../schemes/hyperelliptic_curves/mestre.py | 1 + .../schemes/projective/proj_bdd_height.py | 1 + .../schemes/projective/projective_homset.py | 9 +- src/sage/structure/coerce.pyx | 5 +- src/sage/structure/element.pyx | 5 +- src/sage/structure/factorization.py | 9 +- src/sage/structure/nonexact.py | 1 + src/sage/structure/parent.pyx | 22 +- src/sage/structure/sage_object.pyx | 1 + 118 files changed, 1632 insertions(+), 612 deletions(-) diff --git a/src/sage/algebras/lie_conformal_algebras/n2_lie_conformal_algebra.py b/src/sage/algebras/lie_conformal_algebras/n2_lie_conformal_algebra.py index 23af0d3f7dd..045bfb6e57a 100644 --- a/src/sage/algebras/lie_conformal_algebras/n2_lie_conformal_algebra.py +++ b/src/sage/algebras/lie_conformal_algebras/n2_lie_conformal_algebra.py @@ -43,7 +43,8 @@ class N2LieConformalAlgebra(GradedLieConformalAlgebra): EXAMPLES:: - sage: F. = NumberField(x^2 -2) + sage: x = polygen(ZZ, 'x') + sage: F. = NumberField(x^2 - 2) sage: R = lie_conformal_algebras.N2(F); R The N=2 super Lie conformal algebra over Number Field in x with defining polynomial x^2 - 2 sage: R.inject_variables() diff --git a/src/sage/algebras/quatalg/quaternion_algebra.py b/src/sage/algebras/quatalg/quaternion_algebra.py index 3310b4f026d..77dcfe4db43 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra.py +++ b/src/sage/algebras/quatalg/quaternion_algebra.py @@ -1031,8 +1031,9 @@ def discriminant(self): sage: QuaternionAlgebra(19).discriminant() 19 - sage: F. = NumberField(x^2-x-1) - sage: B. = QuaternionAlgebra(F, 2*a,F(-1)) + sage: x = polygen(ZZ, 'x') + sage: F. = NumberField(x^2 - x - 1) + sage: B. = QuaternionAlgebra(F, 2*a, F(-1)) sage: B.discriminant() Fractional ideal (2) diff --git a/src/sage/algebras/quatalg/quaternion_algebra_element.pyx b/src/sage/algebras/quatalg/quaternion_algebra_element.pyx index b2da19d4c80..0f029344091 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra_element.pyx +++ b/src/sage/algebras/quatalg/quaternion_algebra_element.pyx @@ -515,6 +515,7 @@ cdef class QuaternionAlgebraElement_abstract(AlgebraElement): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2-x-1); Q. = QuaternionAlgebra(K,-1,-1); z=2*i+3*j+4/3*k+5/8 sage: a*z 5/8*a + 2*a*i + 3*a*j + 4/3*a*k @@ -529,6 +530,7 @@ cdef class QuaternionAlgebraElement_abstract(AlgebraElement): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2-x-1); Q. = QuaternionAlgebra(K,-1,-1); z=2*i+3*j+4/3*k+5/8 sage: z*a 5/8*a + 2*a*i + 3*a*j + 4/3*a*k @@ -1806,6 +1808,7 @@ cdef class QuaternionAlgebraElement_number_field(QuaternionAlgebraElement_abstra Check that the fix in :trac:`17099` is correct:: + sage: x = polygen(QQ, 'x') sage: K = NumberField(x**3 + x - 1, 'a') sage: D. = QuaternionAlgebra(K, -1, -3) sage: j/3 + (2*j)/3 == j diff --git a/src/sage/arith/misc.py b/src/sage/arith/misc.py index 9c671105c5a..d3b5d164054 100644 --- a/src/sage/arith/misc.py +++ b/src/sage/arith/misc.py @@ -543,8 +543,9 @@ def is_prime(n): However, number fields redefine ``.is_prime()`` in an incompatible fashion (cf. :trac:`32340`) and we should not warn:: - sage: K. = NumberField(x^2+1) - sage: is_prime(1+i) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: is_prime(1 + i) # optional - sage.rings.number_field True """ try: @@ -3346,11 +3347,12 @@ def crt(a, b, m=None, n=None): Note that this also works for polynomial rings:: - sage: K. = NumberField(x^3 - 7) - sage: R. = K[] - sage: f = y^2 + 3 - sage: g = y^3 - 5 - sage: CRT(1,3,f,g) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 7) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: f = y^2 + 3 # optional - sage.rings.number_field + sage: g = y^3 - 5 # optional - sage.rings.number_field + sage: CRT(1, 3, f, g) # optional - sage.rings.number_field -3/26*y^4 + 5/26*y^3 + 15/26*y + 53/26 sage: CRT(1,a,f,g) (-3/52*a + 3/52)*y^4 + (5/52*a - 5/52)*y^3 + (15/52*a - 15/52)*y + 27/52*a + 25/52 diff --git a/src/sage/calculus/wester.py b/src/sage/calculus/wester.py index 0a2a374cd5f..a352df844da 100644 --- a/src/sage/calculus/wester.py +++ b/src/sage/calculus/wester.py @@ -168,6 +168,7 @@ :: sage: # (YES) Factorize x^4-3*x^2+1 in the field of rational numbers extended by roots of x^2-x-1. + sage: x = polygen(ZZ, 'x') sage: k.< a> = NumberField(x^2 - x -1) sage: R.< y> = k[] sage: f = y^4 - 3*y^2 + 1 diff --git a/src/sage/cpython/getattr.pyx b/src/sage/cpython/getattr.pyx index 0eabdfd36ab..c670cb22d13 100644 --- a/src/sage/cpython/getattr.pyx +++ b/src/sage/cpython/getattr.pyx @@ -54,7 +54,8 @@ cdef class AttributeErrorMessage: Traceback (most recent call last): ... AttributeError: 'sage.rings.integer.Integer' object has no attribute 'bla' - sage: QQ[x].gen().bla + sage: x = polygen(ZZ, 'x') + sage: QQ[x].gen().bla # optional - sage.libs.flint Traceback (most recent call last): ... AttributeError: 'sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint' object has no attribute 'bla' diff --git a/src/sage/geometry/hyperplane_arrangement/arrangement.py b/src/sage/geometry/hyperplane_arrangement/arrangement.py index b740ef79956..091938f5256 100644 --- a/src/sage/geometry/hyperplane_arrangement/arrangement.py +++ b/src/sage/geometry/hyperplane_arrangement/arrangement.py @@ -66,10 +66,10 @@ Number fields are also possible:: - sage: x = var('x') - sage: NF. = NumberField(x**4 - 5*x**2 + 5, embedding=1.90) # optional - sage.rings.number_field - sage: H. = HyperplaneArrangements(NF) # optional - sage.rings.number_field - sage: A = H([[(-a**3 + 3*a, -a**2 + 4), 1], [(a**3 - 4*a, -1), 1], # optional - sage.rings.number_field + sage: x = polygen(QQ, 'x') + sage: NF. = NumberField(x**4 - 5*x**2 + 5, embedding=1.90) # optional - sage.rings.number_field + sage: H. = HyperplaneArrangements(NF) # optional - sage.rings.number_field + sage: A = H([[(-a**3 + 3*a, -a**2 + 4), 1], [(a**3 - 4*a, -1), 1], # optional - sage.rings.number_field ....: [(0, 2*a**2 - 6), 1], [(-a**3 + 4*a, -1), 1], ....: [(a**3 - 3*a, -a**2 + 4), 1]]) sage: A # optional - sage.rings.number_field diff --git a/src/sage/geometry/polyhedron/backend_field.py b/src/sage/geometry/polyhedron/backend_field.py index 2183b0a92b6..4e190c09cda 100644 --- a/src/sage/geometry/polyhedron/backend_field.py +++ b/src/sage/geometry/polyhedron/backend_field.py @@ -58,11 +58,13 @@ class Polyhedron_field(Polyhedron_base): Check that :trac:`19013` is fixed:: - sage: K. = NumberField(x^2-x-1, embedding=1.618) # optional - sage.rings.number_field - sage: P1 = Polyhedron([[0,1],[1,1],[1,-phi+1]]) # optional - sage.rings.number_field - sage: P2 = Polyhedron(ieqs=[[-1,-phi,0]]) # optional - sage.rings.number_field - sage: P1.intersection(P2) # optional - sage.rings.number_field - The empty polyhedron in (Number Field in phi with defining polynomial x^2 - x - 1 with phi = 1.618033988749895?)^2 + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2-x-1, embedding=1.618) # optional - sage.rings.number_field + sage: P1 = Polyhedron([[0,1],[1,1],[1,-phi+1]]) # optional - sage.rings.number_field + sage: P2 = Polyhedron(ieqs=[[-1,-phi,0]]) # optional - sage.rings.number_field + sage: P1.intersection(P2) # optional - sage.rings.number_field + The empty polyhedron + in (Number Field in phi with defining polynomial x^2 - x - 1 with phi = 1.618033988749895?)^2 Check that :trac:`28654` is fixed:: diff --git a/src/sage/geometry/polyhedron/backend_number_field.py b/src/sage/geometry/polyhedron/backend_number_field.py index a963ad9d770..650c41f1e36 100644 --- a/src/sage/geometry/polyhedron/backend_number_field.py +++ b/src/sage/geometry/polyhedron/backend_number_field.py @@ -53,7 +53,7 @@ class Polyhedron_number_field(Polyhedron_field, Polyhedron_base_number_field): with sqrt5 = 2.236067977499790?)^3 defined as the convex hull of 12 vertices - sage: x = polygen(ZZ); P = Polyhedron( # optional - sage.rings.number_field + sage: x = polygen(ZZ); P = Polyhedron( # optional - sage.rings.number_field sage.symbolic ....: vertices=[[sqrt(2)], [AA.polynomial_root(x^3-2, RIF(0,3))]], ....: backend='number_field') sage: P # optional - sage.rings.number_field @@ -75,10 +75,11 @@ class Polyhedron_number_field(Polyhedron_field, Polyhedron_base_number_field): sage: p = Polyhedron([(0,0), (1,0), (1/2, sqrt3/2)], backend='number_field') # optional - sage.rings.number_field sage: TestSuite(p).run() # optional - sage.rings.number_field - sage: K. = NumberField(x^2-x-1, embedding=1.618) # optional - sage.rings.number_field - sage: P1 = Polyhedron([[0,1], [1,1], [1,-phi+1]], backend='number_field') # optional - sage.rings.number_field - sage: P2 = Polyhedron(ieqs=[[-1,-phi,0]], backend='number_field') # optional - sage.rings.number_field - sage: P1.intersection(P2) # optional - sage.rings.number_field + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - x - 1, embedding=1.618) # optional - sage.rings.number_field + sage: P1 = Polyhedron([[0,1], [1,1], [1,-phi+1]], backend='number_field') # optional - sage.rings.number_field + sage: P2 = Polyhedron(ieqs=[[-1,-phi,0]], backend='number_field') # optional - sage.rings.number_field + sage: P1.intersection(P2) # optional - sage.rings.number_field The empty polyhedron in (Number Field in phi with defining polynomial x^2 - x - 1 with phi = 1.618033988749895?)^2 diff --git a/src/sage/geometry/polyhedron/constructor.py b/src/sage/geometry/polyhedron/constructor.py index 0a8cc1854ac..0c3aae6692e 100644 --- a/src/sage/geometry/polyhedron/constructor.py +++ b/src/sage/geometry/polyhedron/constructor.py @@ -198,9 +198,12 @@ to take the smallest extension field. For the equilateral triangle, that would be:: - sage: K. = NumberField(x^2 - 3, embedding=AA(3)**(1/2)) # optional - sage.rings.number_field - sage: Polyhedron([(0,0), (1,0), (1/2, sqrt3/2)]) # optional - sage.rings.number_field - A 2-dimensional polyhedron in (Number Field in sqrt3 with defining polynomial x^2 - 3 with sqrt3 = 1.732050807568878?)^2 defined as the convex hull of 3 vertices + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 3, embedding=AA(3)**(1/2)) # optional - sage.rings.number_field + sage: Polyhedron([(0,0), (1,0), (1/2, sqrt3/2)]) # optional - sage.rings.number_field + A 2-dimensional polyhedron in + (Number Field in sqrt3 with defining polynomial x^2 - 3 with sqrt3 = 1.732050807568878?)^2 + defined as the convex hull of 3 vertices .. WARNING:: @@ -463,11 +466,12 @@ def Polyhedron(vertices=None, rays=None, lines=None, When the input contains elements of a Number Field, they require an embedding:: - sage: K = NumberField(x^2-2,'s') # optional - sage.rings.number_field - sage: s = K.0 # optional - sage.rings.number_field - sage: L = NumberField(x^3-2,'t') # optional - sage.rings.number_field - sage: t = L.0 # optional - sage.rings.number_field - sage: P = Polyhedron(vertices = [[0,s],[t,0]]) # optional - sage.rings.number_field + sage: x = polygen(ZZ, 'x') + sage: K = NumberField(x^2 - 2,'s') # optional - sage.rings.number_field + sage: s = K.0 # optional - sage.rings.number_field + sage: L = NumberField(x^3 - 2,'t') # optional - sage.rings.number_field + sage: t = L.0 # optional - sage.rings.number_field + sage: P = Polyhedron(vertices=[[0,s], [t,0]]) # optional - sage.rings.number_field Traceback (most recent call last): ... ValueError: invalid base ring diff --git a/src/sage/geometry/polyhedron/parent.py b/src/sage/geometry/polyhedron/parent.py index 3640e0c524b..9e841f9b6b8 100644 --- a/src/sage/geometry/polyhedron/parent.py +++ b/src/sage/geometry/polyhedron/parent.py @@ -510,8 +510,9 @@ def _repr_base_ring(self): sage: from sage.geometry.polyhedron.parent import Polyhedra sage: Polyhedra(QQ, 3)._repr_base_ring() 'QQ' - sage: K. = NumberField(x^2 - 3, embedding=AA(3).sqrt()) # optional - sage.rings.number_field - sage: Polyhedra(K, 4)._repr_base_ring() # optional - sage.rings.number_field + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 3, embedding=AA(3).sqrt()) # optional - sage.rings.number_field + sage: Polyhedra(K, 4)._repr_base_ring() # optional - sage.rings.number_field '(Number Field in sqrt3 with defining polynomial x^2 - 3 with sqrt3 = 1.732050807568878?)' """ @@ -544,8 +545,9 @@ def _repr_ambient_module(self): sage: from sage.geometry.polyhedron.parent import Polyhedra sage: Polyhedra(QQ, 3)._repr_ambient_module() 'QQ^3' - sage: K. = NumberField(x^2 - 3, embedding=AA(3).sqrt()) # optional - sage.rings.number_field - sage: Polyhedra(K, 4)._repr_ambient_module() # optional - sage.rings.number_field + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 3, embedding=AA(3).sqrt()) # optional - sage.rings.number_field + sage: Polyhedra(K, 4)._repr_ambient_module() # optional - sage.rings.number_field '(Number Field in sqrt3 with defining polynomial x^2 - 3 with sqrt3 = 1.732050807568878?)^4' """ s = self._repr_base_ring() diff --git a/src/sage/geometry/polyhedron/representation.py b/src/sage/geometry/polyhedron/representation.py index 194d9571712..bab34f3481d 100644 --- a/src/sage/geometry/polyhedron/representation.py +++ b/src/sage/geometry/polyhedron/representation.py @@ -901,9 +901,10 @@ def _repr_(self): Test that :trac:`21105` has been fixed:: - sage: K. = NumberField(x^3 - 2, 'a', embedding=1.26) # optional - sage.rings.number_field - sage: P = Polyhedron(vertices=[(1,1,cbrt2),(cbrt2,1,1)]) # optional - sage.rings.number_field - sage: P.inequalities() # optional - sage.rings.number_field + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 2, 'a', embedding=1.26) # optional - sage.rings.number_field + sage: P = Polyhedron(vertices=[(1,1,cbrt2),(cbrt2,1,1)]) # optional - sage.rings.number_field + sage: P.inequalities() # optional - sage.rings.number_field (An inequality (-cbrt2^2 - cbrt2 - 1, 0, 0) x + cbrt2^2 + cbrt2 + 2 >= 0, An inequality (cbrt2^2 + cbrt2 + 1, 0, 0) x - cbrt2^2 + cbrt2 + 1 >= 0) """ diff --git a/src/sage/groups/additive_abelian/additive_abelian_wrapper.py b/src/sage/groups/additive_abelian/additive_abelian_wrapper.py index 372519833bc..5d211f6383b 100644 --- a/src/sage/groups/additive_abelian/additive_abelian_wrapper.py +++ b/src/sage/groups/additive_abelian/additive_abelian_wrapper.py @@ -338,9 +338,10 @@ def discrete_log(self, x, gens=None): :: - sage: F. = GF(1009**2, modulus=x**2+11); E = EllipticCurve(j=F(940)) - sage: P, Q = E(900*t + 228, 974*t + 185), E(1007*t + 214, 865*t + 802) - sage: E.abelian_group().discrete_log(123 * P + 777 * Q, [P, Q]) + sage: x = polygen(ZZ, 'x') + sage: F. = GF(1009**2, modulus=x**2+11); E = EllipticCurve(j=F(940)) # optional - sage.rings.finite_rings + sage: P, Q = E(900*t + 228, 974*t + 185), E(1007*t + 214, 865*t + 802) # optional - sage.rings.finite_rings + sage: E.abelian_group().discrete_log(123 * P + 777 * Q, [P, Q]) # optional - sage.rings.finite_rings (123, 777) :: diff --git a/src/sage/groups/galois_group.py b/src/sage/groups/galois_group.py index aa1d69d11d4..d4023125644 100644 --- a/src/sage/groups/galois_group.py +++ b/src/sage/groups/galois_group.py @@ -122,6 +122,7 @@ def splitting_field(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x^3 - x + 1, 'a') sage: K.galois_group(names='b').splitting_field() Number Field in b with defining polynomial x^6 - 6*x^4 + 9*x^2 + 23 @@ -282,6 +283,7 @@ def _ambient_group(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^4 + 1) sage: G = L.galois_group() sage: H = G.decomposition_group(L.primes_above(3)[0]) @@ -321,6 +323,7 @@ def _gcdata(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^4 + 1) sage: G = L.galois_group() sage: H = G.decomposition_group(L.primes_above(3)[0]) diff --git a/src/sage/libs/linkages/padics/unram_shared.pxi b/src/sage/libs/linkages/padics/unram_shared.pxi index 10a2f5adde8..708cf7ac736 100644 --- a/src/sage/libs/linkages/padics/unram_shared.pxi +++ b/src/sage/libs/linkages/padics/unram_shared.pxi @@ -41,6 +41,7 @@ def frobenius_unram(self, arithmetic=True): An error will be raised if the parent of self is a ramified extension:: + sage: x = polygen(ZZ, 'x') sage: K. = Qp(5).extension(x^2 - 5) sage: a.frobenius() Traceback (most recent call last): diff --git a/src/sage/libs/singular/singular.pyx b/src/sage/libs/singular/singular.pyx index cc0797d064a..8924789c141 100644 --- a/src/sage/libs/singular/singular.pyx +++ b/src/sage/libs/singular/singular.pyx @@ -526,6 +526,7 @@ cdef object si2sa_NF(number *n, ring *_ring, object base): TESTS:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 2) sage: P. = K[] sage: f = a^21*x^2 + 1 # indirect doctest @@ -1393,7 +1394,8 @@ cdef number *sa2si_NF(object elem, ring *_ring): TESTS:: - sage: F = NumberField(x^3+x+1, 'a') + sage: x = polygen(ZZ, 'x') + sage: F = NumberField(x^3 + x + 1, 'a') sage: type(F) sage: R. = F[] diff --git a/src/sage/matrix/matrix1.pyx b/src/sage/matrix/matrix1.pyx index f38c429d994..ecafc244e06 100644 --- a/src/sage/matrix/matrix1.pyx +++ b/src/sage/matrix/matrix1.pyx @@ -119,9 +119,10 @@ cdef class Matrix(Matrix0): sage: g.IsMatrix() true - sage: L. = NumberField(x^3-2) - sage: A = MatrixSpace(L,2,2)([0,1+tau,2*tau,3]) - sage: g = gap(A); g + sage: x = polygen(ZZ, 'x') + sage: L. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: A = MatrixSpace(L, 2, 2)([0, 1+tau, 2*tau, 3]) # optional - sage.rings.number_field + sage: g = gap(A); g # optional - sage.rings.number_field [ [ !0, tau+1 ], [ 2*tau, !3 ] ] sage: matrix(L, g) == A True diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index e2e6449dfa9..5e05d28c0fb 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -1120,6 +1120,7 @@ cdef class Matrix(Matrix1): Notice the base ring of the results in the next two examples. :: + sage: x = polygen(ZZ, 'x') sage: D = matrix(ZZ['x'],2,[1+x^2,2,3,4-x]) sage: E = matrix(QQ,2,[1,2,3,4]) sage: F = D.elementwise_product(E) @@ -5227,13 +5228,15 @@ cdef class Matrix(Matrix1): An example over a bigger ring:: - sage: L. = NumberField(x^2 - x + 2) - sage: OL = L.ring_of_integers() - sage: A = matrix(L, 2, [1, w/2]) - sage: A.integer_kernel(OL) - Free module of degree 2 and rank 1 over Maximal Order in Number Field in w with defining polynomial x^2 - x + 2 - Echelon basis matrix: - [ -1 -w + 1] + sage: x = polygen(ZZ, 'x') + sage: L. = NumberField(x^2 - x + 2) # optional - sage.rings.number_field + sage: OL = L.ring_of_integers() # optional - sage.rings.number_field + sage: A = matrix(L, 2, [1, w/2]) # optional - sage.rings.number_field + sage: A.integer_kernel(OL) # optional - sage.rings.number_field + Free module of degree 2 and rank 1 over + Maximal Order in Number Field in w with defining polynomial x^2 - x + 2 + Echelon basis matrix: + [ -1 -w + 1] """ try: @@ -7462,10 +7465,11 @@ cdef class Matrix(Matrix1): [ 0 4 8 12] [ 0 0 0 0] - sage: L. = NumberField(x^2 - x + 2) - sage: OL = L.ring_of_integers() - sage: m = matrix(OL, 2, 2, [1,2,3,4+w]) - sage: m.echelon_form() + sage: x = polygen(ZZ, 'x') + sage: L. = NumberField(x^2 - x + 2) # optional - sage.rings.number_field + sage: OL = L.ring_of_integers() # optional - sage.rings.number_field + sage: m = matrix(OL, 2, 2, [1,2,3,4+w]) # optional - sage.rings.number_field + sage: m.echelon_form() # optional - sage.rings.number_field [ 1 2] [ 0 w - 2] sage: E, T = m.echelon_form(transformation=True); E,T @@ -12386,8 +12390,8 @@ cdef class Matrix(Matrix1): ... TypeError: polynomial variable must be a string or polynomial ring generator, not sin(x) - sage: t = polygen(GF(7), 't') - sage: A.cyclic_subspace(v, var=t) + sage: t = polygen(GF(7), 't') # optional - sage.rings.finite_rings + sage: A.cyclic_subspace(v, var=t) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: polynomial generator must be over the same ring as the matrix entries @@ -13502,9 +13506,9 @@ cdef class Matrix(Matrix1): A Hermitian matrix. :: - sage: x = var('x') - sage: C. = NumberField(x^2 + 1) - sage: A = matrix(C, [[ 23, 17*I + 3, 24*I + 25, 21*I], + sage: x = polygen(ZZ) + sage: C. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: A = matrix(C, [[ 23, 17*I + 3, 24*I + 25, 21*I], # optional - sage.rings.number_field ....: [ -17*I + 3, 38, -69*I + 89, 7*I + 15], ....: [-24*I + 25, 69*I + 89, 976, 24*I + 6], ....: [ -21*I, -7*I + 15, -24*I + 6, 28]]) @@ -14732,8 +14736,9 @@ cdef class Matrix(Matrix1): confirmed by the positive determinants of its leading principal submatrices:: - sage: C. = NumberField(x^2 + 1, embedding=CC(0,1)) - sage: A = matrix(C, [[ 23, 17*I + 3, 24*I + 25, 21*I], + sage: x = polygen(ZZ, 'x') + sage: C. = NumberField(x^2 + 1, embedding=CC(0,1)) # optional - sage.rings.number_field + sage: A = matrix(C, [[ 23, 17*I + 3, 24*I + 25, 21*I], # optional - sage.rings.number_field ....: [ -17*I + 3, 38, -69*I + 89, 7*I + 15], ....: [-24*I + 25, 69*I + 89, 976, 24*I + 6], ....: [ -21*I, -7*I + 15, -24*I + 6, 28]]) @@ -15002,9 +15007,10 @@ cdef class Matrix(Matrix1): A matrix over a not-totally-real number field:: - sage: K. = NumberField(x^2+5) - sage: M = matrix(K, [[1+j,1], [0,2*j]]) - sage: M.conjugate() + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 5) # optional - sage.rings.number_field + sage: M = matrix(K, [[1+j,1], [0,2*j]]) # optional - sage.rings.number_field + sage: M.conjugate() # optional - sage.rings.number_field [-j + 1 1] [ 0 -2*j] @@ -15456,9 +15462,10 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: OE. = EquationOrder(x^2 - x + 2) - sage: m = Matrix([ [1, w],[w,7]]) - sage: m.elementary_divisors() + sage: x = polygen(ZZ, 'x') + sage: OE. = EquationOrder(x^2 - x + 2) # optional - sage.rings.number_field + sage: m = Matrix([[1, w], [w, 7]]) # optional - sage.rings.number_field + sage: m.elementary_divisors() # optional - sage.rings.number_field [1, -w + 9] .. SEEALSO:: @@ -15547,10 +15554,11 @@ cdef class Matrix(Matrix1): An example over the ring of integers of a number field (of class number 1):: - sage: OE. = EquationOrder(x^2 - x + 2) - sage: m = Matrix([ [1, w],[w,7]]) - sage: d, u, v = m.smith_form() - sage: (d, u, v) + sage: x = polygen(ZZ, 'x') + sage: OE. = EquationOrder(x^2 - x + 2) # optional - sage.rings.number_field + sage: m = Matrix([[1, w], [w, 7]]) # optional - sage.rings.number_field + sage: d, u, v = m.smith_form() # optional - sage.rings.number_field + sage: (d, u, v) # optional - sage.rings.number_field ( [ 1 0] [ 1 0] [ 1 -w] [ 0 -w + 9], [-w 1], [ 0 1] @@ -15900,8 +15908,9 @@ cdef class Matrix(Matrix1): column pivot. EXAMPLES:: - sage: L. = NumberField(x^3 - 2) - sage: OL = L.ring_of_integers() + sage: x = polygen(ZZ, 'x') + sage: L. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: OL = L.ring_of_integers() # optional - sage.rings.number_field We check some degenerate cases:: @@ -17031,6 +17040,7 @@ cdef class Matrix(Matrix1): sage: K = Cone([(1,0),(-1,0),(0,1),(0,-1)]) sage: K.is_full_space() True + sage: x = polygen(ZZ, 'x') sage: L = matrix(QQ[x], [[x,0],[0,1]]) sage: L.is_positive_operator_on(K) True @@ -17712,9 +17722,10 @@ def _smith_diag(d, transformation=True): EXAMPLES:: sage: from sage.matrix.matrix2 import _smith_diag - sage: OE = EquationOrder(x^2 - x + 2, 'w') - sage: A = matrix(OE, 2, [2,0,0,3]) - sage: D,U,V = _smith_diag(A); D,U,V + sage: x = polygen(ZZ, 'x') + sage: OE = EquationOrder(x^2 - x + 2, 'w') # optional - sage.rings.number_field + sage: A = matrix(OE, 2, [2, 0, 0, 3]) # optional - sage.rings.number_field + sage: D,U,V = _smith_diag(A); D,U,V # optional - sage.rings.number_field ( [1 0] [2 1] [ 1 -3] [0 6], [3 2], [-1 4] @@ -17788,10 +17799,12 @@ def _generic_clear_column(m): EXAMPLES:: - sage: L. = NumberField(x^2 - x + 2) - sage: OL = L.ring_of_integers(); w = OL(w) - sage: m = matrix(OL, 8, 4, [2*w - 2, 2*w + 1, -2, w, 2, -2,-2*w - 2, -2*w + 2, -w + 2, 2*w + 1, -w + 2, -w - 2, -2*w, 2*w, -w+ 2, w - 1, -2*w + 2, 2*w + 2, 2*w - 1, -w, 2*w + 2, -w + 2, 2, 2*w -1, w - 4, -2*w - 2, 2*w - 1, 0, 6, 7, 2*w + 1, 14]) - sage: s,t = m.echelon_form(transformation=True); t*m == s # indirect doctest + sage: x = polygen(ZZ, 'x') + sage: L. = NumberField(x^2 - x + 2) # optional - sage.rings.number_field + sage: OL = L.ring_of_integers(); w = OL(w) # optional - sage.rings.number_field + sage: m = matrix(OL, 8, 4, [2*w - 2, 2*w + 1, -2, w, 2, -2, -2*w - 2, -2*w + 2, -w + 2, 2*w + 1, -w + 2, -w - 2, -2*w, # optional - sage.rings.number_field + ....: 2*w, -w+ 2, w - 1, -2*w + 2, 2*w + 2, 2*w - 1, -w, 2*w + 2, -w + 2, 2, 2*w -1, w - 4, -2*w - 2, 2*w - 1, 0, 6, 7, 2*w + 1, 14]) + sage: s,t = m.echelon_form(transformation=True); t*m == s # indirect doctest # optional - sage.rings.number_field True sage: s[0] (w, 0, 0, 0) @@ -17895,9 +17908,10 @@ def _smith_onestep(m): EXAMPLES:: sage: from sage.matrix.matrix2 import _smith_onestep - sage: OE. = EquationOrder(x^2 - x + 2) - sage: m = matrix(OE, 3,3,[1,0,7,2,w, w+17, 13+8*w, 0, 6]) - sage: a,b,c = _smith_onestep(m); b + sage: x = polygen(ZZ, 'x') + sage: OE. = EquationOrder(x^2 - x + 2) # optional - sage.rings.number_field + sage: m = matrix(OE, 3, 3, [1, 0, 7, 2, w, w+17, 13+8*w, 0, 6]) # optional - sage.rings.number_field + sage: a,b,c = _smith_onestep(m); b # optional - sage.rings.number_field [ 1 0 0] [ 0 w w + 3] [ 0 0 -56*w - 85] diff --git a/src/sage/matrix/matrix_space.py b/src/sage/matrix/matrix_space.py index a2583f7497a..ed0d8a65501 100644 --- a/src/sage/matrix/matrix_space.py +++ b/src/sage/matrix/matrix_space.py @@ -2031,9 +2031,10 @@ def matrix(self, x=None, **kwds): sage: MS([[1],[2]]) [1] [2] - sage: MS = MatrixSpace(CC,2,1) - sage: F = NumberField(x^2+1, name='x') - sage: MS([F(1),F(0)]) + sage: MS = MatrixSpace(CC, 2, 1) + sage: x = polygen(ZZ, 'x') + sage: F = NumberField(x^2 + 1, name='x') # optional - sage.rings.number_field + sage: MS([F(1), F(0)]) # optional - sage.rings.number_field [ 1.00000000000000] [0.000000000000000] diff --git a/src/sage/matrix/matrix_sparse.pyx b/src/sage/matrix/matrix_sparse.pyx index dcd9c2e1550..fdfd1cdf92f 100644 --- a/src/sage/matrix/matrix_sparse.pyx +++ b/src/sage/matrix/matrix_sparse.pyx @@ -45,6 +45,7 @@ cdef class Matrix_sparse(matrix.Matrix): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: A = matrix(QQ['x,y'], 2, [0,-1,2*x,-2], sparse=True); A [ 0 -1] [2*x -2] diff --git a/src/sage/matrix/special.py b/src/sage/matrix/special.py index 41a48c0e99f..b85a4d29777 100644 --- a/src/sage/matrix/special.py +++ b/src/sage/matrix/special.py @@ -2972,8 +2972,8 @@ def random_unimodular_matrix(parent, upper_bound=None, max_tries=100): A matrix over the number Field in `y` with defining polynomial `y^2-2y-2`. :: - sage: y = var('y') - sage: K = NumberField(y^2-2*y-2, 'y') + sage: y = polygen(ZZ, 'y') + sage: K = NumberField(y^2 - 2*y - 2, 'y') sage: C = random_matrix(K, 3, algorithm='unimodular') sage: det(C) 1 diff --git a/src/sage/misc/functional.py b/src/sage/misc/functional.py index aee5d035a66..9407f588848 100644 --- a/src/sage/misc/functional.py +++ b/src/sage/misc/functional.py @@ -874,9 +874,10 @@ def is_integrally_closed(x): doctest:...DeprecationWarning: use X.is_integrally_closed() See https://github.com/sagemath/sage/issues/32347 for details. True - sage: K. = NumberField(x^2 + 189*x + 394) - sage: R = K.order(2*a) - sage: is_integrally_closed(R) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 189*x + 394) # optional - sage.rings.number_field + sage: R = K.order(2*a) # optional - sage.rings.number_field + sage: is_integrally_closed(R) # optional - sage.rings.number_field False """ deprecation(32347, "use X.is_integrally_closed()") @@ -1666,7 +1667,8 @@ def regulator(x): EXAMPLES:: - sage: regulator(NumberField(x^2-2, 'a')) + sage: x = polygen(ZZ, 'x') + sage: regulator(NumberField(x^2 - 2, 'a')) # optional - sage.rings.number_field 0.881373587019543 sage: regulator(EllipticCurve('11a')) 1.00000000000000 diff --git a/src/sage/misc/sage_input.py b/src/sage/misc/sage_input.py index a50bf15d708..f86cd1f8f46 100644 --- a/src/sage/misc/sage_input.py +++ b/src/sage/misc/sage_input.py @@ -13,7 +13,7 @@ sage: sage_input(3) 3 - sage: sage_input((polygen(RR) + RR(pi))^2, verify=True) + sage: sage_input((polygen(RR) + RR(pi))^2, verify=True) # optional - sage.symbolic # Verified R. = RR[] x^2 + 6.2831853071795862*x + 9.869604401089358 @@ -2812,14 +2812,14 @@ def _sie_add_command(self, sif): We also can't use the preparser syntax if there is a conflict between generator names. For example, this works:: - sage: sage_input((polygen(ZZ), polygen(GF(17), 'y'))) + sage: sage_input((polygen(ZZ), polygen(GF(17), 'y'))) # optional - sage.rings.finite_rings R1. = ZZ[] R2. = GF(17)[] (x, y) but this can't use the preparser syntax.:: - sage: sage_input((polygen(ZZ), polygen(GF(17)))) + sage: sage_input((polygen(ZZ), polygen(GF(17)))) # optional - sage.rings.finite_rings R1 = ZZ['x'] x1 = R1.gen() R2 = GF(17)['x'] diff --git a/src/sage/modular/arithgroup/arithgroup_element.pyx b/src/sage/modular/arithgroup/arithgroup_element.pyx index 579cbc654cc..f7812fb4477 100644 --- a/src/sage/modular/arithgroup/arithgroup_element.pyx +++ b/src/sage/modular/arithgroup/arithgroup_element.pyx @@ -342,6 +342,7 @@ cdef class ArithmeticSubgroupElement(MultiplicativeGroupElement): An example involving the Gaussian numbers:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: g.acton(i) 1/1186*i + 77/1186 diff --git a/src/sage/modular/arithgroup/congroup_gamma1.py b/src/sage/modular/arithgroup/congroup_gamma1.py index ed84fd670b1..d32d3646256 100644 --- a/src/sage/modular/arithgroup/congroup_gamma1.py +++ b/src/sage/modular/arithgroup/congroup_gamma1.py @@ -370,6 +370,7 @@ def dimension_modular_forms(self, k=2, eps=None, algorithm="CohenOesterle"): Check that :trac:`18436` is fixed:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + x + 1) sage: G = DirichletGroup(13, base_ring=K) sage: Gamma1(13).dimension_modular_forms(2, G[1]) diff --git a/src/sage/modular/cusps_nf.py b/src/sage/modular/cusps_nf.py index 157ebabe291..7e8ffa6658c 100644 --- a/src/sage/modular/cusps_nf.py +++ b/src/sage/modular/cusps_nf.py @@ -9,6 +9,7 @@ The space of cusps over a number field k:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 5) sage: kCusps = NFCusps(k); kCusps Set of all cusps of Number Field in a with defining polynomial x^2 + 5 @@ -102,6 +103,7 @@ def list_of_representatives(N): EXAMPLES:: sage: from sage.modular.cusps_nf import list_of_representatives + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^4 + 13*x^3 - 11) sage: N = k.ideal(713, a + 208) sage: L = list_of_representatives(N); L @@ -127,6 +129,7 @@ def NFCusps(number_field): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 5) sage: kCusps = NFCusps(k); kCusps Set of all cusps of Number Field in a with defining polynomial x^2 + 5 @@ -152,6 +155,7 @@ class NFCuspsSpace(UniqueRepresentation, Parent): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 5) sage: kCusps = NFCusps(k); kCusps Set of all cusps of Number Field in a with defining polynomial x^2 + 5 @@ -162,6 +166,7 @@ def __init__(self, number_field): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 + x^2 + 13) sage: kCusps = NFCusps(k); kCusps Set of all cusps of Number Field in a with defining polynomial x^3 + x^2 + 13 @@ -175,6 +180,7 @@ def __eq__(self, right): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 5) sage: L. = NumberField(x^2 + 23) sage: kCusps = NFCusps(k); kCusps @@ -198,6 +204,7 @@ def __ne__(self, right): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 5) sage: L. = NumberField(x^2 + 23) sage: kCusps = NFCusps(k); kCusps @@ -219,6 +226,7 @@ def _repr_(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 2) sage: kCusps = NFCusps(k) sage: kCusps @@ -239,6 +247,7 @@ def _latex_(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 5) sage: kCusps = NFCusps(k) sage: latex(kCusps) # indirect doctest @@ -252,6 +261,7 @@ def __call__(self, x): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 5) sage: kCusps = NFCusps(k) sage: c = kCusps(a,2) @@ -283,10 +293,11 @@ def zero(self): EXAMPLES:: - sage: k. = NumberField(x^2 + 5) - sage: kCusps = NFCusps(k) - sage: kCusps.zero() - Cusp [0: 1] of Number Field in a with defining polynomial x^2 + 5 + sage: x = polygen(ZZ, 'x') + sage: k. = NumberField(x^2 + 5) + sage: kCusps = NFCusps(k) + sage: kCusps.zero() + Cusp [0: 1] of Number Field in a with defining polynomial x^2 + 5 """ return self(0) @@ -296,6 +307,7 @@ def number_field(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: kCusps = NFCusps(k) sage: kCusps.number_field() @@ -337,6 +349,7 @@ class NFCusp(Element): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 5) sage: NFCusp(k, a, 2) Cusp [a: 2] of Number Field in a with defining polynomial x^2 + 5 @@ -416,6 +429,7 @@ def __init__(self, number_field, a, b=None, parent=None, lreps=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: c = NFCusp(k, 3, a+1); c Cusp [3: a + 1] of Number Field in a with defining polynomial x^2 + 1 @@ -554,6 +568,7 @@ def _repr_(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: c = NFCusp(k, a, 2); c Cusp [a: 2] of Number Field in a with defining polynomial x^2 + 1 @@ -576,6 +591,7 @@ def number_field(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 2) sage: alpha = NFCusp(k, 1, a + 1) sage: alpha.number_field() @@ -589,6 +605,7 @@ def is_infinity(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: NFCusp(k, a, 2).is_infinity() False @@ -605,6 +622,7 @@ def numerator(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: c = NFCusp(k, a, 2) sage: c.numerator() @@ -623,6 +641,7 @@ def denominator(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: c = NFCusp(k, a, 2) sage: c.denominator() @@ -642,6 +661,7 @@ def _number_field_element_(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 2) sage: NFCusp(k, a, 2)._number_field_element_() 1/2*a @@ -660,6 +680,7 @@ def _ring_of_integers_element_(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 2) sage: NFCusp(k, a+1)._ring_of_integers_element_() a + 1 @@ -684,6 +705,7 @@ def _latex_(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 11) sage: latex(NFCusp(k, 3*a, a + 1)) # indirect doctest \[3 a: a + 1\] @@ -709,6 +731,7 @@ def _richcmp_(self, right, op): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 + x + 1) sage: kCusps = NFCusps(k) @@ -746,6 +769,7 @@ def __neg__(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 23) sage: c = NFCusp(k, a, a+1); c Cusp [a: a + 1] of Number Field in a with defining polynomial x^2 + 23 @@ -771,6 +795,7 @@ def apply(self, g): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 23) sage: beta = NFCusp(k, 0, 1) sage: beta.apply([0, -1, 1, 0]) @@ -788,6 +813,7 @@ def ideal(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 23) sage: alpha = NFCusp(k, 3, a-1) sage: alpha.ideal() @@ -812,6 +838,7 @@ def ABmatrix(self): :: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 + 11) sage: alpha = NFCusp(k, oo) sage: alpha.ABmatrix() @@ -901,8 +928,9 @@ def is_Gamma0_equivalent(self, other, N, Transformation=False): :: - sage: K. = NumberField(x^3-10) - sage: N = K.ideal(a-1) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 10) + sage: N = K.ideal(a - 1) sage: alpha = NFCusp(K, 0) sage: beta = NFCusp(K, oo) sage: alpha.is_Gamma0_equivalent(beta, N) @@ -1008,6 +1036,7 @@ def Gamma0_NFCusps(N): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 5) sage: N = k.ideal(3) sage: L = Gamma0_NFCusps(N) @@ -1026,6 +1055,7 @@ def Gamma0_NFCusps(N): Another example:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^4 - x^3 -21*x^2 + 17*x + 133) sage: N = k.ideal(5) sage: from sage.modular.cusps_nf import number_of_Gamma0_NFCusps @@ -1099,6 +1129,7 @@ def number_of_Gamma0_NFCusps(N): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(2, a+1) sage: from sage.modular.cusps_nf import number_of_Gamma0_NFCusps @@ -1144,6 +1175,7 @@ def NFCusps_ideal_reps_for_levelN(N, nlists=1): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(5, a + 1) sage: from sage.modular.cusps_nf import NFCusps_ideal_reps_for_levelN @@ -1203,6 +1235,7 @@ def units_mod_ideal(I): EXAMPLES:: sage: from sage.modular.cusps_nf import units_mod_ideal + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: I = k.ideal(a + 1) sage: units_mod_ideal(I) diff --git a/src/sage/modular/modsym/p1list_nf.py b/src/sage/modular/modsym/p1list_nf.py index 118d8d5e4fa..493e0e827b5 100644 --- a/src/sage/modular/modsym/p1list_nf.py +++ b/src/sage/modular/modsym/p1list_nf.py @@ -14,6 +14,7 @@ :: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(5, a^2 - a + 1) sage: P = P1NFList(N); P @@ -95,6 +96,7 @@ def P1NFList_clear_level_cache(): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(a+1) sage: alpha = MSymbol(N, 2*a^2, 5) @@ -136,6 +138,7 @@ class MSymbol(SageObject): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(a + 1, 2) sage: MSymbol(N, 3, a^2 + 1) @@ -175,6 +178,7 @@ def __init__(self, N, c, d=None, check=True): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^4 + 13*x - 7) sage: N = k.ideal(5) sage: MSymbol(N, 0, 6*a) @@ -215,6 +219,7 @@ def __repr__(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 23) sage: N = k.ideal(3, a - 1) sage: MSymbol(N, 3, a) @@ -228,6 +233,7 @@ def _latex_(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^4 + 13*x - 7) sage: N = k.ideal(a^3 - 1) sage: alpha = MSymbol(N, 3, 5*a^2 - 1) @@ -244,6 +250,7 @@ def __richcmp__(self, other, op): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 23) sage: N = k.ideal(3, a - 1) sage: alpha = MSymbol(N, 3, a) @@ -265,6 +272,7 @@ def N(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 23) sage: N = k.ideal(3, a - 1) sage: alpha = MSymbol(N, 3, a) @@ -279,6 +287,7 @@ def tuple(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 23) sage: N = k.ideal(3, a - 1) sage: alpha = MSymbol(N, 3, a); alpha @@ -299,6 +308,7 @@ def __getitem__(self, n): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 23) sage: N = k.ideal(3, a - 1) sage: alpha = MSymbol(N, 3, a); alpha @@ -316,6 +326,7 @@ def __get_c(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(a + 1, 2) sage: alpha = MSymbol(N, 3, a^2 + 1) @@ -331,6 +342,7 @@ def __get_d(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(a + 1, 2) sage: alpha = MSymbol(N, 3, a^2 + 1) @@ -353,6 +365,7 @@ def lift_to_sl2_Ok(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 23) sage: N = k.ideal(3, a - 1) sage: alpha = MSymbol(N, 3*a + 1, a) @@ -380,6 +393,7 @@ def normalize(self, with_scalar=False): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 23) sage: N = k.ideal(3, a - 1) sage: alpha1 = MSymbol(N, 3, a); alpha1 @@ -475,6 +489,7 @@ class P1NFList(SageObject): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(5, a + 1) sage: P = P1NFList(N); P @@ -494,6 +509,7 @@ def __init__(self, N): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 5) sage: N = k.ideal(3, a - 1) sage: P = P1NFList(N); P @@ -511,6 +527,7 @@ def __richcmp__(self, other, op): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 23) sage: N1 = k.ideal(3, a + 1) sage: P1 = P1NFList(N1) @@ -533,6 +550,7 @@ def __getitem__(self, n): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(a) sage: P = P1NFList(N) @@ -550,6 +568,7 @@ def __len__(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(5, a^2 - a + 1) sage: P = P1NFList(N) @@ -564,6 +583,7 @@ def __repr__(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(5, a+1) sage: P = P1NFList(N); P @@ -578,6 +598,7 @@ def list(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(5, a+1) sage: P = P1NFList(N) @@ -611,6 +632,7 @@ def normalize(self, c, d=None, with_scalar=False): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 31) sage: N = k.ideal(5, a + 3) sage: P = P1NFList(N) @@ -649,6 +671,7 @@ def N(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 31) sage: N = k.ideal(5, a + 3) sage: P = P1NFList(N) @@ -680,6 +703,7 @@ def index(self, c, d=None, with_scalar=False): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 31) sage: N = k.ideal(5, a + 3) sage: P = P1NFList(N) @@ -760,6 +784,7 @@ def index_of_normalized_pair(self, c, d=None): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 31) sage: N = k.ideal(5, a + 3) sage: P = P1NFList(N) @@ -798,6 +823,7 @@ def lift_to_sl2_Ok(self, i): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 23) sage: N = k.ideal(3) sage: P = P1NFList(N) @@ -832,6 +858,7 @@ def apply_S(self, i): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(5, a + 1) sage: P = P1NFList(N) @@ -866,6 +893,7 @@ def apply_TS(self, i): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(5, a + 1) sage: P = P1NFList(N) @@ -902,6 +930,7 @@ def apply_T_alpha(self, i, alpha=1): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(5, a + 1) sage: P = P1NFList(N) @@ -941,6 +970,7 @@ def apply_J_epsilon(self, i, e1, e2=1): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 11) sage: N = k.ideal(5, a + 1) sage: P = P1NFList(N) @@ -985,6 +1015,7 @@ def p1NFlist(N): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 23) sage: N = k.ideal(3) sage: from sage.modular.modsym.p1list_nf import p1NFlist, psi @@ -1043,6 +1074,7 @@ def lift_to_sl2_Ok(N, c, d): EXAMPLES:: sage: from sage.modular.modsym.p1list_nf import lift_to_sl2_Ok + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 23) sage: Ok = k.ring_of_integers() sage: N = k.ideal(3) @@ -1148,6 +1180,7 @@ def make_coprime(N, c, d): EXAMPLES:: sage: from sage.modular.modsym.p1list_nf import make_coprime + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 23) sage: N = k.ideal(3, a - 1) sage: c = 2*a; d = a + 1 @@ -1183,6 +1216,7 @@ def psi(N): EXAMPLES:: sage: from sage.modular.modsym.p1list_nf import psi + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 23) sage: N = k.ideal(3, a - 1) sage: psi(N) diff --git a/src/sage/modular/overconvergent/genus0.py b/src/sage/modular/overconvergent/genus0.py index 09f39d33785..fe16499d44a 100644 --- a/src/sage/modular/overconvergent/genus0.py +++ b/src/sage/modular/overconvergent/genus0.py @@ -283,7 +283,8 @@ class OverconvergentModularFormsSpace(Module): TESTS:: - sage: K. = Qp(13).extension(x^2-13); M = OverconvergentModularForms(13, 20, radius=1/2, base_ring=K) + sage: x = polygen(ZZ, 'x') + sage: K. = Qp(13).extension(x^2 - 13); M = OverconvergentModularForms(13, 20, radius=1/2, base_ring=K) sage: M is loads(dumps(M)) True """ @@ -357,6 +358,7 @@ def _set_radius(self, radius): sage: M._set_radius(1/3); M Space of 3-adic 1/3-overconvergent modular forms of weight-character 2 over Rational Field + sage: x = polygen(ZZ, 'x') sage: L. = Qp(3).extension(x^5 - 3) sage: OverconvergentModularForms(3, 2, 1/30, base_ring=L).normalising_factor() # indirect doctest w + O(w^101) @@ -424,7 +426,8 @@ def base_extend(self, ring): EXAMPLES:: - sage: M = OverconvergentModularForms(2, 0, 1/2, base_ring = Qp(2)) + sage: M = OverconvergentModularForms(2, 0, 1/2, base_ring=Qp(2)) + sage: x = polygen(ZZ, 'x') sage: M.base_extend(Qp(2).extension(x^2 - 2, names="w")) Space of 2-adic 1/2-overconvergent modular forms of weight-character 0 over 2-adic Eisenstein Extension ... sage: M.base_extend(QQ) @@ -490,6 +493,7 @@ def normalising_factor(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = Qp(7).extension(x^2 - 7) sage: OverconvergentModularForms(7, 0, 1/4, base_ring=L).normalising_factor() w + O(w^41) @@ -555,6 +559,7 @@ def _params(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = Qp(7).extension(x^2 - 7) sage: OverconvergentModularForms(7, 0, 1/4, base_ring=L)._params() (7, @@ -573,6 +578,7 @@ def __reduce__(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = Qp(7).extension(x^2 - 7) sage: OverconvergentModularForms(7, 0, 1/4, base_ring=L).__reduce__() (, @@ -778,7 +784,9 @@ def zero(self): EXAMPLES:: - sage: K. = Qp(13).extension(x^2-13); M = OverconvergentModularForms(13, 20, radius=1/2, base_ring=K) + sage: x = polygen(ZZ, 'x') + sage: K. = Qp(13).extension(x^2 - 13) + sage: M = OverconvergentModularForms(13, 20, radius=1/2, base_ring=K) sage: K.zero() 0 """ @@ -1291,7 +1299,9 @@ class OverconvergentModularFormElement(ModuleElement): EXAMPLES:: - sage: K. = Qp(5).extension(x^7 - 5); s = OverconvergentModularForms(5, 6, 1/21, base_ring=K).0 + sage: x = polygen(ZZ, 'x') + sage: K. = Qp(5).extension(x^7 - 5) + sage: s = OverconvergentModularForms(5, 6, 1/21, base_ring=K).0 sage: s == loads(dumps(s)) True """ @@ -1659,7 +1669,9 @@ def weight(self): EXAMPLES:: - sage: M = OverconvergentModularForms(13, 10, 1/2, base_ring = Qp(13).extension(x^2 - 13,names='a')) + sage: x = polygen(ZZ, 'x') + sage: R = Qp(13).extension(x^2 - 13, names='a') + sage: M = OverconvergentModularForms(13, 10, 1/2, base_ring=R) sage: M.gen(0).weight() 10 """ @@ -1672,7 +1684,9 @@ def additive_order(self): EXAMPLES:: - sage: M = OverconvergentModularForms(13, 10, 1/2, base_ring = Qp(13).extension(x^2 - 13,names='a')) + sage: x = polygen(ZZ, 'x') + sage: R = Qp(13).extension(x^2 - 13, names='a') + sage: M = OverconvergentModularForms(13, 10, 1/2, base_ring=R) sage: M.gen(0).additive_order() +Infinity sage: M(0).additive_order() diff --git a/src/sage/modules/free_module.py b/src/sage/modules/free_module.py index b7618475111..6e648c6bd70 100644 --- a/src/sage/modules/free_module.py +++ b/src/sage/modules/free_module.py @@ -3796,6 +3796,7 @@ def intersection(self, other): We intersect two modules over the ring of integers of a number field:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^2 - x + 2) sage: OL = L.ring_of_integers() sage: V = L**3 diff --git a/src/sage/modules/free_module_integer.py b/src/sage/modules/free_module_integer.py index ddd8a25c92a..5660b48bd10 100644 --- a/src/sage/modules/free_module_integer.py +++ b/src/sage/modules/free_module_integer.py @@ -259,10 +259,11 @@ def __init__(self, ambient, basis, check=True, echelonize=False, sage: M.row_space() == L.matrix().row_space() True - sage: K. = NumberField(x^8+1) - sage: O = K.ring_of_integers() - sage: f = O(a^7 - a^6 + 4*a^5 - a^4 + a^3 + 1) - sage: IntegerLattice(f) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^8 + 1) # optional - sage.rings.number_field + sage: O = K.ring_of_integers() # optional - sage.rings.number_field + sage: f = O(a^7 - a^6 + 4*a^5 - a^4 + a^3 + 1) # optional - sage.rings.number_field + sage: IntegerLattice(f) # optional - sage.rings.number_field Free module of degree 8 and rank 8 over Integer Ring User basis matrix: [ 0 1 0 1 0 3 3 0] diff --git a/src/sage/modules/matrix_morphism.py b/src/sage/modules/matrix_morphism.py index 94069fcc603..b400cc4afd0 100644 --- a/src/sage/modules/matrix_morphism.py +++ b/src/sage/modules/matrix_morphism.py @@ -523,9 +523,10 @@ def __mul__(self, right): Composite maps can be formed with matrix morphisms:: - sage: K. = NumberField(x^2 + 23) - sage: V, VtoK, KtoV = K.vector_space() - sage: f = V.hom([V.0 - V.1, V.0 + V.1])*KtoV; f + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 23) # optional - sage.rings.number_field + sage: V, VtoK, KtoV = K.vector_space() # optional - sage.rings.number_field + sage: f = V.hom([V.0 - V.1, V.0 + V.1])*KtoV; f # optional - sage.rings.number_field Composite map: From: Number Field in a with defining polynomial x^2 + 23 To: Vector space of dimension 2 over Rational Field diff --git a/src/sage/quadratic_forms/quadratic_form.py b/src/sage/quadratic_forms/quadratic_form.py index e2691795ba4..4b9380475d8 100644 --- a/src/sage/quadratic_forms/quadratic_form.py +++ b/src/sage/quadratic_forms/quadratic_form.py @@ -1320,6 +1320,7 @@ def polynomial(self,names='x'): :: + sage: x = polygen(ZZ, 'x') sage: F. = NumberField(x^2 - 5) # optional - sage.rings.number_field sage: Z = F.ring_of_integers() # optional - sage.rings.number_field sage: Q = QuadraticForm(Z, 3, [2*a, 3*a, 0, 1 - a, 0, 2*a + 4]) # optional - sage.rings.number_field diff --git a/src/sage/quadratic_forms/quadratic_form__equivalence_testing.py b/src/sage/quadratic_forms/quadratic_form__equivalence_testing.py index 6196dde8558..5b0ff64b778 100644 --- a/src/sage/quadratic_forms/quadratic_form__equivalence_testing.py +++ b/src/sage/quadratic_forms/quadratic_form__equivalence_testing.py @@ -323,6 +323,7 @@ def is_rationally_isometric(self, other, return_matrix=False): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 3) # optional - sage.rings.number_field sage: V = QuadraticForm(K, 4, [1, 0, 0, 0, 2*a, 0, 0, a, 0, 2]); V # optional - sage.rings.number_field Quadratic form in 4 variables over Number Field in a diff --git a/src/sage/quadratic_forms/quadratic_form__local_field_invariants.py b/src/sage/quadratic_forms/quadratic_form__local_field_invariants.py index bec86a5afef..5c2beb6f7b6 100644 --- a/src/sage/quadratic_forms/quadratic_form__local_field_invariants.py +++ b/src/sage/quadratic_forms/quadratic_form__local_field_invariants.py @@ -434,6 +434,7 @@ def hasse_invariant(self, p): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 23) # optional - sage.rings.number_field sage: Q = DiagonalQuadraticForm(K, [-a, a + 2]) # optional - sage.rings.number_field sage: [Q.hasse_invariant(p) for p in K.primes_above(19)] # optional - sage.rings.number_field @@ -516,6 +517,7 @@ def hasse_invariant__OMeara(self, p): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 23) # optional - sage.rings.number_field sage: Q = DiagonalQuadraticForm(K, [-a, a + 2]) # optional - sage.rings.number_field sage: [Q.hasse_invariant__OMeara(p) for p in K.primes_above(19)] # optional - sage.rings.number_field diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index 4d4e9bfd104..54c88e4b462 100644 --- a/src/sage/rings/abc.pyx +++ b/src/sage/rings/abc.pyx @@ -376,8 +376,9 @@ class Order: EXAMPLES:: sage: import sage.rings.abc - sage: K. = NumberField(x^2 + 1); O = K.order(2*a) # optional - sage.rings.number_field - sage: isinstance(O, sage.rings.abc.Order) # optional - sage.rings.number_field + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 1); O = K.order(2*a) # optional - sage.rings.number_field + sage: isinstance(O, sage.rings.abc.Order) # optional - sage.rings.number_field True By design, there is a unique direct subclass:: diff --git a/src/sage/rings/complex_arb.pyx b/src/sage/rings/complex_arb.pyx index f17ff37893c..b871396fa29 100644 --- a/src/sage/rings/complex_arb.pyx +++ b/src/sage/rings/complex_arb.pyx @@ -101,8 +101,9 @@ Coercion Automatic coercions work as expected:: - sage: bpol = 1/3*CBF(i) + AA(sqrt(2)) + (polygen(RealBallField(20), 'x') + QQbar(i)) - sage: bpol + sage: bpol = 1/3*CBF(i) + AA(sqrt(2)) # optional - sage.symbolic + sage: bpol += polygen(RealBallField(20), 'x') + QQbar(i) # optional - sage.symbolic + sage: bpol # optional - sage.symbolic x + [1.41421 +/- ...e-6] + [1.33333 +/- ...e-6]*I sage: bpol.parent() Univariate Polynomial Ring in x over Complex ball field with 20 bits of precision @@ -549,6 +550,7 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField): sage: CBF.convert_map_from(QuadraticField(-2)) Conversion via _acb_ method map: ... + sage: x = polygen(ZZ, 'x') sage: CBF.coerce_map_from(NumberField(x^7 + 2, 'a', ....: embedding=QQbar(-2)^(1/7))) Conversion via _acb_ method map: diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index 4fc6c4c8d35..e35a362b3ef 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -464,6 +464,7 @@ class ComplexField_class(sage.rings.abc.ComplexField): 1.00000000000000*I sage: CC.gen() + QQ[I].gen() 2.00000000000000*I + sage: x = polygen(ZZ, 'x') sage: CC.gen() + QQ.extension(x^2 + 1, 'I', embedding=None).gen() Traceback (most recent call last): ... @@ -494,7 +495,8 @@ class ComplexField_class(sage.rings.abc.ComplexField): Check that :trac:`14989` is fixed:: - sage: QQi = NumberField(x^2+1, 'i', embedding=CC(0,1)) + sage: x = polygen(ZZ, 'x') + sage: QQi = NumberField(x^2 + 1, 'i', embedding=CC(0,1)) sage: i = QQi.order(QQi.gen()).gen(1) sage: CC(i) 1.00000000000000*I diff --git a/src/sage/rings/continued_fraction.py b/src/sage/rings/continued_fraction.py index c8a68cb309f..599af11ba3f 100644 --- a/src/sage/rings/continued_fraction.py +++ b/src/sage/rings/continued_fraction.py @@ -72,8 +72,9 @@ sage: continued_fraction_list(pi, nterms=5) [3, 7, 15, 1, 292] - sage: K. = NumberField(x^3 - 5, embedding=1.709) - sage: continued_fraction(cbrt5) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 5, embedding=1.709) # optional - sage.rings.number_field + sage: continued_fraction(cbrt5) # optional - sage.rings.number_field [1; 1, 2, 2, 4, 3, 3, 1, 5, 1, 1, 4, 10, 17, 1, 14, 1, 1, 3052, 1, ...] It is also possible to create a continued fraction from a list of partial @@ -621,9 +622,10 @@ def _mpfr_(self, R): sage: cf.n(digits=8) 0.63459101 - sage: K. = NumberField(x^3-2, 'a', embedding=1.25) - sage: b = 504/253*a^2 + 635/253*a + 661/253 - sage: cf = continued_fraction(b); cf + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 2, 'a', embedding=1.25) # optional - sage.rings.number_field + sage: b = 504/253*a^2 + 635/253*a + 661/253 # optional - sage.rings.number_field + sage: cf = continued_fraction(b); cf # optional - sage.rings.number_field [8; 1, 14, 1, 10, 2, 1, 4, 12, 2, 3, 2, 1, 3, 4, 1, 1, 2, 14, 3, ...] sage: cf.n(digits=3) 8.94 @@ -1913,11 +1915,12 @@ def quotient(self, n): The same computation with an element of a number field instead of ``pi`` gives a very satisfactory answer:: - sage: K. = NumberField(x^3 - 2, embedding=1.25) - sage: c2 = continued_fraction(a2) - sage: p0 = c2.numerator(111); q0 = c2.denominator(111) - sage: p1 = c2.numerator(112); q1 = c2.denominator(112) - sage: num = (q0*a2 - p0); num.n() + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 2, embedding=1.25) # optional - sage.rings.number_field + sage: c2 = continued_fraction(a2) # optional - sage.rings.number_field + sage: p0 = c2.numerator(111); q0 = c2.denominator(111) # optional - sage.rings.number_field + sage: p1 = c2.numerator(112); q1 = c2.denominator(112) # optional - sage.rings.number_field + sage: num = (q0*a2 - p0); num.n() # optional - sage.rings.number_field -4.56719261665907e46 sage: den = (q1*a2 - p1); den.n() -3.65375409332726e47 @@ -2565,9 +2568,10 @@ def continued_fraction(x, value=None): ``sqrt(2)`` above), it is much more convenient to use number fields as follows since preperiods and periods are computed:: - sage: K. = NumberField(x^2-5, embedding=2.23) - sage: my_golden_ratio = (1 + sqrt5)/2 - sage: cf = continued_fraction((1+sqrt5)/2); cf + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 5, embedding=2.23) # optional - sage.rings.number_field + sage: my_golden_ratio = (1 + sqrt5)/2 # optional - sage.rings.number_field + sage: cf = continued_fraction((1+sqrt5)/2); cf # optional - sage.rings.number_field [(1)*] sage: cf.convergent(12) 377/233 diff --git a/src/sage/rings/finite_rings/integer_mod.pyx b/src/sage/rings/finite_rings/integer_mod.pyx index ec3268dc84e..03d0e845402 100644 --- a/src/sage/rings/finite_rings/integer_mod.pyx +++ b/src/sage/rings/finite_rings/integer_mod.pyx @@ -609,7 +609,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): sage: sage_input(K(5), verify=True) # Verified GF(7)(5) - sage: sage_input(K(5) * polygen(K), verify=True) + sage: sage_input(K(5) * polygen(K), verify=True) # optional - sage.rings.finite_rings # Verified R. = GF(7)[] 5*x diff --git a/src/sage/rings/finite_rings/residue_field.pyx b/src/sage/rings/finite_rings/residue_field.pyx index 8396e320e6a..b92d7c7052a 100644 --- a/src/sage/rings/finite_rings/residue_field.pyx +++ b/src/sage/rings/finite_rings/residue_field.pyx @@ -7,6 +7,7 @@ polynomials over `GF(p)`. EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 7) # optional - sage.rings.number_field sage: P = K.ideal(29).factor()[0][0] # optional - sage.rings.number_field sage: k = K.residue_field(P) # optional - sage.rings.number_field @@ -215,6 +216,7 @@ class ResidueFieldFactory(UniqueFactory): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 7) # optional - sage.rings.number_field sage: P = K.ideal(29).factor()[0][0] # optional - sage.rings.number_field sage: ResidueField(P) # optional - sage.rings.number_field @@ -307,6 +309,7 @@ class ResidueFieldFactory(UniqueFactory): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 7) # optional - sage.rings.number_field sage: ResidueField(K.ideal(29).factor()[0][0]) # indirect doctest # optional - sage.rings.number_field Residue field in abar of Fractional ideal (2*a^2 + 3*a - 10) @@ -354,6 +357,7 @@ class ResidueFieldFactory(UniqueFactory): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 7) # optional - sage.rings.number_field sage: P = K.ideal(29).factor()[0][0] # optional - sage.rings.number_field sage: ResidueField(P) is ResidueField(P) # indirect doctest # optional - sage.rings.number_field @@ -485,6 +489,7 @@ class ResidueField_generic(Field): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 17) # optional - sage.rings.number_field sage: P = K.ideal(29).factor()[0][0] # optional - sage.rings.number_field sage: k = K.residue_field(P) # indirect doctest # optional - sage.rings.number_field @@ -550,6 +555,7 @@ class ResidueField_generic(Field): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + x + 1) # optional - sage.rings.number_field sage: P = K.ideal(29).factor()[0][0] # optional - sage.rings.number_field sage: k = K.residue_field(P) # indirect doctest # optional - sage.rings.number_field @@ -588,6 +594,7 @@ class ResidueField_generic(Field): EXAMPLES:: sage: from sage.rings.finite_rings.residue_field import ResidueField_generic + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field sage: P = K.ideal(-3*i - 2) # optional - sage.rings.number_field sage: OK = K.maximal_order() # optional - sage.rings.number_field @@ -633,6 +640,7 @@ class ResidueField_generic(Field): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field sage: P = K.ideal(-3*i - 2) # optional - sage.rings.number_field sage: OK = K.maximal_order() # optional - sage.rings.number_field @@ -663,6 +671,7 @@ class ResidueField_generic(Field): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 7) # optional - sage.rings.number_field sage: P = K.ideal(29).factor()[0][0] # optional - sage.rings.number_field sage: k = K.residue_field(P); k # optional - sage.rings.number_field @@ -687,6 +696,7 @@ class ResidueField_generic(Field): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 7) # optional - sage.rings.number_field sage: P = K.ideal(29).factor()[0][0] # optional - sage.rings.number_field sage: k = K.residue_field(P) # optional - sage.rings.number_field @@ -732,6 +742,7 @@ class ResidueField_generic(Field): sage: pi.codomain() # optional - sage.rings.number_field sage.symbolic Residue field of Fractional ideal (a) + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + x^2 - 2*x + 32) # optional - sage.rings.number_field sage: F = K.factor(2)[0][0].residue_field() # optional - sage.rings.number_field sage: F.reduction_map().domain() # optional - sage.rings.number_field @@ -800,6 +811,7 @@ class ResidueField_generic(Field): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 11) # optional - sage.rings.number_field sage: F = K.ideal(37).factor(); F # optional - sage.rings.number_field (Fractional ideal (37, a + 9)) * (Fractional ideal (37, a + 12)) * (Fractional ideal (-2*a + 5)) @@ -832,6 +844,7 @@ class ResidueField_generic(Field): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + x + 1) # optional - sage.rings.number_field sage: hash(K.residue_field(K.prime_above(17))) # random # optional - sage.rings.number_field -6463132282686559142 @@ -878,6 +891,7 @@ cdef class ReductionMap(Map): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + x^2 - 2*x + 8) # optional - sage.rings.number_field sage: F = K.factor(2)[0][0].residue_field() # optional - sage.rings.number_field sage: F.reduction_map() # optional - sage.rings.number_field @@ -919,6 +933,7 @@ cdef class ReductionMap(Map): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field sage: F = K.factor(2)[0][0].residue_field() # optional - sage.rings.number_field sage: r = F.reduction_map() # optional - sage.rings.number_field @@ -948,6 +963,7 @@ cdef class ReductionMap(Map): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field sage: F = K.factor(2)[0][0].residue_field() # optional - sage.rings.number_field sage: r = F.reduction_map() # optional - sage.rings.number_field @@ -980,6 +996,7 @@ cdef class ReductionMap(Map): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field sage: F = K.factor(2)[0][0].residue_field() # optional - sage.rings.number_field sage: r = F.reduction_map(); r # optional - sage.rings.number_field @@ -1091,6 +1108,7 @@ cdef class ReductionMap(Map): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^5 - 5*x + 2) # optional - sage.rings.number_field sage: P = K.ideal(47).factor()[0][0] # optional - sage.rings.number_field sage: k = K.residue_field(P) # optional - sage.rings.number_field @@ -1136,6 +1154,7 @@ cdef class ResidueFieldHomomorphism_global(RingHomomorphism): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 7) # optional - sage.rings.number_field sage: P = K.ideal(29).factor()[0][0] # optional - sage.rings.number_field sage: k = K.residue_field(P) # optional - sage.rings.number_field @@ -1211,6 +1230,7 @@ cdef class ResidueFieldHomomorphism_global(RingHomomorphism): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - x + 8) # optional - sage.rings.number_field sage: P = K.ideal(29).factor()[0][0] # optional - sage.rings.number_field sage: k = K.residue_field(P) # optional - sage.rings.number_field @@ -1241,6 +1261,7 @@ cdef class ResidueFieldHomomorphism_global(RingHomomorphism): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - x + 8) # optional - sage.rings.number_field sage: P = K.ideal(29).factor()[0][0] # optional - sage.rings.number_field sage: k = K.residue_field(P) # optional - sage.rings.number_field @@ -1270,6 +1291,7 @@ cdef class ResidueFieldHomomorphism_global(RingHomomorphism): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - x + 8) # optional - sage.rings.number_field sage: P = K.ideal(29).factor()[0][0] # optional - sage.rings.number_field sage: k = K.residue_field(P) # optional - sage.rings.number_field @@ -1309,6 +1331,7 @@ cdef class ResidueFieldHomomorphism_global(RingHomomorphism): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^5 - 5*x + 2) # optional - sage.rings.number_field sage: P = K.ideal(47).factor()[0][0] # optional - sage.rings.number_field sage: k = K.residue_field(P) # optional - sage.rings.number_field @@ -1353,6 +1376,7 @@ cdef class ResidueFieldHomomorphism_global(RingHomomorphism): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 7) # optional - sage.rings.number_field sage: P = K.ideal(29).factor()[0][0] # optional - sage.rings.number_field sage: k = K.residue_field(P) # optional - sage.rings.number_field @@ -1383,6 +1407,7 @@ cdef class LiftingMap(Section): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) # optional - sage.rings.number_field sage: F = K.factor(5)[0][0].residue_field() # optional - sage.rings.number_field sage: F.degree() # optional - sage.rings.number_field @@ -1420,6 +1445,7 @@ cdef class LiftingMap(Section): From: Residue field in theta_5bar of Fractional ideal (7) To: Maximal Order in Cyclotomic Field of order 5 and degree 4 + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^5 + 2) # optional - sage.rings.number_field sage: F = K.factor(7)[0][0].residue_field() # optional - sage.rings.number_field sage: L = F.lift_map(); L # optional - sage.rings.number_field diff --git a/src/sage/rings/finite_rings/residue_field_pari_ffelt.pyx b/src/sage/rings/finite_rings/residue_field_pari_ffelt.pyx index 29a16dc9047..f4e6ee10b1c 100644 --- a/src/sage/rings/finite_rings/residue_field_pari_ffelt.pyx +++ b/src/sage/rings/finite_rings/residue_field_pari_ffelt.pyx @@ -33,6 +33,7 @@ class ResidueFiniteField_pari_ffelt(ResidueField_generic, FiniteField_pari_ffelt EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 7) # optional - sage.rings.number_field sage: P = K.ideal(923478923).factor()[0][0] # optional - sage.rings.number_field sage: k = K.residue_field(P) # optional - sage.rings.number_field @@ -66,7 +67,8 @@ class ResidueFiniteField_pari_ffelt(ResidueField_generic, FiniteField_pari_ffelt We create a residue field with implementation ``pari_ffelt``:: - sage: K. = NumberField(x^3-7) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 7) sage: P = K.ideal(923478923).factor()[0][0] sage: type(P.residue_field()) @@ -92,6 +94,7 @@ class ResidueFiniteField_pari_ffelt(ResidueField_generic, FiniteField_pari_ffelt EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: P = K.factor(10007)[0][0] # optional - sage.rings.number_field sage: P.residue_class_degree() # optional - sage.rings.number_field diff --git a/src/sage/rings/function_field/valuation.py b/src/sage/rings/function_field/valuation.py index 022103e096d..0db45fb4d54 100644 --- a/src/sage/rings/function_field/valuation.py +++ b/src/sage/rings/function_field/valuation.py @@ -600,6 +600,7 @@ def element_with_valuation(self, s): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 6) # optional - sage.rings.number_field sage: v = K.valuation(2) # optional - sage.rings.number_field sage: R. = K[] # optional - sage.rings.number_field diff --git a/src/sage/rings/ideal.py b/src/sage/rings/ideal.py index 8c51c69a9ae..c474199eacd 100644 --- a/src/sage/rings/ideal.py +++ b/src/sage/rings/ideal.py @@ -506,6 +506,7 @@ def apply_morphism(self, phi): TESTS:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 1) sage: A = K.ideal(a) sage: taus = K.embeddings(K) @@ -1699,8 +1700,9 @@ def __repr__(self): EXAMPLES:: sage: from sage.rings.ideal import Ideal_fractional - sage: K. = NumberField(x^2 + 1) - sage: Ideal_fractional(K, [a]) # indirect doctest + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: Ideal_fractional(K, [a]) # indirect doctest # optional - sage.rings.number_field Fractional ideal (a) of Number Field in a with defining polynomial x^2 + 1 """ return "Fractional ideal %s of %s"%(self._repr_short(), self.ring()) diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 61c980557ff..bddeaa4b9fe 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -5492,7 +5492,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: K = NumberField(x^2 - 2, 'beta') # optional - sage.rings.number_field + sage: x = polygen(ZZ, 'x') + sage: K = NumberField(x^2 - 2, 'beta') # optional - sage.rings.number_field sage: n = 4 sage: n.is_norm(K) # optional - sage.rings.number_field True diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index 09b239a7dea..a39b6d07c9d 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -920,7 +920,8 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ.extension(x^2-5, 'a') + sage: x = polygen(ZZ, 'x') + sage: ZZ.extension(x^2 - 5, 'a') # optional - sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 5 sage: ZZ.extension([x^2 + 1, x^2 + 2], 'a,b') Relative Order in Number Field in a with defining polynomial diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index 84f288793d3..1b8bd3b8452 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -2404,10 +2404,11 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): TESTS:: - sage: A. = ZZ.extension(x^2 - 2) - sage: f = A.coerce_map_from(ZZ) - sage: g = f.extend_to_fraction_field() # indirect doctest - sage: g + sage: x = polygen(ZZ, 'x') + sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: f = A.coerce_map_from(ZZ) # optional - sage.rings.number_field + sage: g = f.extend_to_fraction_field() # indirect doctest # optional - sage.rings.number_field + sage: g # optional - sage.rings.number_field Ring morphism: From: Rational Field To: Number Field in a with defining polynomial x^2 - 2 diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index 978de36ce2d..09fec0aea59 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -313,10 +313,12 @@ def __init__(self, parent, x=0, prec=infinity, is_gen=False, check=False): sage: g.parent() Multivariate Power Series Ring in s, t over Rational Field - sage: K = NumberField(x-3,'a') - sage: g = K.random_element()*f - sage: g.parent() - Multivariate Power Series Ring in s, t over Number Field in a with defining polynomial x - 3 + sage: x = polygen(ZZ, 'x') + sage: K = NumberField(x - 3,'a') # optional - sage.rings.number_field + sage: g = K.random_element()*f # optional - sage.rings.number_field + sage: g.parent() # optional - sage.rings.number_field + Multivariate Power Series Ring in s, t over + Number Field in a with defining polynomial x - 3 TESTS:: diff --git a/src/sage/rings/number_field/S_unit_solver.py b/src/sage/rings/number_field/S_unit_solver.py index af226730584..0a083920875 100644 --- a/src/sage/rings/number_field/S_unit_solver.py +++ b/src/sage/rings/number_field/S_unit_solver.py @@ -22,7 +22,8 @@ EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import solve_S_unit_equation, eq_up_to_order - sage: K. = NumberField(x^2+x+1) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + x + 1) sage: S = K.primes_above(3) sage: expected = [((0, 1), (4, 0), xi + 2, -xi - 1), ....: ((1, -1), (0, -1), 1/3*xi + 2/3, -1/3*xi + 1/3), @@ -96,7 +97,8 @@ def column_Log(SUK, iota, U, prec=106): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import column_Log - sage: K. = NumberField(x^3-3) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 3) sage: S = tuple(K.primes_above(3)) sage: SUK = UnitGroup(K, S=S) sage: phi_complex = K.places()[1] @@ -130,7 +132,8 @@ def c3_func(SUK, prec=106): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import c3_func - sage: K. = NumberField(x^3-3) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 3) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: c3_func(SUK) # abs tol 1e-29 @@ -182,7 +185,8 @@ def c4_func(SUK, v, A, prec=106): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import c4_func - sage: K. = NumberField(x^3-3) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 3) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: phi_real = K.places()[0] sage: phi_complex = K.places()[1] @@ -220,7 +224,8 @@ def beta_k(betas_and_ns): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import beta_k - sage: K. = NumberField(x^3-3) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 3) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: v_fin = tuple(K.primes_above(3))[0] @@ -258,7 +263,8 @@ def mus(SUK, v): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import mus - sage: K. = NumberField(x^3-3) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 3) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: v_fin = tuple(K.primes_above(3))[0] @@ -297,7 +303,8 @@ def possible_mu0s(SUK, v): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import possible_mu0s - sage: K. = NumberField(x^3-3) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 3) sage: S = tuple(K.primes_above(3)) sage: SUK = UnitGroup(K, S=S) sage: v_fin = S[0] @@ -424,6 +431,7 @@ def Yu_condition_115(K, v): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import Yu_condition_115 + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 5) sage: v2 = K.primes_above(2)[0] sage: v11 = K.primes_above(11)[0] @@ -479,6 +487,7 @@ def Yu_modified_height(mu, n, v, prec=106): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 5) sage: v11 = K.primes_above(11)[0] sage: from sage.rings.number_field.S_unit_solver import Yu_modified_height @@ -531,6 +540,7 @@ def Omega_prime(dK, v, mu_list, prec=106): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import mus, Omega_prime + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 3) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(6))) sage: v = K.primes_above(3)[0] @@ -573,6 +583,7 @@ def Yu_C1_star(n, v, prec=106): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 5) sage: v11 = K.primes_above(11)[0] sage: from sage.rings.number_field.S_unit_solver import Yu_C1_star @@ -635,6 +646,7 @@ def Yu_bound(SUK, v, prec=106): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import Yu_bound + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 11) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(6))) sage: v = K.primes_above(3)[0] @@ -717,6 +729,7 @@ def K0_func(SUK, A, prec=106): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import K0_func + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 11) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(6))) sage: v = K.primes_above(3)[0] @@ -767,7 +780,8 @@ def c11_func(SUK, v, A, prec=106): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import c11_func - sage: K. = NumberField(x^3-3) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 3) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: phi_real = K.places()[0] sage: phi_complex = K.places()[1] @@ -807,7 +821,8 @@ def c13_func(SUK, v, prec=106): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import c13_func - sage: K. = NumberField(x^3-3) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 3) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: phi_real = K.places()[0] sage: phi_complex = K.places()[1] @@ -859,7 +874,8 @@ def K1_func(SUK, v, A, prec=106): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import K1_func - sage: K. = NumberField(x^3-3) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 3) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: phi_real = K.places()[0] sage: phi_complex = K.places()[1] @@ -1002,7 +1018,8 @@ def reduction_step_complex_case(place, B0, list_of_gens, torsion_gen, c13): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import reduction_step_complex_case - sage: K. = NumberField([x^3-2]) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField([x^3 - 2]) sage: SK = sum([K.primes_above(p) for p in [2,3,5]],[]) sage: G = [g for g in K.S_unit_group(S=SK).gens_values() if g.multiplicative_order()==Infinity] sage: p1 = K.places(prec=100)[1] @@ -1170,8 +1187,9 @@ def cx_LLL_bound(SUK, A, prec=106): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import cx_LLL_bound - sage: K. = NumberField(x^3-3) - sage: SUK = UnitGroup(K,S=tuple(K.primes_above(3))) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 3) + sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: A = K.roots_of_unity() sage: cx_LLL_bound(SUK,A) # long time @@ -1228,7 +1246,8 @@ def log_p(a, prime, prec): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import log_p - sage: K. = NumberField(x^2+14) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 14) sage: p1 = K.primes_above(3)[0] sage: p1 Fractional ideal (3, a + 1) @@ -1292,7 +1311,8 @@ def log_p_series_part(a, prime, prec): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import log_p_series_part - sage: K. = NumberField(x^2-5) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 5) sage: p1 = K.primes_above(3)[0] sage: p1 Fractional ideal (3) @@ -1459,7 +1479,8 @@ def embedding_to_Kp(a, prime, prec): :: - sage: K. = NumberField(x^4-2) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^4 - 2) sage: p = K.prime_above(7); p Fractional ideal (-a^2 + a - 1) sage: embedding_to_Kp(a^3-3, p, 15) @@ -1506,7 +1527,8 @@ def p_adic_LLL_bound_one_prime(prime, B0, M, M_logp, m0, c3, prec=106): sage: from sage.rings.number_field.S_unit_solver import p_adic_LLL_bound_one_prime sage: prec = 50 - sage: K. = NumberField(x^3-3) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 3) sage: S = tuple(K.primes_above(3)) sage: SUK = UnitGroup(K, S=S) sage: v = S[0] @@ -1639,8 +1661,9 @@ def p_adic_LLL_bound(SUK, A, prec=106): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import p_adic_LLL_bound - sage: K. = NumberField(x^3-3) - sage: SUK = UnitGroup(K,S=tuple(K.primes_above(3))) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 3) + sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: A = SUK.roots_of_unity() sage: prec = 100 sage: p_adic_LLL_bound(SUK,A, prec) @@ -1711,6 +1734,7 @@ def split_primes_large_lcm(SUK, bound): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import split_primes_large_lcm + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 3*x + 1) sage: S = K.primes_above(3) sage: SUK = UnitGroup(K,S=tuple(S)) @@ -1776,6 +1800,7 @@ def sieve_ordering(SUK, q): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import sieve_ordering + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 3*x + 1) sage: SUK = K.S_unit_group(S=3) sage: sieve_data = list(sieve_ordering(SUK, 19)) @@ -2132,6 +2157,7 @@ def construct_complement_dictionaries(split_primes_list, SUK, verbose=False): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import construct_complement_dictionaries + sage: x = polygen(ZZ, 'x') sage: f = x^2 + 5 sage: H = 10 sage: K. = NumberField(f) @@ -2565,7 +2591,8 @@ def solutions_from_systems(SUK, bound, cs_list, split_primes_list): Given a single compatible system, a solution can be found. :: sage: from sage.rings.number_field.S_unit_solver import solutions_from_systems - sage: K. = NumberField(x^2-15) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 15) sage: SUK = K.S_unit_group(S=K.primes_above(2)) sage: split_primes_list = [7, 17] sage: a_compatible_system = [[[(0, 0, 5), (0, 0, 5)], [(0, 0, 15), (0, 0, 15)]]] @@ -2649,8 +2676,9 @@ def sieve_below_bound(K, S, bound=10, bump=10, split_primes_list=[], verbose=Fal EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import sieve_below_bound, eq_up_to_order - sage: K. = NumberField(x^2+x+1) - sage: SUK = UnitGroup(K,S=tuple(K.primes_above(3))) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + x + 1) + sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: S = SUK.primes() sage: sols = sieve_below_bound(K, S, 10) sage: expected = [ @@ -2711,7 +2739,8 @@ def solve_S_unit_equation(K, S, prec=106, include_exponents=True, include_bound= EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import solve_S_unit_equation, eq_up_to_order - sage: K. = NumberField(x^2+x+1) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + x + 1) sage: S = K.primes_above(3) sage: sols = solve_S_unit_equation(K, S, 200) sage: expected = [ diff --git a/src/sage/rings/number_field/bdd_height.py b/src/sage/rings/number_field/bdd_height.py index d0f37a2b192..da81df5f824 100644 --- a/src/sage/rings/number_field/bdd_height.py +++ b/src/sage/rings/number_field/bdd_height.py @@ -69,6 +69,7 @@ def bdd_norm_pr_gens_iq(K, norm_list): norm 5, but no principal ideals of norm 7:: sage: from sage.rings.number_field.bdd_height import bdd_norm_pr_gens_iq + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: L = range(10) sage: bdd_pr_ideals = bdd_norm_pr_gens_iq(K, L) @@ -129,6 +130,7 @@ def bdd_height_iq(K, height_bound): EXAMPLES:: sage: from sage.rings.number_field.bdd_height import bdd_height_iq + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 191) sage: for t in bdd_height_iq(K,8): ....: print(exp(2*t.global_height())) @@ -253,6 +255,7 @@ def bdd_norm_pr_ideal_gens(K, norm_list): :: sage: from sage.rings.number_field.bdd_height import bdd_norm_pr_ideal_gens + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^5 - x + 19) sage: b = bdd_norm_pr_ideal_gens(K, range(30)) sage: key = ZZ(28) @@ -383,6 +386,7 @@ def bdd_height(K, height_bound, tolerance=1e-2, precision=53): There are no elements of negative height:: sage: from sage.rings.number_field.bdd_height import bdd_height + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^5 - x + 7) sage: list(bdd_height(K,-3)) [] diff --git a/src/sage/rings/number_field/class_group.py b/src/sage/rings/number_field/class_group.py index 32b00310b85..5d102f1ebe8 100644 --- a/src/sage/rings/number_field/class_group.py +++ b/src/sage/rings/number_field/class_group.py @@ -9,6 +9,7 @@ EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 23) sage: I = K.class_group().gen(); I Fractional ideal class (2, 1/2*a - 1/2) @@ -53,6 +54,7 @@ class FractionalIdealClass(AbelianGroupWithValuesElement): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: G = NumberField(x^2 + 23,'a').class_group(); G Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23 sage: I = G.0; I @@ -77,6 +79,7 @@ def __init__(self, parent, element, ideal=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 23,'a'); G = K.class_group() sage: G(K.ideal(13, a + 4)) Fractional ideal class (13, 1/2*a + 17/2) @@ -91,6 +94,7 @@ def _repr_(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 23,'a'); G = K.class_group() sage: G(K.ideal(13, a + 4))._repr_() 'Fractional ideal class (13, 1/2*a + 17/2)' @@ -107,6 +111,7 @@ def _mul_(self, other): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: G = NumberField(x^2 + 23,'a').class_group(); G Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23 sage: I = G.0; I @@ -134,6 +139,7 @@ def _div_(self, other): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: G = NumberField(x^2 + 23,'a').class_group(); G Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23 sage: I = G.0; I @@ -153,6 +159,7 @@ def __pow__(self, n): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 3*x + 8) sage: C=K.class_group() sage: c = C(2, a) @@ -178,6 +185,7 @@ def inverse(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 3*x + 8); G = K.class_group() sage: G(2, a).inverse() Fractional ideal class (2, a^2 + 2*a - 1) @@ -217,6 +225,7 @@ def reduce(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 20072); G = k.class_group(); G Class group of order 76 with structure C38 x C2 of Number Field in a with defining polynomial x^2 + 20072 @@ -258,27 +267,28 @@ def representative_prime(self, norm_bound=1000): EXAMPLES:: - sage: K. = NumberField(x^2+31) - sage: K.class_number() - 3 - sage: Cl = K.class_group() - sage: [c.representative_prime() for c in Cl] - [Fractional ideal (3), - Fractional ideal (2, 1/2*a + 1/2), - Fractional ideal (2, 1/2*a - 1/2)] - - sage: K. = NumberField(x^2+223) - sage: K.class_number() - 7 - sage: Cl = K.class_group() - sage: [c.representative_prime() for c in Cl] - [Fractional ideal (3), - Fractional ideal (2, 1/2*a + 1/2), - Fractional ideal (17, 1/2*a + 7/2), - Fractional ideal (7, 1/2*a - 1/2), - Fractional ideal (7, 1/2*a + 1/2), - Fractional ideal (17, 1/2*a + 27/2), - Fractional ideal (2, 1/2*a - 1/2)] + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 31) + sage: K.class_number() + 3 + sage: Cl = K.class_group() + sage: [c.representative_prime() for c in Cl] + [Fractional ideal (3), + Fractional ideal (2, 1/2*a + 1/2), + Fractional ideal (2, 1/2*a - 1/2)] + + sage: K. = NumberField(x^2 + 223) + sage: K.class_number() + 7 + sage: Cl = K.class_group() + sage: [c.representative_prime() for c in Cl] + [Fractional ideal (3), + Fractional ideal (2, 1/2*a + 1/2), + Fractional ideal (17, 1/2*a + 7/2), + Fractional ideal (7, 1/2*a - 1/2), + Fractional ideal (7, 1/2*a + 1/2), + Fractional ideal (17, 1/2*a + 27/2), + Fractional ideal (2, 1/2*a - 1/2)] """ if self.value().is_prime(): return self.value() @@ -401,6 +411,7 @@ class ClassGroup(AbelianGroupWithValues_class): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 23) sage: G = K.class_group(); G Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23 @@ -431,6 +442,7 @@ def __init__(self, gens_orders, names, number_field, gens, proof=True): TESTS:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 23) sage: G = K.class_group() sage: TestSuite(G).run() @@ -448,6 +460,7 @@ def _element_constructor_(self, *args, **kwds): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 389) sage: C = K.class_group() sage: C(K.ideal(b)) # indirect doctest @@ -482,7 +495,8 @@ def _ideal_log(self, ideal): EXAMPLES:: - sage: K. = NumberField(x^2 + 23,'a') + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 23, 'a') sage: G = K.class_group() sage: g = G.an_element() sage: G._ideal_log(g.ideal()) @@ -504,6 +518,7 @@ def gens_ideals(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 + 23) sage: K.class_group().gens_ideals() # random gens (platform dependent) (Fractional ideal (2, 1/4*a^3 - 1/4*a^2 + 1/4*a - 1/4),) @@ -524,6 +539,7 @@ def __iter__(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 + 23) sage: G = K.class_group() sage: G @@ -585,6 +601,7 @@ def _repr_(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: C = NumberField(x^2 + 23, 'a').class_group() sage: C._repr_() 'Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23' @@ -601,6 +618,7 @@ def number_field(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: C = NumberField(x^2 + 23, 'w').class_group(); C Class group of order 3 with structure C3 of Number Field in w with defining polynomial x^2 + 23 sage: C.number_field() diff --git a/src/sage/rings/number_field/galois_group.py b/src/sage/rings/number_field/galois_group.py index 1bf6189b7d9..9867144ca5f 100644 --- a/src/sage/rings/number_field/galois_group.py +++ b/src/sage/rings/number_field/galois_group.py @@ -11,6 +11,7 @@ Standard test of pickleability:: + sage: x = polygen(ZZ, 'x') sage: G = NumberField(x^3 + 2, 'alpha').galois_group(names='beta'); G Galois group 3T2 (S3) with order 6 of x^3 + 2 sage: G == loads(dumps(G)) @@ -65,6 +66,7 @@ def __init__(self, group, number_field): EXAMPLES:: sage: from sage.rings.number_field.galois_group import GaloisGroup_v1 + sage: x = polygen(ZZ, 'x') sage: K = NumberField([x^2 + 1, x^2 + 2],'a') sage: GaloisGroup_v1(K.absolute_polynomial().galois_group(pari_group=True), K) ...DeprecationWarning: GaloisGroup_v1 is deprecated; please use GaloisGroup_v2 @@ -87,6 +89,7 @@ def __eq__(self, other): EXAMPLES:: sage: from sage.rings.number_field.galois_group import GaloisGroup_v1 + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x^3 + 2, 'alpha') sage: G = GaloisGroup_v1(K.absolute_polynomial().galois_group(pari_group=True), K) ...DeprecationWarning: GaloisGroup_v1 is deprecated; please use GaloisGroup_v2 @@ -115,6 +118,7 @@ def __ne__(self, other): EXAMPLES:: sage: from sage.rings.number_field.galois_group import GaloisGroup_v1 + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x^3 + 2, 'alpha') sage: G = GaloisGroup_v1(K.absolute_polynomial().galois_group(pari_group=True), K) ...DeprecationWarning: GaloisGroup_v1 is deprecated; please use GaloisGroup_v2 @@ -137,6 +141,7 @@ def __repr__(self): EXAMPLES:: sage: from sage.rings.number_field.galois_group import GaloisGroup_v1 + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x^4 + 2*x + 2, 'a') sage: G = GaloisGroup_v1(K.absolute_polynomial().galois_group(pari_group=True), K) ...DeprecationWarning: GaloisGroup_v1 is deprecated; please use GaloisGroup_v2 @@ -154,6 +159,7 @@ def group(self): EXAMPLES:: sage: from sage.rings.number_field.galois_group import GaloisGroup_v1 + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x^3 + 2*x + 2, 'theta') sage: G = GaloisGroup_v1(K.absolute_polynomial().galois_group(pari_group=True), K) ...DeprecationWarning: GaloisGroup_v1 is deprecated; please use GaloisGroup_v2 @@ -174,6 +180,7 @@ def order(self): EXAMPLES:: sage: from sage.rings.number_field.galois_group import GaloisGroup_v1 + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x^5 + 2, 'theta_1') sage: G = GaloisGroup_v1(K.absolute_polynomial().galois_group(pari_group=True), K); G ...DeprecationWarning: GaloisGroup_v1 is deprecated; please use GaloisGroup_v2 @@ -191,6 +198,7 @@ def number_field(self): EXAMPLES:: sage: from sage.rings.number_field.galois_group import GaloisGroup_v1 + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x^6 + 2, 't') sage: G = GaloisGroup_v1(K.absolute_polynomial().galois_group(pari_group=True), K); G ...DeprecationWarning: GaloisGroup_v1 is deprecated; please use GaloisGroup_v2 @@ -220,6 +228,7 @@ class GaloisGroup_v2(GaloisGroup_perm): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: G = NumberField(x^3 - x - 1, 'a').galois_closure('b').galois_group() sage: G.subgroup([G([(1,2,3),(4,5,6)])]) Subgroup generated by [(1,2,3)(4,5,6)] of (Galois group 6T2 ([3]2) with order 6 of x^6 - 6*x^4 + 9*x^2 + 23) @@ -258,6 +267,7 @@ def __init__(self, number_field, algorithm='pari', names=None, gc_numbering=None You can specify the variable name for the Galois closure:: + sage: x = polygen(ZZ, 'x') sage: G = NumberField(x^3 - 2, 'b').galois_group(names="c"); G Galois group 3T2 (S3) with order 6 of x^3 - 2 sage: G._galois_closure @@ -300,6 +310,7 @@ def _pol_galgp(self, algorithm=None): EXAMPLES:: sage: R. = ZZ[] + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2*x + 2) sage: G = K.galois_group() sage: G._pol_galgp() @@ -320,6 +331,7 @@ def group(self): EXAMPLES:: sage: R. = ZZ[] + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2*x + 2) sage: G = K.galois_group(type="pari") ...DeprecationWarning: the different Galois types have been merged into one class @@ -340,6 +352,7 @@ def order(self, algorithm=None, recompute=False): EXAMPLES:: sage: R. = ZZ[] + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2*x + 2) sage: G = K.galois_group() sage: G.order() @@ -359,10 +372,12 @@ def easy_order(self, algorithm=None): EXAMPLES:: sage: R. = ZZ[] + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2*x + 2) sage: G = K.galois_group() sage: G.easy_order() 6 + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^72 + 2*x + 2) sage: H = L.galois_group() sage: H.easy_order() @@ -391,10 +406,12 @@ def transitive_number(self, algorithm=None, recompute=False): EXAMPLES:: sage: R. = ZZ[] + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2*x + 2) sage: G = K.galois_group() sage: G.transitive_number() 2 + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^13 + 2*x + 2) sage: H = L.galois_group(algorithm="gap") sage: H.transitive_number() # optional - gap_packages @@ -418,6 +435,7 @@ def pari_label(self): EXAMPLES:: sage: R. = ZZ[] + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^8 - x^5 + x^4 - x^3 + 1) sage: G = K.galois_group() sage: G.transitive_label() @@ -435,6 +453,7 @@ def signature(self): EXAMPLES:: sage: R. = ZZ[] + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: K.galois_group().signature() -1 @@ -460,6 +479,7 @@ def _gcdata(self): EXAMPLES:: sage: R. = ZZ[] + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: G = K.galois_group() sage: G._gcdata @@ -511,6 +531,7 @@ def _pari_data(self): EXAMPLES:: sage: R. = ZZ[] + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: G = K.galois_group() sage: G._pari_data @@ -526,6 +547,7 @@ def _elts(self): EXAMPLES:: sage: R. = ZZ[] + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: G = K.galois_group() sage: G._elts @@ -553,7 +575,8 @@ def _gens(self): EXAMPLES:: sage: R. = ZZ[] - sage: K. = NumberField(x^5-2) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^5 - 2) sage: G = K.galois_group(gc_numbering=False); G Galois group 5T3 (5:4) with order 20 of x^5 - 2 sage: G._gens @@ -645,6 +668,7 @@ def is_galois(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: NumberField(x^3 - x + 1,'a').galois_group(names='b').is_galois() False sage: NumberField(x^2 - x + 1,'a').galois_group().is_galois() @@ -666,6 +690,7 @@ def _repr_(self): sage: G = QuadraticField(-23, 'a').galois_group() sage: G._repr_() 'Galois group 2T1 (S2) with order 2 of x^2 + 23' + sage: x = polygen(ZZ, 'x') sage: G = NumberField(x^3 - 2, 'a').galois_group(names='b') sage: G._repr_() 'Galois group 3T2 (S3) with order 6 of x^3 - 2' @@ -689,6 +714,7 @@ def number_field(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x^3 - x + 1, 'a') sage: K.galois_group(names='b').number_field() is K True @@ -701,6 +727,7 @@ def list(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: NumberField(x^3 - 3*x + 1,'a').galois_group().list() [(), (1,2,3), (1,3,2)] """ @@ -717,12 +744,14 @@ def unrank(self, i): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: G = NumberField(x^3 - 3*x + 1,'a').galois_group() sage: [G.unrank(i) for i in range(G.cardinality())] [(), (1,2,3), (1,3,2)] TESTS:: + sage: x = polygen(ZZ, 'x') sage: G = NumberField(x^3 - 3*x + 1,'a').galois_group() sage: L = [G.unrank(i) for i in range(G.cardinality())] sage: L == G.list() @@ -736,6 +765,7 @@ def __iter__(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: G = NumberField(x^3 - 3*x + 1,'a').galois_group() sage: list(G) == G.list() True @@ -765,6 +795,7 @@ def _ramgroups(self, P): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 - 2*x^2 + 2,'b').galois_closure() sage: P = K.ideal([17, a^2]) sage: G = K.galois_group() @@ -788,7 +819,8 @@ def decomposition_group(self, P): EXAMPLES:: - sage: K. = NumberField(x^4 - 2*x^2 + 2,'b').galois_closure() + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^4 - 2*x^2 + 2, 'b').galois_closure() sage: P = K.ideal([17, a^2]) sage: G = K.galois_group() sage: G.decomposition_group(P) @@ -804,7 +836,8 @@ def decomposition_group(self, P): An example with an infinite place:: - sage: L. = NumberField(x^3 - 2,'a').galois_closure(); G=L.galois_group() + sage: x = polygen(ZZ, 'x') + sage: L. = NumberField(x^3 - 2,'a').galois_closure(); G = L.galois_group() sage: x = L.places()[0] sage: G.decomposition_group(x).order() 2 @@ -838,7 +871,8 @@ def complex_conjugation(self, P=None): An example where the field is not CM, so complex conjugation really depends on the choice of embedding:: - sage: L = NumberField(x^6 + 40*x^3 + 1372,'a') + sage: x = polygen(ZZ, 'x') + sage: L = NumberField(x^6 + 40*x^3 + 1372, 'a') sage: G = L.galois_group() sage: [G.complex_conjugation(x) for x in L.places()] [(1,3)(2,6)(4,5), (1,5)(2,4)(3,6), (1,2)(3,4)(5,6)] @@ -871,7 +905,8 @@ def ramification_group(self, P, v): EXAMPLES:: - sage: K. = NumberField(x^3 - 3,'a').galois_closure() + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 3, 'a').galois_closure() sage: G=K.galois_group() sage: P = K.primes_above(3)[0] sage: G.ramification_group(P, 3) @@ -896,7 +931,8 @@ def inertia_group(self, P): EXAMPLES:: - sage: K. = NumberField(x^2 - 3,'a') + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 3, 'a') sage: G = K.galois_group() sage: G.inertia_group(K.primes_above(2)[0]) Subgroup generated by [(1,2)] of (Galois group 2T1 (S2) with order 2 of x^2 - 3) @@ -915,6 +951,7 @@ def ramification_breaks(self, P): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^8 - 20*x^6 + 104*x^4 - 40*x^2 + 1156) sage: G = K.galois_group() sage: P = K.primes_above(2)[0] @@ -941,6 +978,7 @@ def artin_symbol(self, P): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 - 2*x^2 + 2, 'a').galois_closure() sage: G = K.galois_group() sage: [G.artin_symbol(P) for P in K.primes_above(7)] @@ -997,6 +1035,7 @@ class GaloisGroup_subgroup(GaloisSubgroup_perm): EXAMPLES:: sage: from sage.rings.number_field.galois_group import GaloisGroup_subgroup + sage: x = polygen(ZZ, 'x') sage: G = NumberField(x^3 - x - 1, 'a').galois_closure('b').galois_group() sage: GaloisGroup_subgroup( G, [G([(1,2,3),(4,5,6)])]) Subgroup generated by [(1,2,3)(4,5,6)] of (Galois group 6T2 ([3]2) with order 6 of x^6 - 6*x^4 + 9*x^2 + 23) @@ -1034,6 +1073,7 @@ def _pari_data(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^4 + 1) sage: G = L.galois_group() sage: H = G.decomposition_group(L.primes_above(3)[0]) @@ -1059,6 +1099,7 @@ def fixed_field(self, name=None, polred=None, threshold=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^4 + 1) sage: G = L.galois_group() sage: H = G.decomposition_group(L.primes_above(3)[0]) @@ -1138,6 +1179,7 @@ class GaloisGroupElement(PermutationGroupElement): sage: G[1](w + 2) -w + 2 + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^3 - 2); G = L.galois_group(names='y') sage: G[4] (1,5)(2,4)(3,6) @@ -1167,6 +1209,7 @@ def as_hom(self): polynomials are supported (:trac:`252`):: sage: R. = QQ[] + sage: x = polygen(ZZ, 'x') sage: f = 7/9*x^3 + 7/3*x^2 - 56*x + 123 sage: K. = NumberField(f) sage: G = K.galois_group() @@ -1211,6 +1254,7 @@ def ramification_degree(self, P): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 3, 'a').galois_closure() sage: G = K.galois_group() sage: P = K.primes_above(3)[0] diff --git a/src/sage/rings/number_field/homset.py b/src/sage/rings/number_field/homset.py index 6353353afe1..c1b1aa61843 100644 --- a/src/sage/rings/number_field/homset.py +++ b/src/sage/rings/number_field/homset.py @@ -43,6 +43,7 @@ def __init__(self, R, S, category=None): Check that :trac:`23647` is fixed:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 - 2, x^2 - 3]) sage: e, u, v, w = End(K) sage: e.abs_hom().parent().category() @@ -168,6 +169,7 @@ def order(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: End(k) Automorphism group of Number Field in a with defining polynomial x^2 + 1 @@ -192,6 +194,7 @@ def list(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 3*x + 1) sage: End(K).list() [ @@ -259,6 +262,7 @@ class RelativeNumberFieldHomset(NumberFieldHomset): We construct a homomorphism from a relative field by giving the image of a generator:: + sage: x = polygen(ZZ, 'x') sage: L. = CyclotomicField(3).extension(x^3 - 2) sage: phi = L.hom([cuberoot2 * zeta3]); phi Relative number field endomorphism of Number Field in cuberoot2 with defining polynomial x^3 - 2 over its base field @@ -300,6 +304,7 @@ def _element_constructor_(self, x, base_map=None, base_hom=None, check=True): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: L. = K.extension(x^4 - 2) sage: E = End(L) @@ -400,6 +405,7 @@ def _from_im(self, im_gen, base_map, check=True): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 23) sage: L. = K.extension(x^3 - x + 1) sage: End(L)._from_im( -3/23*a*b^2 + (-9/46*a - 1/2)*b + 2/23*a, K.hom([-a], K)) @@ -427,6 +433,7 @@ def default_base_hom(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^3 - x + 1, x^2 + 23]) sage: M. = NumberField(x^4 + 80*x^2 + 36) sage: Hom(L, M).default_base_hom() @@ -473,6 +480,7 @@ def list(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + x + 1, x^3 + 2]) sage: End(K).list() [ @@ -487,6 +495,7 @@ def list(self): An example with an absolute codomain:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 - 3, x^2 + 2]) sage: Hom(K, CyclotomicField(24, 'z')).list() [ @@ -584,6 +593,7 @@ def list(self): Automorphism group of Cyclotomic Field of order 12 and degree 4 sage: [g(z) for g in G] [z, z^3 - z, -z, -z^3 + z] + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 + x + 1, x^4 + 1]) sage: L Number Field in a with defining polynomial x^2 + x + 1 over its base field diff --git a/src/sage/rings/number_field/maps.py b/src/sage/rings/number_field/maps.py index 68d03c73af3..6adf85cc377 100644 --- a/src/sage/rings/number_field/maps.py +++ b/src/sage/rings/number_field/maps.py @@ -6,6 +6,7 @@ EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = CyclotomicField(3).extension(x^3 - 2) sage: K = L.absolute_field('a') sage: from_K, to_K = K.structure() @@ -54,6 +55,7 @@ class NumberFieldIsomorphism(Map): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 + 3*x + 1) sage: V, fr, to = K.vector_space() sage: isinstance(fr, sage.rings.number_field.maps.NumberFieldIsomorphism) @@ -63,6 +65,7 @@ def _repr_type(self): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 + 3*x + 1) sage: V, fr, to = K.vector_space() sage: fr._repr_type() @@ -74,10 +77,11 @@ def is_injective(self): r""" EXAMPLES:: - sage: K. = NumberField(x^4 + 3*x + 1) - sage: V, fr, to = K.vector_space() - sage: fr.is_injective() - True + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^4 + 3*x + 1) + sage: V, fr, to = K.vector_space() + sage: fr.is_injective() + True """ return True @@ -85,10 +89,11 @@ def is_surjective(self): r""" EXAMPLES:: - sage: K. = NumberField(x^4 + 3*x + 1) - sage: V, fr, to = K.vector_space() - sage: fr.is_surjective() - True + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^4 + 3*x + 1) + sage: V, fr, to = K.vector_space() + sage: fr.is_surjective() + True """ return True @@ -98,6 +103,7 @@ class MapVectorSpaceToNumberField(NumberFieldIsomorphism): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 + 3*x + 1) sage: V, fr, to = K.vector_space() sage: V @@ -154,6 +160,7 @@ def __init__(self, V, K): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^9 + 3) sage: V, fr, to = K.vector_space(); fr # indirect doctest Isomorphism map: @@ -168,6 +175,7 @@ def _call_(self, v): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^9 + 3) sage: V, fr, to = K.vector_space() sage: list(map(fr, V.gens())) # indirect doctest @@ -184,6 +192,7 @@ class MapNumberFieldToVectorSpace(Map): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^3 - x + 1) sage: V, fr, to = L.vector_space() sage: type(to) @@ -195,6 +204,7 @@ def __init__(self, K, V): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^3 - x + 1) sage: L.vector_space()[2] # indirect doctest Isomorphism map: @@ -207,6 +217,7 @@ def _repr_type(self): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 + 1, x^2 - 3]) sage: V, fr, to = L.relative_vector_space() sage: fr._repr_type() @@ -218,6 +229,7 @@ def _call_(self, x): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^3 - x + 1) sage: V, _, to = L.vector_space() sage: v = to(a^2 - a/37 + 56); v # indirect doctest @@ -235,6 +247,7 @@ class MapRelativeVectorSpaceToRelativeNumberField(NumberFieldIsomorphism): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^4 + 3*x^2 + 1) sage: K = L.relativize(L.subfields(2)[0][1], 'a'); K Number Field in a with defining polynomial x^2 - b0*x + 1 over its base field @@ -261,6 +274,7 @@ def __init__(self, V, K): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 1, x^2 - 2]) sage: V, _, to = K.relative_vector_space(); to # indirect doctest Isomorphism map: @@ -273,6 +287,7 @@ def _call_(self, v): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^4 + 3*x^2 + 1) sage: K = L.relativize(L.subfields(2)[0][1], 'a') sage: a0 = K.gen(); b0 = K.base_field().gen() @@ -295,6 +310,7 @@ class MapRelativeNumberFieldToRelativeVectorSpace(NumberFieldIsomorphism): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^3 - x + 1, x^2 + 23]) sage: V, fr, to = K.relative_vector_space() sage: type(to) @@ -305,6 +321,7 @@ def __init__(self, K, V): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^4 + 3*x^2 + 1) sage: K = L.relativize(L.subfields(2)[0][1], 'a') sage: V, fr, to = K.relative_vector_space() @@ -319,7 +336,8 @@ def _call_(self, alpha): """ TESTS:: - sage: K. = NumberField(x^5+2) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^5 + 2) sage: R. = K[] sage: D. = K.extension(y + a + 1) sage: D(a) @@ -368,6 +386,7 @@ class NameChangeMap(NumberFieldIsomorphism): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 3) sage: L. = K.change_names() sage: from_L, to_L = L.structure() @@ -386,6 +405,7 @@ def __init__(self, K, L): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 - 3, x^2 + 7]) sage: L. = K.change_names() sage: L.structure() @@ -401,6 +421,7 @@ def _repr_type(self): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 3) sage: L. = K.change_names() sage: from_L, to_L = L.structure() @@ -413,6 +434,7 @@ def _call_(self, x): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 - 3, x^2 + 7]) sage: L. = K.change_names() sage: to_K, from_K = L.structure() @@ -428,6 +450,7 @@ class MapRelativeToAbsoluteNumberField(NumberFieldIsomorphism): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^6 + 4*x^2 + 200) sage: L = K.relativize(K.subfields(3)[0][1], 'b'); L Number Field in b with defining polynomial x^2 + a0 over its base field @@ -473,6 +496,7 @@ def __init__(self, R, A): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 + 3, x^2 + 5]) sage: K. = L.absolute_field() sage: f = K.structure()[1]; f @@ -488,6 +512,7 @@ def _call_(self, x): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 + 3, x^2 + 5]) sage: K. = L.absolute_field() sage: f = K.structure()[1] @@ -506,6 +531,7 @@ def __init__(self, A, R): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 + 3, x^2 + 5]) sage: K. = L.absolute_field() sage: f = K.structure()[0] # indirect doctest @@ -518,6 +544,7 @@ def _call_(self, x): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 + 3, x^2 + 5]) sage: K. = L.absolute_field() sage: f = K.structure()[0] @@ -535,6 +562,7 @@ class MapVectorSpaceToRelativeNumberField(NumberFieldIsomorphism): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 + 3, x^2 + 5]) sage: V, fr, to = L.absolute_vector_space() sage: type(fr) @@ -545,6 +573,7 @@ def __init__(self, V, L, from_V, from_K): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 + 3, x^2 + 5]) sage: V, fr, to = L.absolute_vector_space() # indirect doctest sage: fr @@ -560,6 +589,7 @@ def _call_(self, x): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 + 3, x^2 + 5]) sage: V, fr, to = L.absolute_vector_space() sage: fr(V([1,3,0,1/17])) # indirect doctest @@ -576,6 +606,7 @@ class MapRelativeNumberFieldToVectorSpace(NumberFieldIsomorphism): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^8 + 100*x^6 + x^2 + 5) sage: L = K.relativize(K.subfields(4)[0][1], 'b'); L Number Field in b with defining polynomial x^2 + a0 over its base field @@ -606,6 +637,7 @@ def __init__(self, L, V, to_K, to_V): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 + 3, x^2 + 5]) sage: V, fr, to = L.absolute_vector_space() # indirect doctest sage: to @@ -621,6 +653,7 @@ def _call_(self, x): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 + 3, x^2 + 5]) sage: V, fr, to = L.absolute_vector_space() sage: to(1 + 2*a + 3*b + 4*a*b) # indirect doctest diff --git a/src/sage/rings/number_field/morphism.py b/src/sage/rings/number_field/morphism.py index 174252dad61..b81d66be294 100644 --- a/src/sage/rings/number_field/morphism.py +++ b/src/sage/rings/number_field/morphism.py @@ -30,6 +30,7 @@ def __invert__(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 5) sage: tau1, tau2 = K.automorphisms(); tau1, tau2 (Ring endomorphism of Number Field in a with defining polynomial x^2 + 5 @@ -100,6 +101,7 @@ def preimage(self, y): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 7) sage: L. = NumberField(x^4 - 7) sage: f = K.embeddings(L)[0] @@ -153,7 +155,8 @@ def __init__(self, parent, abs_hom): r""" EXAMPLES:: - sage: K. = NumberField( [x^3 + 2, x^2 + x + 1] ) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField([x^3 + 2, x^2 + x + 1]) sage: f = K.hom(-a*b - a, K); f Relative number field endomorphism of Number Field in a with defining polynomial x^3 + 2 over its base field Defn: a |--> (-b - 1)*a @@ -174,7 +177,8 @@ def abs_hom(self): EXAMPLES:: - sage: K. = NumberField( [x^3 + 2, x^2 + x + 1] ) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField([x^3 + 2, x^2 + x + 1]) sage: K.hom(a, K).abs_hom() Ring morphism: From: Number Field in a with defining polynomial x^6 - 3*x^5 + 6*x^4 - 3*x^3 - 9*x + 9 @@ -189,7 +193,8 @@ def _repr_type(self): EXAMPLES:: - sage: K. = NumberField( [x^3 + 2, x^2 + x + 1] ) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField([x^3 + 2, x^2 + x + 1]) sage: K.hom(a, K)._repr_type() 'Relative number field' """ @@ -202,7 +207,8 @@ def im_gens(self): EXAMPLES:: - sage: K. = NumberField( [x^3 + 2, x^2 + x + 1] ) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField([x^3 + 2, x^2 + x + 1]) sage: K.hom(a, K).im_gens() [a, b] """ @@ -216,6 +222,7 @@ def _richcmp_(self, other, op): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 - 2, x^2 - 3]) sage: e, u, v, w = End(K) sage: all([u^2 == e, u*v == w, u != e]) @@ -229,7 +236,8 @@ def _repr_defn(self): EXAMPLES:: - sage: K. = NumberField( [x^3 + 2, x^2 + x + 1] ) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField([x^3 + 2, x^2 + x + 1]) sage: K.hom(a, K)._repr_defn() 'a |--> a\nb |--> b' """ @@ -248,7 +256,8 @@ def _call_(self, x): EXAMPLES:: - sage: K. = NumberField( [x^3 + 2, x^2 + x + 1] ) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField([x^3 + 2, x^2 + x + 1]) sage: K.hom(a*b, K)(17 + 3*a + 2*b) # indirect doctest 3*b*a + 2*b + 17 """ diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py index 1627b841c30..4abae320d1a 100644 --- a/src/sage/rings/number_field/number_field.py +++ b/src/sage/rings/number_field/number_field.py @@ -47,6 +47,7 @@ This example follows one in the Magma reference manual:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 - 420*x^2 + 40000) sage: z = y^5/11; z 420/11*y^3 - 40000/11*y @@ -181,6 +182,7 @@ def is_NumberFieldHomsetCodomain(codomain): sage: from sage.rings.number_field.number_field import is_NumberFieldHomsetCodomain sage: is_NumberFieldHomsetCodomain(QQ) True + sage: x = polygen(ZZ, 'x') sage: is_NumberFieldHomsetCodomain(NumberField(x^2 + 1, 'x')) True sage: is_NumberFieldHomsetCodomain(ZZ) @@ -305,6 +307,7 @@ def NumberField(polynomial, name=None, check=True, names=None, embedding=None, Constructing a relative number field:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 2) sage: R. = K[] sage: L. = K.extension(t^3+t+a); L @@ -756,7 +759,8 @@ def NumberFieldTower(polynomials, names, check=True, embeddings=None, latex_name EXAMPLES:: - sage: k. = NumberField([x^2 + 1, x^2 + 3, x^2 + 5]); k # indirect doctest + sage: x = polygen(ZZ, 'x') + sage: k. = NumberField([x^2 + 1, x^2 + 3, x^2 + 5]); k # indirect doctest Number Field in a with defining polynomial x^2 + 1 over its base field sage: a^2 -1 @@ -1028,7 +1032,8 @@ def is_AbsoluteNumberField(x): EXAMPLES:: sage: from sage.rings.number_field.number_field import is_AbsoluteNumberField - sage: is_AbsoluteNumberField(NumberField(x^2+1,'a')) + sage: x = polygen(ZZ, 'x') + sage: is_AbsoluteNumberField(NumberField(x^2 + 1, 'a')) True sage: is_AbsoluteNumberField(NumberField([x^3 + 17, x^2+1],'a')) False @@ -1060,6 +1065,7 @@ def is_QuadraticField(x) -> bool: use isinstance(..., sage.rings.abc.NumberField_quadratic instead See https://github.com/sagemath/sage/issues/32660 for details. True + sage: x = polygen(ZZ, 'x') sage: is_QuadraticField(NumberField(x^2 - 5, 'b')) True sage: is_QuadraticField(NumberField(x^3 - 5, 'b')) @@ -1251,6 +1257,7 @@ def is_CyclotomicField(x) -> bool: EXAMPLES:: sage: from sage.rings.number_field.number_field import is_CyclotomicField + sage: x = polygen(ZZ, 'x') sage: is_CyclotomicField(NumberField(x^2 + 1,'zeta4')) doctest:warning... DeprecationWarning: is_CyclotomicField is deprecated; @@ -1284,6 +1291,7 @@ class NumberField_generic(WithEqualityById, number_field_base.NumberField): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2); K Number Field in a with defining polynomial x^3 - 2 sage: TestSuite(K).run() @@ -1397,6 +1405,7 @@ def __init__(self, polynomial, name, latex_name, EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: NumberField(x^97 - 19, 'a') Number Field in a with defining polynomial x^97 - 19 @@ -1503,6 +1512,7 @@ def _convert_map_from_(self, other): This also works for relative number fields and their absolute fields:: sage: K. = QuadraticField(2) + sage: x = polygen(ZZ, 'x') sage: L. = K.extension(x^2 + 1) sage: M. = L.absolute_field() sage: M(i) @@ -1595,8 +1605,9 @@ def construction(self): EXAMPLES:: - sage: K.=NumberField(x^3+x^2+1,embedding=CC.gen()) - sage: F,R = K.construction() + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 + x^2 + 1, embedding=CC.gen()) + sage: F, R = K.construction() sage: F AlgebraicExtensionFunctor sage: R @@ -1673,6 +1684,7 @@ def _element_constructor_(self, x, check=True): TESTS:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 17) sage: K(a) is a # indirect doctest True @@ -1847,6 +1859,7 @@ def _convert_non_number_field_element(self, x): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^3 + 2/3) sage: K._convert_non_number_field_element(-7/8) -7/8 @@ -1990,7 +2003,8 @@ def _convert_from_str(self, x): EXAMPLES:: - sage: k. = NumberField(x^3+(2/3)*x+1) + sage: x = polygen(ZZ, 'x') + sage: k. = NumberField(x^3 + (2/3)*x + 1) sage: k._convert_from_str('theta25^3 + (1/3)*theta25') -1/3*theta25 - 1 @@ -2015,6 +2029,7 @@ def _Hom_(self, codomain, category=None): This method is implicitly called by :meth:`Hom` and :meth:`sage.categories.homset.Hom`:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1); K Number Field in i with defining polynomial x^2 + 1 sage: K.Hom(K) # indirect doctest @@ -2059,6 +2074,7 @@ def structure(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 3) sage: L. = K.absolute_field(); L Number Field in a with defining polynomial x^2 + 3 @@ -2119,6 +2135,7 @@ def primitive_element(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: K.primitive_element() a @@ -2168,7 +2185,8 @@ def random_element(self, num_bound=None, den_bound=None, EXAMPLES:: - sage: K. = NumberField(x^8+1) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^8 + 1) sage: K.random_element().parent() is K True @@ -2240,6 +2258,7 @@ def subfield(self, alpha, name=None, names=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 - 3); K Number Field in a with defining polynomial x^4 - 3 sage: H., from_H = K.subfield(a^2) @@ -2326,6 +2345,7 @@ def change_generator(self, alpha, name=None, names=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^2 + 1); L Number Field in i with defining polynomial x^2 + 1 sage: K, from_K, to_K = L.change_generator(i/2 + 3) @@ -2571,6 +2591,7 @@ def is_relative(self): """ EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^10 - 2) sage: K.is_absolute() True @@ -2597,6 +2618,7 @@ def quadratic_defect(self, a, p, check=True): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 2) sage: p = K.primes_above(2)[0] sage: K.quadratic_defect(5, p) @@ -2684,6 +2706,7 @@ def is_isomorphic(self, other, isomorphism_maps=False) -> bool: EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 1) sage: m. = NumberField(x^2 + 4) sage: k.is_isomorphic(m) @@ -2747,7 +2770,8 @@ def is_totally_real(self): EXAMPLES:: - sage: NumberField(x^2+2, 'alpha').is_totally_real() + sage: x = polygen(QQ, 'x') + sage: NumberField(x^2 + 2, 'alpha').is_totally_real() False sage: NumberField(x^2-2, 'alpha').is_totally_real() True @@ -2765,7 +2789,8 @@ def is_totally_imaginary(self): EXAMPLES:: - sage: NumberField(x^2+2, 'alpha').is_totally_imaginary() + sage: x = polygen(QQ, 'x') + sage: NumberField(x^2 + 2, 'alpha').is_totally_imaginary() True sage: NumberField(x^2-2, 'alpha').is_totally_imaginary() False @@ -2781,6 +2806,7 @@ def is_CM(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: Q. = NumberField(x - 1) sage: Q.is_CM() False @@ -2915,7 +2941,9 @@ def complex_conjugation(self): Ring endomorphism of Cyclotomic Field of order 8 and degree 4 Defn: zeta8 |--> -zeta8^3 sage: QuadraticField(5, 'a').complex_conjugation() - Identity endomorphism of Number Field in a with defining polynomial x^2 - 5 with a = 2.236067977499790? + Identity endomorphism of Number Field in a with defining + polynomial x^2 - 5 with a = 2.236067977499790? + sage: x = polygen(QQ, 'x') sage: F = NumberField(x^4 + x^3 - 3*x^2 - x + 1, 'a') sage: F.is_totally_real() True @@ -3010,7 +3038,10 @@ def maximal_totally_real_subfield(self): Ring morphism: From: Number Field in a0 with defining polynomial x^14 + x^13 - 13*x^12 - 12*x^11 + 66*x^10 + 55*x^9 - 165*x^8 - 120*x^7 + 210*x^6 + 126*x^5 - 126*x^4 - 56*x^3 + 28*x^2 + 7*x - 1 with a0 = 1.953241111420174? To: Cyclotomic Field of order 29 and degree 28 - Defn: a0 |--> -a^27 - a^26 - a^25 - a^24 - a^23 - a^22 - a^21 - a^20 - a^19 - a^18 - a^17 - a^16 - a^15 - a^14 - a^13 - a^12 - a^11 - a^10 - a^9 - a^8 - a^7 - a^6 - a^5 - a^4 - a^3 - a^2 - 1) + Defn: a0 |--> -a^27 - a^26 - a^25 - a^24 - a^23 - a^22 - a^21 - a^20 - a^19 + - a^18 - a^17 - a^16 - a^15 - a^14 - a^13 - a^12 - a^11 - a^10 + - a^9 - a^8 - a^7 - a^6 - a^5 - a^4 - a^3 - a^2 - 1) + sage: x = polygen(QQ, 'x') sage: F. = NumberField(x^3 - 2) sage: F.maximal_totally_real_subfield() [Rational Field, Coercion map: @@ -3107,6 +3138,7 @@ def complex_embeddings(self, prec=53): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^5 + x + 17) sage: v = k.complex_embeddings() sage: ls = [phi(k.0^2) for phi in v] ; ls # random order @@ -3153,6 +3185,7 @@ def real_embeddings(self, prec=53): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^3 + 2) sage: K.real_embeddings() [ @@ -3230,7 +3263,8 @@ def specified_complex_embedding(self): Most fields don't implicitly have embeddings unless explicitly specified:: - sage: NumberField(x^2-2, 'a').specified_complex_embedding() is None + sage: x = polygen(QQ, 'x') + sage: NumberField(x^2 - 2, 'a').specified_complex_embedding() is None True sage: NumberField(x^3-x+5, 'a').specified_complex_embedding() is None True @@ -3272,7 +3306,8 @@ def gen_embedding(self): sage: QuadraticField(-7, 'a').gen_embedding() 2.645751311064591?*I - sage: NumberField(x^2+7, 'a').gen_embedding() # None + sage: x = polygen(QQ, 'x') + sage: NumberField(x^2 + 7, 'a').gen_embedding() # None """ embedding = self.coerce_embedding() if embedding is None: @@ -3289,7 +3324,8 @@ def algebraic_closure(self): sage: K. = QuadraticField(-1) sage: K.algebraic_closure() Algebraic Field - sage: K. = NumberField(x^3-2) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^3 - 2) sage: K.algebraic_closure() Algebraic Field sage: K = CyclotomicField(23) @@ -3320,7 +3356,8 @@ def conductor(self, check_abelian=True): sage: k = K.subfields(9)[0][0] sage: k.conductor() 27 - sage: K. = NumberField(x^3+x^2-2*x-1) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^3 + x^2 - 2*x - 1) sage: K.conductor() 7 sage: K. = NumberField(x^3+x^2-36*x-4) @@ -3387,7 +3424,8 @@ def dirichlet_group(self): EXAMPLES:: - sage: K. = NumberField(x^3+x^2-36*x-4) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^3 + x^2 - 36*x - 4) sage: K.conductor() 109 sage: K.dirichlet_group() @@ -3434,6 +3472,7 @@ def latex_variable_name(self, name=None): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: NumberField(x^2 + 3, 'a').latex_variable_name() doctest:...: DeprecationWarning: This method is replaced by ... See https://github.com/sagemath/sage/issues/30372 for details. @@ -3455,6 +3494,7 @@ def _repr_(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^13 - (2/3)*x + 3) sage: k._repr_() 'Number Field in a with defining polynomial x^13 - 2/3*x + 3' @@ -3476,6 +3516,7 @@ def _latex_(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^13 - (2/3)*x + 3) sage: k._latex_() '\\Bold{Q}[a]/(a^{13} - \\frac{2}{3} a + 3)' @@ -3502,6 +3543,7 @@ def _ideal_class_(self, n=0): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: NumberField(x^2 + 2, 'c')._ideal_class_() """ @@ -3519,6 +3561,7 @@ def _fractional_ideal_class_(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: NumberField(x^2 + 2, 'c')._fractional_ideal_class_() """ @@ -3531,7 +3574,8 @@ def ideal(self, *gens, **kwds): EXAMPLES:: - sage: K.=NumberField(x^2+1) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^2 + 1) sage: K.ideal(2) Fractional ideal (2) sage: K.ideal(2+i) @@ -3629,7 +3673,8 @@ def fractional_ideal(self, *gens, **kwds): EXAMPLES:: - sage: K. = NumberField(x^3-2) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^3 - 2) sage: K.fractional_ideal([1/a]) Fractional ideal (1/2*a^2) @@ -3682,6 +3727,7 @@ def ideals_of_bdd_norm(self, bound): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 23) sage: d = K.ideals_of_bdd_norm(10) sage: for n in d: @@ -3948,7 +3994,8 @@ def primes_of_bounded_norm(self, B): [Fractional ideal (i + 1), Fractional ideal (-i - 2), Fractional ideal (2*i + 1), Fractional ideal (3)] sage: K.primes_of_bounded_norm(1) [] - sage: K. = NumberField(x^3-2) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^3 - 2) sage: P = K.primes_of_bounded_norm(30) sage: P [Fractional ideal (a), @@ -4135,6 +4182,7 @@ def completely_split_primes(self, B=200): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^3 - 3*x + 1) sage: K.completely_split_primes(100) [17, 19, 37, 53, 71, 73, 89] @@ -4163,6 +4211,7 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 - 3) sage: k._is_valid_homomorphism_(QQ, [0]) False @@ -4217,6 +4266,7 @@ def _pari_absolute_structure(self): If `f` is monic and integral, the result satisfies ``g = f`` and ``alpha = beta = x``:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 - 2) sage: K._pari_absolute_structure() (y^2 - 2, Mod(y, y^2 - 2), Mod(y, y^2 - 2)) @@ -4268,6 +4318,7 @@ def pari_polynomial(self, name='x'): Some examples with relative number fields:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField([x^2 + 3, x^2 + 1]) sage: k.pari_polynomial() x^4 + 8*x^2 + 4 @@ -4323,6 +4374,7 @@ def pari_nf(self, important=True): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^4 - 3*x + 7); k Number Field in a with defining polynomial x^4 - 3*x + 7 sage: k.pari_nf()[:4] @@ -4382,6 +4434,7 @@ def pari_zk(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 - 17) sage: k.pari_zk() [1, 1/3*y^2 - 1/3*y + 1/3, y] @@ -4396,6 +4449,7 @@ def __pari__(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k = NumberField(x^2 + x + 1, 'a') sage: k.__pari__() [y^2 + y + 1, [0, 1], -3, 1, ... [1, y], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, -1]] @@ -4410,6 +4464,7 @@ def _pari_init_(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k = NumberField(x^2 + x + 1, 'a') sage: k._pari_init_() '[y^2 + y + 1, [0, 1], -3, 1, ... [1, y], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, -1]]' @@ -4443,6 +4498,7 @@ def pari_bnf(self, proof=None, units=True): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 1); k Number Field in a with defining polynomial x^2 + 1 sage: len(k.pari_bnf()) @@ -4544,6 +4600,7 @@ def characteristic(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^99 + 2); k Number Field in a with defining polynomial x^99 + 2 sage: k.characteristic() @@ -4571,6 +4628,7 @@ def class_group(self, proof=None, names='c'): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 23) sage: G = K.class_group(); G Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23 @@ -4642,6 +4700,7 @@ def class_number(self, proof=None): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: NumberField(x^2 + 23, 'a').class_number() 3 sage: NumberField(x^2 + 163, 'a').class_number() @@ -4736,6 +4795,7 @@ def S_units(self, S, proof=True): An example in a relative extension (see :trac:`8722`):: + sage: x = polygen(QQ, 'x') sage: L. = NumberField([x^2 + 1, x^2 - 5]) sage: p = L.ideal((-1/2*b - 1/2)*a + 1/2*b - 1/2) sage: W = L.S_units([p]); [x.norm() for x in W] @@ -4789,7 +4849,8 @@ def _S_class_group_and_units(self, S, proof=True): EXAMPLES:: - sage: K. = NumberField(x^2+5) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^2 + 5) sage: K._S_class_group_and_units(()) ([-1], [(Fractional ideal (2, a + 1), 2)]) @@ -4990,6 +5051,7 @@ def selmer_generators(self, S, m, proof=True, orders=False): Verify that :trac:`14489` is fixed; the representation depends on the PARI version:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^3 - 381 * x + 127) sage: gens = K.selmer_generators(K.primes_above(13), 2) sage: len(gens) == 8 @@ -5197,6 +5259,7 @@ def selmer_space(self, S, p, proof=None): Vector space of dimension 2 over Finite Field of size 2 sage: gens [2, -1] + sage: x = polygen(ZZ, 'x') sage: for v in KS2: ....: if not v: ....: continue @@ -5260,6 +5323,7 @@ def composite_fields(self, other, names=None, both_maps=False, preserve_embeddin EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^4 - 2) sage: K.composite_fields(K) [Number Field in a with defining polynomial x^4 - 2, @@ -5592,6 +5656,7 @@ def absolute_degree(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: NumberField(x^3 + x^2 + 997*x + 1, 'a').absolute_degree() 3 sage: NumberField(x + 1, 'a').absolute_degree() @@ -5607,6 +5672,7 @@ def degree(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: NumberField(x^3 + x^2 + 997*x + 1, 'a').degree() 3 sage: NumberField(x + 1, 'a').degree() @@ -5631,6 +5697,7 @@ def different(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 23) sage: d = k.different() sage: d @@ -5677,6 +5744,7 @@ def discriminant(self, v=None): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^3 + x^2 - 2*x + 8) sage: K.disc() -503 @@ -5704,6 +5772,7 @@ def disc(self, v=None): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 - 123) sage: k.disc() 492 @@ -5716,6 +5785,7 @@ def trace_dual_basis(self, b): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^3 + x + 1) sage: b = [1, 2*a, 3*a^2] sage: T = K.trace_dual_basis(b); T @@ -5748,7 +5818,8 @@ def elements_of_norm(self, n, proof=None) -> list: EXAMPLES:: - sage: K. = NumberField(x^2+1) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^2 + 1) sage: K.elements_of_norm(3) [] sage: K.elements_of_norm(50) @@ -5776,6 +5847,7 @@ def extension(self, poly, name=None, names=None, latex_name=None, latex_names=No EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^3 - 2) sage: R. = K[] sage: L. = K.extension(t^2 + a); L @@ -5836,6 +5908,7 @@ def factor(self, n): Here we show how to factor Gaussian integers (up to units). First we form a number field defined by `x^2 + 1`:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 1); K Number Field in I with defining polynomial x^2 + 1 @@ -5914,6 +5987,7 @@ def prime_factors(self, x): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 23) sage: K.prime_factors(w + 1) [Fractional ideal (2, 1/2*w - 1/2), Fractional ideal (2, 1/2*w + 1/2), Fractional ideal (3, 1/2*w + 1/2)] @@ -6033,6 +6107,7 @@ def gen(self, n=0): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^14 + 2); k Number Field in theta with defining polynomial x^14 + 2 sage: k.gen() @@ -6092,6 +6167,7 @@ def is_field(self, proof=True): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: NumberField(x^5 + x + 3, 'c').is_field() True """ @@ -6105,6 +6181,7 @@ def is_galois(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: NumberField(x^2 + 1, 'i').is_galois() True sage: NumberField(x^3 + 2, 'a').is_galois() @@ -6124,6 +6201,7 @@ def is_abelian(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: NumberField(x^2 + 1, 'i').is_abelian() True sage: NumberField(x^3 + 2, 'a').is_abelian() @@ -6183,7 +6261,8 @@ def galois_group(self, type=None, algorithm='pari', names=None, gc_numbering=Non EXAMPLES:: - sage: k. = NumberField(x^2 - 14) # a Galois extension + sage: x = polygen(QQ, 'x') + sage: k. = NumberField(x^2 - 14) # a Galois extension sage: G = k.galois_group(); G Galois group 2T1 (S2) with order 2 of x^2 - 14 sage: G.gen(0) @@ -6266,6 +6345,7 @@ def _normalize_prime_list(self, v): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 1) sage: K._normalize_prime_list(None) () @@ -6300,6 +6380,7 @@ def power_basis(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^5 + 10*x + 1) sage: K.power_basis() [1, a, a^2, a^3, a^4] @@ -6333,6 +6414,7 @@ def integral_basis(self, v=None): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^5 + 10*x + 1) sage: K.integral_basis() [1, a, a^2, a^3, a^4] @@ -6368,6 +6450,7 @@ def _pari_integral_basis(self, v=None, important=True): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^5 + 10*x + 1) sage: K._pari_integral_basis() [1, y, y^2, y^3, y^4] @@ -6450,7 +6533,8 @@ def reduced_basis(self, prec=None): EXAMPLES:: - sage: F. = NumberField(x^6-7*x^4-x^3+11*x^2+x-1) + sage: x = polygen(QQ, 'x') + sage: F. = NumberField(x^6 - 7*x^4 - x^3 + 11*x^2 + x - 1) sage: F.maximal_order().basis() [1/2*t^5 + 1/2*t^4 + 1/2*t^2 + 1/2, t, t^2, t^3, t^4, t^5] sage: F.reduced_basis() @@ -6526,7 +6610,8 @@ def reduced_gram_matrix(self, prec=None): EXAMPLES:: - sage: F. = NumberField(x^6-7*x^4-x^3+11*x^2+x-1) + sage: x = polygen(QQ, 'x') + sage: F. = NumberField(x^6 - 7*x^4 - x^3 + 11*x^2 + x - 1) sage: F.reduced_gram_matrix() [ 6 3 0 2 0 1] [ 3 9 0 1 0 -2] @@ -6649,7 +6734,8 @@ def narrow_class_group(self, proof=None): EXAMPLES:: - sage: NumberField(x^3+x+9, 'a').narrow_class_group() + sage: x = polygen(QQ, 'x') + sage: NumberField(x^3 + x + 9, 'a').narrow_class_group() Multiplicative Abelian group isomorphic to C2 TESTS:: @@ -6670,6 +6756,7 @@ def ngens(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: NumberField(x^2 + 17,'a').ngens() 1 sage: NumberField(x + 3,'a').ngens() @@ -6690,6 +6777,7 @@ def order(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: NumberField(x^2 + 19,'a').order() +Infinity """ @@ -6701,6 +6789,7 @@ def absolute_polynomial_ntl(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: NumberField(x^2 + (2/3)*x - 9/17,'a').absolute_polynomial_ntl() ([-27 34 51], 51) """ @@ -6715,6 +6804,7 @@ def polynomial_ntl(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: NumberField(x^2 + (2/3)*x - 9/17,'a').polynomial_ntl() ([-27 34 51], 51) """ @@ -6736,6 +6826,7 @@ def polynomial(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: NumberField(x^2 + (2/3)*x - 9/17,'a').polynomial() x^2 + 2/3*x - 9/17 """ @@ -6752,7 +6843,7 @@ def defining_polynomial(self): # do not overload this -- overload polynomial i sage: k5. = CyclotomicField(5) sage: k5.defining_polynomial() x^4 + x^3 + x^2 + x + 1 - sage: y = polygen(QQ,'y') + sage: y = polygen(QQ, 'y') sage: k. = NumberField(y^9 - 3*y + 5); k Number Field in a with defining polynomial y^9 - 3*y + 5 sage: k.defining_polynomial() @@ -6767,6 +6858,7 @@ def polynomial_ring(self): EXAMPLES: An example with an absolute field:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 3) sage: y = polygen(QQ, 'y') sage: k. = NumberField(y^2 + 3) @@ -6790,6 +6882,7 @@ def polynomial_quotient_ring(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K = NumberField(x^3 + 2*x - 5, 'alpha') sage: K.polynomial_quotient_ring() Univariate Quotient Polynomial Ring in alpha over Rational Field with modulus x^3 + 2*x - 5 @@ -6809,7 +6902,8 @@ def regulator(self, proof=None): EXAMPLES:: - sage: NumberField(x^2-2, 'a').regulator() + sage: x = polygen(QQ, 'x') + sage: NumberField(x^2 - 2, 'a').regulator() 0.881373587019543 sage: NumberField(x^4+x^3+x^2+x+1, 'a').regulator() 0.962423650119207 @@ -6900,7 +6994,8 @@ def signature(self): EXAMPLES:: - sage: NumberField(x^2+1, 'a').signature() + sage: x = polygen(QQ, 'x') + sage: NumberField(x^2 + 1, 'a').signature() (0, 1) sage: NumberField(x^3-2, 'a').signature() (1, 1) @@ -6915,6 +7010,7 @@ def trace_pairing(self, v): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 3) sage: K.trace_pairing([1,zeta3]) [ 2 0] @@ -6953,6 +7049,7 @@ def uniformizer(self, P, others="positive"): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 5); K Number Field in a with defining polynomial x^2 + 5 sage: P,Q = K.ideal(3).prime_factors() @@ -7325,7 +7422,8 @@ def S_unit_solutions(self, S=[], prec=106, include_exponents=False, include_boun EXAMPLES:: - sage: K. = NumberField(x^2+x+1) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^2 + x + 1) sage: S = K.primes_above(3) sage: K.S_unit_solutions(S) # random, due to ordering [(xi + 2, -xi - 1), (1/3*xi + 2/3, -1/3*xi + 1/3), (-xi, xi + 1), (-xi + 1, xi)] @@ -7373,6 +7471,7 @@ def zeta(self, n=2, all=False): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 3) sage: K.zeta(1) 1 @@ -7465,7 +7564,8 @@ def zeta_order(self): EXAMPLES:: - sage: F. = NumberField(x**22+3) + sage: x = polygen(QQ, 'x') + sage: F. = NumberField(x^22 + 3) sage: F.zeta_order() 6 sage: F. = NumberField(x**2-7) @@ -7510,7 +7610,8 @@ def primitive_root_of_unity(self): EXAMPLES:: - sage: K. = NumberField(x^2+1) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^2 + 1) sage: z = K.primitive_root_of_unity(); z i sage: z.multiplicative_order() @@ -7581,7 +7682,8 @@ def roots_of_unity(self): EXAMPLES:: - sage: K. = NumberField(x^2+1) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^2 + 1) sage: zs = K.roots_of_unity(); zs [b, -1, -b, 1] sage: [ z**K.number_of_roots_of_unity() for z in zs ] @@ -7627,7 +7729,8 @@ def solve_CRT(self, reslist, Ilist, check=True): EXAMPLES:: - sage: K. = NumberField(x^2-10) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^2 - 10) sage: Ilist = [K.primes_above(p)[0] for p in prime_range(10)] sage: b = K.solve_CRT([1,2,3,4],Ilist,True) sage: all(b-i-1 in Ilist[i] for i in range(4)) @@ -7676,6 +7779,7 @@ def valuation(self, prime): The valuation can be specified with an integer ``prime`` that is completely ramified in ``R``:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 1) sage: K.valuation(2) 2-adic valuation @@ -7853,6 +7957,7 @@ def maximal_order(self, v=None, assume_maximal='non-maximal-non-unique'): In this example, the maximal order cannot be generated by a single element:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + x^2 - 2*x+8) sage: o = k.maximal_order() sage: o @@ -7967,6 +8072,7 @@ def __init__(self, polynomial, name, latex_name=None, check=True, embedding=None EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K = NumberField(x^17 + 3, 'a'); K Number Field in a with defining polynomial x^17 + 3 sage: type(K) @@ -8009,6 +8115,7 @@ def _coerce_from_other_number_field(self, x): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^3 + 2) sage: L. = NumberField(x^2 + 1) sage: K._coerce_from_other_number_field(L(2/3)) @@ -8229,6 +8336,7 @@ def _coerce_map_from_(self, R): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: S. = NumberField(x^3 + x + 1) sage: S.coerce(int(4)) # indirect doctest 4 @@ -8290,13 +8398,13 @@ def _coerce_map_from_(self, R): TESTS:: - sage: K. = NumberField(polygen(QQ)^3-2) + sage: K. = NumberField(polygen(QQ)^3 - 2) sage: type(K.coerce_map_from(QQ)) Make sure we still get our optimized morphisms for special fields:: - sage: K. = NumberField(polygen(QQ)^2-2) + sage: K. = NumberField(polygen(QQ)^2 - 2) sage: type(K.coerce_map_from(QQ)) @@ -8352,6 +8460,7 @@ def absolute_polynomial(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 1) sage: K.absolute_polynomial () x^2 + 1 @@ -8370,6 +8479,7 @@ def absolute_generator(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 - 17) sage: K.absolute_generator() a @@ -8388,6 +8498,7 @@ def optimized_representation(self, name=None, both_maps=True): :: + sage: x = polygen(QQ, 'x') sage: K = NumberField([x^2 + p for p in [5, 3, 2]],'a').absolute_field('b'); K Number Field in b with defining polynomial x^8 + 40*x^6 + 352*x^4 + 960*x^2 + 576 sage: L, from_L, to_L = K.optimized_representation() @@ -8484,6 +8595,7 @@ def optimized_subfields(self, degree=0, name=None, both_maps=True): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K = NumberField([x^2 + p for p in [5, 3, 2]],'a').absolute_field('b'); K Number Field in b with defining polynomial x^8 + 40*x^6 + 352*x^4 + 960*x^2 + 576 sage: L = K.optimized_subfields(name='b') @@ -8585,6 +8697,7 @@ def change_names(self, names): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 3); K Number Field in z with defining polynomial x^2 + 3 sage: L. = K.change_names() @@ -8608,7 +8721,8 @@ def subfields(self, degree=0, name=None): EXAMPLES:: - sage: K. = NumberField( [x^3 - 2, x^2 + x + 1] ) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField([x^3 - 2, x^2 + x + 1]) sage: K = K.absolute_field('b') sage: S = K.subfields() sage: len(S) @@ -8680,6 +8794,7 @@ def _subfields_helper(self, degree=0, name=None, both_maps=True, optimize=False) Let's make sure embeddings are being respected:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^4 - 23, embedding=50) sage: K, CDF(a) (Number Field in a with defining polynomial x^4 - 23 with a = 2.189938703094843?, @@ -8770,6 +8885,7 @@ def _maximal_order(self, v=(), assume_maximal=None): TESTS:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + x^2 - 2*x+8) sage: k.maximal_order() is k.maximal_order() # indirect doctest True @@ -8806,6 +8922,7 @@ def order(self, *args, **kwds): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^2 + 1) sage: k.order(2*i) Order in Number Field in i with defining polynomial x^2 + 1 @@ -8860,6 +8977,7 @@ def _order(self, gens, **kwds): Test that caching works:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^3 - 2) sage: K.order(a) is K.order(a) # indirect doctest True @@ -8915,6 +9033,7 @@ def free_module(self, base=None, basis=None, map=True): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: k. = NumberField(x^3 + 2) sage: V, from_V, to_V = k.free_module() sage: from_V(V([1,2,3])) @@ -8956,6 +9075,7 @@ def absolute_vector_space(self, *args, **kwds): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^3 - 5) sage: K.absolute_vector_space() (Vector space of dimension 3 over Rational Field, @@ -8986,6 +9106,7 @@ def _galois_closure_and_embedding(self, names=None): For medium-sized Galois groups of fields with small discriminants, this computation is feasible:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^6 + 4*x^2 + 2) sage: K.galois_group().order() 48 @@ -9032,6 +9153,7 @@ def galois_closure(self, names=None, map=False): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^4 - 2) sage: M = K.galois_closure('b'); M Number Field in b with defining polynomial x^8 + 28*x^4 + 2500 @@ -9090,6 +9212,7 @@ def automorphisms(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 10000) sage: K.automorphisms() [ @@ -9148,6 +9271,7 @@ def embeddings(self, K): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^3 - 2) sage: L. = K.galois_closure(); L Number Field in a1 with defining polynomial x^6 + 108 @@ -9263,7 +9387,8 @@ def minkowski_embedding(self, B=None, prec=None): EXAMPLES:: - sage: F. = NumberField(x^3+2) + sage: x = polygen(QQ, 'x') + sage: F. = NumberField(x^3 + 2) sage: F.minkowski_embedding() [ 1.00000000000000 -1.25992104989487 1.58740105196820] [ 1.41421356237... 0.8908987181... -1.12246204830...] @@ -9334,6 +9459,7 @@ def logarithmic_embedding(self, prec=53): :: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^3 + 5) sage: f = K.logarithmic_embedding() sage: f(0) @@ -9399,7 +9525,8 @@ def places(self, all_complex=False, prec=None): EXAMPLES:: - sage: F. = NumberField(x^3-100*x+1) ; F.places() + sage: x = polygen(QQ, 'x') + sage: F. = NumberField(x^3 - 100*x + 1); F.places() [Ring morphism: From: Number Field in alpha with defining polynomial x^3 - 100*x + 1 To: Real Field with 106 bits of precision @@ -9494,7 +9621,8 @@ def real_places(self, prec=None): EXAMPLES:: - sage: F. = NumberField(x^4-7) ; F.real_places() + sage: x = polygen(QQ, 'x') + sage: F. = NumberField(x^4 - 7) ; F.real_places() [Ring morphism: From: Number Field in alpha with defining polynomial x^4 - 7 To: Real Field with 106 bits of precision @@ -9522,7 +9650,8 @@ def abs_val(self, v, iota, prec=None): EXAMPLES:: - sage: K. = NumberField(x^3-3) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^3 - 3) sage: phi_real = K.places()[0] sage: phi_complex = K.places()[1] sage: v_fin = tuple(K.primes_above(3))[0] @@ -9586,6 +9715,7 @@ def relativize(self, alpha, names, structure=None): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^10 - 2) sage: L. = K.relativize(a^4 + a^2 + 2); L Number Field in c with defining polynomial x^2 - 1/5*d^4 + 8/5*d^3 - 23/5*d^2 + 7*d - 18/5 over its base field @@ -9824,6 +9954,7 @@ def absolute_degree(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 1) sage: K.absolute_degree() 2 @@ -9836,6 +9967,7 @@ def relative_degree(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 1) sage: K.relative_degree() 2 @@ -9848,6 +9980,7 @@ def relative_polynomial(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 1) sage: K.relative_polynomial() x^2 + 1 @@ -9860,6 +9993,7 @@ def relative_vector_space(self, *args, **kwds): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 1) sage: K.relative_vector_space() (Vector space of dimension 2 over Rational Field, @@ -9878,6 +10012,7 @@ def absolute_discriminant(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 1) sage: K.absolute_discriminant() -4 @@ -9890,6 +10025,7 @@ def relative_discriminant(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 1) sage: K.relative_discriminant() -4 @@ -9902,6 +10038,7 @@ def absolute_different(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 1) sage: K.absolute_different() Fractional ideal (2) @@ -9914,6 +10051,7 @@ def relative_different(self): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 1) sage: K.relative_different() Fractional ideal (2) @@ -9952,6 +10090,7 @@ def hilbert_symbol(self, a, b, P=None): Some global examples:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 - 23) sage: K.hilbert_symbol(0, a+5) 0 @@ -10173,6 +10312,7 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 20072) sage: S = [K.primes_above(3)[0], K.primes_above(23)[0]] sage: b = K.hilbert_symbol_negative_at_S(S, a + 1) @@ -10338,8 +10478,9 @@ def hilbert_conductor(self, a, b): EXAMPLES:: - sage: F. = NumberField(x^2-x-1) - sage: F.hilbert_conductor(2*a,F(-1)) + sage: x = polygen(QQ, 'x') + sage: F. = NumberField(x^2 - x - 1) + sage: F.hilbert_conductor(2*a, F(-1)) Fractional ideal (2) sage: K. = NumberField(x^3-4*x+2) sage: K.hilbert_conductor(K(2),K(-2)) @@ -10396,6 +10537,7 @@ def elements_of_bounded_height(self, **kwds): There are no elements in a number field with multiplicative height less than 1:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^5 - x + 19) sage: list(K.elements_of_bounded_height(bound=0.9)) [] @@ -10501,9 +10643,10 @@ def _factor_univariate_polynomial(self, poly, **kwargs): EXAMPLES:: - sage: K. = NumberField(x**2+1) - sage: x = polygen(K,'x') - sage: factor(x*x+4) # indirect doctest + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x**2 + 1) + sage: x = polygen(K, 'x') + sage: factor(x*x + 4) # indirect doctest (x - 2*i) * (x + 2*i) TESTS:: @@ -11290,6 +11433,7 @@ def _Hom_(self, codomain, cat=None): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 3); K Number Field in a with defining polynomial x^2 + 3 sage: CyclotomicField(3).Hom(K) # indirect doctest @@ -11336,7 +11480,8 @@ def is_isomorphic(self, other): True sage: CyclotomicField(11).is_isomorphic(CyclotomicField(23)) False - sage: CyclotomicField(3).is_isomorphic(NumberField(x^2 + x +1, 'a')) + sage: x = polygen(QQ, 'x') + sage: CyclotomicField(3).is_isomorphic(NumberField(x^2 + x + 1, 'a')) True sage: CyclotomicField(18).is_isomorphic(CyclotomicField(9)) True @@ -11982,7 +12127,8 @@ def discriminant(self, v=None): EXAMPLES:: - sage: K. = NumberField(x^2+1) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^2 + 1) sage: K.discriminant() -4 sage: K. = NumberField(x^2+5) @@ -12058,6 +12204,7 @@ def class_number(self, proof=None): sage: type(QuadraticField(-23,'a').class_number()) + sage: x = polygen(QQ, 'x') sage: type(NumberField(x^3 + 23, 'a').class_number()) sage: type(NumberField(x^3 + 23, 'a').extension(x^2 + 5, 'b').class_number()) @@ -12121,6 +12268,7 @@ def hilbert_class_field(self, names): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^2 + 23) sage: L = K.hilbert_class_field('b'); L Number Field in b with defining polynomial x^3 - x^2 + 1 over its base field @@ -12346,7 +12494,8 @@ def refine_embedding(e, prec=None): An example where we extend a real embedding into ``AA``:: - sage: K. = NumberField(x^3-2) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^3 - 2) sage: K.signature() (1, 1) sage: e = K.embeddings(RR)[0]; e @@ -12472,7 +12621,8 @@ def is_real_place(v): EXAMPLES:: - sage: K. = NumberField(x^3-3) + sage: x = polygen(QQ, 'x') + sage: K. = NumberField(x^3 - 3) sage: phi_real = K.places()[0] sage: phi_complex = K.places()[1] sage: v_fin = tuple(K.primes_above(3))[0] diff --git a/src/sage/rings/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index d80c87ea00c..5125d61baf9 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -113,6 +113,7 @@ def is_NumberFieldElement(x): use isinstance(..., sage.structure.element.NumberFieldElement) instead See https://github.com/sagemath/sage/issues/34931 for details. False + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^7 + 17*x + 1) sage: is_NumberFieldElement(a+1) True @@ -130,6 +131,7 @@ def __create__NumberFieldElement_version0(parent, poly): TESTS:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 - 2) sage: R. = QQ[] sage: sage.rings.number_field.number_field_element.__create__NumberFieldElement_version0(k, z^2 + z + 1) @@ -148,6 +150,7 @@ def __create__NumberFieldElement_version1(parent, cls, poly): TESTS:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 - 2) sage: R. = QQ[] sage: sage.rings.number_field.number_field_element.__create__NumberFieldElement_version1(k, type(a), z^2 + z + 1) @@ -170,6 +173,7 @@ def _inverse_mod_generic(elt, I): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: OE. = EquationOrder(x^3 - x + 2) sage: from sage.rings.number_field.number_field_element import _inverse_mod_generic sage: _inverse_mod_generic(w, 13*OE) @@ -203,6 +207,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 + x + 1) sage: a^3 -a - 1 @@ -225,6 +230,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): Return the number field of self. Only accessible from Cython. EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 3) sage: a._number_field() # indirect doctest Number Field in a with defining polynomial x^3 + 3 @@ -235,6 +241,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 3) sage: a._number_field() Number Field in a with defining polynomial x^3 + 3 @@ -431,6 +438,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 - 17*x^2 + 1) sage: t = a.__reduce__(); t (, @@ -461,6 +469,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 2) sage: b = (2/3)*a + 3/5 sage: b._repr_() @@ -476,6 +485,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 - 2) sage: m. = NumberField(x^4 - 2) sage: phi = k.hom([b^2]) @@ -518,6 +528,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: (a**2 - a + 1)._gap_init_() '\\$sage4^2 - \\$sage4 + 1' @@ -612,6 +623,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): TESTS: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: K.zero()._pari_polynomial('x') 0 @@ -642,6 +654,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: K(1).__pari__() Mod(1, y^3 + 2) @@ -739,6 +752,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^5 - x - 1) sage: ((1 + 1/3*a)^4)._pari_init_() 'Mod(1/81*y^4 + 4/27*y^3 + 2/3*y^2 + 4/3*y + 1, y^5 - y - 1)' @@ -775,6 +789,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: m. = NumberField(x^4 - 1789) sage: c = (2/3-4/5*b)^3; c -64/125*b^3 + 32/25*b^2 - 16/15*b + 8/27 @@ -814,6 +829,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 3*x + 8) sage: a + 1 > a # indirect doctest True @@ -916,7 +932,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^3-2) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 2) sage: a._random_element().parent() is K True sage: K. = NumberField(x^2-5) @@ -1013,6 +1030,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 - 2) sage: abs(a) 1.25992104989487 @@ -1045,7 +1063,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2, embedding=AA(2)**(1/3)) sage: K.zero().sign() 0 @@ -1334,7 +1352,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): 1.00000000000000 sage: abs(z^2 + 17*z - 3) 16.0604426799931 - sage: K. = NumberField(x^3+17) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 + 17) sage: abs(a) 2.57128159065824 sage: a.abs(prec=100) @@ -1421,7 +1440,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^2+5) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 5) sage: [1/K(2).abs_non_arch(P) for P in K.primes_above(2)] [2.00000000000000] sage: [1/K(3).abs_non_arch(P) for P in K.primes_above(3)] @@ -1483,6 +1503,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): :: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^6 - 5) sage: alpha = a^3 sage: c = alpha.coordinates_in_terms_of_powers() @@ -1519,6 +1540,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 - 2) sage: a.complex_embeddings() [-0.629960524947437 - 1.09112363597172*I, -0.629960524947437 + 1.09112363597172*I, 1.25992104989487] @@ -1537,6 +1559,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 - 2) sage: a.complex_embedding() -0.629960524947437 - 1.09112363597172*I @@ -1557,6 +1580,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - x - 1) sage: OK = K.ring_of_integers() sage: OK(a).is_unit() @@ -1609,7 +1633,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^3+5) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 + 5) sage: Q. = K[] sage: L = K.extension(X^2+X+beta, 'gamma') sage: (beta/2).is_norm(L) @@ -1749,6 +1774,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + x^2 - 2*x - 1, 'a') sage: P. = K[] sage: L = NumberField(X^2 + a^2 + 2*a + 1, 'b') @@ -1827,6 +1853,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): """ EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: RR(a^2) -1.00000000000000 @@ -1864,6 +1891,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: sage: Pol. = QQ[] + sage: x = polygen(ZZ, 'x') sage: NF. = NumberField(x^7 + 2, embedding=CC(0.99, 0.47)) sage: CBF(a) [0.9947502791976272 +/- 1.09e-17] + [0.4790464865132800 +/- 1.46e-17]*I @@ -1905,6 +1933,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): """ EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: float(a^2) -1.0 @@ -1932,6 +1961,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): """ EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: abs(CDF(a)) 1.0 @@ -1942,6 +1972,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): """ EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: complex(a) 1j @@ -1966,7 +1997,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^2+1) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 1) sage: (6*i + 6).factor() (-i) * (i + 1)^3 * 3 @@ -2021,8 +2053,9 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^2+1) - sage: (1+i).is_prime() + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 1) + sage: (1 + i).is_prime() True sage: ((1+i)/2).is_prime() False @@ -2072,6 +2105,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): The following field has class number 3, but if the ideal ``(self, other)`` happens to be principal, this still works:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 7) sage: K.class_number() 3 @@ -2117,7 +2151,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: F. = NumberField(x^3-3*x-1) + sage: x = polygen(ZZ, 'x') + sage: F. = NumberField(x^3 - 3*x - 1) sage: b.is_totally_positive() False sage: (b^2).is_totally_positive() @@ -2167,6 +2202,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: m. = NumberField(x^4 - 1789) sage: b.is_square() False @@ -2218,6 +2254,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 2) sage: p = K.primes_above(2)[0] sage: K(5).is_padic_square(p) @@ -2240,6 +2277,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 3) sage: K(3).sqrt() a @@ -2316,7 +2354,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^4-7) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^4 - 7) sage: K(7).nth_root(2) a^2 sage: K((a-3)^5).nth_root(5) @@ -2342,7 +2381,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^4-7) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^4 - 7) sage: K(7).is_nth_power(2) True sage: K(7).is_nth_power(4) @@ -2395,6 +2435,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: K. = QuadraticField(2) sage: 2^sqrt2 2^sqrt(2) + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2+1) sage: 2^a Traceback (most recent call last): @@ -2477,6 +2518,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: (a/2) - (a + 3) # indirect doctest -1/2*a - 3 @@ -2507,6 +2549,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: C.=CyclotomicField(12) sage: zeta12*zeta12^11 1 + sage: x = polygen(ZZ, 'x') sage: G. = NumberField(x^3 + 2/3*x + 1) sage: a^3 # indirect doctest -2/3*a - 1 @@ -2561,6 +2604,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): :: + sage: x = polygen(ZZ, 'x') sage: G. = NumberField(x^3 + 2/3*x + 1) sage: a/a # indirect doctest 1 @@ -2659,6 +2703,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: -a # indirect doctest -a @@ -2675,6 +2720,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: L. = K.change_names() sage: La = a._copy_for_parent(L) @@ -2694,6 +2740,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: b = copy(a) sage: b is a @@ -2706,6 +2753,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: b = deepcopy(a) sage: b is a @@ -2731,6 +2779,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^10 - x - 1) sage: int(a) Traceback (most recent call last): @@ -2835,6 +2884,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: NF. = NumberField(x^5 + 7*x + 3, embedding=CC(0,1)) sage: QQbar(alpha) -1.032202770009288? + 1.168103873894207?*I @@ -2892,6 +2942,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: K. = QuadraticField(2, embedding=-1.4) sage: SR(a) # indirect doctest -sqrt(2) + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 2) sage: SR(a) # indirect doctest Traceback (most recent call last): @@ -3018,6 +3069,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): In the first example the conjugates are obvious:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 2) sage: a.galois_conjugates(K) [a, -a] @@ -3085,6 +3137,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): :: + sage: x = polygen(ZZ, 'x') sage: F. = NumberField(x^2 - 2) sage: K. = F.extension(x^2 + 1) sage: j.conjugate() @@ -3132,6 +3185,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^5 - x - 1) sage: f = (-2/3 + 1/3*a)^4; f 1/81*a^4 - 8/81*a^3 + 8/27*a^2 - 32/81*a + 16/81 @@ -3176,6 +3230,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: hash(b^2 + 1) # random 175247765440 @@ -3233,6 +3288,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: (b^2 + 1)._coefficients() [1, 0, 1] @@ -3295,6 +3351,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + x + 1) sage: a._set_multiplicative_order(3) sage: a.multiplicative_order() @@ -3379,6 +3436,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 - 3*x^2 + 3) sage: u.additive_order() +Infinity @@ -3396,6 +3454,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 3) sage: K(1).is_one() True @@ -3422,6 +3481,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 3) sage: cbrt3.is_rational() False @@ -3447,6 +3507,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 3) sage: cbrt3.is_integer() False @@ -3472,7 +3533,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^3 -132/7*x^2 + x + 1); K + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 132/7*x^2 + x + 1); K Number Field in a with defining polynomial x^3 - 132/7*x^2 + x + 1 sage: a.trace() 132/7 @@ -3507,6 +3569,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + x^2 + x - 132/7); K Number Field in a with defining polynomial x^3 + x^2 + x - 132/7 sage: a.norm() @@ -3580,6 +3643,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: sage: K1. = CyclotomicField(11) + sage: x = polygen(ZZ, 'x') sage: K2. = K1.extension(x^2 - 3) sage: K3. = K2.extension(x^2 + 1) sage: (a1 + a2 + a3).absolute_norm() @@ -3598,6 +3662,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: sage: K1. = CyclotomicField(11) + sage: x = polygen(ZZ, 'x') sage: K2. = K1.extension(x^2 - 3) sage: (a1 + a2).relative_norm() a1^2 - 3 @@ -3617,6 +3682,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: (2/3*a - 5/6).vector() (-5/6, 2/3) @@ -3642,6 +3708,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 7) sage: a.charpoly() x^3 + 7 @@ -3656,7 +3723,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^2+3) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 3) sage: a.minpoly('x') x^2 + 3 sage: R. = K['X'] @@ -3677,6 +3745,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 23) sage: a.is_integral() True @@ -3768,6 +3837,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): An example where we explicitly give the subfield or the embedding:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 + 1); L. = NumberField(x^2 + 1) sage: a.matrix(L) [ 0 1] @@ -4171,7 +4241,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^2+5) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 5) sage: b = (1+a)/2 sage: b.norm() 3/2 @@ -4202,7 +4273,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^2+5) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 5) sage: b = (1+a)/2 sage: b.norm() 3/2 @@ -4335,6 +4407,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - x + 2); ((a + 1)/(a + 2)).list() [1/4, 1/2, -1/4] sage: K. = NumberField([x^3 - x + 2, x^2 + 23]); ((a + b)/(a + 2)).list() @@ -4357,6 +4430,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 23) sage: N = k.ideal(3) sage: d = 3*a + 1 @@ -4414,6 +4488,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): Quadratic Residue (11 is not a square modulo 17):: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x - 1) sage: K(11).residue_symbol(K.ideal(17),2) -1 @@ -4551,6 +4626,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: a.different() 3*a^2 @@ -4601,6 +4677,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 - 17, x^3 - 2]) sage: a.absolute_different() 0 @@ -4629,6 +4706,7 @@ cdef class NumberFieldElement_absolute(NumberFieldElement): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) # optional - magma sage: a._magma_init_(magma) # optional - magma '(_sage_[...]![0, 1, 0])' @@ -4893,6 +4971,7 @@ cdef class NumberFieldElement_relative(NumberFieldElement): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 + 1, x^2 + 2]) sage: type(a) # indirect doctest @@ -4909,6 +4988,7 @@ cdef class NumberFieldElement_relative(NumberFieldElement): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^3 - 5, x^2 + 3]) sage: c = (a + b)^3; c 3*b*a^2 - 9*a - 3*b + 5 @@ -4941,6 +5021,7 @@ cdef class NumberFieldElement_relative(NumberFieldElement): """ EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^3 - 5, x^2 + 3]) sage: a._magma_init_(magma) Traceback (most recent call last): @@ -4956,7 +5037,8 @@ cdef class NumberFieldElement_relative(NumberFieldElement): EXAMPLES:: - sage: K. = NumberField([x^3+2, x^2+1]) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField([x^3 + 2, x^2 + 1]) sage: a.list() [0, 1, 0] sage: v = (K.base_field().0 + a)^2 ; v @@ -4990,6 +5072,7 @@ cdef class NumberFieldElement_relative(NumberFieldElement): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^3 - x + 1, x^2 + 23]) sage: repr(a^4*b) # indirect doctest 'b*a^2 - b*a' @@ -5122,6 +5205,7 @@ cdef class NumberFieldElement_relative(NumberFieldElement): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 2, x^2 + 1000*x + 1]) sage: y = K['y'].0 sage: L. = K.extension(y^2 + a*y + b) @@ -5152,6 +5236,7 @@ cdef class NumberFieldElement_relative(NumberFieldElement): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 - 2, x^2 - 3, x^2 - 5]) sage: P = K.prime_factors(5)[1] sage: (2*a + b - c).valuation(P) @@ -5169,6 +5254,7 @@ cdef class OrderElement_absolute(NumberFieldElement_absolute): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: O2 = K.order(2*a) sage: w = O2.1; w @@ -5189,6 +5275,7 @@ cdef class OrderElement_absolute(NumberFieldElement_absolute): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: O2 = K.order(2*a) sage: type(O2.1) # indirect doctest @@ -5208,6 +5295,7 @@ cdef class OrderElement_absolute(NumberFieldElement_absolute): This is called implicitly in multiplication:: + sage: x = polygen(ZZ, 'x') sage: O = EquationOrder(x^3 + 18, 'a') sage: O.1 * O.1 * O.1 -18 @@ -5226,6 +5314,7 @@ cdef class OrderElement_absolute(NumberFieldElement_absolute): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x^3 - 17, 'a') sage: OK = K.ring_of_integers() sage: a = OK(K.gen()) @@ -5249,6 +5338,7 @@ cdef class OrderElement_absolute(NumberFieldElement_absolute): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: OE. = EquationOrder(x^3 - x + 2) sage: w.inverse_mod(13*OE) 6*w^2 - 6 @@ -5273,7 +5363,8 @@ cdef class OrderElement_absolute(NumberFieldElement_absolute): EXAMPLES:: - sage: K = NumberField(x^3 -x + 2, 'a') + sage: x = polygen(ZZ, 'x') + sage: K = NumberField(x^3 - x + 2, 'a') sage: OK = K.ring_of_integers() sage: a = OK(K.gen()) sage: (~a).parent() is K @@ -5292,7 +5383,8 @@ cdef class OrderElement_relative(NumberFieldElement_relative): EXAMPLES:: - sage: O = EquationOrder([x^2 + x + 1, x^3 - 2],'a,b') + sage: x = polygen(ZZ, 'x') + sage: O = EquationOrder([x^2 + x + 1, x^3 - 2], 'a,b') sage: c = O.1; c (-2*b^2 - 2)*a - 2*b^2 - b sage: type(c) @@ -5302,8 +5394,9 @@ cdef class OrderElement_relative(NumberFieldElement_relative): r""" EXAMPLES:: - sage: O = EquationOrder([x^2 + x + 1, x^3 - 2],'a,b') - sage: type(O.1) # indirect doctest + sage: x = polygen(ZZ, 'x') + sage: O = EquationOrder([x^2 + x + 1, x^3 - 2], 'a,b') + sage: type(O.1) # indirect doctest """ K = order.number_field() @@ -5323,6 +5416,7 @@ cdef class OrderElement_relative(NumberFieldElement_relative): This is called implicitly in multiplication:: + sage: x = polygen(ZZ, 'x') sage: O = EquationOrder([x^2 + 18, x^3 + 2], 'a,b') sage: c = O.1 * O.2; c (-23321*b^2 - 9504*b + 10830)*a + 10152*b^2 - 104562*b - 110158 @@ -5345,6 +5439,7 @@ cdef class OrderElement_relative(NumberFieldElement_relative): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K1. = NumberField(x^3 - 17) sage: R. = K1[] sage: K2 = K1.extension(y^2 - a, 'b') @@ -5377,6 +5472,7 @@ cdef class OrderElement_relative(NumberFieldElement_relative): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: E. = NumberField([x^2 - x + 2, x^2 + 1]) sage: OE = E.ring_of_integers() sage: t = OE(b - a).inverse_mod(17*b) @@ -5502,6 +5598,7 @@ class CoordinateFunction(): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + x + 3) sage: f = (a + 1).coordinates_in_terms_of_powers(); f Coordinate function that writes elements in terms of the powers of a + 1 @@ -5516,6 +5613,7 @@ class CoordinateFunction(): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + x + 3) sage: f = (a + 1).coordinates_in_terms_of_powers(); f # indirect doctest Coordinate function that writes elements in terms of the powers of a + 1 @@ -5529,6 +5627,7 @@ class CoordinateFunction(): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + x + 3) sage: f = (a + 1).coordinates_in_terms_of_powers(); repr(f) # indirect doctest 'Coordinate function that writes elements in terms of the powers of a + 1' @@ -5539,6 +5638,7 @@ class CoordinateFunction(): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: (a + 2).coordinates_in_terms_of_powers().alpha() a + 2 @@ -5549,6 +5649,7 @@ class CoordinateFunction(): r""" EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: f = (a + 2).coordinates_in_terms_of_powers() sage: f(1/a) @@ -5576,6 +5677,7 @@ class CoordinateFunction(): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: c = (a + 2).coordinates_in_terms_of_powers() sage: c == (a - 3).coordinates_in_terms_of_powers() @@ -5601,6 +5703,7 @@ class CoordinateFunction(): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: c = (a + 2).coordinates_in_terms_of_powers() sage: c != (a - 3).coordinates_in_terms_of_powers() diff --git a/src/sage/rings/number_field/number_field_element_base.pyx b/src/sage/rings/number_field/number_field_element_base.pyx index 5385833f1d4..ab85fb461fa 100644 --- a/src/sage/rings/number_field/number_field_element_base.pyx +++ b/src/sage/rings/number_field/number_field_element_base.pyx @@ -20,8 +20,9 @@ cdef class NumberFieldElement_base(FieldElement): EXAMPLES:: - sage: k. = NumberField(x^3 + x + 1) - sage: isinstance(a, sage.rings.number_field.number_field_element_base.NumberFieldElement_base) + sage: x = polygen(ZZ, 'x') + sage: k. = NumberField(x^3 + x + 1) # optional - sage.rings.number_field + sage: isinstance(a, sage.rings.number_field.number_field_element_base.NumberFieldElement_base) # optional - sage.rings.number_field True By design, there is a unique direct subclass:: diff --git a/src/sage/rings/number_field/number_field_element_quadratic.pyx b/src/sage/rings/number_field/number_field_element_quadratic.pyx index bcba57457e5..a690dc174af 100644 --- a/src/sage/rings/number_field/number_field_element_quadratic.pyx +++ b/src/sage/rings/number_field/number_field_element_quadratic.pyx @@ -74,7 +74,8 @@ def __make_NumberFieldElement_quadratic0(parent, a, b, denom): TESTS:: - sage: K. = NumberField(x^2-x+13) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - x + 13) sage: loads(dumps(a)) == a # indirect doctest True """ @@ -86,7 +87,8 @@ def __make_NumberFieldElement_quadratic1(parent, cls, a, b, denom): TESTS:: - sage: K. = NumberField(x^2-x+13) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - x + 13) sage: loads(dumps(a)) == a # indirect doctest True @@ -116,7 +118,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): We set up some fields:: - sage: K. = NumberField(x^2+23) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 23) sage: a.parts() (0, 1) sage: F. = NumberField(x^2-x+7) @@ -422,7 +425,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): TESTS: - sage: K. = NumberField(x^2-13) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 13) sage: loads(dumps(a)) == a True sage: loads(dumps(a/3+5)) == a/3+5 @@ -902,7 +906,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): EXAMPLES:: - sage: K. = NumberField(x^2-13) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 13) sage: K.discriminant() 13 sage: a.parts() @@ -983,8 +988,9 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): sage: (-a-2).sign() -1 - sage: K. = NumberField(x^2 + 2*x + 7, 'b', embedding=CC(-1,-sqrt(6))) - sage: b.sign() + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 2*x + 7, 'b', embedding=CC(-1,-sqrt(6))) # optional - sage.symbolic + sage: b.sign() # optional - sage.symbolic Traceback (most recent call last): ... ValueError: a complex number has no sign! @@ -1046,6 +1052,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): Make some random tests to check that the order is compatible with the ones of the real field (RR) and complex field (CC):: + sage: x = polygen(ZZ, 'x') sage: K1 = NumberField(x^2 - 2, 'a', embedding=RR(1.4)) sage: K2 = NumberField(x^2 - 2, 'a', embedding=RR(-1.4)) sage: for _ in range(500): # long time @@ -1316,7 +1323,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): """ EXAMPLES:: - sage: K. = NumberField(x^2-5) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 5) sage: K.discriminant() 5 sage: a+a # indirect doctest @@ -1373,7 +1381,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): """ EXAMPLES:: - sage: K. = NumberField(x^2-13) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 13) sage: b = (a-3)/10; b # indirect doctest 1/10*a - 3/10 sage: b-1 @@ -1420,7 +1429,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): """ EXAMPLES:: - sage: K. = NumberField(x^2+163) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 163) sage: -a -a sage: -(a+4) @@ -1439,7 +1449,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): """ EXAMPLES:: - sage: K. = NumberField(x^2+23) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 23) sage: a*a # indirect doctest -23 sage: (a+1)*(a-1) @@ -1506,7 +1517,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): """ EXAMPLES:: - sage: K. = NumberField(x^2+43) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 43) sage: (1+a)*3 # indirect doctest 3*a + 3 """ @@ -1522,7 +1534,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): """ EXAMPLES:: - sage: K. = NumberField(x^2+43) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 43) sage: 5*(a-1/5) # indirect doctest 5*a - 1 """ @@ -1538,7 +1551,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): """ EXAMPLES:: - sage: K. = NumberField(x^2-5) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 5) sage: ~a 1/5*a sage: ~(a+1) @@ -1611,6 +1625,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): sage: a.galois_conjugate() -a + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 5*x + 1) sage: a.galois_conjugate() -a + 5 @@ -1667,7 +1682,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): EXAMPLES:: - sage: K. = NumberField(x^2+163) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 163) sage: not a False sage: not (a-a) @@ -1679,7 +1695,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): """ EXAMPLES:: - sage: K. = NumberField(x^2+163) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 163) sage: (a+1-a)._integer_() 1 sage: (a+1/2-a)._integer_() @@ -1699,7 +1716,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): """ EXAMPLES:: - sage: K. = NumberField(x^2+163) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 163) sage: (a+1/2-a)._rational_() 1/2 sage: (a+1/2)._rational_() @@ -1843,6 +1861,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): sage: parent(i.imag()) Rational Field + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + x + 1, embedding=CDF.0) sage: a.imag() 1/2*sqrt3 @@ -1916,6 +1935,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): """ EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: F. = NumberField(x^2 - x + 7) sage: b._coefficients() [0, 1] @@ -1943,6 +1963,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 5) sage: b = (a + 1)/2 sage: b.denominator() @@ -1970,7 +1991,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): EXAMPLES:: - sage: K. = NumberField(x^2+x+41) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + x + 41) sage: b = (2*a+1)/6 sage: b.denominator() 6 @@ -1988,7 +2010,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): """ EXAMPLES:: - sage: K. = NumberField(x^2+x+41) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + x + 41) sage: a.trace() -1 sage: a.matrix() @@ -2028,7 +2051,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): EXAMPLES:: - sage: K. = NumberField(x^2-x+3) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - x + 3) sage: a.norm() 3 sage: a.matrix() @@ -2141,7 +2165,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): EXAMPLES:: - sage: K. = NumberField(x^2-x+13) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - x + 13) sage: a.charpoly() x^2 - x + 13 sage: b = 3-a/2 @@ -2166,7 +2191,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): EXAMPLES:: - sage: K. = NumberField(x^2+13) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 13) sage: a.minpoly() x^2 + 13 sage: a.minpoly('T') @@ -2192,7 +2218,8 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): sage: abs(a+2) # indirect test a + 2 - sage: K. = NumberField(x^2+1, embedding=CDF.gen()) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 1, embedding=CDF.gen()) sage: abs(a+1) sqrt(2) """ @@ -2366,7 +2393,8 @@ cdef class NumberFieldElement_quadratic_sqrt(NumberFieldElement_quadratic): EXAMPLES:: - sage: K. = NumberField(x^2+x+41) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + x + 41) sage: a.denominator() 1 sage: b = (2*a+1)/6 @@ -2395,7 +2423,8 @@ cdef class NumberFieldElement_quadratic_sqrt(NumberFieldElement_quadratic): """ EXAMPLES:: - sage: K. = NumberField(x^2+41) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 41) sage: a._coefficients() [0, 1] sage: K.zero()._coefficients() @@ -2421,7 +2450,8 @@ cdef class NumberFieldElement_quadratic_sqrt(NumberFieldElement_quadratic): EXAMPLES:: - sage: K. = NumberField(x^2-13) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 13) sage: elt = a/4 + 1/3 sage: elt[0] 1/3 @@ -2603,6 +2633,7 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: O2 = K.order(2*a) sage: w = O2.1; w @@ -2616,6 +2647,7 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: OK. = EquationOrder(x^2 + 5) sage: v = OK.1 # indirect doctest sage: type(v) @@ -2631,6 +2663,7 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 3) sage: O2 = K.order(2*a) sage: w = O2.gen(1); w @@ -2648,6 +2681,7 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 5) sage: R = K.ring_of_integers() sage: b = R((1+a)/2) @@ -2672,6 +2706,7 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 5) sage: R = K.ring_of_integers() sage: b = R((5+a)/2) @@ -2698,6 +2733,7 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 163) sage: R = K.ring_of_integers() sage: f = R(a).minpoly('x'); f @@ -2724,7 +2760,8 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): """ EXAMPLES:: - sage: K. = NumberField(x^2-27) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 27) sage: R = K.ring_of_integers() sage: aa = R.gen(1); aa 1/3*a @@ -2743,7 +2780,8 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): """ EXAMPLES:: - sage: K. = NumberField(x^2+43) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 43) sage: R = K.ring_of_integers() sage: aa = R.gen(0); aa 1/2*a + 1/2 @@ -2765,7 +2803,8 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): EXAMPLES:: - sage: K = NumberField(x^2 -x + 2, 'a') + sage: x = polygen(ZZ, 'x') + sage: K = NumberField(x^2 - x + 2, 'a') sage: OK = K.ring_of_integers() sage: a = OK(K.gen()) sage: (~a).parent() is K @@ -2792,6 +2831,7 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: OE. = EquationOrder(x^2 - x + 2) sage: w.inverse_mod(13) == 6*w - 6 True @@ -2811,7 +2851,8 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): """ EXAMPLES:: - sage: K. = NumberField(x^2-27) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 27) sage: R = K.ring_of_integers() sage: aa = R.gen(1) sage: aa._coefficients() @@ -2843,7 +2884,8 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): EXAMPLES:: - sage: K. = NumberField(x^2-27) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 27) sage: R = K.ring_of_integers() sage: aa = R.gen(1) sage: aa.denominator() @@ -3073,6 +3115,7 @@ cpdef bint is_sqrt_disc(Rational ad, Rational bd): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: F. = NumberField(x^2 - x + 7) sage: b.denominator() # indirect doctest 1 diff --git a/src/sage/rings/number_field/number_field_ideal_rel.py b/src/sage/rings/number_field/number_field_ideal_rel.py index 1292219f843..6f390aca1dc 100644 --- a/src/sage/rings/number_field/number_field_ideal_rel.py +++ b/src/sage/rings/number_field/number_field_ideal_rel.py @@ -11,6 +11,7 @@ EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 1, x^2 + 2]) sage: A = K.absolute_field('z') sage: I = A.factor(7)[0][0] @@ -49,6 +50,7 @@ class NumberFieldFractionalIdeal_rel(NumberFieldFractionalIdeal): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 1, x^2 + 2]); K Number Field in a0 with defining polynomial x^2 + 1 over its base field sage: i = K.ideal(38); i @@ -81,6 +83,7 @@ def _richcmp_(self, other, op): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 23, x^2 - 7]) sage: I = K.ideal(2, (a + 2*b + 3)/2) sage: J = K.ideal(2, a - b) @@ -99,6 +102,7 @@ def _contains_(self, x): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 23, x^2 - 7]) sage: I = K.ideal(2, (a + 2*b + 3)/2) sage: [z in I for z in [a, b, 2, a + b]] # indirect doctest @@ -115,6 +119,7 @@ def pari_rhnf(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 23, x^2 - 7]) sage: I = K.ideal(2, (a + 2*b + 3)/2) sage: I.pari_rhnf() @@ -208,6 +213,7 @@ def _from_absolute_ideal(self, id): TESTS:: + sage: x = polygen(ZZ, 'x') sage: L. = QQ.extension([x^2 + 71, x^3 + 2*x + 1]) sage: (2*a + b).norm() 22584817 @@ -236,6 +242,7 @@ def free_module(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^3 - x + 1, x^2 + 23]) sage: I = K.ideal(a*b - 1) sage: I.free_module() @@ -256,6 +263,7 @@ def gens_reduced(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 1, x^2 - 2]) sage: I = K.ideal((a + 1)*b/2 + 1) sage: I.gens_reduced() @@ -295,6 +303,7 @@ def __invert__(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 1, x^2 + 2]) sage: I = K.fractional_ideal(4) sage: I^(-1) @@ -313,6 +322,7 @@ def is_principal(self, proof=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 - 23, x^2 + 1]) sage: I = K.ideal([7, (-1/2*b - 3/2)*a + 3/2*b + 9/2]) sage: I.is_principal() @@ -338,6 +348,7 @@ def is_zero(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 3, x^3 + 4]) sage: K.ideal(17).is_zero() False @@ -354,6 +365,7 @@ def absolute_norm(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = QQ.extension([x^2 - 23, x^2 - 5, x^2 - 7]) sage: I = L.ideal(a + b) sage: I.absolute_norm() @@ -416,6 +428,7 @@ def norm(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 1, x^2 - 2]) sage: K.ideal(2).norm() Traceback (most recent call last): @@ -532,6 +545,7 @@ def factor(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = QQ.extension([x^2 + 11, x^2 - 5]) sage: K.factor(5) (Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 3/4))^2 * (Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 7/4))^2 @@ -568,6 +582,7 @@ def integral_basis(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 1, x^2 - 3]) sage: I = K.ideal(17*b - 3*a) sage: x = I.integral_basis(); x # random @@ -591,6 +606,7 @@ def integral_split(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 - 23, x^2 + 1]) sage: I = K.ideal([a + b/3]) sage: J, d = I.integral_split() @@ -608,6 +624,7 @@ def is_prime(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 - 17, x^3 - 2]) sage: K.ideal(a + b).is_prime() True @@ -628,12 +645,13 @@ def is_integral(self): EXAMPLES:: - sage: K. = QQ.extension([x^2 + 11, x^2 - 5]) - sage: I = K.ideal(7).prime_factors()[0] - sage: I.is_integral() - True - sage: (I/2).is_integral() - False + sage: x = polygen(ZZ, 'x') + sage: K. = QQ.extension([x^2 + 11, x^2 - 5]) + sage: I = K.ideal(7).prime_factors()[0] + sage: I.is_integral() + True + sage: (I/2).is_integral() + False """ return self.absolute_ideal().is_integral() @@ -712,6 +730,7 @@ def ramification_index(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 1, x^2 - 2]) sage: K.ideal(2).ramification_index() Traceback (most recent call last): @@ -745,6 +764,7 @@ def residues(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 - 3, x^2 + x + 1]) sage: I = K.ideal(6, -w*a - w + 4) sage: list(I.residues())[:5] @@ -778,6 +798,7 @@ def element_1_mod(self, other): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 - 23, x^2 + 1]) sage: I = Ideal(2, (a - 3*b + 2)/2) sage: J = K.ideal(a) @@ -809,6 +830,7 @@ def smallest_integer(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 - 23, x^2 + 1]) sage: I = K.ideal([a + b]) sage: I.smallest_integer() @@ -835,6 +857,7 @@ def valuation(self, p): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 - 17, x^3 - 2]) sage: A = K.ideal(a + b) sage: A.is_prime() @@ -868,6 +891,7 @@ def is_NumberFieldFractionalIdeal_rel(x): False sage: is_NumberFieldFractionalIdeal_rel(ideal(5)) False + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 2) sage: I = k.ideal([a + 1]); I Fractional ideal (a + 1) diff --git a/src/sage/rings/number_field/number_field_morphisms.pyx b/src/sage/rings/number_field/number_field_morphisms.pyx index 34a51a97c62..7de51f0f4fc 100644 --- a/src/sage/rings/number_field/number_field_morphisms.pyx +++ b/src/sage/rings/number_field/number_field_morphisms.pyx @@ -138,7 +138,8 @@ cdef class NumberFieldEmbedding(Morphism): EXAMPLES:: sage: from sage.rings.number_field.number_field_morphisms import NumberFieldEmbedding - sage: K. = NumberField(x^2-2) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 2) sage: f = NumberFieldEmbedding(K, RLF, 1.4) sage: f # indirect doctest Generic morphism: @@ -177,8 +178,9 @@ cdef class EmbeddedNumberFieldMorphism(NumberFieldEmbedding): EXAMPLES:: - sage: K. = NumberField(x^2+1,embedding=QQbar(I)) - sage: L. = NumberField(x^2+1,embedding=-QQbar(I)) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 1, embedding=QQbar(I)) + sage: L. = NumberField(x^2 + 1, embedding=-QQbar(I)) sage: from sage.rings.number_field.number_field_morphisms import EmbeddedNumberFieldMorphism sage: EmbeddedNumberFieldMorphism(K,L,CDF) Generic morphism: @@ -199,8 +201,9 @@ cdef class EmbeddedNumberFieldMorphism(NumberFieldEmbedding): EXAMPLES:: sage: from sage.rings.number_field.number_field_morphisms import EmbeddedNumberFieldMorphism - sage: K. = NumberField(x^2-17, embedding=4.1) - sage: L. = NumberField(x^4-17, embedding=2.0) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 17, embedding=4.1) + sage: L. = NumberField(x^4 - 17, embedding=2.0) sage: f = EmbeddedNumberFieldMorphism(K, L) sage: f(a) b^2 @@ -272,8 +275,9 @@ cdef class EmbeddedNumberFieldMorphism(NumberFieldEmbedding): EXAMPLES:: sage: from sage.rings.number_field.number_field_morphisms import EmbeddedNumberFieldMorphism - sage: K. = NumberField(x^2-700, embedding=25) - sage: L. = NumberField(x^6-700, embedding=3) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 700, embedding=25) + sage: L. = NumberField(x^6 - 700, embedding=3) sage: f = EmbeddedNumberFieldMorphism(K, L) sage: f(2*a-1) 2*b^3 - 1 @@ -302,8 +306,9 @@ cdef class EmbeddedNumberFieldConversion(Map): EXAMPLES:: sage: from sage.rings.number_field.number_field_morphisms import EmbeddedNumberFieldConversion - sage: K. = NumberField(x^2-17, embedding=4.1) - sage: L. = NumberField(x^4-17, embedding=2.0) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 17, embedding=4.1) + sage: L. = NumberField(x^4 - 17, embedding=2.0) sage: f = EmbeddedNumberFieldConversion(K, L) sage: f(a) b^2 @@ -512,7 +517,8 @@ def create_embedding_from_approx(K, gen_image): EXAMPLES:: sage: from sage.rings.number_field.number_field_morphisms import create_embedding_from_approx - sage: K. = NumberField(x^3-x+1/10) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - x + 1/10) sage: create_embedding_from_approx(K, 1) Generic morphism: From: Number Field in a with defining polynomial x^3 - x + 1/10 diff --git a/src/sage/rings/number_field/number_field_rel.py b/src/sage/rings/number_field/number_field_rel.py index 88284bf8ed0..c623b054bff 100644 --- a/src/sage/rings/number_field/number_field_rel.py +++ b/src/sage/rings/number_field/number_field_rel.py @@ -13,6 +13,7 @@ This example follows one in the Magma reference manual:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 - 420*x^2 + 40000) sage: z = y^5/11; z 420/11*y^3 - 40000/11*y @@ -116,6 +117,7 @@ def is_RelativeNumberField(x): EXAMPLES:: sage: from sage.rings.number_field.number_field_rel import is_RelativeNumberField + sage: x = polygen(ZZ, 'x') sage: is_RelativeNumberField(NumberField(x^2+1,'a')) False sage: k. = NumberField(x^3 - 2) @@ -155,6 +157,7 @@ class NumberField_relative(NumberField_generic): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: t = polygen(K) sage: L. = K.extension(t^2+t+a); L @@ -162,7 +165,7 @@ class NumberField_relative(NumberField_generic): TESTS:: - sage: Z = var('Z') + sage: Z = polygen(ZZ, 'Z') sage: K. = NumberField(Z^3 + Z + 1) sage: L. = K.extension(Z^3 + 2) sage: K = loads(dumps(L)) @@ -339,6 +342,7 @@ def change_names(self, names): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^4 + 3, x^2 + 2]); K Number Field in a with defining polynomial x^4 + 3 over its base field sage: L. = K.change_names() @@ -448,6 +452,7 @@ def is_absolute(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^4 + 3, x^2 + 2]); K Number Field in a with defining polynomial x^4 + 3 over its base field sage: K.is_absolute() @@ -463,6 +468,7 @@ def gens(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^4 + 3, x^2 + 2]); K Number Field in a with defining polynomial x^4 + 3 over its base field sage: K.gens() @@ -490,6 +496,7 @@ def _first_ngens(self, n): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^4 + 3, x^2 + 2]); K Number Field in a with defining polynomial x^4 + 3 over its base field sage: K._first_ngens(0) @@ -514,6 +521,7 @@ def ngens(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^4 + 3, x^2 + 2]); K Number Field in a with defining polynomial x^4 + 3 over its base field sage: K.gens() @@ -529,6 +537,7 @@ def gen(self, n=0): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^4 + 3, x^2 + 2]); K Number Field in a with defining polynomial x^4 + 3 over its base field sage: K.gens() @@ -547,6 +556,7 @@ def galois_closure(self, names=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^4 + 3, x^2 + 2]); K Number Field in a with defining polynomial x^4 + 3 over its base field sage: K.galois_closure('c') @@ -585,6 +595,7 @@ def composite_fields(self, other, names=None, both_maps=False, preserve_embeddin EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 5, x^2 - 2]) sage: L. = NumberField([x^2 + 5, x^2 - 3]) sage: K.composite_fields(L, 'e') @@ -644,6 +655,7 @@ def absolute_degree(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 - 17, x^3 - 2]) sage: K.absolute_degree() 6 @@ -656,6 +668,7 @@ def relative_degree(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 - 17, x^3 - 2]) sage: K.relative_degree() 2 @@ -670,6 +683,7 @@ def degree(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 - 17, x^3 - 2]) sage: K.degree() Traceback (most recent call last): @@ -686,6 +700,7 @@ def _maximal_order(self, v=(), assume_maximal='non-maximal-non-unique'): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 - 17, x^3 - 2]) sage: K.maximal_order() is K.maximal_order() # indirect doctest True @@ -704,6 +719,7 @@ def _repr_(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField([x^5 + 2, x^7 + 3]) sage: repr(k) # indirect doctest 'Number Field in a with defining polynomial x^5 + 2 over its base field' @@ -723,6 +739,7 @@ def _Hom_(self, codomain, category=None): This function is implicitly called by the ``Hom`` method or function:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^3 - 2, x^2+1]) sage: K.Hom(K) # indirect doctest Automorphism group of Number Field in a with defining polynomial x^3 - 2 over its base field @@ -748,6 +765,7 @@ def _latex_(self): EXAMPLES:: sage: x = polygen(QQ) + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: t = polygen(K) sage: K.extension(t^2+t+a, 'b')._latex_() @@ -770,6 +788,7 @@ def _coerce_from_other_number_field(self, x): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: L. = NumberField(x^2 + 1) sage: K._coerce_from_other_number_field(L(2/3)) @@ -951,6 +970,7 @@ def _coerce_map_from_(self, R): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField([x^5 + 2, x^7 + 3]) sage: b = k(k.base_field().gen()) sage: b = k.coerce(k.base_field().gen()) # indirect doctest @@ -1032,6 +1052,7 @@ def __base_inclusion(self, element): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField([x^2 + 3, x^2 + 1]) sage: m = k.base_field(); m Number Field in a1 with defining polynomial x^2 + 1 @@ -1079,6 +1100,7 @@ def _fractional_ideal_class_(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField([x^5 + 2, x^7 + 3]) sage: k._fractional_ideal_class_ () @@ -1100,6 +1122,7 @@ def _pari_base_bnf(self, proof=False, units=True): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField([x^3 + 2, x^2 + 2]) sage: k._pari_base_bnf() [[;], matrix(0,3), [;], ...] @@ -1133,7 +1156,8 @@ def is_galois(self): EXAMPLES:: - sage: k. =NumberField([x^3 - 2, x^2 + x + 1]) + sage: x = polygen(ZZ, 'x') + sage: k. = NumberField([x^3 - 2, x^2 + x + 1]) sage: k.is_galois() Traceback (most recent call last): ... @@ -1148,6 +1172,7 @@ def is_galois_relative(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: y = polygen(K) sage: L. = K.extension(y^2 - a) @@ -1176,6 +1201,7 @@ def is_galois_absolute(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: y = polygen(K); L. = K.extension(y^2 - a) sage: L.is_galois_absolute() @@ -1194,6 +1220,7 @@ def is_isomorphic_relative(self, other, base_isom=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^6 + x^3 + 1) sage: R. = PolynomialRing(K) sage: m1 = 3*z9^4 - 4*z9^3 - 4*z9^2 + 3*z9 - 8 @@ -1270,6 +1297,7 @@ def is_CM_extension(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: F. = NumberField(x^2 - 5) sage: K. = F.extension(x^2 + 7) sage: K.is_CM_extension() @@ -1327,6 +1355,7 @@ def free_module(self, base=None, basis=None, map=True): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 2, x^3 + 2, x^3 + 3]); K Number Field in a with defining polynomial x^2 + 2 over its base field sage: V, from_V, to_V = K.free_module() @@ -1367,6 +1396,7 @@ def relative_vector_space(self, base=None, *args, **kwds): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 2, x^3 + 2, x^3 + 3]); K Number Field in a with defining polynomial x^2 + 2 over its base field sage: V, from_V, to_V = K.relative_vector_space() @@ -1398,6 +1428,7 @@ def absolute_vector_space(self, base=None, *args, **kwds): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^3 + 3, x^3 + 2]); K Number Field in a with defining polynomial x^3 + 3 over its base field sage: V,from_V,to_V = K.absolute_vector_space(); V @@ -1431,6 +1462,7 @@ def vector_space(self, *args, **kwds): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 - 17, x^3 - 2]) sage: K.vector_space() Traceback (most recent call last): @@ -1447,6 +1479,7 @@ def absolute_base_field(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 2, x^3 + 3, x^3 + 2]) sage: K Number Field in a with defining polynomial x^2 + 2 over its base field @@ -1473,6 +1506,7 @@ def _pari_rnfeq(self): TESTS:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 2) sage: x = polygen(K) sage: L. = K.extension(x^5 + 2*a) @@ -1484,6 +1518,7 @@ def _pari_rnfeq(self): Initialization is lazy enough to allow arithmetic in massive fields:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^10 + 2000*x + 100001) sage: x = polygen(K) sage: L. = K.extension(x^10 + 2*a) @@ -1508,6 +1543,7 @@ def _pari_nfzk(self): TESTS:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 2) sage: L. = K.extension(x^2 - 3) sage: L._pari_nfzk() @@ -1601,7 +1637,8 @@ def _gen_relative(self): EXAMPLES:: - sage: k. = NumberField(x^2+1); k + sage: x = polygen(ZZ, 'x') + sage: k. = NumberField(x^2 + 1); k Number Field in a with defining polynomial x^2 + 1 sage: y = polygen(k) sage: m. = k.extension(y^2+3); m @@ -1630,6 +1667,7 @@ def pari_rnf(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField([x^4 + 3, x^2 + 2]) sage: k.pari_rnf() [x^4 + 3, [364, -10*x^7 - 87*x^5 - 370*x^3 - 41*x], [108, 3], ...] @@ -1643,6 +1681,7 @@ def pari_absolute_base_polynomial(self): EXAMPLES:: sage: x = polygen(ZZ) + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 2, x^2 + 3]); K Number Field in a with defining polynomial x^2 + 2 over its base field sage: K.pari_absolute_base_polynomial() @@ -1676,6 +1715,7 @@ def pari_relative_polynomial(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: m. = k.extension(k['w']([i,0,1])) sage: m @@ -1695,7 +1735,8 @@ def number_of_roots_of_unity(self): EXAMPLES:: - sage: K. = NumberField( [x^2 + x + 1, x^4 + 1] ) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField([x^2 + x + 1, x^4 + 1]) sage: K.number_of_roots_of_unity() 24 """ @@ -1707,7 +1748,8 @@ def roots_of_unity(self): EXAMPLES:: - sage: K. = NumberField( [x^2 + x + 1, x^4 + 1] ) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField([x^2 + x + 1, x^4 + 1]) sage: rts = K.roots_of_unity() sage: len(rts) 24 @@ -1757,6 +1799,7 @@ def absolute_field(self, names): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^4 + 3, x^2 + 2]); K Number Field in a with defining polynomial x^4 + 3 over its base field sage: L. = K.absolute_field(); L @@ -1795,6 +1838,7 @@ def absolute_polynomial_ntl(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: NumberField(x^2 + (2/3)*x - 9/17,'a').absolute_polynomial_ntl() ([-27 34 51], 51) """ @@ -1826,6 +1870,7 @@ def absolute_polynomial(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField([x^2 + 1, x^3 + x + 1]); k Number Field in a with defining polynomial x^2 + 1 over its base field sage: k.absolute_polynomial() @@ -1834,6 +1879,7 @@ def absolute_polynomial(self): An example comparing the various defining polynomials to their PARI counterparts:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField([x^2 + 1/3, x^2 + 1/4]) sage: k.absolute_polynomial() x^4 - x^2 + 1 @@ -1856,6 +1902,7 @@ def relative_polynomial(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 + x + 1, x^3 + x + 1]) sage: K.relative_polynomial() x^2 + x + 1 @@ -1893,6 +1940,7 @@ def polynomial(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 + x + 1, x^3 + x + 1]) sage: K.polynomial() Traceback (most recent call last): @@ -1907,6 +1955,7 @@ def base_field(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField([x^3 + x + 1]) sage: R. = k[] sage: L. = NumberField(z^3 + a) @@ -1929,6 +1978,7 @@ def base_ring(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField([x^2 + 1, x^3 + x + 1]) sage: k.base_ring() Number Field in a1 with defining polynomial x^3 + x + 1 @@ -1953,7 +2003,8 @@ def embeddings(self, K): EXAMPLES:: - sage: K. = NumberField([x^3 - 2, x^2+1]) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField([x^3 - 2, x^2 + 1]) sage: f = K.embeddings(ComplexField(58)); f [ Relative number field morphism: @@ -2001,6 +2052,7 @@ def automorphisms(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 10000, x^2 + x + 50]); K Number Field in a with defining polynomial x^2 + 10000 over its base field sage: K.automorphisms() @@ -2099,6 +2151,7 @@ def logarithmic_embedding(self, prec=53): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: t = K['t'].gen() sage: L. = K.extension(t^4 - i) @@ -2155,6 +2208,7 @@ def places(self, all_complex=False, prec=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberFieldTower([x^2 - 5, x^3 + x + 3]) sage: L.places() [Relative number field morphism: @@ -2190,6 +2244,7 @@ def absolute_different(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: t = K['t'].gen() sage: L. = K.extension(t^4 - i) @@ -2208,6 +2263,7 @@ def relative_different(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: PK. = K[] sage: L. = K.extension(t^4 - i) @@ -2226,6 +2282,7 @@ def different(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 + x + 1, x^3 + x + 1]) sage: K.different() Traceback (most recent call last): @@ -2248,6 +2305,7 @@ def absolute_discriminant(self, v=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: t = K['t'].gen() sage: L. = K.extension(t^4 - i) @@ -2270,6 +2328,7 @@ def relative_discriminant(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: t = K['t'].gen() sage: L. = K.extension(t^4 - i) @@ -2305,6 +2364,7 @@ def discriminant(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 + x + 1, x^3 + x + 1]) sage: K.discriminant() Traceback (most recent call last): @@ -2321,6 +2381,7 @@ def disc(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberFieldTower([x^2 + x + 1, x^3 + x + 1]) sage: K.disc() Traceback (most recent call last): @@ -2407,8 +2468,9 @@ def _factor_univariate_polynomial(self, poly, **kwargs): EXAMPLES:: - sage: K. = NumberField(x**2+1) - sage: L. = K.extension(x*x-2) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x**2 + 1) + sage: L. = K.extension(x*x - 2) sage: x = polygen(L,'x') sage: factor(x**2+8) # indirect doctest (x + 2*i*sqrt2) * (x - 2*i*sqrt2) @@ -2492,6 +2554,7 @@ def relativize(self, alpha, names): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^4 + 3, x^2 + 2]); K Number Field in a with defining polynomial x^4 + 3 over its base field sage: L. = K.relativize(a^2) @@ -2589,6 +2652,7 @@ def uniformizer(self, P, others = "positive"): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 23, x^2 - 3]) sage: P = K.prime_factors(5)[0]; P Fractional ideal (5, 1/2*a + b - 5/2) diff --git a/src/sage/rings/number_field/order.py b/src/sage/rings/number_field/order.py index 288e4dc83c5..0a7d9c5c420 100644 --- a/src/sage/rings/number_field/order.py +++ b/src/sage/rings/number_field/order.py @@ -9,6 +9,7 @@ We define an absolute order:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1); O = K.order(2*a) sage: O.basis() [1, 2*a] @@ -115,6 +116,7 @@ def get_object(self, version, key, extra_args): internal state when they are recreated with more additional information available about them:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 - 1000003, x^2 - 5*1000099^2]) sage: O = L.maximal_order([2], assume_maximal=None) @@ -152,6 +154,7 @@ class AbsoluteOrderFactory(OrderFactory): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: K.order(i) Order in Number Field in i with defining polynomial x^2 + 1 @@ -166,6 +169,7 @@ def create_key_and_extra_args(self, K, module_rep, is_maximal=None, check=True, In particular, this normalizes the data that is used when pickling orders:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: OK = K.order(i) sage: OK._factory_data @@ -204,6 +208,7 @@ def create_object(self, version, key, is_maximal=None, is_maximal_at=()): This method is also used during unpickling:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: OK = K.order(i) sage: loads(dumps(OK)) is OK @@ -228,6 +233,7 @@ def reduce_data(self, order): This also works for relative orders since they are wrapping absolute orders:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 - 1000003, x^2 - 5*1000099^2]) sage: O = L.maximal_order([5], assume_maximal=None) @@ -258,6 +264,7 @@ class RelativeOrderFactory(OrderFactory): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: R. = K[] sage: L. = K.extension(j^2 - 2) @@ -274,6 +281,7 @@ def create_key_and_extra_args(self, K, absolute_order, is_maximal=None, check=Tr In particular, this normalizes the data that is used when pickling orders:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: R. = K[] sage: L. = K.extension(j^2 - 2) @@ -301,6 +309,7 @@ def create_object(self, version, key, is_maximal=None, is_maximal_at=()): This method is also used during unpickling:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: R. = K[] sage: L. = K.extension(j^2 - 2) @@ -326,7 +335,8 @@ def is_NumberFieldOrder(R): EXAMPLES:: sage: from sage.rings.number_field.order import is_NumberFieldOrder - sage: is_NumberFieldOrder(NumberField(x^2+1,'a').maximal_order()) + sage: x = polygen(ZZ, 'x') + sage: is_NumberFieldOrder(NumberField(x^2 + 1,'a').maximal_order()) True sage: is_NumberFieldOrder(ZZ) True @@ -350,7 +360,8 @@ def EquationOrder(f, names, **kwds): EXAMPLES:: - sage: O. = EquationOrder([x^2+1, x^2+2]) + sage: x = polygen(ZZ, 'x') + sage: O. = EquationOrder([x^2 + 1, x^2 + 2]) sage: O Relative Order in Number Field in a with defining polynomial x^2 + 1 over its base field sage: O.0 @@ -397,6 +408,7 @@ class Order(IntegralDomain, sage.rings.abc.Order): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 + x + 17) sage: K.maximal_order() Maximal Order in Number Field in theta with defining polynomial x^4 + x + 17 @@ -432,7 +444,8 @@ def __init__(self, K): TESTS:: - sage: k. = NumberField(x^7+3*x+1, embedding=CC(0,1)) + sage: x = polygen(ZZ, 'x') + sage: k. = NumberField(x^7 + 3*x + 1, embedding=CC(0,1)) sage: O = k.order(alg) sage: ordelt = O(alg) sage: CC(ordelt) @@ -450,6 +463,7 @@ def fractional_ideal(self, *args, **kwds): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 2) sage: R = K.maximal_order() sage: R.fractional_ideal(2/3 + 7*a, a) @@ -463,6 +477,7 @@ def ideal(self, *args, **kwds): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 7) sage: R = K.maximal_order() sage: R.ideal(2/3 + 7*a, a) @@ -510,6 +525,7 @@ def _coerce_map_from_(self, R): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 5077) sage: Ok = k.maximal_order() sage: Ok.has_coerce_map_from(k) #indirect doctest @@ -525,6 +541,7 @@ def __mul__(self, right): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 5077); G = k.class_group(); G Class group of order 22 with structure C22 of Number Field in a with defining polynomial x^2 + 5077 sage: G.0 ^ -9 @@ -546,6 +563,7 @@ def __rmul__(self, left): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 431); G = k.class_group(); G Class group of order 21 with structure C21 of Number Field in a with defining polynomial x^2 + 431 sage: G.0 # random output @@ -565,6 +583,7 @@ def is_field(self, proof=True): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x**4 - x**2 + 7) sage: O = L.maximal_order() ; O.is_field() False @@ -579,6 +598,7 @@ def is_noetherian(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x**4 - x**2 + 7) sage: O = L.maximal_order() ; O.is_noetherian() True @@ -595,6 +615,7 @@ def is_integrally_closed(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 189*x + 394) sage: R = K.order(2*a) sage: R.is_integrally_closed() @@ -650,6 +671,7 @@ def gen(self, i): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2*x + 17) sage: O = K.maximal_order(); O Maximal Order in Number Field in c with defining polynomial x^3 + 2*x + 17 @@ -679,6 +701,7 @@ def ngens(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + x^2 - 2*x + 8) sage: O = K.maximal_order() sage: O.ngens() @@ -692,6 +715,7 @@ def basis(self): # this must be defined in derived class EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + x^2 - 16*x + 16) sage: O = K.maximal_order(); O Maximal Order in Number Field in a with defining polynomial x^3 + x^2 - 16*x + 16 @@ -768,6 +792,7 @@ def free_module(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + x^2 - 2*x + 8) sage: O = K.maximal_order(); O.basis() [1, 1/2*a^2 + 1/2*a, a^2] @@ -782,6 +807,7 @@ def free_module(self): a `\ZZ`-module in the absolute_field associated to the relative field:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 1, x^2 + 2]) sage: O = K.maximal_order(); O.basis() [(-3/2*b - 5)*a + 7/2*b - 2, -3*a + 2*b, -2*b*a - 3, -7*a + 5*b] @@ -809,6 +835,7 @@ def ring_generators(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: O = K.maximal_order(); O Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 @@ -853,6 +880,7 @@ def _defining_names(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: B. = EquationOrder(x^2 + 3) sage: B._defining_names() (z,) @@ -873,7 +901,8 @@ def zeta(self, n=2, all=False): EXAMPLES:: - sage: F. = NumberField(x**2+3) + sage: x = polygen(ZZ, 'x') + sage: F. = NumberField(x**2 + 3) sage: F.ring_of_integers().zeta(6) -1/2*alpha + 1/2 sage: O = F.order([3*alpha]) @@ -901,6 +930,7 @@ def number_field(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 + x^2 + 2) sage: O = K.order(2*b); O Order in Number Field in b with defining polynomial x^4 + x^2 + 2 @@ -922,6 +952,7 @@ def ambient(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 - 389) sage: o = k.order(389*z + 1) sage: o @@ -950,7 +981,8 @@ def residue_field(self, prime, names=None, check=False): EXAMPLES:: sage: R. = QQ[] - sage: K. = NumberField(x^4+3*x^2-17) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^4 + 3*x^2 - 17) sage: P = K.ideal(61).factor()[0][0] sage: OK = K.maximal_order() sage: OK.residue_field(P) @@ -972,6 +1004,7 @@ def fraction_field(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 + 17*x^2 + 17) sage: O = K.order(17*b); O Order in Number Field in b with defining polynomial x^4 + 17*x^2 + 17 @@ -987,6 +1020,7 @@ def degree(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 + x^2 - 2*x+8) sage: o = k.maximal_order() sage: o.degree() @@ -1006,6 +1040,7 @@ def rank(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^5 + x^2 + 1) sage: o = k.maximal_order(); o Maximal Order in Number Field in c with defining polynomial x^5 + x^2 + 1 @@ -1054,6 +1089,7 @@ def class_group(self, proof=None, names='c'): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 5077) sage: O = k.maximal_order(); O Maximal Order in Number Field in a with defining polynomial x^2 + 5077 @@ -1072,6 +1108,7 @@ def is_suborder(self, other): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: W. = NumberField(x^2 + 1) sage: O5 = W.order(5*i) sage: O10 = W.order(10*i) @@ -1119,6 +1156,7 @@ def __eq__(self, other): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: O1 = K.order(a); O1 Order in Number Field in a with defining polynomial x^3 + 2 @@ -1151,6 +1189,7 @@ def __ne__(self, other): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: O1 = K.order(a); O1 Order in Number Field in a with defining polynomial x^3 + 2 @@ -1167,6 +1206,7 @@ def __hash__(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: L. = NumberField(x^3 + 3) sage: O1 = K.order(a) @@ -1234,6 +1274,7 @@ def random_element(self, *args, **kwds): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: OK = K.ring_of_integers() sage: OK.random_element() # random output @@ -1291,6 +1332,7 @@ def absolute_degree(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: O = K.maximal_order() sage: O.absolute_degree() @@ -1307,6 +1349,7 @@ def valuation(self, p): The valuation can be specified with an integer ``prime`` that is completely ramified or unramified:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: O = K.order(2*a) sage: valuations.pAdicValuation(O, 2) @@ -1571,6 +1614,7 @@ def __and__(left, right): Verify that an absolute order can be intersected with a relative order:: + sage: x = polygen(ZZ, 'x') sage: L. = K.extension(x^2 - 2) sage: L.absolute_field('z').maximal_order() & L.maximal_order() Maximal Order in Number Field in z with defining polynomial x^4 - 2*x^2 + 9 @@ -1610,6 +1654,7 @@ def _magma_init_(self, magma): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) # optional - magma sage: magma(K.maximal_order()) # optional - magma Equation Order with defining polynomial x^3 + 2 over its ground order @@ -1629,6 +1674,7 @@ def discriminant(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^8 + x^3 - 13*x + 26) sage: O = K.maximal_order() sage: factor(O.discriminant()) @@ -1669,6 +1715,7 @@ def is_maximal(self, p=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: K.order(3*i).is_maximal() @@ -1723,6 +1770,7 @@ def _is_maximal(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: K.order(1337*i)._is_maximal() is None @@ -1746,6 +1794,7 @@ def _is_maximal_at(self, p=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^13 - 2) sage: O = K.order(a) @@ -1783,6 +1832,7 @@ def _assume_maximal(self, is_maximal=True, p=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 - 10001822082820*x^2 + 25009091240356266913960000) sage: O = K.maximal_order([13], assume_maximal=None) @@ -1870,6 +1920,7 @@ def change_names(self, names): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: R = EquationOrder(x^3 + x + 1, 'alpha'); R Order in Number Field in alpha with defining polynomial x^3 + x + 1 sage: R.basis() @@ -1901,6 +1952,7 @@ def index_in(self, other): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: O1 = k.order(i) sage: O5 = k.order(5*i) @@ -1938,6 +1990,7 @@ def module(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 + x + 3) sage: m = k.order(3*a); m Order in Number Field in a with defining polynomial x^3 + x + 3 @@ -1956,6 +2009,7 @@ def intersection(self, other): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^2 + 1) sage: O6 = k.order(6*i) sage: O9 = k.order(9*i) @@ -1978,6 +2032,7 @@ def _repr_(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 - 5) sage: K.maximal_order()._repr_() 'Maximal Order in Number Field in a with defining polynomial x^4 - 5' @@ -2011,6 +2066,7 @@ def basis(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberField(x^3 + x^2 + 1) sage: O = k.maximal_order(); O Maximal Order in Number Field in c with defining polynomial x^3 + x^2 + 1 @@ -2048,6 +2104,7 @@ def absolute_order(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: O1 = K.order(a); O1 Maximal Order in Number Field in a with defining polynomial x^3 + 2 @@ -2073,6 +2130,7 @@ def __init__(self, K, absolute_order): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: k. = NumberFieldTower([x^2 - 3, x^2 + 1]) sage: O = k.maximal_order(); O # indirect doctest Maximal Relative Order in Number Field in a with defining polynomial x^2 - 3 over its base field @@ -2097,6 +2155,7 @@ def _element_constructor_(self, x): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 2, x^2 + 1000*x + 1]) sage: OK = K.ring_of_integers() sage: OK(a) @@ -2140,6 +2199,7 @@ def _repr_(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: O = EquationOrder([x^2 + x + 1, x^3 - 2],'a,b') sage: O._repr_() 'Relative Order in Number Field in a with defining polynomial x^2 + x + 1 over its base field' @@ -2162,6 +2222,7 @@ def absolute_order(self, names='z'): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: R = EquationOrder([x^2 + 1, x^2 - 5], 'i,g'); R Relative Order in Number Field in i with defining polynomial x^2 + 1 over its base field sage: R.basis() @@ -2194,7 +2255,8 @@ def basis(self): EXAMPLES:: - sage: K. = NumberField([x^2+1, x^2+3]) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField([x^2 + 1, x^2 + 3]) sage: O = K.order([a,b]) sage: O.basis() [1, -2*a + b, -b*a - 2, -5*a + 3*b] @@ -2220,7 +2282,8 @@ def __add__(left, right): EXAMPLES:: - sage: K. = NumberField([x^2+1, x^2+3]) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField([x^2 + 1, x^2 + 3]) sage: O2 = K.order([2*a, b]); O2.absolute_discriminant() 36864 sage: O3 = K.order([3*a, 2*b]); O3.absolute_discriminant() @@ -2260,6 +2323,7 @@ def __and__(left, right): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 + 1, x^2 - 5]) sage: O1 = L.order([a, 2*b]) sage: O2 = L.order([2*a, b]) @@ -2298,6 +2362,7 @@ def is_maximal(self, p=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 1, x^2 - 5]) sage: K.order(3*a, b).is_maximal() @@ -2329,6 +2394,7 @@ def _is_maximal(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 1, x^2 - 5]) sage: O = K.order(a, b) sage: O._is_maximal() is None @@ -2350,6 +2416,7 @@ def _is_maximal_at(self, p=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 - 2, x^13 - 2]) sage: O = K.maximal_order([2, 3, 5], assume_maximal=None) sage: O._is_maximal_at(p=7) is None @@ -2375,6 +2442,7 @@ def _assume_maximal(self, is_maximal=True, p=None): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: L. = NumberField([x^2 - 1000005, x^2 - 5*1000099^2]) sage: O = L.maximal_order([13], assume_maximal=None) @@ -2434,6 +2502,7 @@ def absolute_discriminant(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: R = EquationOrder([x^2 + 1, x^3 + 2], 'a,b') sage: d = R.absolute_discriminant(); d -746496 @@ -2450,6 +2519,7 @@ def is_suborder(self, other): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 1, x^3 + 2]) sage: R1 = K.order([a,b]) sage: R2 = K.order([2*a,b]) @@ -2484,6 +2554,7 @@ def index_in(self, other): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^3 + x + 3, x^2 + 1]) sage: R1 = K.order([3*a, 2*b]) sage: R2 = K.order([a, 4*b]) @@ -2504,6 +2575,7 @@ def each_is_integral(v): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: W. = NumberField(x^2 - 5) sage: from sage.rings.number_field.order import each_is_integral sage: each_is_integral([sqrt5, 2, (1+sqrt5)/2]) @@ -2533,6 +2605,7 @@ def absolute_order_from_ring_generators(gens, check_is_integral=True, EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 - 5) sage: K.order(a) Order in Number Field in a with defining polynomial x^4 - 5 @@ -2610,6 +2683,7 @@ def absolute_order_from_module_generators(gens, sage: from sage.rings.number_field.order import absolute_order_from_module_generators + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 - 5) sage: O = K.maximal_order(); O Maximal Order in Number Field in a with defining polynomial x^4 - 5 @@ -2746,6 +2820,7 @@ def relative_order_from_ring_generators(gens, for regular usage:: sage: from sage.rings.number_field.order import relative_order_from_ring_generators + sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^2 + 1, x^2 - 17]) sage: R = K.base_field().maximal_order() sage: S = relative_order_from_ring_generators([i,a]); S diff --git a/src/sage/rings/number_field/selmer_group.py b/src/sage/rings/number_field/selmer_group.py index 487550ef4d5..6b073dc5826 100644 --- a/src/sage/rings/number_field/selmer_group.py +++ b/src/sage/rings/number_field/selmer_group.py @@ -172,6 +172,7 @@ def _coords_in_C_mod_p(I,C,p): of which is not cyclic:: sage: from sage.rings.number_field.selmer_group import _coords_in_C_mod_p + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - x + 58) sage: C = K.class_group() sage: C.gens_orders() @@ -207,6 +208,7 @@ def _root_ideal(I, C, p): EXAMPLES:: sage: from sage.rings.number_field.selmer_group import _root_ideal + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - x + 58) sage: C = K.class_group() sage: cyclic_gens = C.gens_ideals() @@ -264,6 +266,7 @@ def coords_in_U_mod_p(u, U, p): EXAMPLES:: sage: from sage.rings.number_field.selmer_group import coords_in_U_mod_p + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 - 5*x^2 + 1) sage: U = K.unit_group() sage: U @@ -314,6 +317,7 @@ class is a ``p``'th power; EXAMPLES:: sage: from sage.rings.number_field.selmer_group import basis_for_p_cokernel + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - x + 58) sage: S = K.ideal(30).support(); S [Fractional ideal (2, a), diff --git a/src/sage/rings/number_field/structure.py b/src/sage/rings/number_field/structure.py index 52e6ed6d503..09f15b1bba1 100644 --- a/src/sage/rings/number_field/structure.py +++ b/src/sage/rings/number_field/structure.py @@ -72,7 +72,8 @@ class NumberFieldStructure(UniqueRepresentation): True sage: R. = QQ[] - sage: K. = NumberField(x^2+1) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 1) sage: L = K.change_names('j').change_names('i') sage: K is L # K and L differ in "structure", one is the "name-change" of the other False @@ -153,7 +154,8 @@ class NameChange(NumberFieldStructure): Check for memory leaks:: - sage: u=id(NumberField(x^2-5,'a').absolute_field('b')) + sage: x = polygen(ZZ, 'x') + sage: u = id(NumberField(x^2 - 5,'a').absolute_field('b')) sage: import gc sage: gc.collect() #random 10 diff --git a/src/sage/rings/number_field/totallyreal_rel.py b/src/sage/rings/number_field/totallyreal_rel.py index 07477c46f8f..421ddff0947 100644 --- a/src/sage/rings/number_field/totallyreal_rel.py +++ b/src/sage/rings/number_field/totallyreal_rel.py @@ -254,7 +254,8 @@ def __init__(self, F, m, B, a=None): EXAMPLES:: - sage: F. = NumberField(x^2-2) + sage: x = polygen(ZZ, 'x') + sage: F. = NumberField(x^2 - 2) sage: T = sage.rings.number_field.totallyreal_rel.tr_data_rel(F, 2, 2000) """ if a is None: # don't make the stupid noob mistake of putting a=[] diff --git a/src/sage/rings/padics/eisenstein_extension_generic.py b/src/sage/rings/padics/eisenstein_extension_generic.py index 4f68e63ffae..4b97ff9069a 100644 --- a/src/sage/rings/padics/eisenstein_extension_generic.py +++ b/src/sage/rings/padics/eisenstein_extension_generic.py @@ -50,6 +50,7 @@ def _extension_type(self): sage: K._extension_type() 'Unramified' + sage: x = polygen(ZZ, 'x') sage: L. = Qp(5).extension(x^2 - 5) sage: L._extension_type() 'Eisenstein' @@ -66,6 +67,7 @@ def absolute_e(self): sage: K.absolute_e() 1 + sage: x = polygen(ZZ, 'x') sage: L. = Qp(3).extension(x^2 - 3) sage: L.absolute_e() 2 diff --git a/src/sage/rings/padics/morphism.pyx b/src/sage/rings/padics/morphism.pyx index 407bc146990..bf61e1877ef 100644 --- a/src/sage/rings/padics/morphism.pyx +++ b/src/sage/rings/padics/morphism.pyx @@ -63,6 +63,7 @@ cdef class FrobeniusEndomorphism_padics(RingHomomorphism): TypeError: n (=a + O(5^20)) is not an integer sage: K = Qp(5) + sage: x = polygen(ZZ, 'x') sage: L. = K.extension(x^2 - 5) sage: FrobeniusEndomorphism_padics(L) Traceback (most recent call last): diff --git a/src/sage/rings/padics/padic_ZZ_pX_element.pyx b/src/sage/rings/padics/padic_ZZ_pX_element.pyx index ec33070be49..b0beaa85617 100644 --- a/src/sage/rings/padics/padic_ZZ_pX_element.pyx +++ b/src/sage/rings/padics/padic_ZZ_pX_element.pyx @@ -614,7 +614,8 @@ def _test_preprocess_list(R, L): ([1, 10, 25, 0], -1, NTL modulus 625) sage: _test_preprocess_list(ZqCA(25,names='a',implementation="NTL"), [1/5,mod(2,625),Zp(5)(5,3),mod(0,3125)]) ([1, 10, 25, 0], -1, NTL modulus 625) - sage: T. = Qp(5).extension(x^2-5) + sage: x = polygen(ZZ, 'x') + sage: T. = Qp(5).extension(x^2 - 5) sage: _test_preprocess_list(T, [5^-1 + O(5)]) ([1], -1, NTL modulus 25) """ diff --git a/src/sage/rings/padics/padic_ext_element.pyx b/src/sage/rings/padics/padic_ext_element.pyx index 39f58efcd0b..2728506f709 100644 --- a/src/sage/rings/padics/padic_ext_element.pyx +++ b/src/sage/rings/padics/padic_ext_element.pyx @@ -368,6 +368,7 @@ cdef class pAdicExtElement(pAdicGenericElement): An error will be raised if the parent of self is a ramified extension:: + sage: x = polygen(ZZ, 'x') sage: K. = Qp(5).extension(x^2 - 5) sage: a.frobenius() Traceback (most recent call last): diff --git a/src/sage/rings/padics/padic_extension_generic.py b/src/sage/rings/padics/padic_extension_generic.py index b93c404f660..88027e19439 100644 --- a/src/sage/rings/padics/padic_extension_generic.py +++ b/src/sage/rings/padics/padic_extension_generic.py @@ -118,6 +118,7 @@ def _extension_type(self): sage: K._extension_type() 'Unramified' + sage: x = polygen(ZZ, 'x') sage: L. = Qp(5).extension(x^2 - 5) sage: L._extension_type() 'Eisenstein' @@ -138,7 +139,8 @@ def _repr_(self, do_latex=False): 7-adic Unramified Extension Ring in a defined by x^3 + 6*x^2 + 4 sage: R1._latex_() '\\Bold{Z}_{7^{3}}' - sage: R2. = R.ext(x^2+7) + sage: x = polygen(ZZ, 'x') + sage: R2. = R.ext(x^2 + 7) sage: R2 #indirect doctest 7-adic Eisenstein Extension Ring in t defined by x^2 + 7 sage: R2._latex_() diff --git a/src/sage/rings/padics/padic_generic_element.pyx b/src/sage/rings/padics/padic_generic_element.pyx index 081c086f5af..efcbf539b73 100644 --- a/src/sage/rings/padics/padic_generic_element.pyx +++ b/src/sage/rings/padics/padic_generic_element.pyx @@ -562,6 +562,7 @@ cdef class pAdicGenericElement(LocalGenericElement): We check that :trac:`26479` is fixed:: + sage: x = polygen(ZZ, 'x') sage: K. = Qp(2).extension(x^3 - 2) sage: latex(pi) \pi + O(\pi^{61}) @@ -1939,6 +1940,7 @@ cdef class pAdicGenericElement(LocalGenericElement): Over totally ramified extensions:: + sage: x = polygen(ZZ, 'x') sage: L2. = Qp(5).extension(x^4 + 5*x^3 + 10*x^2 + 10*x + 5) sage: u = 1 + pi sage: u.multiplicative_order() @@ -2178,6 +2180,7 @@ cdef class pAdicGenericElement(LocalGenericElement): :: + sage: x = polygen(ZZ, 'x') sage: B. = A.extension(x^5 - 2) sage: pi.is_prime() True @@ -3428,6 +3431,7 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: u.square_root() 1 + t*2^2 + t^2*2^3 + t^2*2^4 + (t^4 + t^3 + t^2)*2^5 + (t^4 + t^2)*2^6 + (t^5 + t^2)*2^7 + (t^6 + t^5 + t^4 + t^2)*2^8 + O(2^9) + sage: x = polygen(ZZ, 'x') sage: R. = Zp(2).extension(x^3 - 2) sage: u = R(1 + a^4 + a^5 + a^7 + a^8, 10); u 1 + a^4 + a^5 + a^7 + a^8 + O(a^10) diff --git a/src/sage/rings/padics/padic_valuation.py b/src/sage/rings/padics/padic_valuation.py index a9df7bd33cf..0c0883dfa96 100644 --- a/src/sage/rings/padics/padic_valuation.py +++ b/src/sage/rings/padics/padic_valuation.py @@ -738,6 +738,7 @@ def extensions(self, ring): TESTS:: sage: R. = QQ[] + sage: x = polygen(ZZ, 'x') sage: L. = QQ.extension(x^3 - 2) sage: R. = L[] sage: M. = L.extension(b^2 + 2*b + a) @@ -1384,6 +1385,7 @@ def _to_base_domain(self, f): Check that this also works for relative extensions:: sage: v = QQ.valuation(2) + sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^2 + 2) sage: M. = L.extension(x^2 + 1) sage: w = v.extension(L).extension(M) diff --git a/src/sage/rings/padics/unramified_extension_generic.py b/src/sage/rings/padics/unramified_extension_generic.py index 7973ed814c3..9689d92ea5e 100644 --- a/src/sage/rings/padics/unramified_extension_generic.py +++ b/src/sage/rings/padics/unramified_extension_generic.py @@ -67,6 +67,7 @@ def _extension_type(self): sage: K._extension_type() 'Unramified' + sage: x = polygen(ZZ, 'x') sage: L. = Qp(5).extension(x^2 - 5) sage: L._extension_type() 'Eisenstein' @@ -84,6 +85,7 @@ def absolute_f(self): sage: K.absolute_f() 5 + sage: x = polygen(ZZ, 'x') sage: L. = Qp(3).extension(x^2 - 3) sage: L.absolute_f() 1 diff --git a/src/sage/rings/polynomial/flatten.py b/src/sage/rings/polynomial/flatten.py index 4ffe29f9ebe..7e50d07d0e2 100644 --- a/src/sage/rings/polynomial/flatten.py +++ b/src/sage/rings/polynomial/flatten.py @@ -108,8 +108,9 @@ def __init__(self, domain): :: - sage: K. = NumberField(x^3 - 2) - sage: R = K['x','y']['a','b'] + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: R = K['x','y']['a','b'] # optional - sage.rings.number_field sage: from sage.rings.polynomial.flatten import FlatteningMorphism sage: f = FlatteningMorphism(R) sage: f(R('v*a*x^2 + b^2 + 1/v*y')) diff --git a/src/sage/rings/polynomial/multi_polynomial_element.py b/src/sage/rings/polynomial/multi_polynomial_element.py index 08cc3dee4d0..fb87a8a7cad 100644 --- a/src/sage/rings/polynomial/multi_polynomial_element.py +++ b/src/sage/rings/polynomial/multi_polynomial_element.py @@ -92,10 +92,11 @@ def __init__(self, parent, x): """ EXAMPLES:: - sage: K. = NumberField(x^3 - 2) - sage: L. = K.extension(x^3 - 3) - sage: S. = L.extension(x^2 - 2) - sage: S + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: L. = K.extension(x^3 - 3) # optional - sage.rings.number_field + sage: S. = L.extension(x^2 - 2) # optional - sage.rings.number_field + sage: S # optional - sage.rings.number_field Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field sage: P. = PolynomialRing(S) # indirect doctest """ @@ -791,11 +792,10 @@ def monomial_coefficient(self, mon): :: - sage: var('a') - a - sage: K. = NumberField(a^2+a+1) - sage: P. = K[] - sage: f=(a*x-1)*((a+1)*y-1); f + sage: a = polygen(ZZ, 'a') + sage: K. = NumberField(a^2 + a + 1) # optional - sage.rings.number_field + sage: P. = K[] # optional - sage.rings.number_field + sage: f = (a*x - 1) * ((a+1)*y - 1); f # optional - sage.rings.number_field -x*y + (-a)*x + (-a - 1)*y + 1 sage: f.monomial_coefficient(x) -a diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index 64f01724081..4e96a6602cc 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -119,10 +119,10 @@ TESTS:: Check if :trac:`6160` is fixed:: - sage: x=var('x') - sage: K. = NumberField(x-1728) - sage: R. = K[] - sage: b-j*c + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x - 1728) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: b - j*c # optional - sage.rings.number_field b - 1728*c .. TODO:: @@ -591,10 +591,10 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): Check if :trac:`6160` is fixed:: - sage: x=var('x') - sage: K. = NumberField(x-1728) - sage: R. = K[] - sage: R.coerce(1) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x - 1728) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: R.coerce(1) # optional - sage.rings.number_field 1 Check if coercion from zero variable polynomial rings work @@ -1267,9 +1267,9 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): sage: P._singular_init_().name() == P._singular_init_().name() False - sage: w = var('w') - sage: R. = PolynomialRing(NumberField(w^2+1,'s')) - sage: singular(R) + sage: w = polygen(ZZ, 'w') + sage: R. = PolynomialRing(NumberField(w^2 + 1,'s')) # optional - sage.rings.number_field + sage: singular(R) # optional - sage.rings.number_field polynomial ring, over a field, global ordering // coefficients: QQ[s]/(s^2+1) // number of vars : 2 @@ -3661,7 +3661,7 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base): Check if :trac:`7152` is fixed:: - sage: x=var('x') + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x**2 + 1) sage: R. = QQ[] sage: p = rho*x @@ -4189,10 +4189,10 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base): Next we factor a polynomial over a number field.:: - sage: p = var('p') - sage: K. = NumberField(p^3-2) - sage: KXY. = K[] - sage: factor(x^3 - 2*y^3) + sage: p = polygen(ZZ, 'p') + sage: K. = NumberField(p^3 - 2) # optional - sage.rings.number_field + sage: KXY. = K[] # optional - sage.rings.number_field + sage: factor(x^3 - 2*y^3) # optional - sage.rings.number_field (x + (-s)*y) * (x^2 + s*x*y + (s^2)*y^2) sage: k = (x^3-2*y^3)^5*(x+s*y)^2*(2/3 + s^2) sage: k.factor() @@ -4201,11 +4201,11 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base): This shows that issue :trac:`2780` is fixed, i.e. that the unit part of the factorization is set correctly:: - sage: x = var('x') - sage: K. = NumberField(x^2 + 1) - sage: R. = PolynomialRing(K) - sage: f = 2*y^2 + 2*z^2 - sage: F = f.factor(); F.unit() + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field + sage: f = 2*y^2 + 2*z^2 # optional - sage.rings.number_field + sage: F = f.factor(); F.unit() # optional - sage.rings.number_field 2 Another example:: @@ -4848,11 +4848,11 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base): sage: f.lcm(x^4) (a^2 + a)*x^6*y + (a^4 + a^3 + a)*x^4*y + (a^5)*x^4 - sage: w = var('w') - sage: r. = PolynomialRing(NumberField(w^4 + 1, 'a'), 2) - sage: a = r.base_ring().0 - sage: f = (a^2+a)*x^2*y + (a^4+a^3+a)*y + a^5 - sage: f.lcm(x^4) + sage: w = polygen(ZZ, 'w') + sage: r. = PolynomialRing(NumberField(w^4 + 1, 'a'), 2) # optional - sage.rings.number_field + sage: a = r.base_ring().0 # optional - sage.rings.number_field + sage: f = (a^2+a)*x^2*y + (a^4+a^3+a)*y + a^5 # optional - sage.rings.number_field + sage: f.lcm(x^4) # optional - sage.rings.number_field (a^2 + a)*x^6*y + (a^3 + a - 1)*x^4*y + (-a)*x^4 TESTS:: diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index 9000c358b26..7fea4f5bd82 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -346,8 +346,8 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: x = polygen(GF(389)) - sage: plot(x^2 + 1, rgbcolor=(0,0,1)) + sage: x = polygen(GF(389)) # optional - sage.rings.finite_rings + sage: plot(x^2 + 1, rgbcolor=(0,0,1)) # optional - sage.rings.finite_rings sage.plot Graphics object consisting of 1 graphics primitive sage: x = polygen(QQ) sage: plot(x^2 + 1, rgbcolor=(1,0,0)) @@ -1678,11 +1678,11 @@ cdef class Polynomial(CommutativePolynomial): Even noncommutative ones:: - sage: M = MatrixSpace(ZZ,2) - sage: x = polygen(M) - sage: p = M([1,2,3,4])*x^3 + M([-1,0,0,1])*x^2 + M([1,3,-1,0])*x + M.one() - sage: q = p.inverse_series_trunc(5) - sage: (p*q).truncate(5) == M.one() + sage: M = MatrixSpace(ZZ, 2) # optional - sage.modules + sage: x = polygen(M) # optional - sage.modules + sage: p = M([1,2,3,4])*x^3 + M([-1,0,0,1])*x^2 + M([1,3,-1,0])*x + M.one() # optional - sage.modules + sage: q = p.inverse_series_trunc(5) # optional - sage.modules + sage: (p*q).truncate(5) == M.one() # optional - sage.modules True sage: q = p.inverse_series_trunc(13) sage: (p*q).truncate(13) == M.one() @@ -1914,8 +1914,8 @@ cdef class Polynomial(CommutativePolynomial): sage: p = 37 * (x-2/3)^2 sage: p.squarefree_decomposition() (37) * (x - 2/3)^2 - sage: x = polygen(GF(3)) - sage: x.squarefree_decomposition() + sage: x = polygen(GF(3)) # optional - sage.rings.finite_rings + sage: x.squarefree_decomposition() # optional - sage.rings.finite_rings x sage: f = QQbar['x'](1) sage: f.squarefree_decomposition() @@ -2059,34 +2059,43 @@ cdef class Polynomial(CommutativePolynomial): Check that our Cantor-Zassenhaus implementation does not loop over finite fields of even characteristic (see :trac:`16162`):: - sage: K. = GF(2**8) - sage: x = polygen(K) - sage: r = (x**2+x+1).any_root() # used to loop - sage: r**2 + r + sage: K. = GF(2**8) # optional - sage.rings.finite_rings + sage: x = polygen(K) # optional - sage.rings.finite_rings + sage: r = (x**2+x+1).any_root() # used to loop # optional - sage.rings.finite_rings + sage: r**2 + r # optional - sage.rings.finite_rings 1 sage: (x**2+a+1).any_root() a^7 + a^2 Also check that such computations can be interrupted:: - sage: K. = GF(2^8) - sage: x = polygen(K) - sage: pol = x^1000000 + x + a - sage: alarm(0.5); pol.any_root() + sage: K. = GF(2^8) # optional - sage.rings.finite_rings + sage: x = polygen(K) # optional - sage.rings.finite_rings + sage: pol = x^1000000 + x + a # optional - sage.rings.finite_rings + sage: alarm(0.5); pol.any_root() # optional - sage.rings.finite_rings Traceback (most recent call last): ... AlarmInterrupt Check root computation over large finite fields:: - sage: K. = GF(2**50) - sage: x = polygen(K) - sage: (x**10+x+a).any_root() - a^49 + a^47 + a^44 + a^42 + a^41 + a^39 + a^38 + a^37 + a^36 + a^34 + a^33 + a^29 + a^27 + a^26 + a^25 + a^23 + a^18 + a^13 + a^7 + a^5 + a^4 + a^3 + a^2 + a - sage: K. = GF(2**150) - sage: x = polygen(K) - sage: (x**10+x+a).any_root() - a^149 + a^148 + a^146 + a^144 + a^143 + a^140 + a^138 + a^136 + a^134 + a^132 + a^131 + a^130 + a^129 + a^127 + a^123 + a^120 + a^118 + a^114 + a^113 + a^112 + a^111 + a^108 + a^104 + a^103 + a^102 + a^99 + a^98 + a^94 + a^91 + a^90 + a^88 + a^79 + a^78 + a^75 + a^73 + a^72 + a^67 + a^65 + a^64 + a^63 + a^62 + a^61 + a^59 + a^57 + a^52 + a^50 + a^48 + a^47 + a^46 + a^45 + a^43 + a^41 + a^39 + a^37 + a^34 + a^31 + a^29 + a^27 + a^25 + a^23 + a^22 + a^20 + a^18 + a^16 + a^14 + a^11 + a^10 + a^8 + a^6 + a^5 + a^4 + a + 1 + sage: K. = GF(2**50) # optional - sage.rings.finite_rings + sage: x = polygen(K) # optional - sage.rings.finite_rings + sage: (x**10+x+a).any_root() # optional - sage.rings.finite_rings + a^49 + a^47 + a^44 + a^42 + a^41 + a^39 + a^38 + a^37 + a^36 + + a^34 + a^33 + a^29 + a^27 + a^26 + a^25 + a^23 + a^18 + + a^13 + a^7 + a^5 + a^4 + a^3 + a^2 + a + sage: K. = GF(2**150) # optional - sage.rings.finite_rings + sage: x = polygen(K) # optional - sage.rings.finite_rings + sage: (x**10+x+a).any_root() # optional - sage.rings.finite_rings + a^149 + a^148 + a^146 + a^144 + a^143 + a^140 + a^138 + a^136 + a^134 + + a^132 + a^131 + a^130 + a^129 + a^127 + a^123 + a^120 + a^118 + a^114 + + a^113 + a^112 + a^111 + a^108 + a^104 + a^103 + a^102 + a^99 + a^98 + + a^94 + a^91 + a^90 + a^88 + a^79 + a^78 + a^75 + a^73 + a^72 + a^67 + + a^65 + a^64 + a^63 + a^62 + a^61 + a^59 + a^57 + a^52 + a^50 + a^48 + + a^47 + a^46 + a^45 + a^43 + a^41 + a^39 + a^37 + a^34 + a^31 + a^29 + + a^27 + a^25 + a^23 + a^22 + a^20 + a^18 + a^16 + a^14 + a^11 + a^10 + + a^8 + a^6 + a^5 + a^4 + a + 1 Check that :trac:`21998` has been resolved:: @@ -2795,11 +2804,11 @@ cdef class Polynomial(CommutativePolynomial): R1. = ZZ[] R2. = R1[] y^2 + (2*x + 2)*y + (x^2 + 2*x + 1) - sage: sage_input(RR(pi) * polygen(RR), verify=True) + sage: sage_input(RR(pi) * polygen(RR), verify=True) # optional - sage.symbolic # Verified R. = RR[] 3.1415926535897931*x - sage: sage_input(polygen(GF(7)) + 12, verify=True) + sage: sage_input(polygen(GF(7)) + 12, verify=True) # optional - sage.rings.finite_rings # Verified R. = GF(7)[] x + 5 @@ -4123,9 +4132,9 @@ cdef class Polynomial(CommutativePolynomial): Over a number field:: - sage: K. = CyclotomicField(15) - sage: x = polygen(K) - sage: ((x^3 + z*x + 1)^3*(x - z)).factor() + sage: K. = CyclotomicField(15) # optional - sage.rings.number_field + sage: x = polygen(K) # optional - sage.rings.number_field + sage: ((x^3 + z*x + 1)^3 * (x - z)).factor() # optional - sage.rings.number_field (x - z) * (x^3 + z*x + 1)^3 sage: cyclotomic_polynomial(12).change_ring(K).factor() (x^2 - z^5 - 1) * (x^2 + z^5) @@ -4135,10 +4144,10 @@ cdef class Polynomial(CommutativePolynomial): Over a relative number field:: sage: x = polygen(QQ) - sage: K. = CyclotomicField(3) - sage: L. = K.extension(x^3 - 2) - sage: t = polygen(L, 't') - sage: f = (t^3 + t + a)*(t^5 + t + z); f + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: L. = K.extension(x^3 - 2) # optional - sage.rings.number_field + sage: t = polygen(L, 't') # optional - sage.rings.number_field + sage: f = (t^3 + t + a) * (t^5 + t + z); f # optional - sage.rings.number_field t^8 + t^6 + a*t^5 + t^4 + z*t^3 + t^2 + (a + z)*t + z*a sage: f.factor() (t^3 + t + a) * (t^5 + t + z) @@ -4353,10 +4362,10 @@ cdef class Polynomial(CommutativePolynomial): A test where nffactor used to fail without a nf structure:: sage: x = polygen(QQ) - sage: K = NumberField([x^2-1099511627777, x^3-3],'a') - sage: x = polygen(K) - sage: f = x^3 - 3 - sage: factor(f) + sage: K = NumberField([x^2 - 1099511627777, x^3 - 3], 'a') # optional - sage.rings.number_field + sage: x = polygen(K) # optional - sage.rings.number_field + sage: f = x^3 - 3 # optional - sage.rings.number_field + sage: factor(f) # optional - sage.rings.number_field (x - a1) * (x^2 + a1*x + a1^2) We check that :trac:`7554` is fixed:: @@ -5028,7 +5037,7 @@ cdef class Polynomial(CommutativePolynomial): sage: f = x^2-x+2 sage: f.is_primitive() True - sage: x=polygen(QQ); f=x^2+1 + sage: x = polygen(QQ); f = x^2 + 1 sage: f.is_primitive() Traceback (most recent call last): ... @@ -5091,8 +5100,8 @@ cdef class Polynomial(CommutativePolynomial): sage: f = x^2-x+2 sage: f.is_primitive(24, [2,3]) True - sage: x=polygen(Integers(103)); f=x^2+1 - sage: f.is_primitive() + sage: x = polygen(Integers(103)); f = x^2 + 1 + sage: f.is_primitive() # optional - sage.rings.finite_rings False """ R = self.base_ring() @@ -6145,11 +6154,11 @@ cdef class Polynomial(CommutativePolynomial): sage: f = - 1/2*x^2 + x^9 + 7*x + 5/11 sage: f.monomials() [x^9, x^2, x, 1] - sage: x = var('x') - sage: K. = NumberField(x**2 + 1) - sage: R. = QQ[] - sage: p = rho*y - sage: p.monomials() + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x**2 + 1) # optional - sage.rings.number_field + sage: R. = QQ[] # optional - sage.rings.number_field + sage: p = rho * y # optional - sage.rings.number_field + sage: p.monomials() # optional - sage.rings.number_field [y] """ if self.is_zero(): @@ -6905,22 +6914,21 @@ cdef class Polynomial(CommutativePolynomial): This function works over any field. However for base rings other than `\ZZ` and `\QQ` only the resultant algorithm is available:: - sage: x = polygen(QQbar) - sage: p1 = x**2 - AA(2).sqrt() - sage: p2 = x**3 - AA(3).sqrt() - sage: r1 = p1.roots(multiplicities=False) - sage: r2 = p2.roots(multiplicities=False) - sage: p = p1.composed_op(p2, operator.add) - sage: p - x^6 - 4.242640687119285?*x^4 - 3.464101615137755?*x^3 + 6*x^2 - 14.69693845669907?*x + 0.1715728752538099? - sage: all(p(x+y).is_zero() for x in r1 for y in r2) - True - - sage: x = polygen(GF(2)) - sage: p1 = x**2 + x - 1 - sage: p2 = x**3 + x - 1 - sage: p_add = p1.composed_op(p2, operator.add) - sage: p_add + sage: x = polygen(QQbar) # optional - sage.rings.number_field + sage: p1 = x**2 - AA(2).sqrt() # optional - sage.rings.number_field + sage: p2 = x**3 - AA(3).sqrt() # optional - sage.rings.number_field + sage: r1 = p1.roots(multiplicities=False) # optional - sage.rings.number_field + sage: r2 = p2.roots(multiplicities=False) # optional - sage.rings.number_field + sage: p = p1.composed_op(p2, operator.add); p # optional - sage.rings.number_field + x^6 - 4.242640687119285?*x^4 - 3.464101615137755?*x^3 + 6*x^2 + - 14.69693845669907?*x + 0.1715728752538099? + sage: all(p(x+y).is_zero() for x in r1 for y in r2) # optional - sage.rings.number_field + True + + sage: x = polygen(GF(2)) # optional - sage.rings.finite_rings + sage: p1 = x**2 + x - 1 # optional - sage.rings.finite_rings + sage: p2 = x**3 + x - 1 # optional - sage.rings.finite_rings + sage: p_add = p1.composed_op(p2, operator.add); p_add # optional - sage.rings.finite_rings x^6 + x^5 + x^3 + x^2 + 1 sage: p_mul = p1.composed_op(p2, operator.mul) sage: p_mul @@ -7803,14 +7811,21 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: K. = QuadraticField(-1) - sage: y = polygen(K) - sage: p = y^4 - 2 - im - sage: p.roots(ring=CC) - [(-1.2146389322441... - 0.14142505258239...*I, 1), (-0.14142505258239... + 1.2146389322441...*I, 1), (0.14142505258239... - 1.2146389322441...*I, 1), (1.2146389322441... + 0.14142505258239...*I, 1)] - sage: p = p^2 * (y^2 - 2) - sage: p.roots(ring=CIF) - [(-1.414213562373095?, 1), (1.414213562373095?, 1), (-1.214638932244183? - 0.141425052582394?*I, 2), (-0.141425052582394? + 1.214638932244183?*I, 2), (0.141425052582394? - 1.214638932244183?*I, 2), (1.214638932244183? + 0.141425052582394?*I, 2)] + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: y = polygen(K) # optional - sage.rings.number_field + sage: p = y^4 - 2 - im # optional - sage.rings.number_field + sage: p.roots(ring=CC) # optional - sage.rings.number_field + [(-1.2146389322441... - 0.14142505258239...*I, 1), + (-0.14142505258239... + 1.2146389322441...*I, 1), + (0.14142505258239... - 1.2146389322441...*I, 1), + (1.2146389322441... + 0.14142505258239...*I, 1)] + sage: p = p^2 * (y^2 - 2) # optional - sage.rings.number_field + sage: p.roots(ring=CIF) # optional - sage.rings.number_field + [(-1.414213562373095?, 1), (1.414213562373095?, 1), + (-1.214638932244183? - 0.141425052582394?*I, 2), + (-0.141425052582394? + 1.214638932244183?*I, 2), + (0.141425052582394? - 1.214638932244183?*I, 2), + (1.214638932244183? + 0.141425052582394?*I, 2)] Note that one should not use NumPy when wanting high precision output as it does not support any of the high precision types:: @@ -7863,12 +7878,12 @@ cdef class Polynomial(CommutativePolynomial): Note that we can find the roots of a polynomial with algebraic coefficients:: - sage: rt2 = sqrt(AA(2)) - sage: rt3 = sqrt(AA(3)) - sage: x = polygen(AA) - sage: f = (x - rt2) * (x - rt3); f - x^2 - 3.146264369941973?*x + 2.449489742783178? - sage: rts = f.roots(); rts + sage: rt2 = sqrt(AA(2)) # optional - sage.rings.number_field + sage: rt3 = sqrt(AA(3)) # optional - sage.rings.number_field + sage: x = polygen(AA) # optional - sage.rings.number_field + sage: f = (x - rt2) * (x - rt3); f # optional - sage.rings.number_field + x^2 - 3.146264369941973?*x + 2.449489742783178? + sage: rts = f.roots(); rts # optional - sage.rings.number_field [(1.414213562373095?, 1), (1.732050807568878?, 1)] sage: rts[0][0] == rt2 True @@ -10014,8 +10029,8 @@ cdef class Polynomial(CommutativePolynomial): Test using other rings:: - sage: z = polygen(GF(5)) - sage: (z - 1).is_cyclotomic() + sage: z = polygen(GF(5)) # optional - sage.rings.finite_rings + sage: (z - 1).is_cyclotomic() # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError: not implemented in non-zero characteristic diff --git a/src/sage/rings/polynomial/polynomial_number_field.pyx b/src/sage/rings/polynomial/polynomial_number_field.pyx index 82c3d467bea..4f9e814d3fb 100644 --- a/src/sage/rings/polynomial/polynomial_number_field.pyx +++ b/src/sage/rings/polynomial/polynomial_number_field.pyx @@ -10,7 +10,8 @@ EXAMPLES: Define a polynomial over an absolute number field and perform basic operations with them:: - sage: N. = NumberField(x^2-2) + sage: x = polygen(ZZ, 'x') + sage: N. = NumberField(x^2 - 2) sage: K. = N[] sage: f = x - a sage: g = x^3 - 2*a + 1 @@ -29,15 +30,15 @@ operations with them:: Polynomials are aware of embeddings of the underlying field:: - sage: x = var('x') - sage: Q7 = Qp(7) - sage: r1 = Q7(3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 +\ - 6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + 7^17 +\ - 4*7^18 + 6*7^19) - sage: N. = NumberField(x^2-2, embedding = r1) - sage: K. = N[] - sage: f = t^3-2*t+1 - sage: f(r1) + sage: x = polygen(ZZ, 'x') + sage: Q7 = Qp(7) # optional - sage.rings.padics + sage: r1 = Q7(3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 # optional - sage.rings.padics + ....: + 6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + 7^17 + ....: + 4*7^18 + 6*7^19) + sage: N. = NumberField(x^2 - 2, embedding=r1) # optional - sage.rings.padics + sage: K. = N[] # optional - sage.rings.padics + sage: f = t^3 - 2*t + 1 # optional - sage.rings.padics + sage: f(r1) # optional - sage.rings.padics 1 + O(7^20) We can also construct polynomials over relative number fields:: @@ -128,7 +129,8 @@ class Polynomial_absolute_number_field_dense(Polynomial_generic_dense_field): EXAMPLES:: - sage: N. = NumberField(x^3-1/2, 'a') + sage: x = polygen(ZZ, 'x') + sage: N. = NumberField(x^3 - 1/2, 'a') sage: R. = N['r'] sage: f = (5/4*a^2 - 2*a + 4)*r^2 + (5*a^2 - 81/5*a - 17/2)*r + 4/5*a^2 + 24*a + 6 sage: g = (5/4*a^2 - 2*a + 4)*r^2 + (-11*a^2 + 79/5*a - 7/2)*r - 4/5*a^2 - 24*a - 6 @@ -149,8 +151,8 @@ class Polynomial_absolute_number_field_dense(Polynomial_generic_dense_field): Test for degree one extensions:: - sage: x = var('x') - sage: N = NumberField(x-3, 'a') + sage: x = polygen(ZZ, 'x') + sage: N = NumberField(x - 3, 'a') sage: a = N.gen() sage: R = N['x'] sage: f = R._random_nonzero_element() @@ -167,7 +169,7 @@ class Polynomial_absolute_number_field_dense(Polynomial_generic_dense_field): Test for coercion with other rings and force weird variables to test PARI behavior:: - sage: r = var('r') + sage: r = polygen(ZZ, 'r') sage: N = NumberField(r^2 - 2, 'r') sage: a = N.gen() sage: R = N['r'] @@ -236,7 +238,8 @@ class Polynomial_relative_number_field_dense(Polynomial_generic_dense_field): EXAMPLES:: - sage: f = NumberField([x^2-2, x^2-3], 'a')['x'].random_element() + sage: x = polygen(ZZ, 'x') + sage: f = NumberField([x^2 - 2, x^2 - 3], 'a')['x'].random_element() sage: from sage.rings.polynomial.polynomial_number_field import Polynomial_relative_number_field_dense sage: isinstance(f, Polynomial_relative_number_field_dense) True @@ -265,20 +268,20 @@ class Polynomial_relative_number_field_dense(Polynomial_generic_dense_field): EXAMPLES:: - sage: N = QQ[sqrt(2), sqrt(3)] - sage: s2, s3 = N.gens() - sage: x = polygen(N) - sage: f = x^4 - 5*x^2 +6 - sage: g = x^3 + (-2*s2 + s3)*x^2 + (-2*s3*s2 + 2)*x + 2*s3 - sage: gcd(f, g) + sage: N = QQ[sqrt(2), sqrt(3)] # optional - sage.symbolic + sage: s2, s3 = N.gens() # optional - sage.symbolic + sage: x = polygen(N) # optional - sage.symbolic + sage: f = x^4 - 5*x^2 + 6 # optional - sage.symbolic + sage: g = x^3 + (-2*s2 + s3)*x^2 + (-2*s3*s2 + 2)*x + 2*s3 # optional - sage.symbolic + sage: gcd(f, g) # optional - sage.symbolic x^2 + (-sqrt2 + sqrt3)*x - sqrt3*sqrt2 sage: f.gcd(g) x^2 + (-sqrt2 + sqrt3)*x - sqrt3*sqrt2 TESTS:: - sage: x = var('x') - sage: R = NumberField([x^2-2, x^2-3], 'a')['x'] + sage: x = polygen(ZZ, 'x') + sage: R = NumberField([x^2 - 2, x^2 - 3], 'a')['x'] sage: f = R._random_nonzero_element() sage: g1 = R.random_element() sage: g2 = R.random_element()*g1+1 diff --git a/src/sage/rings/polynomial/polynomial_quotient_ring.py b/src/sage/rings/polynomial/polynomial_quotient_ring.py index 0c9be09df64..c3faa0849ed 100644 --- a/src/sage/rings/polynomial/polynomial_quotient_ring.py +++ b/src/sage/rings/polynomial/polynomial_quotient_ring.py @@ -1095,10 +1095,11 @@ def is_integral_domain(self, proof = True): domain, even though the base ring is integral and the modulus is irreducible:: - sage: B = ZZ.extension(x^2 - 5, 'a') - sage: R. = PolynomialRing(B) - sage: S = R.quotient(y^2 - y - 1) - sage: S.is_integral_domain() + sage: x = polygen(ZZ, 'x') + sage: B = ZZ.extension(x^2 - 5, 'a') # optional - sage.rings.number_field + sage: R. = PolynomialRing(B) # optional - sage.rings.number_field + sage: S = R.quotient(y^2 - y - 1) # optional - sage.libs.pari sage.rings.number_field + sage: S.is_integral_domain() # optional - sage.libs.pari sage.rings.number_field Traceback (most recent call last): ... NotImplementedError @@ -1150,8 +1151,9 @@ def krull_dimension(self): EXAMPLES:: - sage: R = PolynomialRing(ZZ,'x').quotient(x**6-1) - sage: R.krull_dimension() + sage: x = polygen(ZZ, 'x') + sage: R = PolynomialRing(ZZ, 'x').quotient(x**6 - 1) # optional - sage.libs.pari + sage: R.krull_dimension() # optional - sage.libs.pari 1 sage: R = PolynomialRing(ZZ,'x').quotient(1) sage: R.krull_dimension() @@ -1527,11 +1529,13 @@ def class_group(self, proof=True): EXAMPLES:: - sage: K. = QuadraticField(-3) - sage: K.class_group() - Class group of order 1 of Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I - sage: K. = QQ['x'].quotient(x^2 + 3) - sage: K.class_group() + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: K.class_group() # optional - sage.rings.number_field + Class group of order 1 of Number Field in a + with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + sage: x = polygen(QQ, 'x') + sage: K. = QQ['x'].quotient(x^2 + 3) # optional - sage.libs.pari sage.rings.number_field + sage: K.class_group() # optional - sage.libs.pari sage.rings.number_field [] A trivial algebra over `\QQ(\sqrt{-5})` has the same class group as its @@ -1545,8 +1549,9 @@ def class_group(self, proof=True): The same algebra constructed in a different way:: - sage: K. = QQ['x'].quotient(x^2 + 5) - sage: K.class_group(()) + sage: x = polygen(ZZ, 'x') + sage: K. = QQ['x'].quotient(x^2 + 5) # optional - sage.libs.pari + sage: K.class_group(()) # optional - sage.libs.pari [((2, a + 1), 2)] Here is an example where the base and the extension both contribute to @@ -1622,11 +1627,13 @@ def S_units(self, S, proof=True): EXAMPLES:: - sage: K. = QuadraticField(-3) - sage: K.unit_group() - Unit group with structure C6 of Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I - sage: K. = QQ['x'].quotient(x^2 + 3) - sage: u,o = K.S_units([])[0]; o + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: K.unit_group() # optional - sage.rings.number_field + Unit group with structure C6 of Number Field in a + with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + sage: x = polygen(ZZ, 'x') + sage: K. = QQ['x'].quotient(x^2 + 3) # optional - sage.libs.pari + sage: u, o = K.S_units([])[0]; o # optional - sage.libs.pari 6 sage: 2*u - 1 in {a, -a} True @@ -1639,11 +1646,13 @@ def S_units(self, S, proof=True): :: - sage: K. = QuadraticField(-3) - sage: y = polygen(K) - sage: L. = K['y'].quotient(y^3 + 5); L - Univariate Quotient Polynomial Ring in b over Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I with modulus y^3 + 5 - sage: [u for u, o in L.S_units([]) if o is Infinity] + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: y = polygen(K) # optional - sage.rings.number_field + sage: L. = K['y'].quotient(y^3 + 5); L # optional - sage.rings.number_field + Univariate Quotient Polynomial Ring in b over Number Field in a + with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + with modulus y^3 + 5 + sage: [u for u, o in L.S_units([]) if o is Infinity] # optional - sage.rings.number_field [(-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, 2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2] sage: [u for u, o in L.S_units([K.ideal(1/2*a - 3/2)]) if o is Infinity] @@ -1708,12 +1717,14 @@ def units(self, proof=True): EXAMPLES:: - sage: K. = QuadraticField(-3) - sage: K.unit_group() - Unit group with structure C6 of Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I - sage: K. = QQ['x'].quotient(x^2 + 3) - sage: u = K.units()[0][0] - sage: 2*u - 1 in {a, -a} + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: K.unit_group() # optional - sage.rings.number_field + Unit group with structure C6 of + Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + sage: x = polygen(ZZ, 'x') + sage: K. = QQ['x'].quotient(x^2 + 3) # optional - sage.libs.pari + sage: u = K.units()[0][0] # optional - sage.libs.pari + sage: 2*u - 1 in {a, -a} # optional - sage.libs.pari True sage: u^6 1 @@ -1721,17 +1732,20 @@ def units(self, proof=True): -1 sage: 2*u^2 + 1 in {a, -a} True - sage: K. = QQ['x'].quotient(x^2 + 5) - sage: K.units(()) + sage: x = polygen(ZZ, 'x') + sage: K. = QQ['x'].quotient(x^2 + 5) # optional - sage.libs.pari + sage: K.units(()) # optional - sage.libs.pari [(-1, 2)] :: - sage: K. = QuadraticField(-3) - sage: y = polygen(K) - sage: L. = K['y'].quotient(y^3 + 5); L - Univariate Quotient Polynomial Ring in b over Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I with modulus y^3 + 5 - sage: [u for u, o in L.units() if o is Infinity] + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: y = polygen(K) # optional - sage.rings.number_field + sage: L. = K['y'].quotient(y^3 + 5); L # optional - sage.rings.number_field + Univariate Quotient Polynomial Ring in b over Number Field in a + with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + with modulus y^3 + 5 + sage: [u for u, o in L.units() if o is Infinity] # optional - sage.rings.number_field [(-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, 2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2] sage: L. = K.extension(y^3 + 5) diff --git a/src/sage/rings/polynomial/polynomial_singular_interface.py b/src/sage/rings/polynomial/polynomial_singular_interface.py index 254d908a592..9d89421efa6 100644 --- a/src/sage/rings/polynomial/polynomial_singular_interface.py +++ b/src/sage/rings/polynomial/polynomial_singular_interface.py @@ -212,10 +212,9 @@ def _singular_(self, singular=singular): // : names x y // block 2 : ordering C - sage: w = var('w') - - sage: R. = PolynomialRing(NumberField(w^2+1,'s')) - sage: singular(R) + sage: w = polygen(ZZ, 'w') + sage: R. = PolynomialRing(NumberField(w^2 + 1, 's')) # optional - sage.rings.number_field + sage: singular(R) # optional - sage.rings.number_field polynomial ring, over a field, global ordering // coefficients: QQ[s]/(s^2+1) // number of vars : 1 @@ -399,8 +398,9 @@ def can_convert_to_singular(R): Avoid non absolute number fields (see :trac:`23535`):: - sage: K. = NumberField([x^2-2,x^2-5]) - sage: can_convert_to_singular(K['s,t']) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField([x^2 - 2, x^2 - 5]) # optional - sage.rings.number_field + sage: can_convert_to_singular(K['s,t']) # optional - sage.rings.number_field False Check for :trac:`33319`:: diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index 8339127693b..e336309d5d7 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -665,8 +665,8 @@ def common_polynomial(self, poly): sage: phi * tau == -1 True - sage: x = polygen(SR) - sage: p = (x - sqrt(-5)) * (x - sqrt(3)); p + sage: x = polygen(SR) # optional - sage.symbolic + sage: p = (x - sqrt(-5)) * (x - sqrt(3)); p # optional - sage.symbolic x^2 + (-sqrt(3) - sqrt(-5))*x + sqrt(3)*sqrt(-5) sage: p = QQbar.common_polynomial(p) sage: a = QQbar.polynomial_root(p, CIF(RIF(-0.1, 0.1), RIF(2, 3))); a @@ -1180,6 +1180,7 @@ def _coerce_map_from_(self, from_par): sage: AA.has_coerce_map_from(SR) False + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x^3 - 2, 'a', embedding=2.**(1/3)) sage: AA.has_coerce_map_from(K) True @@ -4701,6 +4702,7 @@ def radical_expression(self): sqrt(sqrt(5) + 5) sage: QQbar.zeta(5).radical_expression() 1/4*sqrt(5) + 1/2*sqrt(-1/2*sqrt(5) - 5/2) - 1/4 + sage: x = polygen(ZZ, 'x') sage: a = QQ[x](x^7 - x - 1).roots(AA, False)[0] sage: a.radical_expression() 1.112775684278706? @@ -5410,7 +5412,8 @@ def _more_precision(self): real which is not the case without calling _ensure_real (see :trac:`11728`):: - sage: P = AA['x'](1+x^4); a1,a2 = P.factor()[0][0],P.factor()[1][0]; a1*a2 + sage: x = polygen(ZZ, 'x') + sage: P = AA['x'](1 + x^4); a1,a2 = P.factor()[0][0], P.factor()[1][0]; a1*a2 x^4 + 1.000000000000000? sage: a1,a2 (x^2 - 1.414213562373095?*x + 1, x^2 + 1.414213562373095?*x + 1) @@ -7078,6 +7081,7 @@ def conjugate(self, n): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: a = (x^2 + 23).roots(ring=QQbar, multiplicities=False)[0] sage: b = a._descr sage: type(b) @@ -7796,6 +7800,7 @@ def generator(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: v = (x^2 - x - 1).roots(ring=AA, multiplicities=False)[1]._descr.exactify() sage: v.generator() Number Field in a with defining polynomial y^2 - y - 1 with a in 1.618033988749895? @@ -7810,6 +7815,7 @@ def exactify(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: v = (x^2 - x - 1).roots(ring=AA, multiplicities=False)[1]._descr.exactify() sage: type(v) @@ -7824,6 +7830,7 @@ def field_element_value(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: v = (x^2 - x - 1).roots(ring=AA, multiplicities=False)[1]._descr.exactify() sage: v.field_element_value() a @@ -7836,6 +7843,7 @@ def minpoly(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: v = (x^2 - x - 1).roots(ring=AA, multiplicities=False)[1]._descr.exactify() sage: type(v) diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index 0e9d1f35f47..243ced61327 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -1422,8 +1422,9 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: K = NumberField(x^2 - 2, 'beta') - sage: (1/7).is_norm(K) + sage: x = polygen(QQ, 'x') + sage: K = NumberField(x^2 - 2, 'beta') # optional - sage.rings.number_field + sage: (1/7).is_norm(K) # optional - sage.rings.number_field True sage: (1/10).is_norm(K) False @@ -1542,7 +1543,8 @@ cdef class Rational(sage.structure.element.FieldElement): sage: QQ(2)._bnfisnorm(QuadraticField(-1, 'i')) (i + 1, 1) - sage: 7._bnfisnorm(NumberField(x^3-2, 'b')) + sage: x = polygen(QQ, 'x') + sage: 7._bnfisnorm(NumberField(x^3 - 2, 'b')) # optional - sage.rings.number_field (1, 7) AUTHORS: diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index ca704238181..f22e4f1dc81 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -1056,7 +1056,8 @@ def extension(self, poly, names, **kwds): We make a single absolute extension:: - sage: K. = QQ.extension(x^3 + 5); K + sage: x = polygen(QQ, 'x') + sage: K. = QQ.extension(x^3 + 5); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 + 5 We make an extension generated by roots of two polynomials:: diff --git a/src/sage/rings/real_arb.pyx b/src/sage/rings/real_arb.pyx index b969c762e84..d95b8abe320 100644 --- a/src/sage/rings/real_arb.pyx +++ b/src/sage/rings/real_arb.pyx @@ -339,7 +339,7 @@ class RealBallField(UniqueRepresentation, sage.rings.abc.RealBallField): :: - sage: (1/2*RBF(1)) + AA(sqrt(2)) - 1 + polygen(QQ, 'x') + sage: (1/2*RBF(1)) + AA(sqrt(2)) - 1 + polygen(QQ, 'x') # optional - sage.symbolic x + [0.914213562373095 +/- ...e-16] TESTS:: diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index 21a2f293ee9..de591cc5ee6 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -1023,7 +1023,7 @@ cdef class RealDoubleElement(FieldElement): sage: sage_input(RDF(-e), verify=True, preparse=False) # Verified -RDF(2.718281828459045...) - sage: sage_input(RDF(pi)*polygen(RDF), verify=True, preparse=None) + sage: sage_input(RDF(pi)*polygen(RDF), verify=True, preparse=None) # optional - sage.symbolic # Verified R = RDF['x'] x = R.gen() diff --git a/src/sage/rings/real_lazy.pyx b/src/sage/rings/real_lazy.pyx index 3d779b359ce..b6ff3f64015 100644 --- a/src/sage/rings/real_lazy.pyx +++ b/src/sage/rings/real_lazy.pyx @@ -1689,7 +1689,8 @@ cdef class LazyAlgebraic(LazyFieldElement): TESTS:: sage: from sage.rings.real_lazy import LazyAlgebraic - sage: a = LazyAlgebraic(RLF, x^2-2, 1.5) + sage: x = polygen(QQ) + sage: a = LazyAlgebraic(RLF, x^2 - 2, 1.5) sage: float(loads(dumps(a))) == float(a) True """ diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index e806637c38a..f689a290e3e 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -785,8 +785,9 @@ cdef class Ring(ParentWithGens): True sage: CC.is_subring(CC) True - sage: K. = NumberField(x^3-x+1/10) - sage: K.is_subring(K) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - x + 1/10) # optional - sage.rings.number_field + sage: K.is_subring(K) # optional - sage.rings.number_field True sage: R. = RR[] sage: R.is_subring(R) @@ -871,9 +872,8 @@ cdef class Ring(ParentWithGens): Make sure :trac:`10481` is fixed:: - sage: var('x') - x - sage: R. = ZZ['x'].quo(x^2) + sage: x = polygen(ZZ, 'x') + sage: R. = ZZ['x'].quo(x^2) # optional - sage.libs.pari sage: R.fraction_field() Traceback (most recent call last): ... @@ -1785,9 +1785,10 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.krull_dimension() 1 - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.krull_dimension() + sage: x = polygen(ZZ, 'x') + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.krull_dimension() # optional - sage.rings.number_field 1 The following are not Dedekind domains but have @@ -1828,9 +1829,10 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.is_integrally_closed() True - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.is_integrally_closed() + sage: x = polygen(ZZ, 'x') + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.is_integrally_closed() # optional - sage.rings.number_field True These, however, are not Dedekind domains:: @@ -1852,11 +1854,13 @@ cdef class DedekindDomain(IntegralDomain): EXAMPLES:: - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.integral_closure() - Gaussian Integers in Number Field in s with defining polynomial x^2 + 1 - sage: OK.integral_closure() == OK + sage: x = polygen(ZZ, 'x') + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.integral_closure() # optional - sage.rings.number_field + Gaussian Integers in Number Field in s + with defining polynomial x^2 + 1 + sage: OK.integral_closure() == OK # optional - sage.rings.number_field True sage: QQ.integral_closure() == QQ @@ -1875,9 +1879,10 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.is_noetherian() True - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.is_noetherian() + sage: x = polygen(ZZ, 'x') + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.is_noetherian() # optional - sage.rings.number_field True sage: QQ.is_noetherian() True @@ -2113,8 +2118,9 @@ cdef class Field(PrincipalIdealDomain): sage: CC.fraction_field() Complex Field with 53 bits of precision - sage: F = NumberField(x^2 + 1, 'i') - sage: F.fraction_field() + sage: x = polygen(ZZ, 'x') + sage: F = NumberField(x^2 + 1, 'i') # optional - sage.rings.number_field + sage: F.fraction_field() # optional - sage.rings.number_field Number Field in i with defining polynomial x^2 + 1 """ return self diff --git a/src/sage/rings/ring_extension.pyx b/src/sage/rings/ring_extension.pyx index c72c5316a90..6d5bff3d49c 100644 --- a/src/sage/rings/ring_extension.pyx +++ b/src/sage/rings/ring_extension.pyx @@ -337,6 +337,7 @@ class RingExtensionFactory(UniqueFactory): sage: QQ.over(ZZ) is E True + sage: x = polygen(ZZ, 'x') sage: K. = QQ.extension(x^2 - 2) sage: E = K.over(QQ) sage: E @@ -624,6 +625,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = QQ.extension(x^2 - 2) sage: E = K.over() # over QQ @@ -660,6 +662,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^2 - 2) sage: K. = A.over() @@ -1447,6 +1450,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): TESTS:: + sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^2 - 2) sage: B. = QQ.extension(x^6 - 2) sage: f = A.hom([b^3]) @@ -1700,6 +1704,7 @@ cdef class RingExtension_generic(CommutativeAlgebra): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: A. = ZZ.extension(x^2 - 5) sage: OK = A.over() # over ZZ sage: OK @@ -1975,6 +1980,7 @@ cdef class RingExtensionFractionField(RingExtension_generic): TESTS:: + sage: x = polygen(ZZ, 'x') sage: A. = ZZ.extension(x^2 - 2) sage: OK = A.over() sage: K = OK.fraction_field() @@ -1996,6 +2002,7 @@ cdef class RingExtensionFractionField(RingExtension_generic): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: A. = ZZ.extension(x^2 - 2) sage: OK = A.over() sage: K = OK.fraction_field() @@ -2015,6 +2022,7 @@ cdef class RingExtensionFractionField(RingExtension_generic): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: A. = ZZ.extension(x^2 - 2) sage: OK = A.over() sage: K = OK.fraction_field() @@ -2085,6 +2093,7 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: + sage: x = polygen(ZZ, 'x') sage: K. = QQ.extension(x^3 - 2) sage: E = K.over() sage: E @@ -2178,6 +2187,7 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: + sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^2 - 2) sage: B. = QQ.extension(x^6 - 2) sage: f = A.hom([b^3]) @@ -2285,6 +2295,7 @@ cdef class RingExtensionWithBasis(RingExtension_generic): TESTS:: + sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^3 - 2) sage: K. = A.over() sage: K.basis_over() @@ -2442,6 +2453,7 @@ cdef class RingExtensionWithBasis(RingExtension_generic): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: A. = ZZ.extension(x^2 - 5) sage: OK = A.over() # over ZZ sage: OK @@ -2508,6 +2520,7 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): TESTS:: + sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^3 - 7) sage: K = A.over() @@ -2535,6 +2548,7 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): TESTS:: + sage: x = polygen(ZZ, 'x') sage: K. = QQ.extension(x^3 + 3*x + 1) sage: E = K.over() sage: E @@ -2684,6 +2698,7 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: A. = ZZ.extension(x^2 - 5) sage: OK = A.over() # over ZZ sage: OK diff --git a/src/sage/rings/ring_extension_element.pyx b/src/sage/rings/ring_extension_element.pyx index 134cd1a1174..17294e7af4a 100644 --- a/src/sage/rings/ring_extension_element.pyx +++ b/src/sage/rings/ring_extension_element.pyx @@ -105,6 +105,7 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^2 - 2) sage: K. = A.over() # over QQ @@ -138,6 +139,7 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^2 - 2) sage: K. = A.over() @@ -381,6 +383,7 @@ cdef class RingExtensionElement(CommutativeAlgebraElement): TESTS:: + sage: x = polygen(ZZ, 'x') sage: A. = ZZ.extension(x^2 - 2) sage: OK = A.over() sage: a = OK(a) @@ -656,6 +659,7 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: A. = ZZ.extension(x^2 - 2) sage: OK = A.over() # over ZZ sage: K = OK.fraction_field() diff --git a/src/sage/rings/ring_extension_morphism.pyx b/src/sage/rings/ring_extension_morphism.pyx index 2cde5d9502d..04d2aa4a650 100644 --- a/src/sage/rings/ring_extension_morphism.pyx +++ b/src/sage/rings/ring_extension_morphism.pyx @@ -241,6 +241,7 @@ cdef class RingExtensionHomomorphism(RingMap): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: A. = QQ.extension(x^2 - 2) sage: K. = A.over() sage: f = K.hom([-sqrt2]) @@ -477,6 +478,7 @@ cdef class RingExtensionHomomorphism(RingMap): TESTS:: + sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^2 - 5) sage: K. = A.over() sage: f = K.hom([-sqrt5]) @@ -556,6 +558,7 @@ cdef class RingExtensionBackendIsomorphism(RingExtensionHomomorphism): TESTS:: + sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^2 - 5) sage: K = A.over() sage: K.coerce_map_from(A) @@ -648,6 +651,7 @@ cdef class RingExtensionBackendReverseIsomorphism(RingExtensionHomomorphism): TESTS:: + sage: x = polygen(ZZ, 'x') sage: A. = QQ.extension(x^2 - 5) sage: K = A.over() sage: A.convert_map_from(K) diff --git a/src/sage/rings/tate_algebra.py b/src/sage/rings/tate_algebra.py index 5d94d204f69..d1371b431f7 100644 --- a/src/sage/rings/tate_algebra.py +++ b/src/sage/rings/tate_algebra.py @@ -91,8 +91,7 @@ sage: f(a^2, 2*a) 1 + 2^2 + a*2^4 + O(2^5) - sage: var('u') - u + sage: u = polygen(ZZ, 'u') sage: L. = K.change(print_mode="series").extension(u^3 - 2) sage: g(pi, 2*pi) pi^7 + pi^8 + pi^19 + pi^20 + O(pi^21) @@ -841,6 +840,7 @@ def _pushout_(self, R): sage: from sage.categories.pushout import pushout sage: R = Zp(2) sage: R1. = Zq(4) + sage: x = polygen(ZZ, 'x') sage: R2. = R.extension(x^2 - 2) sage: A. = TateAlgebra(R, log_radii=[1,2]) @@ -1196,6 +1196,7 @@ def absolute_e(self): sage: A.absolute_e() 1 + sage: x = polygen(ZZ, 'x') sage: S. = R.extension(x^2 - 2) sage: A. = TateAlgebra(S) sage: A.absolute_e() diff --git a/src/sage/rings/tate_algebra_element.pyx b/src/sage/rings/tate_algebra_element.pyx index 80d7c448721..f25d38c139f 100644 --- a/src/sage/rings/tate_algebra_element.pyx +++ b/src/sage/rings/tate_algebra_element.pyx @@ -1884,6 +1884,7 @@ cdef class TateAlgebraElement(CommutativeAlgebraElement): sage: f(a, 2) a^2 + 2^2 + O(2^20) + sage: x = polygen(ZZ, 'x') sage: T. = S.extension(x^2 - 2) sage: f(pi, 2) pi^2 + pi^4 + O(pi^42) @@ -3268,6 +3269,7 @@ cdef class TateAlgebraElement(CommutativeAlgebraElement): sage: f % [2,u] # indirect doctest O(2^10 * ) + sage: x = polygen(ZZ, 'x') sage: S. = R.extension(x^2 - 2) sage: f % (pi*u) # indirect doctest (pi^2 + O(pi^20))*v^2 + O(pi^20 * ) diff --git a/src/sage/schemes/elliptic_curves/cm.py b/src/sage/schemes/elliptic_curves/cm.py index 57f8744dc80..8114262ab8a 100644 --- a/src/sage/schemes/elliptic_curves/cm.py +++ b/src/sage/schemes/elliptic_curves/cm.py @@ -359,6 +359,7 @@ def cm_j_invariants(K, proof=None): Over number fields K of many higher degrees this also works:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: cm_j_invariants(K) # optional - sage.rings.number_field [-262537412640768000, -147197952000, -884736000, -884736, -32768, @@ -414,6 +415,7 @@ def cm_j_invariants_and_orders(K, proof=None): Over number fields K of many higher degrees this also works:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: cm_j_invariants_and_orders(K) # optional - sage.rings.number_field [(-163, 1, -262537412640768000), (-67, 1, -147197952000), @@ -919,6 +921,7 @@ def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None): sage: K. = QuadraticField(5) # optional - sage.rings.number_field sage: is_cm_j_invariant(282880*a + 632000) # optional - sage.rings.number_field (True, (-20, 1)) + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: is_cm_j_invariant(31710790944000*a^2 + 39953093016000*a + 50337742902000) # optional - sage.rings.number_field (True, (-3, 6)) diff --git a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py index 9e1d9473081..121e3494534 100644 --- a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py +++ b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py @@ -769,6 +769,7 @@ class EllipticCurveIsogeny(EllipticCurveHom): sage: E = EllipticCurve('11a1') sage: P_list = E.torsion_points() + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2* x^2 - 40*x - 158) # optional - sage.rings.number_field sage: EK = E.change_ring(K) # optional - sage.rings.number_field sage: P_list = [EK(P) for P in P_list] # optional - sage.rings.number_field @@ -1201,6 +1202,7 @@ def _call_(self, P): Tests for :trac:`10888`:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 3) # optional - sage.rings.number_field sage: E = EllipticCurve(K, [7,0]) # optional - sage.rings.number_field sage: phi = E.isogeny(E(0,0)) # optional - sage.rings.number_field diff --git a/src/sage/schemes/elliptic_curves/ell_field.py b/src/sage/schemes/elliptic_curves/ell_field.py index 457ab8f7e78..c10545b3d5c 100644 --- a/src/sage/schemes/elliptic_curves/ell_field.py +++ b/src/sage/schemes/elliptic_curves/ell_field.py @@ -649,7 +649,8 @@ def descend_to(self, K, f=None): :: sage: F. = QuadraticField(23) # optional - sage.rings.number_field - sage: G. = F.extension(x^3 + 5) + sage: x = polygen(ZZ, 'x') + sage: G. = F.extension(x^3 + 5) # optional - sage.rings.number_field sage: E = EllipticCurve(j=1728*b).change_ring(G) # optional - sage.rings.number_field sage: EF = E.descend_to(F); EF # optional - sage.rings.number_field [Elliptic Curve defined by y^2 = x^3 + (27*b-621)*x + (-1296*b+2484) @@ -1494,6 +1495,7 @@ def isogenies_prime_degree(self, l=None, max_l=31): Examples over number fields (other than QQ):: + sage: x = polygen(ZZ, 'x') sage: QQroot2. = NumberField(x^2 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve(QQroot2, j=8000) # optional - sage.rings.number_field sage: E.isogenies_prime_degree() # optional - sage.rings.number_field @@ -1789,6 +1791,7 @@ class of curves. If the j-invariant is not unique in the isogeny Ordinary curve over finite extension field of degree 2:: + sage: x = polygen(ZZ, 'x') sage: E = EllipticCurve(GF(59^2, "i", x^2 + 1), j=5) # optional - sage.rings.finite_rings sage: G = E.isogeny_ell_graph(5, directed=False, label_by_j=True) # optional - sage.graphs sage.rings.finite_rings sage: G # optional - sage.graphs sage.rings.finite_rings diff --git a/src/sage/schemes/elliptic_curves/ell_generic.py b/src/sage/schemes/elliptic_curves/ell_generic.py index 4989c94d0d2..c33a13abd62 100644 --- a/src/sage/schemes/elliptic_curves/ell_generic.py +++ b/src/sage/schemes/elliptic_curves/ell_generic.py @@ -278,6 +278,7 @@ def _latex_(self): Check that :trac:`12524` is solved:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - x - 1) # optional - sage.rings.number_field sage: E = EllipticCurve([0, 0, phi, 27*phi - 43, -80*phi + 128]) # optional - sage.rings.number_field sage: E._latex_() # optional - sage.rings.number_field @@ -2541,6 +2542,7 @@ def isomorphism_to(self, other): We can also handle injections to different base rings:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 7) # optional - sage.rings.number_field sage: E.isomorphism_to(E.change_ring(K)) # optional - sage.rings.number_field Elliptic-curve morphism: @@ -2583,6 +2585,7 @@ def automorphisms(self, field=None): We can also find automorphisms defined over extension fields:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 3) # adjoin roots of unity # optional - sage.rings.number_field sage: E.automorphisms(K) # optional - sage.rings.number_field [Elliptic-curve endomorphism of Elliptic Curve defined by y^2 + y = x^3 @@ -3328,6 +3331,7 @@ def _p_primary_torsion_basis(self, p, m=None): sage: E = EllipticCurve('11a1') sage: E._p_primary_torsion_basis(5) [[(5 : -6 : 1), 1]] + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 + x^3 + 11*x^2 + 41*x + 101) # optional - sage.rings.number_field sage: EK = E.base_extend(K) # optional - sage.rings.number_field sage: EK._p_primary_torsion_basis(5) # long time (2s on sage.math, 2011) # optional - sage.rings.number_field diff --git a/src/sage/schemes/elliptic_curves/ell_local_data.py b/src/sage/schemes/elliptic_curves/ell_local_data.py index 2845a623d0f..2b9bd9d2ab4 100644 --- a/src/sage/schemes/elliptic_curves/ell_local_data.py +++ b/src/sage/schemes/elliptic_curves/ell_local_data.py @@ -16,6 +16,7 @@ EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: E = EllipticCurve([(2+i)^2, (2+i)^7]) sage: pp = K.fractional_ideal(2+i) @@ -331,6 +332,7 @@ def minimal_model(self, reduce=True): To demonstrate the behaviour of the parameter ``reduce``:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + x + 1) sage: E = EllipticCurve(K, [0, 0, a, 0, 1]) sage: E.local_data(K.ideal(a-1)).minimal_model() @@ -515,6 +517,7 @@ def bad_reduction_type(self): sage: [(p,E.local_data(p).bad_reduction_type()) for p in prime_range(15)] [(2, -1), (3, None), (5, None), (7, 1), (11, None), (13, None)] + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: P17a, P17b = [P for P,e in K.factor(17)] sage: E = EllipticCurve([0, 0, 0, 0, 2*a+1]) @@ -533,6 +536,7 @@ def has_good_reduction(self): sage: [(p,E.local_data(p).has_good_reduction()) for p in prime_range(15)] [(2, False), (3, True), (5, True), (7, False), (11, True), (13, True)] + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: P17a, P17b = [P for P,e in K.factor(17)] sage: E = EllipticCurve([0, 0, 0, 0, 2*a+1]) @@ -554,6 +558,7 @@ def has_bad_reduction(self): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: P17a, P17b = [P for P,e in K.factor(17)] sage: E = EllipticCurve([0, 0, 0, 0, 2*a+1]) @@ -580,6 +585,7 @@ def has_multiplicative_reduction(self): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: P17a, P17b = [P for P,e in K.factor(17)] sage: E = EllipticCurve([0, 0, 0, 0, 2*a+1]) @@ -601,6 +607,7 @@ def has_split_multiplicative_reduction(self): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: P17a, P17b = [P for P,e in K.factor(17)] sage: E = EllipticCurve([0, 0, 0, 0, 2*a+1]) @@ -624,6 +631,7 @@ def has_nonsplit_multiplicative_reduction(self): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: P17a, P17b = [P for P,e in K.factor(17)] sage: E = EllipticCurve([0, 0, 0, 0, 2*a+1]) @@ -645,6 +653,7 @@ def has_additive_reduction(self): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: P17a, P17b = [P for P,e in K.factor(17)] sage: E = EllipticCurve([0, 0, 0, 0, 2*a+1]) @@ -703,7 +712,8 @@ def _tate(self, proof=None, globally=False): The following example shows that the bug at :trac:`9324` is fixed:: - sage: K. = NumberField(x^2-x+6) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - x + 6) sage: E = EllipticCurve([0,0,0,-53160*a-43995,-5067640*a+19402006]) sage: E.conductor() # indirect doctest Fractional ideal (18, 6*a) @@ -1131,8 +1141,9 @@ def check_prime(K, P): 3 sage: check_prime(QQ,ZZ.ideal(31)) 31 - sage: K. = NumberField(x^2-5) - sage: check_prime(K,a) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 5) + sage: check_prime(K, a) Fractional ideal (a) sage: check_prime(K,a+1) Fractional ideal (a + 1) diff --git a/src/sage/schemes/elliptic_curves/ell_number_field.py b/src/sage/schemes/elliptic_curves/ell_number_field.py index 001783fd03c..e01d7436d94 100644 --- a/src/sage/schemes/elliptic_curves/ell_number_field.py +++ b/src/sage/schemes/elliptic_curves/ell_number_field.py @@ -223,6 +223,7 @@ def simon_two_descent(self, verbose=0, lim1=2, lim3=4, limtriv=2, EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 23, 'a') sage: E = EllipticCurve(K, '37') sage: E == loads(dumps(E)) @@ -704,7 +705,8 @@ def _reduce_model(self): EXAMPLES:: - sage: K. = NumberField(x^2-38) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 38) sage: E = EllipticCurve([a, -5*a + 19, -39*a + 237, 368258520200522046806318224*a - 2270097978636731786720858047, 8456608930180227786550494643437985949781*a - 52130038506835491453281450568107193773505]) sage: E.ainvs() (a, @@ -762,7 +764,8 @@ def _scale_by_units(self): EXAMPLES:: - sage: K. = NumberField(x^2-10) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 10) sage: u = a + 3 sage: u.is_unit() True @@ -1259,7 +1262,8 @@ def tamagawa_number(self, P, proof=None): EXAMPLES:: - sage: K. = NumberField(x^2-5) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 5) sage: E = EllipticCurve([20, 225, 750, 625*a + 6875, 31250*a + 46875]) sage: [E.tamagawa_number(P) for P in E.discriminant().support()] [1, 1, 1, 1] @@ -1974,6 +1978,7 @@ def torsion_subgroup(self): EXAMPLES:: sage: E = EllipticCurve('11a1') + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 + x^3 + 11*x^2 + 41*x + 101) sage: EK = E.base_extend(K) sage: tor = EK.torsion_subgroup() # long time (2s on sage.math, 2014) @@ -2033,6 +2038,7 @@ def torsion_order(self): EXAMPLES:: sage: E = EllipticCurve('11a1') + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 + x^3 + 11*x^2 + 41*x + 101) sage: EK = E.base_extend(K) sage: EK.torsion_order() # long time (2s on sage.math, 2014) @@ -2076,6 +2082,7 @@ def torsion_points(self): sage: E = EllipticCurve('11a1') sage: E.torsion_points() [(0 : 1 : 0), (5 : -6 : 1), (5 : 5 : 1), (16 : -61 : 1), (16 : 60 : 1)] + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 + x^3 + 11*x^2 + 41*x + 101) sage: EK = E.base_extend(K) sage: EK.torsion_points() # long time (1s on sage.math, 2014) @@ -2179,6 +2186,7 @@ def rank_bounds(self, **kwds): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 23, 'a') sage: E = EllipticCurve(K, '37') sage: E == loads(dumps(E)) @@ -2258,6 +2266,7 @@ def rank(self, **kwds): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 23, 'a') sage: E = EllipticCurve(K, '37') sage: E == loads(dumps(E)) @@ -2336,6 +2345,7 @@ def gens(self, **kwds): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 23, 'a') sage: E = EllipticCurve(K,[0,0,0,101,0]) sage: E.gens() @@ -2519,6 +2529,7 @@ def height_function(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 5) sage: E = EllipticCurve(K, '11a3') sage: E.height_function() @@ -3303,6 +3314,7 @@ def reducible_primes(self, algorithm='Billerey', max_l=None, EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 - 29, 'a'); a = K.gen() sage: E = EllipticCurve([1, 0, ((5 + a)/2)**2, 0, 0]) sage: rho = E.galois_representation() @@ -3476,6 +3488,7 @@ def galois_representation(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 + 1, 'a') sage: E = EllipticCurve('11a1').change_ring(K) sage: rho = E.galois_representation() @@ -3527,6 +3540,7 @@ def cm_discriminant(self): sage: K. = QuadraticField(5) sage: EllipticCurve(j=282880*a + 632000).cm_discriminant() -20 + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: EllipticCurve(j=31710790944000*a^2 + 39953093016000*a + 50337742902000).cm_discriminant() -108 @@ -3573,6 +3587,7 @@ def has_cm(self): sage: K. = QuadraticField(5) sage: EllipticCurve(j=282880*a + 632000).has_cm() True + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: EllipticCurve(j=31710790944000*a^2 + 39953093016000*a + 50337742902000).has_cm() True @@ -3650,6 +3665,7 @@ def has_rational_cm(self, field=None): is not an extension field of Number Field in a with defining polynomial x^2 - 5 with a = 2.236067977499790? + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: E = EllipticCurve(j=31710790944000*a^2 + 39953093016000*a + 50337742902000) sage: E.has_cm() diff --git a/src/sage/schemes/elliptic_curves/ell_point.py b/src/sage/schemes/elliptic_curves/ell_point.py index 07b3807082c..4b46dae3f96 100644 --- a/src/sage/schemes/elliptic_curves/ell_point.py +++ b/src/sage/schemes/elliptic_curves/ell_point.py @@ -182,6 +182,7 @@ class EllipticCurvePoint_field(SchemeMorphism_point_abelian_variety_field): Abelian group of points on Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field sage: E = EllipticCurve(K, [0,1,0,-160,308]) # optional - sage.rings.number_field sage: P = E(26, -120) # optional - sage.rings.number_field @@ -440,6 +441,7 @@ def scheme(self): Elliptic Curve defined by y^2 = x^3 + x + 1 over Rational Field sage: P.scheme() == P.curve() True + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - 3,'a') # optional - sage.rings.number_field sage: P = E.base_extend(K)(1, a) # optional - sage.rings.number_field sage: P.scheme() # optional - sage.rings.number_field @@ -2345,6 +2347,7 @@ def has_good_reduction(self, P=None): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field sage: E = EllipticCurve(K, [0,1,0,-160,308]) # optional - sage.rings.number_field sage: P = E(26, -120) # optional - sage.rings.number_field @@ -2455,6 +2458,7 @@ def reduction(self, p): :: + sage: x = polygen(ZZ, 'x') sage: F. = NumberField(x^2 + 5) # optional - sage.rings.number_field sage: E = EllipticCurve(F, [1,2,3,4,0]) # optional - sage.rings.number_field sage: Q = E(98, 931) # optional - sage.rings.number_field @@ -2787,6 +2791,7 @@ def archimedean_local_height(self, v=None, prec=None, weighted=False): sage: P.archimedean_local_height(K.places(prec=170)[0]) / 2 # optional - sage.rings.number_field 0.45754773287523276736211210741423654346576029814695 + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field sage: E = EllipticCurve(K, [0,0,4,6*i,0]); E # optional - sage.rings.number_field Elliptic Curve defined by y^2 + 4*y = x^3 + 6*i*x @@ -3006,6 +3011,7 @@ def non_archimedean_local_height(self, v=None, prec=None, Examples 2 and 3 from [Sil1988]_:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field sage: E = EllipticCurve(K, [0,0,4,6*i,0]); E # optional - sage.rings.number_field Elliptic Curve defined by y^2 + 4*y = x^3 + 6*i*x @@ -3249,6 +3255,7 @@ def elliptic_logarithm(self, embedding=None, precision=100, Examples over number fields:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: embs = K.embeddings(CC) # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field diff --git a/src/sage/schemes/elliptic_curves/ell_torsion.py b/src/sage/schemes/elliptic_curves/ell_torsion.py index 6a84cb8a5e6..5cd89e9c2b5 100644 --- a/src/sage/schemes/elliptic_curves/ell_torsion.py +++ b/src/sage/schemes/elliptic_curves/ell_torsion.py @@ -101,6 +101,7 @@ class EllipticCurveTorsionSubgroup(groups.AdditiveAbelianGroupWrapper): Examples over other Number Fields:: sage: E = EllipticCurve('11a1') + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: EK = E.change_ring(K) sage: from sage.schemes.elliptic_curves.ell_torsion import EllipticCurveTorsionSubgroup @@ -145,7 +146,8 @@ def __init__(self, E): sage: from sage.schemes.elliptic_curves.ell_torsion import EllipticCurveTorsionSubgroup sage: E = EllipticCurve('11a1') - sage: K. = NumberField(x^2+1) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + 1) sage: EK = E.change_ring(K) sage: EllipticCurveTorsionSubgroup(EK) Torsion Subgroup isomorphic to Z/5 associated to the @@ -216,6 +218,7 @@ def _repr_(self): EXAMPLES:: sage: E = EllipticCurve('11a1') + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: EK = E.change_ring(K) sage: T = EK.torsion_subgroup(); T._repr_() @@ -245,6 +248,7 @@ def curve(self): EXAMPLES:: sage: E = EllipticCurve('11a1') + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: EK = E.change_ring(K) sage: T = EK.torsion_subgroup() @@ -262,6 +266,7 @@ def points(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: E = EllipticCurve(K, [0,0,0,1,0]) sage: tor = E.torsion_subgroup() diff --git a/src/sage/schemes/elliptic_curves/gal_reps_number_field.py b/src/sage/schemes/elliptic_curves/gal_reps_number_field.py index c9dc54d2668..73cdac18ea8 100644 --- a/src/sage/schemes/elliptic_curves/gal_reps_number_field.py +++ b/src/sage/schemes/elliptic_curves/gal_reps_number_field.py @@ -9,6 +9,7 @@ EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 - 29, 'a'); a = K.gen() sage: E = EllipticCurve([1, 0, ((5 + a)/2)**2, 0, 0]) sage: rho = E.galois_representation() @@ -74,6 +75,7 @@ class GaloisRepresentation(SageObject): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 + 1, 'a') sage: E = EllipticCurve('11a1').change_ring(K) sage: rho = E.galois_representation() @@ -87,6 +89,7 @@ def __init__(self, E): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 + 1, 'a') sage: E = EllipticCurve('11a1').change_ring(K) sage: rho = E.galois_representation() @@ -103,6 +106,7 @@ def __repr__(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 + 1, 'a') sage: E = EllipticCurve('11a1').change_ring(K) sage: rho = E.galois_representation() @@ -128,6 +132,7 @@ def __eq__(self,other): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 + 1, 'a'); a = K.gen() sage: rho1 = EllipticCurve_from_j(1 + a).galois_representation() sage: rho2 = EllipticCurve_from_j(2 + a).galois_representation() @@ -148,6 +153,7 @@ def elliptic_curve(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 + 1, 'a'); a = K.gen() sage: E = EllipticCurve_from_j(a) sage: rho = E.galois_representation() @@ -175,6 +181,7 @@ def non_surjective(self, A=100): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 - 29, 'a'); a = K.gen() sage: E = EllipticCurve([1, 0, ((5 + a)/2)**2, 0, 0]) sage: rho = E.galois_representation() @@ -225,6 +232,7 @@ def is_surjective(self, p, A=100): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 - 29, 'a'); a = K.gen() sage: E = EllipticCurve([1, 0, ((5 + a)/2)**2, 0, 0]) sage: rho = E.galois_representation() @@ -290,6 +298,7 @@ def isogeny_bound(self, A=100): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 - 29, 'a'); a = K.gen() sage: E = EllipticCurve([1, 0, ((5 + a)/2)**2, 0, 0]) sage: rho = E.galois_representation() @@ -369,6 +378,7 @@ def reducible_primes(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 - 29, 'a'); a = K.gen() sage: E = EllipticCurve([1, 0, ((5 + a)/2)**2, 0, 0]) sage: rho = E.galois_representation() @@ -426,6 +436,7 @@ def _non_surjective(E, patience=100): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 - 29, 'a'); a = K.gen() sage: E = EllipticCurve([1, 0, ((5 + a)/2)**2, 0, 0]) sage: sage.schemes.elliptic_curves.gal_reps_number_field._non_surjective(E) # See Section 5.10 of [Ser1972]. # long time @@ -600,6 +611,7 @@ def _exceptionals(E, L, patience=1000): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 - 29, 'a'); a = K.gen() sage: E = EllipticCurve([1, 0, ((5 + a)/2)**2, 0, 0]) sage: sage.schemes.elliptic_curves.gal_reps_number_field._exceptionals(E, [29, 31]) @@ -832,6 +844,7 @@ def _semistable_reducible_primes(E, verbose=False): This example, over a quintic field with Galois group `S_5`, took a very long time before :trac:`22343`:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^5 - 6*x^3 + 8*x - 1) sage: E = EllipticCurve(K, [a^3 - 2*a, a^4 - 2*a^3 - 4*a^2 + 6*a + 1, a + 1, -a^3 + a + 1, -a]) sage: from sage.schemes.elliptic_curves.gal_reps_number_field import _semistable_reducible_primes @@ -1148,6 +1161,7 @@ def Billerey_P_l(E, l): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 - 29, 'a'); a = K.gen() sage: E = EllipticCurve([1, 0, ((5 + a)/2)**2, 0, 0]) sage: from sage.schemes.elliptic_curves.gal_reps_number_field import Billerey_P_l @@ -1184,6 +1198,7 @@ def Billerey_B_l(E,l,B=0): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 - 29, 'a'); a = K.gen() sage: E = EllipticCurve([1, 0, ((5 + a)/2)**2, 0, 0]) sage: from sage.schemes.elliptic_curves.gal_reps_number_field import Billerey_B_l @@ -1225,6 +1240,7 @@ def Billerey_R_q(E, q, B=0): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 - 29, 'a'); a = K.gen() sage: E = EllipticCurve([1, 0, ((5 + a)/2)**2, 0, 0]) sage: from sage.schemes.elliptic_curves.gal_reps_number_field import Billerey_R_q @@ -1285,6 +1301,7 @@ def Billerey_B_bound(E, max_l=200, num_l=8, small_prime_bound=0, debug=False): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 - 29, 'a'); a = K.gen() sage: E = EllipticCurve([1, 0, ((5 + a)/2)**2, 0, 0]) sage: from sage.schemes.elliptic_curves.gal_reps_number_field import Billerey_B_bound @@ -1394,6 +1411,7 @@ def Billerey_R_bound(E, max_l=200, num_l=8, small_prime_bound=None, debug=False) EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 - 29, 'a'); a = K.gen() sage: E = EllipticCurve([1, 0, ((5 + a)/2)**2, 0, 0]) sage: from sage.schemes.elliptic_curves.gal_reps_number_field import Billerey_R_bound @@ -1503,6 +1521,7 @@ def reducible_primes_Billerey(E, num_l=None, max_l=None, verbose=False): EXAMPLES:: sage: from sage.schemes.elliptic_curves.gal_reps_number_field import reducible_primes_Billerey + sage: x = polygen(ZZ, 'x') sage: K = NumberField(x**2 - 29, 'a'); a = K.gen() sage: E = EllipticCurve([1, 0, ((5 + a)/2)**2, 0, 0]) sage: reducible_primes_Billerey(E) # long time @@ -1612,6 +1631,7 @@ def reducible_primes_naive(E, max_l=None, num_P=None, verbose=False): EXAMPLES:: sage: from sage.schemes.elliptic_curves.gal_reps_number_field import reducible_primes_naive + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^4 - 5*x^2 + 3) sage: E = EllipticCurve(K, [a^2 - 2, -a^2 + 3, a^2 - 2, -50*a^2 + 35, 95*a^2 - 67]) sage: reducible_primes_naive(E,num_P=10) diff --git a/src/sage/schemes/elliptic_curves/height.py b/src/sage/schemes/elliptic_curves/height.py index e9eb837d30e..ea80e150c91 100644 --- a/src/sage/schemes/elliptic_curves/height.py +++ b/src/sage/schemes/elliptic_curves/height.py @@ -1161,6 +1161,7 @@ def psi(self, xi, v): An example over a number field:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve([0,0,0,0,a]) # optional - sage.rings.number_field sage: P = E.lift_x(1/3*a^2 + a + 5/3) # optional - sage.rings.number_field @@ -1216,6 +1217,7 @@ def S(self, xi1, xi2, v): An example over a number field:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve([0,0,0,0,a]) # optional - sage.rings.number_field sage: v = K.real_places()[0] # optional - sage.rings.number_field @@ -1267,6 +1269,7 @@ def Sn(self, xi1, xi2, n, v): An example over a number field:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve([0,0,0,0,a]) # optional - sage.rings.number_field sage: v = K.real_places()[0] # optional - sage.rings.number_field @@ -1320,6 +1323,7 @@ def real_intersection_is_empty(self, Bk, v): An example over a number field:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve([0,0,0,0,a]) # optional - sage.rings.number_field sage: v = K.real_places()[0] # optional - sage.rings.number_field @@ -1670,6 +1674,7 @@ def complex_intersection_is_empty(self, Bk, v, verbose=False, use_half=True): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve([0,0,0,0,a]) # optional - sage.rings.number_field sage: v = K.complex_embeddings()[0] # optional - sage.rings.number_field @@ -1788,6 +1793,7 @@ def test_mu(self, mu, N, verbose=True): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve([0,0,0,0,a]) # optional - sage.rings.number_field sage: H = E.height_function() # optional - sage.rings.number_field diff --git a/src/sage/schemes/elliptic_curves/hom.py b/src/sage/schemes/elliptic_curves/hom.py index e1c5ed25c84..2ec9d2fd747 100644 --- a/src/sage/schemes/elliptic_curves/hom.py +++ b/src/sage/schemes/elliptic_curves/hom.py @@ -945,6 +945,7 @@ def find_post_isomorphism(phi, psi): sage: from sage.schemes.elliptic_curves.weierstrass_morphism import WeierstrassIsomorphism sage: from sage.schemes.elliptic_curves.hom_composite import EllipticCurveHom_composite + sage: x = polygen(ZZ, 'x') sage: F. = GF(883^2, modulus=x^2+1) sage: E = EllipticCurve(F, [1,0]) sage: P = E.lift_x(117) diff --git a/src/sage/schemes/elliptic_curves/hom_composite.py b/src/sage/schemes/elliptic_curves/hom_composite.py index a117e2e87d0..6c4bd0fcdd9 100644 --- a/src/sage/schemes/elliptic_curves/hom_composite.py +++ b/src/sage/schemes/elliptic_curves/hom_composite.py @@ -230,6 +230,7 @@ def __init__(self, E, kernel, codomain=None, model=None): The given kernel generators need not be independent:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - x - 5) # optional - sage.rings.number_field sage: E = EllipticCurve('210.b6').change_ring(K) # optional - sage.rings.number_field sage: E.torsion_subgroup() # optional - sage.rings.number_field @@ -402,6 +403,7 @@ def _call_(self, P): TESTS:: sage: from sage.schemes.elliptic_curves.hom_composite import EllipticCurveHom_composite + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 - x - 5) # optional - sage.rings.number_field sage: E = EllipticCurve('210.b6').change_ring(K) # optional - sage.rings.number_field sage: psi = EllipticCurveHom_composite(E, E.torsion_points()) # optional - sage.rings.number_field diff --git a/src/sage/schemes/elliptic_curves/isogeny_small_degree.py b/src/sage/schemes/elliptic_curves/isogeny_small_degree.py index 28b4a8ebcca..57fc5bb1bb3 100644 --- a/src/sage/schemes/elliptic_curves/isogeny_small_degree.py +++ b/src/sage/schemes/elliptic_curves/isogeny_small_degree.py @@ -877,6 +877,7 @@ def isogenies_5_0(E, minimal_models=True): to Elliptic Curve defined by y^2 = x^3 + (9*a+10)*x + (11*a+12) over Finite Field in a of size 13^2] + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x**6 - 320*x**3 - 320) # optional - sage.rings.number_field sage: E = EllipticCurve(K, [0,0,1,0,0]) # optional - sage.rings.number_field sage: isogenies_5_0(E) # optional - sage.rings.number_field @@ -988,6 +989,7 @@ def isogenies_5_1728(E, minimal_models=True): An example of 5-isogenies over a number field:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x**4 + 20*x**2 - 80) # optional - sage.rings.number_field sage: K(5).is_square() # necessary but not sufficient! # optional - sage.rings.number_field True @@ -1133,6 +1135,7 @@ def isogenies_7_0(E, minimal_models=True): to Elliptic Curve defined by y^2 + y = x^3 + (-7) over Number Field in r with defining polynomial x^2 + 3 with r = 1.732050807568878?*I] + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^6 + 1512*x^3 - 21168) # optional - sage.rings.number_field sage: E = EllipticCurve(K, [0,1]) # optional - sage.rings.number_field sage: isogs = isogenies_7_0(E) # optional - sage.rings.number_field @@ -1239,6 +1242,7 @@ def isogenies_7_1728(E, minimal_models=True): :: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^8 + 84*x^6 - 1890*x^4 + 644*x^2 - 567) # optional - sage.rings.number_field sage: E = EllipticCurve(K, [1, 0]) # optional - sage.rings.number_field sage: isogs = isogenies_7_1728(E) # optional - sage.rings.number_field diff --git a/src/sage/schemes/elliptic_curves/kraus.py b/src/sage/schemes/elliptic_curves/kraus.py index 79b7afa9c2c..7599909a2de 100644 --- a/src/sage/schemes/elliptic_curves/kraus.py +++ b/src/sage/schemes/elliptic_curves/kraus.py @@ -86,7 +86,8 @@ def c4c6_nonsingular(c4, c6): Over number fields:: - sage: K. = NumberField(x^2-10) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 10) sage: c4c6_nonsingular(-217728*a - 679104, 141460992*a + 409826304) True sage: K. = NumberField(x^3-10) @@ -120,7 +121,8 @@ def c4c6_model(c4, c6, assume_nonsingular=False): EXAMPLES:: sage: from sage.schemes.elliptic_curves.kraus import c4c6_model - sage: K. = NumberField(x^3-10) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 10) sage: c4c6_model(-217728*a - 679104, 141460992*a + 409826304) Elliptic Curve defined by y^2 = x^3 + (4536*a+14148)*x + (-163728*a-474336) over Number Field in a with defining polynomial x^3 - 10 @@ -164,7 +166,8 @@ def make_integral(a, P, e): sage: from sage.schemes.elliptic_curves.kraus import make_integral - sage: K. = NumberField(x^2-10) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 10) sage: P = K.primes_above(2)[0] sage: e = P.ramification_index(); e 2 @@ -204,7 +207,8 @@ def sqrt_mod_4(x, P): EXAMPLES:: sage: from sage.schemes.elliptic_curves.kraus import sqrt_mod_4 - sage: K. = NumberField(x^2-10) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 10) sage: P = K.primes_above(2)[0] sage: sqrt_mod_4(1+2*a,P) (False, 0) @@ -245,7 +249,8 @@ def test_b2_local(c4, c6, P, b2, debug=False): EXAMPLES:: - sage: K. = NumberField(x^2-10) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 10) sage: c4 = -60544*a + 385796 sage: c6 = -55799680*a + 262126328 sage: P3a, P3b = K.primes_above(3) @@ -307,7 +312,8 @@ def test_b2_global(c4, c6, b2, debug=False): EXAMPLES:: - sage: K. = NumberField(x^2-10) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 10) sage: c4 = -60544*a + 385796 sage: c6 = -55799680*a + 262126328 sage: b2 = a+1 @@ -356,7 +362,8 @@ def check_Kraus_local_3(c4, c6, P, assume_nonsingular=False, debug=False): EXAMPLES:: sage: from sage.schemes.elliptic_curves.kraus import check_Kraus_local_3 - sage: K. = NumberField(x^2-10) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 10) sage: c4 = -60544*a + 385796 sage: c6 = -55799680*a + 262126328 sage: P3a, P3b = K.primes_above(3) @@ -424,7 +431,8 @@ def test_a1a3_local(c4, c6, P, a1, a3, debug=False): EXAMPLES:: sage: from sage.schemes.elliptic_curves.kraus import test_a1a3_local - sage: K. = NumberField(x^2-10) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 10) sage: c4 = -60544*a + 385796 sage: c6 = -55799680*a + 262126328 sage: P = K.primes_above(2)[0] @@ -465,7 +473,8 @@ def test_a1a3_global(c4, c6, a1, a3, debug=False): EXAMPLES:: sage: from sage.schemes.elliptic_curves.kraus import test_a1a3_global - sage: K. = NumberField(x^2-10) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 10) sage: c4 = -60544*a + 385796 sage: c6 = -55799680*a + 262126328 sage: test_a1a3_global(c4,c6,a,a,debug=False) @@ -505,6 +514,7 @@ def test_rst_global(c4, c6, r, s, t, debug=False): EXAMPLES:: sage: from sage.schemes.elliptic_curves.kraus import test_rst_global + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2-10) sage: c4 = -60544*a + 385796 sage: c6 = -55799680*a + 262126328 @@ -570,8 +580,9 @@ def check_Kraus_local_2(c4, c6, P, a1=None, assume_nonsingular=False): EXAMPLES:: sage: from sage.schemes.elliptic_curves.kraus import check_Kraus_local_2 - sage: K. = NumberField(x^2-10) - sage: c4 = -60544*a + 385796 # EllipticCurve([a,a,0,1263*a-8032,62956*a-305877]) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 10) + sage: c4 = -60544*a + 385796 # EllipticCurve([a,a,0,1263*a-8032,62956*a-305877]) sage: c6 = -55799680*a + 262126328 sage: P = K.primes_above(2)[0] sage: check_Kraus_local_2(c4,c6,P) @@ -656,7 +667,8 @@ def check_Kraus_local(c4, c6, P, assume_nonsingular=False): EXAMPLES:: sage: from sage.schemes.elliptic_curves.kraus import check_Kraus_local - sage: K. = NumberField(x^2-15) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 15) sage: P2 = K.primes_above(2)[0] sage: P3 = K.primes_above(3)[0] sage: P5 = K.primes_above(5)[0] @@ -724,7 +736,8 @@ def check_Kraus_global(c4, c6, assume_nonsingular=False, debug=False): EXAMPLES:: sage: from sage.schemes.elliptic_curves.kraus import check_Kraus_global - sage: K. = NumberField(x^2-10) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 10) sage: E = EllipticCurve([a,a,0,1263*a-8032,62956*a-305877]) sage: c4, c6 = E.c_invariants() sage: check_Kraus_global(c4,c6,debug=True) @@ -900,7 +913,8 @@ def semi_global_minimal_model(E, debug=False): EXAMPLES:: - sage: K. = NumberField(x^2-10) + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 - 10) sage: K.class_number() 2 sage: E = EllipticCurve([0,0,0,-186408*a - 589491, 78055704*a + 246833838]) diff --git a/src/sage/schemes/elliptic_curves/modular_parametrization.py b/src/sage/schemes/elliptic_curves/modular_parametrization.py index ee38d1ffe53..891a9e0142f 100644 --- a/src/sage/schemes/elliptic_curves/modular_parametrization.py +++ b/src/sage/schemes/elliptic_curves/modular_parametrization.py @@ -213,8 +213,9 @@ def map_to_complex_numbers(self, z, prec=None): EXAMPLES:: sage: E = EllipticCurve('37a'); phi = E.modular_parametrization() - sage: tau = (sqrt(7)*I - 17)/74 - sage: z = phi.map_to_complex_numbers(tau); z + sage: x = polygen(ZZ, 'x') + sage: tau = (sqrt(7)*I - 17)/74 # optional - sage.symbolic + sage: z = phi.map_to_complex_numbers(tau); z # optional - sage.symbolic 0.929592715285395 - 1.22569469099340*I sage: E.elliptic_exponential(z) (...e-16 - ...e-16*I : ...e-16 + ...e-16*I : 1.00000000000000) diff --git a/src/sage/schemes/elliptic_curves/period_lattice.py b/src/sage/schemes/elliptic_curves/period_lattice.py index 1c767699fb5..7ef65ef2e39 100644 --- a/src/sage/schemes/elliptic_curves/period_lattice.py +++ b/src/sage/schemes/elliptic_curves/period_lattice.py @@ -16,6 +16,7 @@ EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field @@ -179,6 +180,7 @@ def __init__(self, E, embedding=None): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: emb = K.embeddings(RealField())[0] # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field @@ -279,6 +281,7 @@ def __richcmp__(self, other, op): TESTS:: sage: from sage.schemes.elliptic_curves.period_lattice import PeriodLattice_ell + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field sage: embs = K.embeddings(ComplexField()) # optional - sage.rings.number_field @@ -309,6 +312,7 @@ def __repr__(self): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: emb = K.embeddings(RealField())[0] # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field @@ -435,6 +439,7 @@ def basis(self, prec=None, algorithm='sage'): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: emb = K.embeddings(RealField())[0] # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field @@ -536,6 +541,7 @@ def normalised_basis(self, prec=None, algorithm='sage'): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: emb = K.embeddings(RealField())[0] # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field @@ -589,6 +595,7 @@ def tau(self, prec=None, algorithm='sage'): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: emb = K.embeddings(RealField())[0] # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field @@ -635,6 +642,7 @@ def _compute_periods_real(self, prec=None, algorithm='sage'): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field sage: embs = K.embeddings(CC) # optional - sage.rings.number_field @@ -705,6 +713,7 @@ def _compute_periods_complex(self, prec=None, normalise=True): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field sage: embs = K.embeddings(CC) # optional - sage.rings.number_field @@ -776,6 +785,7 @@ def is_real(self): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field sage: [E.period_lattice(emb).is_real() for emb in K.embeddings(CC)] # optional - sage.rings.number_field @@ -850,6 +860,7 @@ def real_period(self, prec=None, algorithm='sage'): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: emb = K.embeddings(RealField())[0] # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field @@ -911,6 +922,7 @@ def omega(self, prec=None, bsd_normalise=False): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: emb = K.embeddings(RealField())[0] # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field @@ -968,6 +980,7 @@ def basis_matrix(self, prec=None, normalised=False): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: emb = K.embeddings(RealField())[0] # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field @@ -1025,6 +1038,7 @@ def complex_area(self, prec=None): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: embs = K.embeddings(ComplexField()) sage: E = EllipticCurve([0,1,0,a,a]) @@ -1091,6 +1105,7 @@ def curve(self): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field sage: L = E.period_lattice(K.embeddings(RealField())[0]) # optional - sage.rings.number_field @@ -1120,6 +1135,7 @@ def ei(self): :: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve([0,1,0,a,a]) # optional - sage.rings.number_field sage: L = E.period_lattice(K.embeddings(RealField())[0]) # optional - sage.rings.number_field @@ -1335,6 +1351,7 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): A number field example:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field sage: E = EllipticCurve([0,0,0,0,a]) # optional - sage.rings.number_field sage: v = K.real_places()[0] # optional - sage.rings.number_field diff --git a/src/sage/schemes/generic/homset.py b/src/sage/schemes/generic/homset.py index 8534b9b2fa0..5e88b3ceef5 100644 --- a/src/sage/schemes/generic/homset.py +++ b/src/sage/schemes/generic/homset.py @@ -668,6 +668,7 @@ def extended_codomain(self): EXAMPLES:: sage: P2 = ProjectiveSpace(QQ, 2) + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + x - (3^3-3)) # optional - sage.rings.number_field sage: K_points = P2(K); K_points # optional - sage.rings.number_field Set of rational points of Projective Space of dimension 2 diff --git a/src/sage/schemes/hyperelliptic_curves/mestre.py b/src/sage/schemes/hyperelliptic_curves/mestre.py index 7a44c8a3ada..166681b32a1 100644 --- a/src/sage/schemes/hyperelliptic_curves/mestre.py +++ b/src/sage/schemes/hyperelliptic_curves/mestre.py @@ -248,6 +248,7 @@ def Mestre_conic(i, xyz=False, names='u,v,w'): Note that the algorithm works over number fields as well:: + sage: x = polygen(ZZ, 'x') sage: k = NumberField(x^2 - 41, 'a') # optional - sage.rings.number_field sage: a = k.an_element() # optional - sage.rings.number_field sage: Mestre_conic([1, 2 + a, a, 4 + a]) # optional - sage.rings.number_field diff --git a/src/sage/schemes/projective/proj_bdd_height.py b/src/sage/schemes/projective/proj_bdd_height.py index dad84b0000c..f2f8a375e01 100644 --- a/src/sage/schemes/projective/proj_bdd_height.py +++ b/src/sage/schemes/projective/proj_bdd_height.py @@ -181,6 +181,7 @@ def points_of_bounded_height(PN, K, dim, bound, prec=53): EXAMPLES: sage: from sage.schemes.projective.proj_bdd_height import points_of_bounded_height + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 7) # optional - sage.rings.number_field sage: P. = ProjectiveSpace(K, 2) # optional - sage.rings.number_field sage: len(list(points_of_bounded_height(P, K, 2, 1))) # optional - sage.rings.number_field diff --git a/src/sage/schemes/projective/projective_homset.py b/src/sage/schemes/projective/projective_homset.py index c11736d7b25..c4aa79b9f7a 100644 --- a/src/sage/schemes/projective/projective_homset.py +++ b/src/sage/schemes/projective/projective_homset.py @@ -579,10 +579,11 @@ class SchemeHomset_points_abelian_variety_field(SchemeHomset_points_projective_f The bug reported at :trac:`1785` is fixed:: - sage: K. = NumberField(x^2 + x - (3^3-3)) # optional - sage.rings.number_field - sage: E = EllipticCurve('37a') # optional - sage.rings.number_field - sage: X = E(K) # optional - sage.rings.number_field - sage: X # optional - sage.rings.number_field + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^2 + x - (3^3-3)) # optional - sage.rings.number_field + sage: E = EllipticCurve('37a') # optional - sage.rings.number_field + sage: X = E(K) # optional - sage.rings.number_field + sage: X # optional - sage.rings.number_field Abelian group of points on Elliptic Curve defined by y^2 + y = x^3 + (-1)*x over Number Field in a with defining polynomial x^2 + x - 24 diff --git a/src/sage/structure/coerce.pyx b/src/sage/structure/coerce.pyx index 86664258c8c..eab5852a410 100644 --- a/src/sage/structure/coerce.pyx +++ b/src/sage/structure/coerce.pyx @@ -549,8 +549,9 @@ cdef class CoercionModel: sage: from sage.structure.coerce import CoercionModel sage: cm = CoercionModel() - sage: K = NumberField(x^2-2, 'a') - sage: A = cm.get_action(ZZ, K, operator.mul) + sage: x = polygen(ZZ, 'x') + sage: K = NumberField(x^2 - 2, 'a') # optional - sage.rings.number_field + sage: A = cm.get_action(ZZ, K, operator.mul) # optional - sage.rings.number_field sage: f, g = cm.coercion_maps(QQ, int) sage: f, g = cm.coercion_maps(ZZ, int) """ diff --git a/src/sage/structure/element.pyx b/src/sage/structure/element.pyx index e52f4665a3f..b7ee6a3a06a 100644 --- a/src/sage/structure/element.pyx +++ b/src/sage/structure/element.pyx @@ -4198,8 +4198,9 @@ cdef class FieldElement(CommutativeRingElement): EXAMPLES:: - sage: K. = NumberField(x^4 + x^2 + 2/3) - sage: c = (1+b) // (1-b); c + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^4 + x^2 + 2/3) # optional - sage.rings.number_field + sage: c = (1+b) // (1-b); c # optional - sage.rings.number_field 3/4*b^3 + 3/4*b^2 + 3/2*b + 1/2 sage: (1+b) / (1-b) == c True diff --git a/src/sage/structure/factorization.py b/src/sage/structure/factorization.py index b2caa14a285..8fa56d6bf75 100644 --- a/src/sage/structure/factorization.py +++ b/src/sage/structure/factorization.py @@ -673,8 +673,8 @@ def sort(self, key=None): We create a factored polynomial:: - sage: x = polygen(QQ,'x') - sage: F = factor(x^3 + 1); F + sage: x = polygen(QQ, 'x') + sage: F = factor(x^3 + 1); F # optional - sage.libs.pari (x + 1) * (x^2 - x + 1) We sort it by decreasing degree:: @@ -1097,8 +1097,9 @@ def __pow__(self, n): sage: f^4 2^8 * 5^8 - sage: K. = NumberField(x^3 - 39*x - 91) - sage: F = K.factor(7); F + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 - 39*x - 91) # optional - sage.rings.number_field + sage: F = K.factor(7); F # optional - sage.rings.number_field (Fractional ideal (7, a)) * (Fractional ideal (7, a + 2)) * (Fractional ideal (7, a - 2)) sage: F^9 (Fractional ideal (7, a))^9 * (Fractional ideal (7, a + 2))^9 * (Fractional ideal (7, a - 2))^9 diff --git a/src/sage/structure/nonexact.py b/src/sage/structure/nonexact.py index 4157295be90..ffb39e5f579 100644 --- a/src/sage/structure/nonexact.py +++ b/src/sage/structure/nonexact.py @@ -50,6 +50,7 @@ def default_prec(self): EXAMPLES:: + sage: x = polygen(ZZ, 'x') sage: R = QQ[[x]] sage: R.default_prec() 20 diff --git a/src/sage/structure/parent.pyx b/src/sage/structure/parent.pyx index 25c4157c3df..815420899e2 100644 --- a/src/sage/structure/parent.pyx +++ b/src/sage/structure/parent.pyx @@ -1862,8 +1862,9 @@ cdef class Parent(sage.structure.category_object.CategoryObject): EXAMPLES:: - sage: K.=NumberField(x^3+x^2+1,embedding=1) - sage: K.coerce_embedding() + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 + x^2 + 1, embedding=1) # optional - sage.rings.number_field + sage: K.coerce_embedding() # optional - sage.rings.number_field Generic morphism: From: Number Field in a with defining polynomial x^3 + x^2 + 1 with a = -1.465571231876768? To: Real Lazy Field @@ -2285,14 +2286,15 @@ cdef class Parent(sage.structure.category_object.CategoryObject): Another test:: - sage: K = NumberField([x^2-2, x^2-3], 'a,b') - sage: M = K.absolute_field('c') - sage: M_to_K, K_to_M = M.structure() - sage: M.register_coercion(K_to_M) - sage: K.register_coercion(M_to_K) - sage: phi = M.coerce_map_from(QQ) - sage: p = QQ.random_element() - sage: c = phi(p) - p; c + sage: x = polygen(ZZ, 'x') + sage: K = NumberField([x^2 - 2, x^2 - 3], 'a,b') # optional - sage.rings.number_field + sage: M = K.absolute_field('c') # optional - sage.rings.number_field + sage: M_to_K, K_to_M = M.structure() # optional - sage.rings.number_field + sage: M.register_coercion(K_to_M) # optional - sage.rings.number_field + sage: K.register_coercion(M_to_K) # optional - sage.rings.number_field + sage: phi = M.coerce_map_from(QQ) # optional - sage.rings.number_field + sage: p = QQ.random_element() # optional - sage.rings.number_field + sage: c = phi(p) - p; c # optional - sage.rings.number_field 0 sage: c.parent() is M True diff --git a/src/sage/structure/sage_object.pyx b/src/sage/structure/sage_object.pyx index eff79810b56..2140a285f2c 100644 --- a/src/sage/structure/sage_object.pyx +++ b/src/sage/structure/sage_object.pyx @@ -845,6 +845,7 @@ cdef class SageObject: This example illustrates caching, which happens automatically since K is a Python object:: + sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) sage: magma(K) is magma(K) # optional - magma True From d8a68e696651a87a543e7e477980bd0d693d9881 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 17 May 2023 21:01:26 -0700 Subject: [PATCH 25/98] Doctest fixups --- src/sage/cpython/getattr.pyx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sage/cpython/getattr.pyx b/src/sage/cpython/getattr.pyx index c670cb22d13..525ea5aa934 100644 --- a/src/sage/cpython/getattr.pyx +++ b/src/sage/cpython/getattr.pyx @@ -84,7 +84,7 @@ cdef class AttributeErrorMessage: ....: except AttributeError as exc: ....: ElementError2 = exc sage: ElementError - AttributeError('sage.symbolic.expression.Expression' object has no attribute '__bla'...) + AttributeError('sage.rings.polynomial...' object has no attribute '__bla'...) sage: ElementError2.args[0] is ElementError.args[0] True sage: isinstance(ElementError.args[0], sage.cpython.getattr.AttributeErrorMessage) @@ -407,13 +407,13 @@ def dir_with_other_class(self, *cls): Check that objects without dicts are well handled:: - sage: cython("cdef class A:\n cdef public int a") # optional - sage.misc.cython - sage: cython("cdef class B:\n cdef public int b") # optional - sage.misc.cython - sage: x = A() # optional - sage.misc.cython - sage: x.a = 1 # optional - sage.misc.cython - sage: hasattr(x,'__dict__') # optional - sage.misc.cython + sage: cython("cdef class A:\n cdef public int a") # optional - sage.misc.cython + sage: cython("cdef class B:\n cdef public int b") # optional - sage.misc.cython + sage: x = A() # optional - sage.misc.cython + sage: x.a = 1 # optional - sage.misc.cython + sage: hasattr(x,'__dict__') # optional - sage.misc.cython False - sage: dir_with_other_class(x, B) # optional - sage.misc.cython + sage: dir_with_other_class(x, B) # optional - sage.misc.cython [..., 'a', 'b'] TESTS: From 0e5eb69030637d89e0c6740fcbb8502647396e3d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 17 May 2023 21:02:44 -0700 Subject: [PATCH 26/98] polygen fixups --- src/sage/rings/number_field/number_field_rel.py | 1 - src/sage/rings/qqbar.py | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/sage/rings/number_field/number_field_rel.py b/src/sage/rings/number_field/number_field_rel.py index c623b054bff..6104d06f54f 100644 --- a/src/sage/rings/number_field/number_field_rel.py +++ b/src/sage/rings/number_field/number_field_rel.py @@ -2151,7 +2151,6 @@ def logarithmic_embedding(self, prec=53): :: - sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: t = K['t'].gen() sage: L. = K.extension(t^4 - i) diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index e336309d5d7..0a6747a57c0 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -4702,14 +4702,14 @@ def radical_expression(self): sqrt(sqrt(5) + 5) sage: QQbar.zeta(5).radical_expression() 1/4*sqrt(5) + 1/2*sqrt(-1/2*sqrt(5) - 5/2) - 1/4 - sage: x = polygen(ZZ, 'x') - sage: a = QQ[x](x^7 - x - 1).roots(AA, False)[0] - sage: a.radical_expression() + sage: x = polygen(QQ, 'x') + sage: a = (x^7 - x - 1).roots(AA, False)[0] + sage: a.radical_expression() # optional - sage.symbolic 1.112775684278706? sage: a.radical_expression().parent() == SR False - sage: a = sorted(QQ[x](x^7-x-1).roots(QQbar, False), key=imag)[0] - sage: a.radical_expression() + sage: a = sorted((x^7-x-1).roots(QQbar, False), key=imag)[0] + sage: a.radical_expression() # optional - sage.symbolic -0.3636235193291805? - 0.9525611952610331?*I sage: QQbar.zeta(5).imag().radical_expression() 1/2*sqrt(1/2*sqrt(5) + 5/2) From d9e6bb2bf7a4e4d6399e4cc5f94abd72ba626ed7 Mon Sep 17 00:00:00 2001 From: Miguel Marco Date: Thu, 18 May 2023 15:05:55 +0200 Subject: [PATCH 27/98] Fix bug caused by cached representation in cohomology classes --- src/sage/algebras/commutative_dga.py | 53 +++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/src/sage/algebras/commutative_dga.py b/src/sage/algebras/commutative_dga.py index f0bf211bfc5..f6672eea10a 100644 --- a/src/sage/algebras/commutative_dga.py +++ b/src/sage/algebras/commutative_dga.py @@ -561,7 +561,7 @@ def cohomology(self, n): H_basis = [sum(c * b for (c, b) in zip(coeffs, B)) for coeffs in H_basis_raw] # Put brackets around classes. - H_basis_brackets = [CohomologyClass(b) for b in H_basis] + H_basis_brackets = [CohomologyClass(b, A) for b in H_basis] return CombinatorialFreeModule(A.base_ring(), H_basis_brackets, sorting_key=sorting_keys, @@ -855,7 +855,7 @@ def cohomology(self, n, total=False): H_basis = [sum(c * b for (c, b) in zip(coeffs, B)) for coeffs in H_basis_raw] # Put brackets around classes. - H_basis_brackets = [CohomologyClass(b) for b in H_basis] + H_basis_brackets = [CohomologyClass(b, A) for b in H_basis] return CombinatorialFreeModule(A.base_ring(), H_basis_brackets, sorting_key=sorting_keys, @@ -3893,10 +3893,54 @@ class CohomologyClass(SageObject, CachedRepresentation): sage: CohomologyClass(3) [3] sage: A. = GradedCommutativeAlgebra(QQ, degrees = (2,2,3,3)) - sage: CohomologyClass(x^2+2*y*z) + sage: CohomologyClass(x^2+2*y*z, A) [2*y*z + x^2] + + In order for the cache to not confuse objects with the same representation, + we can pass a parent as a parameter. + + TESTS:: + + sage: A. = GradedCommutativeAlgebra(QQ) + sage: B1 = A.cdg_algebra({e5:e1*e2,e6:e3*e4}) + sage: B2 = A.cdg_algebra({e5:e1*e2,e6:e1*e2+e3*e4}) + sage: B1.minimal_model() + Commutative Differential Graded Algebra morphism: + From: Commutative Differential Graded Algebra with generators ('x1_0', 'x1_1', 'x1_2', 'x1_3', 'y1_0', 'y1_1') in degrees (1, 1, 1, 1, 1, 1) over Rational Field with differential: + x1_0 --> 0 + x1_1 --> 0 + x1_2 --> 0 + x1_3 --> 0 + y1_0 --> x1_0*x1_1 + y1_1 --> x1_2*x1_3 + To: Commutative Differential Graded Algebra with generators ('e1', 'e2', 'e3', 'e4', 'e5', 'e6') in degrees (1, 1, 1, 1, 1, 1) over Rational Field with differential: + e1 --> 0 + e2 --> 0 + e3 --> 0 + e4 --> 0 + e5 --> e1*e2 + e6 --> e3*e4 + Defn: (x1_0, x1_1, x1_2, x1_3, y1_0, y1_1) --> (e1, e2, e3, e4, e5, e6) + sage: B2.minimal_model() + Commutative Differential Graded Algebra morphism: + From: Commutative Differential Graded Algebra with generators ('x1_0', 'x1_1', 'x1_2', 'x1_3', 'y1_0', 'y1_1') in degrees (1, 1, 1, 1, 1, 1) over Rational Field with differential: + x1_0 --> 0 + x1_1 --> 0 + x1_2 --> 0 + x1_3 --> 0 + y1_0 --> x1_0*x1_1 + y1_1 --> x1_2*x1_3 + To: Commutative Differential Graded Algebra with generators ('e1', 'e2', 'e3', 'e4', 'e5', 'e6') in degrees (1, 1, 1, 1, 1, 1) over Rational Field with differential: + e1 --> 0 + e2 --> 0 + e3 --> 0 + e4 --> 0 + e5 --> e1*e2 + e6 --> e1*e2 + e3*e4 + Defn: (x1_0, x1_1, x1_2, x1_3, y1_0, y1_1) --> (e1, e2, e3, e4, e5, -e5 + e6) + """ - def __init__(self, x): + def __init__(self, x, parent = None): """ EXAMPLES:: @@ -3905,6 +3949,7 @@ def __init__(self, x): [x - 2] """ self._x = x + self._par = parent def __hash__(self): r""" From 21b6ff4ac9bccc9e8bfe6a296a7d7040401a6986 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 18 May 2023 09:45:21 -0700 Subject: [PATCH 28/98] src/sage/rings/qqbar.py: Fix up doctest --- src/sage/rings/qqbar.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index 0a6747a57c0..56186e7f8ac 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -4728,11 +4728,12 @@ def radical_expression(self): :: - sage: a = AA(sqrt(2) + 10^25) - sage: p = a.minpoly() - sage: v = a._value - sage: f = ComplexIntervalField(v.prec()) - sage: [f(b.rhs()).overlaps(f(v)) for b in SR(p).solve(x)] + sage: a = AA(sqrt(2) + 10^25) # optional - sage.symbolic + sage: p = a.minpoly() # optional - sage.symbolic + sage: v = a._value # optional - sage.symbolic + sage: f = ComplexIntervalField(v.prec()) # optional - sage.symbolic + sage: var('x') # optional - sage.symbolic + sage: [f(b.rhs()).overlaps(f(v)) for b in SR(p).solve(x)] # optional - sage.symbolic [True, True] sage: a.radical_expression() sqrt(2) + 10000000000000000000000000 From 7e22e83f5b41e8689f4b15f3d4086c8e840234a3 Mon Sep 17 00:00:00 2001 From: miguelmarco Date: Thu, 18 May 2023 19:26:13 +0200 Subject: [PATCH 29/98] style fix --- src/sage/algebras/commutative_dga.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/algebras/commutative_dga.py b/src/sage/algebras/commutative_dga.py index f6672eea10a..7e8649cc7fb 100644 --- a/src/sage/algebras/commutative_dga.py +++ b/src/sage/algebras/commutative_dga.py @@ -3940,7 +3940,7 @@ class CohomologyClass(SageObject, CachedRepresentation): Defn: (x1_0, x1_1, x1_2, x1_3, y1_0, y1_1) --> (e1, e2, e3, e4, e5, -e5 + e6) """ - def __init__(self, x, parent = None): + def __init__(self, x, parent=None): """ EXAMPLES:: From 39c09f511f41fa4d948a95e03a29af6e32b55647 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 18 May 2023 13:13:07 -0700 Subject: [PATCH 30/98] src/sage/rings/qqbar.py: Fix doctest --- src/sage/rings/qqbar.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index 56186e7f8ac..0c5ddaace47 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -4733,6 +4733,7 @@ def radical_expression(self): sage: v = a._value # optional - sage.symbolic sage: f = ComplexIntervalField(v.prec()) # optional - sage.symbolic sage: var('x') # optional - sage.symbolic + x sage: [f(b.rhs()).overlaps(f(v)) for b in SR(p).solve(x)] # optional - sage.symbolic [True, True] sage: a.radical_expression() @@ -7082,14 +7083,13 @@ def conjugate(self, n): EXAMPLES:: - sage: x = polygen(QQ, 'x') - sage: a = (x^2 + 23).roots(ring=QQbar, multiplicities=False)[0] - sage: b = a._descr - sage: type(b) + sage: a = (x^2 + 23).roots(ring=QQbar, multiplicities=False)[0] # optional - sage.symbolic + sage: b = a._descr # optional - sage.symbolic + sage: type(b) # optional - sage.symbolic - sage: c = b.conjugate(a); c + sage: c = b.conjugate(a); c # optional - sage.symbolic - sage: c.exactify() + sage: c.exactify() # optional - sage.symbolic -2*a + 1 where a^2 - a + 6 = 0 and a in 0.50000000000000000? - 2.397915761656360?*I """ if not self._complex: From 4627fbec387b8c1d3abb6906eb33d6bbe442f7da Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 18 May 2023 16:33:09 -0700 Subject: [PATCH 31/98] src/doc/en/installation/launching.rst: Document workaround for jupyter server port clash on WSL --- src/doc/en/installation/launching.rst | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/doc/en/installation/launching.rst b/src/doc/en/installation/launching.rst index 543a47463f7..33019109960 100644 --- a/src/doc/en/installation/launching.rst +++ b/src/doc/en/installation/launching.rst @@ -29,6 +29,18 @@ To start a Jupyter Notebook instead of a Sage console, run the command instead of just ``sage``. To quit the Jupyter Notebook press `` + `` twice in the console where you launched the command. +You can pass extra parameters to this command. For example, + +.. CODE-BLOCK:: bash + + sage -n jupyter --port 8899 + +will run the Jupyter server on a port different from the default (8888). +In particular on WSL, this is very useful because Jupyter may not be able to +detect whether the default port is already taken by another instance of +Jupyter running in Windows. + + Environment variables --------------------- @@ -83,7 +95,8 @@ the internet, e.g. https://www.ssh.com/ssh/tunneling/example. WSL Post-installation steps --------------------------- -If you've installed Sage Math from source on WSL, there are a couple of extra steps you can do to make your life easier: +If you've installed SageMath from source on WSL, there are a couple of extra steps you can do to make your life easier: + Create a notebook launch script """"""""""""""""""""""""""""""" From 704579fbb76d2d0b87ebd6a8f1d864e83b67fce8 Mon Sep 17 00:00:00 2001 From: miguelmarco Date: Fri, 19 May 2023 13:01:59 +0200 Subject: [PATCH 32/98] Change name of parameter from parent to cdga --- src/sage/algebras/commutative_dga.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/algebras/commutative_dga.py b/src/sage/algebras/commutative_dga.py index 7e8649cc7fb..f1148024ce2 100644 --- a/src/sage/algebras/commutative_dga.py +++ b/src/sage/algebras/commutative_dga.py @@ -3897,7 +3897,7 @@ class CohomologyClass(SageObject, CachedRepresentation): [2*y*z + x^2] In order for the cache to not confuse objects with the same representation, - we can pass a parent as a parameter. + we can pass the parent of the representative as a parameter. TESTS:: @@ -3940,7 +3940,7 @@ class CohomologyClass(SageObject, CachedRepresentation): Defn: (x1_0, x1_1, x1_2, x1_3, y1_0, y1_1) --> (e1, e2, e3, e4, e5, -e5 + e6) """ - def __init__(self, x, parent=None): + def __init__(self, x, cdga=None): """ EXAMPLES:: @@ -3949,7 +3949,7 @@ def __init__(self, x, parent=None): [x - 2] """ self._x = x - self._par = parent + self._cdga = cdga def __hash__(self): r""" From d5b094046bf213d1c77c39b1a0f4b642dd22c7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 21 May 2023 13:33:38 +0200 Subject: [PATCH 33/98] cleanup and details in finite_word.py --- src/sage/combinat/words/finite_word.py | 212 ++++++++++++------------- 1 file changed, 106 insertions(+), 106 deletions(-) diff --git a/src/sage/combinat/words/finite_word.py b/src/sage/combinat/words/finite_word.py index 148e2eb9836..d1aeb7c5b8a 100644 --- a/src/sage/combinat/words/finite_word.py +++ b/src/sage/combinat/words/finite_word.py @@ -501,18 +501,20 @@ def __pow__(self, exp): return self # infinite power of a non-empty word - fcn = lambda n: self[n % self.length()] + def fcn(n): + return self[n % self.length()] + if exp is Infinity: return self._parent.shift()(fcn) - #If exp*|self| is not an integer - length = exp* self.length() + # If exp*|self| is not an integer + length = exp * self.length() if length in ZZ and length >= 0: return self._parent(fcn, length=length) else: raise ValueError("Power of the word is not defined on the exponent {}:" " the length of the word ({}) times the exponent ({}) must" - " be a positive integer".format(exp,self.length(),exp)) + " be a positive integer".format(exp, self.length(), exp)) def length(self): r""" @@ -574,7 +576,7 @@ def content(self, n=None): from collections import Counter c = Counter(self) if n is not None: - alphabet = range(1,n+1) + alphabet = range(1, n + 1) elif not self.parent().alphabet().cardinality() == +Infinity: alphabet = self.parent().alphabet() else: @@ -616,13 +618,13 @@ def is_yamanouchi(self, n=None): """ from sage.combinat.words.word import Word if n is not None: - w = Word(self, alphabet=list(range(1,n+1))) + w = Word(self, alphabet=list(range(1, n + 1))) elif not self.parent().alphabet().cardinality() == +Infinity: w = self else: w = Word(self, alphabet=sorted(self.letters())) l = w.length() - for a in range(l-1,-1,-1): + for a in range(l - 1, -1, -1): mu = w.parent()(self[a:]).content() if not all(mu[i] >= mu[i+1] for i in range(len(mu)-1)): return False @@ -686,7 +688,7 @@ def schuetzenberger_involution(self, n=None): alphsize = parent.alphabet().cardinality() if not alphsize == +Infinity: n = max(parent.alphabet()) - elif r.length()>0: + elif r.length() > 0: n = max(w) for k in range(r.length()): w[k] = n+1 - w[k] @@ -869,7 +871,7 @@ def to_integer_list(self): """ cmp_key = self._parent.sortkey_letters ordered_alphabet = sorted(self.letters(), key=cmp_key) - index = dict((b,a) for (a,b) in enumerate(ordered_alphabet)) + index = {b: a for a, b in enumerate(ordered_alphabet)} return [index[a] for a in self] def to_ordered_set_partition(self): @@ -1579,7 +1581,7 @@ def rauzy_graph(self, n): u = w[:-1] v = w[1:] a = w[-1:] - g.add_edge(u,v,a) + g.add_edge(u, v, a) return g def reduced_rauzy_graph(self, n): @@ -1686,20 +1688,20 @@ def reduced_rauzy_graph(self, n): from copy import copy g = copy(self.rauzy_graph(n)) # Otherwise it changes the rauzy_graph function. - l = [v for v in g if g.in_degree(v)==1 and g.out_degree(v)==1] + l = [v for v in g if g.in_degree(v) == 1 == g.out_degree(v)] if g.num_verts() != 0 and len(l) == g.num_verts(): # In this case, the Rauzy graph is simply a cycle. g = DiGraph() g.allow_loops(True) g.add_vertex(self[:n]) - g.add_edge(self[:n],self[:n],self[n:n+len(l)]) + g.add_edge(self[:n], self[:n], self[n:n + len(l)]) else: g.allow_loops(True) g.allow_multiple_edges(True) for v in l: [i] = g.neighbors_in(v) [o] = g.neighbors_out(v) - g.add_edge(i,o,g.edge_label(i,v)[0]*g.edge_label(v,o)[0]) + g.add_edge(i, o, g.edge_label(i, v)[0]*g.edge_label(v, o)[0]) g.delete_vertex(v) return g @@ -1893,13 +1895,13 @@ def bispecial_factors_iterator(self, n=None): else: left_extensions = defaultdict(set) right_extensions = defaultdict(set) - for w in self.factor_iterator(n+2): + for w in self.factor_iterator(n + 2): v = w[1:-1] left_extensions[v].add(w[0]) right_extensions[v].add(w[-1]) for v in left_extensions: if (len(left_extensions[v]) > 1 and - len(right_extensions[v]) > 1): + len(right_extensions[v]) > 1): yield v def bispecial_factors(self, n=None): @@ -2064,7 +2066,7 @@ def _conjugates_list(self): [word: a] """ S = [self] - for i in range(1,self.length()): + for i in range(1, self.length()): S.append(self.conjugate(i)) return S @@ -2389,12 +2391,12 @@ def longest_common_suffix(self, other): return other iter = enumerate(zip(reversed(self), reversed(other))) - i,(b,c) = next(iter) + i, (b, c) = next(iter) if b != c: - #In this case, return the empty word + # In this case, return the empty word return self[:0] - for i,(b,c) in iter: + for i, (b, c) in iter: if b != c: return self[-i:] else: @@ -2504,14 +2506,14 @@ def is_palindrome(self, f=None): """ l = self.length() if f is None: - return self[:l//2] == self[l//2 + l%2:].reversal() + return self[:l//2] == self[l//2 + l % 2:].reversal() else: from sage.combinat.words.morphism import WordMorphism if not isinstance(f, WordMorphism): f = WordMorphism(f) if not f.is_involution(): raise ValueError("f must be an involution") - return self[:l//2 + l%2] == f(self[l//2:].reversal()) + return self[:l//2 + l % 2] == f(self[l//2:].reversal()) def lps(self, f=None, l=None): r""" @@ -2587,26 +2589,26 @@ def lps(self, f=None, l=None): word: bbabaa word: abbabaab """ - #If the length of the lps of self[:-1] is not known: + # If the length of the lps of self[:-1] is not known: if l is None: l = self.lps_lengths(f)[-1] return self[len(self)-l:] - #If l == w[:-1].length(), there is no shortcut + # If l == w[:-1].length(), there is no shortcut if self.length() == l + 1: return self.lps(f=f) - #Obtain the letter to the left (g) and to the right (d) of the - #precedent lps of self + # Obtain the letter to the left (g) and to the right (d) of the + # precedent lps of self g = self[-l-2] d = self[-1] - #If the word g*d is a `f`-palindrome, the result follows + # If the word g*d is a `f`-palindrome, the result follows if f is None: if g == d: return self[-l-2:] else: - #Otherwise, the length of the lps of self is smallest than l+2 + # Otherwise, the length of the lps of self is smallest than l+2 return self[-l-1:].lps() else: from sage.combinat.words.morphism import WordMorphism @@ -2666,20 +2668,20 @@ def palindromic_lacunas_study(self, f=None): sage: c == set([Word(), Word('ba'), Word('baba'), Word('ab'), Word('bbabaa'), Word('abbabaab')]) True """ - #Initialize the results of computations + # Initialize the results of computations palindromes = set() lengths_lps = [None] * self.length() lacunas = [] - #Initialize the first lps + # Initialize the first lps pal = self[:0] palindromes.add(pal) - #For all the non-empty prefixes of self, + # For all the non-empty prefixes of self, for i in range(self.length()): - #Compute its longest `f`-palindromic suffix using the preceding lps (pal) - pal = self[:i+1].lps(l=pal.length(),f=f) + # Compute its longest `f`-palindromic suffix using the preceding lps (pal) + pal = self[:i+1].lps(l=pal.length(), f=f) lengths_lps[i] = pal.length() @@ -2864,8 +2866,7 @@ def length_maximal_palindrome(self, j, m=None, f=None): i -= 1 if jj == 2 * i: return 0 - else: - return jj - 2*i - 1 + return jj - 2 * i - 1 def lengths_maximal_palindromes(self, f=None): r""" @@ -2911,7 +2912,7 @@ def lengths_maximal_palindromes(self, f=None): for j in range(1, 2 * len(self) + 1): if j >= k + LPC[k]: - p = self.length_maximal_palindrome((j - 1)*0.5, -(j%2), f) + p = self.length_maximal_palindrome((j - 1)*0.5, -(j % 2), f) LPC.append(p) if j + p > k + LPC[k]: k = j @@ -3004,7 +3005,7 @@ def palindromes(self, f=None): [word: , word: ab, word: abbabaab, word: ba, word: baba, word: bbabaa] """ LPS = self.lps_lengths(f) - return set(self[i-LPS[i] : i] for i in range(len(self)+1)) + return set(self[i - LPS[i]: i] for i in range(len(self) + 1)) def palindromic_complexity(self, n): r""" @@ -3026,7 +3027,7 @@ def palindromic_complexity(self, n): sage: [w.palindromic_complexity(i) for i in range(20)] [1, 2, 2, 2, 2, 0, 4, 0, 4, 0, 4, 0, 4, 0, 2, 0, 2, 0, 4, 0] """ - return len([x for x in self.palindromes() if len(x)==n]) + return len([1 for x in self.palindromes() if len(x) == n]) def palindrome_prefixes(self): r""" @@ -3159,10 +3160,10 @@ def defect(self, f=None): A = set(map(D, self.letters())) while A: x = A.pop() - if f(x) != x: # count only non f-palindromic letters + if f(x) != x: # count only non f-palindromic letters if f(x) in A: A.remove(f(x)) - g_w +=1 + g_w += 1 return self.length()+1-g_w-len(self.palindromes(f=f)) @@ -3287,8 +3288,8 @@ def palindromic_closure(self, side='right', f=None): if f is None: if side == 'right': l = self.lps().length() - #return self * self[-(l+1)::-1] - return self * self[:self.length()-l].reversal() + # return self * self[-(l+1)::-1] + return self * self[:self.length() - l].reversal() elif side == 'left': l = self.reversal().lps().length() return self[:l-1:-1] * self @@ -3411,7 +3412,7 @@ def minimal_period(self): """ if self.is_empty(): return 1 - return self.length()-self.length_border() + return self.length() - self.length_border() def order(self): r""" @@ -3438,7 +3439,7 @@ def order(self): 0 """ from sage.rings.rational import Rational - return Rational((self.length(),self.minimal_period())) + return Rational((self.length(), self.minimal_period())) def critical_exponent(self): r""" @@ -3489,8 +3490,8 @@ def critical_exponent(self): queue = [(0, 0, -1, 0)] # suffix tree vertices to visit for Depth First Search best_exp = 1 # best exponent so far while queue: - (v,i,j,l) = queue.pop() - for k in range(i,j+1): + v, i, j, l = queue.pop() + for k in range(i, j+1): if l-j+k-1 != 0: m = pft[l-j+k-2] while m > 0 and self[j-l+m] != self[k-1]: @@ -3504,7 +3505,7 @@ def critical_exponent(self): current_exp = QQ((current_pos+1, current_pos+1-m)) if current_exp > best_exp: best_exp = current_exp - for ((i,j),u) in st._transition_function[v].items(): + for ((i, j), u) in st._transition_function[v].items(): if j is None: j = self.length() queue.append((u, i, j, l+j-i+1)) @@ -3672,7 +3673,7 @@ def periods(self, divide_length=False): """ n = len(self) if divide_length: - possible = (i for i in range(1,n) if n % i == 0) + possible = (i for i in range(1, n) if not n % i) else: possible = range(1, n) return [x for x in possible if self.has_period(x)] @@ -3739,10 +3740,10 @@ def longest_common_subword(self, other): # the empty word. lcs = [[[] for _ in repeat(None, len(w2) + 1)] for j in range(2)] - for i,l1 in enumerate(self): - for j,l2 in enumerate(other): + for i, l1 in enumerate(self): + for j, l2 in enumerate(other): lcs[0][j] = max(lcs[0][j-1], lcs[1][j], - lcs[1][j-1] + ([l1] if l1==l2 else []),key=len) + lcs[1][j-1] + ([l1] if l1 == l2 else []), key=len) # Maintaining the meaning of lcs for the next loop lcs.pop(1) @@ -4029,9 +4030,9 @@ def inversions(self): """ inversion_list = [] cmp_key = self._parent.sortkey_letters - for (i1, letter1) in enumerate(self): + for i1, letter1 in enumerate(self): k1 = cmp_key(letter1) - for (i2, letter2) in enumerate(self[i1 + 1:]): + for i2, letter2 in enumerate(self[i1 + 1:]): k2 = cmp_key(letter2) if k1 > k2: inversion_list.append([i1, i1 + i2 + 1]) @@ -4087,8 +4088,8 @@ def degree(self, weights=None): for a in self: if a not in rank: rank[a] = rank_fcn(a) - deg += rank[a]+1 - elif isinstance(weights, (list,tuple)): + deg += rank[a] + 1 + elif isinstance(weights, (list, tuple)): rank = {} for a in self: if a not in rank: @@ -4212,7 +4213,7 @@ def last_position_dict(self): {'1': 3, '2': 6, '3': 5} """ d = {} - for (i, letter) in enumerate(self): + for i, letter in enumerate(self): d[letter] = i return d @@ -4357,7 +4358,7 @@ def find(self, sub, start=0, end=None): if not isinstance(sub, FiniteWord_class): try: sub = self.parent()(sub) - except (ValueError,TypeError): + except (ValueError, TypeError): return -1 p = self[start:end].first_occurrence(sub) return -1 if p is None else p+start @@ -5180,7 +5181,7 @@ def overlap_partition(self, other, delay=0, p=None, involution=None): {{-4, -2, 0, 2, 4}, {-5, -3, -1, 1, 3, 5}} """ if not isinstance(delay, (int, Integer)): - raise TypeError("delay (=%s) must be an integer"%delay) + raise TypeError("delay (=%s) must be an integer" % delay) elif delay < 0: return other.overlap_partition(self, -delay, p) @@ -5193,23 +5194,23 @@ def overlap_partition(self, other, delay=0, p=None, involution=None): elif not isinstance(p, DisjointSet_class): raise TypeError("p(=%s) is not a DisjointSet" % p) - #Join the classes of each pair of letters that are one above the other + # Join the classes of each pair of letters that are one above the other from sage.combinat.words.morphism import WordMorphism S = zip(islice(self, int(delay), None), other) if involution is None: - for (a,b) in S: + for a, b in S: p.union(a, b) elif isinstance(involution, WordMorphism): - for (a,b) in S: + for a, b in S: p.union(a, b) # take the first letter of the word p.union(involution(a)[0], involution(b)[0]) elif callable(involution): - for (a,b) in S: + for a, b in S: p.union(a, b) p.union(involution(a), involution(b)) else: - raise TypeError("involution (=%s) must be callable"%involution) + raise TypeError("involution (=%s) must be callable" % involution) return p # TODO: requires a parent with a sortkey_letters method @@ -5311,11 +5312,11 @@ def _s(self, i): # replace the unpaired subword i^a (i+1)^b # with i^b (i+1)^a - for j,p in enumerate(unpaired): + for j, p in enumerate(unpaired): if j < len(unpaired_ip): out[p] = i else: - out[p] = i+1 + out[p] = i + 1 return self.parent()(out, check=False) def _to_partition_content(self): @@ -5336,7 +5337,7 @@ def _to_partition_content(self): from sage.combinat.words.word import Word n = max(self) - ev = Word( Words(n)(self).evaluation() ) + ev = Word(Words(n)(self).evaluation()) sig = ev.reversal().standard_permutation().reduced_word() # sig is now the reverse complement of a reduced word for a minimal @@ -5610,7 +5611,7 @@ def balance(self): for i in range(1, self.length()): start = iter(self) end = iter(self) - abelian = dict(zip(alphabet, [0]*len(alphabet))) + abelian = dict(zip(alphabet, [0] * len(alphabet))) for _ in range(i): abelian[next(end)] += 1 abel_max = abelian.copy() @@ -5766,7 +5767,7 @@ def abelian_vectors(self, n): S = set() if n > self.length(): return S - rank = dict((letter,i) for i,letter in enumerate(alphabet)) + rank = {letter: i for i, letter in enumerate(alphabet)} start = iter(self) end = iter(self) abelian = [0] * size @@ -5885,7 +5886,7 @@ def sturmian_desubstitute_as_possible(self): if self.is_empty(): return self W = self.parent() - if W.alphabet().cardinality()== 2: + if W.alphabet().cardinality() == 2: alphabet = W.alphabet() else: alphabet = self.letters() @@ -5893,15 +5894,15 @@ def sturmian_desubstitute_as_possible(self): raise TypeError('your word must be defined on a binary alphabet or use at most two different letters') elif len(alphabet) < 2: return W() - word_from_letter = {l:W([l],datatype="list",check=False) for l in alphabet} + word_from_letter = {l: W([l], datatype="list", check=False) for l in alphabet} is_prefix = True current_run_length = 0 prefix_length = 0 prefix_letter = self[0] - is_isolated = {alphabet[0]:True,alphabet[1]:True} - minimal_run = {alphabet[0]:Infinity,alphabet[1]:Infinity} - maximal_run = {alphabet[0]:0,alphabet[1]:0} - runs = {alphabet[0]:[],alphabet[1]:[]} + is_isolated = {alphabet[0]: True, alphabet[1]: True} + minimal_run = {alphabet[0]: Infinity, alphabet[1]: Infinity} + maximal_run = {alphabet[0]: 0, alphabet[1]: 0} + runs = {alphabet[0]: [], alphabet[1]: []} for i in self: if is_prefix: if i == prefix_letter: @@ -5919,8 +5920,8 @@ def sturmian_desubstitute_as_possible(self): is_isolated[i] = False else: runs[previous_letter].append(current_run_length) - minimal_run[previous_letter] = min(minimal_run[previous_letter],current_run_length) - maximal_run[previous_letter] = max(maximal_run[previous_letter],current_run_length) + minimal_run[previous_letter] = min(minimal_run[previous_letter], current_run_length) + maximal_run[previous_letter] = max(maximal_run[previous_letter], current_run_length) current_run_length = 1 previous_letter = i # at this point, previous_letter is the suffix letter and current_run_length is the suffix length @@ -5930,13 +5931,13 @@ def sturmian_desubstitute_as_possible(self): return W() else: if is_isolated[alphabet[0]]: - l_isolated = alphabet[0] #the isolated letter - l_running = alphabet[1] #the running letter (non-isolated) + l_isolated = alphabet[0] # the isolated letter + l_running = alphabet[1] # the running letter (non-isolated) else: l_isolated = alphabet[1] l_running = alphabet[0] - w_isolated = word_from_letter[l_isolated] #the word associated to the isolated letter - w_running = word_from_letter[l_running] #the word associated to the running letter + w_isolated = word_from_letter[l_isolated] # the word associated to the isolated letter + w_running = word_from_letter[l_running] # the word associated to the running letter min_run = minimal_run[l_running] if (prefix_letter == l_isolated) or (prefix_length <= min_run): desubstitued_word = W() @@ -6066,17 +6067,17 @@ def is_tangent(self): """ if (self.parent().alphabet().cardinality() != 2): raise TypeError('your word must be defined on a binary alphabet') - [a,b] = self.parent().alphabet() + a, b = self.parent().alphabet() mini = 0 maxi = 0 height = 0 for i in self.sturmian_desubstitute_as_possible(): if i == a: height = height + 1 - maxi = max(maxi , height) + maxi = max(maxi, height) if i == b: height = height - 1 - mini = min(mini , height) + mini = min(mini, height) return (maxi - mini <= 2) # TODO. @@ -6291,16 +6292,15 @@ def shuffle(self, other, overlap=0): if overlap == 0: from sage.combinat.words.shuffle_product import ShuffleProduct_w1w2 return ShuffleProduct_w1w2(self, other) - else: - if any(a not in ZZ for a in self) or any(a not in ZZ for a in other): - raise ValueError("for a nonzero overlap, words must contain integers as letters") - if overlap is True: - from sage.combinat.shuffle import ShuffleProduct_overlapping - return ShuffleProduct_overlapping(self, other, self.parent()) - elif isinstance(overlap, (int,Integer)): - from sage.combinat.shuffle import ShuffleProduct_overlapping_r - return ShuffleProduct_overlapping_r(self, other, overlap, self.parent()) - raise ValueError('overlapping must be True or an integer') + if any(a not in ZZ for a in self) or any(a not in ZZ for a in other): + raise ValueError("for a nonzero overlap, words must contain integers as letters") + if overlap is True: + from sage.combinat.shuffle import ShuffleProduct_overlapping + return ShuffleProduct_overlapping(self, other, self.parent()) + elif isinstance(overlap, (int, Integer)): + from sage.combinat.shuffle import ShuffleProduct_overlapping_r + return ShuffleProduct_overlapping_r(self, other, overlap, self.parent()) + raise ValueError('overlapping must be True or an integer') def shifted_shuffle(self, other, shift=None): r""" @@ -6867,7 +6867,7 @@ def colored_vector(self, x=0, y=0, width='default', height=1, cmap='hsv', thickn ... RuntimeError: Color map __doc__ not known """ - #Recognize the color map + # Recognize the color map import matplotlib.cm as cm from matplotlib.colors import LinearSegmentedColormap as C key_error = False @@ -6883,32 +6883,32 @@ def colored_vector(self, x=0, y=0, width='default', height=1, cmap='hsv', thickn sage.misc.verbose.verbose("The possible color maps include: %s" % possibilities, level=0) raise RuntimeError("Color map %s not known" % cmap) - #Drawing the colored vector... + # Drawing the colored vector... from sage.plot.line import line from sage.plot.polygon import polygon from sage.plot.text import text - #The default width of the vector + # The default width of the vector if width == 'default': width = self.length() - #The black frame of the vector + # The black frame of the vector ymax = y + height - L = [(x,y), (x+width,y), (x+width,ymax), (x,ymax), (x,y)] - rep = line(L, rgbcolor=(0,0,0), thickness=thickness) + L = [(x, y), (x+width, y), (x+width, ymax), (x, ymax), (x, y)] + rep = line(L, rgbcolor=(0, 0, 0), thickness=thickness) - #The label + # The label if label is not None: hl = height/2.0 # height of the label rectangle ymax2 = ymax + hl - rep += text(str(label), (x+width/2.0, ymax + hl/2.0), rgbcolor=(1,0,0)) - L = [(x,ymax), (x+width,ymax), (x+width,ymax2), (x,ymax2), (x,ymax)] - rep += line(L, rgbcolor=(0,0,0), thickness=thickness) + rep += text(str(label), (x+width/2.0, ymax + hl/2.0), rgbcolor=(1, 0, 0)) + L = [(x, ymax), (x+width, ymax), (x+width, ymax2), (x, ymax2), (x, ymax)] + rep += line(L, rgbcolor=(0, 0, 0), thickness=thickness) - #base : the width of each rectangle + # base : the width of each rectangle base = width / float(self.length()) if not self.is_empty() else None - #A colored rectangle for each letter + # A colored rectangle for each letter dim = self.parent().alphabet().cardinality() if dim is Infinity: ordered_alphabet = sorted(self.letters(), @@ -6917,8 +6917,8 @@ def colored_vector(self, x=0, y=0, width='default', height=1, cmap='hsv', thickn else: ordered_alphabet = self.parent().alphabet() dim = float(self.parent().alphabet().cardinality()) - letter_to_integer_dict = dict((a, i) for (i, a) in - enumerate(ordered_alphabet)) + letter_to_integer_dict = {a: i for i, a in + enumerate(ordered_alphabet)} xp = x for a in self: i = letter_to_integer_dict[a] From 7f54e9d7861b56bbdec41e6f4689a93c50d6c51a Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Sun, 21 May 2023 13:45:26 +0200 Subject: [PATCH 34/98] Fix build with sphinx 7 Replace or remove use of deprecated stuff --- src/sage_docbuild/conf.py | 2 +- src/sage_docbuild/ext/sage_autodoc.py | 62 ++++++--------------------- 2 files changed, 14 insertions(+), 50 deletions(-) diff --git a/src/sage_docbuild/conf.py b/src/sage_docbuild/conf.py index 740a37cf86f..e2355012f00 100644 --- a/src/sage_docbuild/conf.py +++ b/src/sage_docbuild/conf.py @@ -248,7 +248,7 @@ def set_intersphinx_mappings(app, config): if os.path.isdir(os.path.join(invpath, directory)): src = os.path.join(refpath, directory) dst = os.path.join(invpath, directory, 'objects.inv') - app.config.intersphinx_mapping[src] = dst + app.config.intersphinx_mapping[directory] = (src, dst) intersphinx.normalize_intersphinx_mapping(app, config) diff --git a/src/sage_docbuild/ext/sage_autodoc.py b/src/sage_docbuild/ext/sage_autodoc.py index 14e272d992d..a6253d508fd 100644 --- a/src/sage_docbuild/ext/sage_autodoc.py +++ b/src/sage_docbuild/ext/sage_autodoc.py @@ -44,7 +44,6 @@ import sphinx from sphinx.application import Sphinx from sphinx.config import ENUM, Config -from sphinx.deprecation import RemovedInSphinx60Warning from sphinx.environment import BuildEnvironment from sphinx.ext.autodoc.importer import (get_class_members, get_object_members, import_module, import_object) @@ -56,8 +55,11 @@ from sphinx.util.inspect import (evaluate_signature, getdoc, object_description, safe_getattr, stringify_signature) from sphinx.util.typing import OptionSpec, get_type_hints, restify -from sphinx.util.typing import stringify as stringify_typehint - +try: + from sphinx.util.typing import stringify_annotation +except ImportError: + from sphinx.util.typing import stringify as stringify_annotation + # ------------------------------------------------------------------ from sage.misc.sageinspect import (sage_getdoc_original, sage_getargspec, isclassinstance, @@ -645,34 +647,6 @@ def add_content(self, more_content: Optional[StringList]) -> None: for line, src in zip(more_content.data, more_content.items): self.add_line(line, src[0], src[1]) - def get_object_members(self, want_all: bool) -> Tuple[bool, ObjectMembers]: - """Return ``(members_check_module, members)`` where ``members`` is a - list of ``(membername, member)`` pairs of the members of *self.object*. - - If *want_all* is True, return all members. Else, only return those - members given by *self.options.members* (which may also be None). - """ - warnings.warn('The implementation of Documenter.get_object_members() will be ' - 'removed from Sphinx-6.0.', RemovedInSphinx60Warning) - members = get_object_members(self.object, self.objpath, self.get_attr, self.analyzer) - if not want_all: - if not self.options.members: - return False, [] # type: ignore - # specific members given - selected = [] - for name in self.options.members: - if name in members: - selected.append((name, members[name].value)) - else: - logger.warning(__('missing attribute %s in object %s') % - (name, self.fullname), type='autodoc') - return False, selected - elif self.options.inherited_members: - return False, [(m.name, m.value) for m in members.values()] - else: - return False, [(m.name, m.value) for m in members.values() - if m.directly_defined] - def filter_members(self, members: ObjectMembers, want_all: bool ) -> List[Tuple[str, Any, bool]]: """Filter the given member list. @@ -2050,9 +2024,9 @@ def update_content(self, more_content: StringList) -> None: attrs = [repr(self.object.__name__)] for constraint in self.object.__constraints__: if self.config.autodoc_typehints_format == "short": - attrs.append(stringify_typehint(constraint, "smart")) + attrs.append(stringify_annotation(constraint, "smart")) else: - attrs.append(stringify_typehint(constraint)) + attrs.append(stringify_annotation(constraint)) if self.object.__bound__: if self.config.autodoc_typehints_format == "short": bound = restify(self.object.__bound__, "smart") @@ -2175,10 +2149,10 @@ def add_directive_header(self, sig: str) -> None: self.config.autodoc_type_aliases) if self.objpath[-1] in annotations: if self.config.autodoc_typehints_format == "short": - objrepr = stringify_typehint(annotations.get(self.objpath[-1]), + objrepr = stringify_annotation(annotations.get(self.objpath[-1]), "smart") else: - objrepr = stringify_typehint(annotations.get(self.objpath[-1])) + objrepr = stringify_annotation(annotations.get(self.objpath[-1])) self.add_line(' :type: ' + objrepr, sourcename) try: @@ -2494,16 +2468,6 @@ def get_doc(self) -> Optional[List[List[str]]]: else: return super().get_doc() # type: ignore - @property - def _datadescriptor(self) -> bool: - warnings.warn('AttributeDocumenter._datadescriptor() is deprecated.', - RemovedInSphinx60Warning) - if self.object is SLOTSATTR: - return True - else: - return False - - class RuntimeInstanceAttributeMixin(DataDocumenterMixinBase): """ Mixin for AttributeDocumenter to provide the feature for supporting runtime @@ -2756,10 +2720,10 @@ def add_directive_header(self, sig: str) -> None: self.config.autodoc_type_aliases) if self.objpath[-1] in annotations: if self.config.autodoc_typehints_format == "short": - objrepr = stringify_typehint(annotations.get(self.objpath[-1]), + objrepr = stringify_annotation(annotations.get(self.objpath[-1]), "smart") else: - objrepr = stringify_typehint(annotations.get(self.objpath[-1])) + objrepr = stringify_annotation(annotations.get(self.objpath[-1])) self.add_line(' :type: ' + objrepr, sourcename) try: @@ -2884,9 +2848,9 @@ def add_directive_header(self, sig: str) -> None: type_aliases=self.config.autodoc_type_aliases) if signature.return_annotation is not Parameter.empty: if self.config.autodoc_typehints_format == "short": - objrepr = stringify_typehint(signature.return_annotation, "smart") + objrepr = stringify_annotation(signature.return_annotation, "smart") else: - objrepr = stringify_typehint(signature.return_annotation) + objrepr = stringify_annotation(signature.return_annotation) self.add_line(' :type: ' + objrepr, sourcename) except TypeError as exc: logger.warning(__("Failed to get a function signature for %s: %s"), From 74af336f6c88f6b2e71ff62307e2cb0bb2402715 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 21 May 2023 10:27:12 -0700 Subject: [PATCH 35/98] tox.ini: In config factor -python3.x-minimal, include zlib in EXTRA_SAGE_PACKAGES --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 80b9c18cff5..cc9641a755d 100644 --- a/tox.ini +++ b/tox.ini @@ -522,7 +522,7 @@ setenv = CONFIG_CONFIGURE_ARGS_1=--with-system-python3=yes python3_spkg: CONFIG_CONFIGURE_ARGS_1=--without-system-python3 python3.8,python3.9,python3.10,python3.11,python3.12: CONFIG_CONFIGURE_ARGS_1=--with-system-python3=force --with-python=python{env:PYTHON_MAJOR}.{env:PYTHON_MINOR} - python3.8,python3.9,python3.10,python3.11,python3.12: EXTRA_SAGE_PACKAGES_5=_python{env:PYTHON_MAJOR}.{env:PYTHON_MINOR} _bootstrap liblzma bzip2 libffi libpng + python3.8,python3.9,python3.10,python3.11,python3.12: EXTRA_SAGE_PACKAGES_5=_python{env:PYTHON_MAJOR}.{env:PYTHON_MINOR} _bootstrap liblzma bzip2 libffi libpng zlib macos-python3_xcode: CONFIG_CONFIGURE_ARGS_1=--with-system-python3=force --with-python=/usr/bin/python3 macos-{python3_xcode,nohomebrew}-{python3.8}: CONFIG_CONFIGURE_ARGS_1=--with-system-python3=force --with-python=/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/{env:PYTHON_MAJOR}.{env:PYTHON_MINOR}/bin/python3 # Homebrew keg installs From 4943b7b9bd4bcb1c3a71e9d00f45407b2a9e6c66 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 21 May 2023 10:28:43 -0700 Subject: [PATCH 36/98] tox.ini: Add config factors -gcc_13, -gcc_14 --- tox.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tox.ini b/tox.ini index cc9641a755d..61717e777e7 100644 --- a/tox.ini +++ b/tox.ini @@ -547,6 +547,10 @@ setenv = gcc_11: EXTRA_SAGE_PACKAGES_2=_gcc11 gcc_12: CONFIG_CONFIGURE_ARGS_2=--with-system-gcc=force CC=gcc-12 CXX=g++-12 FC=gfortran-12 gcc_12: EXTRA_SAGE_PACKAGES_2=_gcc12 + gcc_13: CONFIG_CONFIGURE_ARGS_2=--with-system-gcc=force CC=gcc-13 CXX=g++-13 FC=gfortran-13 + gcc_13: EXTRA_SAGE_PACKAGES_2=_gcc13 + gcc_14: CONFIG_CONFIGURE_ARGS_2=--with-system-gcc=force CC=gcc-14 CXX=g++-14 FC=gfortran-14 + gcc_14: EXTRA_SAGE_PACKAGES_2=_gcc14 centos-7-devtoolset: CONFIG_CONFIGURE_ARGS_2=--with-system-gcc=force centos-7-devtoolset-gcc_9: DEVTOOLSET=9 centos-7-devtoolset-gcc_10: DEVTOOLSET=10 From 667248457ab63ad73790f6cb8c39e203618ebf07 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 21 May 2023 10:31:26 -0700 Subject: [PATCH 37/98] tox.ini: Add config factors -macos-12.3, -macos-13.3 --- tox.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tox.ini b/tox.ini index 61717e777e7..657d6ed6766 100644 --- a/tox.ini +++ b/tox.ini @@ -581,6 +581,10 @@ setenv = macos-11.3: MACOSX_DEPLOYMENT_TARGET=11.3 macos-12.1: MACOS_SDK=/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk macos-12.1: MACOSX_DEPLOYMENT_TARGET=12.1 + macos-12.3: MACOS_SDK=/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk + macos-12.3: MACOSX_DEPLOYMENT_TARGET=12.3 + macos-13.3: MACOS_SDK=/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk + macos-13.3: MACOSX_DEPLOYMENT_TARGET=13.3 # # Resulting full configuration args, including EXTRA_CONFIGURE_ARGS from the user environment # From b89d7d0bda8a4b6741f398ce60e447c13d339638 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 21 May 2023 10:43:36 -0700 Subject: [PATCH 38/98] tox.ini: Add ubuntu-mantic, linuxmint-21.2, fedora-39, slackware-15.0, opensuse-15.5 --- tox.ini | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tox.ini b/tox.ini index 657d6ed6766..fe8ae3efd1c 100644 --- a/tox.ini +++ b/tox.ini @@ -201,7 +201,7 @@ setenv = docker: BASE_TAG=latest # # https://hub.docker.com/_/ubuntu?tab=description - # as of 2023-01, latest=jammy=22.04, rolling=kinetic=22.10, devel=lunar=23.04 + # as of 2023-05, latest=jammy=22.04, rolling=lunar=23.04, devel=mantic=23.10 # ubuntu: SYSTEM=debian ubuntu: BASE_IMAGE=ubuntu @@ -222,6 +222,8 @@ setenv = ubuntu-kinetic: IGNORE_MISSING_SYSTEM_PACKAGES=yes ubuntu-lunar: BASE_TAG=lunar ubuntu-lunar: IGNORE_MISSING_SYSTEM_PACKAGES=yes + ubuntu-mantic: BASE_TAG=mantic + ubuntu-mantic: IGNORE_MISSING_SYSTEM_PACKAGES=yes # # https://hub.docker.com/_/debian # debian-bullseye does not have libgiac-dev @@ -254,9 +256,10 @@ setenv = linuxmint-20.3: BASE_IMAGE=linuxmintd/mint20.3 linuxmint-21: BASE_IMAGE=linuxmintd/mint21 linuxmint-21.1: BASE_IMAGE=linuxmintd/mint21.1 + linuxmint-21.2: BASE_IMAGE=linuxmintd/mint21.2 # # https://hub.docker.com/_/fedora - # as of 2023-01, latest=37, rawhide=38 + # as of 2023-05, latest=38, rawhide=39 fedora: SYSTEM=fedora fedora: BASE_IMAGE=fedora fedora-26: BASE_TAG=26 @@ -282,6 +285,8 @@ setenv = fedora-37: IGNORE_MISSING_SYSTEM_PACKAGES=yes fedora-38: BASE_TAG=38 fedora-38: IGNORE_MISSING_SYSTEM_PACKAGES=yes + fedora-39: BASE_TAG=39 + fedora-39: IGNORE_MISSING_SYSTEM_PACKAGES=yes # # https://hub.docker.com/r/scientificlinux/sl # @@ -323,6 +328,7 @@ setenv = slackware: SYSTEM=slackware slackware: BASE_IMAGE=vbatts/slackware slackware-14.2: BASE_TAG=14.2 + slackware-15.0: BASE_TAG=15.0 slackware-current: BASE_TAG=current slackware: IGNORE_MISSING_SYSTEM_PACKAGES=no # @@ -350,7 +356,7 @@ setenv = # # https://hub.docker.com/r/opensuse/leap # - OpenSUSE Leap 42 was superseded by the Leap 15 series. - # - As of 2022-07, latest = 15 = 15.4 + # - As of 2023-05, latest = 15 = 15.4 # https://hub.docker.com/r/opensuse/tumbleweed # - Rolling distribution # @@ -363,6 +369,7 @@ setenv = opensuse-15.2: BASE_TAG=15.2 opensuse-15.3: BASE_TAG=15.3 opensuse-15.4: BASE_TAG=15.4 + opensuse-15.5: BASE_TAG=15.5 opensuse-15: BASE_TAG=15 opensuse-tumbleweed: BASE_IMAGE=opensuse/tumbleweed opensuse-tumbleweed: IGNORE_MISSING_SYSTEM_PACKAGES=no From 5aa31016b248c469f1cad5e562594aa3f4795c28 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 21 May 2023 10:52:06 -0700 Subject: [PATCH 39/98] .github/workflows/docker.yml: Add ubuntu-mantic, linuxmint-21.2, fedora-39, opensuse-15.5-gcc_11-python3.10, debian-bullseye-i386; increase max_parallel to 30 --- .github/workflows/docker.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 04c74659c1d..af225b31aa0 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -23,6 +23,7 @@ on: "ubuntu-jammy", "ubuntu-kinetic", "ubuntu-lunar", + "ubuntu-mantic", "debian-buster", "debian-bullseye", "debian-bookworm", @@ -34,6 +35,7 @@ on: "linuxmint-20.3", "linuxmint-21", "linuxmint-21.1", + "linuxmint-21.2", "fedora-29-python3.8", "fedora-30-python3.8", "fedora-31", @@ -44,6 +46,7 @@ on: "fedora-36", "fedora-37", "fedora-38", + "fedora-39", "centos-7-devtoolset-gcc_11", "centos-stream-8-python3.9", "centos-stream-9-python3.9", @@ -53,10 +56,12 @@ on: "archlinux-latest", "opensuse-15.3-gcc_11-python3.9", "opensuse-15.4-gcc_11-python3.10", + "opensuse-15.5-gcc_11-python3.10", "opensuse-tumbleweed-python3.10", "conda-forge", "ubuntu-bionic-gcc_8-i386", "debian-buster-i386", + "debian-bullseye-i386", ] tox_packages_factors: description: 'Stringified JSON object listing tox packages factors' @@ -71,7 +76,7 @@ on: default: "" max_parallel: type: number - default: 24 + default: 30 free_disk_space: default: false type: boolean From 73f62a2fe6f643f1911c893d17ac7f9f33ad1cbd Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 21 May 2023 16:18:29 -0700 Subject: [PATCH 40/98] .github/workflows/docker.yml: Fix up opensuse-15.5 --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index af225b31aa0..c5c19f9097f 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -56,7 +56,7 @@ on: "archlinux-latest", "opensuse-15.3-gcc_11-python3.9", "opensuse-15.4-gcc_11-python3.10", - "opensuse-15.5-gcc_11-python3.10", + "opensuse-15.5-gcc_11-python3.11", "opensuse-tumbleweed-python3.10", "conda-forge", "ubuntu-bionic-gcc_8-i386", From dd71d186f17792d442df9db89ab5247799f38d93 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 22 May 2023 08:19:12 +0200 Subject: [PATCH 41/98] change_pd_convention initial version --- src/sage/knots/knotinfo.py | 26 +-- src/sage/knots/link.py | 359 ++++++++++++++++++++----------------- 2 files changed, 204 insertions(+), 181 deletions(-) diff --git a/src/sage/knots/knotinfo.py b/src/sage/knots/knotinfo.py index c6c8f554fd5..19e2589af9d 100644 --- a/src/sage/knots/knotinfo.py +++ b/src/sage/knots/knotinfo.py @@ -31,12 +31,11 @@ lines of the examples, are unnecessary. Be aware that there are a couple of conventions used differently on KnotInfo as -in Sage, especially concerning the selection of the symmetry version of the link. +in Sage. -In this context you should note that the PD notation is recorded counter -clockwise in KnotInfo (see note in :meth:`KnotInfoBase.link`). In our transition -to Sage objects this is translated (by default) in order to avoid confusion about -exchanged mirror versions. +For different conventions regarding normalization of the polynomial invariants see +the according documentation of :meth:`KnotInfoBase.homfly_polynomial`, +:meth:`KnotInfoBase.jones_polynomial` and :meth:`KnotInfoBase.alexander_polynomial`. Also, note that the braid notation is used according to Sage, even thought in the source where it is taken from, the braid generators are assumed to have a @@ -44,10 +43,6 @@ 3 of :arxiv:`Gittings, T., "Minimum Braids: A Complete Invariant of Knots and Links" `). -For different conventions regarding normalization of the polynomial invariants see -the according documentation of :meth:`KnotInfoBase.homfly_polynomial`, -:meth:`KnotInfoBase.jones_polynomial` and :meth:`KnotInfoBase.alexander_polynomial`. - Furthermore, note that not all columns available in the database are visible on the web pages (see also the related note under :meth:`KnotInfoBase.khovanov_polynomial`). It is planned to remove non-visible columns from the database in the future (see @@ -1824,14 +1819,6 @@ def link(self, use_item=db.columns().pd_notation, snappy=False): coincides with the crossing number as a topological invariant. - But attention: The convention on how the edges are - listed are opposite to each other - - - KnotInfo: counter clockwise - - Sage: clockwise - - Therefore, we take the mirror version of the ``pd_notation``! - Furthermore, note that the mirror version may depend on the used KnotInfo-notation. For instance, regarding to the knot ``5_1`` the Gauss- and the DT-notation refer to @@ -1905,7 +1892,7 @@ def link(self, use_item=db.columns().pd_notation, snappy=False): sage: K4_1 = KnotInfo.K4_1 sage: K4_1.link().pd_code() - [[4, 1, 5, 2], [8, 5, 1, 6], [6, 4, 7, 3], [2, 8, 3, 7]] + [[4, 2, 5, 1], [8, 6, 1, 5], [6, 3, 7, 4], [2, 7, 3, 8]] sage: K4_1.pd_notation() [[4, 2, 5, 1], [8, 6, 1, 5], [6, 3, 7, 4], [2, 7, 3, 8]] @@ -1931,8 +1918,7 @@ def link(self, use_item=db.columns().pd_notation, snappy=False): from sage.knots.link import Link if use_item == self.items.pd_notation: - pd_code = [[a[0], a[3], a[2], a[1]] for a in self.pd_notation()] # take mirror version, see note above - return Link(pd_code) + return Link(self.pd_notation()) elif use_item == self.items.braid_notation: return Link(self.braid()) elif use_item == self.items.name and snappy: diff --git a/src/sage/knots/link.py b/src/sage/knots/link.py index 4d845139d17..ed251cd9965 100644 --- a/src/sage/knots/link.py +++ b/src/sage/knots/link.py @@ -39,6 +39,8 @@ - Amit Jamadagni - Sebastian Oehms (October 2020, add :meth:`get_knotinfo` and :meth:`is_isotopic`) - Sebastian Oehms (May 2022): add :meth:`links_gould_polynomial` +- Sebastian Oehms (May 2023): change the convention about the ``pd_code`` from + clockwise to anti-clockwise. """ # **************************************************************************** @@ -127,7 +129,7 @@ class Link(SageObject): The diagram of the link is formed by segments that are adjacent to the crossings. Label each one of this segments with a positive number, and for each crossing, write down the four incident segments. The - order of these segments is clockwise, starting with the incoming + order of these segments is anti-clockwise, starting with the incoming undercrossing. There is no particular distinction between knots and links for @@ -189,9 +191,9 @@ class Link(SageObject): We construct the "monster" unknot using a planar code, and then construct the oriented Gauss code and braid representation:: - sage: L = Link([[3,1,2,4], [8,9,1,7], [5,6,7,3], [4,18,6,5], - ....: [17,19,8,18], [9,10,11,14], [10,12,13,11], - ....: [12,19,15,13], [20,16,14,15], [16,20,17,2]]) + sage: L = Link([[3,4,2,1], [8,7,1,9], [5,3,7,6], [4,5,6,18], + ....: [17,18,8,19], [9,14,11,10], [10,11,13,12], + ....: [12,13,15,19], [20,15,14,16], [16,2,17,20]]) sage: L.oriented_gauss_code() [[[1, -4, 3, -1, 10, -9, 6, -7, 8, 5, 4, -3, 2, -6, 7, -8, 9, -10, -5, -2]], [1, -1, 1, 1, 1, -1, -1, -1, -1, -1]] @@ -201,9 +203,9 @@ class Link(SageObject): .. PLOT:: :width: 300 px - L = Link([[3,1,2,4],[8,9,1,7],[5,6,7,3],[4,18,6,5], - [17,19,8,18],[9,10,11,14],[10,12,13,11], - [12,19,15,13],[20,16,14,15],[16,20,17,2]]) + L = Link([[3,4,2,1], [8,7,1,9], [5,3,7,6], [4,5,6,18], + [17,18,8,19], [9,14,11,10], [10,11,13,12], + [12,13,15,19], [20,15,14,16], [16,2,17,20]]) sphinx_plot(L.plot()) We construct the Ochiai unknot by using an oriented Gauss code:: @@ -212,10 +214,10 @@ class Link(SageObject): ....: -11,-16,4,3,-5,6,-9,7,-15,14,16,-10,8,9,-6,5]], ....: [-1,-1,1,1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1]]) sage: L.pd_code() - [[10, 2, 11, 1], [2, 12, 3, 11], [3, 20, 4, 21], [12, 19, 13, 20], - [21, 32, 22, 1], [31, 22, 32, 23], [9, 25, 10, 24], [4, 29, 5, 30], - [23, 30, 24, 31], [28, 14, 29, 13], [17, 14, 18, 15], [5, 17, 6, 16], - [15, 7, 16, 6], [7, 27, 8, 26], [25, 9, 26, 8], [18, 28, 19, 27]] + [[10, 1, 11, 2], [2, 11, 3, 12], [3, 21, 4, 20], [12, 20, 13, 19], + [21, 1, 22, 32], [31, 23, 32, 22], [9, 24, 10, 25], [4, 30, 5, 29], + [23, 31, 24, 30], [28, 13, 29, 14], [17, 15, 18, 14], [5, 16, 6, 17], + [15, 6, 16, 7], [7, 26, 8, 27], [25, 8, 26, 9], [18, 27, 19, 28]] .. PLOT:: :width: 300 px @@ -426,14 +428,15 @@ def arcs(self, presentation='pd'): [[-1, -2], [2, 1]] """ if presentation == 'pd': + pd_code = self.pd_code() G = DiGraph() - for e in set(flatten(self.pd_code())): + for e in set(flatten(pd_code)): G.add_vertex(e) - for cr in zip(self.pd_code(), self.orientation()): + for cr in zip(pd_code, self.orientation()): if cr[1] == 1: - G.add_edge(cr[0][1], cr[0][3]) - else: G.add_edge(cr[0][3], cr[0][1]) + else: + G.add_edge(cr[0][1], cr[0][3]) res = [] for S in G.connected_components_subgraphs(): check = S.is_directed_acyclic(certificate=True) @@ -480,7 +483,7 @@ def fundamental_group(self, presentation='wirtinger'): EXAMPLES:: - sage: L = Link([[1, 2, 3, 4], [3, 2, 1, 4]]) + sage: L = Link([[1, 4, 3, 2], [3, 4, 1, 2]]) sage: L.fundamental_group() Finitely presented group < x0, x1, x2 | x1*x0^-1*x2^-1*x0, x2*x0*x1^-1*x0^-1 > sage: L.fundamental_group('braid') @@ -519,7 +522,7 @@ def fundamental_group(self, presentation='wirtinger'): rels = [] for crossing, orientation in zip(self.pd_code(), self.orientation()): a = arcs.index([i for i in arcs if crossing[0] in i][0]) - b = arcs.index([i for i in arcs if crossing[1] in i][0]) + b = arcs.index([i for i in arcs if crossing[3] in i][0]) c = arcs.index([i for i in arcs if crossing[2] in i][0]) ela = F.gen(a) elb = F.gen(b) @@ -621,13 +624,13 @@ def braid(self): EXAMPLES:: - sage: L = Link([[2, 3, 1, 4], [4, 1, 3, 2]]) + sage: L = Link([[2, 4, 1, 3], [4, 2, 3, 1]]) sage: L.braid() s^2 sage: L = Link([[[-1, 2, -3, 1, -2, 3]], [-1, -1, -1]]) sage: L.braid() s^-3 - sage: L = Link([[1,8,2,7], [8,4,9,5], [3,9,4,10], [10,1,7,6], [5,3,6,2]]) + sage: L = Link([[1,7,2,8], [8,5,9,4], [3,10,4,9], [10,6,7,1], [5,2,6,3]]) sage: L.braid() (s0*s1^-1)^2*s1^-1 @@ -670,6 +673,7 @@ def braid(self): B = BraidGroup(2) self._braid = B.one() return self._braid + seifert_circles = self.seifert_circles() newedge = max(flatten(pd_code)) + 1 for region in self.regions(): @@ -685,21 +689,45 @@ def braid(self): newPD = [list(vertex) for vertex in pd_code] if sign(a) == 1: + # ------------------------------------------------- + # Visualize insertion of the two new crossings D, E + # \ / + # a\ /b existing edges, a down, b up + # D + # n3/ \n0 newedge + 3, newedge + # \ / + # E + # n1/ \n2 newedge + 1, newedge + 2 + # / \ + # C1 C2 existing crossings + # ------------------------------------------------- C1 = newPD[newPD.index(heads[a])] C1[C1.index(a)] = newedge + 1 C2 = newPD[newPD.index(tails[b])] C2[C2.index(b)] = newedge + 2 - newPD.append([newedge + 3, a, b, newedge]) - newPD.append([newedge + 2, newedge + 1, newedge + 3, newedge]) + newPD.append([newedge + 3, newedge, b, a]) # D + newPD.append([newedge + 2, newedge, newedge + 3, newedge + 1]) # E self._braid = Link(newPD).braid() return self._braid else: + # ------------------------------------------------- + # Visualize insertion of the two new crossings D, E + # C1 C2 existing crossings + # \ / + # n1\ /n2 newedge + 1, newedge + 2 + # D + # n3/ \n0 newedge + 3, newedge + # \ / + # E + # a/ \b existing edges, a up, b down + # / \ + # ------------------------------------------------- C1 = newPD[newPD.index(heads[-a])] C1[C1.index(-a)] = newedge + 1 C2 = newPD[newPD.index(tails[-b])] C2[C2.index(-b)] = newedge + 2 - newPD.append([newedge + 2, newedge, newedge + 3, newedge + 1]) - newPD.append([newedge + 3, newedge, -b, -a]) + newPD.append([newedge + 2, newedge +1, newedge + 3, newedge]) # D + newPD.append([newedge + 3, -a, -b, newedge]) # E self._braid = Link(newPD).braid() return self._braid @@ -708,11 +736,11 @@ def braid(self): G.add_vertices([tuple(c) for c in seifert_circles]) for i,c in enumerate(pd_code): if self.orientation()[i] == 1: - a = [x for x in seifert_circles if c[1] in x][0] + a = [x for x in seifert_circles if c[3] in x][0] b = [x for x in seifert_circles if c[0] in x][0] else: a = [x for x in seifert_circles if c[0] in x][0] - b = [x for x in seifert_circles if c[3] in x][0] + b = [x for x in seifert_circles if c[1] in x][0] G.add_edge(tuple(a), tuple(b)) # Get a simple path from a source to a sink in the digraph @@ -733,10 +761,10 @@ def braid(self): if orientation[crossing_index] == 1: b = B([1]) status[0] = crossing[2] - status[1] = crossing[3] + status[1] = crossing[1] else: b = B([-1]) - status[0] = crossing[1] + status[0] = crossing[3] status[1] = crossing[2] counter = 0 while available_crossings: @@ -748,10 +776,10 @@ def braid(self): if orientation[pd_code.index(added)] == 1: b *= B([counter + 1]) status[counter] = added[2] - status[counter + 1] = added[3] + status[counter + 1] = added[1] else: b *= B([-counter - 1]) - status[counter] = added[1] + status[counter] = added[3] status[counter + 1] = added[2] if counter > 0: counter -= 1 @@ -773,50 +801,50 @@ def _directions_of_edges(self): EXAMPLES:: - sage: L = Link([[1, 3, 2, 4], [2, 3, 1, 4]]) + sage: L = Link([[1, 4, 2, 3], [2, 4, 1, 3]]) sage: tails, heads = L._directions_of_edges() sage: tails - {1: [2, 3, 1, 4], 2: [1, 3, 2, 4], 3: [1, 3, 2, 4], 4: [2, 3, 1, 4]} + {1: [2, 4, 1, 3], 2: [1, 4, 2, 3], 3: [1, 4, 2, 3], 4: [2, 4, 1, 3]} sage: heads - {1: [1, 3, 2, 4], 2: [2, 3, 1, 4], 3: [2, 3, 1, 4], 4: [1, 3, 2, 4]} + {1: [1, 4, 2, 3], 2: [2, 4, 1, 3], 3: [2, 4, 1, 3], 4: [1, 4, 2, 3]} :: - sage: L = Link([[1,5,2,4], [5,3,6,2], [3,1,4,6]]) + sage: L = Link([[1,4,2,5], [5,2,6,3], [3,6,4,1]]) sage: tails, heads = L._directions_of_edges() sage: tails - {1: [3, 1, 4, 6], - 2: [1, 5, 2, 4], - 3: [5, 3, 6, 2], - 4: [3, 1, 4, 6], - 5: [1, 5, 2, 4], - 6: [5, 3, 6, 2]} + {1: [3, 6, 4, 1], + 2: [1, 4, 2, 5], + 3: [5, 2, 6, 3], + 4: [3, 6, 4, 1], + 5: [1, 4, 2, 5], + 6: [5, 2, 6, 3]} sage: heads - {1: [1, 5, 2, 4], - 2: [5, 3, 6, 2], - 3: [3, 1, 4, 6], - 4: [1, 5, 2, 4], - 5: [5, 3, 6, 2], - 6: [3, 1, 4, 6]} + {1: [1, 4, 2, 5], + 2: [5, 2, 6, 3], + 3: [3, 6, 4, 1], + 4: [1, 4, 2, 5], + 5: [5, 2, 6, 3], + 6: [3, 6, 4, 1]} :: - sage: L = Link([[1,2,3,3], [2,4,5,5], [4,1,7,7]]) + sage: L = Link([[1,3,3,2], [2,5,5,4], [4,7,7,1]]) sage: tails, heads = L._directions_of_edges() sage: tails - {1: [4, 1, 7, 7], - 2: [1, 2, 3, 3], - 3: [1, 2, 3, 3], - 4: [2, 4, 5, 5], - 5: [2, 4, 5, 5], - 7: [4, 1, 7, 7]} + {1: [4, 7, 7, 1], + 2: [1, 3, 3, 2], + 3: [1, 3, 3, 2], + 4: [2, 5, 5, 4], + 5: [2, 5, 5, 4], + 7: [4, 7, 7, 1]} sage: heads - {1: [1, 2, 3, 3], - 2: [2, 4, 5, 5], - 3: [1, 2, 3, 3], - 4: [4, 1, 7, 7], - 5: [2, 4, 5, 5], - 7: [4, 1, 7, 7]} + {1: [1, 3, 3, 2], + 2: [2, 5, 5, 4], + 3: [1, 3, 3, 2], + 4: [4, 7, 7, 1], + 5: [2, 5, 5, 4], + 7: [4, 7, 7, 1]} """ tails = {} heads = {} @@ -832,10 +860,10 @@ def _directions_of_edges(self): tails[a] = D if D[0] == a: a = D[2] - elif D[1] == a: - a = D[3] - else: + elif D[3] == a: a = D[1] + else: + a = D[3] else: heads[a] = next_crossing[0] tails[a] = D @@ -887,7 +915,7 @@ def _enhanced_states(self): sage: K = Link([[[1,-2,3,-1,2,-3]],[-1,-1,-1]]) sage: K.pd_code() - [[4, 2, 5, 1], [2, 6, 3, 5], [6, 4, 1, 3]] + [[4, 1, 5, 2], [2, 5, 3, 6], [6, 3, 1, 4]] sage: K._enhanced_states() (((0, 0, 0), (((1, 4, 7), (4, 1, 9)), ((2, 5, 7), (5, 2, 8)), ((3, 6, 9), (6, 3, 8))), @@ -1053,16 +1081,16 @@ def _enhanced_states(self): n = nmax + j if not v[j]: # For negative crossings, we go from undercrossings to the left - G.add_edge((cr[3], cr[0], n), cr[0]) - G.add_edge((cr[3], cr[0], n), cr[3]) - G.add_edge((cr[1], cr[2], n), cr[2]) - G.add_edge((cr[1], cr[2], n), cr[1]) + G.add_edge((cr[1], cr[0], n), cr[0]) + G.add_edge((cr[1], cr[0], n), cr[1]) + G.add_edge((cr[3], cr[2], n), cr[2]) + G.add_edge((cr[3], cr[2], n), cr[3]) else: # positive crossings, from undercrossing to the right - G.add_edge((cr[0], cr[1], n), cr[0]) - G.add_edge((cr[0], cr[1], n), cr[1]) - G.add_edge((cr[2], cr[3], n), cr[2]) - G.add_edge((cr[2], cr[3], n), cr[3]) + G.add_edge((cr[0], cr[3], n), cr[0]) + G.add_edge((cr[0], cr[3], n), cr[3]) + G.add_edge((cr[2], cr[1], n), cr[2]) + G.add_edge((cr[2], cr[1], n), cr[1]) sm = set(tuple(sorted(x for x in b if isinstance(x, tuple))) for b in G.connected_components(sort=False)) iindex = (writhe - ncross + 2 * sum(v)) // 2 @@ -1265,10 +1293,10 @@ def oriented_gauss_code(self): EXAMPLES:: - sage: L = Link([[1, 11, 2, 10], [6, 2, 7, 3], [3, 12, 4, 9], [9, 5, 10, 6], [8, 1, 5, 4], [11, 8, 12, 7]]) + sage: L = Link([[1, 10, 2, 11], [6, 3, 7, 2], [3, 9, 4, 12], [9, 6, 10, 5], [8, 4, 5, 1], [11, 7, 12, 8]]) sage: L.oriented_gauss_code() [[[-1, 2, -3, 5], [4, -2, 6, -5], [-4, 1, -6, 3]], [-1, 1, 1, 1, -1, -1]] - sage: L = Link([[1, 4, 2, 3], [6, 1, 3, 2], [7, 4, 8, 5], [5, 8, 6, 7]]) + sage: L = Link([[1, 3, 2, 4], [6, 2, 3, 1], [7, 5, 8, 4], [5, 7, 6, 8]]) sage: L.oriented_gauss_code() [[[-1, 2], [-3, 4], [1, 3, -4, -2]], [-1, -1, 1, 1]] sage: B = BraidGroup(8) @@ -1295,10 +1323,10 @@ def oriented_gauss_code(self): for i, j in enumerate(pd): if orient[i] == -1: crossing_info[(j[0], -1, i + 1)] = j[2] - crossing_info[(j[3], 1, i + 1)] = j[1] + crossing_info[(j[1], 1, i + 1)] = j[3] elif orient[i] == 1: crossing_info[(j[0], -1, i + 1)] = j[2] - crossing_info[(j[1], 1, i + 1)] = j[3] + crossing_info[(j[3], 1, i + 1)] = j[1] edges = {} cross_number = {} for i, j in crossing_info.items(): @@ -1327,27 +1355,34 @@ def pd_code(self): The planar diagram is returned in the following format. We construct the crossing by starting with the entering component - of the undercrossing, move in the clockwise direction and then - generate the list. If the crossing is given by `[a, b, c, d]`, - then we interpret this information as: + of the undercrossing, move in the anti-clockwise direction (see the + note below) and then generate the list. If the crossing is given by + `[a, b, c, d]`, then we interpret this information as: 1. `a` is the entering component of the undercrossing; 2. `b, d` are the components of the overcrossing; 3. `c` is the leaving component of the undercrossing. + .. NOTE:: + + Until version 10.0 the convention to read the ``PD`` code has been + to list the components in clockwise direction. As of version 10.1 + the convention has changed, since it was opposite to the usage in + most other places. + EXAMPLES:: sage: L = Link([[[1, -2, 3, -4, 2, -1, 4, -3]], [1, 1, -1, -1]]) sage: L.pd_code() - [[6, 1, 7, 2], [2, 5, 3, 6], [8, 4, 1, 3], [4, 8, 5, 7]] + [[6, 2, 7, 1], [2, 6, 3, 5], [8, 3, 1, 4], [4, 7, 5, 8]] sage: B = BraidGroup(2) sage: b = B([1, 1, 1, 1, 1]) sage: L = Link(b) sage: L.pd_code() - [[2, 1, 3, 4], [4, 3, 5, 6], [6, 5, 7, 8], [8, 7, 9, 10], [10, 9, 1, 2]] + [[2, 4, 3, 1], [4, 6, 5, 3], [6, 8, 7, 5], [8, 10, 9, 7], [10, 2, 1, 9]] sage: L = Link([[[2, -1], [1, -2]], [1, 1]]) sage: L.pd_code() - [[2, 3, 1, 4], [4, 1, 3, 2]] + [[2, 4, 1, 3], [4, 2, 3, 1]] sage: L = Link([[1, 2, 3, 3], [2, 4, 5, 5], [4, 1, 7, 7]]) sage: L.pd_code() [[1, 2, 3, 3], [2, 4, 5, 5], [4, 1, 7, 7]] @@ -1380,11 +1415,11 @@ def pd_code(self): crossing_dic = {} for i,x in enumerate(oriented_gauss_code[1]): if x == -1: - crossing_dic[i + 1] = [d_dic[-(i + 1)][0], d_dic[i + 1][1], - d_dic[-(i + 1)][1], d_dic[i + 1][0]] - elif x == 1: crossing_dic[i + 1] = [d_dic[-(i + 1)][0], d_dic[i + 1][0], d_dic[-(i + 1)][1], d_dic[i + 1][1]] + elif x == 1: + crossing_dic[i + 1] = [d_dic[-(i + 1)][0], d_dic[i + 1][1], + d_dic[-(i + 1)][1], d_dic[i + 1][0]] elif len(oriented_gauss_code[0]) == 1: for i, j in enumerate(oriented_gauss_code[0][0]): d_dic[j] = [i + 1, i + 2] @@ -1392,11 +1427,11 @@ def pd_code(self): crossing_dic = {} for i, x in enumerate(oriented_gauss_code[1]): if x == -1: - crossing_dic[i + 1] = [d_dic[-(i + 1)][0], d_dic[i + 1][1], - d_dic[-(i + 1)][1], d_dic[i + 1][0]] - elif x == 1: crossing_dic[i + 1] = [d_dic[-(i + 1)][0], d_dic[i + 1][0], d_dic[-(i + 1)][1], d_dic[i + 1][1]] + elif x == 1: + crossing_dic[i + 1] = [d_dic[-(i + 1)][0], d_dic[i + 1][1], + d_dic[-(i + 1)][1], d_dic[i + 1][0]] else: crossing_dic = {} @@ -1412,10 +1447,10 @@ def pd_code(self): for i in b: if i > 0: pd.append( - [strings[i], strings[i - 1], strings_max + 1, strings_max + 2]) + [strings[i], strings_max + 2, strings_max + 1, strings[i - 1]]) else: pd.append( - [strings[abs(i) - 1], strings_max + 1, strings_max + 2, strings[abs(i)]]) + [strings[abs(i) - 1], strings[abs(i)], strings_max + 2, strings_max + 1]) strings[abs(i) - 1] = strings_max + 1 strings[abs(i)] = strings_max + 2 strings_max = strings_max + 2 @@ -1485,7 +1520,7 @@ def dowker_notation(self): """ pd = self.pd_code() orient = self.orientation() - dn = [(i[0], i[3]) if orient[j] == -1 else (i[0], i[1]) + dn = [(i[0], i[1]) if orient[j] == -1 else (i[0], i[3]) for j, i in enumerate(pd)] return dn @@ -1690,7 +1725,7 @@ def number_of_components(self): G.add_vertices(set(flatten(pd))) for c in pd: G.add_edge(c[0], c[2]) - G.add_edge(c[1], c[3]) + G.add_edge(c[3], c[1]) return G.connected_components_number() def is_knot(self): @@ -2130,24 +2165,24 @@ def orientation(self): EXAMPLES:: - sage: L = Link([[1, 4, 5, 2], [3, 5, 6, 7], [4, 8, 9, 6], [7, 9, 10, 11], [8, 1, 13, 10], [11, 13, 2, 3]]) + sage: L = Link([[1, 2, 5, 4], [3, 7, 6, 5], [4, 6, 9, 8], [7, 11, 10, 9], [8, 10, 13, 1], [11, 3, 2, 13]]) sage: L.orientation() [-1, 1, -1, 1, -1, 1] - sage: L = Link([[1, 7, 2, 6], [7, 3, 8, 2], [3, 11, 4, 10], [11, 5, 12, 4], [14, 5, 1, 6], [13, 9, 14, 8], [12, 9, 13, 10]]) + sage: L = Link([[1, 6, 2, 7], [7, 2, 8, 3], [3, 10, 4, 11], [11, 4, 12, 5], [14, 6, 1, 5], [13, 8, 14, 9], [12, 10, 13, 9]]) sage: L.orientation() [-1, -1, -1, -1, 1, -1, 1] - sage: L = Link([[1, 2, 3, 3], [2, 4, 5, 5], [4, 1, 7, 7]]) + sage: L = Link([[1, 3, 3, 2], [2, 5, 5, 4], [4, 7, 7, 1]]) sage: L.orientation() [-1, -1, -1] """ directions = self._directions_of_edges()[0] orientation = [] for C in self.pd_code(): - if C[0] == C[1] or C[2] == C[3]: + if C[0] == C[3] or C[2] == C[1]: orientation.append(-1) - elif C[1] == C[2] or C[0] == C[3]: + elif C[3] == C[2] or C[0] == C[1]: orientation.append(1) - elif directions[C[1]] == C: + elif directions[C[3]] == C: orientation.append(-1) else: orientation.append(1) @@ -2193,11 +2228,12 @@ def seifert_circles(self): sage: A.seifert_circles() [[3], [7], [1, 5], [2, 4], [6, 8]] """ - available_segments = set(flatten(self.pd_code())) + pd = self.pd_code() + available_segments = set(flatten(pd)) result = [] # detect looped segments. They must be their own seifert circles for a in available_segments: - if any(C.count(a) > 1 for C in self.pd_code()): + if any(C.count(a) > 1 for C in pd): result.append([a]) # remove the looped segments from the available for a in result: @@ -2212,11 +2248,11 @@ def seifert_circles(self): par = [] while a not in par: par.append(a) - posnext = C[(C.index(a) + 1) % 4] + posnext = C[(C.index(a) - 1) % 4] if tails[posnext] == C and not [posnext] in result: a = posnext else: - a = C[(C.index(a) - 1) % 4] + a = C[(C.index(a) + 1) % 4] if a in available_segments: available_segments.remove(a) C = heads[a] @@ -2251,7 +2287,7 @@ def regions(self): sage: L = Link([[[1, -2, 3, -4], [-1, 5, -3, 2, -5, 4]], [-1, 1, 1, -1, -1]]) sage: L.regions() [[10, -4, -7], [9, 7, -3], [8, 3], [6, -9, -2], [5, 2, -8, 4], [1, -5], [-1, -10, -6]] - sage: L = Link([[1, 2, 3, 3], [2, 5, 4, 4], [5, 7, 6, 6], [7, 1, 8, 8]]) + sage: L = Link([[1, 3, 3, 2], [2, 4, 4, 5], [5, 6, 6, 7], [7, 8, 8, 1]]) sage: L.regions() [[-3], [-4], [-6], [-8], [7, 1, 2, 5], [-1, 8, -7, 6, -5, 4, -2, 3]] @@ -2274,7 +2310,7 @@ def regions(self): raise NotImplementedError("can only have one isolated component") pd = self.pd_code() if len(pd) == 1: - if pd[0][0] == pd[0][1]: + if pd[0][0] == pd[0][3]: return [[-pd[0][2]], [pd[0][0]], [pd[0][2], -pd[0][0]]] else: return [[pd[0][2]], [-pd[0][0]], [-pd[0][2], pd[0][0]]] @@ -2288,7 +2324,7 @@ def regions(self): for edge in loops: cros = heads[edge] - if cros[1] == edge: + if cros[3] == edge: regions.append([edge]) else: regions.append([-edge]) @@ -2307,13 +2343,13 @@ def regions(self): else: cros = tails[-edge] ind = cros.index(-edge) - next_edge = cros[(ind + 1) % 4] + next_edge = cros[(ind - 1) % 4] if [next_edge] in regions: region.append(-next_edge) - next_edge = cros[(ind - 1) % 4] + next_edge = cros[(ind + 1) % 4] elif [-next_edge] in regions: region.append(next_edge) - next_edge = cros[(ind - 1) % 4] + next_edge = cros[(ind + 1) % 4] if tails[next_edge] == cros: edge = next_edge else: @@ -2357,9 +2393,9 @@ def mirror_image(self): sage: K2 = K.mirror_image(); K2 Knot represented by 3 crossings sage: K.pd_code() - [[4, 1, 5, 2], [2, 5, 3, 6], [6, 3, 1, 4]] - sage: K2.pd_code() [[4, 2, 5, 1], [2, 6, 3, 5], [6, 4, 1, 3]] + sage: K2.pd_code() + [[4, 1, 5, 2], [2, 5, 3, 6], [6, 3, 1, 4]] .. PLOT:: :width: 300 px @@ -2429,9 +2465,9 @@ def reverse(self): a non reversable knot:: - sage: K8_17 = Knot([[6, 2, 7, 1], [14, 8, 15, 7], [8, 3, 9, 4], - ....: [2, 13, 3, 14], [12, 5, 13, 6], [4, 9, 5, 10], - ....: [16, 12, 1, 11], [10, 16, 11, 15]]) + sage: K8_17 = Knot([[6, 1, 7, 2], [14, 7, 15, 8], [8, 4, 9, 3], + ....: [2, 14, 3, 13], [12, 6, 13, 5], [4, 10, 5, 9], + ....: [16, 11, 1, 12], [10, 15, 11, 16]]) sage: K8_17r = K8_17.reverse() sage: b = K8_17.braid(); b s0^2*s1^-1*(s1^-1*s0)^2*s1^-1 @@ -2708,7 +2744,7 @@ def _bracket(self): if not pd_code: return t.parent().one() if len(pd_code) == 1: - if pd_code[0][0] == pd_code[0][1]: + if pd_code[0][0] == pd_code[0][3]: return -t**(-3) else: return -t**3 @@ -2716,42 +2752,42 @@ def _bracket(self): cross = pd_code[0] rest = [list(vertex) for vertex in pd_code[1:]] [a, b, c, d] = cross - if a == b and c == d and len(rest) > 0: + if a == d and c == b and len(rest) > 0: return (~t + t**(-5)) * Link(rest)._bracket() - elif a == d and c == b and len(rest) > 0: + elif a == b and c == d and len(rest) > 0: return (t + t**5) * Link(rest)._bracket() - elif a == b: + elif a == d: for cross in rest: - if d in cross: - cross[cross.index(d)] = c + if b in cross: + cross[cross.index(b)] = c return -t**(-3) * Link(rest)._bracket() - elif a == d: + elif a == b: for cross in rest: if c in cross: - cross[cross.index(c)] = b - return -t**3 * Link(rest)._bracket() - elif c == b: - for cross in rest: - if d in cross: - cross[cross.index(d)] = a + cross[cross.index(c)] = d return -t**3 * Link(rest)._bracket() elif c == d: for cross in rest: if b in cross: cross[cross.index(b)] = a + return -t**3 * Link(rest)._bracket() + elif c == b: + for cross in rest: + if d in cross: + cross[cross.index(d)] = a return -t**(-3) * Link(rest)._bracket() else: rest_2 = [list(vertex) for vertex in rest] for cross in rest: - if d in cross: - cross[cross.index(d)] = a + if b in cross: + cross[cross.index(b)] = a if c in cross: - cross[cross.index(c)] = b + cross[cross.index(c)] = d for cross in rest_2: - if d in cross: - cross[cross.index(d)] = c if b in cross: - cross[cross.index(b)] = a + cross[cross.index(b)] = c + if d in cross: + cross[cross.index(d)] = a return t * Link(rest)._bracket() + ~t * Link(rest_2)._bracket() @cached_method @@ -2834,7 +2870,7 @@ def homfly_polynomial(self, var1=None, var2=None, normalization='lm'): The Hopf link:: - sage: L = Link([[1,3,2,4],[4,2,3,1]]) + sage: L = Link([[1,4,2,3],[4,1,3,2]]) sage: L.homfly_polynomial('x', 'y') -x^-1*y + x^-1*y^-1 + x^-3*y^-1 @@ -2842,16 +2878,16 @@ def homfly_polynomial(self, var1=None, var2=None, normalization='lm'): has been changed. Therefore we substitute `x \mapsto L^{-1}` and `y \mapsto M`:: - sage: L = Link([[1,4,2,3], [4,1,3,2]]) + sage: L = Link([[1,3,2,4], [4,2,3,1]]) sage: L.homfly_polynomial() L^3*M^-1 - L*M + L*M^-1 - sage: L = Link([[1,4,2,3], [4,1,3,2]]) + sage: L = Link([[1,3,2,4], [4,2,3,1]]) sage: L.homfly_polynomial(normalization='az') a^3*z^-1 - a*z - a*z^-1 The figure-eight knot:: - sage: L = Link([[2,1,4,5], [5,6,7,3], [6,4,1,9], [9,2,3,7]]) + sage: L = Link([[2,5,4,1], [5,3,7,6], [6,9,1,4], [9,7,3,2]]) sage: L.homfly_polynomial() -L^2 + M^2 - 1 - L^-2 sage: L.homfly_polynomial('a', 'z', 'az') @@ -2888,7 +2924,7 @@ def homfly_polynomial(self, var1=None, var2=None, normalization='lm'): This works with isolated components:: sage: L = Link([[[1, -1], [2, -2]], [1, 1]]) - sage: L2 = Link([[1, 3, 2, 4], [2, 3, 1, 4]]) + sage: L2 = Link([[1, 4, 2, 3], [2, 4, 1, 3]]) sage: L2.homfly_polynomial() -L*M^-1 - L^-1*M^-1 sage: L.homfly_polynomial() @@ -2989,7 +3025,7 @@ def links_gould_polynomial(self, varnames='t0, t1'): EXAMPLES:: - sage: Hopf = Link([[1, 4, 2, 3], [4, 1, 3, 2]]) + sage: Hopf = Link([[1, 3, 2, 4], [4, 2, 3, 1]]) sage: Hopf.links_gould_polynomial() -1 + t1^-1 + t0^-1 - t0^-1*t1^-1 """ @@ -3044,7 +3080,7 @@ def _coloring_matrix(self, n): crossing = crossings[i] for j in range(di): arc = arcs[j] - if crossing[1] in arc: + if crossing[3] in arc: M[i, j] += 2 if crossing[0] in arc: M[i, j] -= 1 @@ -3120,7 +3156,7 @@ def colorings(self, n): {(1, 2): 2, (3, 4): 0, (5, 6): 1}, {(1, 2): 2, (3, 4): 1, (5, 6): 0}] sage: K.pd_code() - [[4, 1, 5, 2], [2, 5, 3, 6], [6, 3, 1, 4]] + [[4, 2, 5, 1], [2, 6, 3, 5], [6, 4, 1, 3]] sage: K.arcs('pd') [[1, 2], [3, 4], [5, 6]] @@ -3321,8 +3357,9 @@ def plot(self, gap=0.1, component_gap=0.5, solver=None, sage: L.plot(solver='Gurobi') # optional - Gurobi Graphics object consisting of ... graphics primitives """ + pd_code = self.pd_code() if type(color) is not dict: - coloring = {int(i): color for i in set(flatten(self.pd_code()))} + coloring = {int(i): color for i in set(flatten(pd_code))} else: from sage.plot.colors import rainbow ncolors = len(set(color.values())) @@ -3359,7 +3396,7 @@ def plot(self, gap=0.1, component_gap=0.5, solver=None, from sage.plot.circle import circle # Special case for the unknot - if not self.pd_code(): + if not pd_code: return circle((0,0), ZZ(1)/ZZ(2), color=color, **kwargs) # The idea is the same followed in spherogram, but using MLP instead of @@ -3369,7 +3406,7 @@ def plot(self, gap=0.1, component_gap=0.5, solver=None, # with straight angles, and using the minimal number of bends. regions = sorted(self.regions(), key=len) regions = regions[:-1] - edges = list(set(flatten(self.pd_code()))) + edges = list(set(flatten(pd_code))) edges.sort() MLP = MixedIntegerLinearProgram(maximization=False, solver=solver) # v will be the list of variables in the MLP problem. There will be @@ -3493,8 +3530,8 @@ def plot(self, gap=0.1, component_gap=0.5, solver=None, v = MLP.get_values(v) lengths = {piece: sum(v[a] for a in pieces[piece]) for piece in pieces} image = line([], **kwargs) - crossings = {tuple(self.pd_code()[0]): (0, 0, 0)} - availables = self.pd_code()[1:] + crossings = {tuple(pd_code[0]): (0, 0, 0)} + availables = pd_code[1:] used_edges = [] ims = line([], **kwargs) while len(used_edges) < len(edges): @@ -3511,14 +3548,14 @@ def plot(self, gap=0.1, component_gap=0.5, solver=None, e = c[j] kwargs['color'] = coloring[e] used_edges.append(e) - direction = (crossings[c][2] - c.index(e)) % 4 - orien = self.orientation()[self.pd_code().index(list(c))] + direction = (crossings[c][2] + c.index(e)) % 4 + orien = self.orientation()[pd_code.index(list(c))] if s[edges.index(e)] < 0: turn = -1 else: turn = 1 lengthse = [lengths[(e,k)] for k in range(abs(s[edges.index(e)])+1)] - if c.index(e) == 0 or (c.index(e) == 1 and orien == 1) or (c.index(e) == 3 and orien == -1): + if c.index(e) == 0 or (c.index(e) == 3 and orien == 1) or (c.index(e) == 1 and orien == -1): turn = -turn lengthse.reverse() tailshort = (c.index(e) % 2 == 0) @@ -3546,8 +3583,8 @@ def plot(self, gap=0.1, component_gap=0.5, solver=None, c2 = [ee for ee in availables if e in ee] if len(c2) == 1: availables.remove(c2[0]) - crossings[tuple(c2[0])] = (x1, y1, (direction + c2[0].index(e) + 2) % 4) - c2 = [ee for ee in self.pd_code() if e in ee and ee != list(c)] + crossings[tuple(c2[0])] = (x1, y1, (direction - c2[0].index(e) + 2) % 4) + c2 = [ee for ee in pd_code if e in ee and ee != list(c)] if not c2: headshort = not tailshort else: @@ -3612,6 +3649,7 @@ def delta(u, v): ims += sum(line(a[0], **kwargs) for a in im) return image + def _markov_move_cmp(self, braid): r""" Return whether ``self`` can be transformed to the closure of ``braid`` @@ -3631,9 +3669,9 @@ def _markov_move_cmp(self, braid): EXAMPLES:: sage: b = BraidGroup(4)((1, 2, -3, 2, 2, 2, 2, 2, 2, -1, 2, 3, 2)) - sage: L = Link([[2, 1, 4, 5], [5, 4, 6, 7], [7, 6, 8, 9], [9, 8, 10, 11], - ....: [11, 10, 12, 13], [13, 12, 14, 15], [15, 14, 16, 17], - ....: [3, 17, 18, 19], [16, 1, 21, 18], [19, 21, 2, 3]]) + sage: L = Link([[2, 5, 4, 1], [5, 7, 6, 4], [7, 9, 8, 6], [9, 11, 10, 8], + ....: [11, 13, 12, 10], [13, 15, 14, 12], [15, 17, 16, 14], + ....: [3, 19, 18, 17], [16, 18, 21, 1], [19, 3, 2, 21]]) sage: L._markov_move_cmp(b) # both are isotopic to ``9_3`` True sage: bL = L.braid(); bL @@ -3711,7 +3749,8 @@ def _knotinfo_matching_list(self): """ from sage.knots.knotinfo import KnotInfoSeries - cr = len(self.pd_code()) + pd_code = self.pd_code() + cr = len(pd_code) co = self.number_of_components() # set the limits for the KnotInfoSeries @@ -3749,16 +3788,12 @@ def _knotinfo_matching_list(self): ln = Sn.lower_list(oriented=True, comp=co, det=det, homfly=Hp) l = sorted(list(set(la + ln))) - pdm = [[a[0], a[3], a[2], a[1]] for a in self.pd_code() ] br = self.braid() br_ind = br.strands() res = [] for L in l: - if L.pd_notation() == pdm: - # note that KnotInfo pd_notation works counter clockwise. Therefore, - # to compensate this we compare with the mirrored pd_code. See also, - # docstring of :meth:`link` of :class:`~sage.knots.knotinfo.KnotInfoBase`. + if L.pd_notation() == pd_code: return [L], True # pd_notation is unique in the KnotInfo database if L.braid_index() <= br_ind: @@ -3824,9 +3859,9 @@ def get_knotinfo(self, mirror_version=True, unique=True): EXAMPLES:: sage: from sage.knots.knotinfo import KnotInfo - sage: L = Link([[4,2,5,1], [10,3,11,4], [5,16,6,17], [7,12,8,13], - ....: [18,9,19,10], [2,11,3,12], [13,20,14,21], [15,6,16,7], - ....: [22,18,1,17], [8,19,9,20], [21,14,22,15]]) + sage: L = Link([[4,1,5,2], [10,4,11,3], [5,17,6,16], [7,13,8,12], + ....: [18,10,19,9], [2,12,3,11], [13,21,14,20], [15,7,16,6], + ....: [22,17,1,18], [8,20,9,19], [21,15,22,14]]) sage: L.get_knotinfo() # optional - database_knotinfo (, True) @@ -3845,7 +3880,7 @@ def get_knotinfo(self, mirror_version=True, unique=True): ... NotImplementedError: this knot having more than 12 crossings cannot be determined - sage: Link([[1, 5, 2, 4], [3, 1, 4, 8], [5, 3, 6, 2], [6, 9, 7, 10], [10, 7, 9, 8]]) + sage: Link([[1, 4, 2, 5], [3, 8, 4, 1], [5, 2, 6, 3], [6, 10, 7, 9], [10, 8, 9, 7]]) Link with 2 components represented by 5 crossings sage: _.get_knotinfo() Traceback (most recent call last): @@ -4082,6 +4117,7 @@ def answer_list(l): raise NotImplementedError('this link cannot be uniquely determined%s' %non_unique_hint) + self_m = self.mirror_image() ls, proved_s = self._knotinfo_matching_list() lm, proved_m = self_m._knotinfo_matching_list() @@ -4128,6 +4164,7 @@ def answer_list(l): return answer_list(l) + def is_isotopic(self, other): r""" Check whether ``self`` is isotopic to ``other``. From ff44af34b48fc447b4be591da407a660230899f9 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 22 May 2023 18:32:15 +0200 Subject: [PATCH 42/98] 35665: add some docs and fix pycodestyle --- src/sage/knots/link.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/sage/knots/link.py b/src/sage/knots/link.py index ed251cd9965..260022d05b7 100644 --- a/src/sage/knots/link.py +++ b/src/sage/knots/link.py @@ -40,7 +40,7 @@ - Sebastian Oehms (October 2020, add :meth:`get_knotinfo` and :meth:`is_isotopic`) - Sebastian Oehms (May 2022): add :meth:`links_gould_polynomial` - Sebastian Oehms (May 2023): change the convention about the ``pd_code`` from - clockwise to anti-clockwise. + clockwise to anti-clockwise (see :trac:`35665`). """ # **************************************************************************** @@ -1368,7 +1368,10 @@ def pd_code(self): Until version 10.0 the convention to read the ``PD`` code has been to list the components in clockwise direction. As of version 10.1 the convention has changed, since it was opposite to the usage in - most other places. + most other places. + + Thus, if you use ``PD`` codes from former Sage releases with this + version you should check for the correct mirror type. EXAMPLES:: From 0d962f68f16d063b630c97dbe5569f524c8472bd Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Mon, 22 May 2023 23:43:42 +0200 Subject: [PATCH 43/98] Spacing --- src/sage_docbuild/ext/sage_autodoc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage_docbuild/ext/sage_autodoc.py b/src/sage_docbuild/ext/sage_autodoc.py index a6253d508fd..6c6e601614b 100644 --- a/src/sage_docbuild/ext/sage_autodoc.py +++ b/src/sage_docbuild/ext/sage_autodoc.py @@ -55,11 +55,12 @@ from sphinx.util.inspect import (evaluate_signature, getdoc, object_description, safe_getattr, stringify_signature) from sphinx.util.typing import OptionSpec, get_type_hints, restify + try: from sphinx.util.typing import stringify_annotation except ImportError: from sphinx.util.typing import stringify as stringify_annotation - + # ------------------------------------------------------------------ from sage.misc.sageinspect import (sage_getdoc_original, sage_getargspec, isclassinstance, From 2dcc37915dd26485348a98442e4759aab4c3ca00 Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Mon, 22 May 2023 23:45:57 +0200 Subject: [PATCH 44/98] Sync get_object_members in Documenter class with upstream --- src/sage_docbuild/ext/sage_autodoc.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sage_docbuild/ext/sage_autodoc.py b/src/sage_docbuild/ext/sage_autodoc.py index 6c6e601614b..cdea4999bfe 100644 --- a/src/sage_docbuild/ext/sage_autodoc.py +++ b/src/sage_docbuild/ext/sage_autodoc.py @@ -648,6 +648,15 @@ def add_content(self, more_content: Optional[StringList]) -> None: for line, src in zip(more_content.data, more_content.items): self.add_line(line, src[0], src[1]) + def get_object_members(self, want_all: bool) -> tuple[bool, ObjectMembers]: + """Return `(members_check_module, members)` where `members` is a + list of `(membername, member)` pairs of the members of *self.object*. + + If *want_all* is True, return all members. Else, only return those + members given by *self.options.members* (which may also be None). + """ + raise NotImplementedError('must be implemented in subclasses') + def filter_members(self, members: ObjectMembers, want_all: bool ) -> List[Tuple[str, Any, bool]]: """Filter the given member list. From 0daa2b9c24a4b24f5f3e43a6f0c2e4617dcdde7c Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Mon, 22 May 2023 23:52:42 +0200 Subject: [PATCH 45/98] Remove no longer relevant comment --- src/sage_docbuild/conf.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/sage_docbuild/conf.py b/src/sage_docbuild/conf.py index e2355012f00..5d16b48a73b 100644 --- a/src/sage_docbuild/conf.py +++ b/src/sage_docbuild/conf.py @@ -238,8 +238,6 @@ def set_intersphinx_mappings(app, config): app.config.intersphinx_mapping['sagemath'] = (refpath, dst) # Add intersphinx mapping for subdirectories - # We intentionally do not name these such that these get higher - # priority in case of conflicts for directory in os.listdir(os.path.join(invpath)): if directory == 'jupyter_execute': # This directory is created by jupyter-sphinx extension for From 7f46a8d972d15ebd724a44d77b191145e240932b Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Tue, 23 May 2023 09:38:09 +0200 Subject: [PATCH 46/98] Use old Tuple type annotation --- src/sage_docbuild/ext/sage_autodoc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage_docbuild/ext/sage_autodoc.py b/src/sage_docbuild/ext/sage_autodoc.py index cdea4999bfe..f9e97070eb2 100644 --- a/src/sage_docbuild/ext/sage_autodoc.py +++ b/src/sage_docbuild/ext/sage_autodoc.py @@ -38,6 +38,7 @@ from types import ModuleType from typing import (TYPE_CHECKING, Any, Callable, Dict, Iterator, List, Optional, Sequence, Set, Tuple, Type, TypeVar, Union) +from __future__ import annotations from docutils.statemachine import StringList @@ -648,7 +649,7 @@ def add_content(self, more_content: Optional[StringList]) -> None: for line, src in zip(more_content.data, more_content.items): self.add_line(line, src[0], src[1]) - def get_object_members(self, want_all: bool) -> tuple[bool, ObjectMembers]: + def get_object_members(self, want_all: bool) -> Tuple[bool, ObjectMembers]: """Return `(members_check_module, members)` where `members` is a list of `(membername, member)` pairs of the members of *self.object*. From d93dc08c7e2d04c74b75406f3606224ed6b159ea Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Tue, 23 May 2023 10:42:32 +0200 Subject: [PATCH 47/98] Move future import where it belongs --- src/sage_docbuild/ext/sage_autodoc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage_docbuild/ext/sage_autodoc.py b/src/sage_docbuild/ext/sage_autodoc.py index f9e97070eb2..e89b8fc9ba4 100644 --- a/src/sage_docbuild/ext/sage_autodoc.py +++ b/src/sage_docbuild/ext/sage_autodoc.py @@ -31,6 +31,7 @@ - Kwankyu Lee (2018-12-26, 2022-11-08): rebased on the latest sphinx.ext.autodoc """ +from __future__ import annotations import re import warnings @@ -38,7 +39,6 @@ from types import ModuleType from typing import (TYPE_CHECKING, Any, Callable, Dict, Iterator, List, Optional, Sequence, Set, Tuple, Type, TypeVar, Union) -from __future__ import annotations from docutils.statemachine import StringList From 27525f90c9ed8aaa33f74b992389c411219816a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 23 May 2023 11:39:36 +0200 Subject: [PATCH 48/98] cython-lint : removing unused imports in polynomials --- src/sage/rings/polynomial/cyclotomic.pyx | 2 -- .../rings/polynomial/laurent_polynomial.pyx | 2 +- src/sage/rings/polynomial/multi_polynomial.pyx | 4 ++-- .../multi_polynomial_ideal_libsingular.pyx | 3 +-- .../polynomial/multi_polynomial_libsingular.pyx | 14 +++++--------- .../polynomial/multi_polynomial_ring_base.pyx | 5 +---- .../rings/polynomial/ore_polynomial_element.pyx | 5 +---- src/sage/rings/polynomial/pbori/pbori.pyx | 6 ------ src/sage/rings/polynomial/plural.pyx | 6 ++---- src/sage/rings/polynomial/polydict.pyx | 1 - .../rings/polynomial/polynomial_element.pyx | 7 ++----- .../polynomial_integer_dense_flint.pyx | 4 ++-- .../polynomial/polynomial_integer_dense_ntl.pyx | 9 +++------ .../polynomial/polynomial_modn_dense_ntl.pyx | 8 +------- .../polynomial/polynomial_rational_flint.pyx | 4 ++-- .../polynomial/polynomial_real_mpfr_dense.pyx | 2 +- src/sage/rings/polynomial/polynomial_zz_pex.pyx | 7 ------- src/sage/rings/polynomial/real_roots.pyx | 1 - .../polynomial/skew_polynomial_element.pyx | 17 +++-------------- .../polynomial/skew_polynomial_finite_field.pyx | 6 +----- .../polynomial/skew_polynomial_finite_order.pyx | 5 ----- .../rings/polynomial/symmetric_reduction.pyx | 2 -- 22 files changed, 28 insertions(+), 92 deletions(-) diff --git a/src/sage/rings/polynomial/cyclotomic.pyx b/src/sage/rings/polynomial/cyclotomic.pyx index 1053f471a7a..c4594dba8ad 100644 --- a/src/sage/rings/polynomial/cyclotomic.pyx +++ b/src/sage/rings/polynomial/cyclotomic.pyx @@ -36,8 +36,6 @@ from sage.arith.misc import factor from sage.rings.integer_ring import ZZ from sage.misc.misc_c import prod from sage.misc.misc import subsets -from sage.rings.integer cimport Integer -from sage.rings.rational cimport Rational from sage.libs.pari.all import pari diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index b597397c9e5..e9ba094c752 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -12,7 +12,7 @@ Elements of Laurent polynomial rings from sage.rings.integer cimport Integer from sage.categories.map cimport Map -from sage.structure.element import is_Element, coerce_binop, parent +from sage.structure.element import coerce_binop, parent from sage.structure.factorization import Factorization from sage.misc.derivative import multi_derivative from sage.rings.polynomial.polydict cimport monomial_exponent diff --git a/src/sage/rings/polynomial/multi_polynomial.pyx b/src/sage/rings/polynomial/multi_polynomial.pyx index 28d4265dc82..7ddadb96753 100644 --- a/src/sage/rings/polynomial/multi_polynomial.pyx +++ b/src/sage/rings/polynomial/multi_polynomial.pyx @@ -15,7 +15,7 @@ from sage.rings.integer_ring import ZZ from sage.structure.coerce cimport coercion_model from sage.misc.derivative import multi_derivative from sage.combinat.integer_lists.invlex import IntegerListsLex -from itertools import chain, islice +from itertools import chain from sage.misc.misc_c import prod @@ -30,7 +30,7 @@ from sage.categories.map cimport Map from sage.modules.free_module_element import vector from sage.rings.rational_field import QQ from sage.rings.complex_interval_field import ComplexIntervalField -from sage.rings.real_mpfr import RealField_class, RealField +from sage.rings.real_mpfr import RealField from sage.rings.polynomial.polydict cimport ETuple from sage.rings.polynomial.polynomial_element cimport Polynomial diff --git a/src/sage/rings/polynomial/multi_polynomial_ideal_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_ideal_libsingular.pyx index e37147491dd..14820418454 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ideal_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_ideal_libsingular.pyx @@ -56,12 +56,11 @@ from sage.libs.singular.decl cimport scKBase, poly, testHomog, idSkipZeroes, id_ from sage.libs.singular.decl cimport OPT_REDTAIL, singular_options, kInterRed, t_rep_gb, p_GetCoeff from sage.libs.singular.decl cimport pp_Mult_nn, p_Delete, n_Delete from sage.libs.singular.decl cimport rIsPluralRing -from sage.libs.singular.decl cimport n_unknown, n_Zp, n_Q, n_R, n_GF, n_long_R, n_algExt,n_transExt,n_long_C, n_Z, n_Zn, n_Znm, n_Z2m, n_CF +from sage.libs.singular.decl cimport n_Z, n_Zn, n_Znm, n_Z2m from sage.rings.polynomial.multi_polynomial_libsingular cimport new_MP from sage.rings.polynomial.plural cimport new_NCP -from sage.rings.polynomial.multi_polynomial_ideal import MPolynomialIdeal from sage.rings.polynomial.multi_polynomial_libsingular cimport MPolynomial_libsingular from sage.rings.polynomial.multi_polynomial_libsingular cimport MPolynomialRing_libsingular from sage.structure.sequence import Sequence diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index 64f01724081..34bde8650c5 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -185,13 +185,13 @@ from sage.libs.singular.decl cimport (ring, poly, ideal, intvec, number, # singular functions from sage.libs.singular.decl cimport ( errorreported, - n_IsUnit, n_Invers, n_GetChar, + n_Invers, n_GetChar, p_ISet, rChangeCurrRing, p_Copy, p_Init, p_SetCoeff, p_Setm, p_SetExp, p_Add_q, p_NSet, p_GetCoeff, p_Delete, p_GetExp, pNext, rRingVar, omAlloc0, omStrDup, omFree, p_Divide, p_SetCoeff0, n_Init, p_DivisibleBy, pLcm, p_LmDivisibleBy, pMDivide, p_MDivide, p_IsConstant, p_ExpVectorEqual, p_String, p_LmInit, n_Copy, - p_IsUnit, p_IsOne, p_Series, p_Head, idInit, fast_map_common_subexp, id_Delete, - p_IsHomogeneous, p_Homogen, p_Totaldegree,pLDeg1_Totaldegree, singclap_pdivide, singclap_factorize, + p_IsUnit, p_IsOne, p_Head, idInit, fast_map_common_subexp, id_Delete, + p_IsHomogeneous, p_Homogen, p_Totaldegree, singclap_pdivide, singclap_factorize, idLift, IDELEMS, On, Off, SW_USE_CHINREM_GCD, SW_USE_EZGCD, p_LmIsConstant, pTakeOutComp, singclap_gcd, pp_Mult_qq, p_GetMaxExp, pLength, kNF, p_Neg, p_Minus_mm_Mult_qq, p_Plus_mm_Mult_qq, @@ -222,13 +222,11 @@ from sage.rings.polynomial.polynomial_ring import is_PolynomialRing # base ring imports import sage.rings.abc -from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn from sage.rings.rational cimport Rational from sage.rings.rational_field import QQ import sage.rings.abc from sage.rings.integer_ring import is_IntegerRing, ZZ from sage.rings.integer cimport Integer -from sage.rings.integer import GCD_list from sage.rings.number_field.number_field_base cimport NumberField from sage.rings.number_field.order import is_NumberFieldOrder @@ -240,7 +238,7 @@ from sage.structure.parent cimport Parent from sage.structure.category_object cimport CategoryObject from sage.structure.coerce cimport coercion_model -from sage.structure.element cimport Element, CommutativeRingElement +from sage.structure.element cimport Element from sage.structure.richcmp cimport rich_to_bool, richcmp from sage.structure.factorization import Factorization @@ -1373,12 +1371,10 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): // block 2 : ordering C """ - from sage.functions.other import ceil - if singular is None: from sage.interfaces.singular import singular - if self.ngens()==1: + if self.ngens() == 1: _vars = str(self.gen()) if "*" in _vars: # 1.000...000*x _vars = _vars.split("*")[1] diff --git a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx index 70e1e7c861b..7e562883faa 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx @@ -2,7 +2,6 @@ r""" Base class for multivariate polynomial rings """ import itertools -import warnings from collections.abc import Iterable from sage.matrix.constructor import matrix from sage.modules.free_module_element import vector @@ -27,10 +26,8 @@ from sage.combinat.integer_vector import IntegerVectors from sage.rings.integer_ring import ZZ -from .polydict import PolyDict from . import (multi_polynomial_ideal, - polynomial_ring, - multi_polynomial_element) + polynomial_ring) from .term_order import TermOrder from .polynomial_ring_constructor import (PolynomialRing, polynomial_default_category) diff --git a/src/sage/rings/polynomial/ore_polynomial_element.pyx b/src/sage/rings/polynomial/ore_polynomial_element.pyx index 6da45f51d56..50686923750 100644 --- a/src/sage/rings/polynomial/ore_polynomial_element.pyx +++ b/src/sage/rings/polynomial/ore_polynomial_element.pyx @@ -33,20 +33,17 @@ AUTHORS: import re from cysignals.signals cimport sig_check from sage.structure.element import coerce_binop -from sage.misc.superseded import experimental from sage.rings.infinity import infinity -from sage.structure.factorization import Factorization from sage.structure.element cimport Element, RingElement, AlgebraElement from sage.structure.parent cimport Parent from sage.structure.parent_gens cimport ParentWithGens -from sage.misc.abstract_method import abstract_method from sage.categories.homset import Hom from sage.rings.ring import _Fields from sage.rings.integer cimport Integer from cpython.object cimport PyObject_RichCompare from sage.categories.map cimport Map -from sage.rings.morphism cimport Morphism, RingHomomorphism +from sage.rings.morphism cimport Morphism from sage.rings.polynomial.polynomial_element cimport _dict_to_list diff --git a/src/sage/rings/polynomial/pbori/pbori.pyx b/src/sage/rings/polynomial/pbori/pbori.pyx index 62df6fba35c..06151068427 100644 --- a/src/sage/rings/polynomial/pbori/pbori.pyx +++ b/src/sage/rings/polynomial/pbori/pbori.pyx @@ -187,10 +187,7 @@ import operator from sage.cpython.string cimport str_to_bytes, char_to_str -from sage.misc.cachefunc import cached_method - from sage.misc.randstate import current_randstate -from sage.arith.long cimport pyobject_to_long import sage.misc.weak_dict from sage.rings.integer import Integer from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF @@ -202,7 +199,6 @@ from sage.rings.polynomial.polynomial_ring import PolynomialRing_general from sage.rings.ideal import FieldIdeal -from sage.structure.coerce cimport coercion_model from sage.structure.element cimport Element from sage.structure.parent cimport Parent @@ -4634,7 +4630,6 @@ cdef class BooleanPolynomial(MPolynomial): ... TypeError: argument must be a BooleanPolynomial """ - from sage.rings.polynomial.pbori.pbori import red_tail if not I: return self if isinstance(I, BooleanPolynomialIdeal): @@ -5128,7 +5123,6 @@ class BooleanPolynomialIdeal(MPolynomialIdeal): sage: I.reduce(gb[0]*B.gen(1)) 0 """ - from sage.rings.polynomial.pbori.pbori import red_tail try: g = self.__gb except AttributeError: diff --git a/src/sage/rings/polynomial/plural.pyx b/src/sage/rings/polynomial/plural.pyx index 5eabff2d56a..9f2b2eb130e 100644 --- a/src/sage/rings/polynomial/plural.pyx +++ b/src/sage/rings/polynomial/plural.pyx @@ -102,23 +102,21 @@ TESTS:: True """ - from cysignals.memory cimport sig_malloc, sig_free -from sage.cpython.string cimport bytes_to_str from sage.categories.algebras import Algebras from sage.cpython.string cimport char_to_str # singular rings -from sage.libs.singular.ring cimport singular_ring_new, singular_ring_delete, wrap_ring, singular_ring_reference +from sage.libs.singular.ring cimport singular_ring_delete, wrap_ring, singular_ring_reference from sage.libs.singular.singular cimport si2sa, sa2si, overflow_check from sage.libs.singular.function cimport RingWrap -from sage.libs.singular.polynomial cimport (singular_polynomial_call, singular_polynomial_cmp, singular_polynomial_add, singular_polynomial_sub, singular_polynomial_neg, singular_polynomial_pow, singular_polynomial_mul, singular_polynomial_rmul, singular_polynomial_deg, singular_polynomial_str_with_changed_varnames, singular_polynomial_latex, singular_polynomial_str, singular_polynomial_div_coeff) +from sage.libs.singular.polynomial cimport (singular_polynomial_cmp, singular_polynomial_add, singular_polynomial_sub, singular_polynomial_neg, singular_polynomial_pow, singular_polynomial_mul, singular_polynomial_rmul, singular_polynomial_deg, singular_polynomial_str_with_changed_varnames, singular_polynomial_latex, singular_polynomial_str, singular_polynomial_div_coeff) import sage.libs.singular.ring diff --git a/src/sage/rings/polynomial/polydict.pyx b/src/sage/rings/polynomial/polydict.pyx index 3db1bb6c531..a8b9b22dda4 100644 --- a/src/sage/rings/polynomial/polydict.pyx +++ b/src/sage/rings/polynomial/polydict.pyx @@ -41,7 +41,6 @@ from sage.structure.richcmp cimport rich_to_bool from functools import reduce from pprint import pformat -from sage.arith.power import generic_power from sage.misc.latex import latex diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index 9000c358b26..d1dae6ea894 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -60,7 +60,7 @@ cdef is_FractionField cdef ZZ, QQ, RR, CC, RDF, CDF cimport cython -from cpython.number cimport PyNumber_TrueDivide, PyNumber_Check +from cpython.number cimport PyNumber_Check import operator import copy @@ -70,14 +70,11 @@ from io import StringIO from sage.cpython.wrapperdescr cimport wrapperdescr_fastcall import sage.rings.rational import sage.rings.integer -from . import polynomial_ring import sage.rings.integer_ring import sage.rings.rational_field import sage.rings.finite_rings.integer_mod_ring import sage.rings.fraction_field_element import sage.rings.infinity as infinity -from sage.misc.sage_eval import sage_eval -from sage.misc.abstract_method import abstract_method from sage.misc.latex import latex from sage.arith.power cimport generic_power from sage.arith.misc import crt @@ -354,7 +351,7 @@ cdef class Polynomial(CommutativePolynomial): Graphics object consisting of 1 graphics primitive """ R = self.base_ring() - from sage.plot.all import plot, point, line + from sage.plot.all import plot, point if R.characteristic() == 0: if xmin is None and xmax is None: (xmin, xmax) = (-1,1) diff --git a/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx b/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx index 55cb653f6dc..076d7250b10 100644 --- a/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx +++ b/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx @@ -47,7 +47,7 @@ from sage.libs.gmp.mpz cimport * from sage.arith.long cimport pyobject_to_long, is_small_python_int from sage.rings.polynomial.polynomial_element cimport Polynomial -from sage.structure.element cimport ModuleElement, Element +from sage.structure.element cimport Element from sage.structure.element import coerce_binop from sage.libs.ntl.ntl_ZZX cimport ntl_ZZX @@ -70,7 +70,7 @@ from sage.libs.ntl.ZZX cimport * from sage.rings.complex_arb cimport ComplexBall from sage.rings.integer cimport Integer, smallInteger from sage.rings.real_arb cimport RealBall -from sage.rings.real_mpfr cimport RealNumber, RealField_class +from sage.rings.real_mpfr cimport RealNumber from sage.rings.real_mpfi cimport RealIntervalFieldElement from sage.rings.polynomial.evaluation_flint cimport fmpz_poly_evaluation_mpfr, fmpz_poly_evaluation_mpfi diff --git a/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx b/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx index 38e2470f1f1..0d42293aaa3 100644 --- a/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx +++ b/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx @@ -27,7 +27,6 @@ do:: sage: K Univariate Polynomial Ring in x over Integer Ring (using NTL) """ - #***************************************************************************** # Copyright (C) 2007 William Stein # @@ -35,7 +34,7 @@ do:: # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ #***************************************************************************** from cysignals.memory cimport sig_free @@ -45,10 +44,9 @@ from sage.ext.cplusplus cimport ccrepr include "sage/libs/ntl/decl.pxi" from sage.rings.polynomial.polynomial_element cimport Polynomial -from sage.structure.element cimport ModuleElement, Element +from sage.structure.element cimport Element from sage.rings.integer_ring import IntegerRing -from sage.rings.integer_ring cimport IntegerRing_class ZZ_sage = IntegerRing() from sage.libs.ntl.ntl_ZZX cimport ntl_ZZX @@ -57,7 +55,7 @@ from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ from sage.rings.integer import Integer from sage.rings.integer cimport Integer -from sage.rings.real_mpfr cimport RealNumber, RealField_class +from sage.rings.real_mpfr cimport RealNumber from sage.rings.real_mpfi cimport RealIntervalFieldElement from sage.libs.pari.all import pari, pari_gen @@ -66,7 +64,6 @@ from sage.structure.element import coerce_binop from sage.rings.fraction_field_element import FractionFieldElement from sage.arith.functions import lcm -import sage.rings.polynomial.polynomial_ring from sage.libs.ntl.ZZX cimport * diff --git a/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx b/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx index e0621f2c4a4..51a56c955e1 100644 --- a/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx +++ b/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx @@ -32,7 +32,6 @@ AUTHORS: # https://www.gnu.org/licenses/ # **************************************************************************** -from cysignals.memory cimport sig_malloc, sig_free from cysignals.signals cimport sig_on, sig_off from sage.rings.polynomial.polynomial_element cimport Polynomial, _dict_to_list @@ -41,17 +40,13 @@ from sage.libs.pari.all import pari, pari_gen from sage.rings.integer cimport smallInteger -from sage.libs.ntl.all import ZZ as ntl_ZZ, ZZX, zero_ZZX, ZZ_p, ZZ_pX -from sage.rings.rational_field import QQ +from sage.libs.ntl.all import ZZX, ZZ_pX from sage.rings.integer_ring import ZZ -from sage.rings.finite_rings.integer_mod import IntegerMod_abstract from sage.rings.fraction_field_element import FractionFieldElement -import sage.rings.polynomial.polynomial_ring from sage.rings.infinity import infinity -from . import polynomial_singular_interface from sage.interfaces.singular import singular as singular_default from sage.structure.element import coerce_binop @@ -161,7 +156,6 @@ cdef class Polynomial_dense_mod_n(Polynomial): self.__poly = ZZ_pX(x, parent.modulus()) - def __reduce__(self): return make_element, (self.parent(), (self.list(), False, self.is_gen())) diff --git a/src/sage/rings/polynomial/polynomial_rational_flint.pyx b/src/sage/rings/polynomial/polynomial_rational_flint.pyx index d85ad4af690..82c54350981 100644 --- a/src/sage/rings/polynomial/polynomial_rational_flint.pyx +++ b/src/sage/rings/polynomial/polynomial_rational_flint.pyx @@ -22,7 +22,7 @@ AUTHOR: # http://www.gnu.org/licenses/ #***************************************************************************** -from cysignals.memory cimport check_allocarray, check_malloc, sig_free +from cysignals.memory cimport check_allocarray, sig_free from cysignals.signals cimport sig_on, sig_str, sig_off from cpython.int cimport PyInt_AS_LONG @@ -53,7 +53,7 @@ from sage.rings.polynomial.polynomial_element cimport Polynomial from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint from sage.structure.parent cimport Parent -from sage.structure.element cimport Element, ModuleElement, RingElement +from sage.structure.element cimport Element from sage.structure.element import coerce_binop from sage.misc.cachefunc import cached_method diff --git a/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx b/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx index c13372dcd25..acc11f27c35 100644 --- a/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx +++ b/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx @@ -34,7 +34,7 @@ from sage.rings.real_mpfr cimport RealField_class, RealNumber from sage.rings.integer cimport Integer, smallInteger from sage.rings.rational cimport Rational -from sage.structure.element cimport Element, ModuleElement, RingElement +from sage.structure.element cimport Element from sage.structure.element cimport parent from sage.structure.element import coerce_binop from sage.libs.mpfr cimport * diff --git a/src/sage/rings/polynomial/polynomial_zz_pex.pyx b/src/sage/rings/polynomial/polynomial_zz_pex.pyx index 0d885e522ef..17af09d594f 100644 --- a/src/sage/rings/polynomial/polynomial_zz_pex.pyx +++ b/src/sage/rings/polynomial/polynomial_zz_pex.pyx @@ -12,16 +12,10 @@ AUTHOR: - Yann Laigle-Chapuy (2010-01) initial implementation - Lorenz Panny (2023-01): :meth:`minpoly_mod` """ - -from sage.rings.integer_ring import ZZ -from sage.rings.integer_ring cimport IntegerRing_class - from sage.libs.ntl.ntl_ZZ_pEContext cimport ntl_ZZ_pEContext_class from sage.libs.ntl.ZZ_pE cimport ZZ_pE_to_ZZ_pX from sage.libs.ntl.ZZ_pX cimport ZZ_pX_deg, ZZ_pX_coeff -from sage.libs.ntl.ntl_ZZ_pX cimport ntl_ZZ_pX from sage.libs.ntl.ZZ_p cimport ZZ_p_rep -from sage.libs.ntl.ntl_ZZ_pContext cimport ntl_ZZ_pContext_class from sage.libs.ntl.convert cimport ZZ_to_mpz # We need to define this stuff before including the templating stuff @@ -44,7 +38,6 @@ include "sage/libs/ntl/ntl_ZZ_pEX_linkage.pxi" # and then the interface include "polynomial_template.pxi" -from sage.libs.pari.all import pari from sage.libs.ntl.ntl_ZZ_pE cimport ntl_ZZ_pE cdef inline ZZ_pE_c_to_list(ZZ_pE_c x): diff --git a/src/sage/rings/polynomial/real_roots.pyx b/src/sage/rings/polynomial/real_roots.pyx index 94fa0b84d40..721d5e7e7d4 100644 --- a/src/sage/rings/polynomial/real_roots.pyx +++ b/src/sage/rings/polynomial/real_roots.pyx @@ -147,7 +147,6 @@ from sage.modules.free_module_element import free_module_element as vector from sage.modules.free_module import FreeModule from sage.matrix.matrix_space import MatrixSpace from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing -from sage.rings.polynomial.polynomial_ring import polygen from sage.misc.functional import numerator, denominator from sage.misc.misc_c import prod diff --git a/src/sage/rings/polynomial/skew_polynomial_element.pyx b/src/sage/rings/polynomial/skew_polynomial_element.pyx index 6f8bd43da86..539e924a968 100644 --- a/src/sage/rings/polynomial/skew_polynomial_element.pyx +++ b/src/sage/rings/polynomial/skew_polynomial_element.pyx @@ -45,24 +45,13 @@ AUTHORS: # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ #**************************************************************************** - -import re from cysignals.signals cimport sig_check -from sage.rings.infinity import infinity -from sage.structure.factorization import Factorization -from sage.structure.element cimport Element, RingElement, AlgebraElement, ModuleElement -from sage.misc.abstract_method import abstract_method -from sage.categories.homset import Hom -from sage.categories.fields import Fields +from sage.structure.element cimport Element, RingElement, ModuleElement from sage.rings.integer cimport Integer -from cpython.object cimport PyObject_RichCompare -from sage.categories.map cimport Map -from sage.rings.morphism cimport Morphism, RingHomomorphism -from sage.rings.polynomial.polynomial_element cimport _dict_to_list -from sage.structure.element import coerce_binop +from sage.rings.morphism cimport RingHomomorphism from sage.misc.superseded import experimental from sage.rings.polynomial.ore_polynomial_element cimport OrePolynomial diff --git a/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx b/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx index 107077623d6..1d539c93f48 100644 --- a/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx +++ b/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx @@ -22,11 +22,10 @@ AUTHOR:: # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ #**************************************************************************** from sage.structure.element cimport parent -from sage.rings.ring cimport Ring from sage.rings.integer_ring import ZZ from sage.rings.integer cimport Integer from sage.matrix.matrix_space import MatrixSpace @@ -34,11 +33,8 @@ from sage.matrix.matrix2 import NotFullRankError from sage.rings.polynomial.polynomial_element cimport Polynomial from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing -from sage.rings.polynomial.ore_polynomial_element cimport OrePolynomial as SkewPolynomial from sage.rings.polynomial.skew_polynomial_finite_order cimport SkewPolynomial_finite_order_dense -from sage.combinat.permutation import Permutation, Permutations -from sage.combinat.partition import Partition from sage.structure.factorization import Factorization from sage.misc.mrange import xmrange_iter from sage.misc.prandom import sample diff --git a/src/sage/rings/polynomial/skew_polynomial_finite_order.pyx b/src/sage/rings/polynomial/skew_polynomial_finite_order.pyx index f3ff0617484..51ce9e0e3fd 100644 --- a/src/sage/rings/polynomial/skew_polynomial_finite_order.pyx +++ b/src/sage/rings/polynomial/skew_polynomial_finite_order.pyx @@ -18,12 +18,7 @@ AUTHOR:: # (at your option) any later version. # https://www.gnu.org/licenses/ # *************************************************************************** - -import copy -import cysignals from sage.rings.ring cimport Ring -from sage.rings.polynomial.polynomial_element cimport Polynomial -from sage.rings.integer cimport Integer from sage.structure.element cimport RingElement from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.polynomial.skew_polynomial_element cimport SkewPolynomial_generic_dense diff --git a/src/sage/rings/polynomial/symmetric_reduction.pyx b/src/sage/rings/polynomial/symmetric_reduction.pyx index 25213e1318a..463c875ad89 100644 --- a/src/sage/rings/polynomial/symmetric_reduction.pyx +++ b/src/sage/rings/polynomial/symmetric_reduction.pyx @@ -116,8 +116,6 @@ Symmetric Reduction Strategy is created:: # # https://www.gnu.org/licenses/ # **************************************************************************** -import copy -import operator import sys from sage.structure.richcmp cimport richcmp, Py_NE, Py_EQ From 18e29ed6a3d40ac5832cf9a091a26cb756f7ac6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 23 May 2023 11:56:08 +0200 Subject: [PATCH 49/98] cylint: remove unused imports in pyx files in folders a*-geo* --- .../algebras/letterplace/free_algebra_element_letterplace.pyx | 1 - src/sage/algebras/letterplace/free_algebra_letterplace.pyx | 2 -- src/sage/algebras/quatalg/quaternion_algebra_cython.pyx | 3 +-- src/sage/algebras/quatalg/quaternion_algebra_element.pyx | 3 +-- src/sage/calculus/ode.pyx | 3 +-- src/sage/calculus/riemann.pyx | 3 --- src/sage/coding/binary_code.pyx | 1 - src/sage/coding/codecan/codecan.pyx | 3 --- src/sage/crypto/sbox.pyx | 1 - src/sage/data_structures/bounded_integer_sequences.pyx | 1 - src/sage/finance/fractal.pyx | 3 --- .../geometry/polyhedron/combinatorial_polyhedron/base.pyx | 1 - .../polyhedron/combinatorial_polyhedron/conversions.pyx | 3 --- .../polyhedron/combinatorial_polyhedron/face_iterator.pyx | 4 +--- .../polyhedron/combinatorial_polyhedron/list_of_faces.pyx | 3 +-- .../combinatorial_polyhedron/polyhedron_face_lattice.pyx | 3 +-- 16 files changed, 6 insertions(+), 32 deletions(-) diff --git a/src/sage/algebras/letterplace/free_algebra_element_letterplace.pyx b/src/sage/algebras/letterplace/free_algebra_element_letterplace.pyx index 3ccb1f951ed..3dabaa2a798 100644 --- a/src/sage/algebras/letterplace/free_algebra_element_letterplace.pyx +++ b/src/sage/algebras/letterplace/free_algebra_element_letterplace.pyx @@ -19,7 +19,6 @@ AUTHOR: from sage.groups.perm_gps.permgroup_named import CyclicPermutationGroup from sage.libs.singular.function import lib, singular_function -from sage.misc.repr import repr_lincomb from sage.rings.polynomial.multi_polynomial_ideal import MPolynomialIdeal from cpython.object cimport PyObject_RichCompare diff --git a/src/sage/algebras/letterplace/free_algebra_letterplace.pyx b/src/sage/algebras/letterplace/free_algebra_letterplace.pyx index add09456f0b..806c25202f1 100644 --- a/src/sage/algebras/letterplace/free_algebra_letterplace.pyx +++ b/src/sage/algebras/letterplace/free_algebra_letterplace.pyx @@ -115,8 +115,6 @@ TESTS:: algebras with different term orderings, yet. """ - -from sage.misc.misc_c import prod from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.libs.singular.function import lib, singular_function from sage.libs.singular.function cimport RingWrap diff --git a/src/sage/algebras/quatalg/quaternion_algebra_cython.pyx b/src/sage/algebras/quatalg/quaternion_algebra_cython.pyx index 0d110aad7e3..bce313b46bc 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra_cython.pyx +++ b/src/sage/algebras/quatalg/quaternion_algebra_cython.pyx @@ -25,7 +25,7 @@ AUTHORS: # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ # **************************************************************************** from sage.rings.integer_ring import ZZ @@ -38,7 +38,6 @@ from sage.matrix.matrix_rational_dense cimport Matrix_rational_dense from .quaternion_algebra_element cimport QuaternionAlgebraElement_rational_field from sage.libs.gmp.mpz cimport mpz_t, mpz_lcm, mpz_init, mpz_set, mpz_clear, mpz_init_set, mpz_mul, mpz_fdiv_q, mpz_cmp_si -from sage.libs.gmp.mpq cimport mpq_set_num, mpq_set_den, mpq_canonicalize from sage.libs.flint.fmpz cimport fmpz_set_mpz from sage.libs.flint.fmpq cimport fmpq_canonicalise diff --git a/src/sage/algebras/quatalg/quaternion_algebra_element.pyx b/src/sage/algebras/quatalg/quaternion_algebra_element.pyx index b2da19d4c80..1386c2d3cab 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra_element.pyx +++ b/src/sage/algebras/quatalg/quaternion_algebra_element.pyx @@ -32,12 +32,11 @@ Check that :trac:`20829` is fixed:: # https://www.gnu.org/licenses/ # **************************************************************************** -from sage.structure.element cimport AlgebraElement, RingElement, ModuleElement, Element +from sage.structure.element cimport AlgebraElement, Element from sage.structure.richcmp cimport rich_to_bool, rich_to_bool_sgn, richcmp_item from sage.algebras.quatalg.quaternion_algebra_element cimport QuaternionAlgebraElement_abstract from sage.rings.rational cimport Rational from sage.rings.integer cimport Integer -from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint from sage.rings.number_field.number_field_element cimport NumberFieldElement from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.matrix.constructor import matrix diff --git a/src/sage/calculus/ode.pyx b/src/sage/calculus/ode.pyx index 5425a7b0131..544556ddf72 100644 --- a/src/sage/calculus/ode.pyx +++ b/src/sage/calculus/ode.pyx @@ -401,9 +401,8 @@ class ode_solver(): G.save(filename=filename) def ode_solve(self,t_span=False,y_0=False,num_points=False,params=[]): - import inspect cdef double h # step size - h=self.h + h = self.h cdef int i cdef int j cdef int type diff --git a/src/sage/calculus/riemann.pyx b/src/sage/calculus/riemann.pyx index 4dc18b964f2..1f038f4ec03 100644 --- a/src/sage/calculus/riemann.pyx +++ b/src/sage/calculus/riemann.pyx @@ -46,7 +46,6 @@ cimport numpy as np from math import pi from math import sin from math import cos -from math import sqrt from math import log # used for complex plot lightness from math import atan @@ -54,8 +53,6 @@ from math import atan from cmath import exp from cmath import phase -from random import uniform # used for accuracy tests - FLOAT = np.float64 ctypedef np.float64_t FLOAT_T diff --git a/src/sage/coding/binary_code.pyx b/src/sage/coding/binary_code.pyx index 630cba27f36..fcd569779f9 100644 --- a/src/sage/coding/binary_code.pyx +++ b/src/sage/coding/binary_code.pyx @@ -4103,7 +4103,6 @@ cdef class BinaryCodeClassifier: m = BinaryCode(matrix(ZZ, rs)) m_aut_gp_gens, m_labeling, m_size, m_base = self._aut_gp_and_can_label(m) - from sage.arith.misc import factorial if True: # size*factorial(n-B.ncols) == m_size: if len(m_aut_gp_gens) == 0: diff --git a/src/sage/coding/codecan/codecan.pyx b/src/sage/coding/codecan/codecan.pyx index 5320a49b179..90f1fc76194 100644 --- a/src/sage/coding/codecan/codecan.pyx +++ b/src/sage/coding/codecan/codecan.pyx @@ -96,8 +96,6 @@ from copy import copy from cysignals.memory cimport check_allocarray, sig_free from sage.rings.integer cimport Integer -from sage.matrix.matrix cimport Matrix -from sage.groups.perm_gps.permgroup import PermutationGroup cimport sage.groups.perm_gps.partn_ref2.refinement_generic from sage.modules.finite_submodule_iter cimport FiniteFieldsubspace_projPoint_iterator as FFSS_projPoint from sage.groups.perm_gps.partn_ref.data_structures cimport * @@ -757,7 +755,6 @@ cdef class PartitionRefinementLinearCode(PartitionRefinement_generic): This graph will be later used in the refinement procedures. """ - from sage.matrix.constructor import matrix cdef FFSS_projPoint iter = FFSS_projPoint(self._matrix) cdef mp_bitcnt_t i,j diff --git a/src/sage/crypto/sbox.pyx b/src/sage/crypto/sbox.pyx index 399e434def7..27ea987d1e9 100644 --- a/src/sage/crypto/sbox.pyx +++ b/src/sage/crypto/sbox.pyx @@ -15,7 +15,6 @@ from sage.matrix.matrix0 cimport Matrix from sage.misc.cachefunc import cached_method from sage.misc.functional import is_even from sage.misc.misc_c import prod as mul -from sage.misc.superseded import deprecated_function_alias from sage.modules.free_module_element import vector from sage.rings.finite_rings.finite_field_base import FiniteField from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF diff --git a/src/sage/data_structures/bounded_integer_sequences.pyx b/src/sage/data_structures/bounded_integer_sequences.pyx index d431c71f663..7e3846470c0 100644 --- a/src/sage/data_structures/bounded_integer_sequences.pyx +++ b/src/sage/data_structures/bounded_integer_sequences.pyx @@ -112,7 +112,6 @@ from sage.data_structures.bitset_base cimport * from cpython.int cimport PyInt_FromSize_t from cpython.slice cimport PySlice_GetIndicesEx -from sage.libs.gmp.mpn cimport mpn_rshift, mpn_lshift, mpn_copyi, mpn_ior_n, mpn_zero, mpn_copyd, mpn_cmp from sage.libs.flint.flint cimport FLINT_BIT_COUNT as BIT_COUNT from sage.structure.richcmp cimport richcmp_not_equal, rich_to_bool diff --git a/src/sage/finance/fractal.pyx b/src/sage/finance/fractal.pyx index ed67ade8181..a16ccf1a79b 100644 --- a/src/sage/finance/fractal.pyx +++ b/src/sage/finance/fractal.pyx @@ -20,11 +20,8 @@ AUTHOR: - William Stein (2008) """ - -from sage.rings.real_double import RDF from sage.rings.complex_double import CDF from sage.rings.integer import Integer -from sage.modules.free_module_element import vector I = CDF.gen() from sage.stats.time_series cimport TimeSeries diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx b/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx index a415bc44671..f2ad086a174 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx @@ -86,7 +86,6 @@ import numbers from memory_allocator cimport MemoryAllocator from cysignals.memory cimport check_calloc, sig_free -from sage.rings.integer import Integer from sage.graphs.graph import Graph from sage.geometry.polyhedron.base import Polyhedron_base from sage.geometry.lattice_polytope import LatticePolytopeClass diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pyx b/src/sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pyx index 999acbd1f52..b670ad2e53f 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pyx +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pyx @@ -69,13 +69,10 @@ AUTHOR: from memory_allocator cimport MemoryAllocator -from sage.structure.element import is_Matrix from sage.matrix.matrix_dense cimport Matrix_dense from .list_of_faces cimport ListOfFaces from .face_data_structure cimport face_next_atom, face_add_atom_safe, facet_set_coatom, face_clear -from .face_list_data_structure cimport face_list_t - cdef extern from "Python.h": int unlikely(int) nogil # Defined by Cython diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx b/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx index 89d2f01352c..cd24dd5be66 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx @@ -178,10 +178,8 @@ from cython.parallel cimport prange, threadid from cysignals.memory cimport check_allocarray, sig_free from memory_allocator cimport MemoryAllocator -from sage.rings.integer cimport smallInteger from cysignals.signals cimport sig_check -from .conversions cimport bit_rep_to_Vrep_list, Vrep_list_to_bit_rep -from .conversions import facets_tuple_to_bit_rep_of_facets +from .conversions cimport bit_rep_to_Vrep_list from .base cimport CombinatorialPolyhedron from sage.geometry.polyhedron.face import combinatorial_face_to_polyhedral_face, PolyhedronFace diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pyx b/src/sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pyx index c71eaded3b9..d365ee3a24e 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pyx +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pyx @@ -79,7 +79,6 @@ AUTHOR: - Jonathan Kliem (2019-04) """ - # **************************************************************************** # Copyright (C) 2019 Jonathan Kliem # @@ -90,7 +89,6 @@ AUTHOR: # https://www.gnu.org/licenses/ # **************************************************************************** -from sage.structure.element import is_Matrix from sage.matrix.matrix_dense cimport Matrix_dense from .face_list_data_structure cimport * @@ -98,6 +96,7 @@ from .face_list_data_structure cimport * cdef extern from "Python.h": int unlikely(int) nogil # Defined by Cython + cdef class ListOfFaces: r""" A class to store the Bit-representation of faces in. diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pyx b/src/sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pyx index a1c4152bf42..b028925d205 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pyx +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pyx @@ -57,7 +57,7 @@ AUTHOR: # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ #***************************************************************************** from .conversions \ @@ -66,7 +66,6 @@ from .conversions \ from .conversions cimport bit_rep_to_Vrep_list -from sage.rings.integer cimport smallInteger from .base cimport CombinatorialPolyhedron from .face_iterator cimport FaceIterator from .face_list_data_structure cimport * From d1d5d6035b97e4e0bf36e61b32b93c5112a42314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 23 May 2023 12:19:44 +0200 Subject: [PATCH 50/98] cylint: remove unused imports in graphs, groups, interacts --- src/sage/graphs/connectivity.pyx | 3 --- src/sage/graphs/convexity_properties.pyx | 1 - src/sage/graphs/graph_decompositions/bandwidth.pyx | 3 +-- src/sage/graphs/hyperbolicity.pyx | 3 +-- src/sage/graphs/isoperimetric_inequalities.pyx | 2 +- src/sage/graphs/matchpoly.pyx | 3 +-- src/sage/graphs/path_enumeration.pyx | 1 - src/sage/graphs/spanning_tree.pyx | 1 - src/sage/graphs/strongly_regular_db.pyx | 2 -- src/sage/graphs/traversals.pyx | 4 ++-- src/sage/groups/group.pyx | 4 ---- src/sage/groups/libgap_wrapper.pyx | 1 - src/sage/groups/matrix_gps/group_element.pyx | 3 +-- src/sage/groups/matrix_gps/group_element_gap.pyx | 4 ++-- src/sage/groups/old.pyx | 3 --- src/sage/groups/perm_gps/partn_ref/refinement_binary.pyx | 2 -- src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx | 2 -- .../groups/perm_gps/partn_ref/refinement_matrices.pyx | 2 -- src/sage/groups/perm_gps/partn_ref/refinement_python.pyx | 4 ++-- src/sage/groups/perm_gps/permgroup_element.pyx | 8 ++------ src/sage/interacts/library_cython.pyx | 5 +---- 21 files changed, 14 insertions(+), 47 deletions(-) diff --git a/src/sage/graphs/connectivity.pyx b/src/sage/graphs/connectivity.pyx index a1241800ac9..9fc78325601 100644 --- a/src/sage/graphs/connectivity.pyx +++ b/src/sage/graphs/connectivity.pyx @@ -58,9 +58,6 @@ Methods ------- """ -from sage.rings.integer cimport Integer -from cysignals.memory cimport sig_malloc, sig_free - def is_connected(G): """ diff --git a/src/sage/graphs/convexity_properties.pyx b/src/sage/graphs/convexity_properties.pyx index a7243cc8d7a..8c901b5cf94 100644 --- a/src/sage/graphs/convexity_properties.pyx +++ b/src/sage/graphs/convexity_properties.pyx @@ -41,7 +41,6 @@ from sage.numerical.backends.generic_backend cimport GenericBackend from sage.numerical.backends.generic_backend import get_solver from sage.graphs.distances_all_pairs cimport c_distances_all_pairs from cysignals.memory cimport sig_free -from cysignals.signals cimport sig_on, sig_off from memory_allocator cimport MemoryAllocator from libc.stdint cimport uint32_t from sage.graphs.base.static_sparse_graph cimport (short_digraph, diff --git a/src/sage/graphs/graph_decompositions/bandwidth.pyx b/src/sage/graphs/graph_decompositions/bandwidth.pyx index ac65e58059d..874787d4713 100644 --- a/src/sage/graphs/graph_decompositions/bandwidth.pyx +++ b/src/sage/graphs/graph_decompositions/bandwidth.pyx @@ -109,7 +109,7 @@ Functions # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ # **************************************************************************** from libc.stdint cimport uint16_t @@ -117,7 +117,6 @@ from cysignals.signals cimport sig_check from memory_allocator cimport MemoryAllocator from sage.graphs.distances_all_pairs cimport all_pairs_shortest_path_BFS -from sage.graphs.base.boost_graph import bandwidth_heuristics ctypedef uint16_t index_t diff --git a/src/sage/graphs/hyperbolicity.pyx b/src/sage/graphs/hyperbolicity.pyx index a76b5477961..05fb3c3da79 100644 --- a/src/sage/graphs/hyperbolicity.pyx +++ b/src/sage/graphs/hyperbolicity.pyx @@ -146,7 +146,7 @@ Methods # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ # **************************************************************************** from libc.string cimport memset @@ -158,7 +158,6 @@ from sage.graphs.distances_all_pairs cimport c_distances_all_pairs from sage.arith.misc import binomial from sage.rings.integer_ring import ZZ from sage.rings.real_mpfr import RR -from sage.data_structures.bitset import Bitset from sage.graphs.base.static_sparse_graph cimport short_digraph from sage.graphs.base.static_sparse_graph cimport init_short_digraph from sage.graphs.base.static_sparse_graph cimport free_short_digraph diff --git a/src/sage/graphs/isoperimetric_inequalities.pyx b/src/sage/graphs/isoperimetric_inequalities.pyx index 763a2da494e..b7f6510ba94 100644 --- a/src/sage/graphs/isoperimetric_inequalities.pyx +++ b/src/sage/graphs/isoperimetric_inequalities.pyx @@ -23,7 +23,7 @@ Authors: from cysignals.signals cimport sig_on, sig_off from cysignals.memory cimport check_malloc, sig_free -from sage.graphs.base.static_sparse_graph cimport short_digraph, init_short_digraph, free_short_digraph, out_degree +from sage.graphs.base.static_sparse_graph cimport short_digraph, init_short_digraph, free_short_digraph from sage.data_structures.binary_matrix cimport * from sage.graphs.base.static_dense_graph cimport dense_graph_init diff --git a/src/sage/graphs/matchpoly.pyx b/src/sage/graphs/matchpoly.pyx index 4a8c24be8ca..7845b225f9c 100644 --- a/src/sage/graphs/matchpoly.pyx +++ b/src/sage/graphs/matchpoly.pyx @@ -32,7 +32,7 @@ Methods # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ # **************************************************************************** from cysignals.memory cimport check_allocarray, sig_free @@ -41,7 +41,6 @@ from cysignals.signals cimport sig_on, sig_off from sage.rings.polynomial.polynomial_ring import polygen from sage.rings.integer_ring import ZZ from sage.rings.integer cimport Integer -from sage.misc.misc_c import prod from sage.libs.flint.fmpz cimport * from sage.libs.flint.fmpz_poly cimport * diff --git a/src/sage/graphs/path_enumeration.pyx b/src/sage/graphs/path_enumeration.pyx index 0ef63dd0c17..032ebd95ec2 100644 --- a/src/sage/graphs/path_enumeration.pyx +++ b/src/sage/graphs/path_enumeration.pyx @@ -34,7 +34,6 @@ Functions from sage.categories.cartesian_product import cartesian_product from sage.misc.misc_c import prod -from libcpp.vector cimport vector from libcpp.queue cimport priority_queue from libcpp.pair cimport pair from sage.rings.integer_ring import ZZ diff --git a/src/sage/graphs/spanning_tree.pyx b/src/sage/graphs/spanning_tree.pyx index 5c017314724..70ebcd2f599 100644 --- a/src/sage/graphs/spanning_tree.pyx +++ b/src/sage/graphs/spanning_tree.pyx @@ -34,7 +34,6 @@ Methods # https://www.gnu.org/licenses/ # **************************************************************************** -cimport cython from memory_allocator cimport MemoryAllocator from sage.sets.disjoint_set cimport DisjointSet_of_hashables from sage.misc.decorators import rename_keyword diff --git a/src/sage/graphs/strongly_regular_db.pyx b/src/sage/graphs/strongly_regular_db.pyx index 04aa1322837..24f471edd4e 100644 --- a/src/sage/graphs/strongly_regular_db.pyx +++ b/src/sage/graphs/strongly_regular_db.pyx @@ -2574,8 +2574,6 @@ def SRG_176_90_38_54(): sage: G.is_strongly_regular(parameters=True) (176, 90, 38, 54) """ - from sage.graphs.generators.basic import CompleteGraph - from sage.misc.flatten import flatten g = SRG_175_72_20_36() g.relabel(range(175)) # c=filter(lambda x: len(x)==5, g.cliques_maximal()) diff --git a/src/sage/graphs/traversals.pyx b/src/sage/graphs/traversals.pyx index a16ac6d701e..e07c502973e 100644 --- a/src/sage/graphs/traversals.pyx +++ b/src/sage/graphs/traversals.pyx @@ -42,12 +42,12 @@ from libc.stdint cimport uint32_t from libcpp.queue cimport priority_queue from libcpp.pair cimport pair from libcpp.vector cimport vector -from cysignals.signals cimport sig_on, sig_off, sig_check +from cysignals.signals cimport sig_on, sig_off from memory_allocator cimport MemoryAllocator from sage.graphs.base.static_sparse_graph cimport init_short_digraph from sage.graphs.base.static_sparse_graph cimport free_short_digraph -from sage.graphs.base.static_sparse_graph cimport out_degree, has_edge +from sage.graphs.base.static_sparse_graph cimport out_degree def _is_valid_lex_BFS_order(G, L): diff --git a/src/sage/groups/group.pyx b/src/sage/groups/group.pyx index 7947f0f876d..36f18d701b2 100644 --- a/src/sage/groups/group.pyx +++ b/src/sage/groups/group.pyx @@ -17,12 +17,8 @@ Base class for groups # https://www.gnu.org/licenses/ # **************************************************************************** -import random - from sage.structure.parent cimport Parent from sage.rings.infinity import infinity -from sage.rings.integer_ring import ZZ -from sage.misc.lazy_attribute import lazy_attribute def is_Group(x): diff --git a/src/sage/groups/libgap_wrapper.pyx b/src/sage/groups/libgap_wrapper.pyx index dc81b71635b..c65afa447e5 100644 --- a/src/sage/groups/libgap_wrapper.pyx +++ b/src/sage/groups/libgap_wrapper.pyx @@ -65,7 +65,6 @@ from sage.rings.integer import Integer from sage.rings.integer_ring import IntegerRing from sage.misc.cachefunc import cached_method from sage.structure.sage_object import SageObject -from sage.structure.element cimport Element from sage.structure.richcmp cimport richcmp diff --git a/src/sage/groups/matrix_gps/group_element.pyx b/src/sage/groups/matrix_gps/group_element.pyx index c18476a45ba..4e57798b384 100644 --- a/src/sage/groups/matrix_gps/group_element.pyx +++ b/src/sage/groups/matrix_gps/group_element.pyx @@ -73,10 +73,9 @@ AUTHORS: # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ #***************************************************************************** -from sage.misc.cachefunc import cached_method from sage.rings.integer_ring import ZZ from sage.structure.element cimport MultiplicativeGroupElement, Matrix from sage.structure.element import is_Matrix diff --git a/src/sage/groups/matrix_gps/group_element_gap.pyx b/src/sage/groups/matrix_gps/group_element_gap.pyx index 7aba88e9b88..c26ddebde71 100644 --- a/src/sage/groups/matrix_gps/group_element_gap.pyx +++ b/src/sage/groups/matrix_gps/group_element_gap.pyx @@ -14,11 +14,11 @@ Matrix group elements implemented in GAP # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ #***************************************************************************** from sage.groups.matrix_gps.group_element cimport is_MatrixGroupElement -from sage.libs.gap.element cimport GapElement, GapElement_List +from sage.libs.gap.element cimport GapElement from sage.misc.cachefunc import cached_method from sage.structure.element import is_Matrix from sage.structure.factorization import Factorization diff --git a/src/sage/groups/old.pyx b/src/sage/groups/old.pyx index c17082f59cb..92b69af07db 100644 --- a/src/sage/groups/old.pyx +++ b/src/sage/groups/old.pyx @@ -20,9 +20,6 @@ Base class for groups doc=""" Base class for all groups """ - -import random - from sage.rings.infinity import infinity import sage.rings.integer_ring diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_binary.pyx b/src/sage/groups/perm_gps/partn_ref/refinement_binary.pyx index e18fdf5f41a..f521d76b1db 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_binary.pyx +++ b/src/sage/groups/perm_gps/partn_ref/refinement_binary.pyx @@ -1062,9 +1062,7 @@ def random_tests(num=50, n_max=50, k_max=6, nwords_max=200, perms_per_code=10, d sage: import sage.groups.perm_gps.partn_ref.refinement_binary sage: sage.groups.perm_gps.partn_ref.refinement_binary.random_tests() # long time (up to 5s on sage.math, 2012) All passed: ... random tests on ... codes. - """ - from sage.misc.misc import walltime from sage.misc.prandom import random, randint from sage.combinat.permutation import Permutations from sage.matrix.constructor import random_matrix, matrix diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx b/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx index 1acb46201a0..1e1858891d3 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx +++ b/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx @@ -70,7 +70,6 @@ def isomorphic(G1, G2, partn, ordering2, dig, use_indicator_function, sparse=Fal cdef bint loops = 0 from sage.graphs.graph import Graph - from sage.graphs.digraph import DiGraph from sage.graphs.generic_graph import GenericGraph from copy import copy which_G = 1 @@ -380,7 +379,6 @@ def search_tree(G_in, partition, lab=True, dig=False, dict_rep=False, certificat cdef aut_gp_and_can_lab *output cdef PartitionStack *part from sage.graphs.graph import Graph - from sage.graphs.digraph import DiGraph from sage.graphs.generic_graph import GenericGraph from copy import copy if isinstance(G_in, GenericGraph): diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_matrices.pyx b/src/sage/groups/perm_gps/partn_ref/refinement_matrices.pyx index 71f09ccc90f..36883bf8832 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_matrices.pyx +++ b/src/sage/groups/perm_gps/partn_ref/refinement_matrices.pyx @@ -330,9 +330,7 @@ def random_tests(n=10, nrows_max=50, ncols_max=50, nsymbols_max=10, perms_per_ma sage: import sage.groups.perm_gps.partn_ref.refinement_matrices sage: sage.groups.perm_gps.partn_ref.refinement_matrices.random_tests() # long time (up to 30s on sage.math, 2011) All passed: ... random tests on ... matrices. - """ - from sage.misc.misc import walltime from sage.misc.prandom import random, randint from sage.combinat.permutation import Permutations from sage.matrix.constructor import random_matrix, matrix diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_python.pyx b/src/sage/groups/perm_gps/partn_ref/refinement_python.pyx index a24b0499888..bf4eae44469 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_python.pyx +++ b/src/sage/groups/perm_gps/partn_ref/refinement_python.pyx @@ -27,7 +27,7 @@ debugger. # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ #***************************************************************************** from cysignals.memory cimport sig_malloc, sig_free @@ -35,7 +35,7 @@ from cysignals.memory cimport sig_malloc, sig_free from .data_structures cimport * from .automorphism_group_canonical_label cimport ( get_aut_gp_and_can_lab, aut_gp_and_can_lab, - allocate_agcl_output, deallocate_agcl_output) + deallocate_agcl_output) from .double_coset cimport double_coset from sage.rings.integer cimport Integer diff --git a/src/sage/groups/perm_gps/permgroup_element.pyx b/src/sage/groups/perm_gps/permgroup_element.pyx index 1ea9a767fe7..5144a0ee009 100644 --- a/src/sage/groups/perm_gps/permgroup_element.pyx +++ b/src/sage/groups/perm_gps/permgroup_element.pyx @@ -109,9 +109,6 @@ Check that :trac:`13569` is fixed:: # **************************************************************************** import copy -import random - -import sage.groups.old as group from libc.stdlib cimport qsort @@ -128,7 +125,6 @@ from sage.rings.polynomial.polynomial_element import Polynomial from sage.structure.element import is_Matrix from sage.matrix.matrix_space import MatrixSpace from sage.sets.finite_enumerated_set import FiniteEnumeratedSet -import sage.structure.coerce as coerce from sage.structure.richcmp cimport richcmp_not_equal, rich_to_bool from sage.structure.coerce cimport coercion_model from sage.interfaces.abc import GpElement @@ -137,8 +133,8 @@ import sage.interfaces.abc from sage.libs.gap.libgap import libgap from sage.libs.gap.gap_includes cimport (UInt, UInt2, UInt4, T_PERM2, T_PERM4, - NEW_PERM2, NEW_PERM4, TNUM_OBJ, DEG_PERM2, DEG_PERM4, CONST_ADDR_PERM2, - CONST_ADDR_PERM4, ADDR_PERM2, ADDR_PERM4) + NEW_PERM2, TNUM_OBJ, DEG_PERM2, DEG_PERM4, CONST_ADDR_PERM2, + CONST_ADDR_PERM4, ADDR_PERM2) from sage.libs.gap.util cimport initialize from sage.libs.gap.element cimport (GapElement, GapElement_List, GapElement_String, GapElement_Permutation, make_GapElement_Permutation) diff --git a/src/sage/interacts/library_cython.pyx b/src/sage/interacts/library_cython.pyx index daf20c648c8..5f0ff8e7d96 100644 --- a/src/sage/interacts/library_cython.pyx +++ b/src/sage/interacts/library_cython.pyx @@ -6,18 +6,15 @@ AUTHORS: - Harald Schilly (2011-01-16): initial version (#9623) partially based on work by Lauri Ruotsalainen """ - #***************************************************************************** # Copyright (C) 2011 Harald Schilly # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ #***************************************************************************** -from sage.misc.misc_c import prod - cpdef julia(ff_j, z, int iterations): """ From 6b6a50eb0630bcd70f23104db2e1eddd065be7a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 23 May 2023 14:00:47 +0200 Subject: [PATCH 51/98] cylint: remove unused imports in matrix folder --- src/sage/matrix/matrix0.pyx | 4 +--- src/sage/matrix/matrix2.pyx | 5 ++--- src/sage/matrix/matrix_cyclo_dense.pyx | 8 +++----- src/sage/matrix/matrix_dense.pyx | 1 - src/sage/matrix/matrix_gap.pyx | 1 - src/sage/matrix/matrix_generic_sparse.pyx | 4 ---- src/sage/matrix/matrix_gf2e_dense.pyx | 8 ++++---- src/sage/matrix/matrix_gfpn_dense.pyx | 7 +------ src/sage/matrix/matrix_integer_dense.pyx | 2 -- src/sage/matrix/matrix_integer_sparse.pyx | 2 +- src/sage/matrix/matrix_mod2_dense.pyx | 3 +-- src/sage/matrix/matrix_modn_sparse.pyx | 9 +-------- src/sage/matrix/matrix_mpolynomial_dense.pyx | 7 +------ src/sage/matrix/matrix_numpy_dense.pyx | 1 - src/sage/matrix/matrix_polynomial_dense.pyx | 1 - src/sage/matrix/matrix_rational_dense.pyx | 1 - src/sage/matrix/matrix_sparse.pyx | 4 +--- src/sage/matrix/matrix_symbolic_dense.pyx | 4 ++-- src/sage/matrix/misc.pyx | 3 +-- 19 files changed, 19 insertions(+), 56 deletions(-) diff --git a/src/sage/matrix/matrix0.pyx b/src/sage/matrix/matrix0.pyx index d3a5fee358e..5547cea4dba 100644 --- a/src/sage/matrix/matrix0.pyx +++ b/src/sage/matrix/matrix0.pyx @@ -30,13 +30,11 @@ import sage.misc.latex import sage.rings.integer from sage.arith.power cimport generic_power -from sage.misc.verbose import verbose, get_verbose from sage.structure.sequence import Sequence from sage.structure.parent cimport Parent cimport sage.structure.element -from sage.structure.element cimport ModuleElement, Element, RingElement, Vector -from sage.structure.mutability cimport Mutability +from sage.structure.element cimport Element, Vector from sage.misc.misc_c cimport normalize_index from sage.categories.fields import Fields diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index e2e6449dfa9..81307099be8 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -80,19 +80,18 @@ from cpython cimport * from cysignals.signals cimport sig_check from sage.misc.lazy_string import lazy_string -from sage.misc.randstate cimport randstate, current_randstate +from sage.misc.randstate cimport current_randstate from sage.structure.coerce cimport py_scalar_parent from sage.structure.sequence import Sequence from sage.structure.coerce cimport coercion_model from sage.structure.element import is_Vector from sage.structure.element cimport have_same_parent -from sage.misc.verbose import verbose, get_verbose +from sage.misc.verbose import verbose from sage.categories.fields import Fields from sage.categories.integral_domains import IntegralDomains from sage.rings.ring import is_Ring from sage.rings.number_field.number_field_base import NumberField from sage.rings.integer_ring import ZZ, is_IntegerRing -from sage.rings.integer import Integer from sage.rings.rational_field import QQ, is_RationalField import sage.rings.abc from sage.arith.numerical_approx cimport digits_to_bits diff --git a/src/sage/matrix/matrix_cyclo_dense.pyx b/src/sage/matrix/matrix_cyclo_dense.pyx index fbe06c1808b..363fe637e93 100644 --- a/src/sage/matrix/matrix_cyclo_dense.pyx +++ b/src/sage/matrix/matrix_cyclo_dense.pyx @@ -47,13 +47,13 @@ from cysignals.signals cimport sig_on, sig_off include "sage/libs/ntl/decl.pxi" -from sage.structure.element cimport ModuleElement, RingElement, Element, Vector +from sage.structure.element cimport Element from sage.misc.randstate cimport randstate, current_randstate from sage.libs.gmp.randomize cimport * from sage.libs.flint.types cimport fmpz_t, fmpq -from sage.libs.flint.fmpz cimport fmpz_init, fmpz_clear, fmpz_set, fmpz_set_mpz, fmpz_one, fmpz_get_mpz, fmpz_add, fmpz_mul, fmpz_sub, fmpz_mul_si, fmpz_mul_si, fmpz_mul_si, fmpz_divexact, fmpz_lcm -from sage.libs.flint.fmpq cimport fmpq_is_zero, fmpq_get_mpq, fmpq_set_mpq, fmpq_canonicalise +from sage.libs.flint.fmpz cimport fmpz_init, fmpz_clear, fmpz_set_mpz, fmpz_one, fmpz_get_mpz, fmpz_add, fmpz_mul, fmpz_sub, fmpz_mul_si, fmpz_mul_si, fmpz_mul_si, fmpz_divexact, fmpz_lcm +from sage.libs.flint.fmpq cimport fmpq_is_zero, fmpq_set_mpq, fmpq_canonicalise from sage.libs.flint.fmpq_mat cimport fmpq_mat_entry_num, fmpq_mat_entry_den, fmpq_mat_entry from .args cimport MatrixArgs_init @@ -70,14 +70,12 @@ from sage.rings.rational_field import QQ from sage.rings.integer_ring import ZZ from sage.rings.real_mpfr import create_RealNumber as RealNumber from sage.rings.integer cimport Integer -from sage.rings.rational cimport Rational from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.number_field.number_field_element cimport NumberFieldElement from sage.rings.number_field.number_field_element_quadratic cimport NumberFieldElement_quadratic from sage.structure.proof.proof import get_flag as get_proof_flag from sage.misc.verbose import verbose -import math from sage.matrix.matrix_modn_dense_double import MAX_MODULUS as MAX_MODULUS_modn_dense_double from sage.arith.multi_modular import MAX_MODULUS as MAX_MODULUS_multi_modular diff --git a/src/sage/matrix/matrix_dense.pyx b/src/sage/matrix/matrix_dense.pyx index afc24c658e6..164846caba1 100644 --- a/src/sage/matrix/matrix_dense.pyx +++ b/src/sage/matrix/matrix_dense.pyx @@ -10,7 +10,6 @@ TESTS:: cimport sage.matrix.matrix as matrix -from sage.structure.element cimport Element, RingElement from sage.structure.richcmp cimport richcmp_item, rich_to_bool import sage.matrix.matrix_space import sage.structure.sequence diff --git a/src/sage/matrix/matrix_gap.pyx b/src/sage/matrix/matrix_gap.pyx index 8485760e9cb..f3f77dcbe15 100644 --- a/src/sage/matrix/matrix_gap.pyx +++ b/src/sage/matrix/matrix_gap.pyx @@ -12,7 +12,6 @@ Wrappers on GAP matrices # **************************************************************************** from sage.libs.gap.libgap import libgap -from . import matrix_space from sage.structure.element cimport Matrix from .args cimport MatrixArgs_init diff --git a/src/sage/matrix/matrix_generic_sparse.pyx b/src/sage/matrix/matrix_generic_sparse.pyx index a342d5b7353..df138cfab3f 100644 --- a/src/sage/matrix/matrix_generic_sparse.pyx +++ b/src/sage/matrix/matrix_generic_sparse.pyx @@ -52,14 +52,10 @@ EXAMPLES:: sage: c.is_sparse() True """ - -cimport sage.matrix.matrix as matrix cimport sage.matrix.matrix_sparse as matrix_sparse cimport sage.structure.element -from sage.structure.element cimport ModuleElement from .args cimport MatrixArgs_init -import sage.misc.misc as misc cdef class Matrix_generic_sparse(matrix_sparse.Matrix_sparse): r""" diff --git a/src/sage/matrix/matrix_gf2e_dense.pyx b/src/sage/matrix/matrix_gf2e_dense.pyx index 922f6288696..fe8cfb0d38b 100644 --- a/src/sage/matrix/matrix_gf2e_dense.pyx +++ b/src/sage/matrix/matrix_gf2e_dense.pyx @@ -83,11 +83,11 @@ REFERENCES: # https://www.gnu.org/licenses/ #***************************************************************************** -from cysignals.signals cimport sig_check, sig_on, sig_off +from cysignals.signals cimport sig_on, sig_off cimport sage.matrix.matrix_dense as matrix_dense -from sage.structure.element cimport Matrix, Vector -from sage.structure.element cimport ModuleElement, Element, RingElement +from sage.structure.element cimport Matrix +from sage.structure.element cimport Element from sage.structure.richcmp cimport rich_to_bool from sage.rings.finite_rings.element_base cimport Cache_base @@ -97,7 +97,7 @@ from sage.misc.randstate cimport randstate, current_randstate from sage.matrix.matrix_mod2_dense cimport Matrix_mod2_dense from .args cimport SparseEntry, MatrixArgs_init -from sage.libs.m4ri cimport m4ri_word, mzd_copy, mzd_init +from sage.libs.m4ri cimport m4ri_word, mzd_copy from sage.libs.m4rie cimport * from sage.libs.m4rie cimport mzed_t diff --git a/src/sage/matrix/matrix_gfpn_dense.pyx b/src/sage/matrix/matrix_gfpn_dense.pyx index 7d605da8426..abd0754db48 100644 --- a/src/sage/matrix/matrix_gfpn_dense.pyx +++ b/src/sage/matrix/matrix_gfpn_dense.pyx @@ -34,14 +34,11 @@ AUTHORS: # (at your option) any later version. # https://www.gnu.org/licenses/ # *************************************************************************** - from cysignals.memory cimport check_realloc, check_malloc, sig_free from cpython.bytes cimport PyBytes_AsString, PyBytes_FromStringAndSize from cysignals.signals cimport sig_on, sig_off, sig_check cimport cython -import os - #################### # # import sage types @@ -53,12 +50,10 @@ from sage.cpython.string import FS_ENCODING from sage.rings.integer import Integer from sage.rings.finite_rings.finite_field_constructor import GF from sage.rings.finite_rings.integer_mod import IntegerMod_int -from sage.matrix.constructor import random_matrix from sage.matrix.matrix_space import MatrixSpace from sage.misc.randstate import current_randstate from sage.misc.randstate cimport randstate -from sage.misc.cachefunc import cached_method, cached_function -from sage.structure.element cimport Element, ModuleElement, RingElement, Matrix +from sage.structure.element cimport Element, Matrix from sage.structure.richcmp import rich_to_bool from .args cimport MatrixArgs_init diff --git a/src/sage/matrix/matrix_integer_dense.pyx b/src/sage/matrix/matrix_integer_dense.pyx index 9a41264bc4f..a2c8f46247f 100644 --- a/src/sage/matrix/matrix_integer_dense.pyx +++ b/src/sage/matrix/matrix_integer_dense.pyx @@ -86,7 +86,6 @@ from sage.structure.proof.proof import get_flag as get_proof_flag from sage.structure.richcmp cimport rich_to_bool from sage.misc.randstate cimport randstate, current_randstate -from sage.matrix.matrix_rational_dense cimport Matrix_rational_dense from .args cimport SparseEntry, MatrixArgs_init ######################################################### @@ -114,7 +113,6 @@ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint from sage.structure.element cimport Element, Vector from sage.structure.element import is_Vector -from sage.structure.sequence import Sequence from .matrix_modn_dense_float cimport Matrix_modn_dense_template from .matrix_modn_dense_float cimport Matrix_modn_dense_float diff --git a/src/sage/matrix/matrix_integer_sparse.pyx b/src/sage/matrix/matrix_integer_sparse.pyx index a73432e588c..e8f374d0e71 100644 --- a/src/sage/matrix/matrix_integer_sparse.pyx +++ b/src/sage/matrix/matrix_integer_sparse.pyx @@ -62,7 +62,7 @@ from sage.libs.flint.fmpz_poly cimport fmpz_poly_fit_length, fmpz_poly_set_coeff from sage.libs.flint.fmpz_mat cimport fmpz_mat_entry from .matrix_modn_sparse cimport Matrix_modn_sparse -from sage.structure.element cimport ModuleElement, RingElement, Element, Vector +from sage.structure.element cimport Element import sage.matrix.matrix_space as matrix_space diff --git a/src/sage/matrix/matrix_mod2_dense.pyx b/src/sage/matrix/matrix_mod2_dense.pyx index 4d83f299d1c..d5a368d9b70 100644 --- a/src/sage/matrix/matrix_mod2_dense.pyx +++ b/src/sage/matrix/matrix_mod2_dense.pyx @@ -106,7 +106,7 @@ TESTS:: # **************************************************************************** from cysignals.memory cimport check_malloc, sig_free -from cysignals.signals cimport sig_check, sig_on, sig_str, sig_off +from cysignals.signals cimport sig_on, sig_str, sig_off cimport sage.matrix.matrix_dense as matrix_dense from .args cimport SparseEntry, MatrixArgs_init @@ -115,7 +115,6 @@ from sage.structure.element cimport (Matrix, Vector) from sage.modules.free_module_element cimport FreeModuleElement from sage.libs.gmp.random cimport * from sage.misc.randstate cimport randstate, current_randstate -from sage.misc.misc import cputime from sage.misc.verbose import verbose, get_verbose VectorSpace = None from sage.modules.vector_mod2_dense cimport Vector_mod2_dense diff --git a/src/sage/matrix/matrix_modn_sparse.pyx b/src/sage/matrix/matrix_modn_sparse.pyx index 8e7e49cd90c..dd908a4c91b 100644 --- a/src/sage/matrix/matrix_modn_sparse.pyx +++ b/src/sage/matrix/matrix_modn_sparse.pyx @@ -83,7 +83,7 @@ TESTS:: from libc.stdint cimport uint64_t from libc.limits cimport UINT_MAX -from cysignals.memory cimport check_calloc, sig_malloc, sig_free +from cysignals.memory cimport check_calloc, sig_free from cysignals.signals cimport sig_on, sig_off from sage.ext.stdsage cimport PY_NEW @@ -91,7 +91,6 @@ from sage.ext.stdsage cimport PY_NEW from sage.libs.flint.fmpz cimport fmpz_get_mpz, fmpz_set_mpz from sage.libs.flint.fmpz_mat cimport fmpz_mat_entry -from sage.structure.element import is_Vector from sage.modules.vector_modn_sparse cimport * cimport sage.libs.linbox.givaro as givaro @@ -100,7 +99,6 @@ cimport sage.libs.linbox.linbox as linbox from sage.libs.linbox.conversion cimport * from .matrix2 cimport Matrix -from sage.libs.gmp.mpz cimport mpz_init_set_si cimport sage.matrix.matrix as matrix cimport sage.matrix.matrix_sparse as matrix_sparse cimport sage.matrix.matrix_dense as matrix_dense @@ -115,19 +113,14 @@ from sage.matrix.matrix2 import Matrix as Matrix2 from .args cimport SparseEntry, MatrixArgs_init from sage.arith.misc import is_prime -from sage.structure.element import is_Vector - cimport sage.structure.element from sage.data_structures.binary_search cimport * from sage.modules.vector_integer_sparse cimport * -from .matrix_integer_sparse cimport Matrix_integer_sparse from .matrix_integer_dense cimport Matrix_integer_dense from sage.modules.vector_integer_dense cimport Vector_integer_dense -from sage.misc.decorators import rename_keyword - ################ # TODO: change this to use extern cdef's methods. from sage.rings.fast_arith cimport arith_int diff --git a/src/sage/matrix/matrix_mpolynomial_dense.pyx b/src/sage/matrix/matrix_mpolynomial_dense.pyx index ae5886b73ed..814e0d0b135 100644 --- a/src/sage/matrix/matrix_mpolynomial_dense.pyx +++ b/src/sage/matrix/matrix_mpolynomial_dense.pyx @@ -15,16 +15,11 @@ AUTHOR: # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ #***************************************************************************** - - -from sage.rings.polynomial.multi_polynomial_libsingular cimport new_MP - from sage.matrix.matrix_generic_dense cimport Matrix_generic_dense from sage.matrix.matrix2 cimport Matrix -from sage.rings.polynomial.multi_polynomial_libsingular cimport MPolynomial_libsingular from sage.rings.polynomial.multi_polynomial_libsingular cimport MPolynomialRing_libsingular from sage.rings.polynomial.polynomial_singular_interface import can_convert_to_singular diff --git a/src/sage/matrix/matrix_numpy_dense.pyx b/src/sage/matrix/matrix_numpy_dense.pyx index 6a3dafbb07a..5b75ed133ff 100644 --- a/src/sage/matrix/matrix_numpy_dense.pyx +++ b/src/sage/matrix/matrix_numpy_dense.pyx @@ -39,7 +39,6 @@ AUTHORS: # https://www.gnu.org/licenses/ # **************************************************************************** -from .matrix cimport Matrix from .args cimport MatrixArgs_init cimport sage.structure.element diff --git a/src/sage/matrix/matrix_polynomial_dense.pyx b/src/sage/matrix/matrix_polynomial_dense.pyx index c3fd4d5bf61..c8cf66ec9f7 100644 --- a/src/sage/matrix/matrix_polynomial_dense.pyx +++ b/src/sage/matrix/matrix_polynomial_dense.pyx @@ -39,7 +39,6 @@ AUTHORS: from sage.matrix.matrix_generic_dense cimport Matrix_generic_dense from sage.matrix.matrix2 cimport Matrix -from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ diff --git a/src/sage/matrix/matrix_rational_dense.pyx b/src/sage/matrix/matrix_rational_dense.pyx index 66de04c4bc5..c9e1d87b049 100644 --- a/src/sage/matrix/matrix_rational_dense.pyx +++ b/src/sage/matrix/matrix_rational_dense.pyx @@ -119,7 +119,6 @@ from sage.misc.verbose import verbose # ######################################################## # PARI C library -from cypari2.gen cimport Gen from sage.libs.pari.all import PariError from sage.libs.pari.convert_gmp cimport INTFRAC_to_mpq from sage.libs.pari.convert_flint cimport rational_matrix, _new_GEN_from_fmpq_mat_t diff --git a/src/sage/matrix/matrix_sparse.pyx b/src/sage/matrix/matrix_sparse.pyx index dcd9c2e1550..e429b028e0c 100644 --- a/src/sage/matrix/matrix_sparse.pyx +++ b/src/sage/matrix/matrix_sparse.pyx @@ -1,7 +1,6 @@ r""" Base class for sparse matrices """ - # **************************************************************************** # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,10 +15,9 @@ from cysignals.signals cimport sig_check cimport sage.matrix.matrix as matrix cimport sage.matrix.matrix0 as matrix0 -from sage.structure.element cimport Element, RingElement, ModuleElement, Vector +from sage.structure.element cimport Element, Vector from sage.structure.richcmp cimport richcmp_item, rich_to_bool from sage.rings.ring import is_Ring -from sage.misc.verbose import verbose from cpython cimport * from cpython.object cimport Py_EQ, Py_NE diff --git a/src/sage/matrix/matrix_symbolic_dense.pyx b/src/sage/matrix/matrix_symbolic_dense.pyx index 19ca5c85cb2..ceaa32abedb 100644 --- a/src/sage/matrix/matrix_symbolic_dense.pyx +++ b/src/sage/matrix/matrix_symbolic_dense.pyx @@ -155,7 +155,6 @@ Check that :trac:`12778` is fixed:: """ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing -from sage.structure.element cimport ModuleElement, RingElement, Element from sage.structure.factorization import Factorization from .matrix_generic_dense cimport Matrix_generic_dense @@ -163,7 +162,8 @@ from .constructor import matrix cdef maxima -from sage.calculus.calculus import symbolic_expression_from_maxima_string, maxima +from sage.calculus.calculus import maxima + cdef class Matrix_symbolic_dense(Matrix_generic_dense): def echelonize(self, **kwds): diff --git a/src/sage/matrix/misc.pyx b/src/sage/matrix/misc.pyx index 25cffdeef0a..8d5bd2c9b4c 100644 --- a/src/sage/matrix/misc.pyx +++ b/src/sage/matrix/misc.pyx @@ -24,12 +24,11 @@ from sage.libs.flint.fmpz cimport fmpz_set_mpz, fmpz_one from sage.libs.gmp.mpq cimport * from sage.libs.gmp.mpz cimport * from sage.libs.mpfr cimport * -from sage.misc.verbose import get_verbose, verbose +from sage.misc.verbose import verbose from sage.modules.vector_integer_sparse cimport * from sage.modules.vector_modn_sparse cimport * from sage.modules.vector_rational_sparse cimport * from sage.rings.integer cimport Integer -from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ from sage.rings.real_mpfr cimport RealNumber From 00e9d18d9a9727a6cc87ad1b1cef118b530a7ba2 Mon Sep 17 00:00:00 2001 From: Dima Pasechnik Date: Tue, 23 May 2023 13:25:18 +0100 Subject: [PATCH 52/98] correct lastest version in comment --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index fe8ae3efd1c..b125789ed78 100644 --- a/tox.ini +++ b/tox.ini @@ -356,7 +356,7 @@ setenv = # # https://hub.docker.com/r/opensuse/leap # - OpenSUSE Leap 42 was superseded by the Leap 15 series. - # - As of 2023-05, latest = 15 = 15.4 + # - As of 2023-05, latest = 15 = 15.5 # https://hub.docker.com/r/opensuse/tumbleweed # - Rolling distribution # From 06ab3cb5d1536636545054996f16be25223f71bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 23 May 2023 21:04:19 +0200 Subject: [PATCH 53/98] fixing some pycodestyle warnings in schemes/elliptic_curves --- src/sage/schemes/elliptic_curves/cm.py | 17 +-- .../schemes/elliptic_curves/ec_database.py | 4 +- .../elliptic_curves/ell_curve_isogeny.py | 24 ++-- src/sage/schemes/elliptic_curves/ell_field.py | 2 +- .../elliptic_curves/ell_finite_field.py | 18 +-- .../elliptic_curves/ell_modular_symbols.py | 10 +- .../elliptic_curves/ell_rational_field.py | 48 ++++---- src/sage/schemes/elliptic_curves/ell_wp.py | 18 ++- src/sage/schemes/elliptic_curves/gal_reps.py | 46 ++++---- src/sage/schemes/elliptic_curves/gp_simon.py | 6 +- src/sage/schemes/elliptic_curves/heegner.py | 106 +++++++++--------- src/sage/schemes/elliptic_curves/height.py | 11 +- .../schemes/elliptic_curves/hom_velusqrt.py | 2 +- .../schemes/elliptic_curves/isogeny_class.py | 4 +- .../elliptic_curves/isogeny_small_degree.py | 10 +- .../schemes/elliptic_curves/kodaira_symbol.py | 4 +- src/sage/schemes/elliptic_curves/kraus.py | 8 +- .../schemes/elliptic_curves/lseries_ell.py | 2 +- .../schemes/elliptic_curves/mod5family.py | 2 +- .../schemes/elliptic_curves/padic_lseries.py | 102 ++++++++--------- src/sage/schemes/elliptic_curves/padics.py | 6 +- .../schemes/elliptic_curves/period_lattice.py | 43 ++++--- 22 files changed, 248 insertions(+), 245 deletions(-) diff --git a/src/sage/schemes/elliptic_curves/cm.py b/src/sage/schemes/elliptic_curves/cm.py index 57f8744dc80..75432147b01 100644 --- a/src/sage/schemes/elliptic_curves/cm.py +++ b/src/sage/schemes/elliptic_curves/cm.py @@ -157,7 +157,7 @@ def hilbert_class_polynomial(D, algorithm=None): h = len(rqf) # class number c1 = 3.05682737291380 # log(2*10.63) c2 = sum([1/RR(qf[0]) for qf in rqf], RR(0)) - prec = c2*RR(3.142)*RR(D).abs().sqrt() + h*c1 # bound on log + prec = c2 * RR(3.142) * RR(D).abs().sqrt() + h * c1 # bound on log prec = prec * 1.45 # bound on log_2 (1/log(2) = 1.44..) prec = 10 + prec.ceil() # allow for rounding error @@ -242,7 +242,8 @@ def is_HCP(f, check_monic_irreducible=True): from sage.rings.finite_rings.finite_field_constructor import GF h = f.degree() - h2list = [d for d in h.divisors() if (d-h)%2 == 0 and d.prime_to_m_part(2) == 1] + h2list = [d for d in h.divisors() + if (d-h) % 2 == 0 and d.prime_to_m_part(2) == 1] pmin = 33 * (h**2 * (RR(h+2).log().log()+2)**2).ceil() # Guarantees 4*p > |D| for fundamental D under GRH p = pmin-1 @@ -831,7 +832,7 @@ def discriminants_with_bounded_class_number(hmax, B=None, proof=None): if not D.is_discriminant(): continue D0 = D.squarefree_part() - if D0%4 !=1: + if D0 % 4 != 1: D0 *= 4 f = (D//D0).isqrt() @@ -983,10 +984,10 @@ def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None): D = is_HCP(jpol, check_monic_irreducible=False) if D: D0 = D.squarefree_part() - if D0%4 !=1: + if D0 % 4 != 1: D0 *= 4 - f = ZZ(D//D0).isqrt() - return (True, (D0,f)) + f = ZZ(D // D0).isqrt() + return (True, (D0, f)) else: return (False, None) @@ -1020,8 +1021,8 @@ def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None): from sage.schemes.elliptic_curves.constructor import EllipticCurve E = EllipticCurve(j=j).integral_model() D = E.discriminant() - prime_bound = 1000 # test primes of degree 1 up to this norm - max_primes = 20 # test at most this many primes + prime_bound = 1000 # test primes of degree 1 up to this norm + max_primes = 20 # test at most this many primes num_prime = 0 cmd = 0 cmf = 0 diff --git a/src/sage/schemes/elliptic_curves/ec_database.py b/src/sage/schemes/elliptic_curves/ec_database.py index 375e01fa93a..7975ec7edaf 100644 --- a/src/sage/schemes/elliptic_curves/ec_database.py +++ b/src/sage/schemes/elliptic_curves/ec_database.py @@ -133,7 +133,7 @@ def rank(self, rank, tors=0, n=10, labels=False): [] """ from sage.env import ELLCURVE_DATA_DIR - data = os.path.join(ELLCURVE_DATA_DIR, 'rank%s'%rank) + data = os.path.join(ELLCURVE_DATA_DIR, 'rank%s' %rank) try: f = open(data) except IOError: @@ -151,7 +151,7 @@ def rank(self, rank, tors=0, n=10, labels=False): # NOTE: only change this bound below after checking/fixing # the Cremona labels in the elliptic_curves package! if N <= 400000: - label = '%s%s%s'%(N, iso, num) + label = '%s%s%s' %(N, iso, num) else: label = None diff --git a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py index 9e1d9473081..6e09633afb4 100644 --- a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py +++ b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py @@ -483,13 +483,13 @@ def compute_codomain_kohel(E, kernel): v, w = compute_vw_kohel_even_deg1(x0, y0, a1, a2, a4) - elif n == 3: # psi_2tor is the full 2-division polynomial + elif n == 3: # psi_2tor is the full 2-division polynomial b2, b4, _, _ = E.b_invariants() - s1 = -psi_2tor[n-1] - s2 = psi_2tor[n-2] - s3 = -psi_2tor[n-3] + s1 = -psi_2tor[n - 1] + s2 = psi_2tor[n - 2] + s3 = -psi_2tor[n - 3] v, w = compute_vw_kohel_even_deg3(b2, b4, s1, s2, s3) @@ -499,9 +499,9 @@ def compute_codomain_kohel(E, kernel): b2, b4, b6, _ = E.b_invariants() - s1 = -psi[n-1] if n >= 1 else 0 - s2 = psi[n-2] if n >= 2 else 0 - s3 = -psi[n-3] if n >= 3 else 0 + s1 = -psi[n - 1] if n >= 1 else 0 + s2 = psi[n - 2] if n >= 2 else 0 + s3 = -psi[n - 3] if n >= 3 else 0 # initializing these allows us to calculate E2. v, w = compute_vw_kohel_odd(b2, b4, b6, s1, s2, s3, n) @@ -1893,7 +1893,7 @@ def __init_from_kernel_list(self, kernel_gens): to Elliptic Curve defined by y^2 = x^3 + 80816485163488178037199320944019099858815874115367810482828676054000067654558381377552245721755005198633191074893*x + 301497584865165444049833326660609767433467459033532853758006118022998267706948164646650354324860226263546558337993 over Finite Field of size 461742260113997803268895001173557974278278194575766957660028841364655249961609425998827452443620996655395008156411 """ - if self.__check : + if self.__check: for P in kernel_gens: if not P.has_finite_order(): raise ValueError("given kernel contains point of infinite order") @@ -2337,7 +2337,7 @@ def __init_even_kernel_polynomial(self, E, psi_G): (x^7 + 5*x^6 + 2*x^5 + 6*x^4 + 3*x^3 + 5*x^2 + 6*x + 3, (x^9 + 4*x^8 + 2*x^7 + 4*x^3 + 2*x^2 + x + 6)*y, 1, 6, 3, 4) """ # check if the polynomial really divides the two_torsion_polynomial - if self.__check and E.division_polynomial(2, x=self.__poly_ring.gen()) % psi_G != 0 : + if self.__check and E.division_polynomial(2, x=self.__poly_ring.gen()) % psi_G != 0: raise ValueError(f"the polynomial {psi_G} does not define a finite subgroup of {E}") n = psi_G.degree() # 1 or 3 @@ -2363,9 +2363,9 @@ def __init_even_kernel_polynomial(self, E, psi_G): omega = (y*psi_G**2 - v*(a1*psi_G + (y - y0)))*psi_G elif n == 3: - s1 = -psi_G[n-1] - s2 = psi_G[n-2] - s3 = -psi_G[n-3] + s1 = -psi_G[n - 1] + s2 = psi_G[n - 2] + s3 = -psi_G[n - 3] psi_G_pr = psi_G.derivative() psi_G_prpr = psi_G_pr.derivative() diff --git a/src/sage/schemes/elliptic_curves/ell_field.py b/src/sage/schemes/elliptic_curves/ell_field.py index 457ab8f7e78..34171c2c04b 100644 --- a/src/sage/schemes/elliptic_curves/ell_field.py +++ b/src/sage/schemes/elliptic_curves/ell_field.py @@ -155,7 +155,7 @@ def quadratic_twist(self, D=None): # degree is odd we can take D=1; otherwise it suffices to # consider odd powers of a generator. D = K(1) - if K.degree()%2==0: + if K.degree() %2==0: D = K.gen() a = D**2 while (x**2 + x + D).roots(): diff --git a/src/sage/schemes/elliptic_curves/ell_finite_field.py b/src/sage/schemes/elliptic_curves/ell_finite_field.py index 67311df1789..fceaf24616a 100644 --- a/src/sage/schemes/elliptic_curves/ell_finite_field.py +++ b/src/sage/schemes/elliptic_curves/ell_finite_field.py @@ -1569,11 +1569,11 @@ def endomorphism_discriminant_from_class_number(self, h): raise ValueError("Elliptic curve ({}) must be ordinary".format(self)) D1 = self.frobenius_discriminant() D0 = D1.squarefree_part() - if D0%4 !=1: + if D0 %4 !=1: D0 *= 4 v = ZZ(D1//D0).isqrt() h0 = D0.class_number() - if h%h0: + if h %h0: raise ValueError("Incorrect class number {}".format(h)) from sage.schemes.elliptic_curves.cm import OrderClassNumber cs = [v//f for f in v.divisors() if OrderClassNumber(D0,h0,f) == h] # cofactors c=v/f compatible with h(f**2D0)=h @@ -1828,7 +1828,7 @@ def curves_with_j_0(K): if p==3: return curves_with_j_0_char3(K) q = K.cardinality() - if q%3==2: + if q %3==2: # Then we only have two quadratic twists (and -3 is non-square) return [EllipticCurve(K, [0,a]) for a in [1,-27]] # Now we have genuine sextic twists, find D generating K* mod 6th powers @@ -1885,7 +1885,7 @@ def curves_with_j_1728(K): if p==3: return curves_with_j_0_char3(K) q = K.cardinality() - if q%4==3: + if q %4==3: return [EllipticCurve(K, [a,0]) for a in [1,-1]] # Now we have genuine quartic twists, find D generating K* mod 4th powers q2 = (q-1)//2 @@ -1954,8 +1954,10 @@ def curves_with_j_0_char2(K): """ if not K.is_finite() or K.characteristic() != 2: raise ValueError("field must be finite of characteristic 2") - if K.degree()%2: - return [EllipticCurve(K,[0,0,1,0,0]), EllipticCurve(K,[0,0,1,1,0]), EllipticCurve(K,[0,0,1,1,1])] + if K.degree() % 2: + return [EllipticCurve(K, [0, 0, 1, 0, 0]), + EllipticCurve(K, [0, 0, 1, 1, 0]), + EllipticCurve(K, [0, 0, 1, 1, 1])] # find a,b,c,d,e such that # a is not a cube, i.e. a**((q-1)//3)!=1 # Tr(b)=1 @@ -1971,7 +1973,7 @@ def curves_with_j_0_char2(K): while not b or not b.trace(): b = K.random_element() c = K.one() # OK if degree is 2 mod 4 - if K.degree()%4 == 0: + if K.degree() %4 == 0: while (x**4+x+c).roots(): c = K.random_element() while not d or (x**2+a*x+d).roots(): @@ -2048,7 +2050,7 @@ def curves_with_j_0_char3(K): while not b or not b.trace(): b = K.random_element() - if K.degree()%2: + if K.degree() %2: return [EllipticCurve(K, a4a6) for a4a6 in [[1,0], [-1,0], [-1,b], [-1,-b]]] diff --git a/src/sage/schemes/elliptic_curves/ell_modular_symbols.py b/src/sage/schemes/elliptic_curves/ell_modular_symbols.py index d2f92b789c8..5fc0398b20e 100644 --- a/src/sage/schemes/elliptic_curves/ell_modular_symbols.py +++ b/src/sage/schemes/elliptic_curves/ell_modular_symbols.py @@ -219,7 +219,7 @@ def _repr_(self): Modular symbol with sign -1 over Rational Field attached to Elliptic Curve defined by y^2 + y = x^3 + x^2 over Rational Field """ - return "Modular symbol with sign %s over %s attached to %s"%( + return "Modular symbol with sign %s over %s attached to %s" %( self._sign, self._base_ring, self._E) class ModularSymbolECLIB(ModularSymbol): @@ -468,7 +468,7 @@ def __init__(self, E, sign, normalize="L_ratio"): self._scaling = 1 self._e = self._modsym.dual_eigenvector() else : - raise ValueError("no normalization %s known for modular symbols"%normalize) + raise ValueError("no normalization %s known for modular symbols" %normalize) def _find_scaling_L_ratio(self): r""" @@ -553,7 +553,7 @@ def _find_scaling_L_ratio(self): if at0 != 0 : l1 = self.__lalg__(1) if at0 != l1: - verbose('scale modular symbols by %s'%(l1/at0)) + verbose('scale modular symbols by %s' %(l1/at0)) self._scaling = l1/at0 else : # if [0] = 0, we can still hope to scale it correctly by considering twists of E @@ -574,7 +574,7 @@ def _find_scaling_L_ratio(self): else : l1 = self.__lalg__(D) if at0 != l1: - verbose('scale modular symbols by %s found at D=%s '%(l1/at0,D), level=2) + verbose('scale modular symbols by %s found at D=%s ' %(l1/at0,D), level=2) self._scaling = l1/at0 else : # that is when sign = -1 @@ -593,7 +593,7 @@ def _find_scaling_L_ratio(self): else : l1 = self.__lalg__(D) if at0 != l1: - verbose('scale modular symbols by %s'%(l1/at0)) + verbose('scale modular symbols by %s' %(l1/at0)) self._scaling = l1/at0 def __lalg__(self, D): diff --git a/src/sage/schemes/elliptic_curves/ell_rational_field.py b/src/sage/schemes/elliptic_curves/ell_rational_field.py index 420a6c7cc77..edbd87412f1 100644 --- a/src/sage/schemes/elliptic_curves/ell_rational_field.py +++ b/src/sage/schemes/elliptic_curves/ell_rational_field.py @@ -539,7 +539,7 @@ def conductor(self, algorithm="pari"): try: return self.__conductor_gp except AttributeError: - self.__conductor_gp = Integer(gp.eval('ellglobalred(ellinit(%s,0))[1]'%list(self.a_invariants()))) + self.__conductor_gp = Integer(gp.eval('ellglobalred(ellinit(%s,0))[1]' %list(self.a_invariants()))) return self.__conductor_gp elif algorithm == "mwrank": @@ -565,11 +565,11 @@ def conductor(self, algorithm="pari"): N3 = self.conductor("gp") N4 = self.conductor("generic") if N1 != N2 or N2 != N3 or N2 != N4: - raise ArithmeticError("PARI, mwrank, gp and Sage compute different conductors (%s,%s,%s,%s) for %s"%( + raise ArithmeticError("PARI, mwrank, gp and Sage compute different conductors (%s,%s,%s,%s) for %s" %( N1, N2, N3, N4, self)) return N1 else: - raise ValueError("algorithm %r is not known"%algorithm) + raise ValueError("algorithm %r is not known" %algorithm) #################################################################### # Access to PARI curves related to this curve. @@ -711,13 +711,13 @@ def database_curve(self): try: return self.__database_curve except AttributeError: - verbose_verbose("Looking up %s in the database."%self) + verbose_verbose("Looking up %s in the database." %self) D = sage.databases.cremona.CremonaDatabase() ainvs = list(self.minimal_model().ainvs()) try: self.__database_curve = D.elliptic_curve_from_ainvs(ainvs) except RuntimeError: - raise RuntimeError("Elliptic curve %s not in the database."%self) + raise RuntimeError("Elliptic curve %s not in the database." %self) return self.__database_curve def Np(self, p): @@ -910,7 +910,7 @@ def anlist(self, n, python_ints=False): n = int(n) e = self.pari_mincurve() if n >= 2147483648: - raise RuntimeError("anlist: n (=%s) must be < 2147483648."%n) + raise RuntimeError("anlist: n (=%s) must be < 2147483648." %n) v = [0] + e.ellan(n, python_ints=True) if not python_ints: @@ -1535,7 +1535,7 @@ def analytic_rank(self, algorithm="pari", leading_coefficient=False): from sage.lfunctions.lcalc import lcalc return lcalc.analytic_rank(L=self) except TypeError as msg: - raise RuntimeError("unable to compute analytic rank using rubinstein algorithm (%s)"%msg) + raise RuntimeError("unable to compute analytic rank using rubinstein algorithm (%s)" %msg) elif algorithm == 'sympow': if leading_coefficient: raise NotImplementedError("Cannot compute leading coefficient using sympow") @@ -1561,7 +1561,7 @@ def analytic_rank(self, algorithm="pari", leading_coefficient=False): raise RuntimeError("Bug in analytic_rank; algorithms don't agree! (E=%s)" % self) return list(S)[0] else: - raise ValueError("algorithm %s not defined"%algorithm) + raise ValueError("algorithm %s not defined" %algorithm) def analytic_rank_upper_bound(self, max_Delta=None, @@ -2095,7 +2095,7 @@ def rank(self, use_database=True, verbose=False, # true rank rank_bound = self.analytic_rank_upper_bound() if rank_bound <= 1: - verbose_verbose("rank %s due to zero sum bound and parity"%rank_bound) + verbose_verbose("rank %s due to zero sum bound and parity" %rank_bound) rank = Integer(rank_bound) self.__rank = (rank, proof) return rank @@ -2113,7 +2113,7 @@ def rank(self, use_database=True, verbose=False, else: Lprime, err = self.lseries().deriv_at1(prec) if abs(Lprime) > err + R(0.0001): # definitely doesn't vanish - verbose_verbose("rank 1 because L'(E,1)=%s"%Lprime) + verbose_verbose("rank 1 because L'(E,1)=%s" %Lprime) rank = Integer(1) self.__rank = (rank, proof) return rank @@ -2162,7 +2162,7 @@ def rank(self, use_database=True, verbose=False, match = 'found points of rank' i = X.find(match) if i == -1: - raise RuntimeError("%s\nbug -- tried to find 'Rank =' or 'found points of rank' in mwrank output but couldn't."%X) + raise RuntimeError("%s\nbug -- tried to find 'Rank =' or 'found points of rank' in mwrank output but couldn't." %X) j = i + X[i:].find('\n') rank = Integer(X[i+len(match)+1:j]) self.__rank = (rank, proof) @@ -2320,7 +2320,7 @@ def _compute_gens(self, proof, verbose_verbose("Rank = 1, so using direct search.") h = 6 while h <= rank1_search: - verbose_verbose("Trying direct search up to height %s"%h) + verbose_verbose("Trying direct search up to height %s" %h) G = self.point_search(h, verbose) G = [P for P in G if P.order() == oo] if G: @@ -2636,7 +2636,7 @@ def saturation(self, points, verbose=False, max_prime=-1, min_prime=2): if not isinstance(P, ell_point.EllipticCurvePoint_field): P = self(P) elif P.curve() != self: - raise ArithmeticError("point (=%s) must be %s."%(P,self)) + raise ArithmeticError("point (=%s) must be %s." %(P,self)) minimal = True if not self.is_minimal(): @@ -2773,7 +2773,7 @@ def h_oo(x): elif algorithm == 'mwrank': return self.mwrank_curve().silverman_bound() else: - raise ValueError("unknown algorithm '%s'"%algorithm) + raise ValueError("unknown algorithm '%s'" %algorithm) def point_search(self, height_limit, verbose=False, rank_bound=None): r""" @@ -3183,7 +3183,7 @@ def tamagawa_exponent(self, p): if not cp==4: return cp ks = self.kodaira_type(p) - if ks._roman==1 and ks._n%2==0 and ks._starred: + if ks._roman==1 and ks._n %2==0 and ks._starred: return 2 return 4 @@ -3763,7 +3763,7 @@ def modular_degree(self, algorithm='sympow', M=1): from sage.interfaces.magma import magma m = rings.Integer(magma(self).ModularDegree()) else: - raise ValueError("unknown algorithm %s"%algorithm) + raise ValueError("unknown algorithm %s" %algorithm) self.__modular_degree = m return m @@ -4285,7 +4285,7 @@ def cm_discriminant(self): try: return ZZ(CMJ[self.j_invariant()]) except KeyError: - raise ValueError("%s does not have CM"%self) + raise ValueError("%s does not have CM" %self) def has_rational_cm(self, field=None): r""" @@ -4726,9 +4726,9 @@ def isogenies_prime_degree(self, l=None): if l.is_prime(proof=False): return isogenies_sporadic_Q(self, l) else: - raise ValueError("%s is not prime."%l) + raise ValueError("%s is not prime." %l) except AttributeError: - raise ValueError("%s is not prime."%l) + raise ValueError("%s is not prime." %l) if l is None: isogs = isogenies_prime_degree_genus_0(self) if isogs: @@ -5375,8 +5375,8 @@ def supersingular_primes(self, B): v = self.aplist(max(B, 3)) P = rings.prime_range(max(B,3)+1) N = self.conductor() - return [P[i] for i in [0,1] if P[i] <= B and v[i]%P[i]==0 and N%P[i] != 0] + \ - [P[i] for i in range(2,len(v)) if v[i] == 0 and N%P[i] != 0] + return [P[i] for i in [0,1] if P[i] <= B and v[i] %P[i]==0 and N %P[i] != 0] + \ + [P[i] for i in range(2,len(v)) if v[i] == 0 and N %P[i] != 0] def ordinary_primes(self, B): """ @@ -6386,7 +6386,7 @@ def S_integral_points(self, S, mw_base='auto', both_signs=False, verbose=False, if not self.is_integral(): raise ValueError("S_integral_points() can only be called on an integral model") if not all(self.is_p_minimal(s) for s in S): - raise ValueError("%s must be p-minimal for all primes in S"%self) + raise ValueError("%s must be p-minimal for all primes in S" %self) try: len_S = len(S) @@ -6430,11 +6430,11 @@ def reduction_at(p): m = copy(M.identity_matrix()) for i in range(r): try: - m[i, r] = Z((beta[indexp][i])%pc) + m[i, r] = Z((beta[indexp][i]) %pc) except ZeroDivisionError: #If Inverse doesn't exist, change denominator (which is only approx) val_nu = (beta[indexp][i]).numerator() val_de = (beta[indexp][i]).denominator() - m[i, r] = Z((val_nu/(val_de+1))%pc) + m[i, r] = Z((val_nu/(val_de+1)) %pc) m[r,r] = max(Z(1), pc) #LLL - implemented in sage - operates on rows not on columns diff --git a/src/sage/schemes/elliptic_curves/ell_wp.py b/src/sage/schemes/elliptic_curves/ell_wp.py index 820b9050a22..317a68e6a2d 100644 --- a/src/sage/schemes/elliptic_curves/ell_wp.py +++ b/src/sage/schemes/elliptic_curves/ell_wp.py @@ -142,7 +142,7 @@ def weierstrass_p(E, prec=20, algorithm=None): if algorithm == "pari": if 0 < p <= prec + 2: - raise ValueError("for computing the Weierstrass p-function via pari, the characteristic (%s) of the underlying field must be greater than prec + 2 = %s"%(p,prec+2)) + raise ValueError("for computing the Weierstrass p-function via pari, the characteristic (%s) of the underlying field must be greater than prec + 2 = %s" %(p,prec+2)) return compute_wp_pari(E, prec) # quadratic and fast algorithms require short Weierstrass model @@ -153,11 +153,11 @@ def weierstrass_p(E, prec=20, algorithm=None): if algorithm == "quadratic": if 0 < p <= prec + 2: - raise ValueError("for computing the Weierstrass p-function via the quadratic algorithm, the characteristic (%s) of the underlying field must be greater than prec + 2 = %s"%(p,prec+2)) + raise ValueError("for computing the Weierstrass p-function via the quadratic algorithm, the characteristic (%s) of the underlying field must be greater than prec + 2 = %s" %(p,prec+2)) wp = compute_wp_quadratic(k, A, B, prec) elif algorithm == "fast": if 0 < p <= prec + 4: - raise ValueError("for computing the Weierstrass p-function via the fast algorithm, the characteristic (%s) of the underlying field must be greater than prec + 4 = %s"%(p,prec+4)) + raise ValueError("for computing the Weierstrass p-function via the fast algorithm, the characteristic (%s) of the underlying field must be greater than prec + 4 = %s" %(p,prec+4)) wp = compute_wp_fast(k, A, B, prec) else: raise ValueError("unknown algorithm for computing the Weierstrass p-function") @@ -341,14 +341,12 @@ def solve_linear_differential_system(a, b, c, alpha): sage: f(0) == alpha # optional - sage.rings.finite_rings True """ - a_recip = 1/a - B = b * a_recip - C = c * a_recip + a_recip = 1 / a + B = b * a_recip + C = c * a_recip int_B = B.integral() J = int_B.exp() - J_recip = 1/J + J_recip = 1 / J CJ = C * J int_CJ = CJ.integral() - f = J_recip * (alpha + int_CJ) - - return f + return J_recip * (alpha + int_CJ) diff --git a/src/sage/schemes/elliptic_curves/gal_reps.py b/src/sage/schemes/elliptic_curves/gal_reps.py index ca9a3e1753c..28ac78664bc 100644 --- a/src/sage/schemes/elliptic_curves/gal_reps.py +++ b/src/sage/schemes/elliptic_curves/gal_reps.py @@ -462,9 +462,9 @@ def _is_surjective(self, p, A): sage: rho._is_surjective(5,1000) """ T = self._E.torsion_subgroup().order() - if T % p == 0 and p != 2 : + if T % p == 0 and p != 2: # we could probably determine the group structure directly - self.__image_type[p] = "The image is meta-cyclic inside a Borel subgroup as there is a %s-torsion point on the curve."%p + self.__image_type[p] = "The image is meta-cyclic inside a Borel subgroup as there is a %s-torsion point on the curve." %p return False R = rings.PolynomialRing(self._E.base_ring(), 'x') @@ -578,7 +578,7 @@ def _is_surjective(self, p, A): if s != 0 and s not in signs: signs.append(s) if len(signs) == 2 and exclude_exceptional_image: - self.__image_type[p] = "The image is all of GL_2(F_%s)."%p + self.__image_type[p] = "The image is all of GL_2(F_%s)." %p return True #,None if A == -1: # we came in from is reducible. Now go out with False @@ -675,19 +675,19 @@ def non_surjective(self, A=1000): p0 = arith.next_prime(p0+1) C2 = (sqrt(p0)+1)**8 C = max(C1,C2) - verbose("j is not integral -- Serre's bound is %s"%C) + verbose("j is not integral -- Serre's bound is %s" %C) C3 = 1 + 4*sqrt(6)*int(N)/3 * sqrt(misc.mul([1+1.0/int(p) for p,_ in arith.factor(N)])) C = min(C,C3) - verbose("conductor = %s, and bound is %s"%(N,C)) + verbose("conductor = %s, and bound is %s" %(N,C)) else: # Cojocaru's bound (depends on the conductor) C = 1 + 4*sqrt(6)*int(N)/3 * sqrt(misc.mul([1+1.0/int(p) for p,_ in arith.factor(N)])) - verbose("conductor = %s, and bound is %s"%(N,C)) + verbose("conductor = %s, and bound is %s" %(N,C)) B = [] p = 2 while p <= C: t = self.is_surjective(p, A=A) - verbose("(%s,%s)"%(p,t)) + verbose("(%s,%s)" %(p,t)) # both False and None will be appended here. if not t: B.append(p) @@ -833,7 +833,7 @@ def image_type(self, p): # check if the rep is reducible if self.is_reducible(p): - self.__image_type[p] = "The image is contained in a Borel subgroup as there is a %s-isogeny."%p + self.__image_type[p] = "The image is contained in a Borel subgroup as there is a %s-isogeny." % p return self.__image_type[p] # if we are then the image of rho is not surjective and not contained in a Borel subgroup @@ -843,10 +843,10 @@ def image_type(self, p): # or the image in PGL_2 is one of the three exceptional groups A_4 S_4 A_5 non_split_str = "The image is contained in the normalizer of a non-split Cartan group." - split_str = "The image is contained in the normalizer of a split Cartan group." - s4_str = "The image in PGL_2(F_%s) is the exceptional group S_4."%p - a4_str = "The image in PGL_2(F_%s) is the exceptional group A_4."%p - a5_str = "The image in PGL_2(F_%s) is the exceptional group A_5."%p + split_str = "The image is contained in the normalizer of a split Cartan group." + s4_str = "The image in PGL_2(F_%s) is the exceptional group S_4." % p + a4_str = "The image in PGL_2(F_%s) is the exceptional group A_4." % p + a5_str = "The image in PGL_2(F_%s) is the exceptional group A_5." % p # we first treat p=3 and 5 separately. p=2 has already been done. @@ -989,25 +989,25 @@ def image_type(self, p): u = k(a_ell)**2 * k(ell)**(-1) if (u not in ex_setp) and could_be_exc == 1: # it can not be in the exceptional - verbose("the image cannot be exceptional, found u=%s"%u, level=2) + verbose("the image cannot be exceptional, found u=%s" %u, level=2) could_be_exc = 0 if a_ell != 0 and arith.kronecker(a_ell**2 - 4*ell,p) == 1 and could_be_non_split == 1: # it can not be in the normalizer of the non-split Cartan - verbose("the image cannot be non-split, found u=%s"%u, level=2) + verbose("the image cannot be non-split, found u=%s" %u, level=2) could_be_non_split = 0 if a_ell != 0 and arith.kronecker(a_ell**2 - 4*ell,p) == -1 and could_be_split == 1: # it can not be in the normalizer of the split Cartan - verbose("the image cannot be split, found u=%s"%u, level=2) + verbose("the image cannot be split, found u=%s" %u, level=2) could_be_split = 0 assert could_be_exc + could_be_split + could_be_non_split > 0, "bug in image_type." if could_be_exc + could_be_split + could_be_non_split == 1: # it is only one of the three cases: - if could_be_split == 1 : + if could_be_split == 1: self.__image_type[p] = split_str return self.__image_type[p] - if could_be_non_split == 1 : + if could_be_non_split == 1: self.__image_type[p] = non_split_str return self.__image_type[p] if could_be_exc == 1: @@ -1015,7 +1015,7 @@ def image_type(self, p): could_be_a4 = 1 could_be_s4 = 1 could_be_a5 = 1 - if p % 5 != 1 and p % 5 != 4 : + if p % 5 != 1 and p % 5 != 4: could_be_a5 = 0 # elements of order 5 # bug corrected see trac 14577 R = k['X'] @@ -1031,7 +1031,7 @@ def image_type(self, p): # it can not be A4 not A5 as they have no elements of order 4 could_be_a4 = 0 could_be_a5 = 0 - if u in el5 : + if u in el5: # it can not be A4 or S4 as they have no elements of order 5 could_be_a4 = 0 could_be_s4 = 0 @@ -1050,7 +1050,7 @@ def image_type(self, p): return self.__image_type[p] else: - self.__image_type[p] = "The image in PGL_2(F_%s) is an exceptional group A_4, S_4 or A_5, but we could not determine which one."%p + self.__image_type[p] = "The image in PGL_2(F_%s) is an exceptional group A_4, S_4 or A_5, but we could not determine which one." %p return self.__image_type[p] # If all fails, we probably have a fairly small group and we can try to detect it using the galois_group @@ -1058,7 +1058,7 @@ def image_type(self, p): K = self._E.division_field(p, 'z') d = K.absolute_degree() - verbose("field of degree %s. try to compute Galois group"%(d), level=2) + verbose("field of degree %s. try to compute Galois group" %(d), level=2) # If the degree is too big, we have no chance at the Galois # group. K.galois_group calls is_galois which used to rely on # pari's Galois group computations, so degree < 12 @@ -1067,7 +1067,7 @@ def image_type(self, p): raise Exception() G = K.galois_group() except Exception: - self.__image_type[p] = "The image is a group of order %s."%d + self.__image_type[p] = "The image is a group of order %s." %d return self.__image_type[p] else: @@ -1075,7 +1075,7 @@ def image_type(self, p): ab = "" else: ab = "non-" - self.__image_type[p] = "The image is a " + ab + "abelian group of order %s."%G.order() + self.__image_type[p] = "The image is a " + ab + "abelian group of order %s." %G.order() return self.__image_type[p] ## everything failed : diff --git a/src/sage/schemes/elliptic_curves/gp_simon.py b/src/sage/schemes/elliptic_curves/gp_simon.py index 7b01dbc9d7f..0161e734fff 100644 --- a/src/sage/schemes/elliptic_curves/gp_simon.py +++ b/src/sage/schemes/elliptic_curves/gp_simon.py @@ -133,14 +133,14 @@ def simon_two_descent(E, verbose=0, lim1=None, lim3=None, limtriv=None, if limtriv is None: limtriv = 2 - gp('DEBUGLEVEL_ell=%s; LIM1=%s; LIM3=%s; LIMTRIV=%s; MAXPROB=%s; LIMBIGPRIME=%s;'%( + gp('DEBUGLEVEL_ell=%s; LIM1=%s; LIM3=%s; LIMTRIV=%s; MAXPROB=%s; LIMBIGPRIME=%s;' %( verbose, lim1, lim3, limtriv, maxprob, limbigprime)) if verbose >= 2: print(cmd) - s = gp.eval('ans=%s;'%cmd) + s = gp.eval('ans=%s;' %cmd) if s.find(" *** ") != -1: - raise RuntimeError("\n%s\nAn error occurred while running Simon's 2-descent program"%s) + raise RuntimeError("\n%s\nAn error occurred while running Simon's 2-descent program" %s) if verbose > 0: print(s) v = gp.eval('ans') diff --git a/src/sage/schemes/elliptic_curves/heegner.py b/src/sage/schemes/elliptic_curves/heegner.py index d8ba886fe2c..d5e2a7e306d 100644 --- a/src/sage/schemes/elliptic_curves/heegner.py +++ b/src/sage/schemes/elliptic_curves/heegner.py @@ -521,7 +521,7 @@ def quadratic_field(self): with sqrt_minus_7 = 2.645751311064591?*I """ D = self.__D - var = 'sqrt_minus_%s'%(-D) + var = 'sqrt_minus_%s' %(-D) return number_field.QuadraticField(D,var) @cached_method @@ -743,10 +743,10 @@ def _repr_(self): 'Galois group of Ring class field extension of QQ[sqrt(-7)] of conductor 5' """ if self.base_field() != QQ: - s = " over %s"%self.base_field() + s = " over %s" %self.base_field() else: s = '' - return "Galois group of %s%s"%(self.field(), s) + return "Galois group of %s%s" %(self.field(), s) def field(self): """ @@ -1060,7 +1060,7 @@ def _alpha_to_p1_element(self, alpha): n = gcd(w) w /= n c = P1.N() - w = P1.normalize(ZZ(w[0])%c, ZZ(w[1])%c) + w = P1.normalize(ZZ(w[0]) %c, ZZ(w[1]) %c) if w == (0,0): w = (1,0) return w @@ -1390,7 +1390,7 @@ def _repr_(self): sage: conj._repr_() 'Complex conjugation automorphism of Ring class field extension of QQ[sqrt(-7)] of conductor 5' """ - return "Complex conjugation automorphism of %s"%self.domain() + return "Complex conjugation automorphism of %s" %self.domain() ## def __mul__(self, right): ## """ @@ -1616,7 +1616,7 @@ def _repr_(self): sage: s._repr_() 'Class field automorphism defined by x^2 + 45*y^2' """ - return "Class field automorphism defined by %s"%self.__quadratic_form + return "Class field automorphism defined by %s" %self.__quadratic_form def __mul__(self, right): """ @@ -1684,7 +1684,7 @@ def ideal(self): c = M.conductor() sqrtD = K.gen() (A,B,C) = f - if A%c == 0: + if A %c == 0: A, C = C, A return K.fractional_ideal([A, (-B+c*sqrtD)/2]) @@ -1807,7 +1807,7 @@ def _repr_(self): sage: H._repr_() 'Heegner point of level 389, discriminant -7, and conductor 5' """ - return "Heegner point of level %s, discriminant %s, and conductor %s"%( + return "Heegner point of level %s, discriminant %s, and conductor %s" %( self.__N, self.__D, self.__c) def __hash__(self): @@ -2051,7 +2051,7 @@ def _repr_(self): sage: heegner_points(389)._repr_() 'Set of all Heegner points on X_0(389)' """ - return "Set of all Heegner points on X_0(%s)"%self.level() + return "Set of all Heegner points on X_0(%s)" %self.level() def reduce_mod(self, ell): r""" @@ -2155,7 +2155,7 @@ def __init__(self, N, D): HeegnerPoints.__init__(self, N) D = ZZ(D) if not satisfies_weak_heegner_hypothesis(N,D): - raise ValueError("D (=%s) must satisfy the weak Heegner hypothesis for N (=%s)"%(D,N)) + raise ValueError("D (=%s) must satisfy the weak Heegner hypothesis for N (=%s)" %(D,N)) self.__D = D def __eq__(self, other): @@ -2197,7 +2197,7 @@ def _repr_(self): sage: heegner_points(389,-7)._repr_() 'Set of all Heegner points on X_0(389) associated to QQ[sqrt(-7)]' """ - return "Set of all Heegner points on X_0(%s) associated to QQ[sqrt(%s)]"%( + return "Set of all Heegner points on X_0(%s) associated to QQ[sqrt(%s)]" %( self.level(), self.discriminant()) def discriminant(self): @@ -2224,7 +2224,7 @@ def quadratic_field(self): with sqrt_minus_7 = 2.645751311064591?*I """ D = self.__D - var = 'sqrt_minus_%s'%(-D) + var = 'sqrt_minus_%s' %(-D) return number_field.QuadraticField(D,var) def kolyvagin_conductors(self, r=None, n=10, E=None, m=None): @@ -2448,7 +2448,7 @@ def _repr_(self): sage: H = heegner_points(37,-7,5); H._repr_() 'All Heegner points of conductor 5 on X_0(37) associated to QQ[sqrt(-7)]' """ - return "All Heegner points of conductor %s on X_0(%s) associated to QQ[sqrt(%s)]"%( + return "All Heegner points of conductor %s on X_0(%s) associated to QQ[sqrt(%s)]" %( self.conductor(), self.level(), self.discriminant()) def conductor(self): @@ -2563,7 +2563,7 @@ def betas(self): N = self.level() R = Integers(4*N) m = 2*N - return tuple(sorted( set([a%m for a in R(D).sqrt(all=True)]) )) + return tuple(sorted( set([a %m for a in R(D).sqrt(all=True)]) )) @cached_method def points(self, beta=None): @@ -2721,7 +2721,7 @@ def __init__(self, N, D, c=ZZ(1), f=None, check=True): if c.gcd(N) != 1: raise ValueError("conductor c (=%s) must be coprime to N (=%s)" % (c, N)) if not satisfies_weak_heegner_hypothesis(N, D): - raise ValueError("N (=%s) and D (=%s) must satisfy the Heegner hypothesis"%(N, D)) + raise ValueError("N (=%s) and D (=%s) must satisfy the Heegner hypothesis" %(N, D)) if f is not None: if isinstance(f, tuple): if len(f) != 3: @@ -2741,7 +2741,7 @@ def __init__(self, N, D, c=ZZ(1), f=None, check=True): raise TypeError("f must be a 3-tuple, quadratic form, or element of the upper half plane") A, B, C = f if B*B - 4*A*C != D*c*c: - raise ValueError("f (=%s) must have discriminant %s"%(f, D*c*c)) + raise ValueError("f (=%s) must have discriminant %s" %(f, D*c*c)) HeegnerPoint.__init__(self, N, D, c) if f is None: # We know that N|A, so A = N is optimal. @@ -2797,11 +2797,11 @@ def _repr_(self): 'Heegner point 5/74*sqrt(-7) - 11/74 of discriminant -7 and conductor 5 on X_0(37)' """ c = self.conductor() - s = " and conductor %s"%c if c != 1 else "" + s = " and conductor %s" %c if c != 1 else "" N = self.level() D = self.discriminant() - tau = repr(self.tau()).replace('sqrt_minus_%s'%(-D),'sqrt(%s)'%D) - return "Heegner point %s of discriminant %s%s on X_0(%s)"%(tau, D, s, N) + tau = repr(self.tau()).replace('sqrt_minus_%s' %(-D),'sqrt(%s)' %D) + return "Heegner point %s of discriminant %s%s on X_0(%s)" %(tau, D, s, N) def atkin_lehner_act(self, Q=None): r""" @@ -3114,9 +3114,9 @@ def _repr_(self): sage: P._repr_() 'Heegner point of discriminant -7 and conductor 97 on elliptic curve of conductor 389' """ - s = " and conductor %s"%self.conductor() if self.conductor() != 1 else "" + s = " and conductor %s" %self.conductor() if self.conductor() != 1 else "" N = self.__E.conductor() - return "Heegner point of discriminant %s%s on elliptic curve of conductor %s"%(self.discriminant(), s, N) + return "Heegner point of discriminant %s%s on elliptic curve of conductor %s" %(self.discriminant(), s, N) def heegner_point_on_X0N(self): r""" @@ -3771,7 +3771,7 @@ def _square_roots_mod_2N_of_D_mod_4N(self): N = self.__E.conductor() R = Integers(4*N) m = 2*N - return sorted( set([a%m for a in R(self.discriminant()).sqrt(all=True)]) ) + return sorted( set([a %m for a in R(self.discriminant()).sqrt(all=True)]) ) def _trace_numerical_conductor_1(self, prec=53): """ @@ -3862,7 +3862,7 @@ def _good_tau_representatives(self): s = s.lift() f = (a*N, b+2*N*s, ZZ( ((b + 2*N*s)**2 - D)/(4*a*N)) ) for d in divs: - Q = d * prod(p**k for p,k in N.factor() if (b-beta)%(p**k)!=0) + Q = d * prod(p**k for p,k in N.factor() if (b-beta) %(p**k)!=0) g = self._qf_atkin_lehner_act(Q, f) gbar = (ZZ(g[0]/N), -g[1], g[2]*N) g = self._qf_reduce(g) @@ -4529,7 +4529,7 @@ def __init__(self, kolyvagin_point, n): n = gcd([(p+1).gcd(E.ap(p)) for p in c.prime_divisors()]) if not kolyvagin_point.satisfies_kolyvagin_hypothesis(n): - raise ValueError("Kolyvagin point does not satisfy Kolyvagin hypothesis for %s"%n) + raise ValueError("Kolyvagin point does not satisfy Kolyvagin hypothesis for %s" %n) self.__kolyvagin_point = kolyvagin_point self.__n = n @@ -4641,7 +4641,7 @@ def _repr_(self): sage: t._repr_() 'Kolyvagin cohomology class c(5) in H^1(K,E[2])' """ - return "Kolyvagin cohomology class c(%s) in H^1(K,E[%s])"%( + return "Kolyvagin cohomology class c(%s) in H^1(K,E[%s])" %( self.conductor(), self.n()) @@ -4729,7 +4729,7 @@ def _repr_(self): sage: heegner_points(11).reduce_mod(13)._repr_() 'Heegner points on X_0(11) over F_13' """ - return "Heegner points on X_0(%s) over F_%s"%( + return "Heegner points on X_0(%s) over F_%s" %( self.__level, self.__ell) def level(self): @@ -5002,7 +5002,7 @@ def heegner_divisor(self, D, c=ZZ(1)): if a > 0: reps = Q.representation_vector_list(n+1)[-1] k = len([r for r in reps if gcd(r) == 1]) - assert k%2 == 0 + assert k %2 == 0 v[i] += k // 2 return B(v) @@ -5072,12 +5072,12 @@ def modp_splitting_data(self, p): """ p = ZZ(p) if not p.is_prime(): - raise ValueError("p (=%s) must be prime"%p) + raise ValueError("p (=%s) must be prime" %p) if p == 2: raise ValueError("p must be odd") Q = self.quaternion_algebra() if Q.discriminant() % p == 0: - raise ValueError("p (=%s) must be an unramified prime"%p) + raise ValueError("p (=%s) must be an unramified prime" %p) i, j, k = Q.gens() F = GF(p) i2 = F(i*i) @@ -5181,7 +5181,7 @@ def cyclic_subideal_p1(self, I, c): V = V.intersection(phi(B[i]).kernel()) b = V.basis() assert len(b) == 1, "common kernel must have dimension 1" - uv = P1.normalize(ZZ(b[0][0])%c, ZZ(b[0][1])%c) + uv = P1.normalize(ZZ(b[0][0]) %c, ZZ(b[0][1]) %c) ans[uv] = J assert len(ans) == c+1 return ans @@ -5555,7 +5555,7 @@ def modp_dual_elliptic_curve_factor(self, E, p, bound=10): raise ValueError("conductor of E must equal level of self") p = ZZ(p) if not p.is_prime(): - raise ValueError("p (=%s) must be prime"%p) + raise ValueError("p (=%s) must be prime" %p) bad = self.__level * self.__ell V = None @@ -5563,7 +5563,7 @@ def modp_dual_elliptic_curve_factor(self, E, p, bound=10): B = self.brandt_module() F = GF(p) while q <= bound and (V is None or V.dimension() > 2): - verbose("q = %s"%q) + verbose("q = %s" %q) if bad % q != 0: T = B._compute_hecke_matrix_directly(q).change_ring(F).transpose() if V is None: @@ -6075,8 +6075,8 @@ def _repr_(self): sage: f = H.optimal_embeddings(-7, 2, R)[1]; f._repr_() 'Embedding sending 2*sqrt(-7) to -5*i + k' """ - a = '%ssqrt(%s)'%('%s*'%self.__c if self.__c > 1 else '', self.__D) - return "Embedding sending %s to %s"%(a, self.__beta) + a = '%ssqrt(%s)' %('%s*' %self.__c if self.__c > 1 else '', self.__D) + return "Embedding sending %s to %s" %(a, self.__beta) def conjugate(self): """ @@ -6580,13 +6580,13 @@ def heegner_point_height(self, D, prec=2, check_rank=True): """ if not self.satisfies_heegner_hypothesis(D): - raise ArithmeticError("Discriminant (=%s) must be a fundamental discriminant that satisfies the Heegner hypothesis."%D) + raise ArithmeticError("Discriminant (=%s) must be a fundamental discriminant that satisfies the Heegner hypothesis." %D) if check_rank and self.rank() >= 2: return ZZ(0) if D == -3 or D == -4: - raise ArithmeticError("Discriminant (=%s) must not be -3 or -4."%D) + raise ArithmeticError("Discriminant (=%s) must not be -3 or -4." %D) eps = self.root_number() L1_vanishes = self.lseries().L1_vanishes() @@ -6736,7 +6736,7 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, True """ if not self.satisfies_heegner_hypothesis(D): - raise ArithmeticError("Discriminant (=%s) must be a fundamental discriminant that satisfies the Heegner hypothesis."%D) + raise ArithmeticError("Discriminant (=%s) must be a fundamental discriminant that satisfies the Heegner hypothesis." %D) if check_rank and self.rank() >= 2: return rings.infinity @@ -6751,7 +6751,7 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, # Heegner point on the twist. ht = h0/2 - verbose('Height of heegner point = %s'%ht, tm) + verbose('Height of heegner point = %s' %ht, tm) if self.root_number() == 1: F = self.quadratic_twist(D) @@ -6759,11 +6759,11 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, F = self # Now rank(F) > 0 h = ht.upper() - verbose("Heegner height bound = %s"%h) + verbose("Heegner height bound = %s" %h) B = F.CPS_height_bound() - verbose("CPS bound = %s"%B) + verbose("CPS bound = %s" %B) c = h/(min_p**2) + B - verbose("Search would have to be up to height = %s"%c) + verbose("Search would have to be up to height = %s" %c) from .ell_rational_field import _MAX_HEIGHT @@ -6780,7 +6780,7 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, if z.is_divisible_by(2): a = 2 else: - FK_even_tor_pts = [T for T in FK.torsion_subgroup().gens() if T.order()%2==0] + FK_even_tor_pts = [T for T in FK.torsion_subgroup().gens() if T.order() %2==0] if len(FK_even_tor_pts) == 2: FK_even_tor_pts.append(sum(FK_even_tor_pts)) for T in FK_even_tor_pts: @@ -6805,7 +6805,7 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, if z.is_divisible_by(2): a = 2 else: - FK_even_tor_pts = [T for T in FK.torsion_subgroup().gens() if T.order()%2==0] + FK_even_tor_pts = [T for T in FK.torsion_subgroup().gens() if T.order() %2==0] if len(FK_even_tor_pts) == 2: FK_even_tor_pts.append(sum(FK_even_tor_pts)) for T in FK_even_tor_pts: @@ -6905,9 +6905,9 @@ def heegner_index_bound(self, D=0, prec=5, max_height=None): return 0, D, False F = self.quadratic_twist(D) h = ht.upper() - verbose("Heegner height bound = %s"%h) + verbose("Heegner height bound = %s" %h) B = F.CPS_height_bound() - verbose("CPS bound = %s"%B) + verbose("CPS bound = %s" %B) if self.two_torsion_rank() == 0: H = h else: @@ -6921,13 +6921,13 @@ def heegner_index_bound(self, D=0, prec=5, max_height=None): if p > 100: break p = next_prime(p) - verbose("Using p = %s"%p) + verbose("Using p = %s" %p) if c > max_height: - verbose("No information by searching only up to max_height (=%s)."%c) + verbose("No information by searching only up to max_height (=%s)." %c) return -1, D, False - verbose("Searching up to height = %s"%c) + verbose("Searching up to height = %s" %c) eps = 10e-5 def _bound(P): @@ -6942,15 +6942,15 @@ def _bound(P): IR = rings.RealIntervalField(20) # todo: 20? h = IR(reg-eps,reg+eps) ind2 = ht/(h/2) - verbose("index squared = %s"%ind2) + verbose("index squared = %s" %ind2) ind = ind2.sqrt() - verbose("index = %s"%ind) + verbose("index = %s" %ind) # Compute upper bound on square root of index. if ind.absolute_diameter() < 1: t, i = ind.is_int() if t: # unique integer in interval, so we've found exact index squared. return prime_divisors(i), D, i - raise RuntimeError("Unable to compute bound for e=%s, D=%s (try increasing precision)"%(self, D)) + raise RuntimeError("Unable to compute bound for e=%s, D=%s (try increasing precision)" %(self, D)) # First try a quick search, in case we get lucky and find # a generator. @@ -7004,7 +7004,7 @@ def _heegner_index_in_EK(self, D): """ # check conditions, then use cache if possible. if not self.satisfies_heegner_hypothesis(D): - raise ValueError("D (=%s) must satisfy the Heegner hypothesis"%D) + raise ValueError("D (=%s) must satisfy the Heegner hypothesis" %D) try: return self.__heegner_index_in_EK[D] except AttributeError: @@ -7151,7 +7151,7 @@ def heegner_sha_an(self, D, prec=53): """ # check conditions, then return from cache if possible. if not self.satisfies_heegner_hypothesis(D): - raise ValueError("D (=%s) must satisfy the Heegner hypothesis"%D) + raise ValueError("D (=%s) must satisfy the Heegner hypothesis" %D) try: return self.__heegner_sha_an[(D, prec)] except AttributeError: diff --git a/src/sage/schemes/elliptic_curves/height.py b/src/sage/schemes/elliptic_curves/height.py index e9eb837d30e..877b051cdd4 100644 --- a/src/sage/schemes/elliptic_curves/height.py +++ b/src/sage/schemes/elliptic_curves/height.py @@ -511,7 +511,7 @@ def nonneg_region(f): () """ roots = sorted(f.roots()) - sign_changes = [r for r,e in roots if e%2 == 1] + sign_changes = [r for r,e in roots if e %2 == 1] if (f.leading_coefficient() * (-1)**f.degree()) > 0: sign_changes = [-infinity] + sign_changes if f.leading_coefficient() > 0: @@ -552,15 +552,16 @@ def inf_max_abs(f, g, D): sage: max(abs(f(r0)), abs(g(r0))) 425.638201706391 """ - xs = f.roots() + f.derivative().roots() + xs = f.roots() + f.derivative().roots() xs += g.roots() + g.derivative().roots() - xs += (f-g).roots() + (f+g).roots() - xs = [r for r,e in xs if r in D] # ignore multiplicities and points outside D + xs += (f - g).roots() + (f + g).roots() + xs = [r for r, _ in xs if r in D] # ignore multiplicities and points outside D xs += D.finite_endpoints() # include endpoints of intervals if xs: - return min([max(abs(f(r)), abs(g(r))) for r in xs]) + return min(max(abs(f(r)), abs(g(r))) for r in xs) return infinity + def min_on_disk(f, tol, max_iter=10000): r""" Returns the minimum of a real-valued complex function on a square. diff --git a/src/sage/schemes/elliptic_curves/hom_velusqrt.py b/src/sage/schemes/elliptic_curves/hom_velusqrt.py index 15863173c4f..d002ce03357 100644 --- a/src/sage/schemes/elliptic_curves/hom_velusqrt.py +++ b/src/sage/schemes/elliptic_curves/hom_velusqrt.py @@ -455,7 +455,7 @@ def _hI_resultant(self, poly, rems=None): if rems is None: rems = self.hItree.remainders(poly) r = prod(rems) - s = -1 if len(self.hItree)%2 == 1 == poly.degree() else 1 + s = -1 if len(self.hItree) %2 == 1 == poly.degree() else 1 assert r.is_constant() return s * r[0] diff --git a/src/sage/schemes/elliptic_curves/isogeny_class.py b/src/sage/schemes/elliptic_curves/isogeny_class.py index 43495d65293..9eb69746841 100644 --- a/src/sage/schemes/elliptic_curves/isogeny_class.py +++ b/src/sage/schemes/elliptic_curves/isogeny_class.py @@ -227,9 +227,9 @@ def _repr_(self): Elliptic Curve defined by y^2 + (i+1)*x*y + (i+1)*y = x^3 + i*x^2 + (-i+33)*x + (-58*i) over Number Field in i with defining polynomial x^2 + 1 with i = 1*I] """ if self._label: - return "Elliptic curve isogeny class %s"%(self._label) + return "Elliptic curve isogeny class %s" %(self._label) else: - return "Isogeny class of %r"%(self.E) + return "Isogeny class of %r" %(self.E) def __contains__(self, x): """ diff --git a/src/sage/schemes/elliptic_curves/isogeny_small_degree.py b/src/sage/schemes/elliptic_curves/isogeny_small_degree.py index 28b4a8ebcca..a8c84de2613 100644 --- a/src/sage/schemes/elliptic_curves/isogeny_small_degree.py +++ b/src/sage/schemes/elliptic_curves/isogeny_small_degree.py @@ -288,7 +288,7 @@ def isogenies_prime_degree_genus_0(E, l=None, minimal_models=True): to Elliptic Curve defined by y^2 + x*y + y = x^3 - 76*x + 298 over Rational Field] """ if l not in [2, 3, 5, 7, 13, None]: - raise ValueError("%s is not a genus 0 prime."%l) + raise ValueError("%s is not a genus 0 prime." %l) F = E.base_ring() j = E.j_invariant() if F.characteristic() in [2, 3, l]: @@ -1624,7 +1624,7 @@ def _hyperelliptic_isogeny_data(l): ValueError: 37 must be one of [11, 17, 19, 23, 29, 31, 41, 47, 59, 71]. """ if l not in hyperelliptic_primes: - raise ValueError("%s must be one of %s."%(l,hyperelliptic_primes)) + raise ValueError("%s must be one of %s." %(l,hyperelliptic_primes)) data = {} Zu = PolynomialRing(ZZ,'u') Zuv = PolynomialRing(ZZ,['u','v']) @@ -2091,7 +2091,7 @@ def isogenies_prime_degree_genus_plus_0_j0(E, l, minimal_models=True): [Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6] """ if l not in hyperelliptic_primes: - raise ValueError("%s must be one of %s."%(l,hyperelliptic_primes)) + raise ValueError("%s must be one of %s." %(l,hyperelliptic_primes)) F = E.base_field() if E.j_invariant() != 0: raise ValueError(("j-invariant must be 0.")) @@ -2213,7 +2213,7 @@ def isogenies_prime_degree_genus_plus_0_j1728(E, l, minimal_models=True): [(17, 2), (29, 2), (41, 2)] """ if l not in hyperelliptic_primes: - raise ValueError("%s must be one of %s."%(l,hyperelliptic_primes)) + raise ValueError("%s must be one of %s." %(l,hyperelliptic_primes)) F = E.base_ring() if E.j_invariant() != 1728: raise ValueError("j-invariant must be 1728.") @@ -2795,7 +2795,7 @@ def isogenies_prime_degree(E, l, minimal_models=True): with a = 3.316624790355400?*I] """ if not l.is_prime(): - raise ValueError("%s is not prime."%l) + raise ValueError("%s is not prime." %l) if l==2: return isogenies_2(E, minimal_models=minimal_models) if l==3: diff --git a/src/sage/schemes/elliptic_curves/kodaira_symbol.py b/src/sage/schemes/elliptic_curves/kodaira_symbol.py index c8a9f90da4a..b4bbe78b951 100644 --- a/src/sage/schemes/elliptic_curves/kodaira_symbol.py +++ b/src/sage/schemes/elliptic_curves/kodaira_symbol.py @@ -202,14 +202,14 @@ def __init__(self, symbol): else: self._pari = -self._n - 4 self._str = "I" + symbol + "*" - self._latex = "I_{%s}^*"%(symbol) + self._latex = "I_{%s}^*" % (symbol) else: if self._n == 0: self._pari = 1 else: self._pari = self._n + 4 self._str = "I" + symbol - self._latex = "I_{%s}"%(symbol) + self._latex = "I_{%s}" % (symbol) else: raise ValueError("input is not a Kodaira symbol") diff --git a/src/sage/schemes/elliptic_curves/kraus.py b/src/sage/schemes/elliptic_curves/kraus.py index 79b7afa9c2c..f8c6bc8b18a 100644 --- a/src/sage/schemes/elliptic_curves/kraus.py +++ b/src/sage/schemes/elliptic_curves/kraus.py @@ -618,17 +618,17 @@ def check_Kraus_local_2(c4, c6, P, a1=None, assume_nonsingular=False): P2res = [a1] if a1 else P2.residues() for a1 in P2res: Px = -a1**6+3*a1**2*c4+2*c6 - if Px.valuation(P) >= 4*e : # (i) + if Px.valuation(P) >= 4*e: # (i) flag, a3 = sqrt_mod_4(Px/16,P) # (ii) if flag: a1sq = a1*a1 - if (4*a1sq*Px-(a1sq**2-c4)**2).valuation(P) >= 8*e : # (iii) + if (4*a1sq*Px-(a1sq**2-c4)**2).valuation(P) >= 8*e: # (iii) if test_a1a3_local(c4,c6,P,a1,a3): - return True, a1,a3 + return True, a1, a3 else: raise RuntimeError("check_Kraus_local_2 fails") # end of loop, but no a1 found - return False,0,0 + return False, 0, 0 # Wrapper function for local Kraus check, outsources the real work to # other functions for primes dividing 2 or 3: diff --git a/src/sage/schemes/elliptic_curves/lseries_ell.py b/src/sage/schemes/elliptic_curves/lseries_ell.py index 7f0e4d3e5e5..45db560c861 100644 --- a/src/sage/schemes/elliptic_curves/lseries_ell.py +++ b/src/sage/schemes/elliptic_curves/lseries_ell.py @@ -98,7 +98,7 @@ def _repr_(self): sage: L._repr_() 'Complex L-series of the Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field' """ - return "Complex L-series of the %s"%self.__E + return "Complex L-series of the %s" % self.__E def dokchitser(self, prec=53, max_imaginary_part=0, diff --git a/src/sage/schemes/elliptic_curves/mod5family.py b/src/sage/schemes/elliptic_curves/mod5family.py index 9fe4b2db894..64069c342b7 100644 --- a/src/sage/schemes/elliptic_curves/mod5family.py +++ b/src/sage/schemes/elliptic_curves/mod5family.py @@ -80,7 +80,7 @@ def mod5family(a, b): beta[20] = 30015*(J - 1)**10*(1001 + 634920*J + 3880800*J**2 + 142879744*J**3 - 1168475904*J**4 + 1188919296*J**5 - 143327232*J**6) beta[21] = 100050*(J - 1)**10*(143 + 107250*J + 808368*J**2 + 38518336*J**3 - 451953408*J**4 + 757651968*J**5 - 367276032*J**6) beta[22] = 450225*(J - 1)**11*(-13 - 11440*J - 117216*J**2 - 6444800*J**3 + 94192384*J**4 - 142000128*J**5 + 95551488*J**6) - beta[23] = 156600*(J - 1)**11*(-13 - 13299*J - 163284*J**2 - 11171552*J**3 + 217203840*J**4 - 474406656*J**5 + 747740160*J**6 - 429981696*J**7) + beta[23] = 156600*(J - 1)**11*(-13 - 13299*J - 163284*J**2 - 11171552*J**3 + 217203840*J**4 - 474406656*J**5 + 747740160*J**6 - 429981696*J**7) beta[24] = 6525*(J - 1)**12*(91 + 107536*J + 1680624*J**2 + 132912128*J**3 - 3147511552*J**4 + 6260502528*J**5 - 21054173184*J**6 + 10319560704*J**7) beta[25] = 1566*(J - 1)**12*(91 + 123292*J + 2261248*J**2 + 216211904*J**3 - diff --git a/src/sage/schemes/elliptic_curves/padic_lseries.py b/src/sage/schemes/elliptic_curves/padic_lseries.py index 74581cd2479..9bb33ff952b 100644 --- a/src/sage/schemes/elliptic_curves/padic_lseries.py +++ b/src/sage/schemes/elliptic_curves/padic_lseries.py @@ -876,16 +876,16 @@ def series(self, n=2, quadratic_twist=+1, prec=5, eta=0): if D % 4 == 0: d = D//4 if not d.is_squarefree() or d % 4 == 1: - raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field"%D) + raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" %D) else: if not D.is_squarefree() or D % 4 != 1: - raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field"%D) + raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" %D) if gcd(D,self._p) != 1: - raise ValueError("quadratic twist (=%s) must be coprime to p (=%s) "%(D,self._p)) + raise ValueError("quadratic twist (=%s) must be coprime to p (=%s) " %(D,self._p)) if gcd(D, self._E.conductor()) != 1: for ell in prime_divisors(D): if valuation(self._E.conductor(), ell) > valuation(D, ell): - raise ValueError("cannot twist a curve of conductor (=%s) by the quadratic twist (=%s)."%(self._E.conductor(),D)) + raise ValueError("cannot twist a curve of conductor (=%s) by the quadratic twist (=%s)." %(self._E.conductor(),D)) p = self._p si = 1-2*(eta % 2) @@ -915,13 +915,13 @@ def series(self, n=2, quadratic_twist=+1, prec=5, eta=0): bounds = self._prec_bounds(n,prec,sign=si) padic_prec = max(bounds[1:]) + 5 - verbose("using p-adic precision of %s"%padic_prec) + verbose("using p-adic precision of %s" %padic_prec) if p == 2: res_series_prec = min(p**(n-2), prec) else: res_series_prec = min(p**(n-1), prec) - verbose("using series precision of %s"%res_series_prec) + verbose("using series precision of %s" %res_series_prec) ans = self._get_series_from_cache(n, res_series_prec,D,eta) if ans is not None: @@ -946,13 +946,13 @@ def series(self, n=2, quadratic_twist=+1, prec=5, eta=0): p_power = p**(n-1) a_range = p - verbose("Now iterating over %s summands"%((p-1)*p_power)) + verbose("Now iterating over %s summands" %((p-1)*p_power)) verbose_level = get_verbose() count_verb = 0 for j in range(p_power): s = K(0) if verbose_level >= 2 and j/p_power*100 > count_verb + 3: - verbose("%.2f percent done"%(float(j)/p_power*100)) + verbose("%.2f percent done" %(float(j)/p_power*100)) count_verb += 3 for a in range(1,a_range): b = teich[a] * gamma_power @@ -961,7 +961,7 @@ def series(self, n=2, quadratic_twist=+1, prec=5, eta=0): one_plus_T_factor *= 1+T gamma_power *= gamma - verbose("the series before adjusting the precision is %s"%L) + verbose("the series before adjusting the precision is %s" %L) # Now create series but with each coefficient truncated # so it is proven correct: K = Qp(p, padic_prec, print_mode='series') @@ -1070,7 +1070,7 @@ def _c_bound(self, sign=+1): # else the same reasoning as in _set_denom in numerical # modular symbol. We rely on the fact that p is semistable from sage.databases.cremona import CremonaDatabase - isog = E.isogeny_class() + isog = E.isogeny_class() t = 0 if N <= CremonaDatabase().largest_conductor(): E0 = E.optimal_curve() @@ -1095,7 +1095,7 @@ def _c_bound(self, sign=+1): if p == 2: t += 1 if p == 2 and E0.real_components() == 1: - t += 1 # slanted lattice + t += 1 # slanted lattice # this was the bound for E0 now compare periods # to get the bound for E @@ -1227,7 +1227,7 @@ def series(self, n=3, quadratic_twist=+1, prec=5, eta=0): if D % 4 == 0: d = D//4 if not d.is_squarefree() or d % 4 == 1: - raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field"%D) + raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" %D) else: if not D.is_squarefree() or D % 4 != 1: raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" % D) @@ -1288,13 +1288,13 @@ def series(self, n=3, quadratic_twist=+1, prec=5, eta=0): a_range = p si = 1-2*(eta % 2) - verbose("Now iterating over %s summands"%((p-1)*p_power)) + verbose("Now iterating over %s summands" %((p-1)*p_power)) verbose_level = get_verbose() count_verb = 0 for j in range(p_power): s = K(0) if verbose_level >= 2 and j/p_power*100 > count_verb + 3: - verbose("%.2f percent done"%(float(j)/p_power*100)) + verbose("%.2f percent done" %(float(j)/p_power*100)) count_verb += 3 for a in range(1,a_range): b = teich[a] * gamma_power @@ -1393,15 +1393,15 @@ def _poly(self, a): # this should be implemented in elements of Eisenstein rings at some point trac 20248 if a.is_zero(): - return [0,0] + return [0, 0] v, k = a._ntl_rep_abs() K = a.base_ring() pi = K.uniformiser() - v0 = K(v[0]._sage_()) * pi**k - v1 = K(v[1]._sage_()) * pi**k + v0 = K(v[0]._sage_()) * pi**k + v1 = K(v[1]._sage_()) * pi**k alpha = a.parent().gen() - assert v0 + v1*alpha == a - return [ v0, v1 ] + assert v0 + v1 * alpha == a + return [v0, v1] def Dp_valued_series(self, n=3, quadratic_twist=+1, prec=5): r""" @@ -1437,8 +1437,8 @@ def Dp_valued_series(self, n=3, quadratic_twist=+1, prec=5): lps = self.series(n, quadratic_twist=quadratic_twist, prec=prec) # now split up the series in two lps = G + H * alpha - R = lps.base_ring().base_ring() # Qp - QpT , T = PowerSeriesRing(R, 'T', prec).objgen() + R = lps.base_ring().base_ring() # Qp + QpT, T = PowerSeriesRing(R, 'T', prec).objgen() Gli = [] Hli = [] for n in range(lps.prec()): @@ -1449,10 +1449,10 @@ def Dp_valued_series(self, n=3, quadratic_twist=+1, prec=5): H = QpT(Hli, prec) # now compute phi - phi = matrix.matrix([[0,-1/p],[1,E.ap(p)/p]]) - lpv = vector([G + (E.ap(p))*H , - R(p) * H ]) # this is L_p - eps = (1-phi)**(-2) - resu = lpv*eps.transpose() + phi = matrix.matrix([[0, -1 / p], [1, E.ap(p) / p]]) + lpv = vector([G + (E.ap(p)) * H, - R(p) * H]) # this is L_p + eps = (1 - phi)**(-2) + resu = lpv * eps.transpose() return resu def frobenius(self, prec=20, algorithm="mw"): @@ -1485,7 +1485,7 @@ def frobenius(self, prec=20, algorithm="mw"): E = self._E p = self._p if algorithm != "mw" and algorithm !="approx": - raise ValueError("Unknown algorithm %s."%algorithm) + raise ValueError("Unknown algorithm %s." %algorithm) if algorithm == "approx": return self.__phi_bpr(prec=prec) if p < 4 and algorithm == "mw": @@ -1501,24 +1501,24 @@ def frobenius(self, prec=20, algorithm="mw"): fr = matrix.matrix(output_ring,2,2,fr) # return a vector for PARI's ellchangecurve to pass from e1 to e2 - def isom(e1,e2): + def isom(e1, e2): if not e1.is_isomorphic(e2): raise ValueError("Curves must be isomorphic.") - usq = (e1.discriminant()/e2.discriminant()).nth_root(6) + usq = (e1.discriminant() / e2.discriminant()).nth_root(6) u = usq.sqrt() - s = (u * e2.a1() - e1.a1() )/ZZ(2) - r = (usq * e2.a2() - e1.a2() + s**2 + e1.a1()*s)/ZZ(3) - t = (u**3 * e2.a3() - e1.a3() - e1.a1()*r)/ZZ(2) - return [u,r,s,t] + s = (u * e2.a1() - e1.a1()) / ZZ(2) + r = (usq * e2.a2() - e1.a2() + s**2 + e1.a1()*s) / ZZ(3) + t = (u**3 * e2.a3() - e1.a3() - e1.a1()*r) / ZZ(2) + return [u, r, s, t] - v = isom(E,Ew) + v = isom(E, Ew) u = v[0] r = v[1] # change basis - A = matrix.matrix([[u,-r/u],[0,1/u]]) + A = matrix.matrix([[u, -r/u], [0, 1/u]]) frn = A * fr * A**(-1) - return 1/p*frn + return 1 / p*frn def __phi_bpr(self, prec=0): r""" @@ -1571,31 +1571,33 @@ def __phi_bpr(self, prec=0): for k in range(1,prec+1): # this is the equation eq[0]*x+eq[1]*y+eq[2] == 0 # such that delta_ = delta + d^dpr*x ... - eq = [(p**dpr*cs[k]) % p**k,(-p**dga*ds[k]) % p**k , (delta*cs[k]-gamma*ds[k]-cs[k-1]) % p**k ] + eq = [(p**dpr*cs[k]) % p**k, + (-p**dga*ds[k]) % p**k, + (delta*cs[k]-gamma*ds[k]-cs[k-1]) % p**k] verbose("valuations : %s" % ([x.valuation(p) for x in eq])) - v = min([x.valuation(p) for x in eq]) + v = min(x.valuation(p) for x in eq) if v == infinity: - verbose("no new information at step k=%s"%k) + verbose("no new information at step k=%s" % k) else: eq = [ZZ(x/p**v) for x in eq] - verbose("renormalised eq mod p^%s is now %s"%(k-v,eq)) + verbose("renormalised eq mod p^%s is now %s" % (k-v,eq)) if eq[0].valuation(p) == 0: l = min(eq[1].valuation(p),k-v) if l == 0: - verbose("not uniquely determined at step k=%s"%k) + verbose("not uniquely determined at step k=%s" %k) else: ainv = eq[0].inverse_mod(p**l) delta = delta - eq[2]*ainv*p**dpr dpr = dpr + l delta = delta % p**dpr - verbose("delta_prec increased to %s\n delta is now %s"%(dpr,delta)) + verbose("delta_prec increased to %s\n delta is now %s" %(dpr,delta)) elif eq[1].valuation(p) == 0: l = min(eq[0].valuation(p),k-v) ainv = eq[1].inverse_mod(p**l) gamma = gamma - eq[2]*ainv*p**dga dga = dga + l gamma = gamma % p**dga - verbose("gamma_prec increased to %s\n gamma is now %s"%(dga,gamma)) + verbose("gamma_prec increased to %s\n gamma is now %s" %(dga,gamma)) else: raise RuntimeError("Bug: no delta or gamma can exist") @@ -1603,7 +1605,7 @@ def __phi_bpr(self, prec=0): R = Qp(p,max(dpr,dga)+1) delta = R(delta,absprec=dpr) gamma = R(gamma,absprec=dga) - verbose("result delta = %s\n gamma = %s\n check : %s"%(delta,gamma, [Qp(p,k)(delta * cs[k] - gamma * ds[k] - cs[k-1]) for k in range(1,prec+1)] )) + verbose("result delta = %s\n gamma = %s\n check : %s" %(delta,gamma, [Qp(p,k)(delta * cs[k] - gamma * ds[k] - cs[k-1]) for k in range(1,prec+1)] )) a = delta c = -gamma d = E.ap(p) - a @@ -1685,15 +1687,15 @@ def height(P,check=True): tt = R(tt) zz = elog(tt) - homega = -zz**2/n**2 + homega = -zz**2 / n**2 - eQ = denominator(Q[1])/denominator(Q[0]) + eQ = denominator(Q[1]) / denominator(Q[0]) si = self.bernardi_sigma_function(prec=prec+4) - heta = 2 * log(si(zz)/eQ) / n**2 + heta = 2 * log(si(zz)/eQ) / n**2 - R = Qp(p,prec) + R = Qp(p, prec) - return vector([-R(heta),R(homega)]) + return vector([-R(heta), R(homega)]) return height @@ -1720,10 +1722,10 @@ def Dp_valued_regulator(self, prec=20, v1=0, v2=0): p = self._p E = self._E - h = self.Dp_valued_height(prec=prec) + h = self.Dp_valued_height(prec=prec) # this is the height_{v} (P) for a v in D_p - def hv(vec,P): + def hv(vec, P): hP = h(P) return - vec[0]*hP[1] +vec[1]*hP[0] diff --git a/src/sage/schemes/elliptic_curves/padics.py b/src/sage/schemes/elliptic_curves/padics.py index 8dc75a35a43..d0c16cec86e 100644 --- a/src/sage/schemes/elliptic_curves/padics.py +++ b/src/sage/schemes/elliptic_curves/padics.py @@ -317,7 +317,7 @@ def padic_regulator(self, p, prec=20, height=None, check_hypotheses=True): p = Integer(p) # this is assumed in code below if check_hypotheses: if not p.is_prime(): - raise ValueError("p = (%s) must be prime"%p) + raise ValueError("p = (%s) must be prime" %p) if p == 2: raise ValueError("p must be odd") # todo if self.conductor() % (p**2) == 0: @@ -715,7 +715,7 @@ def padic_height(self, p, prec=20, sigma=None, check_hypotheses=True): """ if check_hypotheses: if not p.is_prime(): - raise ValueError("p = (%s) must be prime"%p) + raise ValueError("p = (%s) must be prime" %p) if p == 2: raise ValueError("p must be odd") # todo if self.conductor() % (p**2) == 0: @@ -867,7 +867,7 @@ def padic_height_via_multiply(self, p, prec=20, E2=None, check_hypotheses=True): """ if check_hypotheses: if not p.is_prime(): - raise ValueError("p = (%s) must be prime"%p) + raise ValueError("p = (%s) must be prime" %p) if p == 2: raise ValueError("p must be odd") # todo if self.conductor() % p == 0: diff --git a/src/sage/schemes/elliptic_curves/period_lattice.py b/src/sage/schemes/elliptic_curves/period_lattice.py index 1c767699fb5..e3513ee8b05 100644 --- a/src/sage/schemes/elliptic_curves/period_lattice.py +++ b/src/sage/schemes/elliptic_curves/period_lattice.py @@ -320,9 +320,8 @@ def __repr__(self): Defn: a |--> 1.259921049894873? """ if self.E.base_field() is QQ: - return "Period lattice associated to %s"%(self.E) - else: - return "Period lattice associated to %s with respect to the embedding %s"%(self.E, self.embedding) + return "Period lattice associated to %s" % (self.E) + return "Period lattice associated to %s with respect to the embedding %s" % (self.E, self.embedding) def __call__(self, P, prec=None): r""" @@ -1198,23 +1197,23 @@ def coordinates(self, z, rounding=None): C = ComplexField() z = C(z) except TypeError: - raise TypeError("%s is not a complex number"%z) + raise TypeError("%s is not a complex number" % z) prec = C.precision() from sage.matrix.constructor import Matrix from sage.modules.free_module_element import vector if self.real_flag: - w1,w2 = self.basis(prec) - M = Matrix([[w1,0], list(w2)])**(-1) + w1, w2 = self.basis(prec) + M = Matrix([[w1, 0], list(w2)])**(-1) else: - w1,w2 = self.normalised_basis(prec) + w1, w2 = self.normalised_basis(prec) M = Matrix([list(w1), list(w2)])**(-1) - u,v = vector(z)*M + u, v = vector(z) * M # Now z = u*w1+v*w2 - if rounding=='round': + if rounding == 'round': return u.round(), v.round() - if rounding=='floor': + if rounding == 'floor': return u.floor(), v.floor() - return u,v + return u, v def reduce(self, z): r""" @@ -1275,17 +1274,17 @@ def reduce(self, z): # NB We assume here that when the embedding is real then the # point is also real! - if self.real_flag == 0: + if self.real_flag == 0: return z if self.real_flag == -1: - k = (z.imag()/w2.imag()).round() + k = (z.imag() / w2.imag()).round() z = z-k*w2 - return C(z.real(),0) + return C(z.real(), 0) - if ((2*z.imag()/w2.imag()).round())%2: - return C(z.real(),w2.imag()/2) + if ((2*z.imag()/w2.imag()).round()) % 2: + return C(z.real(), w2.imag() / 2) else: - return C(z.real(),0) + return C(z.real(), 0) def e_log_RC(self, xP, yP, prec=None, reduce=True): r""" @@ -1442,7 +1441,7 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): z = ((a/t).arctan())/a z = ComplexField(prec)(z) if reduce: - z = self.reduce(z) + z = self.reduce(z) return z if self.real_flag==-1: # real, connected case @@ -1476,13 +1475,13 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): if (r-1).abs() < eps: break t *= r - z = ((a/t).arctan())/a + z = ((a / t).arctan()) / a if on_egg: - w1,w2 = self._compute_periods_real(prec) - z += w2/2 + w1, w2 = self._compute_periods_real(prec) + z += w2 / 2 z = ComplexField(prec)(z) if reduce: - z = self.reduce(z) + z = self.reduce(z) return z def elliptic_logarithm(self, P, prec=None, reduce=True): From 45ed1075d530316bbaaf7087fb2e7933ad3bdac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 23 May 2023 21:05:11 +0200 Subject: [PATCH 54/98] another fix for pep8 --- src/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py index 9ab9dfbcb4c..a56fee001cf 100644 --- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py +++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py @@ -349,7 +349,7 @@ def odd_degree_model(self): raise ValueError("No odd degree model exists over field of definition") rt = rts[0] x = f.parent().gen() - fnew = f((x*rt + 1)/x).numerator() # move rt to "infinity" + fnew = f((x * rt + 1) / x).numerator() # move rt to "infinity" from .constructor import HyperellipticCurve return HyperellipticCurve(fnew, 0, names=self._names, PP=self._PP) From 448336105d92d93f58355b83c31698f46401ae7d Mon Sep 17 00:00:00 2001 From: Antonio Rojas Date: Wed, 24 May 2023 00:46:08 +0200 Subject: [PATCH 55/98] Fix building the Singular docstring dictionaty when Singular info is built with recent texinfo When building the Singular info with recent texinfo, sections are numbered using capital letters instead of numbers. This breaks the current matching logic. --- src/sage/interfaces/singular.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/interfaces/singular.py b/src/sage/interfaces/singular.py index b79e08c44f9..91a4abd7713 100644 --- a/src/sage/interfaces/singular.py +++ b/src/sage/interfaces/singular.py @@ -2405,7 +2405,7 @@ def generate_docstring_dictionary(): a, b = m.groups() node_names[a] = b.strip() - if line == "6 Index\n": + if line in ("6 Index\n", "F Index\n"): in_node = False nodes[curr_node] = "".join(L) # last node From cab8cb11d262f6c08c5faa4d53c0a7630fa46123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Wed, 24 May 2023 08:32:37 +0200 Subject: [PATCH 56/98] more pep8 fixes in elliptic curves --- src/sage/schemes/elliptic_curves/cm.py | 27 ++-- .../schemes/elliptic_curves/constructor.py | 20 +-- .../schemes/elliptic_curves/ec_database.py | 4 +- src/sage/schemes/elliptic_curves/ell_field.py | 98 ++++++------- .../elliptic_curves/ell_finite_field.py | 40 +++--- .../elliptic_curves/ell_modular_symbols.py | 18 +-- .../elliptic_curves/ell_rational_field.py | 132 +++++++++--------- src/sage/schemes/elliptic_curves/ell_wp.py | 6 +- .../schemes/elliptic_curves/formal_group.py | 2 +- src/sage/schemes/elliptic_curves/gal_reps.py | 30 ++-- .../elliptic_curves/gal_reps_number_field.py | 26 ++-- src/sage/schemes/elliptic_curves/gp_simon.py | 8 +- src/sage/schemes/elliptic_curves/heegner.py | 106 +++++++------- src/sage/schemes/elliptic_curves/height.py | 2 +- .../schemes/elliptic_curves/hom_composite.py | 2 +- .../schemes/elliptic_curves/hom_velusqrt.py | 2 +- .../schemes/elliptic_curves/isogeny_class.py | 28 ++-- .../elliptic_curves/isogeny_small_degree.py | 42 +++--- src/sage/schemes/elliptic_curves/kraus.py | 12 +- .../schemes/elliptic_curves/padic_lseries.py | 54 +++---- src/sage/schemes/elliptic_curves/padics.py | 8 +- .../schemes/elliptic_curves/period_lattice.py | 48 +++---- .../schemes/elliptic_curves/saturation.py | 6 +- 23 files changed, 361 insertions(+), 360 deletions(-) diff --git a/src/sage/schemes/elliptic_curves/cm.py b/src/sage/schemes/elliptic_curves/cm.py index 75432147b01..a70c09f79bd 100644 --- a/src/sage/schemes/elliptic_curves/cm.py +++ b/src/sage/schemes/elliptic_curves/cm.py @@ -263,7 +263,7 @@ def is_HCP(f, check_monic_irreducible=True): continue if not fp.is_squarefree(): continue - if d100: + if h > 100: raise NotImplementedError("CM data only available for class numbers up to 100") for d,f in cm_orders(h): if jpol == hilbert_class_polynomial(d*f**2): @@ -1046,8 +1047,8 @@ def is_cm_j_invariant(j, algorithm='CremonaSutherland', method=None): if cmd: # we have a candidate CM field already break else: # we need to try more primes - max_primes *=2 - if D.valuation(P)>0: # skip bad primes + max_primes *= 2 + if D.valuation(P) > 0: # skip bad primes continue aP = E.reduction(P).trace_of_frobenius() if aP == 0: # skip supersingular primes diff --git a/src/sage/schemes/elliptic_curves/constructor.py b/src/sage/schemes/elliptic_curves/constructor.py index 15bdb273259..eae54a05fcd 100644 --- a/src/sage/schemes/elliptic_curves/constructor.py +++ b/src/sage/schemes/elliptic_curves/constructor.py @@ -696,14 +696,14 @@ def coefficients_from_j(j, minimal_twist=True): if K not in _Fields: K = K.fraction_field() - char=K.characteristic() - if char==2: + char = K.characteristic() + if char == 2: if j == 0: return Sequence([0, 0, 1, 0, 0], universe=K) else: return Sequence([1, 0, 0, 0, 1/j], universe=K) if char == 3: - if j==0: + if j == 0: return Sequence([0, 0, 0, 1, 0], universe=K) else: return Sequence([0, j, 0, 0, -j**2], universe=K) @@ -717,7 +717,7 @@ def coefficients_from_j(j, minimal_twist=True): return Sequence([0, 0, 0, -1, 0], universe=K) # 32a2 if not minimal_twist: - k=j-1728 + k = j-1728 return Sequence([0, 0, 0, -3*j*k, -2*j*k**2], universe=K) n = j.numerator() @@ -729,7 +729,7 @@ def coefficients_from_j(j, minimal_twist=True): from sage.sets.set import Set for p in Set(n.prime_divisors()+m.prime_divisors()): e = min(a4.valuation(p)//2,a6.valuation(p)//3) - if e>0: + if e > 0: p = p**e a4 /= p**2 a6 /= p**3 @@ -754,7 +754,7 @@ def coefficients_from_j(j, minimal_twist=True): return Sequence([0, 0, 0, 0, 1], universe=K) if j == 1728: return Sequence([0, 0, 0, 1, 0], universe=K) - k=j-1728 + k = j-1728 return Sequence([0, 0, 0, -3*j*k, -2*j*k**2], universe=K) @@ -1112,7 +1112,7 @@ def EllipticCurve_from_cubic(F, P=None, morphism=True): # Test whether P is a flex; if not test whether there are any rational flexes: hessian = Matrix([[F.derivative(v1, v2) for v1 in R.gens()] for v2 in R.gens()]).det() - if P and hessian(P)==0: + if P and hessian(P) == 0: flex_point = P else: flexes = C.intersection(Curve(hessian)).rational_points() @@ -1174,11 +1174,11 @@ def EllipticCurve_from_cubic(F, P=None, morphism=True): if not P: raise ValueError('A point must be given when the cubic has no rational flexes') L = tangent_at_smooth_point(C,P) - Qlist = [Q for Q in C.intersection(Curve(L)).rational_points() if C(Q)!=CP] + Qlist = [Q for Q in C.intersection(Curve(L)).rational_points() if C(Q) != CP] # assert Qlist P2 = C(Qlist[0]) L2 = tangent_at_smooth_point(C,P2) - Qlist = [Q for Q in C.intersection(Curve(L2)).rational_points() if C(Q)!=P2] + Qlist = [Q for Q in C.intersection(Curve(L2)).rational_points() if C(Q) != P2] # assert Qlist P3 = C(Qlist[0]) @@ -1345,7 +1345,7 @@ def chord_and_tangent(F, P): raise TypeError('{} does not define a point on a projective curve over {} defined by {}'.format(P,K,F)) L = Curve(tangent_at_smooth_point(C,P)) - Qlist = [Q for Q in C.intersection(L).rational_points() if Q!=P] + Qlist = [Q for Q in C.intersection(L).rational_points() if Q != P] if Qlist: return Qlist[0] return P diff --git a/src/sage/schemes/elliptic_curves/ec_database.py b/src/sage/schemes/elliptic_curves/ec_database.py index 7975ec7edaf..043c287ec7e 100644 --- a/src/sage/schemes/elliptic_curves/ec_database.py +++ b/src/sage/schemes/elliptic_curves/ec_database.py @@ -133,7 +133,7 @@ def rank(self, rank, tors=0, n=10, labels=False): [] """ from sage.env import ELLCURVE_DATA_DIR - data = os.path.join(ELLCURVE_DATA_DIR, 'rank%s' %rank) + data = os.path.join(ELLCURVE_DATA_DIR, 'rank%s' % rank) try: f = open(data) except IOError: @@ -151,7 +151,7 @@ def rank(self, rank, tors=0, n=10, labels=False): # NOTE: only change this bound below after checking/fixing # the Cremona labels in the elliptic_curves package! if N <= 400000: - label = '%s%s%s' %(N, iso, num) + label = '%s%s%s' % (N, iso, num) else: label = None diff --git a/src/sage/schemes/elliptic_curves/ell_field.py b/src/sage/schemes/elliptic_curves/ell_field.py index 34171c2c04b..ae0c0073a9c 100644 --- a/src/sage/schemes/elliptic_curves/ell_field.py +++ b/src/sage/schemes/elliptic_curves/ell_field.py @@ -155,7 +155,7 @@ def quadratic_twist(self, D=None): # degree is odd we can take D=1; otherwise it suffices to # consider odd powers of a generator. D = K(1) - if K.degree() %2==0: + if K.degree() % 2 == 0: D = K.gen() a = D**2 while (x**2 + x + D).roots(): @@ -172,26 +172,26 @@ def quadratic_twist(self, D=None): raise ValueError("twisting parameter D must be specified over infinite fields.") else: try: - D=K(D) + D = K(D) except ValueError: raise ValueError("twisting parameter D must be in the base field.") - if char!=2 and D.is_zero(): + if char != 2 and D.is_zero(): raise ValueError("twisting parameter D must be nonzero when characteristic is not 2") - if char!=2: - b2,b4,b6,b8=self.b_invariants() + if char != 2: + b2,b4,b6,b8 = self.b_invariants() # E is isomorphic to [0,b2,0,8*b4,16*b6] return EllipticCurve(K,[0,b2*D,0,8*b4*D**2,16*b6*D**3]) # now char==2 - if self.j_invariant() !=0: # iff a1!=0 - a1,a2,a3,a4,a6=self.ainvs() - E0=self.change_weierstrass_model(a1,a3/a1,0,(a1**2*a4+a3**2)/a1**3) + if self.j_invariant() != 0: # iff a1!=0 + a1,a2,a3,a4,a6 = self.ainvs() + E0 = self.change_weierstrass_model(a1,a3/a1,0,(a1**2*a4+a3**2)/a1**3) # which has the form = [1,A2,0,0,A6] - assert E0.a1()==K(1) - assert E0.a3()==K(0) - assert E0.a4()==K(0) + assert E0.a1() == K(1) + assert E0.a3() == K(0) + assert E0.a4() == K(0) return EllipticCurve(K,[1,E0.a2()+D,0,0,E0.a6()]) else: raise ValueError("Quadratic twist not implemented in char 2 when j=0") @@ -229,8 +229,8 @@ def two_torsion_rank(self): sage: EllipticCurve('15a1').two_torsion_rank() 2 """ - f=self.division_polynomial(rings.Integer(2)) - n=len(f.roots())+1 + f = self.division_polynomial(rings.Integer(2)) + n = len(f.roots())+1 return rings.Integer(n).ord(rings.Integer(2)) def quartic_twist(self, D): @@ -258,22 +258,22 @@ def quartic_twist(self, D): sage: E.is_isomorphic(E1, GF(13^4,'a')) # optional - sage.rings.finite_rings True """ - K=self.base_ring() - char=K.characteristic() - D=K(D) + K = self.base_ring() + char = K.characteristic() + D = K(D) - if char==2 or char==3: + if char == 2 or char == 3: raise ValueError("Quartic twist not defined in chars 2,3") - if self.j_invariant() !=K(1728): + if self.j_invariant() != K(1728): raise ValueError("Quartic twist not defined when j!=1728") if D.is_zero(): raise ValueError("quartic twist requires a nonzero argument") - c4,c6=self.c_invariants() + c4,c6 = self.c_invariants() # E is isomorphic to [0,0,0,-27*c4,0] - assert c6==0 + assert c6 == 0 return EllipticCurve(K,[0,0,0,-27*c4*D,0]) def sextic_twist(self, D): @@ -303,22 +303,22 @@ def sextic_twist(self, D): sage: E.is_isomorphic(E1, GF(13^6,'a')) # optional - sage.rings.finite_rings True """ - K=self.base_ring() - char=K.characteristic() - D=K(D) + K = self.base_ring() + char = K.characteristic() + D = K(D) - if char==2 or char==3: + if char == 2 or char == 3: raise ValueError("Sextic twist not defined in chars 2,3") - if self.j_invariant() !=K(0): + if self.j_invariant() != K(0): raise ValueError("Sextic twist not defined when j!=0") if D.is_zero(): raise ValueError("Sextic twist requires a nonzero argument") - c4,c6=self.c_invariants() + c4,c6 = self.c_invariants() # E is isomorphic to [0,0,0,0,-54*c6] - assert c4==0 + assert c4 == 0 return EllipticCurve(K,[0,0,0,0,-54*c6*D]) def is_quadratic_twist(self, other): @@ -420,7 +420,7 @@ def is_quadratic_twist(self, other): zero = K.zero() if not K == F.base_ring(): return zero - j=E.j_invariant() + j = E.j_invariant() if j != F.j_invariant(): return zero @@ -429,12 +429,12 @@ def is_quadratic_twist(self, other): return rings.ZZ(1) return K.one() - char=K.characteristic() + char = K.characteristic() - if char==2: + if char == 2: raise NotImplementedError("not implemented in characteristic 2") - elif char==3: - if j==0: + elif char == 3: + if j == 0: raise NotImplementedError("not implemented in characteristic 3 for curves of j-invariant 0") D = E.b2()/F.b2() @@ -443,18 +443,18 @@ def is_quadratic_twist(self, other): c4E,c6E = E.c_invariants() c4F,c6F = F.c_invariants() - if j==0: + if j == 0: um = c6E/c6F - x=rings.polygen(K) - ulist=(x**3-um).roots(multiplicities=False) + x = rings.polygen(K) + ulist = (x**3-um).roots(multiplicities=False) if not ulist: D = zero else: D = ulist[0] - elif j==1728: - um=c4E/c4F - x=rings.polygen(K) - ulist=(x**2-um).roots(multiplicities=False) + elif j == 1728: + um = c4E/c4F + x = rings.polygen(K) + ulist = (x**2-um).roots(multiplicities=False) if not ulist: D = zero else: @@ -519,18 +519,18 @@ def is_quartic_twist(self, other): zero = K.zero() if not K == F.base_ring(): return zero - j=E.j_invariant() - if j != F.j_invariant() or j!=K(1728): + j = E.j_invariant() + if j != F.j_invariant() or j != K(1728): return zero if E.is_isomorphic(F): return K.one() - char=K.characteristic() + char = K.characteristic() - if char==2: + if char == 2: raise NotImplementedError("not implemented in characteristic 2") - elif char==3: + elif char == 3: raise NotImplementedError("not implemented in characteristic 3") else: # now char!=2,3: @@ -588,18 +588,18 @@ def is_sextic_twist(self, other): zero = K.zero() if not K == F.base_ring(): return zero - j=E.j_invariant() + j = E.j_invariant() if j != F.j_invariant() or not j.is_zero(): return zero if E.is_isomorphic(F): return K.one() - char=K.characteristic() + char = K.characteristic() - if char==2: + if char == 2: raise NotImplementedError("not implemented in characteristic 2") - elif char==3: + elif char == 3: raise NotImplementedError("not implemented in characteristic 3") else: # now char!=2,3: @@ -1757,7 +1757,7 @@ def hasse_invariant(self): R = k['x'] x = R.gen() E = self.short_weierstrass_model() - f=(x**3+E.a4()*x+E.a6())**((p-1)//2) + f = (x**3+E.a4()*x+E.a6())**((p-1)//2) return f.coefficients(sparse=False)[p-1] def isogeny_ell_graph(self, l, directed=True, label_by_j=False): diff --git a/src/sage/schemes/elliptic_curves/ell_finite_field.py b/src/sage/schemes/elliptic_curves/ell_finite_field.py index fceaf24616a..cd1e9c1733c 100644 --- a/src/sage/schemes/elliptic_curves/ell_finite_field.py +++ b/src/sage/schemes/elliptic_curves/ell_finite_field.py @@ -146,7 +146,7 @@ def _points_via_group_structure(self): ni = G.generator_orders() ngens = G.ngens() - H0=[self(0)] + H0 = [self(0)] if ngens == 0: # trivial group return H0 for m in range(1,ni[0]): @@ -155,7 +155,7 @@ def _points_via_group_structure(self): return H0 # else noncyclic group - H1=[self(0)] + H1 = [self(0)] for m in range(1,ni[1]): H1.append(H1[-1]+pts[1]) return [P+Q for P in H0 for Q in H1] @@ -207,10 +207,10 @@ def points(self): from sage.structure.sequence import Sequence k = self.base_ring() - if k.is_prime_field() and k.order()>50: + if k.is_prime_field() and k.order() > 50: v = self._points_via_group_structure() else: - v =self._points_fast_sqrt() + v = self._points_fast_sqrt() v.sort() self.__points = Sequence(v, immutable=True) return self.__points @@ -1498,7 +1498,7 @@ def height_above_floor(self, ell, e): phi = gen_to_sage(pari.polmodular(ell),{'x':X, 'y':Y}) j1 = phi([x,j]).roots(multiplicities=False) nj1 = len(j1) - on_floor = self.two_torsion_rank() < 2 if ell==2 else nj1 <= ell + on_floor = self.two_torsion_rank() < 2 if ell == 2 else nj1 <= ell if on_floor: return 0 if e == 1 or nj1 != ell+1: # double roots can only happen at the surface @@ -1569,11 +1569,11 @@ def endomorphism_discriminant_from_class_number(self, h): raise ValueError("Elliptic curve ({}) must be ordinary".format(self)) D1 = self.frobenius_discriminant() D0 = D1.squarefree_part() - if D0 %4 !=1: + if D0 % 4 != 1: D0 *= 4 v = ZZ(D1//D0).isqrt() h0 = D0.class_number() - if h %h0: + if h % h0: raise ValueError("Incorrect class number {}".format(h)) from sage.schemes.elliptic_curves.cm import OrderClassNumber cs = [v//f for f in v.divisors() if OrderClassNumber(D0,h0,f) == h] # cofactors c=v/f compatible with h(f**2D0)=h @@ -1754,7 +1754,7 @@ def twists(self): twists = None if not j: twists = curves_with_j_0(K) - elif j==1728: + elif j == 1728: twists = curves_with_j_1728(K) if twists: # i.e. if j=0 or 1728 # replace the one isomorphic to self with self and move to front @@ -1823,19 +1823,19 @@ def curves_with_j_0(K): if not K.is_finite(): raise ValueError("field must be finite") p = K.characteristic() - if p==2: + if p == 2: return curves_with_j_0_char2(K) - if p==3: + if p == 3: return curves_with_j_0_char3(K) q = K.cardinality() - if q %3==2: + if q % 3 == 2: # Then we only have two quadratic twists (and -3 is non-square) return [EllipticCurve(K, [0,a]) for a in [1,-27]] # Now we have genuine sextic twists, find D generating K* mod 6th powers q2 = (q-1)//2 q3 = (q-1)//3 D = K.gen() - while not D or D**q2 == 1 or D**q3==1: + while not D or D**q2 == 1 or D**q3 == 1: D = K.random_element() return [EllipticCurve(K, [0,D**i]) for i in range(6)] @@ -1880,12 +1880,12 @@ def curves_with_j_1728(K): if not K.is_finite(): raise ValueError("field must be finite") p = K.characteristic() - if p==2: + if p == 2: return curves_with_j_0_char2(K) - if p==3: + if p == 3: return curves_with_j_0_char3(K) q = K.cardinality() - if q %4==3: + if q % 4 == 3: return [EllipticCurve(K, [a,0]) for a in [1,-1]] # Now we have genuine quartic twists, find D generating K* mod 4th powers q2 = (q-1)//2 @@ -1967,13 +1967,13 @@ def curves_with_j_0_char2(K): a = b = c = d = e = None x = polygen(K) q3 = (K.cardinality()-1)//3 - while not a or a**q3==1: + while not a or a**q3 == 1: a = K.random_element() asq = a*a while not b or not b.trace(): b = K.random_element() c = K.one() # OK if degree is 2 mod 4 - if K.degree() %4 == 0: + if K.degree() % 4 == 0: while (x**4+x+c).roots(): c = K.random_element() while not d or (x**2+a*x+d).roots(): @@ -2050,7 +2050,7 @@ def curves_with_j_0_char3(K): while not b or not b.trace(): b = K.random_element() - if K.degree() %2: + if K.degree() % 2: return [EllipticCurve(K, a4a6) for a4a6 in [[1,0], [-1,0], [-1,b], [-1,-b]]] @@ -2203,7 +2203,7 @@ def supersingular_j_polynomial(p, use_cache=True): raise ValueError("p (=%s) should be a prime number" % p) J = polygen(GF(p),'j') - if p<13: + if p < 13: return J.parent().one() if use_cache: fill_ss_j_dict() @@ -2211,7 +2211,7 @@ def supersingular_j_polynomial(p, use_cache=True): return J.parent()(supersingular_j_polynomials[p]) from sage.misc.misc_c import prod - m=(p-1)//2 + m = (p-1)//2 X,T = PolynomialRing(GF(p),2,names=['X','T']).gens() H = sum(binomial(m, i) ** 2 * T ** i for i in range(m + 1)) F = T**2 * (T-1)**2 * X - 256*(T**2-T+1)**3 diff --git a/src/sage/schemes/elliptic_curves/ell_modular_symbols.py b/src/sage/schemes/elliptic_curves/ell_modular_symbols.py index 5fc0398b20e..11c0bc4b978 100644 --- a/src/sage/schemes/elliptic_curves/ell_modular_symbols.py +++ b/src/sage/schemes/elliptic_curves/ell_modular_symbols.py @@ -219,7 +219,7 @@ def _repr_(self): Modular symbol with sign -1 over Rational Field attached to Elliptic Curve defined by y^2 + y = x^3 + x^2 over Rational Field """ - return "Modular symbol with sign %s over %s attached to %s" %( + return "Modular symbol with sign %s over %s attached to %s" % ( self._sign, self._base_ring, self._E) class ModularSymbolECLIB(ModularSymbol): @@ -333,11 +333,11 @@ def __init__(self, E, sign, nap=1000): raise TypeError('sign must -1 or 1') self._sign = ZZ(sign) self._E = E - self._scaling = 1 if E.discriminant()>0 else ZZ(1)/2 + self._scaling = 1 if E.discriminant() > 0 else ZZ(1)/2 self._implementation = "eclib" self._base_ring = QQ # The ECModularSymbol class must be initialized with sign=0 to compute minus symbols - self._modsym = ECModularSymbol(E, int(sign==1), nap) + self._modsym = ECModularSymbol(E, int(sign == 1), nap) self.cache = {True: {}, False: {}} def _call_with_caching(self, r, base_at_infinity=True): @@ -468,7 +468,7 @@ def __init__(self, E, sign, normalize="L_ratio"): self._scaling = 1 self._e = self._modsym.dual_eigenvector() else : - raise ValueError("no normalization %s known for modular symbols" %normalize) + raise ValueError("no normalization %s known for modular symbols" % normalize) def _find_scaling_L_ratio(self): r""" @@ -553,7 +553,7 @@ def _find_scaling_L_ratio(self): if at0 != 0 : l1 = self.__lalg__(1) if at0 != l1: - verbose('scale modular symbols by %s' %(l1/at0)) + verbose('scale modular symbols by %s' % (l1/at0)) self._scaling = l1/at0 else : # if [0] = 0, we can still hope to scale it correctly by considering twists of E @@ -565,7 +565,7 @@ def _find_scaling_L_ratio(self): D = Dlist[j] # the following line checks if the twist of the newform of E by D is a newform # this is to avoid that we 'twist back' - if all( valuation(E.conductor(),ell)<= valuation(D,ell) for ell in prime_divisors(D) ) : + if all( valuation(E.conductor(),ell) <= valuation(D,ell) for ell in prime_divisors(D) ) : at0 = sum([kronecker_symbol(D,u) * self(ZZ(u)/D) for u in range(1,abs(D))]) j += 1 if j == 30 and at0 == 0: # curves like "121b1", "225a1", "225e1", "256a1", "256b1", "289a1", "361a1", "400a1", "400c1", "400h1", "441b1", "441c1", "441d1", "441f1 .. will arrive here @@ -574,7 +574,7 @@ def _find_scaling_L_ratio(self): else : l1 = self.__lalg__(D) if at0 != l1: - verbose('scale modular symbols by %s found at D=%s ' %(l1/at0,D), level=2) + verbose('scale modular symbols by %s found at D=%s ' % (l1/at0,D), level=2) self._scaling = l1/at0 else : # that is when sign = -1 @@ -584,7 +584,7 @@ def _find_scaling_L_ratio(self): while j < 30 and at0 == 0 : # computes [0]+ for the twist of E by D until one value is non-zero D = Dlist[j] - if all( valuation(E.conductor(),ell)<= valuation(D,ell) for ell in prime_divisors(D) ) : + if all( valuation(E.conductor(),ell) <= valuation(D,ell) for ell in prime_divisors(D) ) : at0 = - sum([kronecker_symbol(D,u) * self(ZZ(u)/D) for u in range(1,abs(D))]) j += 1 if j == 30 and at0 == 0: # no more hope for a normalization @@ -593,7 +593,7 @@ def _find_scaling_L_ratio(self): else : l1 = self.__lalg__(D) if at0 != l1: - verbose('scale modular symbols by %s' %(l1/at0)) + verbose('scale modular symbols by %s' % (l1/at0)) self._scaling = l1/at0 def __lalg__(self, D): diff --git a/src/sage/schemes/elliptic_curves/ell_rational_field.py b/src/sage/schemes/elliptic_curves/ell_rational_field.py index edbd87412f1..824149ca204 100644 --- a/src/sage/schemes/elliptic_curves/ell_rational_field.py +++ b/src/sage/schemes/elliptic_curves/ell_rational_field.py @@ -104,13 +104,13 @@ Z = IntegerRing() IR = rings.RealIntervalField(20) -_MAX_HEIGHT=21 +_MAX_HEIGHT = 21 # complex multiplication dictionary: # CMJ is a dict of pairs (j,D) where j is a rational CM j-invariant # and D is the corresponding quadratic discriminant -CMJ={ 0: -3, 54000: -12, -12288000: -27, 1728: -4, 287496: -16, +CMJ = { 0: -3, 54000: -12, -12288000: -27, 1728: -4, 287496: -16, -3375: -7, 16581375: -28, 8000: -8, -32768: -11, -884736: -19, -884736000: -43, -147197952000: -67, -262537412640768000: -163} @@ -539,7 +539,7 @@ def conductor(self, algorithm="pari"): try: return self.__conductor_gp except AttributeError: - self.__conductor_gp = Integer(gp.eval('ellglobalred(ellinit(%s,0))[1]' %list(self.a_invariants()))) + self.__conductor_gp = Integer(gp.eval('ellglobalred(ellinit(%s,0))[1]' % list(self.a_invariants()))) return self.__conductor_gp elif algorithm == "mwrank": @@ -565,11 +565,11 @@ def conductor(self, algorithm="pari"): N3 = self.conductor("gp") N4 = self.conductor("generic") if N1 != N2 or N2 != N3 or N2 != N4: - raise ArithmeticError("PARI, mwrank, gp and Sage compute different conductors (%s,%s,%s,%s) for %s" %( + raise ArithmeticError("PARI, mwrank, gp and Sage compute different conductors (%s,%s,%s,%s) for %s" % ( N1, N2, N3, N4, self)) return N1 else: - raise ValueError("algorithm %r is not known" %algorithm) + raise ValueError("algorithm %r is not known" % algorithm) #################################################################### # Access to PARI curves related to this curve. @@ -711,13 +711,13 @@ def database_curve(self): try: return self.__database_curve except AttributeError: - verbose_verbose("Looking up %s in the database." %self) + verbose_verbose("Looking up %s in the database." % self) D = sage.databases.cremona.CremonaDatabase() ainvs = list(self.minimal_model().ainvs()) try: self.__database_curve = D.elliptic_curve_from_ainvs(ainvs) except RuntimeError: - raise RuntimeError("Elliptic curve %s not in the database." %self) + raise RuntimeError("Elliptic curve %s not in the database." % self) return self.__database_curve def Np(self, p): @@ -910,7 +910,7 @@ def anlist(self, n, python_ints=False): n = int(n) e = self.pari_mincurve() if n >= 2147483648: - raise RuntimeError("anlist: n (=%s) must be < 2147483648." %n) + raise RuntimeError("anlist: n (=%s) must be < 2147483648." % n) v = [0] + e.ellan(n, python_ints=True) if not python_ints: @@ -1535,7 +1535,7 @@ def analytic_rank(self, algorithm="pari", leading_coefficient=False): from sage.lfunctions.lcalc import lcalc return lcalc.analytic_rank(L=self) except TypeError as msg: - raise RuntimeError("unable to compute analytic rank using rubinstein algorithm (%s)" %msg) + raise RuntimeError("unable to compute analytic rank using rubinstein algorithm (%s)" % msg) elif algorithm == 'sympow': if leading_coefficient: raise NotImplementedError("Cannot compute leading coefficient using sympow") @@ -1561,7 +1561,7 @@ def analytic_rank(self, algorithm="pari", leading_coefficient=False): raise RuntimeError("Bug in analytic_rank; algorithms don't agree! (E=%s)" % self) return list(S)[0] else: - raise ValueError("algorithm %s not defined" %algorithm) + raise ValueError("algorithm %s not defined" % algorithm) def analytic_rank_upper_bound(self, max_Delta=None, @@ -1917,7 +1917,7 @@ def simon_two_descent(self, verbose=0, lim1=5, lim3=50, limtriv=3, two_selmer_rank = t[1] pts = t[2] if rank_low_bd == two_selmer_rank - self.two_torsion_rank(): - if verbose>0: + if verbose > 0: print("Rank determined successfully, saturating...") gens = self.saturation(pts)[0] if len(gens) == rank_low_bd: @@ -2095,7 +2095,7 @@ def rank(self, use_database=True, verbose=False, # true rank rank_bound = self.analytic_rank_upper_bound() if rank_bound <= 1: - verbose_verbose("rank %s due to zero sum bound and parity" %rank_bound) + verbose_verbose("rank %s due to zero sum bound and parity" % rank_bound) rank = Integer(rank_bound) self.__rank = (rank, proof) return rank @@ -2113,7 +2113,7 @@ def rank(self, use_database=True, verbose=False, else: Lprime, err = self.lseries().deriv_at1(prec) if abs(Lprime) > err + R(0.0001): # definitely doesn't vanish - verbose_verbose("rank 1 because L'(E,1)=%s" %Lprime) + verbose_verbose("rank 1 because L'(E,1)=%s" % Lprime) rank = Integer(1) self.__rank = (rank, proof) return rank @@ -2144,7 +2144,7 @@ def rank(self, use_database=True, verbose=False, X = self.mwrank() if 'determined unconditionally' not in X or 'only a lower bound of' in X: if proof: - X= "".join(X.split("\n")[-4:-2]) + X = "".join(X.split("\n")[-4:-2]) print(X) raise RuntimeError('rank not provably correct') else: @@ -2162,7 +2162,7 @@ def rank(self, use_database=True, verbose=False, match = 'found points of rank' i = X.find(match) if i == -1: - raise RuntimeError("%s\nbug -- tried to find 'Rank =' or 'found points of rank' in mwrank output but couldn't." %X) + raise RuntimeError("%s\nbug -- tried to find 'Rank =' or 'found points of rank' in mwrank output but couldn't." % X) j = i + X[i:].find('\n') rank = Integer(X[i+len(match)+1:j]) self.__rank = (rank, proof) @@ -2320,7 +2320,7 @@ def _compute_gens(self, proof, verbose_verbose("Rank = 1, so using direct search.") h = 6 while h <= rank1_search: - verbose_verbose("Trying direct search up to height %s" %h) + verbose_verbose("Trying direct search up to height %s" % h) G = self.point_search(h, verbose) G = [P for P in G if P.order() == oo] if G: @@ -2636,7 +2636,7 @@ def saturation(self, points, verbose=False, max_prime=-1, min_prime=2): if not isinstance(P, ell_point.EllipticCurvePoint_field): P = self(P) elif P.curve() != self: - raise ArithmeticError("point (=%s) must be %s." %(P,self)) + raise ArithmeticError("point (=%s) must be %s." % (P,self)) minimal = True if not self.is_minimal(): @@ -2773,7 +2773,7 @@ def h_oo(x): elif algorithm == 'mwrank': return self.mwrank_curve().silverman_bound() else: - raise ValueError("unknown algorithm '%s'" %algorithm) + raise ValueError("unknown algorithm '%s'" % algorithm) def point_search(self, height_limit, verbose=False, rank_bound=None): r""" @@ -3180,10 +3180,10 @@ def tamagawa_exponent(self, p): if not arith.is_prime(p): raise ArithmeticError("p must be prime") cp = self.tamagawa_number(p) - if not cp==4: + if not cp == 4: return cp ks = self.kodaira_type(p) - if ks._roman==1 and ks._n %2==0 and ks._starred: + if ks._roman == 1 and ks._n % 2 == 0 and ks._starred: return 2 return 4 @@ -3763,7 +3763,7 @@ def modular_degree(self, algorithm='sympow', M=1): from sage.interfaces.magma import magma m = rings.Integer(magma(self).ModularDegree()) else: - raise ValueError("unknown algorithm %s" %algorithm) + raise ValueError("unknown algorithm %s" % algorithm) self.__modular_degree = m return m @@ -3884,7 +3884,7 @@ def congruence_number(self, M=1): 1 """ # Case 1: M==1 - if M==1: + if M == 1: try: return self.__congruence_number except AttributeError: @@ -3996,7 +3996,7 @@ def reduction(self,p): raise AttributeError("p must be prime.") disc = self.discriminant() if not disc.valuation(p) == 0: - local_data=self.local_data(p) + local_data = self.local_data(p) if local_data.has_good_reduction(): return local_data.minimal_model().change_ring(rings.GF(p)) raise AttributeError("The curve must have good reduction at p.") @@ -4285,7 +4285,7 @@ def cm_discriminant(self): try: return ZZ(CMJ[self.j_invariant()]) except KeyError: - raise ValueError("%s does not have CM" %self) + raise ValueError("%s does not have CM" % self) def has_rational_cm(self, field=None): r""" @@ -4367,7 +4367,7 @@ def has_rational_cm(self, field=None): except ValueError: return False try: - if field.characteristic()==0: + if field.characteristic() == 0: D = field(D) return D.is_square() raise ValueError("Error in has_rational_cm: %s is not an extension field of QQ" % field) @@ -4726,9 +4726,9 @@ def isogenies_prime_degree(self, l=None): if l.is_prime(proof=False): return isogenies_sporadic_Q(self, l) else: - raise ValueError("%s is not prime." %l) + raise ValueError("%s is not prime." % l) except AttributeError: - raise ValueError("%s is not prime." %l) + raise ValueError("%s is not prime." % l) if l is None: isogs = isogenies_prime_degree_genus_0(self) if isogs: @@ -5375,8 +5375,8 @@ def supersingular_primes(self, B): v = self.aplist(max(B, 3)) P = rings.prime_range(max(B,3)+1) N = self.conductor() - return [P[i] for i in [0,1] if P[i] <= B and v[i] %P[i]==0 and N %P[i] != 0] + \ - [P[i] for i in range(2,len(v)) if v[i] == 0 and N %P[i] != 0] + return [P[i] for i in [0,1] if P[i] <= B and v[i] % P[i] == 0 and N % P[i] != 0] + \ + [P[i] for i in range(2,len(v)) if v[i] == 0 and N % P[i] != 0] def ordinary_primes(self, B): """ @@ -6004,7 +6004,7 @@ def point_preprocessing(free,tor): P = free[i0] for i in range(r): if not free_id[i]: - if i==i0: + if i == i0: newfree[i] = 2*newfree[i] else: newfree[i] += P @@ -6039,9 +6039,9 @@ def point_preprocessing(free,tor): RR = R prec = RR.precision() ei = pol.roots(RR,multiplicities=False) - while len(ei)<3: - prec*=2 - RR=RealField(prec) + while len(ei) < 3: + prec *= 2 + RR = RealField(prec) ei = pol.roots(RR,multiplicities=False) e1,e2,e3 = ei if r >= 1: #preprocessing of mw_base only necessary if rank > 0 @@ -6072,9 +6072,9 @@ def point_preprocessing(free,tor): h_E = self.height() w1, w2 = self.period_lattice().basis() mu = R(disc).abs().log() / 6 - if j!=0: + if j != 0: mu += max(R(1),R(j).abs().log()) / 6 - if b2!=0: + if b2 != 0: mu += max(R(1),R(b2).abs().log()) mu += log(R(2)) else: @@ -6100,7 +6100,7 @@ def point_preprocessing(free,tor): mod_h_list.append(max(mw_base[i].height(),h_E,c7*mw_base_log[i]**2)) c9_help_list.append((mod_h_list[i]).sqrt()/mw_base_log[i]) c9 = e/c7.sqrt() * min(c9_help_list) - n=r+1 + n = r+1 c10 = R(2 * 10**(8+7*n) * R((2/e)**(2 * n**2)) * (n+1)**(4 * n**2 + 10 * n) * log(c9)**(-2*n - 1) * misc.prod(mod_h_list)) top = Z(128) # arbitrary first upper bound @@ -6210,7 +6210,7 @@ def point_preprocessing(free,tor): print(L) sys.stdout.flush() - if len(tors_points)>1: + if len(tors_points) > 1: x_int_points_t = set() for x in x_int_points: P = self.lift_x(x) @@ -6386,7 +6386,7 @@ def S_integral_points(self, S, mw_base='auto', both_signs=False, verbose=False, if not self.is_integral(): raise ValueError("S_integral_points() can only be called on an integral model") if not all(self.is_p_minimal(s) for s in S): - raise ValueError("%s must be p-minimal for all primes in S" %self) + raise ValueError("%s must be p-minimal for all primes in S" % self) try: len_S = len(S) @@ -6430,11 +6430,11 @@ def reduction_at(p): m = copy(M.identity_matrix()) for i in range(r): try: - m[i, r] = Z((beta[indexp][i]) %pc) + m[i, r] = Z((beta[indexp][i]) % pc) except ZeroDivisionError: #If Inverse doesn't exist, change denominator (which is only approx) val_nu = (beta[indexp][i]).numerator() val_de = (beta[indexp][i]).denominator() - m[i, r] = Z((val_nu/(val_de+1)) %pc) + m[i, r] = Z((val_nu/(val_de+1)) % pc) m[r,r] = max(Z(1), pc) #LLL - implemented in sage - operates on rows not on columns @@ -6489,8 +6489,8 @@ def S_integral_points_with_bounded_mw_coeffs(): denominator. """ from sage.groups.generic import multiples - xs=set() - N=H_q + xs = set() + N = H_q def test(P): """ @@ -6509,7 +6509,7 @@ def test_with_T(R): test(R+T) # For small rank and small H_q perform simple search - if r==1 and N<=10: + if r == 1 and N <= 10: for P in multiples(mw_base[0],N+1): test_with_T(P) return xs @@ -6519,7 +6519,7 @@ def test_with_T(R): # stops when (0,0,...,0) is reached because after that, only inverse points of # previously tested points would be tested - E0=E(0) + E0 = E(0) ni = [-N for i in range(r)] mw_baseN = [-N*P for P in mw_base] Pi = [0 for j in range(r)] @@ -6528,7 +6528,7 @@ def test_with_T(R): Pi[i] = Pi[i-1] + mw_baseN[i] while True: - if all(n==0 for n in ni): + if all(n == 0 for n in ni): test_with_T(E0) break @@ -6537,11 +6537,11 @@ def test_with_T(R): # increment indices and stored points i0 = r-1 - while ni[i0]==N: + while ni[i0] == N: ni[i0] = -N i0 -= 1 ni[i0] += 1 - if all(n==0 for n in ni[0:i0+1]): + if all(n == 0 for n in ni[0:i0+1]): Pi[i0] = E0 else: Pi[i0] += mw_base[i0] @@ -6579,7 +6579,7 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): and search for integral points on the scaled model. """ x_min = min(self.two_division_polynomial().roots(R,multiplicities=False)) - x_min_neg = bool(x_min<0) + x_min_neg = bool(x_min < 0) x_min_pos = not x_min_neg log_ab = R(abs_bound.log()) alpha = [(log_ab/R(log(p,e))).floor() for p in S] @@ -6617,11 +6617,11 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): for n in arith.xsrange(n_min,n_max+1): tmp = n/de # to save time, do not check de is the exact denominator if E.is_x_coord(tmp): - xs+=[tmp] + xs += [tmp] if not pos_n_only: if n <= neg_n_max: if E.is_x_coord(-tmp): - xs+=[-tmp] + xs += [-tmp] return set(xs) #<------------------------------------------------------------------------- @@ -6631,7 +6631,7 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): E = self tors_points = E.torsion_points() - if (r==0):#only Torsionpoints to consider + if (r == 0):#only Torsionpoints to consider int_points = [P for P in tors_points if not P.is_zero()] int_points = [P for P in int_points if P[0].is_S_integral(S)] if not both_signs: @@ -6665,9 +6665,9 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): RR = R prec = RR.precision() ei = pol.roots(RR,multiplicities=False) - while len(ei)<3: - prec*=2 - RR=RealField(prec) + while len(ei) < 3: + prec *= 2 + RR = RealField(prec) ei = pol.roots(RR,multiplicities=False) e1,e2,e3 = ei elif disc < 0: # one real component => 1 root in RR (=: e3), @@ -6715,21 +6715,21 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): mw_base_log = [(pts.elliptic_logarithm().abs())*(len_tors/w1) for pts in mw_base] mw_base_p_log = [] beta = [] - mp=[] + mp = [] tmp = 0 for p in S: Np = E.Np(p) cp = E.tamagawa_exponent(p) mp_temp = Z(len_tors).lcm(cp*Np) mp.append(mp_temp) #only necessary because of verbose below - p_prec=30+E.discriminant().valuation(p) - p_prec_ok=False + p_prec = 30+E.discriminant().valuation(p) + p_prec_ok = False while not p_prec_ok: if verbose: print("p=", p, ": trying with p_prec = ", p_prec) try: mw_base_p_log.append([mp_temp*(pts.padic_elliptic_logarithm(p,absprec=p_prec)) for pts in mw_base]) - p_prec_ok=True + p_prec_ok = True except ValueError: p_prec *= 2 #reorder mw_base_p: last value has minimal valuation at p @@ -6748,7 +6748,7 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): except ValueError: # e.g. mw_base_p_log[tmp]==[0]: can occur e.g. [?]'172c6, S=[2] beta.append([0] for j in range(r)) - tmp +=1 + tmp += 1 if verbose: print('mw_base', mw_base) @@ -6775,7 +6775,7 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): while break_cond < 0.9: #reduction at infinity - bound_list=[] + bound_list = [] c = R((H_q**n)*100) m = copy(M.identity_matrix()) for i in range(r): @@ -6865,7 +6865,7 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound): print(L) sys.stdout.flush() - if len(tors_points)>1: + if len(tors_points) > 1: x_S_int_points_t = set() for x in x_S_int_points: P = E.lift_x(x) @@ -6984,7 +6984,7 @@ def integral_points_with_bounded_mw_coeffs(E, mw_base, N, x_bound): True """ from sage.groups.generic import multiples - xs=set() + xs = set() tors_points = E.torsion_points() r = len(mw_base) @@ -7007,7 +7007,7 @@ def use_t(R): # We use a naive method when the number of possibilities is small: - if r==1 and N<=10: + if r == 1 and N <= 10: for P in multiples(mw_base[0],N+1): use_t(P) return xs @@ -7040,7 +7040,7 @@ def is_approx_integral(rx): Rgens = [ER.lift_x(P[0]) for P in mw_base] for i in range(r): - if abs(Rgens[i][1]-mw_base[i][1])>abs((-Rgens[i])[1]-mw_base[i][1]): + if abs(Rgens[i][1]-mw_base[i][1]) > abs((-Rgens[i])[1]-mw_base[i][1]): Rgens[i] = -Rgens[i] # the ni loop through all tuples (a1,a2,...,ar) with @@ -7070,13 +7070,13 @@ def is_approx_integral(rx): # increment indices and stored points i0 = r-1 - while ni[i0]==N: + while ni[i0] == N: ni[i0] = -N i0 -= 1 ni[i0] += 1 # The next lines are to prevent rounding error: (-P)+P behaves # badly for real points! - if all(n==0 for n in ni[0:i0+1]): + if all(n == 0 for n in ni[0:i0+1]): RPi[i0] = ER0 else: RPi[i0] += Rgens[i0] diff --git a/src/sage/schemes/elliptic_curves/ell_wp.py b/src/sage/schemes/elliptic_curves/ell_wp.py index 317a68e6a2d..462899d33f2 100644 --- a/src/sage/schemes/elliptic_curves/ell_wp.py +++ b/src/sage/schemes/elliptic_curves/ell_wp.py @@ -142,7 +142,7 @@ def weierstrass_p(E, prec=20, algorithm=None): if algorithm == "pari": if 0 < p <= prec + 2: - raise ValueError("for computing the Weierstrass p-function via pari, the characteristic (%s) of the underlying field must be greater than prec + 2 = %s" %(p,prec+2)) + raise ValueError("for computing the Weierstrass p-function via pari, the characteristic (%s) of the underlying field must be greater than prec + 2 = %s" % (p,prec+2)) return compute_wp_pari(E, prec) # quadratic and fast algorithms require short Weierstrass model @@ -153,11 +153,11 @@ def weierstrass_p(E, prec=20, algorithm=None): if algorithm == "quadratic": if 0 < p <= prec + 2: - raise ValueError("for computing the Weierstrass p-function via the quadratic algorithm, the characteristic (%s) of the underlying field must be greater than prec + 2 = %s" %(p,prec+2)) + raise ValueError("for computing the Weierstrass p-function via the quadratic algorithm, the characteristic (%s) of the underlying field must be greater than prec + 2 = %s" % (p,prec+2)) wp = compute_wp_quadratic(k, A, B, prec) elif algorithm == "fast": if 0 < p <= prec + 4: - raise ValueError("for computing the Weierstrass p-function via the fast algorithm, the characteristic (%s) of the underlying field must be greater than prec + 4 = %s" %(p,prec+4)) + raise ValueError("for computing the Weierstrass p-function via the fast algorithm, the characteristic (%s) of the underlying field must be greater than prec + 4 = %s" % (p,prec+4)) wp = compute_wp_fast(k, A, B, prec) else: raise ValueError("unknown algorithm for computing the Weierstrass p-function") diff --git a/src/sage/schemes/elliptic_curves/formal_group.py b/src/sage/schemes/elliptic_curves/formal_group.py index 3bf8ae2474f..7949eb94bcf 100644 --- a/src/sage/schemes/elliptic_curves/formal_group.py +++ b/src/sage/schemes/elliptic_curves/formal_group.py @@ -551,7 +551,7 @@ def group_law(self, prec=10): # note that the following formula differs from the one in Silverman page 119. # See github issue 9646 for the explanation and justification. t3 = -t1 - t2 - \ - (a1*lam + a3*lam2 + a2*nu + 2*a4*lam*nu + 3*a6*lam2*nu)/ \ + (a1*lam + a3*lam2 + a2*nu + 2*a4*lam*nu + 3*a6*lam2*nu) / \ (1 + a2*lam + a4*lam2 + a6*lam3) inv = self.inverse(prec) diff --git a/src/sage/schemes/elliptic_curves/gal_reps.py b/src/sage/schemes/elliptic_curves/gal_reps.py index 28ac78664bc..1b8d2ad64fd 100644 --- a/src/sage/schemes/elliptic_curves/gal_reps.py +++ b/src/sage/schemes/elliptic_curves/gal_reps.py @@ -352,7 +352,7 @@ def reducible_primes(self): if j in sporadic_j: # includes all CM j-invariants R = [sporadic_j[j]] else: - R = [l for l in [2,3,5,7,13] if len(E.isogenies_prime_degree(l))>0] + R = [l for l in [2,3,5,7,13] if len(E.isogenies_prime_degree(l)) > 0] self.__reducible_primes = R return R @@ -464,7 +464,7 @@ def _is_surjective(self, p, A): T = self._E.torsion_subgroup().order() if T % p == 0 and p != 2: # we could probably determine the group structure directly - self.__image_type[p] = "The image is meta-cyclic inside a Borel subgroup as there is a %s-torsion point on the curve." %p + self.__image_type[p] = "The image is meta-cyclic inside a Borel subgroup as there is a %s-torsion point on the curve." % p return False R = rings.PolynomialRing(self._E.base_ring(), 'x') @@ -472,7 +472,7 @@ def _is_surjective(self, p, A): if p == 2: # E is isomorphic to [0,b2,0,8*b4,16*b6] - b2,b4,b6,b8=self._E.b_invariants() + b2,b4,b6,b8 = self._E.b_invariants() f = x**3 + b2*x**2 + 8*b4*x + 16*b6 if not f.is_irreducible(): if len(f.roots()) > 2: @@ -578,7 +578,7 @@ def _is_surjective(self, p, A): if s != 0 and s not in signs: signs.append(s) if len(signs) == 2 and exclude_exceptional_image: - self.__image_type[p] = "The image is all of GL_2(F_%s)." %p + self.__image_type[p] = "The image is all of GL_2(F_%s)." % p return True #,None if A == -1: # we came in from is reducible. Now go out with False @@ -675,19 +675,19 @@ def non_surjective(self, A=1000): p0 = arith.next_prime(p0+1) C2 = (sqrt(p0)+1)**8 C = max(C1,C2) - verbose("j is not integral -- Serre's bound is %s" %C) + verbose("j is not integral -- Serre's bound is %s" % C) C3 = 1 + 4*sqrt(6)*int(N)/3 * sqrt(misc.mul([1+1.0/int(p) for p,_ in arith.factor(N)])) C = min(C,C3) - verbose("conductor = %s, and bound is %s" %(N,C)) + verbose("conductor = %s, and bound is %s" % (N,C)) else: # Cojocaru's bound (depends on the conductor) C = 1 + 4*sqrt(6)*int(N)/3 * sqrt(misc.mul([1+1.0/int(p) for p,_ in arith.factor(N)])) - verbose("conductor = %s, and bound is %s" %(N,C)) + verbose("conductor = %s, and bound is %s" % (N,C)) B = [] p = 2 while p <= C: t = self.is_surjective(p, A=A) - verbose("(%s,%s)" %(p,t)) + verbose("(%s,%s)" % (p,t)) # both False and None will be appended here. if not t: B.append(p) @@ -989,15 +989,15 @@ def image_type(self, p): u = k(a_ell)**2 * k(ell)**(-1) if (u not in ex_setp) and could_be_exc == 1: # it can not be in the exceptional - verbose("the image cannot be exceptional, found u=%s" %u, level=2) + verbose("the image cannot be exceptional, found u=%s" % u, level=2) could_be_exc = 0 if a_ell != 0 and arith.kronecker(a_ell**2 - 4*ell,p) == 1 and could_be_non_split == 1: # it can not be in the normalizer of the non-split Cartan - verbose("the image cannot be non-split, found u=%s" %u, level=2) + verbose("the image cannot be non-split, found u=%s" % u, level=2) could_be_non_split = 0 if a_ell != 0 and arith.kronecker(a_ell**2 - 4*ell,p) == -1 and could_be_split == 1: # it can not be in the normalizer of the split Cartan - verbose("the image cannot be split, found u=%s" %u, level=2) + verbose("the image cannot be split, found u=%s" % u, level=2) could_be_split = 0 assert could_be_exc + could_be_split + could_be_non_split > 0, "bug in image_type." @@ -1050,7 +1050,7 @@ def image_type(self, p): return self.__image_type[p] else: - self.__image_type[p] = "The image in PGL_2(F_%s) is an exceptional group A_4, S_4 or A_5, but we could not determine which one." %p + self.__image_type[p] = "The image in PGL_2(F_%s) is an exceptional group A_4, S_4 or A_5, but we could not determine which one." % p return self.__image_type[p] # If all fails, we probably have a fairly small group and we can try to detect it using the galois_group @@ -1058,7 +1058,7 @@ def image_type(self, p): K = self._E.division_field(p, 'z') d = K.absolute_degree() - verbose("field of degree %s. try to compute Galois group" %(d), level=2) + verbose("field of degree %s. try to compute Galois group" % (d), level=2) # If the degree is too big, we have no chance at the Galois # group. K.galois_group calls is_galois which used to rely on # pari's Galois group computations, so degree < 12 @@ -1067,7 +1067,7 @@ def image_type(self, p): raise Exception() G = K.galois_group() except Exception: - self.__image_type[p] = "The image is a group of order %s." %d + self.__image_type[p] = "The image is a group of order %s." % d return self.__image_type[p] else: @@ -1075,7 +1075,7 @@ def image_type(self, p): ab = "" else: ab = "non-" - self.__image_type[p] = "The image is a " + ab + "abelian group of order %s." %G.order() + self.__image_type[p] = "The image is a " + ab + "abelian group of order %s." % G.order() return self.__image_type[p] ## everything failed : diff --git a/src/sage/schemes/elliptic_curves/gal_reps_number_field.py b/src/sage/schemes/elliptic_curves/gal_reps_number_field.py index c9dc54d2668..10b92bc9978 100644 --- a/src/sage/schemes/elliptic_curves/gal_reps_number_field.py +++ b/src/sage/schemes/elliptic_curves/gal_reps_number_field.py @@ -542,7 +542,7 @@ def Frobenius_filter(E, L, patience=100): L.remove(2) include_2 = not E.division_polynomial(2).is_irreducible() - K_is_Q = (K==QQ) + K_is_Q = (K == QQ) from sage.arith.misc import primes from sage.rings.infinity import infinity @@ -557,7 +557,7 @@ def primes_iter(): yield P numP = 0 for P in primes_iter(): - if not L or numP==patience: # stop if no primes are left, or patience is exhausted + if not L or numP == patience: # stop if no primes are left, or patience is exhausted break numP += 1 @@ -798,7 +798,7 @@ def deg_one_primes_iter(K, principal_only=False): # imaginary quadratic fields have no principal primes of norm < disc / 4 start = K.discriminant().abs() // 4 if principal_only and K.signature() == (0,1) else 2 - K_is_Q = (K==QQ) + K_is_Q = (K == QQ) for p in primes(start=start, stop=Infinity): if K_is_Q: @@ -859,23 +859,23 @@ def _semistable_reducible_primes(E, verbose=False): while len(precomp) < 2: P = next(deg_one_primes) p = P.norm() - if p != last_p and (d==1 or P.ramification_index() == 1) and E.has_good_reduction(P): + if p != last_p and (d == 1 or P.ramification_index() == 1) and E.has_good_reduction(P): precomp.append(P) last_p = p Px, Py = precomp x, y = [PP.gens_reduced()[0] for PP in precomp] - EmodPx = E.reduction(Px) if d>1 else E.reduction(x) - EmodPy = E.reduction(Py) if d>1 else E.reduction(y) + EmodPx = E.reduction(Px) if d > 1 else E.reduction(x) + EmodPy = E.reduction(Py) if d > 1 else E.reduction(y) fxpol = EmodPx.frobenius_polynomial() fypol = EmodPy.frobenius_polynomial() fx12pol = fxpol.adams_operator(12) # roots are 12th powers of those of fxpol fy12pol = fypol.adams_operator(12) - px = x.norm() if d>1 else x - py = y.norm() if d>1 else x + px = x.norm() if d > 1 else x + py = y.norm() if d > 1 else x Zx = fxpol.parent() - xpol = x.charpoly() if d>1 else Zx([-x,1]) - ypol = y.charpoly() if d>1 else Zx([-y,1]) + xpol = x.charpoly() if d > 1 else Zx([-x,1]) + ypol = y.charpoly() if d > 1 else Zx([-y,1]) if verbose: print("Finished precomp, x={} (p={}), y={} (p={})".format(x,px,y,py)) @@ -938,7 +938,7 @@ def _semistable_reducible_primes(E, verbose=False): # has CM and computing the set of CM j-invariants of K to check. # TODO: Is this the best value for this parameter? - while div==0 and patience>0: + while div == 0 and patience > 0: P = next(deg_one_primes) # a prime of K not K_rel while E.has_bad_reduction(P): P = next(deg_one_primes) @@ -954,7 +954,7 @@ def _semistable_reducible_primes(E, verbose=False): div2 = Integer(xpol.resultant(fpol.adams_operator(12)) // x.norm()**12) if div2: div = div2.isqrt() - assert div2==div**2 + assert div2 == div**2 if verbose: print("...div = {}".format(div)) else: @@ -1324,7 +1324,7 @@ def remove_primes(B): B1 = B1.prime_to_m_part(p) return B1 ll = primes(5,max_l) # iterator - while B!=1 and len(ells)= 2: print(cmd) - s = gp.eval('ans=%s;' %cmd) + s = gp.eval('ans=%s;' % cmd) if s.find(" *** ") != -1: - raise RuntimeError("\n%s\nAn error occurred while running Simon's 2-descent program" %s) + raise RuntimeError("\n%s\nAn error occurred while running Simon's 2-descent program" % s) if verbose > 0: print(s) v = gp.eval('ans') - if v=='ans': # then the call to ellQ_ellrank() or bnfellrank() failed + if v == 'ans': # then the call to ellQ_ellrank() or bnfellrank() failed raise RuntimeError("An error occurred while running Simon's 2-descent program") if verbose >= 2: print("v = %s" % v) diff --git a/src/sage/schemes/elliptic_curves/heegner.py b/src/sage/schemes/elliptic_curves/heegner.py index d5e2a7e306d..71e620c643a 100644 --- a/src/sage/schemes/elliptic_curves/heegner.py +++ b/src/sage/schemes/elliptic_curves/heegner.py @@ -521,7 +521,7 @@ def quadratic_field(self): with sqrt_minus_7 = 2.645751311064591?*I """ D = self.__D - var = 'sqrt_minus_%s' %(-D) + var = 'sqrt_minus_%s' % (-D) return number_field.QuadraticField(D,var) @cached_method @@ -743,10 +743,10 @@ def _repr_(self): 'Galois group of Ring class field extension of QQ[sqrt(-7)] of conductor 5' """ if self.base_field() != QQ: - s = " over %s" %self.base_field() + s = " over %s" % self.base_field() else: s = '' - return "Galois group of %s%s" %(self.field(), s) + return "Galois group of %s%s" % (self.field(), s) def field(self): """ @@ -1060,7 +1060,7 @@ def _alpha_to_p1_element(self, alpha): n = gcd(w) w /= n c = P1.N() - w = P1.normalize(ZZ(w[0]) %c, ZZ(w[1]) %c) + w = P1.normalize(ZZ(w[0]) % c, ZZ(w[1]) % c) if w == (0,0): w = (1,0) return w @@ -1390,7 +1390,7 @@ def _repr_(self): sage: conj._repr_() 'Complex conjugation automorphism of Ring class field extension of QQ[sqrt(-7)] of conductor 5' """ - return "Complex conjugation automorphism of %s" %self.domain() + return "Complex conjugation automorphism of %s" % self.domain() ## def __mul__(self, right): ## """ @@ -1616,7 +1616,7 @@ def _repr_(self): sage: s._repr_() 'Class field automorphism defined by x^2 + 45*y^2' """ - return "Class field automorphism defined by %s" %self.__quadratic_form + return "Class field automorphism defined by %s" % self.__quadratic_form def __mul__(self, right): """ @@ -1684,7 +1684,7 @@ def ideal(self): c = M.conductor() sqrtD = K.gen() (A,B,C) = f - if A %c == 0: + if A % c == 0: A, C = C, A return K.fractional_ideal([A, (-B+c*sqrtD)/2]) @@ -1807,7 +1807,7 @@ def _repr_(self): sage: H._repr_() 'Heegner point of level 389, discriminant -7, and conductor 5' """ - return "Heegner point of level %s, discriminant %s, and conductor %s" %( + return "Heegner point of level %s, discriminant %s, and conductor %s" % ( self.__N, self.__D, self.__c) def __hash__(self): @@ -2051,7 +2051,7 @@ def _repr_(self): sage: heegner_points(389)._repr_() 'Set of all Heegner points on X_0(389)' """ - return "Set of all Heegner points on X_0(%s)" %self.level() + return "Set of all Heegner points on X_0(%s)" % self.level() def reduce_mod(self, ell): r""" @@ -2155,7 +2155,7 @@ def __init__(self, N, D): HeegnerPoints.__init__(self, N) D = ZZ(D) if not satisfies_weak_heegner_hypothesis(N,D): - raise ValueError("D (=%s) must satisfy the weak Heegner hypothesis for N (=%s)" %(D,N)) + raise ValueError("D (=%s) must satisfy the weak Heegner hypothesis for N (=%s)" % (D,N)) self.__D = D def __eq__(self, other): @@ -2197,7 +2197,7 @@ def _repr_(self): sage: heegner_points(389,-7)._repr_() 'Set of all Heegner points on X_0(389) associated to QQ[sqrt(-7)]' """ - return "Set of all Heegner points on X_0(%s) associated to QQ[sqrt(%s)]" %( + return "Set of all Heegner points on X_0(%s) associated to QQ[sqrt(%s)]" % ( self.level(), self.discriminant()) def discriminant(self): @@ -2224,7 +2224,7 @@ def quadratic_field(self): with sqrt_minus_7 = 2.645751311064591?*I """ D = self.__D - var = 'sqrt_minus_%s' %(-D) + var = 'sqrt_minus_%s' % (-D) return number_field.QuadraticField(D,var) def kolyvagin_conductors(self, r=None, n=10, E=None, m=None): @@ -2448,7 +2448,7 @@ def _repr_(self): sage: H = heegner_points(37,-7,5); H._repr_() 'All Heegner points of conductor 5 on X_0(37) associated to QQ[sqrt(-7)]' """ - return "All Heegner points of conductor %s on X_0(%s) associated to QQ[sqrt(%s)]" %( + return "All Heegner points of conductor %s on X_0(%s) associated to QQ[sqrt(%s)]" % ( self.conductor(), self.level(), self.discriminant()) def conductor(self): @@ -2563,7 +2563,7 @@ def betas(self): N = self.level() R = Integers(4*N) m = 2*N - return tuple(sorted( set([a %m for a in R(D).sqrt(all=True)]) )) + return tuple(sorted( set([a % m for a in R(D).sqrt(all=True)]) )) @cached_method def points(self, beta=None): @@ -2721,7 +2721,7 @@ def __init__(self, N, D, c=ZZ(1), f=None, check=True): if c.gcd(N) != 1: raise ValueError("conductor c (=%s) must be coprime to N (=%s)" % (c, N)) if not satisfies_weak_heegner_hypothesis(N, D): - raise ValueError("N (=%s) and D (=%s) must satisfy the Heegner hypothesis" %(N, D)) + raise ValueError("N (=%s) and D (=%s) must satisfy the Heegner hypothesis" % (N, D)) if f is not None: if isinstance(f, tuple): if len(f) != 3: @@ -2741,7 +2741,7 @@ def __init__(self, N, D, c=ZZ(1), f=None, check=True): raise TypeError("f must be a 3-tuple, quadratic form, or element of the upper half plane") A, B, C = f if B*B - 4*A*C != D*c*c: - raise ValueError("f (=%s) must have discriminant %s" %(f, D*c*c)) + raise ValueError("f (=%s) must have discriminant %s" % (f, D*c*c)) HeegnerPoint.__init__(self, N, D, c) if f is None: # We know that N|A, so A = N is optimal. @@ -2797,11 +2797,11 @@ def _repr_(self): 'Heegner point 5/74*sqrt(-7) - 11/74 of discriminant -7 and conductor 5 on X_0(37)' """ c = self.conductor() - s = " and conductor %s" %c if c != 1 else "" + s = " and conductor %s" % c if c != 1 else "" N = self.level() D = self.discriminant() - tau = repr(self.tau()).replace('sqrt_minus_%s' %(-D),'sqrt(%s)' %D) - return "Heegner point %s of discriminant %s%s on X_0(%s)" %(tau, D, s, N) + tau = repr(self.tau()).replace('sqrt_minus_%s' % (-D),'sqrt(%s)' % D) + return "Heegner point %s of discriminant %s%s on X_0(%s)" % (tau, D, s, N) def atkin_lehner_act(self, Q=None): r""" @@ -3114,9 +3114,9 @@ def _repr_(self): sage: P._repr_() 'Heegner point of discriminant -7 and conductor 97 on elliptic curve of conductor 389' """ - s = " and conductor %s" %self.conductor() if self.conductor() != 1 else "" + s = " and conductor %s" % self.conductor() if self.conductor() != 1 else "" N = self.__E.conductor() - return "Heegner point of discriminant %s%s on elliptic curve of conductor %s" %(self.discriminant(), s, N) + return "Heegner point of discriminant %s%s on elliptic curve of conductor %s" % (self.discriminant(), s, N) def heegner_point_on_X0N(self): r""" @@ -3771,7 +3771,7 @@ def _square_roots_mod_2N_of_D_mod_4N(self): N = self.__E.conductor() R = Integers(4*N) m = 2*N - return sorted( set([a %m for a in R(self.discriminant()).sqrt(all=True)]) ) + return sorted( set([a % m for a in R(self.discriminant()).sqrt(all=True)]) ) def _trace_numerical_conductor_1(self, prec=53): """ @@ -3862,7 +3862,7 @@ def _good_tau_representatives(self): s = s.lift() f = (a*N, b+2*N*s, ZZ( ((b + 2*N*s)**2 - D)/(4*a*N)) ) for d in divs: - Q = d * prod(p**k for p,k in N.factor() if (b-beta) %(p**k)!=0) + Q = d * prod(p**k for p,k in N.factor() if (b-beta) % (p**k) != 0) g = self._qf_atkin_lehner_act(Q, f) gbar = (ZZ(g[0]/N), -g[1], g[2]*N) g = self._qf_reduce(g) @@ -4529,7 +4529,7 @@ def __init__(self, kolyvagin_point, n): n = gcd([(p+1).gcd(E.ap(p)) for p in c.prime_divisors()]) if not kolyvagin_point.satisfies_kolyvagin_hypothesis(n): - raise ValueError("Kolyvagin point does not satisfy Kolyvagin hypothesis for %s" %n) + raise ValueError("Kolyvagin point does not satisfy Kolyvagin hypothesis for %s" % n) self.__kolyvagin_point = kolyvagin_point self.__n = n @@ -4641,7 +4641,7 @@ def _repr_(self): sage: t._repr_() 'Kolyvagin cohomology class c(5) in H^1(K,E[2])' """ - return "Kolyvagin cohomology class c(%s) in H^1(K,E[%s])" %( + return "Kolyvagin cohomology class c(%s) in H^1(K,E[%s])" % ( self.conductor(), self.n()) @@ -4729,7 +4729,7 @@ def _repr_(self): sage: heegner_points(11).reduce_mod(13)._repr_() 'Heegner points on X_0(11) over F_13' """ - return "Heegner points on X_0(%s) over F_%s" %( + return "Heegner points on X_0(%s) over F_%s" % ( self.__level, self.__ell) def level(self): @@ -5002,7 +5002,7 @@ def heegner_divisor(self, D, c=ZZ(1)): if a > 0: reps = Q.representation_vector_list(n+1)[-1] k = len([r for r in reps if gcd(r) == 1]) - assert k %2 == 0 + assert k % 2 == 0 v[i] += k // 2 return B(v) @@ -5072,12 +5072,12 @@ def modp_splitting_data(self, p): """ p = ZZ(p) if not p.is_prime(): - raise ValueError("p (=%s) must be prime" %p) + raise ValueError("p (=%s) must be prime" % p) if p == 2: raise ValueError("p must be odd") Q = self.quaternion_algebra() if Q.discriminant() % p == 0: - raise ValueError("p (=%s) must be an unramified prime" %p) + raise ValueError("p (=%s) must be an unramified prime" % p) i, j, k = Q.gens() F = GF(p) i2 = F(i*i) @@ -5181,7 +5181,7 @@ def cyclic_subideal_p1(self, I, c): V = V.intersection(phi(B[i]).kernel()) b = V.basis() assert len(b) == 1, "common kernel must have dimension 1" - uv = P1.normalize(ZZ(b[0][0]) %c, ZZ(b[0][1]) %c) + uv = P1.normalize(ZZ(b[0][0]) % c, ZZ(b[0][1]) % c) ans[uv] = J assert len(ans) == c+1 return ans @@ -5555,7 +5555,7 @@ def modp_dual_elliptic_curve_factor(self, E, p, bound=10): raise ValueError("conductor of E must equal level of self") p = ZZ(p) if not p.is_prime(): - raise ValueError("p (=%s) must be prime" %p) + raise ValueError("p (=%s) must be prime" % p) bad = self.__level * self.__ell V = None @@ -5563,7 +5563,7 @@ def modp_dual_elliptic_curve_factor(self, E, p, bound=10): B = self.brandt_module() F = GF(p) while q <= bound and (V is None or V.dimension() > 2): - verbose("q = %s" %q) + verbose("q = %s" % q) if bad % q != 0: T = B._compute_hecke_matrix_directly(q).change_ring(F).transpose() if V is None: @@ -6075,8 +6075,8 @@ def _repr_(self): sage: f = H.optimal_embeddings(-7, 2, R)[1]; f._repr_() 'Embedding sending 2*sqrt(-7) to -5*i + k' """ - a = '%ssqrt(%s)' %('%s*' %self.__c if self.__c > 1 else '', self.__D) - return "Embedding sending %s to %s" %(a, self.__beta) + a = '%ssqrt(%s)' % ('%s*' % self.__c if self.__c > 1 else '', self.__D) + return "Embedding sending %s to %s" % (a, self.__beta) def conjugate(self): """ @@ -6580,13 +6580,13 @@ def heegner_point_height(self, D, prec=2, check_rank=True): """ if not self.satisfies_heegner_hypothesis(D): - raise ArithmeticError("Discriminant (=%s) must be a fundamental discriminant that satisfies the Heegner hypothesis." %D) + raise ArithmeticError("Discriminant (=%s) must be a fundamental discriminant that satisfies the Heegner hypothesis." % D) if check_rank and self.rank() >= 2: return ZZ(0) if D == -3 or D == -4: - raise ArithmeticError("Discriminant (=%s) must not be -3 or -4." %D) + raise ArithmeticError("Discriminant (=%s) must not be -3 or -4." % D) eps = self.root_number() L1_vanishes = self.lseries().L1_vanishes() @@ -6736,7 +6736,7 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, True """ if not self.satisfies_heegner_hypothesis(D): - raise ArithmeticError("Discriminant (=%s) must be a fundamental discriminant that satisfies the Heegner hypothesis." %D) + raise ArithmeticError("Discriminant (=%s) must be a fundamental discriminant that satisfies the Heegner hypothesis." % D) if check_rank and self.rank() >= 2: return rings.infinity @@ -6751,7 +6751,7 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, # Heegner point on the twist. ht = h0/2 - verbose('Height of heegner point = %s' %ht, tm) + verbose('Height of heegner point = %s' % ht, tm) if self.root_number() == 1: F = self.quadratic_twist(D) @@ -6759,11 +6759,11 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, F = self # Now rank(F) > 0 h = ht.upper() - verbose("Heegner height bound = %s" %h) + verbose("Heegner height bound = %s" % h) B = F.CPS_height_bound() - verbose("CPS bound = %s" %B) + verbose("CPS bound = %s" % B) c = h/(min_p**2) + B - verbose("Search would have to be up to height = %s" %c) + verbose("Search would have to be up to height = %s" % c) from .ell_rational_field import _MAX_HEIGHT @@ -6780,7 +6780,7 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, if z.is_divisible_by(2): a = 2 else: - FK_even_tor_pts = [T for T in FK.torsion_subgroup().gens() if T.order() %2==0] + FK_even_tor_pts = [T for T in FK.torsion_subgroup().gens() if T.order() % 2 == 0] if len(FK_even_tor_pts) == 2: FK_even_tor_pts.append(sum(FK_even_tor_pts)) for T in FK_even_tor_pts: @@ -6805,7 +6805,7 @@ def heegner_index(self, D, min_p=2, prec=5, descent_second_limit=12, if z.is_divisible_by(2): a = 2 else: - FK_even_tor_pts = [T for T in FK.torsion_subgroup().gens() if T.order() %2==0] + FK_even_tor_pts = [T for T in FK.torsion_subgroup().gens() if T.order() % 2 == 0] if len(FK_even_tor_pts) == 2: FK_even_tor_pts.append(sum(FK_even_tor_pts)) for T in FK_even_tor_pts: @@ -6905,9 +6905,9 @@ def heegner_index_bound(self, D=0, prec=5, max_height=None): return 0, D, False F = self.quadratic_twist(D) h = ht.upper() - verbose("Heegner height bound = %s" %h) + verbose("Heegner height bound = %s" % h) B = F.CPS_height_bound() - verbose("CPS bound = %s" %B) + verbose("CPS bound = %s" % B) if self.two_torsion_rank() == 0: H = h else: @@ -6921,13 +6921,13 @@ def heegner_index_bound(self, D=0, prec=5, max_height=None): if p > 100: break p = next_prime(p) - verbose("Using p = %s" %p) + verbose("Using p = %s" % p) if c > max_height: - verbose("No information by searching only up to max_height (=%s)." %c) + verbose("No information by searching only up to max_height (=%s)." % c) return -1, D, False - verbose("Searching up to height = %s" %c) + verbose("Searching up to height = %s" % c) eps = 10e-5 def _bound(P): @@ -6942,15 +6942,15 @@ def _bound(P): IR = rings.RealIntervalField(20) # todo: 20? h = IR(reg-eps,reg+eps) ind2 = ht/(h/2) - verbose("index squared = %s" %ind2) + verbose("index squared = %s" % ind2) ind = ind2.sqrt() - verbose("index = %s" %ind) + verbose("index = %s" % ind) # Compute upper bound on square root of index. if ind.absolute_diameter() < 1: t, i = ind.is_int() if t: # unique integer in interval, so we've found exact index squared. return prime_divisors(i), D, i - raise RuntimeError("Unable to compute bound for e=%s, D=%s (try increasing precision)" %(self, D)) + raise RuntimeError("Unable to compute bound for e=%s, D=%s (try increasing precision)" % (self, D)) # First try a quick search, in case we get lucky and find # a generator. @@ -7004,7 +7004,7 @@ def _heegner_index_in_EK(self, D): """ # check conditions, then use cache if possible. if not self.satisfies_heegner_hypothesis(D): - raise ValueError("D (=%s) must satisfy the Heegner hypothesis" %D) + raise ValueError("D (=%s) must satisfy the Heegner hypothesis" % D) try: return self.__heegner_index_in_EK[D] except AttributeError: @@ -7151,7 +7151,7 @@ def heegner_sha_an(self, D, prec=53): """ # check conditions, then return from cache if possible. if not self.satisfies_heegner_hypothesis(D): - raise ValueError("D (=%s) must satisfy the Heegner hypothesis" %D) + raise ValueError("D (=%s) must satisfy the Heegner hypothesis" % D) try: return self.__heegner_sha_an[(D, prec)] except AttributeError: diff --git a/src/sage/schemes/elliptic_curves/height.py b/src/sage/schemes/elliptic_curves/height.py index 877b051cdd4..318aa85caa0 100644 --- a/src/sage/schemes/elliptic_curves/height.py +++ b/src/sage/schemes/elliptic_curves/height.py @@ -511,7 +511,7 @@ def nonneg_region(f): () """ roots = sorted(f.roots()) - sign_changes = [r for r,e in roots if e %2 == 1] + sign_changes = [r for r,e in roots if e % 2 == 1] if (f.leading_coefficient() * (-1)**f.degree()) > 0: sign_changes = [-infinity] + sign_changes if f.leading_coefficient() > 0: diff --git a/src/sage/schemes/elliptic_curves/hom_composite.py b/src/sage/schemes/elliptic_curves/hom_composite.py index a117e2e87d0..b449fe77e41 100644 --- a/src/sage/schemes/elliptic_curves/hom_composite.py +++ b/src/sage/schemes/elliptic_curves/hom_composite.py @@ -474,7 +474,7 @@ def _repr_(self): from itertools import groupby degs = [phi.degree() for phi in self._phis] grouped = [(d, sum(1 for _ in g)) for d,g in groupby(degs)] - degs_str = '*'.join(str(d) + (f'^{e}' if e>1 else '') for d,e in grouped) + degs_str = '*'.join(str(d) + (f'^{e}' if e > 1 else '') for d,e in grouped) return f'Composite morphism of degree {self._degree} = {degs_str}:' \ f'\n From: {self._domain}' \ f'\n To: {self._codomain}' diff --git a/src/sage/schemes/elliptic_curves/hom_velusqrt.py b/src/sage/schemes/elliptic_curves/hom_velusqrt.py index d002ce03357..b60e551d876 100644 --- a/src/sage/schemes/elliptic_curves/hom_velusqrt.py +++ b/src/sage/schemes/elliptic_curves/hom_velusqrt.py @@ -455,7 +455,7 @@ def _hI_resultant(self, poly, rems=None): if rems is None: rems = self.hItree.remainders(poly) r = prod(rems) - s = -1 if len(self.hItree) %2 == 1 == poly.degree() else 1 + s = -1 if len(self.hItree) % 2 == 1 == poly.degree() else 1 assert r.is_constant() return s * r[0] diff --git a/src/sage/schemes/elliptic_curves/isogeny_class.py b/src/sage/schemes/elliptic_curves/isogeny_class.py index 9eb69746841..1588ecbe814 100644 --- a/src/sage/schemes/elliptic_curves/isogeny_class.py +++ b/src/sage/schemes/elliptic_curves/isogeny_class.py @@ -227,9 +227,9 @@ def _repr_(self): Elliptic Curve defined by y^2 + (i+1)*x*y + (i+1)*y = x^3 + i*x^2 + (-i+33)*x + (-58*i) over Number Field in i with defining polynomial x^2 + 1 with i = 1*I] """ if self._label: - return "Elliptic curve isogeny class %s" %(self._label) + return "Elliptic curve isogeny class %s" % (self._label) else: - return "Isogeny class of %r" %(self.E) + return "Isogeny class of %r" % (self.E) def __contains__(self, x): """ @@ -853,9 +853,9 @@ def add_tup(t): js = [j for j,E3 in enumerate(curves) if E2.is_isomorphic(E3)] if js: # seen codomain already -- up to isomorphism j = js[0] - if phi.codomain()!=curves[j]: + if phi.codomain() != curves[j]: phi = E2.isomorphism_to(curves[j]) * phi - assert phi.domain()==curves[i] and phi.codomain()==curves[j] + assert phi.domain() == curves[i] and phi.codomain() == curves[j] add_tup([i,j,d,phi]) else: curves.append(E2) @@ -885,7 +885,7 @@ def add_tup(t): mat = MatrixSpace(ZZ, ncurves)(0) self._maps = [[0] * ncurves for _ in range(ncurves)] for i,j,l,phi in tuples: - if phi!=0: + if phi != 0: mat[perm[i],perm[j]] = l self._maps[perm[i]][perm[j]] = phi self._mat = fill_isogeny_matrix(mat) @@ -932,16 +932,16 @@ def find_quadratic_form(d, n): for Q in allQs[d]: if Q.solve_integer(n): return Q - raise ValueError("No form of discriminant %d represents %s" %(d,n)) + raise ValueError("No form of discriminant %d represents %s" % (d,n)) mat = self._mat qfmat = [[0 for i in range(ncurves)] for j in range(ncurves)] for i, E1 in enumerate(self.curves): for j, E2 in enumerate(self.curves): - if j1]) + L1 = Set([l for l in ram_l if d.valuation(l) > 1]) L += L1 if verbose: print("upward primes: %s" % L1) @@ -1269,7 +1269,7 @@ def isogeny_degrees_cm(E, verbose=False): # l-1 must divide n/2h: L1 = Set([lm1+1 for lm1 in divs - if (lm1+1).is_prime() and kronecker_symbol(d,lm1+1)==+1]) + if (lm1+1).is_prime() and kronecker_symbol(d,lm1+1) == +1]) L += L1 if verbose: print("downward split primes: %s" % L1) @@ -1278,7 +1278,7 @@ def isogeny_degrees_cm(E, verbose=False): # l+1 must divide n/2h: L1 = Set([lp1-1 for lp1 in divs - if (lp1-1).is_prime() and kronecker_symbol(d,lp1-1)==-1]) + if (lp1-1).is_prime() and kronecker_symbol(d,lp1-1) == -1]) L += L1 if verbose: print("downward inert primes: %s" % L1) diff --git a/src/sage/schemes/elliptic_curves/isogeny_small_degree.py b/src/sage/schemes/elliptic_curves/isogeny_small_degree.py index a8c84de2613..30312da99a6 100644 --- a/src/sage/schemes/elliptic_curves/isogeny_small_degree.py +++ b/src/sage/schemes/elliptic_curves/isogeny_small_degree.py @@ -204,7 +204,7 @@ def Psi(l, use_stored=True): if l == 3: return X + t + 27 if l == 5: - return X**2 + 2*X*(t**2 + 22*t + 125)+ (t**2 + 22*t + 89) * (t**2 + 22*t + 125) + return X**2 + 2*X*(t**2 + 22*t + 125) + (t**2 + 22*t + 89) * (t**2 + 22*t + 125) if l == 7: return (X**3 + 3*(t**2 + 13*t + 49)*X**2 + 3*(t**2 + 13*t + 33)*(t**2 + 13*t + 49)*X @@ -288,7 +288,7 @@ def isogenies_prime_degree_genus_0(E, l=None, minimal_models=True): to Elliptic Curve defined by y^2 + x*y + y = x^3 - 76*x + 298 over Rational Field] """ if l not in [2, 3, 5, 7, 13, None]: - raise ValueError("%s is not a genus 0 prime." %l) + raise ValueError("%s is not a genus 0 prime." % l) F = E.base_ring() j = E.j_invariant() if F.characteristic() in [2, 3, l]: @@ -327,8 +327,8 @@ def isogenies_prime_degree_genus_0(E, l=None, minimal_models=True): from sage.misc.misc_c import prod psi = Psi(l) X = t - f = R(prod( [p for p,e in jt.factor() if e==3] - +[p for p,e in kt.factor() if e==2])) + f = R(prod( [p for p,e in jt.factor() if e == 3] + + [p for p,e in kt.factor() if e == 2])) kernels = [R(psi(X*T*(j-1728)*t0/f(t0),t0)) for t0 in t_list] kernels = [ker.monic() for ker in kernels] E1 = EllipticCurve([-27*c4,-54*c6]) @@ -555,17 +555,17 @@ def _sporadic_Q_data(j): a4a6 = list(E.ainvs())[3:] L = E.period_lattice() pr = 100 - if ell==163: - pr=1000 - elif ell>30: - pr=300 + if ell == 163: + pr = 1000 + elif ell > 30: + pr = 300 w1, w2 = L.basis(prec=pr) X = polygen(RealField(pr),'X') w = w1 # real period if j in [-121, -24729001, -162677523113838677, QQ(-882216989)/131072]: w = 2*w2-w1 # imaginary period kerpol = prod(([X-L.elliptic_exponential(n*w/ell)[0] for n in range(1,(ell+1)//2)])) - if j==-162677523113838677: + if j == -162677523113838677: kerpolcoeffs = [(37*c.real()).round()/37 for c in list(kerpol)] else: kerpolcoeffs = [c.real().round() for c in list(kerpol)] @@ -908,7 +908,7 @@ def isogenies_5_0(E, minimal_models=True): betas = sorted((x**6-160*a*x**3-80*a**2).roots(multiplicities=False)) if not betas: return [] - gammas = [(beta**2 *(beta**3-140*a))/(120*a) for beta in betas] + gammas = [(beta**2 * (beta**3-140*a))/(120*a) for beta in betas] from sage.rings.number_field.number_field_base import NumberField model = "minimal" if minimal_models and isinstance(F, NumberField) else None isogs = [Ew.isogeny(x**2+beta*x+gamma, model=model) for beta,gamma in zip(betas,gammas)] @@ -1153,7 +1153,7 @@ def isogenies_7_0(E, minimal_models=True): [158428486656000/7*a^3 - 313976217600000, -158428486656000/7*a^3 - 34534529335296000] """ - if E.j_invariant()!=0: + if E.j_invariant() != 0: raise ValueError("j-invariant must be 0.") F = E.base_field() if F.characteristic() in [2,3,7]: @@ -1254,7 +1254,7 @@ def isogenies_7_1728(E, minimal_models=True): sage: E1.is_quadratic_twist(E2) # optional - sage.rings.number_field -1 """ - if E.j_invariant()!=1728: + if E.j_invariant() != 1728: raise ValueError("j_invariant must be 1728 (in base field).") F = E.base_field() if F.characteristic() in [2,3,7]: @@ -1393,7 +1393,7 @@ def isogenies_13_0(E, minimal_models=True): ....: for phi in isogenies_13_0(E)]) 2 """ - if E.j_invariant()!=0: + if E.j_invariant() != 0: raise ValueError("j-invariant must be 0.") F = E.base_field() if F.characteristic() in [2,3,13]: @@ -1538,7 +1538,7 @@ def isogenies_13_1728(E, minimal_models=True): + 2810970361185589/1329760446964992*a^7 - 281503836888046601/8975883017013696*a^5 + 1287313166530075/848061509544*a^3 - 9768837984886039/6925835661276*a)] """ - if E.j_invariant()!=1728: + if E.j_invariant() != 1728: raise ValueError("j-invariant must be 1728.") F = E.base_field() if F.characteristic() in [2, 3, 13]: @@ -1624,7 +1624,7 @@ def _hyperelliptic_isogeny_data(l): ValueError: 37 must be one of [11, 17, 19, 23, 29, 31, 41, 47, 59, 71]. """ if l not in hyperelliptic_primes: - raise ValueError("%s must be one of %s." %(l,hyperelliptic_primes)) + raise ValueError("%s must be one of %s." % (l,hyperelliptic_primes)) data = {} Zu = PolynomialRing(ZZ,'u') Zuv = PolynomialRing(ZZ,['u','v']) @@ -2091,7 +2091,7 @@ def isogenies_prime_degree_genus_plus_0_j0(E, l, minimal_models=True): [Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6] """ if l not in hyperelliptic_primes: - raise ValueError("%s must be one of %s." %(l,hyperelliptic_primes)) + raise ValueError("%s must be one of %s." % (l,hyperelliptic_primes)) F = E.base_field() if E.j_invariant() != 0: raise ValueError(("j-invariant must be 0.")) @@ -2213,7 +2213,7 @@ def isogenies_prime_degree_genus_plus_0_j1728(E, l, minimal_models=True): [(17, 2), (29, 2), (41, 2)] """ if l not in hyperelliptic_primes: - raise ValueError("%s must be one of %s." %(l,hyperelliptic_primes)) + raise ValueError("%s must be one of %s." % (l,hyperelliptic_primes)) F = E.base_ring() if E.j_invariant() != 1728: raise ValueError("j-invariant must be 1728.") @@ -2795,14 +2795,14 @@ def isogenies_prime_degree(E, l, minimal_models=True): with a = 3.316624790355400?*I] """ if not l.is_prime(): - raise ValueError("%s is not prime." %l) - if l==2: + raise ValueError("%s is not prime." % l) + if l == 2: return isogenies_2(E, minimal_models=minimal_models) - if l==3: + if l == 3: return isogenies_3(E, minimal_models=minimal_models) p = E.base_ring().characteristic() - if l==p: + if l == p: return isogenies_prime_degree_general(E,l, minimal_models=minimal_models) if l in [5,7,13] and p not in [2,3]: diff --git a/src/sage/schemes/elliptic_curves/kraus.py b/src/sage/schemes/elliptic_curves/kraus.py index f8c6bc8b18a..29fddb57f6b 100644 --- a/src/sage/schemes/elliptic_curves/kraus.py +++ b/src/sage/schemes/elliptic_curves/kraus.py @@ -379,12 +379,12 @@ def check_Kraus_local_3(c4, c6, P, assume_nonsingular=False, debug=False): return False, 0 e = P.ramification_index() P3 = P**e - if c4.valuation(P)==0: + if c4.valuation(P) == 0: b2 = (-c6*c4.inverse_mod(P3)).mod(P3) if debug: assert test_b2_local(c4,c6,P,b2) return True, b2 - if c6.valuation(P)>=3*e: + if c6.valuation(P) >= 3*e: b2 = c6.parent().zero() if debug: assert test_b2_local(c4,c6,P,b2) @@ -525,7 +525,7 @@ def test_rst_global(c4, c6, r, s, t, debug=False): K = E.base_field() for P in K.primes_above(2)+K.primes_above(3): if not E.is_local_integral_model(P): - print(" -- not integral at P=%s" %P) + print(" -- not integral at P=%s" % P) return False return E @@ -584,7 +584,7 @@ def check_Kraus_local_2(c4, c6, P, a1=None, assume_nonsingular=False): P2 = P**e c4val = c4.valuation(P) - if c4val==0: + if c4val == 0: if a1 is None: flag, t = sqrt_mod_4(-c6,P) if not flag: @@ -688,14 +688,14 @@ def check_Kraus_local(c4, c6, P, assume_nonsingular=False): if not c4c6_nonsingular(c4,c6): return False, None K = c4.parent() - if K(2).valuation(P) >0: + if K(2).valuation(P) > 0: flag, a1, a3 = check_Kraus_local_2(c4,c6,P,None,True) if flag: E = test_a1a3_local(c4,c6,P,a1,a3) if E: return (True, E) return (False, None) - if K(3).valuation(P) >0: + if K(3).valuation(P) > 0: flag, b2 = check_Kraus_local_3(c4,c6,P,True) if flag: E = test_b2_local(c4,c6,P,b2) diff --git a/src/sage/schemes/elliptic_curves/padic_lseries.py b/src/sage/schemes/elliptic_curves/padic_lseries.py index 9bb33ff952b..f264ca20434 100644 --- a/src/sage/schemes/elliptic_curves/padic_lseries.py +++ b/src/sage/schemes/elliptic_curves/padic_lseries.py @@ -444,7 +444,7 @@ def measure(self, a, n, prec, quadratic_twist=+1, sign=+1): if self._E.conductor() % p == 0: mu = chip**n * z * sum([kronecker_symbol(D,u) * f(a/(p*w)+ZZ(u)/D) for u in range(1,D.abs())]) else: - mu = chip**n * z * sum([kronecker_symbol(D,u) *( f(a/(p*w)+ZZ(u)/D) - chip /alpha * f(a/w+ZZ(u)/D) ) for u in range(1,D.abs())]) + mu = chip**n * z * sum([kronecker_symbol(D,u) * ( f(a/(p*w)+ZZ(u)/D) - chip / alpha * f(a/w+ZZ(u)/D) ) for u in range(1,D.abs())]) return s*mu def alpha(self, prec=20): @@ -868,7 +868,7 @@ def series(self, n=2, quadratic_twist=+1, prec=5, eta=0): raise ValueError("Insufficient precision (%s)" % prec) # check if the conditions on quadratic_twist are satisfied - eta = ZZ(eta) % (self._p- 1) if self._p != 2 else ZZ(eta) % 2 + eta = ZZ(eta) % (self._p - 1) if self._p != 2 else ZZ(eta) % 2 D = ZZ(quadratic_twist) if D != 1: if eta != 0: @@ -876,20 +876,20 @@ def series(self, n=2, quadratic_twist=+1, prec=5, eta=0): if D % 4 == 0: d = D//4 if not d.is_squarefree() or d % 4 == 1: - raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" %D) + raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" % D) else: if not D.is_squarefree() or D % 4 != 1: - raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" %D) + raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" % D) if gcd(D,self._p) != 1: - raise ValueError("quadratic twist (=%s) must be coprime to p (=%s) " %(D,self._p)) + raise ValueError("quadratic twist (=%s) must be coprime to p (=%s) " % (D,self._p)) if gcd(D, self._E.conductor()) != 1: for ell in prime_divisors(D): if valuation(self._E.conductor(), ell) > valuation(D, ell): - raise ValueError("cannot twist a curve of conductor (=%s) by the quadratic twist (=%s)." %(self._E.conductor(),D)) + raise ValueError("cannot twist a curve of conductor (=%s) by the quadratic twist (=%s)." % (self._E.conductor(),D)) p = self._p si = 1-2*(eta % 2) - #verbose("computing L-series for p=%s, n=%s, and prec=%s"%(p,n,prec)) + # verbose("computing L-series for p=%s, n=%s, and prec=%s" % (p,n,prec)) if prec == 1: if eta == 0: @@ -915,13 +915,13 @@ def series(self, n=2, quadratic_twist=+1, prec=5, eta=0): bounds = self._prec_bounds(n,prec,sign=si) padic_prec = max(bounds[1:]) + 5 - verbose("using p-adic precision of %s" %padic_prec) + verbose("using p-adic precision of %s" % padic_prec) if p == 2: res_series_prec = min(p**(n-2), prec) else: res_series_prec = min(p**(n-1), prec) - verbose("using series precision of %s" %res_series_prec) + verbose("using series precision of %s" % res_series_prec) ans = self._get_series_from_cache(n, res_series_prec,D,eta) if ans is not None: @@ -942,17 +942,17 @@ def series(self, n=2, quadratic_twist=+1, prec=5, eta=0): a_range = 3 else: teich = self.teichmuller(padic_prec) - gamma = K(1+ p) + gamma = K(1 + p) p_power = p**(n-1) a_range = p - verbose("Now iterating over %s summands" %((p-1)*p_power)) + verbose("Now iterating over %s summands" % ((p-1)*p_power)) verbose_level = get_verbose() count_verb = 0 for j in range(p_power): s = K(0) if verbose_level >= 2 and j/p_power*100 > count_verb + 3: - verbose("%.2f percent done" %(float(j)/p_power*100)) + verbose("%.2f percent done" % (float(j)/p_power*100)) count_verb += 3 for a in range(1,a_range): b = teich[a] * gamma_power @@ -961,7 +961,7 @@ def series(self, n=2, quadratic_twist=+1, prec=5, eta=0): one_plus_T_factor *= 1+T gamma_power *= gamma - verbose("the series before adjusting the precision is %s" %L) + verbose("the series before adjusting the precision is %s" % L) # Now create series but with each coefficient truncated # so it is proven correct: K = Qp(p, padic_prec, print_mode='series') @@ -1052,7 +1052,7 @@ def _c_bound(self, sign=+1): if E.galois_representation().is_irreducible(p): return 0 - if self._implementation=="sage": + if self._implementation == "sage": m = E.modular_symbol_space(sign=1) b = m.boundary_map().codomain() C = b._known_cusps() # all known, since computed the boundary map @@ -1112,7 +1112,7 @@ def _c_bound(self, sign=+1): if E0.real_components() == 1: om0 *= 2 m = max(isog.matrix().list()) - q = (om/om0 *m).round()/m + q = (om/om0 * m).round()/m t += valuation(q,p) return max(t,0) @@ -1227,7 +1227,7 @@ def series(self, n=3, quadratic_twist=+1, prec=5, eta=0): if D % 4 == 0: d = D//4 if not d.is_squarefree() or d % 4 == 1: - raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" %D) + raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" % D) else: if not D.is_squarefree() or D % 4 != 1: raise ValueError("quadratic_twist (=%s) must be a fundamental discriminant of a quadratic field" % D) @@ -1283,18 +1283,18 @@ def series(self, n=3, quadratic_twist=+1, prec=5, eta=0): a_range = 3 else: teich = self.teichmuller(padic_prec) - gamma = 1+ p + gamma = 1 + p p_power = p**(n-1) a_range = p si = 1-2*(eta % 2) - verbose("Now iterating over %s summands" %((p-1)*p_power)) + verbose("Now iterating over %s summands" % ((p-1)*p_power)) verbose_level = get_verbose() count_verb = 0 for j in range(p_power): s = K(0) if verbose_level >= 2 and j/p_power*100 > count_verb + 3: - verbose("%.2f percent done" %(float(j)/p_power*100)) + verbose("%.2f percent done" % (float(j)/p_power*100)) count_verb += 3 for a in range(1,a_range): b = teich[a] * gamma_power @@ -1484,8 +1484,8 @@ def frobenius(self, prec=20, algorithm="mw"): """ E = self._E p = self._p - if algorithm != "mw" and algorithm !="approx": - raise ValueError("Unknown algorithm %s." %algorithm) + if algorithm != "mw" and algorithm != "approx": + raise ValueError("Unknown algorithm %s." % algorithm) if algorithm == "approx": return self.__phi_bpr(prec=prec) if p < 4 and algorithm == "mw": @@ -1584,20 +1584,20 @@ def __phi_bpr(self, prec=0): if eq[0].valuation(p) == 0: l = min(eq[1].valuation(p),k-v) if l == 0: - verbose("not uniquely determined at step k=%s" %k) + verbose("not uniquely determined at step k=%s" % k) else: ainv = eq[0].inverse_mod(p**l) delta = delta - eq[2]*ainv*p**dpr dpr = dpr + l delta = delta % p**dpr - verbose("delta_prec increased to %s\n delta is now %s" %(dpr,delta)) + verbose("delta_prec increased to %s\n delta is now %s" % (dpr,delta)) elif eq[1].valuation(p) == 0: l = min(eq[0].valuation(p),k-v) ainv = eq[1].inverse_mod(p**l) gamma = gamma - eq[2]*ainv*p**dga dga = dga + l gamma = gamma % p**dga - verbose("gamma_prec increased to %s\n gamma is now %s" %(dga,gamma)) + verbose("gamma_prec increased to %s\n gamma is now %s" % (dga,gamma)) else: raise RuntimeError("Bug: no delta or gamma can exist") @@ -1605,7 +1605,7 @@ def __phi_bpr(self, prec=0): R = Qp(p,max(dpr,dga)+1) delta = R(delta,absprec=dpr) gamma = R(gamma,absprec=dga) - verbose("result delta = %s\n gamma = %s\n check : %s" %(delta,gamma, [Qp(p,k)(delta * cs[k] - gamma * ds[k] - cs[k-1]) for k in range(1,prec+1)] )) + verbose("result delta = %s\n gamma = %s\n check : %s" % (delta,gamma, [Qp(p,k)(delta * cs[k] - gamma * ds[k] - cs[k-1]) for k in range(1,prec+1)] )) a = delta c = -gamma d = E.ap(p) - a @@ -1727,7 +1727,7 @@ def Dp_valued_regulator(self, prec=20, v1=0, v2=0): # this is the height_{v} (P) for a v in D_p def hv(vec, P): hP = h(P) - return - vec[0]*hP[1] +vec[1]*hP[0] + return - vec[0]*hP[1] + vec[1]*hP[0] # def hvpairing(vec,P,Q): # return (hv(vec, P+Q) - hv(vec,P)-hv(vec,Q))/2 @@ -1750,7 +1750,7 @@ def regv(vec): point_height = [hv(vec, P) for P in basis] for i in range(rk): for j in range(i+1, rk): - M[i, j] = M[j, i] = (hv(vec,basis[i] + basis[j])- point_height[i] - point_height[j] )/2 + M[i, j] = M[j, i] = (hv(vec,basis[i] + basis[j]) - point_height[i] - point_height[j] )/2 for i in range(rk): M[i, i] = point_height[i] diff --git a/src/sage/schemes/elliptic_curves/padics.py b/src/sage/schemes/elliptic_curves/padics.py index d0c16cec86e..30587d1cfa5 100644 --- a/src/sage/schemes/elliptic_curves/padics.py +++ b/src/sage/schemes/elliptic_curves/padics.py @@ -317,7 +317,7 @@ def padic_regulator(self, p, prec=20, height=None, check_hypotheses=True): p = Integer(p) # this is assumed in code below if check_hypotheses: if not p.is_prime(): - raise ValueError("p = (%s) must be prime" %p) + raise ValueError("p = (%s) must be prime" % p) if p == 2: raise ValueError("p must be odd") # todo if self.conductor() % (p**2) == 0: @@ -715,7 +715,7 @@ def padic_height(self, p, prec=20, sigma=None, check_hypotheses=True): """ if check_hypotheses: if not p.is_prime(): - raise ValueError("p = (%s) must be prime" %p) + raise ValueError("p = (%s) must be prime" % p) if p == 2: raise ValueError("p must be odd") # todo if self.conductor() % (p**2) == 0: @@ -867,7 +867,7 @@ def padic_height_via_multiply(self, p, prec=20, E2=None, check_hypotheses=True): """ if check_hypotheses: if not p.is_prime(): - raise ValueError("p = (%s) must be prime" %p) + raise ValueError("p = (%s) must be prime" % p) if p == 2: raise ValueError("p must be odd") # todo if self.conductor() % p == 0: @@ -1122,7 +1122,7 @@ def padic_sigma(self, p, N=20, E2=None, check=False, check_hypotheses=True): sigma = sigma.padded_list(N+1) - sigma[0] = K(0, N +1) + sigma[0] = K(0, N + 1) sigma[1] = K(1, N) for n in range(2, N+1): sigma[n] = K(sigma[n].lift(), N - n + 1) diff --git a/src/sage/schemes/elliptic_curves/period_lattice.py b/src/sage/schemes/elliptic_curves/period_lattice.py index e3513ee8b05..615ae86bb60 100644 --- a/src/sage/schemes/elliptic_curves/period_lattice.py +++ b/src/sage/schemes/elliptic_curves/period_lattice.py @@ -236,7 +236,7 @@ def __init__(self, E, embedding=None): self.real_flag = 0 if real: self.real_flag = +1 - if embedding(E.discriminant())<0: + if embedding(E.discriminant()) < 0: self.real_flag = -1 # The following algebraic data associated to E and the @@ -662,7 +662,7 @@ def _compute_periods_real(self, prec=None, algorithm='sage'): w1, w2 = E_pari.omega() return R(w1), C(w2) - if algorithm!='sage': + if algorithm != 'sage': raise ValueError("invalid value of 'algorithm' parameter") pi = R.pi() @@ -742,13 +742,13 @@ def _compute_periods_complex(self, prec=None, normalise=True): pi = C.pi() a, b, c = (C(x) for x in self._abc) if (a+b).abs() < (a-b).abs(): - b=-b + b = -b if (a+c).abs() < (a-c).abs(): - c=-c + c = -c w1 = pi/a.agm(b) w2 = pi*C.gen()/a.agm(c) - if (w1/w2).imag()<0: - w2=-w2 + if (w1/w2).imag() < 0: + w2 = -w2 if normalise: w1w2, mat = normalise_periods(w1,w2) return w1w2 @@ -785,7 +785,7 @@ def is_real(self): The lattice is real if it is associated to a real embedding; such lattices are stable under conjugation. """ - return self.real_flag!=0 + return self.real_flag != 0 def is_rectangular(self): r""" @@ -1393,10 +1393,10 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): if wP.is_zero(): # 2-torsion treated separately w1,w2 = self._compute_periods_complex(prec,normalise=False) - if xP==e1: + if xP == e1: z = w2/2 else: - if xP==e3: + if xP == e3: z = w1/2 else: z = (w1+w2)/2 @@ -1414,15 +1414,15 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): # but also causes problems (see #10026). It is left in but # commented out below. - if self.real_flag==0: # complex case + if self.real_flag == 0: # complex case a = C((e1-e3).sqrt()) b = C((e1-e2).sqrt()) if (a+b).abs() < (a-b).abs(): - b=-b + b = -b r = C(((xP-e3)/(xP-e2)).sqrt()) - if r.real()<0: - r=-r + if r.real() < 0: + r = -r t = -C(wP)/(2*r*(xP-e2)) # eps controls the end of the loop. Since we aim at a target # precision of prec bits, eps = 2^(-prec) is enough. @@ -1431,12 +1431,12 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): s = b*r+a a, b = (a+b)/2, (a*b).sqrt() if (a+b).abs() < (a-b).abs(): - b=-b + b = -b r = (a*(r+1)/s).sqrt() if (r.abs()-1).abs() < eps: break - if r.real()<0: - r=-r + if r.real() < 0: + r = -r t *= r z = ((a/t).arctan())/a z = ComplexField(prec)(z) @@ -1444,7 +1444,7 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): z = self.reduce(z) return z - if self.real_flag==-1: # real, connected case + if self.real_flag == -1: # real, connected case z = C(self._abc[0]) # sqrt(e3-e1) a, y, b = z.real(), z.imag(), z.abs() uv = (xP-e1).sqrt() @@ -1456,8 +1456,8 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): a = R(e3-e1).sqrt() b = R(e3-e2).sqrt() if (a+b).abs() < (a-b).abs(): - b=-b - on_egg = (xP=0.999 and tau.real().abs() <= 0.5 + assert a*d-b*c == 1 + assert tau.abs() >= 0.999 and tau.real().abs() <= 0.5 return tau, [a,b,c,d] @@ -1965,13 +1965,13 @@ def normalise_periods(w1, w2): """ tau = w1/w2 s = +1 - if tau.imag()<0: + if tau.imag() < 0: w2 = -w2 tau = -tau s = -1 tau, abcd = reduce_tau(tau) a, b, c, d = abcd - if s<0: + if s < 0: abcd = (a,-b,c,-d) return (a*w1+b*w2,c*w1+d*w2), abcd diff --git a/src/sage/schemes/elliptic_curves/saturation.py b/src/sage/schemes/elliptic_curves/saturation.py index b76cd5d2ebf..c75972e7f02 100644 --- a/src/sage/schemes/elliptic_curves/saturation.py +++ b/src/sage/schemes/elliptic_curves/saturation.py @@ -492,7 +492,7 @@ def p_saturation(self, Plist, p, sieve=True): # and there is no simple test.) avoid = [self._N, self._D] + [P[0].denominator_ideal().norm() for P in Plist] - cm_test = E.has_rational_cm() and kro(E.cm_discriminant(), p)==-1 + cm_test = E.has_rational_cm() and kro(E.cm_discriminant(), p) == -1 for q in Primes(): if any(q.divides(m) for m in avoid): continue @@ -543,7 +543,7 @@ def p_saturation(self, Plist, p, sieve=True): # point which is certainly a p-multiple # modulo 15 primes Q, and we test if it # actually is a p-multiple: - if len(Rlist)==1: + if len(Rlist) == 1: R = Rlist[0] pts = R.division_points(p) if pts: @@ -650,7 +650,7 @@ def p_projections(Eq, Plist, p, debug=False): m = n.prime_to_m_part(p) # prime-to-p part of order if debug: print("m={}, n={}".format(m,n)) - if m==n: # p-primary part trivial, nothing to do + if m == n: # p-primary part trivial, nothing to do return [] G = Eq.abelian_group() if debug: From 6741bbf6b7ac300c054c58bb8ab0bf96f41b5697 Mon Sep 17 00:00:00 2001 From: Miguel Marco Date: Wed, 24 May 2023 23:11:09 +0200 Subject: [PATCH 57/98] register magic modes for lazy imported interfaces --- src/sage/repl/interface_magic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/repl/interface_magic.py b/src/sage/repl/interface_magic.py index 856bdcd120d..9662603cbdd 100644 --- a/src/sage/repl/interface_magic.py +++ b/src/sage/repl/interface_magic.py @@ -97,7 +97,7 @@ def all_iter(cls): except ImportError: return for name, obj in sage.interfaces.all.__dict__.items(): - if isinstance(obj, sage.interfaces.interface.Interface): + if isinstance(obj, (sage.interfaces.interface.Interface, sage.misc.lazy_import.LazyImport)): yield cls(name, obj) @classmethod From 2a112396a366003aecc9d1f1ece74682f22043e1 Mon Sep 17 00:00:00 2001 From: Miguel Marco Date: Wed, 24 May 2023 23:11:09 +0200 Subject: [PATCH 58/98] register magic modes for lazy imported interfaces --- src/sage/repl/interface_magic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/repl/interface_magic.py b/src/sage/repl/interface_magic.py index 856bdcd120d..9662603cbdd 100644 --- a/src/sage/repl/interface_magic.py +++ b/src/sage/repl/interface_magic.py @@ -97,7 +97,7 @@ def all_iter(cls): except ImportError: return for name, obj in sage.interfaces.all.__dict__.items(): - if isinstance(obj, sage.interfaces.interface.Interface): + if isinstance(obj, (sage.interfaces.interface.Interface, sage.misc.lazy_import.LazyImport)): yield cls(name, obj) @classmethod From c27aafa0499e6f9b994b013100342798866ec52a Mon Sep 17 00:00:00 2001 From: Lorenz Panny Date: Fri, 26 May 2023 19:00:46 +0800 Subject: [PATCH 59/98] add deprecation warning for #34880 --- src/sage/algebras/quatalg/quaternion_algebra.py | 16 +++++++++++----- src/sage/modular/quatalg/brandt.py | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/sage/algebras/quatalg/quaternion_algebra.py b/src/sage/algebras/quatalg/quaternion_algebra.py index 3310b4f026d..19a3d6b969a 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra.py +++ b/src/sage/algebras/quatalg/quaternion_algebra.py @@ -1399,8 +1399,8 @@ def __init__(self, A, basis, check=True): raise ValueError("lattice must contain 1") # check if multiplicatively closed - M1 = basis_for_quaternion_lattice(basis) - M2 = basis_for_quaternion_lattice(list(basis) + [x * y for x in basis for y in basis]) + M1 = basis_for_quaternion_lattice(basis, reverse=False) + M2 = basis_for_quaternion_lattice(list(basis) + [x * y for x in basis for y in basis], reverse=False) if M1 != M2: raise ValueError("given lattice must be a ring") @@ -2548,7 +2548,7 @@ def __mul__(self, right): # if self.__right_order == right.__left_order: # left_order = self.__left_order # right_order = right.__right_order - basis = tuple(basis_for_quaternion_lattice(gens)) + basis = tuple(basis_for_quaternion_lattice(gens, reverse=False)) A = self.quaternion_algebra() return A.ideal(basis, check=False) @@ -2691,7 +2691,7 @@ def multiply_by_conjugate(self, J): """ Jbar = [b.conjugate() for b in J.basis()] gens = [a * b for a in self.basis() for b in Jbar] - basis = tuple(basis_for_quaternion_lattice(gens)) + basis = tuple(basis_for_quaternion_lattice(gens, reverse=False)) R = self.quaternion_algebra() return R.ideal(basis, check=False) @@ -2899,7 +2899,7 @@ def cyclic_right_subideals(self, p, alpha=None): ####################################################################### -def basis_for_quaternion_lattice(gens, reverse=False): +def basis_for_quaternion_lattice(gens, reverse=None): r""" Return a basis for the `\ZZ`-lattice in a quaternion algebra spanned by the given gens. @@ -2918,12 +2918,18 @@ def basis_for_quaternion_lattice(gens, reverse=False): sage: from sage.algebras.quatalg.quaternion_algebra import basis_for_quaternion_lattice sage: A. = QuaternionAlgebra(-1,-7) sage: basis_for_quaternion_lattice([i+j, i-j, 2*k, A(1/3)]) + doctest:warning ... DeprecationWarning: ... [1/3, i + j, 2*j, 2*k] sage: basis_for_quaternion_lattice([A(1),i,j,k]) [1, i, j, k] """ + if reverse is None: + from sage.misc.superseded import deprecation + deprecation(34880, 'The default value for the "reverse" argument to basis_for_quaternion_lattice() will' + ' change from False to True. Pass the argument explicitly to silence this warning.') + reverse = False if not gens: return [] Z, d = quaternion_algebra_cython.integral_matrix_and_denom_from_rational_quaternions(gens, reverse) diff --git a/src/sage/modular/quatalg/brandt.py b/src/sage/modular/quatalg/brandt.py index 9bbe2865b47..effb2adbfcf 100644 --- a/src/sage/modular/quatalg/brandt.py +++ b/src/sage/modular/quatalg/brandt.py @@ -399,7 +399,7 @@ def basis_for_left_ideal(R, gens): sage: sage.modular.quatalg.brandt.basis_for_left_ideal(B.maximal_order(), [3*(i+j),3*(i-j),6*k,A(3)]) [3/2 + 1/2*i + k, i + 2*k, 3/2*j + 3/2*k, 3*k] """ - return basis_for_quaternion_lattice([b * g for b in R.basis() for g in gens]) + return basis_for_quaternion_lattice([b * g for b in R.basis() for g in gens], reverse=False) def right_order(R, basis): From d4bee566d481fa5b6e27a040017c432b4c718645 Mon Sep 17 00:00:00 2001 From: Daniel Krenn Date: Fri, 26 May 2023 19:24:56 +0200 Subject: [PATCH 60/98] unify input of matrices and vectors --- src/sage/combinat/k_regular_sequence.py | 5 +++++ src/sage/combinat/recognizable_series.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/sage/combinat/k_regular_sequence.py b/src/sage/combinat/k_regular_sequence.py index 1ec99957aa8..596b6adb2a7 100644 --- a/src/sage/combinat/k_regular_sequence.py +++ b/src/sage/combinat/k_regular_sequence.py @@ -150,6 +150,11 @@ def __init__(self, parent, mu, left=None, right=None): :doc:`k-regular sequence `, :class:`kRegularSequenceSpace`. + + TESTS:: + + sage: Seq2(([[1, 0], [0, 1]], [[1, 1], [0, 1]]), (1, 0), (0, 1)) + 2-regular sequence 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, ... """ super().__init__(parent=parent, mu=mu, left=left, right=right) diff --git a/src/sage/combinat/recognizable_series.py b/src/sage/combinat/recognizable_series.py index 89737a780df..2ee8faaa565 100644 --- a/src/sage/combinat/recognizable_series.py +++ b/src/sage/combinat/recognizable_series.py @@ -441,6 +441,7 @@ def __init__(self, parent, mu, left, right): super(RecognizableSeries, self).__init__(parent=parent) from copy import copy + from sage.matrix.constructor import Matrix from sage.modules.free_module_element import vector from sage.sets.family import Family @@ -456,7 +457,7 @@ def immutable(m): return m if isinstance(mu, dict): - mu = dict((a, immutable(M)) for a, M in mu.items()) + mu = dict((a, immutable(Matrix(M))) for a, M in mu.items()) mu = Family(mu) if not mu.is_finite(): From c4744f7a478b462b5a64161ca28143052cc295f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 26 May 2023 20:45:43 +0200 Subject: [PATCH 61/98] fixing a lot of pycostyle warnings in calculus folder --- src/sage/calculus/all.py | 27 ++- src/sage/calculus/calculus.py | 1 + src/sage/calculus/desolvers.py | 355 ++++++++++++++-------------- src/sage/calculus/functional.py | 8 + src/sage/calculus/functions.py | 4 +- src/sage/calculus/transforms/dft.py | 3 +- src/sage/calculus/wester.py | 8 +- 7 files changed, 210 insertions(+), 196 deletions(-) diff --git a/src/sage/calculus/all.py b/src/sage/calculus/all.py index bc93e3f62a7..c83a97f6eb4 100644 --- a/src/sage/calculus/all.py +++ b/src/sage/calculus/all.py @@ -1,7 +1,7 @@ from .calculus import maxima as maxima_calculus from .calculus import (laplace, inverse_laplace, - limit, lim) + limit, lim) from .integration import numerical_integral, monte_carlo_integral integral_numerical = numerical_integral @@ -9,17 +9,17 @@ from .interpolation import spline, Spline from .functional import (diff, derivative, - expand, - taylor, simplify) + expand, + taylor, simplify) -from .functions import (wronskian,jacobian) +from .functions import (wronskian, jacobian) from .ode import ode_solver, ode_system from .desolvers import (desolve, desolve_laplace, desolve_system, - eulers_method, eulers_method_2x2, - eulers_method_2x2_plot, desolve_rk4, desolve_system_rk4, - desolve_odeint, desolve_mintides, desolve_tides_mpfr) + eulers_method, eulers_method_2x2, + eulers_method_2x2_plot, desolve_rk4, desolve_system_rk4, + desolve_odeint, desolve_mintides, desolve_tides_mpfr) from .var import (var, function, clear_vars) @@ -27,8 +27,8 @@ # We lazy_import the following modules since they import numpy which slows down sage startup from sage.misc.lazy_import import lazy_import -lazy_import("sage.calculus.riemann",["Riemann_Map"]) -lazy_import("sage.calculus.interpolators",["polygon_spline","complex_cubic_spline"]) +lazy_import("sage.calculus.riemann", ["Riemann_Map"]) +lazy_import("sage.calculus.interpolators", ["polygon_spline", "complex_cubic_spline"]) from sage.modules.free_module_element import vector from sage.matrix.constructor import matrix @@ -77,21 +77,21 @@ def symbolic_expression(x): If ``x`` is a list or tuple, create a vector of symbolic expressions:: - sage: v=symbolic_expression([x,1]); v + sage: v = symbolic_expression([x,1]); v (x, 1) sage: v.base_ring() Symbolic Ring - sage: v=symbolic_expression((x,1)); v + sage: v = symbolic_expression((x,1)); v (x, 1) sage: v.base_ring() Symbolic Ring - sage: v=symbolic_expression((3,1)); v + sage: v = symbolic_expression((3,1)); v (3, 1) sage: v.base_ring() Symbolic Ring sage: E = EllipticCurve('15a'); E Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 10*x - 10 over Rational Field - sage: v=symbolic_expression([E,E]); v + sage: v = symbolic_expression([E,E]); v (x*y + y^2 + y == x^3 + x^2 - 10*x - 10, x*y + y^2 + y == x^3 + x^2 - 10*x - 10) sage: v.base_ring() Symbolic Ring @@ -229,4 +229,5 @@ def symbolic_expression(x): return SR(result).function(*vars) return SR(x) + from . import desolvers diff --git a/src/sage/calculus/calculus.py b/src/sage/calculus/calculus.py index dae380180ac..4d99e48b474 100644 --- a/src/sage/calculus/calculus.py +++ b/src/sage/calculus/calculus.py @@ -2099,6 +2099,7 @@ def dummy_pochhammer(*args): from sage.functions.gamma import gamma return gamma(x + y) / gamma(x) + ####################################################### # # Helper functions for printing latex expression diff --git a/src/sage/calculus/desolvers.py b/src/sage/calculus/desolvers.py index e0c31925f44..eacf05f92e2 100644 --- a/src/sage/calculus/desolvers.py +++ b/src/sage/calculus/desolvers.py @@ -60,7 +60,6 @@ - Robert Marik (10-2009) - Some bugfixes and enhancements - Miguel Marco (06-2014) - Tides desolvers - """ ########################################################################## @@ -76,7 +75,6 @@ import os from sage.interfaces.maxima import Maxima -from sage.misc.lazy_import import lazy_import from sage.misc.functional import N from sage.rings.real_mpfr import RealField from sage.structure.element import Expression @@ -86,6 +84,7 @@ maxima = Maxima() + def fricas_desolve(de, dvar, ics, ivar): r""" Solve an ODE using FriCAS. @@ -118,9 +117,10 @@ def fricas_desolve(de, dvar, ics, ivar): if isinstance(y, dict): basis = y["basis"] particular = y["particular"] - return particular + sum(SR.var("_C"+str(i))*v for i, v in enumerate(basis)) - else: - return y + return particular + sum(SR.var("_C" + str(i)) * v + for i, v in enumerate(basis)) + return y + def fricas_desolve_system(des, dvars, ics, ivar): r""" @@ -163,8 +163,8 @@ def fricas_desolve_system(des, dvars, ics, ivar): y = fricas(des).solve(ops, ivar).sage() basis = y["basis"] particular = y["particular"] - pars = [SR.var("_C"+str(i)) for i in range(len(basis))] - solv = particular + sum(p*v for p, v in zip(pars, basis)) + pars = [SR.var("_C" + str(i)) for i in range(len(basis))] + solv = particular + sum(p * v for p, v in zip(pars, basis)) if ics is None: sols = solv @@ -176,6 +176,7 @@ def fricas_desolve_system(des, dvars, ics, ivar): return [dvar == sol for dvar, sol in zip(dvars, sols)] + def desolve(de, dvar, ics=None, ivar=None, show_method=False, contrib_ode=False, algorithm="maxima"): r""" @@ -570,24 +571,24 @@ def desolve(de, dvar, ics=None, ivar=None, show_method=False, contrib_ode=False, de00 = de._maxima_() P = de00.parent() - dvar_str=P(dvar.operator()).str() - ivar_str=P(ivar).str() + dvar_str = P(dvar.operator()).str() + ivar_str = P(ivar).str() de00 = de00.str() def sanitize_var(exprs): - return exprs.replace("'"+dvar_str+"("+ivar_str+")",dvar_str) + return exprs.replace("'" + dvar_str + "(" + ivar_str + ")", dvar_str) de0 = sanitize_var(de00) - ode_solver="ode2" - cmd="(TEMP:%s(%s,%s,%s), if TEMP=false then TEMP else substitute(%s=%s(%s),TEMP))"%(ode_solver,de0,dvar_str,ivar_str,dvar_str,dvar_str,ivar_str) + ode_solver = "ode2" + cmd = "(TEMP:%s(%s,%s,%s), if TEMP=false then TEMP else substitute(%s=%s(%s),TEMP))" % (ode_solver, de0, dvar_str, ivar_str, dvar_str, dvar_str, ivar_str) # we produce string like this # ode2('diff(y,x,2)+2*'diff(y,x,1)+y-cos(x),y(x),x) soln = P(cmd) if str(soln).strip() == 'false': if contrib_ode: - ode_solver="contrib_ode" + ode_solver = "contrib_ode" P("load('contrib_ode)") - cmd="(TEMP:%s(%s,%s,%s), if TEMP=false then TEMP else substitute(%s=%s(%s),TEMP))"%(ode_solver,de0,dvar_str,ivar_str,dvar_str,dvar_str,ivar_str) + cmd = "(TEMP:%s(%s,%s,%s), if TEMP=false then TEMP else substitute(%s=%s(%s),TEMP))" % (ode_solver, de0, dvar_str, ivar_str, dvar_str, dvar_str, ivar_str) # we produce string like this # (TEMP:contrib_ode(x*('diff(y,x,1))^2-(x*y+1)*'diff(y,x,1)+y,y,x), if TEMP=false then TEMP else substitute(y=y(x),TEMP)) soln = P(cmd) @@ -597,23 +598,23 @@ def sanitize_var(exprs): raise NotImplementedError("Maxima was unable to solve this ODE. Consider to set option contrib_ode to True.") if show_method: - maxima_method=P("method") + maxima_method = P("method") if ics is not None: if not (isinstance(soln.sage(), Expression) and soln.sage().is_relational()): if not show_method: - maxima_method=P("method") - raise NotImplementedError("Unable to use initial condition for this equation (%s)."%(str(maxima_method).strip())) + maxima_method = P("method") + raise NotImplementedError("Unable to use initial condition for this equation (%s)." % (str(maxima_method).strip())) if len(ics) == 2: - tempic=(ivar==ics[0])._maxima_().str() - tempic=tempic+","+(dvar==ics[1])._maxima_().str() - cmd="(TEMP:ic1(%s(%s,%s,%s),%s),substitute(%s=%s(%s),TEMP))"%(ode_solver,de00,dvar_str,ivar_str,tempic,dvar_str,dvar_str,ivar_str) - cmd=sanitize_var(cmd) + tempic = (ivar == ics[0])._maxima_().str() + tempic = tempic + "," + (dvar == ics[1])._maxima_().str() + cmd = "(TEMP:ic1(%s(%s,%s,%s),%s),substitute(%s=%s(%s),TEMP))" % (ode_solver, de00, dvar_str, ivar_str, tempic, dvar_str, dvar_str, ivar_str) + cmd = sanitize_var(cmd) # we produce string like this # (TEMP:ic2(ode2('diff(y,x,2)+2*'diff(y,x,1)+y-cos(x),y,x),x=0,y=3,'diff(y,x)=1),substitute(y=y(x),TEMP)) - soln=P(cmd) + soln = P(cmd) if len(ics) == 3: - #fixed ic2 command from Maxima - we have to ensure that %k1, %k2 do not depend on variables, should be removed when fixed in Maxima + # fixed ic2 command from Maxima - we have to ensure that %k1, %k2 do not depend on variables, should be removed when fixed in Maxima P("ic2_sage(soln,xa,ya,dya):=block([programmode:true,backsubst:true,singsolve:true,temp,%k2,%k1,TEMP_k], \ noteqn(xa), noteqn(ya), noteqn(dya), boundtest('%k1,%k1), boundtest('%k2,%k2), \ temp: lhs(soln) - rhs(soln), \ @@ -621,30 +622,30 @@ def sanitize_var(exprs): if not freeof(lhs(ya),TEMP_k) or not freeof(lhs(xa),TEMP_k) then return (false), \ temp: maplist(lambda([zz], subst(zz,soln)), TEMP_k), \ if length(temp)=1 then return(first(temp)) else return(temp))") - tempic=P(ivar==ics[0]).str() - tempic=tempic+","+P(dvar==ics[1]).str() - tempic=tempic+",'diff("+dvar_str+","+ivar_str+")="+P(ics[2]).str() - cmd="(TEMP:ic2_sage(%s(%s,%s,%s),%s),substitute(%s=%s(%s),TEMP))"%(ode_solver,de00,dvar_str,ivar_str,tempic,dvar_str,dvar_str,ivar_str) - cmd=sanitize_var(cmd) + tempic = P(ivar == ics[0]).str() + tempic += "," + P(dvar == ics[1]).str() + tempic += ",'diff(" + dvar_str + "," + ivar_str + ")=" + P(ics[2]).str() + cmd = "(TEMP:ic2_sage(%s(%s,%s,%s),%s),substitute(%s=%s(%s),TEMP))" % (ode_solver, de00, dvar_str, ivar_str, tempic, dvar_str, dvar_str, ivar_str) + cmd = sanitize_var(cmd) # we produce string like this # (TEMP:ic2(ode2('diff(y,x,2)+2*'diff(y,x,1)+y-cos(x),y,x),x=0,y=3,'diff(y,x)=1),substitute(y=y(x),TEMP)) - soln=P(cmd) + soln = P(cmd) if str(soln).strip() == 'false': raise NotImplementedError("Maxima was unable to solve this IVP. Remove the initial condition to get the general solution.") if len(ics) == 4: - #fixed bc2 command from Maxima - we have to ensure that %k1, %k2 do not depend on variables, should be removed when fixed in Maxima + # fixed bc2 command from Maxima - we have to ensure that %k1, %k2 do not depend on variables, should be removed when fixed in Maxima P("bc2_sage(soln,xa,ya,xb,yb):=block([programmode:true,backsubst:true,singsolve:true,temp,%k1,%k2,TEMP_k], \ noteqn(xa), noteqn(ya), noteqn(xb), noteqn(yb), boundtest('%k1,%k1), boundtest('%k2,%k2), \ TEMP_k:solve([subst([xa,ya],soln), subst([xb,yb],soln)], [%k1,%k2]), \ if not freeof(lhs(ya),TEMP_k) or not freeof(lhs(xa),TEMP_k) then return (false), \ temp: maplist(lambda([zz], subst(zz,soln)),TEMP_k), \ if length(temp)=1 then return(first(temp)) else return(temp))") - cmd="bc2_sage(%s(%s,%s,%s),%s,%s=%s,%s,%s=%s)"%(ode_solver,de00,dvar_str,ivar_str,P(ivar==ics[0]).str(),dvar_str,P(ics[1]).str(),P(ivar==ics[2]).str(),dvar_str,P(ics[3]).str()) - cmd="(TEMP:%s,substitute(%s=%s(%s),TEMP))"%(cmd,dvar_str,dvar_str,ivar_str) - cmd=sanitize_var(cmd) + cmd = "bc2_sage(%s(%s,%s,%s),%s,%s=%s,%s,%s=%s)" % (ode_solver, de00, dvar_str, ivar_str, P(ivar == ics[0]).str(), dvar_str, P(ics[1]).str(), P(ivar == ics[2]).str(), dvar_str, P(ics[3]).str()) + cmd = "(TEMP:%s,substitute(%s=%s(%s),TEMP))" % (cmd, dvar_str, dvar_str, ivar_str) + cmd = sanitize_var(cmd) # we produce string like this # (TEMP:bc2(ode2('diff(y,x,2)+2*'diff(y,x,1)+y-cos(x),y,x),x=0,y=3,x=%pi/2,y=2),substitute(y=y(x),TEMP)) - soln=P(cmd) + soln = P(cmd) if str(soln).strip() == 'false': raise NotImplementedError("Maxima was unable to solve this BVP. Remove the initial condition to get the general solution.") @@ -654,39 +655,38 @@ def sanitize_var(exprs): # This probably will not happen for solutions obtained via ode2, anyway. soln = soln.rhs() if show_method: - return [soln,maxima_method.str()] - else: - return soln + return [soln, maxima_method.str()] + return soln -#def desolve_laplace2(de,vars,ics=None): -## """ -## Solves an ODE using laplace transforms via maxima. Initial conditions -## are optional. - -## INPUT: -## de -- a lambda expression representing the ODE -## (eg, de = "diff(f(x),x,2)=diff(f(x),x)+sin(x)") -## vars -- a list of strings representing the variables -## (eg, vars = ["x","f"], if x is the independent -## variable and f is the dependent variable) -## ics -- a list of numbers representing initial conditions, -## with symbols allowed which are represented by strings -## (eg, f(0)=1, f'(0)=2 is ics = [0,1,2]) - -## EXAMPLES:: - -## sage: from sage.calculus.desolvers import desolve_laplace -## sage: x = var('x') -## sage: f = function('f')(x) -## sage: de = lambda y: diff(y,x,x) - 2*diff(y,x) + y -## sage: desolve_laplace(de(f(x)),[f,x]) -## #x*%e^x*(?%at('diff('f(x),x,1),x=0))-'f(0)*x*%e^x+'f(0)*%e^x -## sage: desolve_laplace(de(f(x)),[f,x],[0,1,2]) # IC option does not work -## #x*%e^x*(?%at('diff('f(x),x,1),x=0))-'f(0)*x*%e^x+'f(0)*%e^x - -## AUTHOR: David Joyner (1st version 1-2006, 8-2007) -## """ +# def desolve_laplace2(de,vars,ics=None): +# """ +# Solves an ODE using laplace transforms via maxima. Initial conditions +# are optional. + +# INPUT: +# de -- a lambda expression representing the ODE +# (eg, de = "diff(f(x),x,2)=diff(f(x),x)+sin(x)") +# vars -- a list of strings representing the variables +# (eg, vars = ["x","f"], if x is the independent +# variable and f is the dependent variable) +# ics -- a list of numbers representing initial conditions, +# with symbols allowed which are represented by strings +# (eg, f(0)=1, f'(0)=2 is ics = [0,1,2]) + +# EXAMPLES:: + +# sage: from sage.calculus.desolvers import desolve_laplace +# sage: x = var('x') +# sage: f = function('f')(x) +# sage: de = lambda y: diff(y,x,x) - 2*diff(y,x) + y +# sage: desolve_laplace(de(f(x)),[f,x]) +# #x*%e^x*(?%at('diff('f(x),x,1),x=0))-'f(0)*x*%e^x+'f(0)*%e^x +# sage: desolve_laplace(de(f(x)),[f,x],[0,1,2]) # IC option does not work +# #x*%e^x*(?%at('diff('f(x),x,1),x=0))-'f(0)*x*%e^x+'f(0)*%e^x + +# AUTHOR: David Joyner (1st version 1-2006, 8-2007) +# """ # ######## this method seems reasonable but doesn't work for some reason # name0 = vars[0]._repr_()[0:(len(vars[0]._repr_())-2-len(str(vars[1])))] # name1 = str(vars[1]) @@ -783,18 +783,18 @@ def desolve_laplace(de, dvar, ics=None, ivar=None): - Robert Marik (10-2009) """ - #This is the original code from David Joyner (inputs and outputs strings) - #maxima("de:"+de._repr_()+"=0;") - #if ics is not None: - # d = len(ics) - # for i in range(0,d-1): - # ic = "atvalue(diff("+vars[1]+"("+vars[0]+"),"+str(vars[0])+","+str(i)+"),"+str(vars[0])+"="+str(ics[0])+","+str(ics[1+i])+")" - # maxima(ic) + # This is the original code from David Joyner (inputs and outputs strings) + # maxima("de:"+de._repr_()+"=0;") + # if ics is not None: + # d = len(ics) + # for i in range(0,d-1): + # ic = "atvalue(diff("+vars[1]+"("+vars[0]+"),"+str(vars[0])+","+str(i)+"),"+str(vars[0])+"="+str(ics[0])+","+str(ics[1+i])+")" + # maxima(ic) # - #cmd = "desolve("+de._repr_()+","+vars[1]+"("+vars[0]+"));" - #return maxima(cmd).rhs()._maxima_init_() + # cmd = "desolve("+de._repr_()+","+vars[1]+"("+vars[0]+"));" + # return maxima(cmd).rhs()._maxima_init_() - ## verbatim copy from desolve - begin + # verbatim copy from desolve - begin if isinstance(de, Expression) and de.is_relational(): de = de.lhs() - de.rhs() if isinstance(dvar, Expression) and dvar.is_symbol(): @@ -808,25 +808,27 @@ def desolve_laplace(de, dvar, ics=None, ivar=None): if len(ivars) != 1: raise ValueError("Unable to determine independent variable, please specify.") ivar = ivars[0] - ## verbatim copy from desolve - end + # verbatim copy from desolve - end dvar_str = str(dvar) - def sanitize_var(exprs): # 'y(x) -> y(x) - return exprs.replace("'"+dvar_str,dvar_str) - de0=de._maxima_() + def sanitize_var(exprs): + # 'y(x) -> y(x) + return exprs.replace("'" + dvar_str, dvar_str) + + de0 = de._maxima_() P = de0.parent() i = dvar_str.find('(') - dvar_str = dvar_str[:i+1] + '_SAGE_VAR_' + dvar_str[i+1:] - cmd = sanitize_var("desolve("+de0.str()+","+dvar_str+")") - soln=P(cmd).rhs() + dvar_str = dvar_str[:i + 1] + '_SAGE_VAR_' + dvar_str[i + 1:] + cmd = sanitize_var("desolve(" + de0.str() + "," + dvar_str + ")") + soln = P(cmd).rhs() if str(soln).strip() == 'false': raise NotImplementedError("Maxima was unable to solve this ODE.") - soln=soln.sage() + soln = soln.sage() if ics is not None: d = len(ics) - for i in range(0,d-1): - soln=eval('soln.substitute(diff(dvar,ivar,i)('+str(ivar)+'=ics[0])==ics[i+1])') + for i in range(d - 1): + soln = eval('soln.substitute(diff(dvar,ivar,i)(' + str(ivar) + '=ics[0])==ics[i+1])') return soln @@ -976,7 +978,7 @@ def desolve_system(des, vars, ics=None, ivar=None, algorithm="maxima"): if ics is not None: ivar_ic = ics[0] for dvar, ic in zip(dvars, ics[1:]): - dvar.atvalue(ivar==ivar_ic, ic) + dvar.atvalue(ivar == ivar_ic, ic) soln = dvars[0].parent().desolve(des, dvars) if str(soln).strip() == 'false': raise NotImplementedError("Maxima was unable to solve this system.") @@ -986,11 +988,11 @@ def desolve_system(des, vars, ics=None, ivar=None, algorithm="maxima"): if ics is not None: ivar_ic = ics[0] for dvar, ic in zip(dvars, ics[:1]): - dvar.atvalue(ivar==ivar_ic, dvar) + dvar.atvalue(ivar == ivar_ic, dvar) return soln -def eulers_method(f,x0,y0,h,x1,algorithm="table"): +def eulers_method(f, x0, y0, h, x1, algorithm="table"): r""" This implements Euler's method for finding numerically the solution of the 1st order ODE `y' = f(x,y)`, `y(a)=c`. The ``x`` @@ -1062,23 +1064,23 @@ def eulers_method(f,x0,y0,h,x1,algorithm="table"): - David Joyner """ - if algorithm=="table": - print("%10s %20s %25s"%("x","y","h*f(x,y)")) - n=int((1.0)*(x1-x0)/h) + if algorithm == "table": + print("%10s %20s %25s" % ("x", "y", "h*f(x,y)")) + n = int((1.0) * (x1 - x0) / h) x00 = x0 y00 = y0 - soln = [[x00,y00]] - for i in range(n+1): - if algorithm=="table": - print("%10r %20r %20r"%(x00,y00,h*f(x00,y00))) - y00 = y00+h*f(x00,y00) - x00=x00+h - soln.append([x00,y00]) - if algorithm!="table": + soln = [[x00, y00]] + for i in range(n + 1): + if algorithm == "table": + print("%10r %20r %20r" % (x00, y00, h * f(x00, y00))) + y00 = y00 + h * f(x00, y00) + x00 = x00 + h + soln.append([x00, y00]) + if algorithm != "table": return soln -def eulers_method_2x2(f,g, t0, x0, y0, h, t1,algorithm="table"): +def eulers_method_2x2(f, g, t0, x0, y0, h, t1, algorithm="table"): r""" This implements Euler's method for finding numerically the solution of the 1st order system of two ODEs @@ -1162,25 +1164,26 @@ def eulers_method_2x2(f,g, t0, x0, y0, h, t1,algorithm="table"): - David Joyner """ - if algorithm=="table": - print("%10s %20s %25s %20s %20s"%("t", "x","h*f(t,x,y)","y", "h*g(t,x,y)")) - n = int((1.0)*(t1-t0)/h) + if algorithm == "table": + print("%10s %20s %25s %20s %20s" % ("t", "x", "h*f(t,x,y)", "y", "h*g(t,x,y)")) + n = int((1.0) * (t1 - t0) / h) t00 = t0 x00 = x0 y00 = y0 soln = [[t00, x00, y00]] - for i in range(n+1): - if algorithm=="table": - print("%10r %20r %25r %20r %20r"%(t00,x00,h*f(t00,x00,y00),y00,h*g(t00,x00,y00))) - x01 = x00 + h*f(t00,x00,y00) - y00 = y00 + h*g(t00,x00,y00) + for i in range(n + 1): + if algorithm == "table": + print("%10r %20r %25r %20r %20r" % (t00, x00, h * f(t00, x00, y00), y00, h * g(t00, x00, y00))) + x01 = x00 + h * f(t00, x00, y00) + y00 = y00 + h * g(t00, x00, y00) x00 = x01 t00 = t00 + h - soln.append([t00,x00,y00]) - if algorithm!="table": + soln.append([t00, x00, y00]) + if algorithm != "table": return soln -def eulers_method_2x2_plot(f,g, t0, x0, y0, h, t1): + +def eulers_method_2x2_plot(f, g, t0, x0, y0, h, t1): r""" Plot solution of ODE. @@ -1207,7 +1210,7 @@ def eulers_method_2x2_plot(f,g, t0, x0, y0, h, t1): """ from sage.plot.line import line - n = int((1.0)*(t1-t0)/h) + n = int((1.0) * (t1 - t0) / h) t00 = t0 x00 = x0 y00 = y0 @@ -1223,7 +1226,7 @@ def eulers_method_2x2_plot(f,g, t0, x0, y0, h, t1): return [Q1, Q2] -def desolve_rk4_determine_bounds(ics,end_points=None): +def desolve_rk4_determine_bounds(ics, end_points=None): """ Used to determine bounds for numerical integration. @@ -1365,26 +1368,26 @@ def desolve_rk4(de, dvar, ics=None, ivar=None, end_points=None, step=0.1, output raise ValueError("Unable to determine independent variable, please specify.") ivar = ivars[0] - step=abs(step) + step = abs(step) def desolve_rk4_inner(de, dvar): - de0=de._maxima_() + de0 = de._maxima_() maxima("load('dynamics)") - lower_bound,upper_bound=desolve_rk4_determine_bounds(ics,end_points) - sol_1, sol_2 = [],[] - if lower_boundics[0]: - cmd="rk(%s,%s,%s,[%s,%s,%s,%s])\ - "%(de0.str(),'_SAGE_VAR_'+str(dvar),str(ics[1]),'_SAGE_VAR_'+str(ivar),str(ics[0]),upper_bound,step) - sol_2=maxima(cmd).sage() + if upper_bound > ics[0]: + cmd = "rk(%s,%s,%s,[%s,%s,%s,%s])\ + " % (de0.str(), '_SAGE_VAR_' + str(dvar), str(ics[1]), '_SAGE_VAR_' + str(ivar), str(ics[0]), upper_bound, step) + sol_2 = maxima(cmd).sage() sol_2.pop(0) - sol=sol_1 - sol.extend([[ics[0],ics[1]]]) + sol = sol_1 + sol.extend([[ics[0], ics[1]]]) sol.extend(sol_2) if output == 'list': @@ -1408,7 +1411,7 @@ def desolve_rk4_inner(de, dvar): YMAX = t if t < YMIN: YMIN = t - return plot_slope_field(de, (ivar,XMIN,XMAX), (dvar,YMIN,YMAX))+R + return plot_slope_field(de, (ivar, XMIN, XMAX), (dvar, YMIN, YMAX)) + R if not (isinstance(dvar, Expression) and dvar.is_symbol()): from sage.symbolic.ring import SR @@ -1417,14 +1420,15 @@ def desolve_rk4_inner(de, dvar): if isinstance(de, Expression) and de.is_relational(): de = de.lhs() - de.rhs() # consider to add warning if the solution is not unique - de=solve(de,diff(dvar,ivar),solution_dict=True) + de = solve(de, diff(dvar, ivar), solution_dict=True) if len(de) != 1: raise NotImplementedError("Sorry, cannot find explicit formula for right-hand side of the ODE.") with SR.temp_var() as dummy_dvar: - return desolve_rk4_inner(de[0][diff(dvar,ivar)].subs({dvar:dummy_dvar}), dummy_dvar) + return desolve_rk4_inner(de[0][diff(dvar, ivar)].subs({dvar: dummy_dvar}), dummy_dvar) else: return desolve_rk4_inner(de, dvar) + def desolve_system_rk4(des, vars, ics=None, ivar=None, end_points=None, step=0.1): r""" Solve numerically a system of first-order ordinary differential @@ -1505,34 +1509,35 @@ def desolve_system_rk4(des, vars, ics=None, ivar=None, end_points=None, step=0.1 desstr = "[" + ",".join(dess) + "]" varss = [varsi._maxima_().str() for varsi in vars] varstr = "[" + ",".join(varss) + "]" - x0=ics[0] - icss = [ics[i]._maxima_().str() for i in range(1,len(ics))] + x0 = ics[0] + icss = [ics[i]._maxima_().str() for i in range(1, len(ics))] icstr = "[" + ",".join(icss) + "]" - step=abs(step) + step = abs(step) maxima("load('dynamics)") - lower_bound,upper_bound=desolve_rk4_determine_bounds(ics,end_points) - sol_1, sol_2 = [],[] - if lower_boundics[0]: - cmd="rk(%s,%s,%s,[%s,%s,%s,%s])\ - "%(desstr,varstr,icstr,'_SAGE_VAR_'+str(ivar),str(x0),upper_bound,step) - sol_2=maxima(cmd).sage() + if upper_bound > ics[0]: + cmd = "rk(%s,%s,%s,[%s,%s,%s,%s])\ + " % (desstr, varstr, icstr, '_SAGE_VAR_' + str(ivar), str(x0), upper_bound, step) + sol_2 = maxima(cmd).sage() sol_2.pop(0) - sol=sol_1 + sol = sol_1 sol.append(ics) sol.extend(sol_2) return sol -def desolve_odeint(des, ics, times, dvars, ivar=None, compute_jac=False, args=() -, rtol=None, atol=None, tcrit=None, h0=0.0, hmax=0.0, hmin=0.0, ixpr=0 -, mxstep=0, mxhnil=0, mxordn=12, mxords=5, printmessg=0): + +def desolve_odeint(des, ics, times, dvars, ivar=None, compute_jac=False, args=(), + rtol=None, atol=None, tcrit=None, h0=0.0, hmax=0.0, hmin=0.0, ixpr=0, + mxstep=0, mxhnil=0, mxordn=12, mxords=5, printmessg=0): r""" Solve numerically a system of first-order ordinary differential equations using ``odeint`` from scipy.integrate module. @@ -1702,10 +1707,9 @@ def Dfun(y, t): v.append(t) return [[element(*v) for element in row] for row in J] - sol=odeint(func, ics, times, args=args, Dfun=Dfun, rtol=rtol, atol=atol, - tcrit=tcrit, h0=h0, hmax=hmax, hmin=hmin, ixpr=ixpr, mxstep=mxstep, - mxhnil=mxhnil, mxordn=mxordn, mxords=mxords, printmessg=printmessg) - return sol + return odeint(func, ics, times, args=args, Dfun=Dfun, rtol=rtol, atol=atol, + tcrit=tcrit, h0=h0, hmax=hmax, hmin=hmin, ixpr=ixpr, mxstep=mxstep, + mxhnil=mxhnil, mxordn=mxordn, mxords=mxords, printmessg=printmessg) if isinstance(dvars, Expression) and dvars.is_symbol(): dvars = [dvars] @@ -1717,7 +1721,7 @@ def Dfun(y, t): all_vars = set().union(*[de.variables() for de in des]) ivars = all_vars - set(dvars) - if len(ivars)==1: + if len(ivars) == 1: return desolve_odeint_inner(next(iter(ivars))) elif not ivars: from sage.symbolic.ring import SR @@ -1727,7 +1731,8 @@ def Dfun(y, t): raise ValueError("Unable to determine independent variable, please specify.") return desolve_odeint_inner(ivar) -def desolve_mintides(f, ics, initial, final, delta, tolrel=1e-16, tolabs=1e-16): + +def desolve_mintides(f, ics, initial, final, delta, tolrel=1e-16, tolabs=1e-16): r""" Solve numerically a system of first order differential equations using the taylor series integrator implemented in mintides. @@ -1798,27 +1803,27 @@ def desolve_mintides(f, ics, initial, final, delta, tolrel=1e-16, tolabs=1e-16) from sage.misc.temporary_file import tmp_dir tempdir = tmp_dir() intfile = os.path.join(tempdir, 'integrator.c') - drfile = os.path.join(tempdir ,'driver.c') + drfile = os.path.join(tempdir, 'driver.c') fileoutput = os.path.join(tempdir, 'output') runmefile = os.path.join(tempdir, 'runme') - genfiles_mintides(intfile, drfile, f, [N(_) for _ in ics], N(initial), N(final), N(delta), N(tolrel), - N(tolabs), fileoutput) + genfiles_mintides(intfile, drfile, f, [N(_) for _ in ics], + N(initial), N(final), N(delta), N(tolrel), + N(tolabs), fileoutput) subprocess.check_call('gcc -o ' + runmefile + ' ' + os.path.join(tempdir, '*.c ') + - os.path.join('$SAGE_LOCAL','lib','libTIDES.a') + ' $LDFLAGS ' - + os.path.join('-L$SAGE_LOCAL','lib ') +' -lm -O2 ' + - os.path.join('-I$SAGE_LOCAL','include '), - shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - subprocess.check_call(os.path.join(tempdir, 'runme'), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - outfile = open(fileoutput) - res = outfile.readlines() - outfile.close() + os.path.join('$SAGE_LOCAL', 'lib', 'libTIDES.a') + ' $LDFLAGS ' + + os.path.join('-L$SAGE_LOCAL', 'lib ') + ' -lm -O2 ' + + os.path.join('-I$SAGE_LOCAL', 'include '), + shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + subprocess.check_call(os.path.join(tempdir, 'runme'), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + with open(fileoutput) as outfile: + res = outfile.readlines() for i in range(len(res)): res[i] = [RealField()(_) for _ in res[i].split(' ') if len(_) > 2] shutil.rmtree(tempdir) return res -def desolve_tides_mpfr(f, ics, initial, final, delta, tolrel=1e-16, tolabs=1e-16, digits=50): +def desolve_tides_mpfr(f, ics, initial, final, delta, tolrel=1e-16, tolabs=1e-16, digits=50): r""" Solve numerically a system of first order differential equations using the taylor series integrator in arbitrary precision implemented in tides. @@ -1902,17 +1907,17 @@ def desolve_tides_mpfr(f, ics, initial, final, delta, tolrel=1e-16, tolabs=1e-1 fileoutput = os.path.join(tempdir, 'output') runmefile = os.path.join(tempdir, 'runme') genfiles_mpfr(intfile, drfile, f, ics, initial, final, delta, [], [], - digits, tolrel, tolabs, fileoutput) + digits, tolrel, tolabs, fileoutput) subprocess.check_call('gcc -o ' + runmefile + ' ' + os.path.join(tempdir, '*.c ') + - os.path.join('$SAGE_LOCAL','lib','libTIDES.a') + ' $LDFLAGS ' - + os.path.join('-L$SAGE_LOCAL','lib ') + '-lmpfr -lgmp -lm -O2 -w ' + - os.path.join('-I$SAGE_LOCAL','include ') , - shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - subprocess.check_call(os.path.join(tempdir, 'runme'), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - outfile = open(fileoutput) - res = outfile.readlines() - outfile.close() + os.path.join('$SAGE_LOCAL', 'lib', 'libTIDES.a') + ' $LDFLAGS ' + + os.path.join('-L$SAGE_LOCAL', 'lib ') + '-lmpfr -lgmp -lm -O2 -w ' + + os.path.join('-I$SAGE_LOCAL', 'include '), + shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + subprocess.check_call(os.path.join(tempdir, 'runme'), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + with open(fileoutput) as outfile: + res = outfile.readlines() for i in range(len(res)): - res[i] = [RealField(ceil(digits*log(10,2)))(_) for _ in res[i].split(' ') if len(_) > 2] + res[i] = [RealField(ceil(digits * log(10, 2)))(piece) + for piece in res[i].split(' ') if len(piece) > 2] shutil.rmtree(tempdir) return res diff --git a/src/sage/calculus/functional.py b/src/sage/calculus/functional.py index 9cce6cc1e83..285e1394ab1 100644 --- a/src/sage/calculus/functional.py +++ b/src/sage/calculus/functional.py @@ -48,6 +48,7 @@ def simplify(f): except AttributeError: return f + def derivative(f, *args, **kwds): r""" The derivative of `f`. @@ -151,8 +152,10 @@ def derivative(f, *args, **kwds): f = SR(f) return f.derivative(*args, **kwds) + diff = derivative + def integral(f, *args, **kwds): r""" The integral of `f`. @@ -299,8 +302,10 @@ def integral(f, *args, **kwds): f = SR(f) return f.integral(*args, **kwds) + integrate = integral + def limit(f, dir=None, taylor=False, **argv): r""" Return the limit as the variable `v` approaches `a` @@ -353,8 +358,10 @@ def limit(f, dir=None, taylor=False, **argv): f = SR(f) return f.limit(dir=dir, taylor=taylor, **argv) + lim = limit + def taylor(f, *args): """ Expands self in a truncated Taylor or Laurent series in the @@ -397,6 +404,7 @@ def taylor(f, *args): f = SR(f) return f.taylor(*args) + def expand(x, *args, **kwds): """ EXAMPLES:: diff --git a/src/sage/calculus/functions.py b/src/sage/calculus/functions.py index 910984cb578..6c47b0d2fc9 100644 --- a/src/sage/calculus/functions.py +++ b/src/sage/calculus/functions.py @@ -134,9 +134,9 @@ def jacobian(functions, variables): [ x^3*cos(y) 3*x^2*sin(y)] [ cos(x)*cos(y) -sin(x)*sin(y)] [ 0 e^x] - """ - if is_Matrix(functions) and (functions.nrows()==1 or functions.ncols()==1): + if is_Matrix(functions) and (functions.nrows() == 1 + or functions.ncols() == 1): functions = functions.list() elif not (isinstance(functions, (tuple, list)) or is_Vector(functions)): functions = [functions] diff --git a/src/sage/calculus/transforms/dft.py b/src/sage/calculus/transforms/dft.py index 9fd396f1915..db18a20e129 100644 --- a/src/sage/calculus/transforms/dft.py +++ b/src/sage/calculus/transforms/dft.py @@ -73,7 +73,6 @@ ########################################################################## from sage.rings.number_field.number_field import CyclotomicField from sage.misc.lazy_import import lazy_import -lazy_import("sage.plot.all", ["polygon", "line", "text"]) from sage.groups.abelian_gps.abelian_group import AbelianGroup from sage.groups.perm_gps.permgroup_element import is_PermutationGroupElement from sage.rings.integer_ring import ZZ @@ -83,9 +82,9 @@ from sage.functions.all import sin, cos from sage.calculus.transforms.fft import FastFourierTransform from sage.calculus.transforms.dwt import WaveletTransform - from sage.structure.sage_object import SageObject from sage.structure.sequence import Sequence +lazy_import("sage.plot.all", ["polygon", "line", "text"]) class IndexedSequence(SageObject): diff --git a/src/sage/calculus/wester.py b/src/sage/calculus/wester.py index 0a2a374cd5f..a6aab275c61 100644 --- a/src/sage/calculus/wester.py +++ b/src/sage/calculus/wester.py @@ -226,16 +226,16 @@ sage: # Maxima doesn't solve inequalities sage: # (but some Maxima packages do): sage: eqn = abs(x-1) > 2 - sage: eqn - abs(x - 1) > 2 + sage: eqn.solve(x) + [[x < -1], [3 < x]] :: sage: # (NO) Solve the inequality (x-1)*...*(x-5)<0. sage: eqn = prod(x-i for i in range(1,5 +1)) < 0 sage: # but don't know how to solve - sage: eqn - (x - 1)*(x - 2)*(x - 3)*(x - 4)*(x - 5) < 0 + sage: eqn.solve(x) + [[x < 1], [x > 2, x < 3], [x > 4, x < 5]] :: From b3d322ee8e98eb666ddc18fe9d94973202a70b4a Mon Sep 17 00:00:00 2001 From: miguelmarco Date: Sat, 27 May 2023 00:45:24 +0200 Subject: [PATCH 62/98] Update src/sage/algebras/commutative_dga.py Co-authored-by: Travis Scrimshaw --- src/sage/algebras/commutative_dga.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sage/algebras/commutative_dga.py b/src/sage/algebras/commutative_dga.py index f1148024ce2..43fbf65c29d 100644 --- a/src/sage/algebras/commutative_dga.py +++ b/src/sage/algebras/commutative_dga.py @@ -3896,10 +3896,11 @@ class CohomologyClass(SageObject, CachedRepresentation): sage: CohomologyClass(x^2+2*y*z, A) [2*y*z + x^2] - In order for the cache to not confuse objects with the same representation, - we can pass the parent of the representative as a parameter. - TESTS:: + TESTS: + + In order for the cache to not confuse objects with the same representation, + we can pass the parent of the representative as a parameter:: sage: A. = GradedCommutativeAlgebra(QQ) sage: B1 = A.cdg_algebra({e5:e1*e2,e6:e3*e4}) From af62ec2023e905399e56951bd7f8bd6723644814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 27 May 2023 08:33:19 +0200 Subject: [PATCH 63/98] remove commented code --- src/sage/calculus/desolvers.py | 43 ---------------------------------- 1 file changed, 43 deletions(-) diff --git a/src/sage/calculus/desolvers.py b/src/sage/calculus/desolvers.py index eacf05f92e2..55ed3a0fe10 100644 --- a/src/sage/calculus/desolvers.py +++ b/src/sage/calculus/desolvers.py @@ -659,49 +659,6 @@ def sanitize_var(exprs): return soln -# def desolve_laplace2(de,vars,ics=None): -# """ -# Solves an ODE using laplace transforms via maxima. Initial conditions -# are optional. - -# INPUT: -# de -- a lambda expression representing the ODE -# (eg, de = "diff(f(x),x,2)=diff(f(x),x)+sin(x)") -# vars -- a list of strings representing the variables -# (eg, vars = ["x","f"], if x is the independent -# variable and f is the dependent variable) -# ics -- a list of numbers representing initial conditions, -# with symbols allowed which are represented by strings -# (eg, f(0)=1, f'(0)=2 is ics = [0,1,2]) - -# EXAMPLES:: - -# sage: from sage.calculus.desolvers import desolve_laplace -# sage: x = var('x') -# sage: f = function('f')(x) -# sage: de = lambda y: diff(y,x,x) - 2*diff(y,x) + y -# sage: desolve_laplace(de(f(x)),[f,x]) -# #x*%e^x*(?%at('diff('f(x),x,1),x=0))-'f(0)*x*%e^x+'f(0)*%e^x -# sage: desolve_laplace(de(f(x)),[f,x],[0,1,2]) # IC option does not work -# #x*%e^x*(?%at('diff('f(x),x,1),x=0))-'f(0)*x*%e^x+'f(0)*%e^x - -# AUTHOR: David Joyner (1st version 1-2006, 8-2007) -# """ -# ######## this method seems reasonable but doesn't work for some reason -# name0 = vars[0]._repr_()[0:(len(vars[0]._repr_())-2-len(str(vars[1])))] -# name1 = str(vars[1]) -# #maxima("de:"+de+";") -# if ics is not None: -# ic0 = maxima("ic:"+str(vars[1])+"="+str(ics[0])) -# d = len(ics) -# for i in range(d-1): -# maxima(vars[0](vars[1])).diff(vars[1],i).atvalue(ic0,ics[i+1]) -# de0 = de._maxima_() -# #cmd = "desolve("+de+","+vars[1]+"("+vars[0]+"));" -# #return maxima.eval(cmd) -# return de0.desolve(vars[0]).rhs() - - def desolve_laplace(de, dvar, ics=None, ivar=None): """ Solve an ODE using Laplace transforms. Initial conditions are optional. From 5c910ab07bd0f00fb9612b126282efc6ee8fc4bc Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 21 May 2023 17:29:01 -0700 Subject: [PATCH 64/98] build/pkgs/sympy: Update to 1.12 --- build/pkgs/sympy/checksums.ini | 6 +++--- build/pkgs/sympy/package-version.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/pkgs/sympy/checksums.ini b/build/pkgs/sympy/checksums.ini index f59c0083e07..72ea62bb91f 100644 --- a/build/pkgs/sympy/checksums.ini +++ b/build/pkgs/sympy/checksums.ini @@ -1,5 +1,5 @@ tarball=sympy-VERSION.tar.gz -sha1=9e75c8cafa4324f2803a6488ac713d87adf5cb64 -md5=232141d248ab4164e92c8ac59a996914 -cksum=2645245679 +sha1=604968f191e2d69053b8310066d089f73a1bd109 +md5=3e0033109352d7303ea97b9216e16645 +cksum=2437095035 upstream_url=https://github.com/sympy/sympy/releases/download/sympy-VERSION/sympy-VERSION.tar.gz diff --git a/build/pkgs/sympy/package-version.txt b/build/pkgs/sympy/package-version.txt index 720c7384c61..809bdcb851d 100644 --- a/build/pkgs/sympy/package-version.txt +++ b/build/pkgs/sympy/package-version.txt @@ -1 +1 @@ -1.11.1 +1.12 From cc63398a0b70f9052cbe9735de4ebb34f1587823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 28 May 2023 16:26:24 +0200 Subject: [PATCH 65/98] some fixes for pycodestyle E275 --- .../weyl_lie_conformal_algebra.py | 18 ++++++++++-------- src/sage/crypto/block_cipher/des.py | 4 ++-- src/sage/crypto/mq/sr.py | 2 +- src/sage/games/quantumino.py | 4 ++-- src/sage/geometry/polyhedron/parent.py | 6 +++--- src/sage/interfaces/qepcad.py | 2 +- src/sage/logic/boolformula.py | 3 ++- src/sage/modular/arithgroup/congroup_gamma0.py | 2 +- src/sage/modular/btquotients/btquotient.py | 6 +++--- src/sage/modular/hypergeometric_motive.py | 9 ++++----- .../modular/modform/l_series_gross_zagier.py | 2 +- .../modform_hecketriangle/abstract_space.py | 7 +++---- .../hecke_triangle_group_element.py | 8 ++++---- src/sage/modular/modsym/tests.py | 6 +++--- src/sage/modular/overconvergent/genus0.py | 4 ++-- src/sage/modular/pollack_stevens/modsym.py | 6 +++--- src/sage/modular/quatalg/brandt.py | 10 +++++----- src/sage/modular/ssmod/ssmod.py | 13 ++++++------- src/sage/modules/free_module_homspace.py | 2 +- src/sage/modules/free_module_integer.py | 2 +- src/sage/modules/with_basis/morphism.py | 4 ++-- src/sage/monoids/automatic_semigroup.py | 14 +++++++------- src/sage/plot/plot3d/shapes2.py | 2 +- ...adratic_form__mass__Conway_Sloane_masses.py | 18 +++++++++--------- src/sage/sat/boolean_polynomials.py | 4 ++-- .../sets/disjoint_union_enumerated_sets.py | 4 ++-- src/sage/sets/family.py | 13 +++++++------ .../distributions/discrete_gaussian_lattice.py | 4 ++-- src/sage/structure/dynamic_class.py | 2 +- src/sage/tests/benchmark.py | 4 ++-- src/sage/tests/finite_poset.py | 6 +++--- src/sage/topology/simplicial_set.py | 4 ++-- 32 files changed, 98 insertions(+), 97 deletions(-) diff --git a/src/sage/algebras/lie_conformal_algebras/weyl_lie_conformal_algebra.py b/src/sage/algebras/lie_conformal_algebras/weyl_lie_conformal_algebra.py index c51ed309ca5..e4a91723558 100644 --- a/src/sage/algebras/lie_conformal_algebras/weyl_lie_conformal_algebra.py +++ b/src/sage/algebras/lie_conformal_algebras/weyl_lie_conformal_algebra.py @@ -23,21 +23,22 @@ - Reimundo Heluani (2019-08-09): Initial implementation. """ -#****************************************************************************** +# ***************************************************************************** # Copyright (C) 2019 Reimundo Heluani # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from .lie_conformal_algebra_with_structure_coefs import \ - LieConformalAlgebraWithStructureCoefficients + LieConformalAlgebraWithStructureCoefficients from sage.matrix.special import identity_matrix from sage.structure.indexed_generators import standardize_names_index_set + class WeylLieConformalAlgebra(LieConformalAlgebraWithStructureCoefficients): r""" The Weyl Lie conformal algebra. @@ -132,7 +133,7 @@ def __init__(self, R, ngens=None, gram_matrix=None, names=None, from sage.matrix.matrix_space import MatrixSpace if ngens: from sage.rings.integer_ring import ZZ - if not(ngens in ZZ and not ngens % 2): + if not (ngens in ZZ and not ngens % 2): raise ValueError("ngens needs to be an even positive Integer, " f"got {ngens}") if gram_matrix is not None: @@ -163,8 +164,9 @@ def __init__(self, R, ngens=None, gram_matrix=None, names=None, names, index_set = standardize_names_index_set(names=names, index_set=index_set, ngens=ngens) - weyldict = { (i,j): {0: {('K',0): gram_matrix[index_set.rank(i), - index_set.rank(j)]}} for i in index_set for j in index_set} + weyldict = {(i, j): {0: {('K', 0): gram_matrix[index_set.rank(i), + index_set.rank(j)]}} + for i in index_set for j in index_set} super().__init__(R, weyldict, names=names, latex_names=latex_names, @@ -182,7 +184,7 @@ def _repr_(self): The Weyl Lie conformal algebra with generators (alpha0, alpha1, K) over Integer Ring """ return "The Weyl Lie conformal algebra with generators {} over {}"\ - .format(self.gens(),self.base_ring()) + .format(self.gens(), self.base_ring()) def gram_matrix(self): r""" diff --git a/src/sage/crypto/block_cipher/des.py b/src/sage/crypto/block_cipher/des.py index 4eddfba1425..e0d7f8b0471 100644 --- a/src/sage/crypto/block_cipher/des.py +++ b/src/sage/crypto/block_cipher/des.py @@ -472,8 +472,8 @@ def __repr__(self): DES block cipher with 16 rounds and the following key schedule: Original DES key schedule with 16 rounds """ - return('DES block cipher with %s rounds and the following key ' - 'schedule:\n%s' % (self._rounds, self.keySchedule.__repr__())) + return ('DES block cipher with %s rounds and the following key ' + 'schedule:\n%s' % (self._rounds, self.keySchedule.__repr__())) def encrypt(self, plaintext, key): r""" diff --git a/src/sage/crypto/mq/sr.py b/src/sage/crypto/mq/sr.py index 14385e96878..b00952486de 100644 --- a/src/sage/crypto/mq/sr.py +++ b/src/sage/crypto/mq/sr.py @@ -665,7 +665,7 @@ def __ne__(self, other): sage: sr1 != sr2 True """ - return not(self == other) + return not (self == other) def sub_bytes(self, d): r""" diff --git a/src/sage/games/quantumino.py b/src/sage/games/quantumino.py index 98332762613..9f8da835585 100644 --- a/src/sage/games/quantumino.py +++ b/src/sage/games/quantumino.py @@ -424,8 +424,8 @@ def __init__(self, aside, box=(5, 8, 2)): Quantumino solver for the box (5, 8, 2) Aside pentamino number: 9 """ - if not(0 <= aside < 17): - raise ValueError("aside (=%s) must be between 0 and 16" % aside) + if not (0 <= aside < 17): + raise ValueError(f"aside (={aside}) must be between 0 and 16") self._aside = aside self._box = box diff --git a/src/sage/geometry/polyhedron/parent.py b/src/sage/geometry/polyhedron/parent.py index 1993f17b1cc..813f30a7d4b 100644 --- a/src/sage/geometry/polyhedron/parent.py +++ b/src/sage/geometry/polyhedron/parent.py @@ -400,10 +400,10 @@ def some_elements(self): points = [] R = self.base_ring() for i in range(self.ambient_dim() + 5): - points.append([R(i*j^2) for j in range(self.ambient_dim())]) + points.append([R(i * j**2) for j in range(self.ambient_dim())]) return [ - self.element_class(self, [points[0:self.ambient_dim()+1], [], []], None), - self.element_class(self, [points[0:1], points[1:self.ambient_dim()+1], []], None), + self.element_class(self, [points[0:self.ambient_dim() + 1], [], []], None), + self.element_class(self, [points[0:1], points[1:self.ambient_dim() + 1], []], None), self.element_class(self, [points[0:3], points[4:5], []], None), self.element_class(self, None, None)] diff --git a/src/sage/interfaces/qepcad.py b/src/sage/interfaces/qepcad.py index fb850931b91..f54c8e181d7 100644 --- a/src/sage/interfaces/qepcad.py +++ b/src/sage/interfaces/qepcad.py @@ -2427,7 +2427,7 @@ def __init__(self, parent, lines): index = (index,) self._index = index - self._dimension = sum([r&1 for r in index]) + self._dimension = sum([r & 1 for r in index]) if 'Level ' in line: self._level = int(line.split(':')[1].strip()) if 'Number of children' in line: diff --git a/src/sage/logic/boolformula.py b/src/sage/logic/boolformula.py index 137edb8e8a2..ae2c1ee6aba 100644 --- a/src/sage/logic/boolformula.py +++ b/src/sage/logic/boolformula.py @@ -1167,7 +1167,7 @@ def convert_opt(self, tree): lval = ('prop', tree[1]) else: lval = tree[1] - if not isinstance(tree[2], tuple) and not(tree[2] is None): + if not isinstance(tree[2], tuple) and tree[2] is not None: rval = ('prop', tree[2]) else: rval = tree[2] @@ -1557,5 +1557,6 @@ def length(self): # `len(self)`, but this may be deprecated in the future (see :trac:`32148`): __len__ = length + # allow is_consequence to be called as a function (not only as a method of BooleanFormula) is_consequence = BooleanFormula.is_consequence diff --git a/src/sage/modular/arithgroup/congroup_gamma0.py b/src/sage/modular/arithgroup/congroup_gamma0.py index edd8108350a..5bc0a6e4b3a 100644 --- a/src/sage/modular/arithgroup/congroup_gamma0.py +++ b/src/sage/modular/arithgroup/congroup_gamma0.py @@ -596,7 +596,7 @@ def dimension_new_cusp_forms(self, k=2, p=0): N = self.level() k = ZZ(k) - if not(p == 0 or N % p): + if not (p == 0 or N % p): return (self.dimension_cusp_forms(k) - 2 * self.restrict(N // p).dimension_new_cusp_forms(k)) diff --git a/src/sage/modular/btquotients/btquotient.py b/src/sage/modular/btquotients/btquotient.py index c7564695c8a..a8445989f48 100644 --- a/src/sage/modular/btquotients/btquotient.py +++ b/src/sage/modular/btquotients/btquotient.py @@ -428,8 +428,8 @@ def __init__(self, p): sage: T = BruhatTitsTree(17) sage: TestSuite(T).run() """ - if not(ZZ(p).is_prime()): - raise ValueError('Input (%s) must be prime' % p) + if not ZZ(p).is_prime(): + raise ValueError(f'input ({p}) must be prime') self._p = ZZ(p) self._Mat_22 = MatrixSpace(ZZ, 2, 2) self._mat_p001 = self._Mat_22([self._p, 0, 0, 1]) @@ -2283,7 +2283,7 @@ def _local_splitting(self, prec): self._II = M([0, a, 1, 0]) z = 0 self._JJ = 0 - while(self._JJ == 0): + while self._JJ == 0: c = a * z * z + b if c.is_square(): x = c.sqrt() diff --git a/src/sage/modular/hypergeometric_motive.py b/src/sage/modular/hypergeometric_motive.py index ad34fb3c92b..0db87ac9f66 100644 --- a/src/sage/modular/hypergeometric_motive.py +++ b/src/sage/modular/hypergeometric_motive.py @@ -688,11 +688,10 @@ def zigzag(self, x, flip_beta=False): alpha = self._alpha beta = self._beta if flip_beta: - return(sum(1 for a in alpha if a <= x) - - sum(1 for b in beta if 1 - b <= x)) - else: - return(sum(1 for a in alpha if a <= x) - - sum(1 for b in beta if b <= x)) + return (sum(1 for a in alpha if a <= x) - + sum(1 for b in beta if 1 - b <= x)) + return (sum(1 for a in alpha if a <= x) - + sum(1 for b in beta if b <= x)) def weight(self): """ diff --git a/src/sage/modular/modform/l_series_gross_zagier.py b/src/sage/modular/modform/l_series_gross_zagier.py index 1f3401c8506..28acdeeb978 100644 --- a/src/sage/modular/modform/l_series_gross_zagier.py +++ b/src/sage/modular/modform/l_series_gross_zagier.py @@ -48,7 +48,7 @@ def __init__(self, E, A, prec=53): ideal = A.ideal() K = A.gens()[0].parent() D = K.disc() - if not(K.degree() == 2 and D < 0): + if not (K.degree() == 2 and D < 0): raise ValueError("A is not an ideal class in an" " imaginary quadratic field") Q = ideal.quadratic_form().reduced_form() diff --git a/src/sage/modular/modform_hecketriangle/abstract_space.py b/src/sage/modular/modform_hecketriangle/abstract_space.py index 6c6bb8e32aa..11ed594308e 100644 --- a/src/sage/modular/modform_hecketriangle/abstract_space.py +++ b/src/sage/modular/modform_hecketriangle/abstract_space.py @@ -571,14 +571,13 @@ def element_from_coordinates(self, vec): sage: el.parent() == subspace True """ - if not self.module(): - raise ValueError("No free module defined for {}".format(self)) + raise ValueError(f"no free module defined for {self}") basis = self.gens() - assert(len(basis) == len(vec)) + assert len(basis) == len(vec) # vec = self.module()(self.module().linear_combination_of_basis(vec)) # this also handles the trivial case (dimension 0) - return self(sum([vec[k]*basis[k] for k in range(0, len(vec))])) + return self(sum([vec[k] * basis[k] for k in range(len(vec))])) def element_from_ambient_coordinates(self, vec): r""" diff --git a/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py b/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py index 8f4d3a25d47..af1c6c89a3a 100644 --- a/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py +++ b/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py @@ -615,9 +615,9 @@ def continued_fraction(self): cf_index = ZZ.zero() one = ZZ.one() - while(p not in cf_dict): + while p not in cf_dict: cf_dict[p] = cf_index - if (p == infinity): + if p == infinity: # TODO: The choice of r doesn't matter? r = ZZ.zero() #elif self.is_elliptic(): @@ -819,7 +819,7 @@ def _primitive_block_decomposition_data(self): number_of_ones.append(ones) initial_ones = number_of_ones.pop(0) - if len(list_larger) == 0: + if not list_larger: list_v1 = [-ZZ(1)] list_vlarger = [ initial_ones + 2 ] else: @@ -835,7 +835,7 @@ def _primitive_block_decomposition_data(self): L_len = len(L) k = 0 - while(k < L_len - 1): + while k < L_len - 1: if L[k][0] == L[k+1][0]: k_entry = L.pop(k+1) L[k][1] += k_entry[1] diff --git a/src/sage/modular/modsym/tests.py b/src/sage/modular/modsym/tests.py index cb9e19cc8b1..c50bdeddb2c 100644 --- a/src/sage/modular/modsym/tests.py +++ b/src/sage/modular/modsym/tests.py @@ -67,9 +67,9 @@ def __init__(self, levels=20, weights=4, onlyg0=False, onlyg1=False, weights = list(range(2, int(weights) + 1)) self.levels = levels self.weights = weights - if not(levels): + if not levels: raise RuntimeError("levels must have positive length") - if not(weights): + if not weights: raise RuntimeError("weights must have positive length") self.current_space = None self.onlyg0 = onlyg0 @@ -78,7 +78,7 @@ def __init__(self, levels=20, weights=4, onlyg0=False, onlyg1=False, def __repr__(self): """ - Return the string representation of self. + Return the string representation of ``self``. EXAMPLES:: diff --git a/src/sage/modular/overconvergent/genus0.py b/src/sage/modular/overconvergent/genus0.py index 09f39d33785..255e4dd09f3 100644 --- a/src/sage/modular/overconvergent/genus0.py +++ b/src/sage/modular/overconvergent/genus0.py @@ -943,8 +943,8 @@ def _convert_to_basis(self, qexp): g = self._gsr.gen() answer = self._gsr(0) for i in range(n): - assert(x.valuation() >= i) - answer += (x[i] / self._basis_cache[i][i])*g**i + assert x.valuation() >= i + answer += (x[i] / self._basis_cache[i][i]) * g**i x = x - self._basis_cache[i] * answer[i] return answer + O(g**n) diff --git a/src/sage/modular/pollack_stevens/modsym.py b/src/sage/modular/pollack_stevens/modsym.py index 7881476e311..a9ff459a590 100644 --- a/src/sage/modular/pollack_stevens/modsym.py +++ b/src/sage/modular/pollack_stevens/modsym.py @@ -830,8 +830,8 @@ def _consistency_check(self): # fundamental domain t = self.parent().coefficient_module().zero() for g in MR.gens()[1:]: - if not(g in MR.reps_with_two_torsion() - or g in MR.reps_with_three_torsion()): + if not (g in MR.reps_with_two_torsion() + or g in MR.reps_with_three_torsion()): t += f[g] * MR.gammas[g] - f[g] else: if g in MR.reps_with_two_torsion(): @@ -843,7 +843,7 @@ def _consistency_check(self): if f[id] * MR.gammas[id] - f[id] != -t: print(t) print(f[id] * MR.gammas[id] - f[id]) - raise ValueError("Does not add up correctly around loop") + raise ValueError("does not add up correctly around loop") print("This modular symbol satisfies the Manin relations") diff --git a/src/sage/modular/quatalg/brandt.py b/src/sage/modular/quatalg/brandt.py index 9bbe2865b47..887742dd791 100644 --- a/src/sage/modular/quatalg/brandt.py +++ b/src/sage/modular/quatalg/brandt.py @@ -876,7 +876,7 @@ def cyclic_submodules(self, I, p): """ if not Integer(p).is_prime(): raise ValueError("p must be a prime") - if not(self.level() % p): + if not self.level() % p: raise ValueError("p must be coprime to the level") R = self.order_of_level_N() @@ -922,7 +922,7 @@ def cyclic_submodules(self, I, p): v = [A(1), alpha, beta, alpha * beta] M = rational_matrix_from_rational_quaternions(v) e = M.determinant() - if e and not((d / e).valuation(p)): + if e and not (d / e).valuation(p): S = A.quaternion_order(v) break if S is not None: @@ -1177,7 +1177,7 @@ def _compute_hecke_matrix_directly(self, n, B=None, sparse=False): for r in range(len(C)): percent_done = 100 * r // len(C) if percent_done != last_percent: - if not(percent_done % 5): + if not percent_done % 5: verbose("percent done: %s" % percent_done) last_percent = percent_done if use_fast_alg: @@ -1296,7 +1296,7 @@ def _smallest_good_prime(self): """ level = self.level() p = ZZ(2) - while not(level % p): + while not level % p: p = next_prime(p) return p @@ -1555,7 +1555,7 @@ def eisenstein_subspace(self): p = Integer(2) N = self.level() while V.dimension() >= 2: - while not(N % p): + while not N % p: p = p.next_prime() A = V.T(p) - (p + 1) V = A.kernel() diff --git a/src/sage/modular/ssmod/ssmod.py b/src/sage/modular/ssmod/ssmod.py index 089089995b8..78fe82dc1f1 100644 --- a/src/sage/modular/ssmod/ssmod.py +++ b/src/sage/modular/ssmod/ssmod.py @@ -233,8 +233,8 @@ def dimension_supersingular_module(prime, level=1): - Iftikhar Burhanuddin - burhanud@usc.edu """ - if not(Integer(prime).is_prime()): - raise ValueError("%s is not a prime" % prime) + if not Integer(prime).is_prime(): + raise ValueError(f"{prime} is not a prime") if level == 1: return Gamma0(prime).dimension_modular_forms(2) @@ -243,8 +243,7 @@ def dimension_supersingular_module(prime, level=1): # elif (level in [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 16, 18, 25]): # compute basis - else: - raise NotImplementedError + raise NotImplementedError def supersingular_D(prime): @@ -331,12 +330,12 @@ def supersingular_j(FF): - Iftikhar Burhanuddin -- burhanud@usc.edu """ - if not(FF.is_field()) or not(FF.is_finite()): + if not FF.is_field() or not FF.is_finite(): raise ValueError("%s is not a finite field" % FF) prime = FF.characteristic() - if not(Integer(prime).is_prime()): + if not Integer(prime).is_prime(): raise ValueError("%s is not a prime" % prime) - if not(Integer(FF.cardinality())) == Integer(prime**2): + if FF.cardinality() != Integer(prime**2): raise ValueError("%s is not a quadratic extension" % FF) if kronecker(-1, prime) != 1: j_invss = 1728 # (2^2 * 3)^3 diff --git a/src/sage/modules/free_module_homspace.py b/src/sage/modules/free_module_homspace.py index 4d99c5f4223..f019bee9ba8 100644 --- a/src/sage/modules/free_module_homspace.py +++ b/src/sage/modules/free_module_homspace.py @@ -215,7 +215,7 @@ def __call__(self, A, **kwds): # Let us hope that FreeModuleMorphism knows to handle # that case pass - if not(self.codomain().base_ring().has_coerce_map_from(self.domain().base_ring())) and not(A.is_zero()): + if not self.codomain().base_ring().has_coerce_map_from(self.domain().base_ring()) and not A.is_zero(): raise TypeError("nontrivial morphisms require a coercion map from the base ring of the domain to the base ring of the codomain") return free_module_morphism.FreeModuleMorphism(self, A, side) diff --git a/src/sage/modules/free_module_integer.py b/src/sage/modules/free_module_integer.py index ddd8a25c92a..f32b0c5e1dd 100644 --- a/src/sage/modules/free_module_integer.py +++ b/src/sage/modules/free_module_integer.py @@ -622,7 +622,7 @@ def update_reduced_basis(self, w): """ w = matrix(ZZ, w) L = w.stack(self.reduced_basis).LLL() - assert(L[0] == 0) + assert L[0] == 0 self._reduced_basis = L.matrix_from_rows(range(1, L.nrows())) @cached_method diff --git a/src/sage/modules/with_basis/morphism.py b/src/sage/modules/with_basis/morphism.py index 0a38d7903d0..9f51c7f2e7b 100644 --- a/src/sage/modules/with_basis/morphism.py +++ b/src/sage/modules/with_basis/morphism.py @@ -396,9 +396,9 @@ def __call__(self, *args): Add more tests for multi-parameter module morphisms. """ before = args[0:self._position] - after = args[self._position+1:len(args)] + after = args[self._position + 1:len(args)] x = args[self._position] - assert(x.parent() is self.domain()) + assert x.parent() is self.domain() mc = x.monomial_coefficients(copy=False) if self._is_module_with_basis_over_same_base_ring: diff --git a/src/sage/monoids/automatic_semigroup.py b/src/sage/monoids/automatic_semigroup.py index dd1a17bd575..2604f0f2533 100644 --- a/src/sage/monoids/automatic_semigroup.py +++ b/src/sage/monoids/automatic_semigroup.py @@ -557,7 +557,7 @@ def lift(self, x): sage: [m.lift() for m in M] [1, 3, 5, 9, 0, 10, 12, 6] """ - assert(x in self) + assert x in self return x.lift() def semigroup_generators(self): @@ -744,14 +744,14 @@ def product(self, x, y): sage: a*b [1] """ - assert(x in self) - assert(y in self) + assert x in self + assert y in self red = y._reduced_word if red is None: return self._retract(self._mul(x.lift(), y.lift())) - else: - for i in red: - x = x.transition(i) + + for i in red: + x = x.transition(i) return x def from_reduced_word(self, l): @@ -942,7 +942,7 @@ def transition(self, i): [1, 2] """ parent = self.parent() - assert(i in parent._generators.keys()) + assert i in parent._generators.keys() return parent._retract(parent._mul(self.lift(), parent._generators_in_ambient[i])) def _repr_(self): diff --git a/src/sage/plot/plot3d/shapes2.py b/src/sage/plot/plot3d/shapes2.py index e771763955e..ae879508511 100644 --- a/src/sage/plot/plot3d/shapes2.py +++ b/src/sage/plot/plot3d/shapes2.py @@ -1255,7 +1255,7 @@ def corners(self, corner_cutoff=None, max_len=None): elif corner_cutoff <= -1: # no corners - if not(max_len is None): + if max_len is not None: # forced by the maximal number of consecutive smooth points return self.points[:-1][::max_len - 1] else: diff --git a/src/sage/quadratic_forms/quadratic_form__mass__Conway_Sloane_masses.py b/src/sage/quadratic_forms/quadratic_form__mass__Conway_Sloane_masses.py index 22e70881009..08543c49629 100644 --- a/src/sage/quadratic_forms/quadratic_form__mass__Conway_Sloane_masses.py +++ b/src/sage/quadratic_forms/quadratic_form__mass__Conway_Sloane_masses.py @@ -353,24 +353,24 @@ def conway_octane_of_this_unimodular_Jordan_block_at_2(self): # Diagonalize the 2x2 block else: - B = self[ind, ind+1] - if (B % 2 != 0): + B = self[ind, ind + 1] + if B % 2: raise RuntimeError("we expected the mixed term to be even") a = self[ind, ind] - b = ZZ(B / ZZ(2)) - c = self[ind+1, ind+1] + b = B // ZZ(2) + c = self[ind + 1, ind + 1] tmp_disc = b * b - a * c # Perform the diagonalization - if (tmp_disc % 8 == 1): # 2xy + if tmp_disc % 8 == 1: # 2xy tmp_diag_vec[ind] = 1 - tmp_diag_vec[ind+1] = -1 + tmp_diag_vec[ind + 1] = -1 ind += 2 - elif(tmp_disc % 8 == 5): # 2x^2 + 2xy + 2y^2 - tmp_diag_vec[0] = 3*u + elif tmp_disc % 8 == 5: # 2x^2 + 2xy + 2y^2 + tmp_diag_vec[0] = 3 * u tmp_diag_vec[ind] = -u - tmp_diag_vec[ind+1] = -u + tmp_diag_vec[ind + 1] = -u ind += 2 u = tmp_diag_vec[0] else: diff --git a/src/sage/sat/boolean_polynomials.py b/src/sage/sat/boolean_polynomials.py index 0d4abb66d93..2f3e650d70b 100644 --- a/src/sage/sat/boolean_polynomials.py +++ b/src/sage/sat/boolean_polynomials.py @@ -219,7 +219,7 @@ def solve(F, converter=None, solver=None, n=1, target_variables=None, **kwds): instead of classes is discouraged because these objects are stateful. """ - assert(n>0) + assert n > 0 try: len(F) @@ -234,7 +234,7 @@ def solve(F, converter=None, solver=None, n=1, target_variables=None, **kwds): target_variables = PolynomialSequence(F).variables() else: target_variables = PolynomialSequence(target_variables).variables() - assert(set(target_variables).issubset(set(P.gens()))) + assert set(target_variables).issubset(set(P.gens())) # instantiate the SAT solver diff --git a/src/sage/sets/disjoint_union_enumerated_sets.py b/src/sage/sets/disjoint_union_enumerated_sets.py index 8e272984619..19459d04e9d 100644 --- a/src/sage/sets/disjoint_union_enumerated_sets.py +++ b/src/sage/sets/disjoint_union_enumerated_sets.py @@ -258,8 +258,8 @@ def __classcall_private__(cls, fam, facade=True, """ # facade = options.pop('facade', True); # keepkey = options.pop('keepkey', False); - assert(isinstance(facade, bool)) - assert(isinstance(keepkey, bool)) + assert isinstance(facade, bool) + assert isinstance(keepkey, bool) return super().__classcall__( cls, Family(fam), facade=facade, keepkey=keepkey, category=category) diff --git a/src/sage/sets/family.py b/src/sage/sets/family.py index d8401a81055..1eeb1aa0e96 100644 --- a/src/sage/sets/family.py +++ b/src/sage/sets/family.py @@ -377,8 +377,8 @@ def Family(indices, function=None, hidden_keys=[], hidden_function=None, lazy=Fa sage: f[5] 1 """ - assert(isinstance(hidden_keys, list)) - assert(isinstance(lazy, bool)) + assert isinstance(hidden_keys, list) + assert isinstance(lazy, bool) if not hidden_keys: if hidden_function is not None: @@ -488,13 +488,14 @@ def zip(self, f, other, name=None): sage: list(h) ['a1', 'b2', 'd3'] """ - assert(self.keys() == other.keys()) - assert(self.hidden_keys() == other.hidden_keys()) - return Family(self.keys(), lambda i: f(self[i],other[i]), hidden_keys=self.hidden_keys(), name=name) + assert self.keys() == other.keys() + assert self.hidden_keys() == other.hidden_keys() + return Family(self.keys(), lambda i: f(self[i], other[i]), + hidden_keys=self.hidden_keys(), name=name) def map(self, f, name=None): r""" - Returns the family `( f(\mathtt{self}[i]) )_{i \in I}`, where + Return the family `( f(\mathtt{self}[i]) )_{i \in I}`, where `I` is the index set of self. .. TODO:: good name? diff --git a/src/sage/stats/distributions/discrete_gaussian_lattice.py b/src/sage/stats/distributions/discrete_gaussian_lattice.py index 766cb2d4a41..f140d18f4c5 100644 --- a/src/sage/stats/distributions/discrete_gaussian_lattice.py +++ b/src/sage/stats/distributions/discrete_gaussian_lattice.py @@ -95,7 +95,7 @@ def _iter_vectors(n, lower, upper, step=None): raise ValueError("Expected n>0 but got %d <= 0" % n) step = n - assert(step > 0) + assert step > 0 if step == 1: for x in range(lower, upper): v = vector(ZZ, n) @@ -470,7 +470,7 @@ def _call(self): b_ = self._G[i] c_ = c.dot_product(b_) / b_.dot_product(b_) sigma_ = sigma / b_.norm() - assert(sigma_ > 0) + assert sigma_ > 0 z = DiscreteGaussianDistributionIntegerSampler(sigma=sigma_, c=c_, algorithm="uniform+online")() c = c - z * B[i] v = v + z * B[i] diff --git a/src/sage/structure/dynamic_class.py b/src/sage/structure/dynamic_class.py index 0e671f90c1c..cd72c1832a0 100644 --- a/src/sage/structure/dynamic_class.py +++ b/src/sage/structure/dynamic_class.py @@ -322,7 +322,7 @@ class also has a zero ``__dictoffset__``. This means that the name = str(name) except UnicodeEncodeError: pass - assert(isinstance(name, str)) + assert isinstance(name, str) # assert(cls is None or issubtype(type(cls), type) or type(cls) is classobj) if cache is True: return dynamic_class_internal(name, bases, cls, reduction, doccls, prepend_cls_bases) diff --git a/src/sage/tests/benchmark.py b/src/sage/tests/benchmark.py index 8b202e92e59..c85e380c530 100644 --- a/src/sage/tests/benchmark.py +++ b/src/sage/tests/benchmark.py @@ -1848,7 +1848,7 @@ def suite1(): Factorial(2*10**6).run(systems=['sage', 'magma']) Fibonacci(10**6).run() - Fibonacci(2*10^7).run(systems=["sage", "magma", "mathematica"]) + Fibonacci(2*10**7).run(systems=["sage", "magma", "mathematica"]) MatrixKernel(150,QQ).run() @@ -1861,7 +1861,7 @@ def suite1(): PolyFactor(700,GF(19)) PolyFactor(500,GF(49,'a')) - PolyFactor(100,GF(10007^3,'a')) + PolyFactor(100,GF((10007,3),'a')) CharPolyTp(54,4).run() CharPolyTp(389,2).run() diff --git a/src/sage/tests/finite_poset.py b/src/sage/tests/finite_poset.py index 56495b04492..11092c3d966 100644 --- a/src/sage/tests/finite_poset.py +++ b/src/sage/tests/finite_poset.py @@ -537,9 +537,9 @@ def test_finite_poset(P): P_dual = P.dual() selfdual_properties = ['chain', 'bounded', 'connected', 'graded', 'ranked', 'series_parallel', 'slender', 'lattice'] for prop in selfdual_properties: - f = attrcall('is_'+prop) + f = attrcall('is_' + prop) if f(P) != f(P_dual): - raise ValueError("error in self-dual property %s" % prop) + raise ValueError(f"error in self-dual property {prop}") if P.is_graded(): if P.is_bounded(): if P.is_eulerian() != P_dual.is_eulerian(): @@ -547,7 +547,7 @@ def test_finite_poset(P): if P.is_eulerian(): P_ = P.star_product(P) if not P_.is_eulerian(): - raise("error in star product / eulerian") + raise ValueError("error in star product / eulerian") chain1 = P.random_maximal_chain() if len(chain1) != h1: raise ValueError("error in is_graded") diff --git a/src/sage/topology/simplicial_set.py b/src/sage/topology/simplicial_set.py index 07cc22070c0..96a5ad3a193 100644 --- a/src/sage/topology/simplicial_set.py +++ b/src/sage/topology/simplicial_set.py @@ -1859,7 +1859,7 @@ def subsimplicial_set(self, simplices): keep.update([f.nondegenerate() for f in data[underlying]]) else: # x is a vertex - assert(underlying.dimension() == 0) + assert underlying.dimension() == 0 vertices.add(underlying) missing = set(nondegenerate_simplices).difference(keep) for x in missing: @@ -3319,7 +3319,7 @@ def face(sigma, i): for x in simplices: if x not in data: # x had better be a vertex. - assert(x.dimension() == 0) + assert x.dimension() == 0 data[x] = None # Check the simplicial identity d_i d_j = d_{j-1} d_i. From ca1468838a85992f4745226e6dbe37f23718c245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 28 May 2023 17:37:18 +0200 Subject: [PATCH 66/98] cython-lint : removed many unused imports in rings/ --- src/sage/rings/complex_arb.pyx | 14 ++++++-------- src/sage/rings/complex_double.pyx | 3 +-- src/sage/rings/complex_interval.pyx | 7 +++---- src/sage/rings/complex_mpc.pyx | 4 ++-- src/sage/rings/complex_mpfr.pyx | 6 ++---- src/sage/rings/factorint.pyx | 8 +++----- src/sage/rings/finite_rings/element_base.pyx | 1 - src/sage/rings/finite_rings/element_givaro.pyx | 10 +--------- src/sage/rings/finite_rings/element_ntl_gf2e.pyx | 8 -------- src/sage/rings/finite_rings/element_pari_ffelt.pyx | 2 -- src/sage/rings/finite_rings/finite_field_base.pyx | 3 +-- .../rings/finite_rings/hom_finite_field_givaro.pyx | 7 +++---- .../rings/finite_rings/hom_prime_finite_field.pyx | 3 --- src/sage/rings/finite_rings/integer_mod.pyx | 6 ++---- src/sage/rings/finite_rings/residue_field.pyx | 4 +--- src/sage/rings/fraction_field_FpT.pyx | 8 ++------ src/sage/rings/fraction_field_element.pyx | 9 +++------ src/sage/rings/function_field/element.pyx | 2 +- src/sage/rings/function_field/element_polymod.pyx | 9 ++++----- src/sage/rings/function_field/element_rational.pyx | 9 ++++----- src/sage/rings/integer.pyx | 10 +++------- src/sage/rings/integer_ring.pyx | 2 -- src/sage/rings/laurent_series_ring_element.pyx | 11 ++++------- src/sage/rings/morphism.pyx | 2 -- .../rings/number_field/number_field_element.pyx | 5 +---- .../number_field_element_quadratic.pyx | 2 -- .../rings/number_field/number_field_morphisms.pyx | 2 -- src/sage/rings/number_field/totallyreal.pyx | 8 +++----- src/sage/rings/number_field/totallyreal_data.pyx | 2 -- src/sage/rings/power_series_mpoly.pyx | 8 +++----- src/sage/rings/power_series_poly.pyx | 8 +++----- src/sage/rings/power_series_ring_element.pyx | 7 +------ src/sage/rings/puiseux_series_ring_element.pyx | 7 +------ src/sage/rings/rational.pyx | 7 +------ src/sage/rings/real_arb.pyx | 3 +-- src/sage/rings/real_double.pyx | 3 --- src/sage/rings/real_interval_absolute.pyx | 2 +- src/sage/rings/real_mpfi.pyx | 11 ++++------- src/sage/rings/real_mpfr.pyx | 4 ++-- src/sage/rings/ring_extension.pyx | 7 +++---- src/sage/rings/ring_extension_element.pyx | 8 +++----- src/sage/rings/semirings/tropical_semiring.pyx | 8 +++----- src/sage/rings/tate_algebra_element.pyx | 7 +------ src/sage/rings/tate_algebra_ideal.pyx | 4 +--- 44 files changed, 78 insertions(+), 183 deletions(-) diff --git a/src/sage/rings/complex_arb.pyx b/src/sage/rings/complex_arb.pyx index 977a0858f52..3410297f2cb 100644 --- a/src/sage/rings/complex_arb.pyx +++ b/src/sage/rings/complex_arb.pyx @@ -153,7 +153,6 @@ import sage.categories.fields cimport sage.rings.abc cimport sage.rings.rational -from cpython.float cimport PyFloat_AS_DOUBLE from cpython.int cimport PyInt_AS_LONG from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE from cpython.complex cimport PyComplex_FromDoubles @@ -169,13 +168,13 @@ from sage.libs.arb.acb_hypgeom cimport * from sage.libs.arb.acb_elliptic cimport * from sage.libs.arb.acb_modular cimport * from sage.libs.arb.acb_poly cimport * -from sage.libs.arb.arf cimport arf_init, arf_get_d, arf_get_mpfr, arf_set_mpfr, arf_clear, arf_set_mag, arf_set, arf_is_nan -from sage.libs.arb.mag cimport (mag_init, mag_clear, mag_add, mag_set_d, - MAG_BITS, mag_is_inf, mag_is_finite, mag_zero, mag_set_ui_2exp_si, +from sage.libs.arb.arf cimport arf_init, arf_get_d, arf_get_mpfr, arf_clear, arf_set, arf_is_nan +from sage.libs.arb.mag cimport (mag_init, mag_clear, mag_set_d, + MAG_BITS, mag_zero, mag_set_ui_2exp_si, mag_mul_2exp_si) -from sage.libs.flint.fmpz cimport fmpz_t, fmpz_init, fmpz_get_mpz, fmpz_set_mpz, fmpz_clear, fmpz_abs +from sage.libs.flint.fmpz cimport fmpz_t, fmpz_init, fmpz_get_mpz, fmpz_set_mpz, fmpz_clear from sage.libs.flint.fmpq cimport fmpq_t, fmpq_init, fmpq_set_mpq, fmpq_clear -from sage.libs.gmp.mpz cimport mpz_fits_ulong_p, mpz_fits_slong_p, mpz_get_ui, mpz_get_si, mpz_sgn +from sage.libs.gmp.mpz cimport mpz_fits_slong_p, mpz_get_si from sage.libs.gsl.complex cimport gsl_complex_rect from sage.rings.real_double cimport RealDoubleElement from sage.rings.complex_double cimport ComplexDoubleElement @@ -186,13 +185,12 @@ from sage.rings.real_arb import RealBallField from sage.rings.real_mpfi cimport RealIntervalField_class from sage.rings.real_mpfr cimport RealField_class, RealField, RealNumber from sage.rings.ring import Field -from sage.structure.element cimport Element, ModuleElement +from sage.structure.element cimport Element from sage.structure.unique_representation import UniqueRepresentation from sage.arith.long cimport is_small_python_int from sage.misc.lazy_string import lazy_string from sage.misc.superseded import deprecated_function_alias -from sage.rings.complex_mpfr import ComplexField from sage.rings.complex_interval_field import ComplexIntervalField, ComplexIntervalField_class from sage.rings.integer_ring import ZZ diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index b4fec10c68a..4a978027a87 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -68,7 +68,6 @@ AUTHORS: # https://www.gnu.org/licenses/ # **************************************************************************** -import operator from cpython.object cimport Py_NE from sage.misc.randstate cimport randstate, current_randstate @@ -83,7 +82,7 @@ import sage.rings.abc cimport sage.rings.ring cimport sage.rings.integer -from sage.structure.element cimport RingElement, Element, ModuleElement, FieldElement +from sage.structure.element cimport Element, FieldElement from sage.structure.parent cimport Parent from sage.structure.parent_gens import ParentWithGens from sage.structure.richcmp cimport rich_to_bool diff --git a/src/sage/rings/complex_interval.pyx b/src/sage/rings/complex_interval.pyx index 88603696b73..12e32fc2d90 100644 --- a/src/sage/rings/complex_interval.pyx +++ b/src/sage/rings/complex_interval.pyx @@ -64,13 +64,12 @@ from sage.libs.flint.fmpz cimport * from sage.libs.mpfr cimport MPFR_RNDU, MPFR_RNDD from sage.arith.constants cimport LOG_TEN_TWO_PLUS_EPSILON -from sage.structure.element cimport FieldElement, RingElement, Element, ModuleElement +from sage.structure.element cimport FieldElement from sage.structure.parent cimport Parent from .complex_mpfr cimport ComplexNumber -from .complex_mpfr import ComplexField from sage.rings.integer cimport Integer cimport sage.rings.real_mpfi as real_mpfi -from .real_mpfr cimport RealNumber, RealField +from .real_mpfr cimport RealNumber from .convert.mpfi cimport mpfi_set_sage from .infinity import infinity @@ -90,7 +89,7 @@ def is_ComplexIntervalFieldElement(x): return isinstance(x, ComplexIntervalFieldElement) -cdef class ComplexIntervalFieldElement(sage.structure.element.FieldElement): +cdef class ComplexIntervalFieldElement(FieldElement): """ A complex interval. diff --git a/src/sage/rings/complex_mpc.pyx b/src/sage/rings/complex_mpc.pyx index f6287353dac..403808808c5 100644 --- a/src/sage/rings/complex_mpc.pyx +++ b/src/sage/rings/complex_mpc.pyx @@ -69,7 +69,7 @@ from sage.libs.mpfr cimport * from sage.libs.mpc cimport * from sage.structure.parent cimport Parent from sage.structure.parent_gens cimport ParentWithGens -from sage.structure.element cimport RingElement, Element, ModuleElement +from sage.structure.element cimport Element from sage.structure.richcmp cimport rich_to_bool from sage.categories.map cimport Map from sage.libs.pari.all import pari @@ -2578,5 +2578,5 @@ cdef class CCtoMPC(Map): # Support Python's numbers abstract base class -import numbers +# import numbers from sage.rings.complex_mpc import MPComplexNumber diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index cff1b54fb66..beb386832e2 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -30,15 +30,13 @@ AUTHORS: # https://www.gnu.org/licenses/ # **************************************************************************** -import math -import operator import weakref import sage.misc.misc from sage.libs.mpfr cimport * -from sage.structure.element cimport FieldElement, RingElement, Element, ModuleElement +from sage.structure.element cimport RingElement, Element from sage.structure.richcmp cimport rich_to_bool from sage.categories.map cimport Map from sage.structure.parent import Parent @@ -48,7 +46,7 @@ from sage.misc.sage_eval import sage_eval import sage.rings.abc from sage.arith.constants cimport LOG_TEN_TWO_PLUS_EPSILON -from . import ring, infinity +from . import infinity from .integer cimport Integer from .complex_double cimport ComplexDoubleElement diff --git a/src/sage/rings/factorint.pyx b/src/sage/rings/factorint.pyx index 5718d6691ae..fea5b444b00 100644 --- a/src/sage/rings/factorint.pyx +++ b/src/sage/rings/factorint.pyx @@ -8,7 +8,7 @@ AUTHORS: """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2010-2011 André Apitzsch # 2012 Nils Bruin # 2014 David Roe @@ -17,16 +17,14 @@ AUTHORS: # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from sage.ext.stdsage cimport PY_NEW from sage.libs.gmp.mpz cimport * from sage.rings.integer cimport Integer -from sage.rings.fast_arith import prime_range from sage.structure.factorization_integer import IntegerFactorization -from math import floor from sage.misc.misc_c import prod cdef extern from "limits.h": diff --git a/src/sage/rings/finite_rings/element_base.pyx b/src/sage/rings/finite_rings/element_base.pyx index e2f819daabf..db5e5bac5f0 100755 --- a/src/sage/rings/finite_rings/element_base.pyx +++ b/src/sage/rings/finite_rings/element_base.pyx @@ -505,7 +505,6 @@ cdef class FinitePolyExtElement(FiniteRingElement): """ if var is None: var = self.parent().variable_name() - from sage.libs.pari.all import pari ffgen = self._parent.modulus()._pari_with_name(var).ffgen() polypari = self.polynomial()._pari_with_name() # Add ffgen - ffgen to ensure that we really get an FFELT diff --git a/src/sage/rings/finite_rings/element_givaro.pyx b/src/sage/rings/finite_rings/element_givaro.pyx index bdb42614592..61e8e5b99ca 100644 --- a/src/sage/rings/finite_rings/element_givaro.pyx +++ b/src/sage/rings/finite_rings/element_givaro.pyx @@ -56,23 +56,16 @@ from cysignals.signals cimport sig_on, sig_off from cypari2.paridecl cimport * -from sage.misc.randstate cimport randstate, current_randstate -from sage.rings.finite_rings.finite_field_base cimport FiniteField -from sage.rings.ring cimport Ring +from sage.misc.randstate cimport current_randstate from .element_pari_ffelt cimport FiniteFieldElement_pari_ffelt from sage.structure.richcmp cimport richcmp -from sage.structure.element cimport Element, ModuleElement, RingElement -import operator import sage.arith.all -import sage.rings.finite_rings.finite_field_constructor as finite_field -from sage.libs.pari.all import pari from cypari2.gen cimport Gen from cypari2.stack cimport clear_stack from sage.structure.parent cimport Parent - from sage.interfaces.abc import GapElement cdef object is_IntegerMod @@ -1579,7 +1572,6 @@ cdef class FiniteField_givaroElement(FinitePolyExtElement): """ # TODO -- I'm sure this can be made vastly faster # using how elements are represented as a power of the generator ?? - import sage.arith.all if self._multiplicative_order is not None: return self._multiplicative_order diff --git a/src/sage/rings/finite_rings/element_ntl_gf2e.pyx b/src/sage/rings/finite_rings/element_ntl_gf2e.pyx index 16065f47966..f6fa95241dc 100644 --- a/src/sage/rings/finite_rings/element_ntl_gf2e.pyx +++ b/src/sage/rings/finite_rings/element_ntl_gf2e.pyx @@ -34,26 +34,18 @@ from cypari2.paridecl cimport * from sage.structure.richcmp cimport (richcmp, richcmp_not_equal, rich_to_bool) -from sage.structure.element cimport Element, ModuleElement, RingElement from sage.structure.parent cimport Parent -from sage.rings.ring cimport Ring - from sage.rings.finite_rings.finite_field_base cimport FiniteField from sage.libs.pari.all import pari from cypari2.gen cimport Gen from cypari2.stack cimport clear_stack -from sage.misc.randstate import current_randstate -from sage.arith.long cimport pyobject_to_long - from .element_pari_ffelt import FiniteFieldElement_pari_ffelt from .finite_field_ntl_gf2e import FiniteField_ntl_gf2e -from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing - from sage.interfaces.abc import GapElement diff --git a/src/sage/rings/finite_rings/element_pari_ffelt.pyx b/src/sage/rings/finite_rings/element_pari_ffelt.pyx index 74b8ce40c7b..5d16aa857b0 100644 --- a/src/sage/rings/finite_rings/element_pari_ffelt.pyx +++ b/src/sage/rings/finite_rings/element_pari_ffelt.pyx @@ -16,7 +16,6 @@ AUTHORS: # https://www.gnu.org/licenses/ # **************************************************************************** -from cysignals.memory cimport sig_free from cysignals.signals cimport sig_on, sig_off from cypari2.paridecl cimport * @@ -34,7 +33,6 @@ from sage.rings.integer cimport Integer from sage.rings.polynomial.polynomial_element import Polynomial from sage.rings.polynomial.multi_polynomial_element import MPolynomial from sage.rings.rational import Rational -from sage.structure.element cimport Element, ModuleElement, RingElement from sage.structure.richcmp cimport rich_to_bool diff --git a/src/sage/rings/finite_rings/finite_field_base.pyx b/src/sage/rings/finite_rings/finite_field_base.pyx index 3e243cd89e8..4f4d7f64c72 100644 --- a/src/sage/rings/finite_rings/finite_field_base.pyx +++ b/src/sage/rings/finite_rings/finite_field_base.pyx @@ -1283,13 +1283,12 @@ cdef class FiniteField(Field): else: raise ValueError("{} is not a subfield".format(base)) - if map is False: # shortcut + if map is False: # shortcut return V if inclusion_map is None: inclusion_map = self.coerce_map_from(base) - from sage.modules.free_module_element import vector from sage.matrix.constructor import matrix from .maps_finite_field import ( MorphismVectorSpaceToFiniteField, MorphismFiniteFieldToVectorSpace) diff --git a/src/sage/rings/finite_rings/hom_finite_field_givaro.pyx b/src/sage/rings/finite_rings/hom_finite_field_givaro.pyx index ad88a240355..aae6c84ab25 100644 --- a/src/sage/rings/finite_rings/hom_finite_field_givaro.pyx +++ b/src/sage/rings/finite_rings/hom_finite_field_givaro.pyx @@ -22,13 +22,13 @@ AUTHOR: - Xavier Caruso (2012-06-29) """ -############################################################################# +# ########################################################################### # Copyright (C) 2012 Xavier Caruso # # Distributed under the terms of the GNU General Public License (GPL) # -# http://www.gnu.org/licenses/ -#**************************************************************************** +# https://www.gnu.org/licenses/ +# *************************************************************************** from sage.rings.finite_rings.finite_field_constructor import FiniteField @@ -41,7 +41,6 @@ from .hom_prime_finite_field cimport FiniteFieldHomomorphism_prime from sage.categories.homset import Hom from sage.structure.element cimport Element -from sage.rings.morphism cimport RingHomomorphism_im_gens from sage.rings.finite_rings.finite_field_givaro import FiniteField_givaro from .element_givaro cimport FiniteField_givaroElement diff --git a/src/sage/rings/finite_rings/hom_prime_finite_field.pyx b/src/sage/rings/finite_rings/hom_prime_finite_field.pyx index 617595ea383..acf63449e5a 100644 --- a/src/sage/rings/finite_rings/hom_prime_finite_field.pyx +++ b/src/sage/rings/finite_rings/hom_prime_finite_field.pyx @@ -24,8 +24,6 @@ AUTHOR: # http://www.gnu.org/licenses/ #**************************************************************************** -from sage.rings.integer cimport Integer - from sage.categories.homset import Hom from sage.structure.element cimport Element @@ -34,7 +32,6 @@ from .hom_finite_field cimport FiniteFieldHomomorphism_generic from .hom_finite_field cimport FrobeniusEndomorphism_finite_field from sage.rings.finite_rings.finite_field_base import FiniteField -from sage.rings.morphism cimport RingHomomorphism_im_gens cdef class SectionFiniteFieldHomomorphism_prime(SectionFiniteFieldHomomorphism_generic): diff --git a/src/sage/rings/finite_rings/integer_mod.pyx b/src/sage/rings/finite_rings/integer_mod.pyx index 61cc6bc657e..830f1472a5e 100644 --- a/src/sage/rings/finite_rings/integer_mod.pyx +++ b/src/sage/rings/finite_rings/integer_mod.pyx @@ -78,13 +78,11 @@ from libc.math cimport log2, ceil from sage.libs.gmp.all cimport * -import operator - cdef bint use_32bit_type(int_fast64_t modulus): return modulus <= INTEGER_MOD_INT32_LIMIT from sage.arith.long cimport ( - integer_check_long, integer_check_long_py, is_small_python_int, ERR_OVERFLOW) + integer_check_long, integer_check_long_py, is_small_python_int) import sage.rings.rational as rational from sage.libs.pari.all import pari, PariError @@ -100,7 +98,7 @@ from sage.structure.richcmp cimport rich_to_bool_sgn, rich_to_bool import sage.structure.element cimport sage.structure.element coerce_binop = sage.structure.element.coerce_binop -from sage.structure.element cimport RingElement, ModuleElement, Element +from sage.structure.element cimport Element from sage.categories.morphism cimport Morphism from sage.categories.map cimport Map diff --git a/src/sage/rings/finite_rings/residue_field.pyx b/src/sage/rings/finite_rings/residue_field.pyx index 8396e320e6a..8576a4e6045 100644 --- a/src/sage/rings/finite_rings/residue_field.pyx +++ b/src/sage/rings/finite_rings/residue_field.pyx @@ -160,7 +160,7 @@ And now over a large prime field:: # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ # ***************************************************************************** @@ -168,9 +168,7 @@ from sage.rings.ring cimport Field from sage.rings.integer cimport Integer from sage.rings.rational cimport Rational from sage.categories.homset import Hom -from sage.categories.basic import Fields, Rings from sage.categories.pushout import AlgebraicExtensionFunctor -from sage.rings.finite_rings.integer_mod_ring import Integers from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ from sage.rings.finite_rings.finite_field_constructor import zech_log_bound, FiniteField as GF diff --git a/src/sage/rings/fraction_field_FpT.pyx b/src/sage/rings/fraction_field_FpT.pyx index 1224f2de95b..0a25191a11c 100644 --- a/src/sage/rings/fraction_field_FpT.pyx +++ b/src/sage/rings/fraction_field_FpT.pyx @@ -6,23 +6,19 @@ # distutils: language = c++ "Univariate rational functions over prime fields" -import sys - from cysignals.signals cimport sig_on, sig_off from sage.rings.finite_rings.stdint cimport INTEGER_MOD_INT32_LIMIT from sage.libs.gmp.mpz cimport * -from sage.rings.finite_rings.finite_field_constructor import GF from sage.libs.flint.nmod_poly cimport * from sage.libs.flint.ulong_extras cimport n_jacobi -from sage.structure.element cimport Element, ModuleElement, FieldElement +from sage.structure.element cimport Element, FieldElement from sage.rings.integer_ring import ZZ -from sage.rings.fraction_field import FractionField_generic, FractionField_1poly_field +from sage.rings.fraction_field import FractionField_1poly_field from sage.rings.finite_rings.integer_mod cimport IntegerMod_int from sage.rings.integer cimport Integer from sage.rings.polynomial.polynomial_zmod_flint cimport Polynomial_zmod_flint, get_cparent -import sage.algebras.algebra from sage.structure.richcmp cimport rich_to_bool from sage.rings.finite_rings.integer_mod cimport mod_inverse_int diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index ca1dedf1803..11a2b646d35 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -9,22 +9,19 @@ AUTHORS: derivative to use Henrici's algorithms [Hor1972]_ """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2005 William Stein # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from sage.structure.element cimport FieldElement, parent from sage.structure.richcmp cimport richcmp -# from sage.rings.polynomial.flatten import SpecializationMorphism -from . import integer_ring -from .integer_ring import ZZ from .rational_field import QQ import sage.misc.latex as latex diff --git a/src/sage/rings/function_field/element.pyx b/src/sage/rings/function_field/element.pyx index 7ec3d58db82..3aebcbc3f1a 100644 --- a/src/sage/rings/function_field/element.pyx +++ b/src/sage/rings/function_field/element.pyx @@ -65,7 +65,7 @@ AUTHORS: # https://www.gnu.org/licenses/ # **************************************************************************** -from sage.structure.element cimport FieldElement, RingElement, ModuleElement, Element +from sage.structure.element cimport FieldElement from sage.misc.cachefunc import cached_method diff --git a/src/sage/rings/function_field/element_polymod.pyx b/src/sage/rings/function_field/element_polymod.pyx index 2b9fc822ff4..21aa9e36ab3 100644 --- a/src/sage/rings/function_field/element_polymod.pyx +++ b/src/sage/rings/function_field/element_polymod.pyx @@ -3,18 +3,17 @@ r""" Elements of function fields: extension """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2023 Kwankyu Lee # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** -from sage.misc.cachefunc import cached_method from sage.structure.richcmp cimport richcmp -from sage.structure.element cimport FieldElement, RingElement, ModuleElement, Element +from sage.structure.element cimport FieldElement from sage.rings.function_field.element cimport FunctionFieldElement diff --git a/src/sage/rings/function_field/element_rational.pyx b/src/sage/rings/function_field/element_rational.pyx index 7bbb8f809b5..9af91c2b496 100644 --- a/src/sage/rings/function_field/element_rational.pyx +++ b/src/sage/rings/function_field/element_rational.pyx @@ -2,18 +2,17 @@ r""" Elements of function fields: rational """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2023 Kwankyu Lee # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** -from sage.misc.cachefunc import cached_method from sage.structure.richcmp cimport richcmp, richcmp_not_equal -from sage.structure.element cimport FieldElement, RingElement, ModuleElement, Element +from sage.structure.element cimport FieldElement from sage.rings.function_field.element cimport FunctionFieldElement diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 4c0ee165cee..de03c340c04 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -143,8 +143,7 @@ AUTHORS: # creation and deletion are setup by the call to hook_fast_tp_functions cimport cython -from libc.math cimport (ldexp, sqrt as sqrt_double, log as log_c, - ceil as ceil_c, isnan) +from libc.math cimport (ldexp, sqrt as sqrt_double, isnan) from libc.string cimport memcpy from libc.limits cimport LONG_MAX @@ -152,7 +151,6 @@ from cysignals.memory cimport check_allocarray, check_malloc, sig_free from cysignals.signals cimport sig_on, sig_off, sig_check, sig_occurred import operator -import sys from sage.ext.stdsage cimport PY_NEW from sage.cpython.python_debug cimport if_Py_TRACE_REFS_then_PyObject_INIT @@ -160,7 +158,7 @@ from sage.cpython.python_debug cimport if_Py_TRACE_REFS_then_PyObject_INIT from sage.libs.gmp.mpz cimport * from sage.libs.gmp.mpq cimport * from sage.cpython.string cimport char_to_str, str_to_bytes -from sage.arith.long cimport (pyobject_to_long, integer_check_long, +from sage.arith.long cimport (integer_check_long, integer_check_long_py, is_small_python_int) from cpython.list cimport * @@ -170,13 +168,11 @@ from cpython.object cimport * from libc.stdint cimport uint64_t cimport sage.structure.element from sage.structure.coerce cimport coercion_model -from sage.structure.element cimport (Element, EuclideanDomainElement, - parent) +from sage.structure.element cimport (Element, parent) from sage.structure.parent cimport Parent from sage.rings.rational cimport Rational from sage.arith.rational_reconstruction cimport mpq_rational_reconstruction from sage.libs.gmp.pylong cimport * -from sage.libs.gmp.mpq cimport mpq_neg from sage.libs.gmp.binop cimport mpq_add_z, mpq_mul_z, mpq_div_zz import sage.rings.infinity diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index 9c89f6d8bb0..ba270deb935 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -63,13 +63,11 @@ from sage.structure.coerce cimport is_numpy_type from sage.structure.element cimport parent from sage.structure.parent_gens import ParentWithGens from sage.structure.richcmp cimport rich_to_bool -from sage.structure.sequence import Sequence from sage.misc.misc_c import prod from sage.misc.randstate cimport randstate, current_randstate, SAGE_RAND_MAX cimport sage.rings.integer as integer -cimport sage.rings.rational as rational from . import ring diff --git a/src/sage/rings/laurent_series_ring_element.pyx b/src/sage/rings/laurent_series_ring_element.pyx index 8d98c35ddbb..cbc72d22373 100644 --- a/src/sage/rings/laurent_series_ring_element.pyx +++ b/src/sage/rings/laurent_series_ring_element.pyx @@ -51,7 +51,7 @@ AUTHORS: - Robert Bradshaw: Cython version """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2005 William Stein # 2017 Vincent Delecroix <20100.delecroix@gmail.com> # @@ -64,19 +64,16 @@ AUTHORS: # # The full text of the GPL is available at: # -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from .infinity import infinity -from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ -import sage.rings.polynomial.polynomial_element as polynomial import sage.misc.latex -from sage.rings.integer import Integer from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial_univariate from .power_series_ring_element cimport PowerSeries -from sage.structure.element cimport Element, ModuleElement, RingElement, AlgebraElement +from sage.structure.element cimport Element, AlgebraElement from sage.structure.richcmp cimport richcmp_not_equal, rich_to_bool from sage.misc.derivative import multi_derivative diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index 34224b8b705..ba341f7f93a 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -397,8 +397,6 @@ compare equal:: # https://www.gnu.org/licenses/ # **************************************************************************** -from cpython.object cimport Py_EQ, Py_NE - from . import ideal import sage.structure.all from sage.structure.richcmp cimport (richcmp, rich_to_bool) diff --git a/src/sage/rings/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index e249bab8fa1..69e08907c51 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -45,7 +45,7 @@ include "sage/libs/ntl/decl.pxi" from sage.libs.gmp.mpz cimport * from sage.libs.gmp.mpq cimport * -from sage.libs.mpfi cimport mpfi_t, mpfi_init, mpfi_set, mpfi_clear, mpfi_div_z, mpfi_init2, mpfi_get_prec, mpfi_set_prec +from sage.libs.mpfi cimport mpfi_t, mpfi_clear, mpfi_div_z, mpfi_init2, mpfi_get_prec, mpfi_set_prec from sage.libs.mpfr cimport mpfr_equal_p, mpfr_less_p, mpfr_greater_p, mpfr_greaterequal_p, mpfr_floor, mpfr_get_z, MPFR_RNDN from sage.libs.ntl.error import NTLError from sage.libs.ntl.convert cimport mpz_to_ZZ @@ -67,12 +67,10 @@ from sage.rings.real_mpfi cimport RealIntervalFieldElement cimport sage.rings.number_field.number_field_base as number_field_base -from sage.rings.integer_ring cimport IntegerRing_class from sage.rings.rational cimport Rational from sage.rings.infinity import infinity from sage.categories.fields import Fields from sage.misc.superseded import deprecation -from sage.modules.free_module_element import vector from sage.structure.element cimport Element, FieldElement from sage.structure.element cimport parent @@ -2997,7 +2995,6 @@ cdef class NumberFieldElement(NumberFieldElement_base): from sage.functions.log import exp from sage.rings.complex_mpfr import ComplexField from sage.rings.imaginary_unit import I - from sage.rings.real_mpfr import RR from sage.symbolic.constants import pi CC = ComplexField(53) two_pi_i = 2 * pi * I diff --git a/src/sage/rings/number_field/number_field_element_quadratic.pyx b/src/sage/rings/number_field/number_field_element_quadratic.pyx index 062e15b238d..2d4f9b34e55 100644 --- a/src/sage/rings/number_field/number_field_element_quadratic.pyx +++ b/src/sage/rings/number_field/number_field_element_quadratic.pyx @@ -56,8 +56,6 @@ from sage.structure.richcmp cimport rich_to_bool_sgn from sage.rings.rational cimport Rational from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ -from sage.rings.real_double import RDF -from sage.rings.complex_double import CDF from sage.categories.morphism cimport Morphism from sage.rings.number_field.number_field_element import _inverse_mod_generic from sage.rings.real_mpfi cimport RealIntervalField_class diff --git a/src/sage/rings/number_field/number_field_morphisms.pyx b/src/sage/rings/number_field/number_field_morphisms.pyx index 2838370c327..d349e6c981a 100644 --- a/src/sage/rings/number_field/number_field_morphisms.pyx +++ b/src/sage/rings/number_field/number_field_morphisms.pyx @@ -26,8 +26,6 @@ from sage.categories.morphism cimport Morphism from sage.categories.map cimport Map from sage.categories.pushout import pushout -from sage.rings.real_mpfr import RealField, mpfr_prec_min -from sage.rings.complex_mpfr import ComplexField from sage.rings.real_lazy import RLF, CLF, LazyField, LazyAlgebraic diff --git a/src/sage/rings/number_field/totallyreal.pyx b/src/sage/rings/number_field/totallyreal.pyx index ecd563fb3cf..6706efc6233 100644 --- a/src/sage/rings/number_field/totallyreal.pyx +++ b/src/sage/rings/number_field/totallyreal.pyx @@ -82,15 +82,15 @@ Authors ------ """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2007 William Stein and John Voight # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from cysignals.memory cimport check_calloc, sig_free @@ -105,10 +105,8 @@ from sage.libs.pari.misc cimport new_t_POL_from_int_star from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.integer import Integer from sage.rings.integer cimport Integer -from sage.rings.integer_ring import IntegerRing from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ -from sage.misc.misc import cputime from sage.rings.number_field.totallyreal_data import tr_data, int_has_small_square_divisor from sage.rings.number_field.totallyreal_data cimport tr_data diff --git a/src/sage/rings/number_field/totallyreal_data.pyx b/src/sage/rings/number_field/totallyreal_data.pyx index c0d865db02c..1eaeeae8343 100644 --- a/src/sage/rings/number_field/totallyreal_data.pyx +++ b/src/sage/rings/number_field/totallyreal_data.pyx @@ -30,9 +30,7 @@ from cysignals.memory cimport sig_malloc, sig_free from sage.arith.misc import binomial from sage.arith.misc import GCD as gcd from sage.libs.gmp.mpz cimport * -from sage.rings.rational_field import RationalField from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing -from sage.rings.real_mpfi import RealIntervalField from sage.rings.real_mpfr import RealField from sage.rings.integer_ring import ZZ from sage.rings.integer cimport Integer diff --git a/src/sage/rings/power_series_mpoly.pyx b/src/sage/rings/power_series_mpoly.pyx index 475546cd6be..0c901a3557b 100644 --- a/src/sage/rings/power_series_mpoly.pyx +++ b/src/sage/rings/power_series_mpoly.pyx @@ -1,14 +1,12 @@ # NOT ready to be used -- possibly should be deleted. from .power_series_ring_element cimport PowerSeries -from sage.structure.element cimport Element, ModuleElement, RingElement -from .infinity import infinity, is_Infinite -from sage.libs.pari.all import PariError -from .power_series_ring_element import is_PowerSeries -from . import rational_field +from sage.structure.element cimport Element +from .infinity import infinity from .polynomial.multi_polynomial_ring_base import is_MPolynomialRing from . import power_series_poly + cdef class PowerSeries_mpoly(PowerSeries): def __init__(self, parent, f=0, prec=infinity, int check=1, is_gen=0): diff --git a/src/sage/rings/power_series_poly.pyx b/src/sage/rings/power_series_poly.pyx index 6b7dcce74ab..4cf4d8307ac 100644 --- a/src/sage/rings/power_series_poly.pyx +++ b/src/sage/rings/power_series_poly.pyx @@ -5,8 +5,8 @@ Power Series Methods The class ``PowerSeries_poly`` provides additional methods for univariate power series. """ from .power_series_ring_element cimport PowerSeries -from sage.structure.element cimport Element, ModuleElement, RingElement -from .infinity import infinity, is_Infinite +from sage.structure.element cimport Element +from .infinity import infinity from sage.libs.pari.all import pari_gen, PariError @@ -1221,9 +1221,7 @@ cdef class PowerSeries_poly(PowerSeries): Order(x^20) """ from sage.symbolic.ring import SR - from sage.rings.infinity import PlusInfinity - poly = self.polynomial() - pex = SR(poly) + pex = SR(self.polynomial()) var = SR.var(self.variable()) return pex.series(var, self.prec()) diff --git a/src/sage/rings/power_series_ring_element.pyx b/src/sage/rings/power_series_ring_element.pyx index 1e166618e9d..6382704764d 100644 --- a/src/sage/rings/power_series_ring_element.pyx +++ b/src/sage/rings/power_series_ring_element.pyx @@ -95,8 +95,6 @@ With power series the behavior is the same. # https://www.gnu.org/licenses/ # **************************************************************************** -import operator - from cpython.object cimport Py_EQ, Py_NE from .infinity import infinity, is_Infinite @@ -107,11 +105,8 @@ import sage.rings.polynomial.polynomial_element import sage.misc.misc import sage.arith.all as arith import sage.misc.latex -from . import rational_field -from . import integer_ring from .integer import Integer from sage.rings.finite_rings.integer_mod_ring import IntegerModRing -from warnings import warn from sage.categories.fields import Fields _Fields = Fields() @@ -120,7 +115,7 @@ from sage.misc.derivative import multi_derivative Polynomial = sage.rings.polynomial.polynomial_element.Polynomial_generic_dense -from sage.structure.element cimport AlgebraElement, RingElement, ModuleElement, Element +from sage.structure.element cimport AlgebraElement, RingElement from sage.structure.richcmp cimport richcmp diff --git a/src/sage/rings/puiseux_series_ring_element.pyx b/src/sage/rings/puiseux_series_ring_element.pyx index 7fe08d1b46d..9543ce5a24a 100644 --- a/src/sage/rings/puiseux_series_ring_element.pyx +++ b/src/sage/rings/puiseux_series_ring_element.pyx @@ -104,17 +104,12 @@ REFERENCES: from sage.arith.functions import lcm from sage.arith.misc import gcd -from sage.ext.fast_callable import fast_callable -from sage.rings.big_oh import O from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ from sage.rings.complex_mpfr import ComplexField from sage.rings.infinity import infinity from sage.rings.laurent_series_ring_element cimport LaurentSeries -from sage.rings.laurent_series_ring import LaurentSeriesRing -from sage.rings.power_series_ring_element cimport PowerSeries -from sage.structure.element cimport (Element, ModuleElement, - RingElement, AlgebraElement) +from sage.structure.element cimport (Element, AlgebraElement) from sage.structure.richcmp cimport richcmp diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index 8f5c9df7593..1b3e4db5563 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -65,11 +65,9 @@ from cysignals.signals cimport sig_on, sig_off import operator import fractions -from sage.arith.long cimport pyobject_to_long, integer_check_long_py +from sage.arith.long cimport integer_check_long_py from sage.cpython.string cimport char_to_str, str_to_bytes -import sage.misc.misc as misc -from sage.structure.sage_object cimport SageObject from sage.structure.richcmp cimport rich_to_bool_sgn import sage.rings.rational_field @@ -77,7 +75,6 @@ cimport sage.rings.integer as integer from .integer cimport Integer from .integer_ring import ZZ -from sage.arith.rational_reconstruction cimport mpq_rational_reconstruction from sage.structure.coerce cimport is_numpy_type @@ -85,13 +82,11 @@ from sage.libs.gmp.pylong cimport mpz_set_pylong from sage.structure.coerce cimport coercion_model from sage.structure.element cimport Element -from sage.structure.element import coerce_binop from sage.structure.parent cimport Parent from sage.categories.morphism cimport Morphism from sage.categories.map cimport Map - import sage.rings.real_mpfr import sage.rings.real_double from libc.stdint cimport uint64_t diff --git a/src/sage/rings/real_arb.pyx b/src/sage/rings/real_arb.pyx index 383376cd1ff..86f24e7cb20 100644 --- a/src/sage/rings/real_arb.pyx +++ b/src/sage/rings/real_arb.pyx @@ -217,12 +217,11 @@ from sage.libs.mpfi cimport * from sage.libs.mpfr cimport * from sage.libs.mpfr cimport MPFR_RNDN, MPFR_RNDU, MPFR_RNDD, MPFR_RNDZ -from sage.structure.element cimport Element, ModuleElement, RingElement +from sage.structure.element cimport Element, RingElement from sage.rings.ring cimport Field import sage.rings.abc from sage.rings.integer cimport Integer from sage.rings.rational cimport Rational -from sage.rings.real_double cimport RealDoubleElement from sage.rings.real_mpfr cimport RealField_class, RealField, RealNumber from sage.arith.long cimport is_small_python_int diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index dcaf1108e8c..3b0f31de78b 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -45,13 +45,10 @@ from libc.string cimport memcpy from cpython.object cimport * from cpython.float cimport * -from cysignals.signals cimport sig_on, sig_off - from sage.ext.stdsage cimport PY_NEW from sage.cpython.python_debug cimport if_Py_TRACE_REFS_then_PyObject_INIT import math -import operator import sage.rings.integer import sage.rings.rational diff --git a/src/sage/rings/real_interval_absolute.pyx b/src/sage/rings/real_interval_absolute.pyx index fb505b5205b..3d0dabaaa5f 100644 --- a/src/sage/rings/real_interval_absolute.pyx +++ b/src/sage/rings/real_interval_absolute.pyx @@ -7,7 +7,7 @@ from sage.ext.stdsage cimport PY_NEW from sage.libs.gmp.mpz cimport * from sage.structure.factory import UniqueFactory -from sage.structure.element cimport RingElement, ModuleElement, Element, FieldElement +from sage.structure.element cimport Element, FieldElement from sage.rings.ring cimport Field from sage.rings.integer cimport Integer import sage.rings.abc diff --git a/src/sage/rings/real_mpfi.pyx b/src/sage/rings/real_mpfi.pyx index 1904bbff3e7..1193a14baff 100644 --- a/src/sage/rings/real_mpfi.pyx +++ b/src/sage/rings/real_mpfi.pyx @@ -264,7 +264,7 @@ from sage.libs.mpfi cimport * from sage.arith.constants cimport LOG_TEN_TWO_PLUS_EPSILON cimport sage.structure.element -from sage.structure.element cimport RingElement, Element, ModuleElement +from sage.structure.element cimport RingElement, Element from sage.structure.element cimport have_same_parent from sage.structure.parent cimport Parent from sage.structure.richcmp cimport richcmp @@ -272,14 +272,10 @@ from sage.structure.richcmp cimport richcmp from .convert.mpfi cimport mpfi_set_sage from .real_mpfr cimport RealField_class, RealNumber, RealField from .integer cimport Integer -from .real_double cimport RealDoubleElement -from .real_double import RDF from .integer_ring import ZZ from .rational_field import QQ -from sage.categories.morphism cimport Map cimport sage.rings.abc -cimport sage.rings.real_mpfr as real_mpfr import math # for log import sys @@ -2935,8 +2931,9 @@ cdef class RealIntervalFieldElement(RingElement): def __rshift__(x, y): """ - Returns `x / 2^y`, for `y` an integer. Much faster - than an ordinary division. + Return `x / 2^y`, for `y` an integer. + + Much faster than an ordinary division. EXAMPLES:: diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index 61569a41ff2..e2f1b91e3fb 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -132,9 +132,9 @@ from sage.misc.randstate cimport randstate, current_randstate from sage.cpython.string cimport char_to_str, str_to_bytes from sage.misc.superseded import deprecation_cython as deprecation -from sage.structure.element cimport RingElement, Element, ModuleElement +from sage.structure.element cimport Element from sage.structure.element cimport have_same_parent -from sage.structure.richcmp cimport rich_to_bool_sgn, rich_to_bool +from sage.structure.richcmp cimport rich_to_bool_sgn cdef bin_op from sage.structure.element import bin_op diff --git a/src/sage/rings/ring_extension.pyx b/src/sage/rings/ring_extension.pyx index cb71cd576aa..e90917654e3 100644 --- a/src/sage/rings/ring_extension.pyx +++ b/src/sage/rings/ring_extension.pyx @@ -100,15 +100,15 @@ AUTHOR: - Xavier Caruso (2019) """ -############################################################################# +# ########################################################################### # Copyright (C) 2019 Xavier Caruso # # This program is free softwGare: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#**************************************************************************** +# https://www.gnu.org/licenses/ +# *************************************************************************** from sage.misc.fast_methods cimport hash_by_id @@ -122,7 +122,6 @@ from sage.structure.element cimport Element from sage.structure.category_object import normalize_names from sage.categories.map cimport Map from sage.categories.commutative_rings import CommutativeRings -from sage.categories.commutative_algebras import CommutativeAlgebras from sage.categories.fields import Fields from sage.rings.ring cimport CommutativeRing, CommutativeAlgebra from sage.rings.integer_ring import ZZ diff --git a/src/sage/rings/ring_extension_element.pyx b/src/sage/rings/ring_extension_element.pyx index 134cd1a1174..03eac9df70c 100644 --- a/src/sage/rings/ring_extension_element.pyx +++ b/src/sage/rings/ring_extension_element.pyx @@ -6,26 +6,24 @@ AUTHOR: - Xavier Caruso (2019) """ -############################################################################# +# ########################################################################### # Copyright (C) 2019 Xavier Caruso # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#**************************************************************************** +# https://www.gnu.org/licenses/ +# *************************************************************************** from sage.ext.stdsage cimport PY_NEW -from sage.misc.cachefunc import cached_method from sage.cpython.getattr cimport AttributeErrorMessage from sage.cpython.getattr import dir_with_other_class from sage.misc.latex import latex from sage.structure.category_object import normalize_names from sage.structure.element cimport CommutativeAlgebraElement -from sage.structure.element cimport Element from sage.rings.integer_ring import ZZ from sage.categories.fields import Fields from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing diff --git a/src/sage/rings/semirings/tropical_semiring.pyx b/src/sage/rings/semirings/tropical_semiring.pyx index 73c3b8820ec..5beff3cff55 100644 --- a/src/sage/rings/semirings/tropical_semiring.pyx +++ b/src/sage/rings/semirings/tropical_semiring.pyx @@ -5,7 +5,7 @@ AUTHORS: - Travis Scrimshaw (2013-04-28) - Initial version """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2013 Travis Scrimshaw # # Distributed under the terms of the GNU General Public License (GPL) @@ -17,8 +17,8 @@ AUTHORS: # # The full text of the GPL is available at: # -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from sage.misc.cachefunc import cached_method from sage.structure.parent import Parent @@ -27,10 +27,8 @@ from sage.structure.element cimport Element, ModuleElement from sage.structure.richcmp cimport rich_to_bool from sage.categories.semirings import Semirings from sage.categories.map cimport Map -from sage.sets.family import Family from sage.rings.integer_ring import ZZ -import operator cdef class TropicalSemiringElement(Element): r""" diff --git a/src/sage/rings/tate_algebra_element.pyx b/src/sage/rings/tate_algebra_element.pyx index 80d7c448721..36f6fbf6348 100644 --- a/src/sage/rings/tate_algebra_element.pyx +++ b/src/sage/rings/tate_algebra_element.pyx @@ -20,14 +20,13 @@ AUTHOR: # https://www.gnu.org/licenses/ # *************************************************************************** -from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE +from cpython.object cimport Py_EQ, Py_NE from sage.structure.richcmp cimport rich_to_bool_sgn from sage.structure.element import coerce_binop from sage.structure.element cimport Element from sage.structure.element cimport MonoidElement from sage.structure.element cimport CommutativeAlgebraElement -from sage.structure.sequence import Sequence from sage.rings.infinity import Infinity from sage.rings.integer_ring import ZZ @@ -258,9 +257,7 @@ cdef class TateAlgebraTerm(MonoidElement): ...00000000010*x*y sage: T(2*x*y)._latex_() '...00000000010xy' - """ - from sage.misc.latex import latex parent = self._parent s = "" if self._coeff._is_atomic() or (-self._coeff)._is_atomic(): @@ -1255,9 +1252,7 @@ cdef class TateAlgebraElement(CommutativeAlgebraElement): ...0000000001*x^3 + ...0000000001*x + ...00000000010*x^2 sage: f._latex_() '...0000000001x^{3} + ...0000000001x + ...00000000010x^{2}' - """ - from sage.misc.latex import latex base = self._parent.base_ring() nvars = self._parent.ngens() vars = self._parent.variable_names() diff --git a/src/sage/rings/tate_algebra_ideal.pyx b/src/sage/rings/tate_algebra_ideal.pyx index 9d4fd1f63b8..e9b45049897 100644 --- a/src/sage/rings/tate_algebra_ideal.pyx +++ b/src/sage/rings/tate_algebra_ideal.pyx @@ -20,15 +20,13 @@ AUTHORS: # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ # *************************************************************************** from sage.rings.ideal import Ideal_generic -from sage.misc.cachefunc import cached_method from sage.structure.richcmp import op_EQ, op_NE, op_LT, op_GT, op_LE, op_GE -from sage.structure.element cimport Element from sage.rings.polynomial.polydict cimport PolyDict from sage.rings.tate_algebra_element cimport TateAlgebraTerm From d57488e0d8c682811ad4047fa966c283454146f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 28 May 2023 20:42:27 +0200 Subject: [PATCH 67/98] fixing the doctests --- src/sage/geometry/polyhedron/parent.py | 18 ++++++++++++++---- src/sage/modular/btquotients/btquotient.py | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/sage/geometry/polyhedron/parent.py b/src/sage/geometry/polyhedron/parent.py index 813f30a7d4b..e891299ab15 100644 --- a/src/sage/geometry/polyhedron/parent.py +++ b/src/sage/geometry/polyhedron/parent.py @@ -2,12 +2,12 @@ Parents for Polyhedra """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2014 Volker Braun # # Distributed under the terms of the GNU General Public License (GPL) -# http://www.gnu.org/licenses/ -#****************************************************************************** +# https://www.gnu.org/licenses/ +# ***************************************************************************** from sage.structure.parent import Parent from sage.structure.element import get_coercion_model @@ -400,7 +400,7 @@ def some_elements(self): points = [] R = self.base_ring() for i in range(self.ambient_dim() + 5): - points.append([R(i * j**2) for j in range(self.ambient_dim())]) + points.append([R(i * j ^ 2) for j in range(self.ambient_dim())]) return [ self.element_class(self, [points[0:self.ambient_dim() + 1], [], []], None), self.element_class(self, [points[0:1], points[1:self.ambient_dim() + 1], []], None), @@ -1212,9 +1212,11 @@ def _element_constructor_polyhedron(self, polyhedron, **kwds): else: return Polyhedra_base._element_constructor_polyhedron(self, polyhedron, **kwds) + class Polyhedra_ZZ_normaliz(Polyhedra_base): Element = Polyhedron_ZZ_normaliz + class Polyhedra_QQ_ppl(Polyhedra_base): Element = Polyhedron_QQ_ppl @@ -1244,27 +1246,35 @@ def _element_constructor_polyhedron(self, polyhedron, **kwds): else: return Polyhedra_base._element_constructor_polyhedron(self, polyhedron, **kwds) + class Polyhedra_QQ_normaliz(Polyhedra_base): Element = Polyhedron_QQ_normaliz + class Polyhedra_QQ_cdd(Polyhedra_base): Element = Polyhedron_QQ_cdd + class Polyhedra_RDF_cdd(Polyhedra_base): Element = Polyhedron_RDF_cdd + class Polyhedra_normaliz(Polyhedra_base): Element = Polyhedron_normaliz + class Polyhedra_polymake(Polyhedra_base): Element = Polyhedron_polymake + class Polyhedra_field(Polyhedra_base): Element = Polyhedron_field + class Polyhedra_number_field(Polyhedra_base): Element = Polyhedron_number_field + @cached_function def does_backend_handle_base_ring(base_ring, backend): r""" diff --git a/src/sage/modular/btquotients/btquotient.py b/src/sage/modular/btquotients/btquotient.py index a8445989f48..ff9701f3d33 100644 --- a/src/sage/modular/btquotients/btquotient.py +++ b/src/sage/modular/btquotients/btquotient.py @@ -412,7 +412,7 @@ class BruhatTitsTree(SageObject, UniqueRepresentation): sage: T = BruhatTitsTree(4) Traceback (most recent call last): ... - ValueError: Input (4) must be prime + ValueError: input (4) must be prime AUTHORS: From 9b3d50ffa6888cda65122965c6b46c7ac23d906f Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Fri, 28 Apr 2023 18:15:10 +0900 Subject: [PATCH 68/98] Implementing the Casimir elements of a finite dimensional Lie algebra. --- .../lie_algebras/poincare_birkhoff_witt.py | 40 +++++ ...ite_dimensional_lie_algebras_with_basis.py | 157 ++++++++++++++++++ 2 files changed, 197 insertions(+) diff --git a/src/sage/algebras/lie_algebras/poincare_birkhoff_witt.py b/src/sage/algebras/lie_algebras/poincare_birkhoff_witt.py index dbfc3d3d5ec..38334bfe1f8 100644 --- a/src/sage/algebras/lie_algebras/poincare_birkhoff_witt.py +++ b/src/sage/algebras/lie_algebras/poincare_birkhoff_witt.py @@ -496,6 +496,46 @@ def degree_on_basis(self, m): """ return m.length() + def casimir_element(self, order=2): + r""" + Return the Casimir element of ``self``. + + .. SEEALSO:: + + :meth:`~sage.categories.finite_dimensional_lie_algebras_with_basis.FiniteDimensionalLieAlgebrasWithBasis.ParentMethods.casimir_element` + + INPUT: + + - ``order`` -- (default: ``2``) the order of the Casimir element + + EXAMPLES:: + + sage: L = LieAlgebra(QQ, cartan_type=['G', 2]) + sage: U = L.pbw_basis() + sage: C = U.casimir_element(); C + 1/4*PBW[alpha[2]]*PBW[-alpha[2]] + 1/12*PBW[alpha[1]]*PBW[-alpha[1]] + + 1/12*PBW[alpha[1] + alpha[2]]*PBW[-alpha[1] - alpha[2]] + 1/12*PBW[2*alpha[1] + alpha[2]]*PBW[-2*alpha[1] - alpha[2]] + + 1/4*PBW[3*alpha[1] + alpha[2]]*PBW[-3*alpha[1] - alpha[2]] + + 1/4*PBW[3*alpha[1] + 2*alpha[2]]*PBW[-3*alpha[1] - 2*alpha[2]] + + 1/12*PBW[alphacheck[1]]^2 + 1/4*PBW[alphacheck[1]]*PBW[alphacheck[2]] + + 1/4*PBW[alphacheck[2]]^2 - 5/12*PBW[alphacheck[1]] - 3/4*PBW[alphacheck[2]] + sage: all(g * C == C * g for g in U.algebra_generators()) + True + + TESTS:: + + sage: H = lie_algebras.Heisenberg(QQ, oo) + sage: U = H.pbw_basis() + sage: U.casimir_element() + Traceback (most recent call last): + ... + ValueError: the Lie algebra must be finite dimensional + """ + from sage.rings.infinity import Infinity + if self._g.dimension() == Infinity: + raise ValueError("the Lie algebra must be finite dimensional") + return self._g.casimir_element(order=order, UEA=self) + class Element(CombinatorialFreeModule.Element): def _act_on_(self, x, self_on_left): """ diff --git a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py index 3637ea46298..b943de3975f 100644 --- a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py @@ -1594,6 +1594,163 @@ def universal_commutative_algebra(self): R = P[0].parent() return R.quotient(P) + def casimir_element(self, order=2, UEA=None, force_generic=False): + r""" + Return the Casimir element in the universal enveloping algebra + of ``self``. + + A *Casimir element* of order `k` is a distinguished basis element + for the center of `U(\mathfrak{g})` of homogeneous degree `k` + (that is, it is an element of `U_k \setminus U_{k-1}`, where + `\{U_i\}_{i=0}^{\infty}` is the natural filtration of + `U(\mathfrak{g})`. When `\mathfrak{g}` is a simple Lie algebra, + then this spans `Z(U(\mathfrak{g}))_k`. + + INPUT: + + - ``order`` -- (default: ``2``) the order of the Casimir element + - ``UEA`` -- (optional) the universal enveloping algebra to + return the result in + - ``force_generic`` -- (default: ``False``) if ``True`` for the + quadradic order, then this uses the default algorithm; otherwise + this is ignored + + ALGORITHM: + + For the quadradic order (i.e., ``order=2``), then this uses + K^{ij}`, the inverse of the Killing form matrix, to compute + `C_{(2)} = sum_{i,j} K^{ij} X_i \cdot X_j`, where `\{X_1, \ldots, + X_n\}` is a basis for `\mathfrak{g}`. Otherwise this solves the + system of equations + + .. MATH:: + + f_{aj}^b \kappa^{jc\cdots d} + f_{aj}^c \kappa^{cj\cdots d} + \cdots + f_{aj}^d \kappa^{bc \cdots j} + + for the symmetric tensor `\kappa^{i_1 \cdots i_m}`, where `m` + is the ``order``. + + EXAMPLES:: + + sage: L = LieAlgebra(QQ, cartan_type=['A', 1]) + sage: C = L.casimir_element(); C + 1/8*b1^2 + 1/2*b0*b2 - 1/4*b1 + sage: U = L.universal_enveloping_algebra() + sage: all(g * C == C * g for g in U.gens()) + True + sage: U = L.pbw_basis() + sage: C = L.casimir_element(UEA=U); C + 1/2*PBW[alpha[1]]*PBW[-alpha[1]] + 1/8*PBW[alphacheck[1]]^2 - 1/4*PBW[alphacheck[1]] + sage: all(g * C == C * g for g in U.algebra_generators()) + True + + sage: L = LieAlgebra(QQ, cartan_type=['B', 2]) + sage: U = L.pbw_basis() + sage: C = L.casimir_element(UEA=U) + sage: all(g * C == C * g for g in U.algebra_generators()) + True + + sage: L = LieAlgebra(QQ, cartan_type=['C', 3]) + sage: U = L.pbw_basis() + sage: C = L.casimir_element(UEA=U) + sage: all(g * C == C * g for g in U.algebra_generators()) + True + + sage: L = LieAlgebra(QQ, cartan_type=['A', 1]) + sage: C4 = L.casimir_element(order=4, UEA=L.pbw_basis()); C4 + 4*PBW[alpha[1]]^2*PBW[-alpha[1]]^2 + + 2*PBW[alpha[1]]*PBW[alphacheck[1]]^2*PBW[-alpha[1]] + + 1/4*PBW[alphacheck[1]]^4 - PBW[alphacheck[1]]^3 + - 4*PBW[alpha[1]]*PBW[-alpha[1]] + 2*PBW[alphacheck[1]] + sage: all(g * C4 == C4 * g for g in L.pbw_basis().algebra_generators()) + True + + sage: L = lie_algebras.Heisenberg(QQ, 2) + sage: L.casimir_element() + 0 + + TESTS:: + + sage: L = LieAlgebra(QQ, cartan_type=['A', 1]) + sage: L.casimir_element(1) + Traceback (most recent call last): + ... + ValueError: invalid order + sage: 4 * L.casimir_element() == L.casimir_element(force_generic=True) + True + + .. TODO:: + + Use the symmetry of the tensor to reduce the number of + equations and/or variables to solve. + """ + if order < 2: + raise ValueError("invalid order") + + if UEA is None: + UEA = self.universal_enveloping_algebra() + + B = self.basis() + + if order == 2 and not force_generic: + # Special case for the quadradic using the Killing form + try: + K = self.killing_form_matrix().inverse() + return UEA.sum(K[i, j] * UEA(x) * UEA(y) for i, x in enumerate(B) + for j, y in enumerate(B) if K[i, j]) + except (ValueError, TypeError, ZeroDivisionError): + # fall back to finding solutions to the system of equations + pass + + keys = self.get_order() + dim = len(keys) + s_coeffs = dict(self.structure_coefficients()) + for k in list(s_coeffs.keys()): + s_coeffs[k[1], k[0]] = -s_coeffs[k] + + # setup the equations + from sage.matrix.constructor import matrix + from itertools import product + eqns = matrix.zero(self.base_ring(), dim**(order+1), dim**order, sparse=True) + for ii, p in enumerate(product(range(dim), repeat=order+1)): + i = p[0] + a = keys[i] + for j, b in enumerate(keys): + if (a, b) not in s_coeffs: + continue + sc_val = s_coeffs[a, b] + for k in range(order): + c = keys[p[k+1]] + if not sc_val[c]: + continue + pp = list(p[1:]) + pp[k] = j + jj = sum(dim**m * pp[m] for m in range(order)) + eqns[ii, jj] += sc_val[c] + + ker = eqns.right_kernel() + if ker.dimension() == 0: + return self.zero() + + tens = ker.basis()[0] + del eqns # no need to hold onto the matrix + + from sage.rings.integer_ring import ZZ + def to_prod(index): + coeff = tens[index] + p = [0] * order + base = dim ** (order-1) + for i in range(order): + p[i] = index // base + index %= base + base //= dim + p.reverse() + return coeff * UEA.prod(UEA(B[keys[i]]) for i in p) + + return UEA.sum(to_prod(index) for index in tens.support()) + + class ElementMethods: def adjoint_matrix(self, sparse=False): # In #11111 (more or less) by using matrix of a morphism """ From c8fce0646d43c469dba7f28a5f35fc26ad336eba Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Mon, 1 May 2023 13:57:10 +0900 Subject: [PATCH 69/98] Fixing some docstring and linter issues. --- .../finite_dimensional_lie_algebras_with_basis.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py index b943de3975f..c17e4f372b1 100644 --- a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py @@ -1619,7 +1619,7 @@ def casimir_element(self, order=2, UEA=None, force_generic=False): For the quadradic order (i.e., ``order=2``), then this uses K^{ij}`, the inverse of the Killing form matrix, to compute - `C_{(2)} = sum_{i,j} K^{ij} X_i \cdot X_j`, where `\{X_1, \ldots, + `C_{(2)} = \sum_{i,j} K^{ij} X_i \cdots X_j`, where `\{X_1, \ldots, X_n\}` is a basis for `\mathfrak{g}`. Otherwise this solves the system of equations @@ -1628,8 +1628,10 @@ def casimir_element(self, order=2, UEA=None, force_generic=False): f_{aj}^b \kappa^{jc\cdots d} + f_{aj}^c \kappa^{cj\cdots d} \cdots + f_{aj}^d \kappa^{bc \cdots j} - for the symmetric tensor `\kappa^{i_1 \cdots i_m}`, where `m` - is the ``order``. + for the symmetric tensor `\kappa^{i_1 \cdots i_k}`, where `k` + is the ``order``. This system comes from `[X_i, C_{(k)}] = 0` + with `C_{(k)} = \sum_{i_1, \ldots, i_k\}^n + \kappa^{i_1 \cdots i_k} X_{i_1} \cdots X_{i_k}`. EXAMPLES:: @@ -1641,7 +1643,8 @@ def casimir_element(self, order=2, UEA=None, force_generic=False): True sage: U = L.pbw_basis() sage: C = L.casimir_element(UEA=U); C - 1/2*PBW[alpha[1]]*PBW[-alpha[1]] + 1/8*PBW[alphacheck[1]]^2 - 1/4*PBW[alphacheck[1]] + 1/2*PBW[alpha[1]]*PBW[-alpha[1]] + 1/8*PBW[alphacheck[1]]^2 + - 1/4*PBW[alphacheck[1]] sage: all(g * C == C * g for g in U.algebra_generators()) True @@ -1736,7 +1739,6 @@ def casimir_element(self, order=2, UEA=None, force_generic=False): tens = ker.basis()[0] del eqns # no need to hold onto the matrix - from sage.rings.integer_ring import ZZ def to_prod(index): coeff = tens[index] p = [0] * order From 39ebfc9970c393052280d005e82422ff66980e8d Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Mon, 29 May 2023 09:16:12 +0900 Subject: [PATCH 70/98] Reviewer changes. --- .../finite_dimensional_lie_algebras_with_basis.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py index c17e4f372b1..c3881278e1c 100644 --- a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py @@ -1603,7 +1603,7 @@ def casimir_element(self, order=2, UEA=None, force_generic=False): for the center of `U(\mathfrak{g})` of homogeneous degree `k` (that is, it is an element of `U_k \setminus U_{k-1}`, where `\{U_i\}_{i=0}^{\infty}` is the natural filtration of - `U(\mathfrak{g})`. When `\mathfrak{g}` is a simple Lie algebra, + `U(\mathfrak{g})`). When `\mathfrak{g}` is a simple Lie algebra, then this spans `Z(U(\mathfrak{g}))_k`. INPUT: @@ -1612,12 +1612,12 @@ def casimir_element(self, order=2, UEA=None, force_generic=False): - ``UEA`` -- (optional) the universal enveloping algebra to return the result in - ``force_generic`` -- (default: ``False``) if ``True`` for the - quadradic order, then this uses the default algorithm; otherwise + quadratic order, then this uses the default algorithm; otherwise this is ignored ALGORITHM: - For the quadradic order (i.e., ``order=2``), then this uses + For the quadratic order (i.e., ``order=2``), then this uses K^{ij}`, the inverse of the Killing form matrix, to compute `C_{(2)} = \sum_{i,j} K^{ij} X_i \cdots X_j`, where `\{X_1, \ldots, X_n\}` is a basis for `\mathfrak{g}`. Otherwise this solves the @@ -1697,7 +1697,7 @@ def casimir_element(self, order=2, UEA=None, force_generic=False): B = self.basis() if order == 2 and not force_generic: - # Special case for the quadradic using the Killing form + # Special case for the quadratic using the Killing form try: K = self.killing_form_matrix().inverse() return UEA.sum(K[i, j] * UEA(x) * UEA(y) for i, x in enumerate(B) From 1cdc54d457456b5c9c53638fae5dd10ac251190f Mon Sep 17 00:00:00 2001 From: Lorenz Panny Date: Tue, 14 Mar 2023 13:11:27 +0800 Subject: [PATCH 71/98] make EllipticCurve_generic.lift_x() deterministic --- src/sage/schemes/elliptic_curves/ell_generic.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/sage/schemes/elliptic_curves/ell_generic.py b/src/sage/schemes/elliptic_curves/ell_generic.py index 4989c94d0d2..755cf7a0f82 100644 --- a/src/sage/schemes/elliptic_curves/ell_generic.py +++ b/src/sage/schemes/elliptic_curves/ell_generic.py @@ -711,6 +711,9 @@ def lift_x(self, x, all=False, extend=False): r""" Return one or all points with given `x`-coordinate. + This method is deterministic: It returns the same data each + time when called again with the same `x`. + INPUT: - ``x`` -- an element of the base ring of the curve, or of an extension. @@ -873,6 +876,15 @@ def lift_x(self, x, all=False, extend=False): [] sage: E.lift_x(7, all=True) # optional - sage.rings.finite_rings [(7 : 3 : 1), (7 : 14 : 1)] + + Check determinism:: + + sage: F. = GF((101,3)) + sage: {(t+1).sqrt() for _ in range(1000)} # both square roots can occur + {29*t^2 + 56*t + 26, 72*t^2 + 45*t + 75} + sage: E = EllipticCurve(F, [1,1]) + sage: {E.lift_x(t+1) for _ in range(1000)} # but .lift_x() uses a fixed one + {(t + 1 : 39*t^2 + 14*t + 12 : 1)} """ K = self.base_ring() L = x.parent() @@ -909,6 +921,8 @@ def lift_x(self, x, all=False, extend=False): if D.is_square(): # avoid automatic creation of sqrts ys = [(-b+d)/2 for d in D.sqrt(all=True)] + ys.sort() # ensure deterministic behavior + # Return the point(s) if any: if ys: @@ -939,6 +953,7 @@ def lift_x(self, x, all=False, extend=False): ys = [y1] else: ys = [y1, y2] + ys.sort() # ensure deterministic behavior one = M.one() if all: return [EM.point([x, y, one], check=False) for y in ys] From ad84fdf5e67d40c8a73b551491b2c3708eb58e75 Mon Sep 17 00:00:00 2001 From: Lorenz Panny Date: Mon, 15 May 2023 18:56:38 +0800 Subject: [PATCH 72/98] update some doctests --- .../schemes/elliptic_curves/ell_generic.py | 30 +++++++++---------- src/sage/schemes/elliptic_curves/ell_point.py | 8 ++--- .../elliptic_curves/ell_rational_field.py | 29 +++++++----------- .../schemes/elliptic_curves/hom_composite.py | 4 +-- 4 files changed, 32 insertions(+), 39 deletions(-) diff --git a/src/sage/schemes/elliptic_curves/ell_generic.py b/src/sage/schemes/elliptic_curves/ell_generic.py index 755cf7a0f82..f9f83154ec4 100644 --- a/src/sage/schemes/elliptic_curves/ell_generic.py +++ b/src/sage/schemes/elliptic_curves/ell_generic.py @@ -748,11 +748,11 @@ def lift_x(self, x, all=False, extend=False): sage: E = EllipticCurve('37a'); E Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field sage: E.lift_x(1) - (1 : 0 : 1) + (1 : -1 : 1) sage: E.lift_x(2) - (2 : 2 : 1) + (2 : -3 : 1) sage: E.lift_x(1/4, all=True) - [(1/4 : -3/8 : 1), (1/4 : -5/8 : 1)] + [(1/4 : -5/8 : 1), (1/4 : -3/8 : 1)] There are no rational points with `x`-coordinate 3:: @@ -768,7 +768,7 @@ def lift_x(self, x, all=False, extend=False): the base ring to the parent of `x`:: sage: P = E.lift_x(3, extend=True); P # optional - sage.rings.number_field - (3 : y : 1) + (3 : -y - 1 : 1) sage: P.curve() # optional - sage.rings.number_field Elliptic Curve defined by y^2 + y = x^3 + (-1)*x over Number Field in y with defining polynomial y^2 + y - 24 @@ -776,15 +776,15 @@ def lift_x(self, x, all=False, extend=False): Or we can extend scalars. There are two such points in `E(\RR)`:: sage: E.change_ring(RR).lift_x(3, all=True) - [(3.00000000000000 : 4.42442890089805 : 1.00000000000000), - (3.00000000000000 : -5.42442890089805 : 1.00000000000000)] + [(3.00000000000000 : -5.42442890089805 : 1.00000000000000), + (3.00000000000000 : 4.42442890089805 : 1.00000000000000)] And of course it always works in `E(\CC)`:: sage: E.change_ring(RR).lift_x(.5, all=True) [] sage: E.change_ring(CC).lift_x(.5) - (0.500000000000000 : -0.500000000000000 + 0.353553390593274*I : 1.00000000000000) + (0.500000000000000 : -0.500000000000000 - 0.353553390593274*I : 1.00000000000000) In this example we start with a curve defined over `\QQ` which has no rational points with `x=0`, but using @@ -794,7 +794,7 @@ def lift_x(self, x, all=False, extend=False): sage: E = EllipticCurve([0,0,0,0,2]); E Elliptic Curve defined by y^2 = x^3 + 2 over Rational Field sage: P = E.lift_x(0, extend=True); P # optional - sage.rings.number_field - (0 : y : 1) + (0 : -y : 1) sage: P.curve() # optional - sage.rings.number_field Elliptic Curve defined by y^2 = x^3 + 2 over Number Field in y with defining polynomial y^2 - 2 @@ -804,7 +804,7 @@ def lift_x(self, x, all=False, extend=False): sage: E = EllipticCurve('37a').change_ring(GF(17)); E # optional - sage.rings.finite_rings Elliptic Curve defined by y^2 + y = x^3 + 16*x over Finite Field of size 17 sage: E.lift_x(7) # optional - sage.rings.finite_rings - (7 : 11 : 1) + (7 : 5 : 1) sage: E.lift_x(3) # optional - sage.rings.finite_rings Traceback (most recent call last): ... @@ -823,14 +823,14 @@ def lift_x(self, x, all=False, extend=False): sage: E = EllipticCurve('37a') sage: P = E.lift_x(pAdicField(17, 5)(6)); P # optional - sage.rings.padics - (6 + O(17^5) : 2 + 16*17 + 16*17^2 + 16*17^3 + 16*17^4 + O(17^5) : 1 + O(17^5)) + (6 + O(17^5) : 14 + O(17^5) : 1 + O(17^5)) sage: P.curve() # optional - sage.rings.padics Elliptic Curve defined by y^2 + (1+O(17^5))*y = x^3 + (16+16*17+16*17^2+16*17^3+16*17^4+O(17^5))*x over 17-adic Field with capped relative precision 5 sage: K. = PowerSeriesRing(QQ, 't', 5) sage: P = E.lift_x(1 + t); P - (1 + t : 2*t - t^2 + 5*t^3 - 21*t^4 + O(t^5) : 1) + (1 + t : -1 - 2*t + t^2 - 5*t^3 + 21*t^4 + O(t^5) : 1) sage: K. = GF(16) # optional - sage.rings.finite_rings sage: P = E.change_ring(K).lift_x(a^3); P # optional - sage.rings.finite_rings (a^3 : a^3 + a : 1) @@ -843,7 +843,7 @@ def lift_x(self, x, all=False, extend=False): Elliptic Curve defined by y^2 = x^3 + 2 over Rational Field sage: x = polygen(QQ) sage: P = E.lift_x(x, extend=True); P - (x : y : 1) + (x : -y : 1) This point is a generic point on E:: @@ -853,9 +853,9 @@ def lift_x(self, x, all=False, extend=False): over Fraction Field of Univariate Polynomial Ring in x over Rational Field with modulus y^2 - x^3 - 2 sage: -P - (x : -y : 1) + (x : y : 1) sage: 2*P - ((1/4*x^4 - 4*x)/(x^3 + 2) : ((1/8*x^6 + 5*x^3 - 4)/(x^6 + 4*x^3 + 4))*y : 1) + ((1/4*x^4 - 4*x)/(x^3 + 2) : ((-1/8*x^6 - 5*x^3 + 4)/(x^6 + 4*x^3 + 4))*y : 1) Check that :trac:`30297` is fixed:: @@ -1707,7 +1707,7 @@ def division_polynomial_0(self, n, x=None): sage: xlist = pol.roots(multiplicities=False); xlist [9, 2, -1/3, -5] sage: [E.lift_x(x, all=True) for x in xlist] - [[(9 : 23 : 1), (9 : -33 : 1)], [(2 : 2 : 1), (2 : -5 : 1)], [], []] + [[(9 : -33 : 1), (9 : 23 : 1)], [(2 : -5 : 1), (2 : 2 : 1)], [], []] .. NOTE:: diff --git a/src/sage/schemes/elliptic_curves/ell_point.py b/src/sage/schemes/elliptic_curves/ell_point.py index 07b3807082c..e82da73e901 100644 --- a/src/sage/schemes/elliptic_curves/ell_point.py +++ b/src/sage/schemes/elliptic_curves/ell_point.py @@ -2631,7 +2631,7 @@ def height(self, precision=None, normalised=True, algorithm='pari'): sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field sage: E = EllipticCurve(K, [0,0,4,6*i,0]) # optional - sage.rings.number_field sage: Q = E.lift_x(-9/4); Q # optional - sage.rings.number_field - (-9/4 : -27/8*i : 1) + (-9/4 : 27/8*i - 4 : 1) sage: Q.height() # optional - sage.rings.number_field 2.69518560017909 sage: (15*Q).height() / Q.height() # optional - sage.rings.number_field @@ -2783,7 +2783,7 @@ def archimedean_local_height(self, v=None, prec=None, weighted=False): Elliptic Curve defined by y^2 + y = x^3 + (-1)*x^2 over Number Field in a with defining polynomial x^2 + 2 with a = 1.414213562373095?*I sage: P = E.lift_x(2 + a); P # optional - sage.rings.number_field - (a + 2 : 2*a + 1 : 1) + (a + 2 : -2*a - 2 : 1) sage: P.archimedean_local_height(K.places(prec=170)[0]) / 2 # optional - sage.rings.number_field 0.45754773287523276736211210741423654346576029814695 @@ -2796,7 +2796,7 @@ def archimedean_local_height(self, v=None, prec=None, weighted=False): 0.510184995162373 sage: Q = E.lift_x(-9/4); Q # optional - sage.rings.number_field - (-9/4 : -27/8*i : 1) + (-9/4 : 27/8*i - 4 : 1) sage: Q.archimedean_local_height(K.places()[0]) / 2 # optional - sage.rings.number_field 0.654445619529600 @@ -3019,7 +3019,7 @@ def non_archimedean_local_height(self, v=None, prec=None, 0 sage: Q = E.lift_x(-9/4); Q # optional - sage.rings.number_field - (-9/4 : -27/8*i : 1) + (-9/4 : 27/8*i - 4 : 1) sage: Q.non_archimedean_local_height(K.ideal(1+i)) # optional - sage.rings.number_field 2*log(2) sage: Q.non_archimedean_local_height(K.ideal(3)) # optional - sage.rings.number_field diff --git a/src/sage/schemes/elliptic_curves/ell_rational_field.py b/src/sage/schemes/elliptic_curves/ell_rational_field.py index 420a6c7cc77..b833ffea0f7 100644 --- a/src/sage/schemes/elliptic_curves/ell_rational_field.py +++ b/src/sage/schemes/elliptic_curves/ell_rational_field.py @@ -5821,7 +5821,7 @@ def integral_x_coords_in_interval(self,xmin,xmax): sage: E = EllipticCurve("141d1") sage: E.integral_points() - [(0 : 0 : 1), (2 : 1 : 1)] + [(0 : -1 : 1), (2 : -2 : 1)] """ xmin = pari(xmin) xmax = pari(xmax) @@ -5868,10 +5868,11 @@ def integral_points(self, mw_base='auto', both_signs=False, verbose=False): sage: E = EllipticCurve([0,0,1,-7,6]) sage: P1 = E.point((2,0)); P2 = E.point((-1,3)); P3 = E.point((4,6)) sage: a = E.integral_points([P1,P2,P3]); a - [(-3 : 0 : 1), (-2 : 3 : 1), (-1 : 3 : 1), (0 : 2 : 1), (1 : 0 : 1), - (2 : 0 : 1), (3 : 3 : 1), (4 : 6 : 1), (8 : 21 : 1), (11 : 35 : 1), - (14 : 51 : 1), (21 : 95 : 1), (37 : 224 : 1), (52 : 374 : 1), - (93 : 896 : 1), (342 : 6324 : 1), (406 : 8180 : 1), (816 : 23309 : 1)] + [(-3 : -1 : 1), (-2 : -4 : 1), (-1 : -4 : 1), (0 : -3 : 1), + (1 : -1 : 1), (2 : -1 : 1), (3 : -4 : 1), (4 : -7 : 1), + (8 : -22 : 1), (11 : -36 : 1), (14 : -52 : 1), (21 : -96 : 1), + (37 : -225 : 1), (52 : -375 : 1), (93 : -897 : 1), + (342 : -6325 : 1), (406 : -8181 : 1), (816 : -23310 : 1)] :: @@ -5908,7 +5909,7 @@ def integral_points(self, mw_base='auto', both_signs=False, verbose=False): An example with negative discriminant:: sage: EllipticCurve('900d1').integral_points() - [(-11 : 27 : 1), (-4 : 34 : 1), (4 : 18 : 1), (16 : 54 : 1)] + [(-11 : -27 : 1), (-4 : -34 : 1), (4 : -18 : 1), (16 : -54 : 1)] Another example with rank 5 and no torsion points:: @@ -5924,7 +5925,7 @@ def integral_points(self, mw_base='auto', both_signs=False, verbose=False): The bug reported on :trac:`4525` is now fixed:: sage: EllipticCurve('91b1').integral_points() - [(-1 : 3 : 1), (1 : 0 : 1), (3 : 4 : 1)] + [(-1 : -4 : 1), (1 : -1 : 1), (3 : -5 : 1)] :: @@ -6352,17 +6353,9 @@ def S_integral_points(self, S, mw_base='auto', both_signs=False, verbose=False, This is curve "7690e1" which failed until :trac:`4805` was fixed:: sage: EllipticCurve([1,1,1,-301,-1821]).S_integral_points([13,2]) - [(-13 : 16 : 1), - (-9 : 20 : 1), - (-7 : 4 : 1), - (21 : 30 : 1), - (23 : 52 : 1), - (63 : 452 : 1), - (71 : 548 : 1), - (87 : 756 : 1), - (2711 : 139828 : 1), - (7323 : 623052 : 1), - (17687 : 2343476 : 1)] + [(-13 : -4 : 1), (-9 : -12 : 1), (-7 : 2 : 1), (21 : -52 : 1), + (23 : -76 : 1), (63 : -516 : 1), (71 : -620 : 1), (87 : -844 : 1), + (2711 : -142540 : 1), (7323 : -630376 : 1), (17687 : -2361164 : 1)] - Some parts of this implementation are partially based on the function integral_points() diff --git a/src/sage/schemes/elliptic_curves/hom_composite.py b/src/sage/schemes/elliptic_curves/hom_composite.py index a117e2e87d0..739cce2e67e 100644 --- a/src/sage/schemes/elliptic_curves/hom_composite.py +++ b/src/sage/schemes/elliptic_curves/hom_composite.py @@ -41,7 +41,7 @@ From: Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field of size 419 To: Elliptic Curve defined by y^2 = x^3 + 101*x + 285 over Finite Field of size 419 sage: psi(E.lift_x(11)) # optional - sage.rings.finite_rings - (352 : 73 : 1) + (352 : 346 : 1) sage: psi.rational_maps() # optional - sage.rings.finite_rings ((x^35 + 162*x^34 + 186*x^33 + 92*x^32 - ... + 44*x^3 + 190*x^2 + 80*x - 72)/(x^34 + 162*x^33 - 129*x^32 + 41*x^31 + ... + 66*x^3 - 191*x^2 + 119*x + 21), @@ -407,7 +407,7 @@ def _call_(self, P): sage: psi = EllipticCurveHom_composite(E, E.torsion_points()) # optional - sage.rings.number_field sage: R = E.lift_x(15/4 * (a+3)) # optional - sage.rings.number_field sage: psi(R) # indirect doctest # optional - sage.rings.number_field - (1033648757/303450 : 58397496786187/1083316500*a - 62088706165177/2166633000 : 1) + (1033648757/303450 : -58397496786187/1083316500*a + 54706287407197/2166633000 : 1) Check that copying the order over works:: From 663175ba54f3ed67e38615aa5dd5d32c21cf557a Mon Sep 17 00:00:00 2001 From: John Cremona Date: Mon, 15 May 2023 15:06:51 +0200 Subject: [PATCH 73/98] fix doctests in 3 files --- .../elliptic_curves/ell_rational_field.py | 56 ++++++++++++++----- src/sage/schemes/elliptic_curves/height.py | 6 +- .../schemes/elliptic_curves/period_lattice.py | 8 +-- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/src/sage/schemes/elliptic_curves/ell_rational_field.py b/src/sage/schemes/elliptic_curves/ell_rational_field.py index b833ffea0f7..3080282eff8 100644 --- a/src/sage/schemes/elliptic_curves/ell_rational_field.py +++ b/src/sage/schemes/elliptic_curves/ell_rational_field.py @@ -6308,19 +6308,49 @@ def S_integral_points(self, S, mw_base='auto', both_signs=False, verbose=False, x-coords of points with bounded absolute value [-3, -2, -1, 0, 1, 2] Total number of S-integral points: 43 - [(-3 : 0 : 1), (-26/9 : 28/27 : 1), (-8159/2916 : 233461/157464 : 1), - (-2759/1024 : 60819/32768 : 1), (-151/64 : 1333/512 : 1), - (-1343/576 : 36575/13824 : 1), (-2 : 3 : 1), (-7/4 : 25/8 : 1), (-1 : 3 : 1), - (-47/256 : 9191/4096 : 1), (0 : 2 : 1), (1/4 : 13/8 : 1), (4/9 : 35/27 : 1), - (9/16 : 69/64 : 1), (58/81 : 559/729 : 1), (7/9 : 17/27 : 1), - (6169/6561 : 109871/531441 : 1), (1 : 0 : 1), (17/16 : -25/64 : 1), (2 : 0 : 1), - (33/16 : 17/64 : 1), (172/81 : 350/729 : 1), (9/4 : 7/8 : 1), (25/9 : 64/27 : 1), - (3 : 3 : 1), (31/9 : 116/27 : 1), (4 : 6 : 1), (25/4 : 111/8 : 1), - (1793/256 : 68991/4096 : 1), (8 : 21 : 1), (625/64 : 14839/512 : 1), (11 : 35 : 1), - (14 : 51 : 1), (21 : 95 : 1), (37 : 224 : 1), (52 : 374 : 1), - (6142/81 : 480700/729 : 1), (93 : 896 : 1), (4537/36 : 305425/216 : 1), - (342 : 6324 : 1), (406 : 8180 : 1), (816 : 23309 : 1), - (207331217/4096 : 2985362173625/262144 : 1)] + [(-3 : -1 : 1), + (-26/9 : -55/27 : 1), + (-8159/2916 : -390925/157464 : 1), + (-2759/1024 : -93587/32768 : 1), + (-151/64 : -1845/512 : 1), + (-1343/576 : -50399/13824 : 1), + (-2 : -4 : 1), + (-7/4 : -33/8 : 1), + (-1 : -4 : 1), + (-47/256 : -13287/4096 : 1), + (0 : -3 : 1), + (1/4 : -21/8 : 1), + (4/9 : -62/27 : 1), + (9/16 : -133/64 : 1), + (58/81 : -1288/729 : 1), + (7/9 : -44/27 : 1), + (6169/6561 : -641312/531441 : 1), + (1 : -1 : 1), + (17/16 : -39/64 : 1), + (2 : -1 : 1), + (33/16 : -81/64 : 1), + (172/81 : -1079/729 : 1), + (9/4 : -15/8 : 1), + (25/9 : -91/27 : 1), + (3 : -4 : 1), + (31/9 : -143/27 : 1), + (4 : -7 : 1), + (25/4 : -119/8 : 1), + (1793/256 : -73087/4096 : 1), + (8 : -22 : 1), + (625/64 : -15351/512 : 1), + (11 : -36 : 1), + (14 : -52 : 1), + (21 : -96 : 1), + (37 : -225 : 1), + (52 : -375 : 1), + (6142/81 : -481429/729 : 1), + (93 : -897 : 1), + (4537/36 : -305641/216 : 1), + (342 : -6325 : 1), + (406 : -8181 : 1), + (816 : -23310 : 1), + (207331217/4096 : -2985362435769/262144 : 1)] It is not necessary to specify mw_base; if it is not provided, then the Mordell-Weil basis must be computed, which may take diff --git a/src/sage/schemes/elliptic_curves/height.py b/src/sage/schemes/elliptic_curves/height.py index e9eb837d30e..ae1f19e1f69 100644 --- a/src/sage/schemes/elliptic_curves/height.py +++ b/src/sage/schemes/elliptic_curves/height.py @@ -1152,9 +1152,9 @@ def psi(self, xi, v): sage: L = E.period_lattice(v) sage: P = E.lift_x(10/9) sage: L(P) - 1.53151606047462 + 0.958696500380439 sage: L(P) / L.real_period() - 0.615014189772115 + 0.384985810227885 sage: H = E.height_function() sage: H.psi(10/9, v) 0.615014189772115 @@ -1221,7 +1221,7 @@ def S(self, xi1, xi2, v): sage: v = K.real_places()[0] # optional - sage.rings.number_field sage: H = E.height_function() # optional - sage.rings.number_field sage: H.S(9, 10, v) # optional - sage.rings.number_field - ([0.0781194447253472, 0.0823423732016403] U [0.917657626798360, 0.921880555274653]) + ([0.078119444725347..., 0.082342373201640...] U [0.91765762679836..., 0.92188055527465...]) """ L = self.E.period_lattice(v) w1, w2 = L.basis(prec=v.codomain().prec()) diff --git a/src/sage/schemes/elliptic_curves/period_lattice.py b/src/sage/schemes/elliptic_curves/period_lattice.py index 1c767699fb5..39664e6d5fb 100644 --- a/src/sage/schemes/elliptic_curves/period_lattice.py +++ b/src/sage/schemes/elliptic_curves/period_lattice.py @@ -1353,12 +1353,12 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): sage: P = ER.lift_x(12.34) # optional - sage.rings.number_field sage: xP, yP = P.xy() # optional - sage.rings.number_field sage: xP, yP # optional - sage.rings.number_field - (12.3400000000000, 43.3628968710567) + (12.3400000000000, -43.3628968710567) sage: L.e_log_RC(xP, yP) # optional - sage.rings.number_field - 3.76298229503967 + 0.284656841192041 sage: xP, yP = ER.lift_x(0).xy() # optional - sage.rings.number_field sage: L.e_log_RC(xP, yP) # optional - sage.rings.number_field - 2.69842609082114 + 1.34921304541057 Elliptic logs of complex points:: @@ -1373,7 +1373,7 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): sage: EC = EllipticCurve([v(ai) for ai in E.a_invariants()]) # optional - sage.rings.number_field sage: xP, yP = EC.lift_x(0).xy() # optional - sage.rings.number_field sage: L.e_log_RC(xP, yP) # optional - sage.rings.number_field - 1.03355715602040 - 0.867257428417356*I + 2.06711431204080 - 1.73451485683471*I """ if prec is None: prec = RealField().precision() From 6da5d127de1cdaec99d9ecbde8974548e5d93852 Mon Sep 17 00:00:00 2001 From: Lorenz Panny Date: Tue, 16 May 2023 01:52:42 +0800 Subject: [PATCH 74/98] fix one more doctest failure --- src/sage/rings/polynomial/multi_polynomial_ideal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/polynomial/multi_polynomial_ideal.py b/src/sage/rings/polynomial/multi_polynomial_ideal.py index 47f14f96229..b1d3bc8eaf4 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ideal.py +++ b/src/sage/rings/polynomial/multi_polynomial_ideal.py @@ -5418,7 +5418,7 @@ def weil_restriction(self): We pick a point on ``E``:: sage: p = E.lift_x(1); p # optional - sage.rings.number_field - (1 : 2 : 1) + (1 : -6 : 1) sage: I = E.defining_ideal(); I # optional - sage.rings.number_field Ideal (-x^3 - 2*x^2*z + x*y*z + y^2*z - 4*x*z^2 + 3*y*z^2 - 5*z^3) From 9204fcf79f79bc19fb2ca7eca637b904de42bdca Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Mon, 29 May 2023 18:50:35 +0900 Subject: [PATCH 75/98] Fixing some issues with the latex in the casimir_element() doc. --- .../finite_dimensional_lie_algebras_with_basis.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py index c3881278e1c..051e5ba1b61 100644 --- a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py @@ -1628,10 +1628,13 @@ def casimir_element(self, order=2, UEA=None, force_generic=False): f_{aj}^b \kappa^{jc\cdots d} + f_{aj}^c \kappa^{cj\cdots d} \cdots + f_{aj}^d \kappa^{bc \cdots j} - for the symmetric tensor `\kappa^{i_1 \cdots i_k}`, where `k` - is the ``order``. This system comes from `[X_i, C_{(k)}] = 0` - with `C_{(k)} = \sum_{i_1, \ldots, i_k\}^n - \kappa^{i_1 \cdots i_k} X_{i_1} \cdots X_{i_k}`. + for the symmetric tensor `\kappa^{i_1 \cdots i_k}`, where `k` is + the ``order``. This system comes from `[X_i, C_{(k)}] = 0` with + + .. MATH:: + + C_{(k)} = \sum_{i_1, \ldots, i_k}^n + \kappa^{i_1 \cdots i_k} X_{i_1} \cdots X_{i_k}. EXAMPLES:: From f8d36081b34bb2614a208504c39506b363b6e75b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 28 May 2023 20:31:01 +0200 Subject: [PATCH 76/98] cylint: remove unused imports in folders [s-z]* --- src/sage/matrix/matrix_space.py | 6 +++--- src/sage/stats/time_series.pyx | 8 ++++---- src/sage/structure/category_object.pyx | 12 ++++++------ src/sage/structure/coerce.pyx | 20 +++++++++----------- src/sage/structure/element.pyx | 9 +-------- src/sage/structure/formal_sum.py | 8 ++++---- src/sage/structure/parent.pyx | 6 ++---- src/sage/symbolic/ring.pyx | 8 -------- 8 files changed, 29 insertions(+), 48 deletions(-) diff --git a/src/sage/matrix/matrix_space.py b/src/sage/matrix/matrix_space.py index a2583f7497a..474f6be7d75 100644 --- a/src/sage/matrix/matrix_space.py +++ b/src/sage/matrix/matrix_space.py @@ -39,7 +39,7 @@ # Sage matrix imports see :trac:`34283` # Sage imports -import sage.structure.coerce +import sage.structure.coerce_actions from sage.structure.parent import Parent from sage.structure.unique_representation import UniqueRepresentation import sage.rings.integer as integer @@ -1054,7 +1054,7 @@ def _get_action_(self, S, op, self_on_left): return matrix_action.MatrixPolymapAction(self, S) else: # action of base ring - return sage.structure.coerce.RightModuleAction(S, self) + return sage.structure.coerce_actions.RightModuleAction(S, self) else: if is_MatrixSpace(S): # matrix multiplications @@ -1065,7 +1065,7 @@ def _get_action_(self, S, op, self_on_left): return matrix_action.PolymapMatrixAction(self, S) else: # action of base ring - return sage.structure.coerce.LeftModuleAction(S, self) + return sage.structure.coerce_actions.LeftModuleAction(S, self) except TypeError: return None diff --git a/src/sage/stats/time_series.pyx b/src/sage/stats/time_series.pyx index 01a735a9679..bf4ffbc178e 100644 --- a/src/sage/stats/time_series.pyx +++ b/src/sage/stats/time_series.pyx @@ -36,19 +36,19 @@ AUTHOR: - William Stein """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2008 William Stein # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** cimport cython from cpython.bytes cimport PyBytes_FromStringAndSize, PyBytes_AsString -from libc.math cimport exp, floor, log, pow, sqrt +from libc.math cimport exp, log, pow, sqrt from libc.string cimport memcpy from cysignals.memory cimport sig_malloc, sig_free from sage.structure.richcmp cimport rich_to_bool diff --git a/src/sage/structure/category_object.pyx b/src/sage/structure/category_object.pyx index 52abd7d918b..f20e3fcf884 100644 --- a/src/sage/structure/category_object.pyx +++ b/src/sage/structure/category_object.pyx @@ -47,18 +47,17 @@ This example illustrates generators for a free module over `\ZZ`. ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)) """ -#***************************************************************************** +# **************************************************************************** # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from sage.cpython.getattr import dir_with_other_class from sage.cpython.getattr cimport getattr_from_other_class from sage.categories.category import Category -from sage.structure.debug_options cimport debug from sage.misc.cachefunc import cached_method from sage.structure.dynamic_class import DynamicMetaclass @@ -668,7 +667,7 @@ cdef class CategoryObject(SageObject): sage: print(latex(f)) 5 x_{1}^{10} + x_{0}^{3} """ - from sage.misc.latex import latex, latex_variable_name + from sage.misc.latex import latex_variable_name try: names = self._latex_names if names is not None: @@ -676,7 +675,8 @@ cdef class CategoryObject(SageObject): except AttributeError: pass # Compute the latex versions of the variable names. - self._latex_names = [latex_variable_name(x) for x in self.variable_names()] + self._latex_names = [latex_variable_name(x) + for x in self.variable_names()] return self._latex_names def latex_name(self): diff --git a/src/sage/structure/coerce.pyx b/src/sage/structure/coerce.pyx index 86664258c8c..0a9644865ee 100644 --- a/src/sage/structure/coerce.pyx +++ b/src/sage/structure/coerce.pyx @@ -64,36 +64,35 @@ For more information on how to specify coercions, conversions, and actions, see the documentation for :class:`Parent`. """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2007 Robert Bradshaw # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** -from cpython.object cimport (PyObject, PyTypeObject, - PyObject_CallObject, PyObject_RichCompare, Py_TYPE, - Py_EQ, Py_NE, Py_LT, Py_LE, Py_GT, Py_GE) +from cpython.object cimport (PyTypeObject, PyObject_CallObject, + PyObject_RichCompare, Py_TYPE, + Py_EQ, Py_NE, Py_LT, Py_LE, Py_GT) from cpython.weakref cimport PyWeakref_GET_OBJECT, PyWeakref_NewRef from libc.string cimport strncmp cimport gmpy2 -cdef add, mul, truediv -from operator import add, mul, truediv +cdef mul, truediv +from operator import mul, truediv from .richcmp cimport rich_to_bool, revop from .sage_object cimport SageObject from .parent cimport Parent_richcmp_element_without_coercion from .element cimport bin_op_exception, parent, Element -from .coerce_actions import LeftModuleAction, RightModuleAction from .coerce_exceptions import CoercionException from sage.rings.integer_fake cimport is_Integer from sage.categories.map cimport Map from sage.categories.morphism import IdentityMorphism -from sage.categories.action cimport Action, InverseAction, PrecomposedAction +from sage.categories.action cimport Action, PrecomposedAction from sage.sets.pythonclass cimport Set_PythonType import traceback @@ -1652,7 +1651,6 @@ cdef class CoercionModel: sage: print(cm.discover_coercion(QQ, QQ^3)) None """ - from sage.categories.homset import Hom if R is S: return None, None diff --git a/src/sage/structure/element.pyx b/src/sage/structure/element.pyx index e52f4665a3f..175ce4ff6b7 100644 --- a/src/sage/structure/element.pyx +++ b/src/sage/structure/element.pyx @@ -290,15 +290,11 @@ continue down the MRO and find the ``_add_`` method in the category. cimport cython from cpython cimport * -from cpython.ref cimport PyObject from sage.ext.stdsage cimport * -import types cdef add, sub, mul, truediv, floordiv, mod, matmul, pow -cdef iadd, isub, imul, itruediv, ifloordiv, imod, ipow -from operator import (add, sub, mul, truediv, floordiv, mod, matmul, pow, - iadd, isub, imul, itruediv, ifloordiv, imod, imatmul, ipow) +from operator import (add, sub, mul, truediv, floordiv, mod, matmul, pow) cdef dict _coerce_op_symbols = dict( add='+', sub='-', mul='*', truediv='/', floordiv='//', mod='%', matmul='@', pow='^', @@ -310,8 +306,6 @@ from sage.structure.parent cimport Parent from sage.cpython.type cimport can_assign_class from sage.cpython.getattr cimport getattr_from_other_class from sage.misc.lazy_format import LazyFormat -from sage.misc import sageinspect -from sage.misc.classcall_metaclass cimport ClasscallMetaclass from sage.arith.long cimport integer_check_long_py from sage.arith.power cimport generic_power as arith_generic_power from sage.arith.numerical_approx cimport digits_to_bits @@ -711,7 +705,6 @@ cdef class Element(SageObject): ... AssertionError: self.an_element() is not in self """ - from sage.categories.objects import Objects tester = self._tester(**options) SageObject._test_category(self, tester = tester) category = self.category() diff --git a/src/sage/structure/formal_sum.py b/src/sage/structure/formal_sum.py index 4552b62a546..7a788c3994f 100644 --- a/src/sage/structure/formal_sum.py +++ b/src/sage/structure/formal_sum.py @@ -49,7 +49,7 @@ True """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2004 William Stein # # Distributed under the terms of the GNU General Public License (GPL) @@ -61,8 +61,8 @@ # # The full text of the GPL is available at: # -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from sage.misc.repr import repr_lincomb import operator @@ -73,7 +73,7 @@ from sage.structure.richcmp import richcmp from sage.rings.integer_ring import ZZ from sage.structure.parent import Parent -from sage.structure.coerce import LeftModuleAction, RightModuleAction +from sage.structure.coerce_actions import LeftModuleAction, RightModuleAction from sage.categories.action import PrecomposedAction from sage.structure.unique_representation import UniqueRepresentation diff --git a/src/sage/structure/parent.pyx b/src/sage/structure/parent.pyx index e9cd5a71ed2..f3552e01d5a 100644 --- a/src/sage/structure/parent.pyx +++ b/src/sage/structure/parent.pyx @@ -103,7 +103,7 @@ This came up in some subtle bug once:: # https://www.gnu.org/licenses/ # **************************************************************************** -from cpython.object cimport PyObject, Py_NE, Py_EQ, Py_LE, Py_GE +from cpython.object cimport Py_EQ, Py_LE, Py_GE from cpython.bool cimport * from types import MethodType, BuiltinMethodType @@ -111,7 +111,6 @@ import operator from copy import copy from sage.cpython.type cimport can_assign_class -cimport sage.categories.morphism as morphism cimport sage.categories.map as map from sage.structure.debug_options cimport debug from sage.structure.sage_object cimport SageObject @@ -119,7 +118,7 @@ from sage.misc.cachefunc import cached_method from sage.misc.lazy_attribute import lazy_attribute from sage.categories.sets_cat import Sets, EmptySetError from sage.misc.lazy_string cimport _LazyString -from sage.sets.pythonclass cimport Set_PythonType_class, Set_PythonType +from sage.sets.pythonclass cimport Set_PythonType_class from .category_object import CategoryObject from .coerce cimport coercion_model from .coerce cimport parent_is_integers @@ -2597,7 +2596,6 @@ cdef class Parent(sage.structure.category_object.CategoryObject): # If needed, it will be passed to Left/RightModuleAction. from sage.categories.action import Action, PrecomposedAction from sage.categories.homset import Hom - from .coerce_actions import LeftModuleAction, RightModuleAction cdef Parent R for action in self._action_list: diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index a0c497dc65d..b0e5ae7cd48 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -205,22 +205,14 @@ cdef class SymbolicRing(sage.rings.abc.SymbolicRing): return False else: - from sage.rings.real_mpfr import mpfr_prec_min - from sage.rings.fraction_field import is_FractionField - from sage.rings.real_mpfi import is_RealIntervalField - from sage.rings.real_arb import RealBallField - from sage.rings.complex_arb import ComplexBallField from sage.rings.polynomial.polynomial_ring import is_PolynomialRing from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing from sage.rings.polynomial.laurent_polynomial_ring_base import LaurentPolynomialRing_generic - from sage.rings.complex_mpfr import ComplexField from sage.rings.infinity import InfinityRing, UnsignedInfinityRing from sage.rings.real_lazy import RLF, CLF from sage.rings.finite_rings.finite_field_base import FiniteField - from sage.interfaces.maxima import Maxima - from .subring import GenericSymbolicSubring if R._is_numerical(): From b9caf43501b31375d7c48d0b874ce1c2cee48f8f Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Mon, 29 May 2023 20:58:54 +0900 Subject: [PATCH 77/98] Change to make the linter happy. --- .../categories/finite_dimensional_lie_algebras_with_basis.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py index 051e5ba1b61..0c8940a3dd2 100644 --- a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py @@ -1755,7 +1755,6 @@ def to_prod(index): return UEA.sum(to_prod(index) for index in tens.support()) - class ElementMethods: def adjoint_matrix(self, sparse=False): # In #11111 (more or less) by using matrix of a morphism """ From b808b91ee99912d77622b0d91c562d27d18e275d Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Mon, 29 May 2023 22:38:22 +0900 Subject: [PATCH 78/98] FIxing one other latex formatting issue I missed. --- .../categories/finite_dimensional_lie_algebras_with_basis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py index 0c8940a3dd2..c8ab60cbba1 100644 --- a/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_lie_algebras_with_basis.py @@ -1618,7 +1618,7 @@ def casimir_element(self, order=2, UEA=None, force_generic=False): ALGORITHM: For the quadratic order (i.e., ``order=2``), then this uses - K^{ij}`, the inverse of the Killing form matrix, to compute + `K^{ij}`, the inverse of the Killing form matrix, to compute `C_{(2)} = \sum_{i,j} K^{ij} X_i \cdots X_j`, where `\{X_1, \ldots, X_n\}` is a basis for `\mathfrak{g}`. Otherwise this solves the system of equations From a10ce8ccbbf8a31ce6444556997d73be70b05cfc Mon Sep 17 00:00:00 2001 From: Daniel Krenn Date: Mon, 29 May 2023 19:49:39 +0200 Subject: [PATCH 79/98] Update src/sage/combinat/recognizable_series.py Co-authored-by: Travis Scrimshaw --- src/sage/combinat/recognizable_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/combinat/recognizable_series.py b/src/sage/combinat/recognizable_series.py index 2ee8faaa565..f717393edf0 100644 --- a/src/sage/combinat/recognizable_series.py +++ b/src/sage/combinat/recognizable_series.py @@ -457,7 +457,7 @@ def immutable(m): return m if isinstance(mu, dict): - mu = dict((a, immutable(Matrix(M))) for a, M in mu.items()) + mu = {a: Matrix(M, immutable=True) for a, M in mu.items()} mu = Family(mu) if not mu.is_finite(): From 841c4fe298738c12bc8d88f3325167918fcb802f Mon Sep 17 00:00:00 2001 From: Daniel Bump <75940445+dwbmscz@users.noreply.github.com> Date: Mon, 29 May 2023 11:00:29 -0700 Subject: [PATCH 80/98] Correct spelling in permgroup_named: Diyclic => DiCyclic --- src/sage/groups/perm_gps/permgroup_named.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/groups/perm_gps/permgroup_named.py b/src/sage/groups/perm_gps/permgroup_named.py index dbd529c8eb1..e166145f180 100644 --- a/src/sage/groups/perm_gps/permgroup_named.py +++ b/src/sage/groups/perm_gps/permgroup_named.py @@ -920,7 +920,7 @@ class DiCyclicGroup(PermutationGroup_unique): TESTS:: sage: groups.permutation.DiCyclic(6) - Diyclic group of order 24 as a permutation group + DiCyclic group of order 24 as a permutation group AUTHOR: @@ -976,9 +976,9 @@ def _repr_(self): EXAMPLES:: sage: DiCyclicGroup(12) - Diyclic group of order 48 as a permutation group + DiCyclic group of order 48 as a permutation group """ - return "Diyclic group of order %s as a permutation group"%self.order() + return "DiCyclic group of order %s as a permutation group"%self.order() def is_commutative(self): r""" From ded1602ef48f026a91356192f9019e57f40755b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 29 May 2023 20:52:25 +0200 Subject: [PATCH 81/98] some cosmetics --- src/sage/geometry/polyhedron/parent.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/sage/geometry/polyhedron/parent.py b/src/sage/geometry/polyhedron/parent.py index e891299ab15..ff868847471 100644 --- a/src/sage/geometry/polyhedron/parent.py +++ b/src/sage/geometry/polyhedron/parent.py @@ -193,7 +193,7 @@ def Polyhedra(ambient_space_or_base_ring=None, ambient_dim=None, backend=None, * return Polyhedra_field(base_ring.fraction_field(), ambient_dim, backend) else: raise ValueError('No such backend (=' + str(backend) + - ') implemented for given basering (=' + str(base_ring)+').') + ') implemented for given basering (=' + str(base_ring) + ').') class Polyhedra_base(UniqueRepresentation, Parent): @@ -400,7 +400,7 @@ def some_elements(self): points = [] R = self.base_ring() for i in range(self.ambient_dim() + 5): - points.append([R(i * j ^ 2) for j in range(self.ambient_dim())]) + points.append([R(i*j ^ 2) for j in range(self.ambient_dim())]) return [ self.element_class(self, [points[0:self.ambient_dim() + 1], [], []], None), self.element_class(self, [points[0:1], points[1:self.ambient_dim() + 1], []], None), @@ -421,7 +421,7 @@ def zero(self): sage: p + p == p True """ - Vrep = [[[self.base_ring().zero()]*self.ambient_dim()], [], []] + Vrep = [[[self.base_ring().zero()] * self.ambient_dim()], [], []] return self.element_class(self, Vrep, None) def empty(self): @@ -454,7 +454,7 @@ def universe(self): True """ R = self.base_ring() - return self(None, [[[R.one()]+[R.zero()]*self.ambient_dim()], []], convert=True) + return self(None, [[[R.one()] + [R.zero()] * self.ambient_dim()], []], convert=True) @cached_method def Vrepresentation_space(self): @@ -502,10 +502,9 @@ def Hrepresentation_space(self): """ if self.base_ring() in Fields(): from sage.modules.free_module import VectorSpace - return VectorSpace(self.base_ring(), self.ambient_dim()+1) - else: - from sage.modules.free_module import FreeModule - return FreeModule(self.base_ring(), self.ambient_dim()+1) + return VectorSpace(self.base_ring(), self.ambient_dim() + 1) + from sage.modules.free_module import FreeModule + return FreeModule(self.base_ring(), self.ambient_dim() + 1) def _repr_base_ring(self): """ @@ -574,7 +573,7 @@ def _repr_(self): sage: Polyhedra(QQ, 3)._repr_() 'Polyhedra in QQ^3' """ - return 'Polyhedra in '+self._repr_ambient_module() + return 'Polyhedra in ' + self._repr_ambient_module() def _element_constructor_(self, *args, **kwds): """ @@ -675,7 +674,7 @@ def convert_base_ring_Hrep(lstlst): if m == 0: newlstlst.append(lst) else: - newlstlst.append([q/m for q in lst]) + newlstlst.append([q / m for q in lst]) else: newlstlst.append(lst) return convert_base_ring(newlstlst) @@ -900,14 +899,14 @@ def _coerce_base_ring(self, other): except TypeError: pass if other_ring is None: - raise TypeError('Could not coerce '+str(other)+' into ZZ, QQ, or RDF.') + raise TypeError(f'Could not coerce {other} into ZZ, QQ, or RDF.') if not other_ring.is_exact(): other_ring = RDF # the only supported floating-point numbers for now cm_map, cm_ring = get_coercion_model().analyse(self.base_ring(), other_ring) if cm_ring is None: - raise TypeError('Could not coerce type '+str(other)+' into ZZ, QQ, or RDF.') + raise TypeError(f'Could not coerce type {other} into ZZ, QQ, or RDF.') return cm_ring def _coerce_map_from_(self, X): From 6d8bf99c4a07bdb8dc2137c2758a42225d666e3b Mon Sep 17 00:00:00 2001 From: Daniel Bump <75940445+dwbmscz@users.noreply.github.com> Date: Mon, 29 May 2023 18:51:33 -0700 Subject: [PATCH 82/98] one more misspelled DiCyclic --- src/sage/algebras/fusion_rings/fusion_double.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/algebras/fusion_rings/fusion_double.py b/src/sage/algebras/fusion_rings/fusion_double.py index 4904c5b13e7..8d6dd3c6586 100644 --- a/src/sage/algebras/fusion_rings/fusion_double.py +++ b/src/sage/algebras/fusion_rings/fusion_double.py @@ -711,7 +711,7 @@ def group(self): EXAMPLES:: sage: FusionDouble(DiCyclicGroup(4)).group() - Diyclic group of order 16 as a permutation group + DiCyclic group of order 16 as a permutation group """ return self._G From a2e6c6e6ff9c4e126f2ebddb7757f97f2d8f2591 Mon Sep 17 00:00:00 2001 From: "Rusydi H. Makarim" Date: Tue, 30 May 2023 07:11:08 +0400 Subject: [PATCH 83/98] fix for non-invertible sbox --- src/sage/crypto/sbox.pyx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/sage/crypto/sbox.pyx b/src/sage/crypto/sbox.pyx index 399e434def7..6b446a4d7c9 100644 --- a/src/sage/crypto/sbox.pyx +++ b/src/sage/crypto/sbox.pyx @@ -1410,6 +1410,12 @@ cdef class SBox(SageObject): sage: S = SBox([12,5,6,11,9,0,10,13,3,14,15,8,4,7,1,2]) sage: S.linear_branch_number() 2 + + TESTS:: + + sage: f = SBox([0, 2, 0, 6, 2, 2, 3, 7]) + sage: f.linear_branch_number() + 1 """ cdef Py_ssize_t m = self.m cdef Py_ssize_t n = self.n @@ -1417,8 +1423,8 @@ cdef class SBox(SageObject): cdef Py_ssize_t ret = (1 << m) + (1 << n) cdef Py_ssize_t a, b, w - for a in range(1, 1 << m): - for b in range(1 << n): + for a in range(1 << m): + for b in range(1, 1 << n): if lat.get_unsafe(a, b) != 0: w = hamming_weight(a) + hamming_weight(b) if w < ret: From 17a5859bbabc76aa5e66f3678db9056aae9b3782 Mon Sep 17 00:00:00 2001 From: Lorenz Panny Date: Fri, 29 Jul 2022 13:01:04 +0800 Subject: [PATCH 84/98] implement sparse strategy for prime-power isogenies --- src/doc/en/reference/references/index.rst | 5 + .../schemes/elliptic_curves/hom_composite.py | 103 ++++++++++++++---- 2 files changed, 89 insertions(+), 19 deletions(-) diff --git a/src/doc/en/reference/references/index.rst b/src/doc/en/reference/references/index.rst index fda85973f75..52f520395d6 100644 --- a/src/doc/en/reference/references/index.rst +++ b/src/doc/en/reference/references/index.rst @@ -2021,6 +2021,11 @@ REFERENCES: .. [DeVi1984] \M.-P. Delest, and G. Viennot, *Algebraic Languages and Polyominoes Enumeration.* Theoret. Comput. Sci. 34, 169-206, 1984. +.. [DJP2014] Luca De Feo, David Jao and Jérôme Plût: Towards quantum-resistant + cryptosystems from supersingular elliptic curve isogenies. Journal + of Mathematical Cryptology, vol. 8, no. 3, 2014, pp. 209-247. + https://eprint.iacr.org/2011/506.pdf + .. [DFMS1996] Philipppe Di Francesco, Pierre Mathieu, and David Sénéchal. *Conformal Field Theory*. Graduate Texts in Contemporary Physics, Springer, 1996. diff --git a/src/sage/schemes/elliptic_curves/hom_composite.py b/src/sage/schemes/elliptic_curves/hom_composite.py index a117e2e87d0..abbebccb98d 100644 --- a/src/sage/schemes/elliptic_curves/hom_composite.py +++ b/src/sage/schemes/elliptic_curves/hom_composite.py @@ -92,8 +92,6 @@ from sage.schemes.elliptic_curves.ell_curve_isogeny import EllipticCurveIsogeny from sage.schemes.elliptic_curves.weierstrass_morphism import WeierstrassIsomorphism, identity_morphism -# TODO: Implement sparse strategies? (cf. the SIKE cryptosystem) - def _eval_factored_isogeny(phis, P): """ @@ -120,33 +118,100 @@ def _eval_factored_isogeny(phis, P): return P -def _compute_factored_isogeny_prime_power(P, l, e): - """ - This method takes a point `P` of order `l^e` and returns - a sequence of degree-`l` isogenies whose composition has +def _compute_factored_isogeny_prime_power(P, l, n, split=.8): + r""" + This method takes a point `P` of order `\ell^n` and returns + a sequence of degree-`\ell` isogenies whose composition has the subgroup generated by `P` as its kernel. + The optional argument ``split``, a real number between + `0` and `1`, controls the *strategy* used to compute the + isogeny: In general, the algorithm performs a number of + scalar multiplications `[\ell]` and a number of + `\ell`-isogeny evaluations, and there exist tradeoffs + between them. + + - Setting ``split`` to `0` skews the algorithm towards + isogenies, minimizing multiplications. + The asymptotic complexity is `O(n \log(\ell) + n^2 \ell)`. + + - Setting ``split`` to `1` skews the algorithm towards + multiplications, minimizing isogenies. + The asymptotic complexity is `O(n^2 \log(\ell) + n \ell)`. + + - Values strictly between `0` and `1` define *sparse* + strategies, which balance the number of isogenies and + multiplications according to the parameter. + The asymptotic complexity is `O(n \log(n) \ell)`. + + .. NOTE:: + + As of July 2022, good values for ``split`` range somewhere + between roughly `0.6` and `0.9`, depending on the size of + `\ell` and the cost of base-field arithmetic. + + REFERENCES: + + Sparse strategies were introduced in [DJP2014]_, §4.2.2. + + ALGORITHM: + + The splitting rule implemented here is a simple heuristic which + is usually not optimal. The advantage is that it does not rely + on prior knowledge of degrees and exact costs of elliptic-curve + arithmetic, while still working reasonably well for a fairly + wide range of situations. + EXAMPLES:: sage: from sage.schemes.elliptic_curves import hom_composite sage: E = EllipticCurve(GF(8191), [1,0]) # optional - sage.rings.finite_rings sage: P = E.random_point() # optional - sage.rings.finite_rings - sage: (l,e), = P.order().factor() # optional - sage.rings.finite_rings - sage: phis = hom_composite._compute_factored_isogeny_prime_power(P, l, e) # optional - sage.rings.finite_rings + sage: (l,n), = P.order().factor() # optional - sage.rings.finite_rings + sage: phis = hom_composite._compute_factored_isogeny_prime_power(P, l, n) # optional - sage.rings.finite_rings sage: hom_composite._eval_factored_isogeny(phis, P) # optional - sage.rings.finite_rings (0 : 1 : 0) - sage: [phi.degree() for phi in phis] == [l]*e # optional - sage.rings.finite_rings + sage: [phi.degree() for phi in phis] == [l]*n # optional - sage.rings.finite_rings + True + + All choices of ``split`` produce the same result, albeit + not equally fast:: + + sage: E = EllipticCurve(GF(2^127 - 1), [1,0]) # optional - sage.rings.finite_rings + sage: P, = E.gens() # optional - sage.rings.finite_rings + sage: (l,n), = P.order().factor() # optional - sage.rings.finite_rings + sage: phis = hom_composite._compute_factored_isogeny_prime_power(P,l,n) # optional - sage.rings.finite_rings + sage: phis == hom_composite._compute_factored_isogeny_prime_power(P,l,n, split=0) # optional - sage.rings.finite_rings + True + sage: phis == hom_composite._compute_factored_isogeny_prime_power(P,l,n, split=0.1) # optional - sage.rings.finite_rings + True + sage: phis == hom_composite._compute_factored_isogeny_prime_power(P,l,n, split=0.5) # optional - sage.rings.finite_rings + True + sage: phis == hom_composite._compute_factored_isogeny_prime_power(P,l,n, split=0.9) # optional - sage.rings.finite_rings + True + sage: phis == hom_composite._compute_factored_isogeny_prime_power(P,l,n, split=1) # optional - sage.rings.finite_rings True """ - E = P.curve() - phis = [] - for i in range(e): - K = l**(e-1-i) * P - phi = EllipticCurveIsogeny(E, K) - E = phi.codomain() - P = phi(P) - phis.append(phi) - return phis + def rec(Q, k): + + if k == 1: + # base case: Q has order l + return [EllipticCurveIsogeny(Q.curve(), Q)] + + # recursive case: k > 1 and Q has order l^k + + k1 = int(k * split + .5) + k1 = max(1, min(k - 1, k1)) # clamp to [1, k - 1] + + Q1 = l**k1 * Q + L = rec(Q1, k - k1) + + Q2 = _eval_factored_isogeny(L, Q) + R = rec(Q2, k1) + + return L + R + + return rec(P, n) def _compute_factored_isogeny_single_generator(P): @@ -196,7 +261,7 @@ def _compute_factored_isogeny(kernel): phis = [] ker = list(kernel) while ker: - K, ker = ker[0], ker[1:] + K = ker.pop(0) psis = _compute_factored_isogeny_single_generator(K) ker = [_eval_factored_isogeny(psis, P) for P in ker] phis += psis From b39d8a37b8aed978e719943d2a896e0e8e9fa9cf Mon Sep 17 00:00:00 2001 From: Cyril Bouvier Date: Tue, 30 May 2023 11:47:04 +0200 Subject: [PATCH 85/98] Better error message --- src/sage/graphs/generic_graph.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index a040e6d45c8..8bf4ffb9482 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -1923,7 +1923,7 @@ def adjacency_matrix(self, sparse=None, vertices=None, *, base_ring=None, **kwds sage: Graph ([[0, 42, 'John'], [(42, 'John')]]).adjacency_matrix() Traceback (most recent call last): ... - TypeError: Vertices are not comparable, you must used the ``vertices`` parameter of the ``adjacency_matrix`` method to specify an ordering + TypeError: Vertex labels are not comparable. You must specify an ordering using parameter ``vertices`` sage: Graph ([[0, 42, 'John'], [(42, 'John')]]).adjacency_matrix(vertices=['John', 42, 0]) [0 1 0] [1 0 0] @@ -1939,7 +1939,7 @@ def adjacency_matrix(self, sparse=None, vertices=None, *, base_ring=None, **kwds try: vertices = self.vertices(sort=True) except TypeError: - raise TypeError ("Vertices are not comparable, you must used the ``vertices`` parameter of the ``adjacency_matrix`` method to specify an ordering") + raise TypeError ("Vertex labels are not comparable. You must specify an ordering using parameter ``vertices``") elif (len(vertices) != n or set(vertices) != set(self.vertex_iterator())): raise ValueError("``vertices`` must be a permutation of the vertices") From a7f0659f86156738926e5abf723a4004b17cd8f0 Mon Sep 17 00:00:00 2001 From: Cyril Bouvier Date: Tue, 30 May 2023 13:51:32 +0200 Subject: [PATCH 86/98] Adopt long line to 80cols --- src/sage/graphs/generic_graph.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 8bf4ffb9482..23e0dfea719 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -1939,7 +1939,9 @@ def adjacency_matrix(self, sparse=None, vertices=None, *, base_ring=None, **kwds try: vertices = self.vertices(sort=True) except TypeError: - raise TypeError ("Vertex labels are not comparable. You must specify an ordering using parameter ``vertices``") + raise TypeError ("Vertex labels are not comparable. You must " + "specify an ordering using parameter " + "``vertices``") elif (len(vertices) != n or set(vertices) != set(self.vertex_iterator())): raise ValueError("``vertices`` must be a permutation of the vertices") From f18b978714db434cf9e4b550a585aede1bed43ae Mon Sep 17 00:00:00 2001 From: Cyril Bouvier Date: Tue, 30 May 2023 13:55:34 +0200 Subject: [PATCH 87/98] Remove useless space --- src/sage/graphs/generic_graph.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 23e0dfea719..8573b1164da 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -1939,9 +1939,9 @@ def adjacency_matrix(self, sparse=None, vertices=None, *, base_ring=None, **kwds try: vertices = self.vertices(sort=True) except TypeError: - raise TypeError ("Vertex labels are not comparable. You must " - "specify an ordering using parameter " - "``vertices``") + raise TypeError("Vertex labels are not comparable. You must " + "specify an ordering using parameter " + "``vertices``") elif (len(vertices) != n or set(vertices) != set(self.vertex_iterator())): raise ValueError("``vertices`` must be a permutation of the vertices") From 4f47156f6c3810eb4decc1750a43a091d601be34 Mon Sep 17 00:00:00 2001 From: Daniel Bump <75940445+dwbmscz@users.noreply.github.com> Date: Tue, 30 May 2023 08:43:14 -0700 Subject: [PATCH 88/98] Use Dicyclic, not DiCyclic in the repr method of dicyclic groups --- src/sage/algebras/fusion_rings/fusion_double.py | 2 +- src/sage/groups/perm_gps/permgroup_named.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sage/algebras/fusion_rings/fusion_double.py b/src/sage/algebras/fusion_rings/fusion_double.py index 8d6dd3c6586..13fa276d8f0 100644 --- a/src/sage/algebras/fusion_rings/fusion_double.py +++ b/src/sage/algebras/fusion_rings/fusion_double.py @@ -711,7 +711,7 @@ def group(self): EXAMPLES:: sage: FusionDouble(DiCyclicGroup(4)).group() - DiCyclic group of order 16 as a permutation group + Dicyclic group of order 16 as a permutation group """ return self._G diff --git a/src/sage/groups/perm_gps/permgroup_named.py b/src/sage/groups/perm_gps/permgroup_named.py index e166145f180..746cd5ddbab 100644 --- a/src/sage/groups/perm_gps/permgroup_named.py +++ b/src/sage/groups/perm_gps/permgroup_named.py @@ -920,7 +920,7 @@ class DiCyclicGroup(PermutationGroup_unique): TESTS:: sage: groups.permutation.DiCyclic(6) - DiCyclic group of order 24 as a permutation group + Dicyclic group of order 24 as a permutation group AUTHOR: @@ -976,9 +976,9 @@ def _repr_(self): EXAMPLES:: sage: DiCyclicGroup(12) - DiCyclic group of order 48 as a permutation group + Dicyclic group of order 48 as a permutation group """ - return "DiCyclic group of order %s as a permutation group"%self.order() + return "Dicyclic group of order %s as a permutation group"%self.order() def is_commutative(self): r""" From 1a2e9f5ecbbf8c94b3cac35402f5d3ef262578d8 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 31 May 2023 08:13:17 +0200 Subject: [PATCH 89/98] 35172: vars.SYNC_LABELS_BIDIRECT -> vars.SYNC_LABELS_IGNORE_EVENTS --- .github/workflows/sync_labels.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/sync_labels.yml b/.github/workflows/sync_labels.yml index 0171fdb427b..acc02862657 100644 --- a/.github/workflows/sync_labels.yml +++ b/.github/workflows/sync_labels.yml @@ -20,10 +20,7 @@ on: jobs: synchronize: if: | # check variables from repository settings to suspend the job - vars.SYNC_LABELS_ACTIVE == 'yes' && ( - vars.SYNC_LABELS_BIDIRECT == 'yes' || - github.event.action != 'labeled' && - github.event.action != 'unlabeled') + vars.SYNC_LABELS_ACTIVE == 'yes' && ! contains(vars.SYNC_LABELS_IGNORE_EVENTS, github.event.action) runs-on: ubuntu-latest steps: # Checkout the Python script From 5c1ec45c4c7bb62e3d7be333e00e89030494df30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Wed, 31 May 2023 08:50:52 +0200 Subject: [PATCH 90/98] cylint: remove imports in misc/ --- src/sage/misc/binary_tree.pyx | 1 - src/sage/misc/fpickle.pyx | 27 ++++++++++++++++----------- src/sage/misc/misc_c.pyx | 2 -- src/sage/misc/parser.pyx | 4 +--- src/sage/misc/randstate.pyx | 2 -- src/sage/misc/session.pyx | 3 +-- src/sage/misc/weak_dict.pyx | 4 +--- 7 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/sage/misc/binary_tree.pyx b/src/sage/misc/binary_tree.pyx index 8827cac9ef2..c0fe8310c9b 100644 --- a/src/sage/misc/binary_tree.pyx +++ b/src/sage/misc/binary_tree.pyx @@ -63,7 +63,6 @@ cdef object binary_tree_get(binary_tree_node *self, int key): cdef object binary_tree_delete(binary_tree_node *self, int key): cdef object t - cdef binary_tree_node *cur if self.key > key: if self.left == NULL: return None diff --git a/src/sage/misc/fpickle.pyx b/src/sage/misc/fpickle.pyx index 793041d1422..08212b996f9 100644 --- a/src/sage/misc/fpickle.pyx +++ b/src/sage/misc/fpickle.pyx @@ -5,7 +5,6 @@ Function pickling REFERENCE: The python cookbook. """ - import copyreg import pickle import sys @@ -91,6 +90,7 @@ def pickle_function(func): """ return pickle.dumps(func.__code__) + def unpickle_function(pickled): """ Unpickle a pickled function. @@ -106,15 +106,16 @@ def unpickle_function(pickled): return types.FunctionType(recovered, globals()) - def call_pickled_function(fpargs): import sage.all - from sage.misc.fpickle import unpickle_function + from sage.misc.fpickle import unpickle_function # used below (fp, (args, kwds)) = fpargs - f = eval("unpickle_function(fp)", sage.all.__dict__, {'fp':fp}) - res = eval("f(*args, **kwds)",sage.all.__dict__, {'args':args, 'kwds':kwds, 'f':f}) + f = eval("unpickle_function(fp)", sage.all.__dict__, {'fp': fp}) + res = eval("f(*args, **kwds)", sage.all.__dict__, + {'args': args, 'kwds': kwds, 'f': f}) return ((args, kwds), res) + # The following four methods are taken from twisted.persisted.styles - the # import of twisted.persisted.styles takes a long time and we do not use # most functionality it provides @@ -128,11 +129,11 @@ def pickleMethod(method): def unpickleMethod(im_name, - __self__, - im_class): + __self__, + im_class): 'support function for copyreg to unpickle method refs' try: - unbound = getattr(im_class,im_name) + unbound = getattr(im_class, im_name) if __self__ is None: return unbound @@ -154,21 +155,25 @@ def unpickleMethod(im_name, __self__) return bound + copyreg.pickle(types.MethodType, - pickleMethod, - unpickleMethod) + pickleMethod, + unpickleMethod) oldModules = {} + def pickleModule(module): 'support function for copyreg to pickle module refs' return unpickleModule, (module.__name__,) + def unpickleModule(name): 'support function for copyreg to unpickle module refs' if name in oldModules: name = oldModules[name] - return __import__(name,{},{},'x') + return __import__(name, {}, {}, 'x') + copyreg.pickle(types.ModuleType, pickleModule, diff --git a/src/sage/misc/misc_c.pyx b/src/sage/misc/misc_c.pyx index 20a0fe0016c..d5492ba1e00 100644 --- a/src/sage/misc/misc_c.pyx +++ b/src/sage/misc/misc_c.pyx @@ -23,8 +23,6 @@ AUTHORS: # https://www.gnu.org/licenses/ # **************************************************************************** -import sys - from cpython.sequence cimport * from cpython.list cimport * from cpython.tuple cimport * diff --git a/src/sage/misc/parser.pyx b/src/sage/misc/parser.pyx index 29d7a9cd7a0..78c2d6d0169 100644 --- a/src/sage/misc/parser.pyx +++ b/src/sage/misc/parser.pyx @@ -20,8 +20,6 @@ AUTHOR: # https://www.gnu.org/licenses/ # *************************************************************************** -from libc.string cimport strchr -from cpython.bytes cimport PyBytes_FromStringAndSize from cpython.list cimport PyList_Append import math @@ -1095,4 +1093,4 @@ cdef class LookupNameMaker: except KeyError: if self.fallback is not None: return self.fallback(name) - raise NameError("Unknown variable: '{}'".format(name)) + raise NameError(f"Unknown variable: '{name}'") diff --git a/src/sage/misc/randstate.pyx b/src/sage/misc/randstate.pyx index 4af9306cb63..e9f3db46753 100644 --- a/src/sage/misc/randstate.pyx +++ b/src/sage/misc/randstate.pyx @@ -419,7 +419,6 @@ import os import time import weakref import random as _random -import sys use_urandom = False # Check whether os.urandom() works. @@ -713,7 +712,6 @@ cdef class randstate: if self._gap_saved_seed is not None: mersenne_seed, classic_seed = self._gap_saved_seed else: - import sage.rings.integer_ring as integer_ring from sage.rings.integer_ring import ZZ seed = ZZ.random_element(long(1)<<128) classic_seed = seed diff --git a/src/sage/misc/session.pyx b/src/sage/misc/session.pyx index d1aa84b92af..de649f80425 100644 --- a/src/sage/misc/session.pyx +++ b/src/sage/misc/session.pyx @@ -61,12 +61,11 @@ AUTHOR: # Copyright (C) 2007,2010 William Stein # Distributed under the terms of the GNU General Public License (GPL) # The full text of the GPL is available at: -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ ############################################################################# # Standard python imports import builtins -import os import types # We want the caller's locals, but locals() is emulated in Cython diff --git a/src/sage/misc/weak_dict.pyx b/src/sage/misc/weak_dict.pyx index 9202e96c99e..59a399fed20 100644 --- a/src/sage/misc/weak_dict.pyx +++ b/src/sage/misc/weak_dict.pyx @@ -118,15 +118,13 @@ See :trac:`13394` for a discussion of some of the design considerations. # https://www.gnu.org/licenses/ # **************************************************************************** -import weakref from weakref import KeyedRef from copy import deepcopy from cpython.dict cimport PyDict_SetItem, PyDict_Next from cpython.tuple cimport PyTuple_GET_SIZE, PyTuple_New from cpython.weakref cimport PyWeakref_NewRef -from cpython.object cimport PyObject_Hash -from cpython.ref cimport Py_INCREF, Py_XINCREF, Py_XDECREF +from cpython.ref cimport Py_INCREF from sage.cpython.dict_del_by_value cimport * from sage.misc.superseded import deprecation From 909f7671692564d953f89faf722cde1350ca1c73 Mon Sep 17 00:00:00 2001 From: Vincent Delecroix Date: Wed, 31 May 2023 12:54:13 +0200 Subject: [PATCH 91/98] Fix corner case of ordered set partitions iteration --- src/sage/combinat/set_partition_ordered.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/sage/combinat/set_partition_ordered.py b/src/sage/combinat/set_partition_ordered.py index b883df5cb98..d5dae5ba617 100644 --- a/src/sage/combinat/set_partition_ordered.py +++ b/src/sage/combinat/set_partition_ordered.py @@ -1114,6 +1114,13 @@ def __iter__(self): [{1, 3}, {2}], [{2, 3}, {1}], [{1, 2, 3}]] + + TESTS: + + Test for :issue:`35654`:: + + sage: OrderedSetPartitions(set(),[0,0,0]).list() + [[{}, {}, {}]] """ for x in Compositions(len(self._set)): for z in OrderedSetPartitions(self._set, x): @@ -1379,11 +1386,18 @@ def multiset_permutation_next_lex(l): [2, 1, 0, 0, 1] [2, 1, 0, 1, 0] [2, 1, 1, 0, 0] + + TESTS: + + Test for :issue:`35654`:: + + sage: multiset_permutation_next_lex([]) + 0 """ i = len(l) - 2 while i >= 0 and l[i] >= l[i + 1]: i -= 1 - if i == -1: + if i <= -1: return 0 j = len(l) - 1 while l[j] <= l[i]: From bf4789e95837430b1db2d6ecb6e135ed66454376 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 31 May 2023 14:50:48 +0200 Subject: [PATCH 92/98] GAP: fix definition of 'Int' The GAP Int type, like UInt, has the size of a machine pointer (at least on the usual desktop system architectures), not a machine int. I.e. on a typical 64bit OS it is a 64bit integer, not a 32bit integer. This often makes no difference on little endian systems but can have disastrous consequences for large values or on big endian systems. Also fix a copy&paste mistake in the `make_gap_integer` argument name. --- src/sage/libs/gap/element.pxd | 2 +- src/sage/libs/gap/gap_includes.pxd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/libs/gap/element.pxd b/src/sage/libs/gap/element.pxd index a1bf8118d4f..d6bf4f8b3ff 100644 --- a/src/sage/libs/gap/element.pxd +++ b/src/sage/libs/gap/element.pxd @@ -15,7 +15,7 @@ from sage.structure.element cimport Element, ModuleElement, RingElement cdef Obj make_gap_list(sage_list) except NULL cdef Obj make_gap_matrix(sage_list, gap_ring) except NULL cdef Obj make_gap_record(sage_dict) except NULL -cdef Obj make_gap_integer(sage_dict) except NULL +cdef Obj make_gap_integer(sage_int) except NULL cdef Obj make_gap_string(sage_string) except NULL cdef GapElement make_any_gap_element(parent, Obj obj) diff --git a/src/sage/libs/gap/gap_includes.pxd b/src/sage/libs/gap/gap_includes.pxd index 5cbffa54021..f3467e89051 100644 --- a/src/sage/libs/gap/gap_includes.pxd +++ b/src/sage/libs/gap/gap_includes.pxd @@ -13,7 +13,7 @@ from libc.stdint cimport uintptr_t, uint8_t, uint16_t, uint32_t, uint64_t cdef extern from "gap/system.h" nogil: ctypedef char Char - ctypedef int Int + ctypedef intptr_t Int ctypedef uintptr_t UInt ctypedef uint8_t UInt1 ctypedef uint16_t UInt2 From b8b09abcdfbdaa36cc8906e55ae3a745b658d11a Mon Sep 17 00:00:00 2001 From: sheerluck Date: Wed, 31 May 2023 22:56:41 +0300 Subject: [PATCH 93/98] Remove gentoo-python3.9 --- .github/workflows/docker.yml | 1 - tox.ini | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 307490406c9..178bb50a064 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -47,7 +47,6 @@ on: "centos-7-devtoolset-gcc_11", "centos-stream-8-python3.9", "centos-stream-9-python3.9", - "gentoo-python3.9", "gentoo-python3.10", "gentoo-python3.11", "archlinux-latest", diff --git a/tox.ini b/tox.ini index 80b9c18cff5..db48a7e80d5 100644 --- a/tox.ini +++ b/tox.ini @@ -307,7 +307,6 @@ setenv = # gentoo: SYSTEM=gentoo gentoo: BASE_IMAGE=sheerluck/sage-on-gentoo-stage4 - gentoo-python3.9: BASE_TAG=latest-py39 gentoo-python3.10: BASE_TAG=latest-py10 gentoo-python3.11: BASE_TAG=latest-py11 gentoo: IGNORE_MISSING_SYSTEM_PACKAGES=no From db93a1a715813a5ba47d15e260c0d72ed86786cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 2 Jun 2023 08:00:33 +0200 Subject: [PATCH 94/98] Update gap_includes.pxd add missing import --- src/sage/libs/gap/gap_includes.pxd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/libs/gap/gap_includes.pxd b/src/sage/libs/gap/gap_includes.pxd index f3467e89051..4a1ab942cbf 100644 --- a/src/sage/libs/gap/gap_includes.pxd +++ b/src/sage/libs/gap/gap_includes.pxd @@ -9,7 +9,7 @@ # http://www.gnu.org/licenses/ ############################################################################### -from libc.stdint cimport uintptr_t, uint8_t, uint16_t, uint32_t, uint64_t +from libc.stdint cimport intptr_t, uintptr_t, uint8_t, uint16_t, uint32_t, uint64_t cdef extern from "gap/system.h" nogil: ctypedef char Char From 8eb6854650a79782a475c5903277c089d76eeedc Mon Sep 17 00:00:00 2001 From: Sebastian Oehms Date: Fri, 2 Jun 2023 09:00:54 +0200 Subject: [PATCH 95/98] 35172: use Json array for SYNC_LABELS_IGNORE_EVENTS --- .github/workflows/sync_labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync_labels.yml b/.github/workflows/sync_labels.yml index acc02862657..ec2f61ab53f 100644 --- a/.github/workflows/sync_labels.yml +++ b/.github/workflows/sync_labels.yml @@ -20,7 +20,7 @@ on: jobs: synchronize: if: | # check variables from repository settings to suspend the job - vars.SYNC_LABELS_ACTIVE == 'yes' && ! contains(vars.SYNC_LABELS_IGNORE_EVENTS, github.event.action) + vars.SYNC_LABELS_ACTIVE == 'yes' && (! vars.SYNC_LABELS_IGNORE_EVENTS || ! contains(fromJSON(vars.SYNC_LABELS_IGNORE_EVENTS), github.event.action)) runs-on: ubuntu-latest steps: # Checkout the Python script From 54002f2d298c8125570fab7f31f19a86a3bafb61 Mon Sep 17 00:00:00 2001 From: Sebastian Oehms Date: Fri, 2 Jun 2023 17:59:38 +0200 Subject: [PATCH 96/98] 36172: Title corrections according to review --- .github/sync_labels.py | 2 +- .github/workflows/sync_labels.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/sync_labels.py b/.github/sync_labels.py index 05fa1459b5e..c920d21fca4 100755 --- a/.github/sync_labels.py +++ b/.github/sync_labels.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- r""" -Python script to sync labels that are migrated from Trac selection lists. +Python script to sync status and priority labels. For more information see https://github.com/sagemath/sage/pull/35172 """ diff --git a/.github/workflows/sync_labels.yml b/.github/workflows/sync_labels.yml index ec2f61ab53f..f9378d1fe9d 100644 --- a/.github/workflows/sync_labels.yml +++ b/.github/workflows/sync_labels.yml @@ -4,7 +4,7 @@ # Furthermore in the case of the state it checks the labels # to coincide with the corresponding review state. -name: Synchronize selection list lables +name: Synchronize labels on: issues: From b9bf5bbe02e8de5e87e069925ab82d14c1922e9e Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 2 Jun 2023 11:04:02 -0700 Subject: [PATCH 97/98] src/sage/rings/lazy_series.py: Add # optional - sage.rings.number_field --- src/sage/rings/lazy_series.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sage/rings/lazy_series.py b/src/sage/rings/lazy_series.py index f5440ead30e..d1647ec445f 100644 --- a/src/sage/rings/lazy_series.py +++ b/src/sage/rings/lazy_series.py @@ -175,9 +175,9 @@ sage: check(L, lambda n: n, valuation=-5) # optional - sage.rings.finite_rings sage: check(L, gen(), valuation=-5) # optional - sage.rings.finite_rings - sage: L = LazyDirichletSeriesRing(QQbar, "s") - sage: check(L, lambda n: n, valuation=2) - sage: check(L, gen(), valuation=2) + sage: L = LazyDirichletSeriesRing(QQbar, "s") # optional - sage.rings.number_field + sage: check(L, lambda n: n, valuation=2) # optional - sage.rings.number_field + sage: check(L, gen(), valuation=2) # optional - sage.rings.number_field sage: L. = LazyPowerSeriesRing(GF(2)) # optional - sage.rings.finite_rings sage: check(L, lambda n: n, valuation=0) # optional - sage.rings.finite_rings @@ -296,9 +296,9 @@ def __init__(self, parent, coeff_stream): sage: L. = LazyLaurentSeriesRing(ZZ) sage: TestSuite(L.an_element()).run() - sage: L = LazyDirichletSeriesRing(QQbar, 'z') - sage: g = L(constant=1) - sage: TestSuite(g).run() + sage: L = LazyDirichletSeriesRing(QQbar, 'z') # optional - sage.rings.number_field + sage: g = L(constant=1) # optional - sage.rings.number_field + sage: TestSuite(g).run() # optional - sage.rings.number_field """ Element.__init__(self, parent) self._coeff_stream = coeff_stream From 2f426a11f4c38e8e73ccd3f39374a74aa08e91ab Mon Sep 17 00:00:00 2001 From: Release Manager Date: Sun, 4 Jun 2023 01:16:42 +0200 Subject: [PATCH 98/98] Updated SageMath version to 10.1.beta2 --- .zenodo.json | 8 ++++---- VERSION.txt | 2 +- build/pkgs/configure/checksums.ini | 6 +++--- build/pkgs/configure/package-version.txt | 2 +- build/pkgs/sage_conf/install-requires.txt | 2 +- build/pkgs/sage_docbuild/install-requires.txt | 2 +- build/pkgs/sage_setup/install-requires.txt | 2 +- build/pkgs/sage_sws2rst/install-requires.txt | 2 +- build/pkgs/sagelib/install-requires.txt | 2 +- build/pkgs/sagemath_categories/install-requires.txt | 2 +- build/pkgs/sagemath_environment/install-requires.txt | 2 +- build/pkgs/sagemath_objects/install-requires.txt | 2 +- build/pkgs/sagemath_repl/install-requires.txt | 2 +- pkgs/sage-conf/VERSION.txt | 2 +- pkgs/sage-conf_pypi/VERSION.txt | 2 +- pkgs/sage-docbuild/VERSION.txt | 2 +- pkgs/sage-setup/VERSION.txt | 2 +- pkgs/sage-sws2rst/VERSION.txt | 2 +- pkgs/sagemath-categories/VERSION.txt | 2 +- pkgs/sagemath-environment/VERSION.txt | 2 +- pkgs/sagemath-objects/VERSION.txt | 2 +- pkgs/sagemath-repl/VERSION.txt | 2 +- src/VERSION.txt | 2 +- src/bin/sage-version.sh | 6 +++--- src/sage/version.py | 6 +++--- 25 files changed, 34 insertions(+), 34 deletions(-) diff --git a/.zenodo.json b/.zenodo.json index 97103250fe1..0072019287e 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -1,10 +1,10 @@ { "description": "Mirror of the Sage https://sagemath.org/ source tree", "license": "other-open", - "title": "sagemath/sage: 10.1.beta1", - "version": "10.1.beta1", + "title": "sagemath/sage: 10.1.beta2", + "version": "10.1.beta2", "upload_type": "software", - "publication_date": "2023-05-28", + "publication_date": "2023-06-03", "creators": [ { "affiliation": "SageMath.org", @@ -15,7 +15,7 @@ "related_identifiers": [ { "scheme": "url", - "identifier": "https://github.com/sagemath/sage/tree/10.1.beta1", + "identifier": "https://github.com/sagemath/sage/tree/10.1.beta2", "relation": "isSupplementTo" }, { diff --git a/VERSION.txt b/VERSION.txt index 9cdd3f93482..c4c9b181ed8 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -SageMath version 10.1.beta1, Release Date: 2023-05-28 +SageMath version 10.1.beta2, Release Date: 2023-06-03 diff --git a/build/pkgs/configure/checksums.ini b/build/pkgs/configure/checksums.ini index 073256acb1a..aba45904375 100644 --- a/build/pkgs/configure/checksums.ini +++ b/build/pkgs/configure/checksums.ini @@ -1,4 +1,4 @@ tarball=configure-VERSION.tar.gz -sha1=828899494028e64e114575d588ddb389ab8d3934 -md5=cea4edd6bca8a8ad4b654919dfa90ad1 -cksum=1753584513 +sha1=05ff783186ba44f6afec3fad5fecea42acb32db6 +md5=ecd17bd2d001b1c17586fa7877550bf9 +cksum=1852648534 diff --git a/build/pkgs/configure/package-version.txt b/build/pkgs/configure/package-version.txt index 8962f1ff62e..4d8c8abae1e 100644 --- a/build/pkgs/configure/package-version.txt +++ b/build/pkgs/configure/package-version.txt @@ -1 +1 @@ -9585a189b3d64daf382d733eb625f221509d731b +17aa7f7ea5b8522f028ef5a87613f1979978a748 diff --git a/build/pkgs/sage_conf/install-requires.txt b/build/pkgs/sage_conf/install-requires.txt index 8a5ab548d0c..d50a8e7117e 100644 --- a/build/pkgs/sage_conf/install-requires.txt +++ b/build/pkgs/sage_conf/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sage-conf ~= 10.1b1 +sage-conf ~= 10.1b2 diff --git a/build/pkgs/sage_docbuild/install-requires.txt b/build/pkgs/sage_docbuild/install-requires.txt index 7cb7b7017b7..bd6be79c3ef 100644 --- a/build/pkgs/sage_docbuild/install-requires.txt +++ b/build/pkgs/sage_docbuild/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sage-docbuild ~= 10.1b1 +sage-docbuild ~= 10.1b2 diff --git a/build/pkgs/sage_setup/install-requires.txt b/build/pkgs/sage_setup/install-requires.txt index 9e4fd055191..e2f10b4a6b5 100644 --- a/build/pkgs/sage_setup/install-requires.txt +++ b/build/pkgs/sage_setup/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sage-setup ~= 10.1b1 +sage-setup ~= 10.1b2 diff --git a/build/pkgs/sage_sws2rst/install-requires.txt b/build/pkgs/sage_sws2rst/install-requires.txt index e96243d443f..cae34b0b6fe 100644 --- a/build/pkgs/sage_sws2rst/install-requires.txt +++ b/build/pkgs/sage_sws2rst/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sage-sws2rst ~= 10.1b1 +sage-sws2rst ~= 10.1b2 diff --git a/build/pkgs/sagelib/install-requires.txt b/build/pkgs/sagelib/install-requires.txt index ad7980ea6fa..35c2a8040ec 100644 --- a/build/pkgs/sagelib/install-requires.txt +++ b/build/pkgs/sagelib/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagelib ~= 10.1b1 +sagelib ~= 10.1b2 diff --git a/build/pkgs/sagemath_categories/install-requires.txt b/build/pkgs/sagemath_categories/install-requires.txt index 466d34772ac..1b18527c75d 100644 --- a/build/pkgs/sagemath_categories/install-requires.txt +++ b/build/pkgs/sagemath_categories/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-categories ~= 10.1b1 +sagemath-categories ~= 10.1b2 diff --git a/build/pkgs/sagemath_environment/install-requires.txt b/build/pkgs/sagemath_environment/install-requires.txt index 631a8e84280..dddc4170942 100644 --- a/build/pkgs/sagemath_environment/install-requires.txt +++ b/build/pkgs/sagemath_environment/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-environment ~= 10.1b1 +sagemath-environment ~= 10.1b2 diff --git a/build/pkgs/sagemath_objects/install-requires.txt b/build/pkgs/sagemath_objects/install-requires.txt index 9cb7e0a9f89..8254467164b 100644 --- a/build/pkgs/sagemath_objects/install-requires.txt +++ b/build/pkgs/sagemath_objects/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-objects ~= 10.1b1 +sagemath-objects ~= 10.1b2 diff --git a/build/pkgs/sagemath_repl/install-requires.txt b/build/pkgs/sagemath_repl/install-requires.txt index c6319b340ce..6b98d320073 100644 --- a/build/pkgs/sagemath_repl/install-requires.txt +++ b/build/pkgs/sagemath_repl/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-repl ~= 10.1b1 +sagemath-repl ~= 10.1b2 diff --git a/pkgs/sage-conf/VERSION.txt b/pkgs/sage-conf/VERSION.txt index 74e3c313022..05e26b17161 100644 --- a/pkgs/sage-conf/VERSION.txt +++ b/pkgs/sage-conf/VERSION.txt @@ -1 +1 @@ -10.1.beta1 +10.1.beta2 diff --git a/pkgs/sage-conf_pypi/VERSION.txt b/pkgs/sage-conf_pypi/VERSION.txt index 74e3c313022..05e26b17161 100644 --- a/pkgs/sage-conf_pypi/VERSION.txt +++ b/pkgs/sage-conf_pypi/VERSION.txt @@ -1 +1 @@ -10.1.beta1 +10.1.beta2 diff --git a/pkgs/sage-docbuild/VERSION.txt b/pkgs/sage-docbuild/VERSION.txt index 74e3c313022..05e26b17161 100644 --- a/pkgs/sage-docbuild/VERSION.txt +++ b/pkgs/sage-docbuild/VERSION.txt @@ -1 +1 @@ -10.1.beta1 +10.1.beta2 diff --git a/pkgs/sage-setup/VERSION.txt b/pkgs/sage-setup/VERSION.txt index 74e3c313022..05e26b17161 100644 --- a/pkgs/sage-setup/VERSION.txt +++ b/pkgs/sage-setup/VERSION.txt @@ -1 +1 @@ -10.1.beta1 +10.1.beta2 diff --git a/pkgs/sage-sws2rst/VERSION.txt b/pkgs/sage-sws2rst/VERSION.txt index 74e3c313022..05e26b17161 100644 --- a/pkgs/sage-sws2rst/VERSION.txt +++ b/pkgs/sage-sws2rst/VERSION.txt @@ -1 +1 @@ -10.1.beta1 +10.1.beta2 diff --git a/pkgs/sagemath-categories/VERSION.txt b/pkgs/sagemath-categories/VERSION.txt index 74e3c313022..05e26b17161 100644 --- a/pkgs/sagemath-categories/VERSION.txt +++ b/pkgs/sagemath-categories/VERSION.txt @@ -1 +1 @@ -10.1.beta1 +10.1.beta2 diff --git a/pkgs/sagemath-environment/VERSION.txt b/pkgs/sagemath-environment/VERSION.txt index 74e3c313022..05e26b17161 100644 --- a/pkgs/sagemath-environment/VERSION.txt +++ b/pkgs/sagemath-environment/VERSION.txt @@ -1 +1 @@ -10.1.beta1 +10.1.beta2 diff --git a/pkgs/sagemath-objects/VERSION.txt b/pkgs/sagemath-objects/VERSION.txt index 74e3c313022..05e26b17161 100644 --- a/pkgs/sagemath-objects/VERSION.txt +++ b/pkgs/sagemath-objects/VERSION.txt @@ -1 +1 @@ -10.1.beta1 +10.1.beta2 diff --git a/pkgs/sagemath-repl/VERSION.txt b/pkgs/sagemath-repl/VERSION.txt index 74e3c313022..05e26b17161 100644 --- a/pkgs/sagemath-repl/VERSION.txt +++ b/pkgs/sagemath-repl/VERSION.txt @@ -1 +1 @@ -10.1.beta1 +10.1.beta2 diff --git a/src/VERSION.txt b/src/VERSION.txt index 74e3c313022..05e26b17161 100644 --- a/src/VERSION.txt +++ b/src/VERSION.txt @@ -1 +1 @@ -10.1.beta1 +10.1.beta2 diff --git a/src/bin/sage-version.sh b/src/bin/sage-version.sh index 45af95e04a7..1a398cd9676 100644 --- a/src/bin/sage-version.sh +++ b/src/bin/sage-version.sh @@ -4,6 +4,6 @@ # which stops "setup.py develop" from rewriting it as a Python file. : # This file is auto-generated by the sage-update-version script, do not edit! -SAGE_VERSION='10.1.beta1' -SAGE_RELEASE_DATE='2023-05-28' -SAGE_VERSION_BANNER='SageMath version 10.1.beta1, Release Date: 2023-05-28' +SAGE_VERSION='10.1.beta2' +SAGE_RELEASE_DATE='2023-06-03' +SAGE_VERSION_BANNER='SageMath version 10.1.beta2, Release Date: 2023-06-03' diff --git a/src/sage/version.py b/src/sage/version.py index 5cb86f018bb..0ac9bf873ed 100644 --- a/src/sage/version.py +++ b/src/sage/version.py @@ -1,5 +1,5 @@ # Sage version information for Python scripts # This file is auto-generated by the sage-update-version script, do not edit! -version = '10.1.beta1' -date = '2023-05-28' -banner = 'SageMath version 10.1.beta1, Release Date: 2023-05-28' +version = '10.1.beta2' +date = '2023-06-03' +banner = 'SageMath version 10.1.beta2, Release Date: 2023-06-03'