Skip to content

Commit

Permalink
polynomialSubresultants unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed May 3, 2024
1 parent 03828f8 commit 9bb7f6b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,11 @@ check whether a variable is involved in a function-like object (a spray or a
ratio of sprays), and `dropVariables`, to drop a given number of leading
variables in a function-like object. The `dropVariables` functions is very
unsafe: if a variable is dropped while it is involved, the result can be an
invalid function-like object.
invalid function-like object.


## 0.5.2.0 - 2024-05-XX

* Function `polynomialSubresultants`, to compute the polynomial subresultants
of two sprays (while the `subresultants` function computes the principal
subresultants).
2 changes: 1 addition & 1 deletion hspray.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: hspray
version: 0.5.1.0
version: 0.5.2.0
synopsis: Multivariate polynomials and fractions of multivariate polynomials.
description: Manipulation of multivariate polynomials over a commutative ring and fractions of multivariate polynomials over a commutative field, Gröbner bases, resultant and subresultants, and greatest common divisor. It is possible to deal with multivariate polynomials whose coefficients are fractions of multivariate polynomials, and they can be interpreted as parametric polynomials with symbolic parameters.
homepage: https://github.com/stla/hspray#readme
Expand Down
35 changes: 9 additions & 26 deletions src/Math/Algebra/Hspray.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2446,7 +2446,8 @@ resultant var p q =
det = detLaplace $
sylvesterMatrix (sprayCoefficients p') (sprayCoefficients q')

-- | Subresultants of two sprays
-- | Subresultants of two sprays (the /principal/ subresultants, while the
-- `polynomialSubresultants` function returns the polynomial subresultants)
subresultants :: (Eq a, AlgRing.C a)
=> Int -- ^ indicator of the variable with respect to which the subresultants are desired (e.g. 1 for x)
-> Spray a
Expand Down Expand Up @@ -2533,32 +2534,14 @@ resultant' var sprayA sprayB
h' = exactDivisionBy (h^**^delta) (h ^*^ g'^**^delta)
h'' = exactDivisionBy (h'^**^degp') (h' ^*^ ellq'^**^degp')

{- sresMatrix :: (Eq a, AlgRing.C a) => Spray a -> Spray a -> Int -> Spray a
sresMatrix p q i = if n == m && i == n
then q
else detLaplace matrix
where
d = max (numberOfVariables p) (numberOfVariables q)
x = lone d
pcoeffs = reverse $ sprayCoefficients' d p
qcoeffs = reverse $ sprayCoefficients' d q
pcoeff k = if k < 0 then zeroSpray else pcoeffs !! k
qcoeff k = if k < 0 then zeroSpray else qcoeffs !! k
n = length pcoeffs - 1
m = length qcoeffs - 1
prow k = replicate k zeroSpray ++
[pcoeff j | j <- [n, n-1 .. 2*i - m + k + 2]] ++
[x^**^(m-i-1-k) ^*^ p]
prows = [prow k | k <- [0 .. m - i - 1]]
qrow k = replicate k zeroSpray ++
[qcoeff j | j <- [m, m-1 .. 2*i - n + k + 2]] ++
[x^**^(n-i-1-k) ^*^ q]
qrows = [qrow k | k <- [0 .. n - i - 1]]
matrix = fromLists (prows ++ qrows)
-}

-- | Polynomial subresultants of two sprays (the `subresultants` function
-- computes the /principal/ subresultants)
polynomialSubresultants ::
(Eq a, AlgRing.C a) => Int -> Spray a -> Spray a -> [Spray a]
(Eq a, AlgRing.C a)
=> Int -- ^ index of the variable with respect to which the subresultants will be computed (e.g. 2 for @y@)
-> Spray a
-> Spray a
-> [Spray a]
polynomialSubresultants var p q
| var < 1 || var > d
= error "polynomialSubresultants: invalid variable index."
Expand Down
32 changes: 30 additions & 2 deletions tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import Math.Algebra.Hspray ( Spray,
subresultants,
resultant1,
subresultants1,
polynomialSubresultants,
sprayDivision,
gcdSpray,
QSpray',
Expand Down Expand Up @@ -804,9 +805,36 @@ main = defaultMain $ testGroup
test1 = rx == rx'
test2 = ry == ry'
test3 = rz == rz'
assertBool "" (test1 && test2 && test3),
assertBool "" (test1 && test2 && test3)

testCase "gcdSpray - univariate example" $ do
, testCase "polynomialSubresultants" $ do
let
x = qlone 1
y = qlone 2
p = x^**^3^*^y^**^3 ^+^ x^**^2 ^+^ 3*^x ^+^ unitSpray
q = x^**^4 ^+^ 2*^x^**^3 ^-^ x^*^y^**^4
srs1 = map prettyQSpray (polynomialSubresultants 1 p q)
srs2 = map prettyQSpray (polynomialSubresultants 2 p q)
assertEqual ""
(srs1, srs2)
(
[
"y^21 + 15*y^14 - 11*y^11 + y^8 + 37*y^7 + 4*y^4 - 8*y^3 - 1"
, "x.y^17 + 14*x.y^10 - 11*x.y^7 + x.y^4 + 39*x.y^3 + 5*x + 2*y^10 - y^7 + 14*y^3 + 2"
, "-5*x^2.y^3 + x^2 - x.y^10 - 7*x.y^3 + 3*x - 2*y^3 + 1"
, "x^3.y^3 + x^2 + 3*x + 1"
],
[
"x^24 + 6*x^23 + 12*x^22 + 8*x^21 - x^11 - 12*x^10 - 58*x^9 - 144*x^8 - 195*x^7 - 144*x^6 - 58*x^5 - 12*x^4 - x^3"
, "x^13 + 5*x^12 + 7*x^11 + 2*x^10 + x^9.y + 6*x^8.y + 11*x^7.y + 6*x^6.y + x^5.y"
, "x^10 + 2*x^9 + x^6.y + 3*x^5.y + x^4.y"
, "x^3.y^3 + x^2 + 3*x + 1"
]

)


, testCase "gcdSpray - univariate example" $ do
let
x = lone 1 :: Spray Rational
sprayD = x^**^2 ^+^ unitSpray
Expand Down

0 comments on commit 9bb7f6b

Please sign in to comment.