Skip to content

Commit 61e845c

Browse files
author
Release Manager
committed
gh-35021: Implement check for Lorentzian polynomials #28252 Fixes #28252 ### πŸ“š Description <!-- Describe your changes in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If it resolves an open issue, please link to the issue here. For example "Closes #1337" --> ### πŸ“ Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [ ] I have linked an issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### βŒ› Dependencies <!-- List all open pull requests that this PR logically depends on --> <!-- - #xyz: short description why this is a dependency - #abc: ... --> URL: #35021 Reported by: FrΓ©dΓ©ric Chapoton Reviewer(s): Travis Scrimshaw
2 parents bf6c233 + 2590c05 commit 61e845c

File tree

4 files changed

+366
-12
lines changed

4 files changed

+366
-12
lines changed

β€Žsrc/doc/en/reference/references/index.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,10 @@ REFERENCES:
803803
Stein. strassen_window_multiply_c. strassen.pyx, Sage
804804
3.0, 2008. http://www.sagemath.org
805805
806+
.. [BrHu2019] Petter BrΓ€ndΓ©n, June Huh. *Lorentzian polynomials*.
807+
Ann. Math. (2) 192, No. 3, 821-891 (2020).
808+
:arxiv:`1902.03719`, :doi:`10.4007/annals.2020.192.3.4`.
809+
806810
.. [BHNR2004] \S. Brlek, S. Hamel, M. Nivat, C. Reutenauer, On the
807811
Palindromic Complexity of Infinite Words,
808812
in J. Berstel, J. Karhumaki, D. Perrin, Eds,
@@ -3247,6 +3251,11 @@ REFERENCES:
32473251
Designs, Codes and Cryptography 8 (1996) 145-157.
32483252
:doi:`10.1023/A:1018037025910`.
32493253
3254+
.. [HMMS2019] June Huh, Jacob P. Matherne, Karola MΓ©szΓ‘ros, Avery St. Dizier.
3255+
*Logarithmic concavity of Schur and related polynomials*.
3256+
Trans. Am. Math. Soc. 375, No. 6, 4411-4427 (2022).
3257+
:arxiv:`1906.09633`, :doi:`10.1090/tran/8606`.
3258+
32503259
.. [Hutz2007] \B. Hutz. Arithmetic Dynamics on Varieties of dimension greater
32513260
than one. PhD Thesis, Brown University 2007
32523261

β€Žsrc/sage/quadratic_forms/quadratic_form.py

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
from sage.arith.all import GCD, LCM
3131
from sage.rings.all import Ideal, QQ
3232
from sage.rings.ring import is_Ring, PrincipalIdealDomain
33-
from sage.structure.sage_object import SageObject
3433
from sage.structure.element import is_Vector
3534
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
35+
from sage.rings.polynomial.polynomial_element import is_Polynomial
36+
from sage.rings.polynomial.multi_polynomial_element import is_MPolynomial
3637
from sage.modules.free_module_element import vector
3738
from sage.quadratic_forms.genera.genus import genera
3839
from sage.quadratic_forms.quadratic_form__evaluate import QFEvaluateVector, QFEvaluateMatrix
39-
40+
from sage.structure.sage_object import SageObject
41+
from sage.combinat.integer_lists.invlex import IntegerListsLex
4042

4143
def QuadraticForm__constructor(R, n=None, entries=None):
4244
"""
@@ -206,6 +208,10 @@ class QuadraticForm(SageObject):
206208
in `R` (given lexicographically, or equivalently, by rows of the
207209
matrix)
208210
211+
#. ``QuadraticForm(p)``, where
212+
213+
- `p` -- a homogeneous polynomial of degree `2`
214+
209215
#. ``QuadraticForm(R, n)``, where
210216
211217
- `R` -- a ring
@@ -284,6 +290,16 @@ class QuadraticForm(SageObject):
284290
[ 1 5 ]
285291
[ * 4 ]
286292
293+
::
294+
295+
sage: P.<x,y,z> = QQ[]
296+
sage: p = x^2 + 2*x*y + x*z/2 + y^2 + y*z/3
297+
sage: QuadraticForm(p)
298+
Quadratic form in 3 variables over Rational Field with coefficients:
299+
[ 1 2 1/2 ]
300+
[ * 1 1/3 ]
301+
[ * * 0 ]
302+
287303
::
288304
289305
sage: QuadraticForm(ZZ, m + m.transpose())
@@ -499,6 +515,25 @@ def __init__(self, R, n=None, entries=None, unsafe_initialization=False, number_
499515
sage: s.dim()
500516
4
501517
518+
sage: P.<x,y,z> = QQ[]
519+
sage: p = x^2 + y^2 + 2*x*z
520+
sage: QuadraticForm(p)
521+
Quadratic form in 3 variables over Rational Field with coefficients:
522+
[ 1 0 2 ]
523+
[ * 1 0 ]
524+
[ * * 0 ]
525+
sage: z = P.zero()
526+
sage: QuadraticForm(z)
527+
Quadratic form in 3 variables over Rational Field with coefficients:
528+
[ 0 0 0 ]
529+
[ * 0 0 ]
530+
[ * * 0 ]
531+
sage: q = x^2 + 3*y - z
532+
sage: QuadraticForm(q)
533+
Traceback (most recent call last):
534+
...
535+
ValueError: polynomial is neither zero nor homogeneous of degree 2
536+
502537
TESTS::
503538
504539
sage: s == loads(dumps(s))
@@ -510,6 +545,10 @@ def __init__(self, R, n=None, entries=None, unsafe_initialization=False, number_
510545
511546
sage: x = polygen(ZZ, 'x')
512547
sage: QuadraticForm(x**2)
548+
Quadratic form in 1 variables over Integer Ring with coefficients:
549+
[ 1 ]
550+
551+
sage: QuadraticForm(1)
513552
Traceback (most recent call last):
514553
....
515554
TypeError: wrong input for QuadraticForm
@@ -527,20 +566,39 @@ def __init__(self, R, n=None, entries=None, unsafe_initialization=False, number_
527566
M_ring = R
528567
matrix_init_flag = True
529568

530-
elif not is_Matrix(R):
531-
# first argument, if not a ring, must be a matrix
532-
raise TypeError('wrong input for QuadraticForm')
533-
else:
534-
# Deal with: QuadraticForm(matrix)
569+
elif is_Matrix(R):
570+
M = R
571+
535572
# Test if R is symmetric and has even diagonal
536-
if not self._is_even_symmetric_matrix_(R):
573+
if not self._is_even_symmetric_matrix_(M):
537574
raise TypeError("the matrix is not a symmetric with even diagonal")
538575

539-
# Rename the matrix and ring
540-
M = R
541-
M_ring = R.base_ring()
576+
M_ring = M.base_ring()
542577
matrix_init_flag = True
543578

579+
elif is_Polynomial(R) or is_MPolynomial(R):
580+
p = R
581+
582+
if not p.is_zero() and not (p.is_homogeneous() and p.degree() == 2):
583+
raise ValueError("polynomial is neither zero nor homogeneous of degree 2")
584+
585+
P = p.parent()
586+
R, n = P.base_ring(), P.ngens()
587+
588+
# Extract quadratic form coefficients
589+
entries = []
590+
if n == 0:
591+
exponents = []
592+
elif n == 1:
593+
exponents = [2]
594+
else:
595+
exponents = IntegerListsLex(2, length=n)
596+
for alpha in exponents:
597+
entries.append(p[alpha])
598+
599+
else:
600+
raise TypeError('wrong input for QuadraticForm')
601+
544602
# Perform the quadratic form initialization
545603
if matrix_init_flag:
546604
self.__n = ZZ(M.nrows())

0 commit comments

Comments
Β (0)