Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Commit

Permalink
Remove shift()
Browse files Browse the repository at this point in the history
it is inconsistent with shifts everywhere else (not dropping coefficients) and
it also is not really useful as it can not be implemented everywhere.

This might cause some performance regression.
  • Loading branch information
saraedum committed Nov 28, 2016
1 parent d0d2661 commit 6a3126c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 339 deletions.
65 changes: 1 addition & 64 deletions augmented_valuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def equivalence_unit(self, s):
sage: w.equivalence_unit(3/2)
Traceback (most recent call last):
...
ValueError: 3/2 is not in the value group of 2-adic valuation
ValueError: 3/2 is not in the value semigroup of 2-adic valuation
sage: w.equivalence_unit(1)
2 + O(2^6)
Expand Down Expand Up @@ -462,69 +462,6 @@ def element_with_valuation(self, s):
s -= self._mu
return ret * self._base_valuation.element_with_valuation(s)

def shift(self, x, s):
r"""
Return a modified version of ``x`` whose valuation is increased by ``s``.
The element returned is such that repeated shifts which go back to
the original valuation produce the same element in reduction.
EXAMPLES::
sage: from mac_lane import * # optional: standalone
sage: R.<x> = QQ[]
sage: v = GaussValuation(R, pAdicValuation(QQ, 2))
sage: w = v.augmentation(x, 1)
sage: w.shift(1, 1)
2
Whenever there is ramification, a shift with such consistency is not
possible::
sage: w = v.augmentation(x, 1/2)
sage: w.shift(1, -1/2)
Traceback (most recent call last):
...
NotImplementedError: Shifts with consistent reduction not implemented for this augmented valuation
Multiplication by an :meth:`element_with_valuation` might sometimes
produce useful results in such cases::
sage: 1 * w.element_with_valuation(-1/2)
1/2*x
However, this does not preserve the element in reduction::
sage: 1 * w.element_with_valuation(-1/2) * w.element_with_valuation(1/2)
1/2*x^2
In general this is only possible by using an
:meth:`equivalence_unit` and its :meth:`equialence_reciprocal`.
These do, however, not exist for all values of ``s``.
"""
from sage.categories.fields import Fields
if not self.domain().base_ring() in Fields():
raise NotImplementedError("only implemented for polynomial rings over fields")

if s not in self.value_group():
raise ValueError("s must be in the value group of the valuation")

if self.value_group() == self._base_valuation.value_group():
return self._base_valuation.shift(x, s)

if self._base_valuation.value_group().is_trivial():
# We could implement a consistent shift in this case by multplying
# and dividing by powers of the key polynomial. Since an element of
# positive valuation has to be a power of the key polynomial, there
# can be no ambiguity here
raise NotImplementedError("Shifts with consistent reduction not implemented for augmented valuations over trivial valuations")

# Except for very few special cases, it is not possible to implement a
# consistent shift for augmented valuations
raise NotImplementedError("Shifts with consistent reduction not implemented for this augmented valuation")

def _repr_(self):
"""
Return a printable representation of this valuation.
Expand Down
58 changes: 1 addition & 57 deletions gauss_valuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,61 +242,6 @@ def uniformizer(self):
"""
return self.domain()(self._base_valuation.uniformizer())

def shift(self, f, s):
"""
Multiply ``f`` by a power of the uniformizer which has valuation ``s``.
INPUT:
- ``f`` -- a polynomial in the domain of this valuation
- ``s`` -- an element of the :meth:`value_group`
EXAMPLES::
sage: from mac_lane import * # optional: standalone
sage: S.<x> = QQ[]
sage: v = GaussValuation(S, pAdicValuation(QQ, 5))
sage: v.shift(x, -2)
1/25*x
It is an error to perform a shift if the result is not in the domain of
the valuation anymore::
sage: S.<x> = Zp(2,5)[]
sage: v = GaussValuation(S)
sage: f = v.shift(x, 2); f
(2^2 + O(2^7))*x
sage: f.parent() is S
True
sage: f = v.shift(x, -2)
Traceback (most recent call last):
...
ValueError: since 2-adic Ring with capped relative precision 5 is not a field, -s must not exceed the valuation of f but 2 does exceed 0
Of course, the above example works over a field::
sage: S.<x> = Qp(2,5)[]
sage: v = GaussValuation(S)
sage: f = v.shift(x, -2); f
(2^-2 + O(2^3))*x
"""
f = self.domain().coerce(f)
s = self.value_group()(s)

if s == 0:
return f

from sage.categories.fields import Fields
if -s > self(f) and self.domain().base_ring() not in Fields():
raise ValueError("since %r is not a field, -s must not exceed the valuation of f but %r does exceed %r"%(self.domain().base_ring(), -s, self(f)))

if f == 0:
raise ValueError("can not shift zero")

return f.map_coefficients(lambda c:self._base_valuation.shift(c, s))

def valuations(self, f):
"""
Return the valuations of the `f_i\phi^i` in the expansion `f=\sum f_i\phi^i`.
Expand Down Expand Up @@ -478,8 +423,7 @@ def equivalence_unit(self, s):
(3^-2 + O(3^3))
"""
one = self._base_valuation.domain().one()
ret = self._base_valuation.shift(one, s)
ret = self._base_valuation.element_with_valuation(s)
return self.domain()(ret)

def element_with_valuation(self, s):
Expand Down
4 changes: 2 additions & 2 deletions inductive_valuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def equivalence_unit(self, s):
sage: w.equivalence_unit(-1)
Traceback (most recent call last):
...
ValueError: can not shift 1 down by 1 in Integer Ring with respect to 2-adic valuation
ValueError: s must be in the value semigroup of this valuation but -1 is not in Additive Abelian Semigroup generated by 1
"""

Expand Down Expand Up @@ -321,7 +321,7 @@ def element_with_valuation(self, s):
sage: v.element_with_valuation(-2)
Traceback (most recent call last):
...
ValueError: can not shift 1 down by 2 in Integer Ring with respect to 2-adic valuation
ValueError: s must be in the value semigroup of this valuation but -2 is not in Additive Abelian Semigroup generated by 1
"""

Expand Down
22 changes: 0 additions & 22 deletions limit_valuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,28 +416,6 @@ def lift(self, F):
F = self.residue_ring().coerce(F)
return self._initial_approximation.lift(F)

def shift(self, x, s):
r"""
Return a modified version of ``x`` whose valuation is increased by ``s``.
The element returned is such that repeated shifts which go back to
the original valuation produce the same element in reduction.
EXAMPLES::
sage: from mac_lane import * # optional: standalone
sage: K.<x> = FunctionField(QQ)
sage: R.<y> = K[]
sage: L.<y> = K.extension(y^2 - (x - 1))
sage: v = FunctionFieldValuation(K, 0)
sage: w = v.extension(L)
sage: w.shift(y, 1)
x*y
"""
return self._initial_approximation.shift(x, s)

def uniformizer(self):
r"""
Return a uniformizing element for this valuation.
Expand Down
69 changes: 8 additions & 61 deletions padic_valuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,82 +815,29 @@ def uniformizer(self):
"""
return self.domain().uniformizer()

def shift(self, c, v):
def element_with_valuation(self, v):
"""
Multiply ``c`` by a power of a uniformizer such that its valuation
changes by ``v``.
Return an element of valuation ``v``.
INPUT:
- ``c`` -- an element of the domain of this valuation
- ``v`` -- an integer
OUTPUT:
If the resulting element has negative valation, it will be brought to
the fraction field, otherwise it is an element of the domain.
- ``v`` -- an element of the :meth:`value_semigroup` of this valuation
EXAMPLES::
sage: from mac_lane import * # optional: standalone
sage: R = Zp(3)
sage: v = pAdicValuation(Zp(3))
sage: v.shift(R(2),3)
2*3^3 + O(3^23)
TESTS:
Make sure that we work around the following bug in p-adics::
sage: R = Zp(3)
sage: R(1) >> 1 # this should throw an exception
O(3^19)
However, our shift gets this right::
sage: v = pAdicValuation(Zp(3))
sage: v.shift(R(1), -1)
Traceback (most recent call last):
...
ValueError: can not shift down 1 + O(3^20) by 1 in 3-adic Ring with capped relative precision 20 with respect to 3-adic valuation
Note that the same happens for ZpCA::
sage: R = ZpCA(3)
sage: R(1) >> 1 # this should throw an exception
O(3^19)
But we also detect that one::
sage: v = pAdicValuation(ZpCA(3))
sage: v.shift(R(1), -1)
Traceback (most recent call last):
...
ValueError: can not shift down 1 + O(3^20) by 1 in 3-adic Ring with capped absolute precision 20 with respect to 3-adic valuation
sage: v.element_with_valuation(3)
3^3 + O(3^23)
"""
from sage.rings.all import QQ, ZZ
c = self.domain().coerce(c)
if c == 0:
if v == 0:
return c
raise ValueError("can not shift a zero")

v = QQ(v)
if v not in self.value_group():
raise ValueError("%r is not in the value group of %r"%(v, self))
if v not in self.value_semigroup():
raise ValueError("%r is not in the value semigroup of %r"%(v, self))
v = ZZ(v * self.domain().ramification_index())

# Work around a bug in ZpCR/ZpCA p-adics
# TODO: fix this upstream
from sage.rings.padics.padic_capped_absolute_element import pAdicCappedAbsoluteElement
from sage.rings.padics.padic_capped_relative_element import pAdicCappedRelativeElement
from sage.categories.fields import Fields
if (isinstance(c, pAdicCappedAbsoluteElement) or (isinstance(c, pAdicCappedRelativeElement) and c.parent() not in Fields())) and -v > self(c):
raise ValueError("can not shift down %r by %r in %r with respect to %r"%(c, -v, self.domain(), self))

return c<<v
return self.domain().one() << v

def _repr_(self):
"""
Expand Down
Loading

0 comments on commit 6a3126c

Please sign in to comment.