Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
181 views
unlisted
ubuntu2004
1
# -*- coding: utf-8 -*-
2
# ****************************************************************************
3
# Copyright (C) 2021, Vincent Delecroix <[email protected]>
4
#
5
# Distributed under the terms of the GNU General Public License (GPL)
6
# as published by the Free Software Foundation; either version 2 of
7
# the License, or (at your option) any later version.
8
# https://www.gnu.org/licenses/
9
# ****************************************************************************
10
11
def inverse_of_unit(elt):
12
"""
13
Generic inversion of univariate or multivariate element of a graded algebra.
14
15
TESTS::
16
17
sage: Integers(1)['x'](0).inverse_of_unit()
18
0
19
"""
20
P = elt.parent()
21
if not elt.is_unit():
22
raise ArithmeticError("{} is not a unit in {}".format(elt, elt.parent()))
23
24
u = elt.constant_coefficient()
25
ui = u.inverse_of_unit()
26
n = - ui * (elt - u) # nilpotent
27
nn = n
28
res = P.one()
29
while nn:
30
res += nn
31
nn *= n
32
return ui * res
33
34