Skip to content

Commit 764a026

Browse files
committed
Update doc strings
1 parent 846d3d8 commit 764a026

File tree

5 files changed

+157
-289
lines changed

5 files changed

+157
-289
lines changed

src/flint/flint_base/flint_base.pyx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ cdef class flint_mpoly_context(flint_elem):
424424
to ``1``. ``exp_vec``` defaults to ``(0,) * self.nvars()```.
425425
426426
>>> from flint import fmpz_mpoly_ctx, Ordering
427-
>>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
427+
>>> ctx = fmpz_mpoly_ctx.get_context(('x', 2), 'lex')
428428
>>> ctx.term(coeff=5, exp_vec=(2, 3))
429429
5*x0^2*x1^3
430430
>>> ctx.term()
@@ -465,11 +465,11 @@ cdef class flint_mod_mpoly_context(flint_mpoly_context):
465465
"""
466466
Return whether the modulus is prime
467467
468-
>>> from flint import Ordering, fmpz_mod_mpoly_ctx
469-
>>> ctx = fmpz_mod_mpoly_ctx.get_context(4, Ordering.degrevlex, 2**127, 'z')
468+
>>> from flint import fmpz_mod_mpoly_ctx
469+
>>> ctx = fmpz_mod_mpoly_ctx.get_context(('z',), 2**127, 'degrevlex')
470470
>>> ctx.is_prime()
471471
False
472-
>>> ctx = fmpz_mod_mpoly_ctx.get_context(4, Ordering.degrevlex, 2**127 - 1, 'z')
472+
>>> ctx = fmpz_mod_mpoly_ctx.get_context(('z',), 2**127 - 1, 'degrevlex')
473473
>>> ctx.is_prime()
474474
True
475475
"""
@@ -746,8 +746,8 @@ cdef class flint_mpoly(flint_elem):
746746
"""
747747
In-place addition, mutates self.
748748
749-
>>> from flint import Ordering, fmpz_mpoly_ctx
750-
>>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
749+
>>> from flint import fmpz_mpoly_ctx
750+
>>> ctx = fmpz_mpoly_ctx.get_context(('x', 2), 'lex')
751751
>>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
752752
>>> f
753753
4*x0*x1 + 2*x0 + 3*x1
@@ -771,8 +771,8 @@ cdef class flint_mpoly(flint_elem):
771771
"""
772772
In-place subtraction, mutates self.
773773
774-
>>> from flint import Ordering, fmpz_mpoly_ctx
775-
>>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
774+
>>> from flint import fmpz_mpoly_ctx
775+
>>> ctx = fmpz_mpoly_ctx.get_context(('x', 2), 'lex')
776776
>>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
777777
>>> f
778778
4*x0*x1 + 2*x0 + 3*x1
@@ -796,8 +796,8 @@ cdef class flint_mpoly(flint_elem):
796796
"""
797797
In-place multiplication, mutates self.
798798
799-
>>> from flint import Ordering, fmpz_mpoly_ctx
800-
>>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
799+
>>> from flint import fmpz_mpoly_ctx
800+
>>> ctx = fmpz_mpoly_ctx.get_context(('x', 2), 'lex')
801801
>>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
802802
>>> f
803803
4*x0*x1 + 2*x0 + 3*x1
@@ -822,7 +822,7 @@ cdef class flint_mpoly(flint_elem):
822822
Returns True if ``self`` contains a term with exponent vector ``x`` and a non-zero coefficient.
823823
824824
>>> from flint import fmpq_mpoly_ctx, Ordering
825-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
825+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
826826
>>> p = ctx.from_dict({(0, 1): 2, (1, 1): 3})
827827
>>> (1, 1) in p
828828
True
@@ -843,7 +843,7 @@ cdef class flint_mpoly(flint_elem):
843843
Return the exponent vectors and coefficient of each term.
844844
845845
>>> from flint import fmpq_mpoly_ctx, Ordering
846-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
846+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
847847
>>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
848848
>>> list(f.terms())
849849
[((1, 1), 4), ((1, 0), 2), ((0, 1), 3), ((0, 0), 1)]

src/flint/types/fmpq_mpoly.pyx

Lines changed: 33 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ cdef class fmpq_mpoly_ctx(flint_mpoly_context):
122122
"""
123123
Return the number of variables in the context
124124
125-
>>> from flint import Ordering
126-
>>> ctx = fmpq_mpoly_ctx.get_context(4, Ordering.lex, 'x')
125+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 4), 'lex')
127126
>>> ctx.nvars()
128127
4
129128
"""
@@ -133,19 +132,17 @@ cdef class fmpq_mpoly_ctx(flint_mpoly_context):
133132
"""
134133
Return the term order of the context object.
135134
136-
>>> from flint import Ordering
137-
>>> ctx = fmpq_mpoly_ctx.get_context(4, Ordering.deglex, 'w')
135+
>>> ctx = fmpq_mpoly_ctx.get_context(('w', 4), 'deglex')
138136
>>> ctx.ordering()
139-
<Ordering.deglex: 1>
137+
<Ordering.deglex: 'deglex'>
140138
"""
141139
return ordering_c_to_py(self.val.zctx.minfo.ord)
142140

143141
def gen(self, slong i):
144142
"""
145143
Return the ``i`` th generator of the polynomial ring
146144
147-
>>> from flint import Ordering
148-
>>> ctx = fmpq_mpoly_ctx.get_context(3, Ordering.degrevlex, 'z')
145+
>>> ctx = fmpq_mpoly_ctx.get_context(('z', 3), 'degrevlex')
149146
>>> ctx.gen(1)
150147
z1
151148
"""
@@ -175,8 +172,7 @@ cdef class fmpq_mpoly_ctx(flint_mpoly_context):
175172
The dictionary's keys are tuples of ints (or anything that implicitly converts
176173
to fmpz) representing exponents, and corresponding coefficient values of fmpq.
177174
178-
>>> from flint import Ordering
179-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x,y')
175+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 'y'), 'lex')
180176
>>> ctx.from_dict({(1,0):2, (1,1):3, (0,1):1})
181177
3*x*y + 2*x + y
182178
"""
@@ -306,8 +302,7 @@ cdef class fmpq_mpoly(flint_mpoly):
306302
Always returns a value, missing keys will return ``0``.
307303
Negative exponents are made positive.
308304
309-
>>> from flint import Ordering
310-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
305+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
311306
>>> p = ctx.from_dict({(0, 1): 2, (1, 1): 3})
312307
>>> p[1, 1]
313308
3
@@ -332,8 +327,7 @@ cdef class fmpq_mpoly(flint_mpoly):
332327
Will always set a value, missing keys will create a new term.
333328
Negative exponents are made positive.
334329
335-
>>> from flint import Ordering
336-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
330+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
337331
>>> p = ctx.from_dict({(0, 1): 2, (1, 1): 3})
338332
>>> p[1, 1] = 20
339333
>>> p
@@ -511,8 +505,7 @@ cdef class fmpq_mpoly(flint_mpoly):
511505
"""
512506
Return the exponent vectors of each term as a tuple of fmpz.
513507
514-
>>> from flint import Ordering
515-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
508+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
516509
>>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
517510
>>> f.monoms()
518511
[(1, 1), (1, 0), (0, 1), (0, 0)]
@@ -533,8 +526,7 @@ cdef class fmpq_mpoly(flint_mpoly):
533526
"""
534527
Return the coefficients of each term as a fmpq.
535528
536-
>>> from flint import Ordering
537-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
529+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
538530
>>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
539531
>>> f.coeffs()
540532
[4, 2, 3, 1]
@@ -556,8 +548,7 @@ cdef class fmpq_mpoly(flint_mpoly):
556548
# """
557549
# Return the terms of this polynomial as a list of fmpq_mpolys.
558550

559-
# >>> from flint import Ordering
560-
# >>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
551+
# >>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
561552
# >>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
562553
# >>> f.terms()
563554
# [4*x0*x1, 2*x0, 3*x1, 1]
@@ -580,8 +571,7 @@ cdef class fmpq_mpoly(flint_mpoly):
580571
Partial evaluate this polynomial with select constants. Keys must be generator names or generator indices,
581572
all values must be fmpq.
582573

583-
>>> from flint import Ordering
584-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
574+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
585575
>>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
586576
>>> f.subs({"x1": 0})
587577
2*x0 + 1
@@ -610,9 +600,8 @@ cdef class fmpq_mpoly(flint_mpoly):
610600
Compose this polynomial with other fmpq_mpolys. All arguments must share the same context, it may different
611601
from this polynomials context.
612602

613-
>>> from flint import Ordering
614-
>>> ctx = fmpq_mpoly_ctx.get_context(1, Ordering.lex, 'x')
615-
>>> ctx1 = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'y')
603+
>>> ctx = fmpq_mpoly_ctx.get_context(('x',), 'lex')
604+
>>> ctx1 = fmpq_mpoly_ctx.get_context(('y', 2), 'lex')
616605
>>> f = ctx.from_dict({(2,): 1})
617606
>>> g = ctx1.from_dict({(1, 0): 1, (0, 1): 1})
618607
>>> f
@@ -660,8 +649,7 @@ cdef class fmpq_mpoly(flint_mpoly):
660649
"""
661650
Return the context object for this polynomials.
662651
663-
>>> from flint import Ordering
664-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
652+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
665653
>>> p = ctx.from_dict({(0, 1): 2})
666654
>>> ctx is p.context()
667655
True
@@ -672,8 +660,7 @@ cdef class fmpq_mpoly(flint_mpoly):
672660
"""
673661
Return the coefficient at index ``i``.
674662
675-
>>> from flint import Ordering
676-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
663+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
677664
>>> p = ctx.from_dict({(0, 1): 2, (1, 1): 3})
678665
>>> p.coefficient(1)
679666
2
@@ -690,8 +677,7 @@ cdef class fmpq_mpoly(flint_mpoly):
690677
"""
691678
Return the exponent vector at index ``i`` as a tuple.
692679
693-
>>> from flint import Ordering
694-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
680+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
695681
>>> p = ctx.from_dict({(0, 1): 2, (1, 1): 3})
696682
>>> p.monomial(1)
697683
(0, 1)
@@ -709,8 +695,7 @@ cdef class fmpq_mpoly(flint_mpoly):
709695
"""
710696
Return a dictionary of variable name to degree.
711697
712-
>>> from flint import Ordering
713-
>>> ctx = fmpq_mpoly_ctx.get_context(4, Ordering.lex, 'x')
698+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 4), 'lex')
714699
>>> p = ctx.from_dict({(1, 0, 0, 0): 1, (0, 2, 0, 0): 2, (0, 0, 3, 0): 3})
715700
>>> p.degrees()
716701
(1, 2, 3, 0)
@@ -726,8 +711,7 @@ cdef class fmpq_mpoly(flint_mpoly):
726711
"""
727712
Return the total degree.
728713
729-
>>> from flint import Ordering
730-
>>> ctx = fmpq_mpoly_ctx.get_context(4, Ordering.lex, 'x')
714+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 4), 'lex')
731715
>>> p = ctx.from_dict({(1, 0, 0, 0): 1, (0, 2, 0, 0): 2, (0, 0, 3, 0): 3})
732716
>>> p.total_degree()
733717
3
@@ -740,8 +724,7 @@ cdef class fmpq_mpoly(flint_mpoly):
740724
"""
741725
Leading coefficient in the monomial ordering.
742726
743-
>>> from flint import Ordering
744-
>>> ctx = fmpq_mpoly_ctx(2, Ordering.lex, ['x', 'y'])
727+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 'y'), 'lex')
745728
>>> x, y = ctx.gens()
746729
>>> p = 2*x*y + 3*x + 4*y**2 + 5
747730
>>> p
@@ -770,8 +753,7 @@ cdef class fmpq_mpoly(flint_mpoly):
770753
"""
771754
Return the gcd of self and other.
772755
773-
>>> from flint import Ordering
774-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
756+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
775757
>>> f = ctx.from_dict({(1, 1): 4, (0, 0): 1})
776758
>>> g = ctx.from_dict({(0, 1): 2, (1, 0): 2})
777759
>>> (f * g).gcd(f)
@@ -792,8 +774,7 @@ cdef class fmpq_mpoly(flint_mpoly):
792774
Return the GCD of the terms of ``self``. If ``self`` is zero, then the result will
793775
be zero, otherwise it will be a monomial with positive coefficient.
794776
795-
>>> from flint import Ordering
796-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
777+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
797778
>>> x0, x1 = ctx.gens()
798779
>>> f = 3 * x0**2 * x1 + 6 * x0 * x1
799780
>>> f.term_content()
@@ -807,8 +788,7 @@ cdef class fmpq_mpoly(flint_mpoly):
807788
"""
808789
Return the resultant of ``self`` and ``other`` with respect to variable ``var``.
809790
810-
>>> from flint import Ordering
811-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
791+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
812792
>>> x0, x1 = ctx.gens()
813793
>>> f = x0**2 * x1 + x0 * x1
814794
>>> g = x0 + x1
@@ -834,8 +814,7 @@ cdef class fmpq_mpoly(flint_mpoly):
834814
"""
835815
Return the discriminant of ``self`` with respect to variable ``var``.
836816
837-
>>> from flint import Ordering
838-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
817+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
839818
>>> x0, x1 = ctx.gens()
840819
>>> f = (x0 + x1)**2 + 1
841820
>>> f.discriminant('x1')
@@ -856,8 +835,7 @@ cdef class fmpq_mpoly(flint_mpoly):
856835
"""
857836
Return the square root of self.
858837
859-
>>> from flint import Ordering
860-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
838+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
861839
>>> f = ctx.from_dict({(1, 1): 4, (0, 0): 1})
862840
>>> (f * f).sqrt()
863841
4*x0*x1 + 1
@@ -876,9 +854,8 @@ cdef class fmpq_mpoly(flint_mpoly):
876854
(c, factors) where c is the content of the coefficients and
877855
factors is a list of (poly, exp) pairs.
878856
879-
>>> from flint import Ordering
880857
>>> Zm = fmpq_mpoly
881-
>>> ctx = fmpq_mpoly_ctx.get_context(3, Ordering.lex, 'x,y,z')
858+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 'y', 'z'), 'lex')
882859
>>> p1 = Zm("2*x + 4", ctx)
883860
>>> p2 = Zm("3*x*z + 3*x + 3*z + 3", ctx)
884861
>>> (p1 * p2).factor()
@@ -915,9 +892,8 @@ cdef class fmpq_mpoly(flint_mpoly):
915892
(c, factors) where c is the content of the coefficients and
916893
factors is a list of (poly, exp) pairs.
917894
918-
>>> from flint import Ordering
919895
>>> Zm = fmpq_mpoly
920-
>>> ctx = fmpq_mpoly_ctx.get_context(3, Ordering.lex, 'x,y,z')
896+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 'y', 'z'), 'lex')
921897
>>> p1 = Zm("2*x + 4", ctx)
922898
>>> p2 = Zm("3*x*y + 3*x + 3*y + 3", ctx)
923899
>>> (p1 * p2).factor_squarefree()
@@ -954,8 +930,7 @@ cdef class fmpq_mpoly(flint_mpoly):
954930
The argument can either be the variable as a string, or the index of the
955931
variable in the context.
956932
957-
>>> from flint import Ordering
958-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
933+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
959934
>>> p = ctx.from_dict({(0, 3): 2, (2, 1): 3})
960935
>>> p
961936
3*x0^2*x1 + 2*x1^3
@@ -979,8 +954,7 @@ cdef class fmpq_mpoly(flint_mpoly):
979954
Return the integral of this polynomial with respect to the provided variable The argument can either be the
980955
variable as a string, or the index of the variable in the context.
981956
982-
>>> from flint import Ordering
983-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
957+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
984958
>>> p = ctx.from_dict({(0, 3): 2, (2, 1): 3})
985959
>>> p
986960
3*x0^2*x1 + 2*x1^3
@@ -1004,8 +978,7 @@ cdef class fmpq_mpoly(flint_mpoly):
1004978
Compute the inflation of ``self`` for a provided ``N``, that is return ``q``
1005979
such that ``q(X) = p(X^N)``.
1006980

1007-
>>> from flint import Ordering
1008-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, nametup=('x', 'y'))
981+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 'y'), 'lex')
1009982
>>> x, y = ctx.gens()
1010983
>>> f = x + y + 1
1011984
>>> f.inflate([2, 3])
@@ -1033,8 +1006,7 @@ cdef class fmpq_mpoly(flint_mpoly):
10331006
Compute the deflation of ``self`` for a provided ``N``, that is return ``q``
10341007
such that ``q(X) = p(X^(1/N))``.
10351008

1036-
>>> from flint import Ordering
1037-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, nametup=('x', 'y'))
1009+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 'y'), 'lex')
10381010
>>> x, y = ctx.gens()
10391011
>>> f = x**3 * y + x * y**4 + x * y
10401012
>>> f.deflate([2, 3])
@@ -1058,8 +1030,7 @@ cdef class fmpq_mpoly(flint_mpoly):
10581030
"""
10591031
Compute the deflation of ``self``, that is ``p(X^(1/N))`` for maximal N.
10601032

1061-
>>> from flint import Ordering
1062-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, nametup=('x', 'y'))
1033+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 'y'), 'lex')
10631034
>>> x, y = ctx.gens()
10641035
>>> f = x**2 * y**2 + x * y**2
10651036
>>> q, N = f.deflation()
@@ -1091,8 +1062,7 @@ cdef class fmpq_mpoly(flint_mpoly):
10911062
= m * q(X^N)`` for maximal N. The returned monomial allows the undo-ing of the
10921063
deflation.
10931064

1094-
>>> from flint import Ordering
1095-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, nametup=('x', 'y'))
1065+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 'y'), 'lex')
10961066
>>> x, y = ctx.gens()
10971067
>>> f = x**3 * y + x * y**4 + x * y
10981068
>>> fd, N, m = f.deflation_monom()
@@ -1123,8 +1093,7 @@ cdef class fmpq_mpoly(flint_mpoly):
11231093
exponents. It is the exponent vector of the monomial returned by
11241094
``deflation_monom``.
11251095

1126-
>>> from flint import Ordering
1127-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, nametup=('x', 'y'))
1096+
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 'y'), 'lex')
11281097
>>> x, y = ctx.gens()
11291098
>>> f = x**3 * y + x * y**4 + x * y
11301099
>>> N, I = f.deflation_index()

0 commit comments

Comments
 (0)