Skip to content

Commit

Permalink
prettyParametricQSpray
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Apr 21, 2024
1 parent 82f694f commit 86d41b5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
40 changes: 22 additions & 18 deletions src/Math/Algebra/Hspray.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2999,7 +2999,8 @@ evalParametricSpray spray xs = if length xs >= numberOfVariables spray
-- True
canCoerceToSimpleParametricSpray ::
(Eq a, AlgRing.C a) => ParametricSpray a -> Bool
canCoerceToSimpleParametricSpray spray = all isPolynomialRatioOfSprays (HM.elems spray)
canCoerceToSimpleParametricSpray spray =
all isPolynomialRatioOfSprays (HM.elems spray)

-- | Coerces a parametric spray to a simple parametric spray, without
-- checking this makes sense with `canCoerceToSimpleParametricSpray`
Expand Down Expand Up @@ -3029,8 +3030,7 @@ fromOneParameterQSpray = HM.map fromRatioOfQPolynomials
-- | Converts a parametric spray to a one-parameter spray, without checking
-- the conversion makes sense
parametricSprayToOneParameterSpray ::
forall a. (AlgRing.C a)
=> ParametricSpray a -> OneParameterSpray a
forall a. (AlgRing.C a) => ParametricSpray a -> OneParameterSpray a
parametricSprayToOneParameterSpray = HM.map toRatioOfPolynomials
where
toRatioOfPolynomials :: RatioOfSprays a -> RatioOfPolynomials a
Expand All @@ -3047,8 +3047,7 @@ parametricSprayToOneParameterSpray = HM.map toRatioOfPolynomials

-- | Converts a rational parametric spray to a rational one-parameter spray,
-- without checking the conversion makes sense
parametricQSprayToOneParameterQSpray ::
ParametricQSpray -> OneParameterQSpray
parametricQSprayToOneParameterQSpray :: ParametricQSpray -> OneParameterQSpray
parametricQSprayToOneParameterQSpray = HM.map toRatioOfQPolynomials
where
toRatioOfQPolynomials :: RatioOfQSprays -> RatioOfQPolynomials
Expand Down Expand Up @@ -3139,16 +3138,19 @@ jacobiPolynomial n
prettyParametricQSprayABCXYZ ::
[String] -- ^ usually some letters, to denote the parameters of the spray
-> [String] -- ^ usually some letters, to denote the variables of the spray
-> ParametricQSpray -- ^ a parametric rational spray
-> ParametricQSpray -- ^ a parametric rational spray
-> String
prettyParametricQSprayABCXYZ abc xyz =
showSpray (prettyRatioOfQSpraysXYZ abc) ("{ ", " }") (showMonomialsXYZ xyz)
prettyParametricQSprayABCXYZ abc xyz spray =
showSpray rOSShower ("{ ", " }") (showMonomialsXYZ xyz) spray
where
rOSShower = if numberOfParameters spray <= length abc
then prettyRatioOfQSpraysXYZ abc
else prettyRatioOfQSpraysX1X2X3 (abc !! 0)

-- | Pretty form of a parametric rational spray
--
-- prop> prettyParametricQSpray spray == prettyParametricQSprayABCXYZ ["a"] ["X","Y","Z"] spray
prettyParametricQSpray :: ParametricQSpray -> String
prettyParametricQSpray = prettyParametricQSprayABCXYZ ["a"] ["X", "Y", "Z"]
prettyParametricQSpray =
showSpray (prettyRatioOfQSpraysX1X2X3 "a") ("{ ", " }") (showMonomialsXYZ ["X", "Y", "Z"])

-- | Pretty form of a simple parametric rational spray, using some given strings (typically some
-- letters) to denote the parameters and some given strings (typically some letters) to
Expand All @@ -3169,16 +3171,18 @@ prettyParametricQSpray = prettyParametricQSprayABCXYZ ["a"] ["X", "Y", "Z"]
-- >>> putStrLn $ prettySimpleParametricQSprayABCXYZ ["a","b"] ["X","Y","Z"] spqs
-- { a + b }*X^2 + { a^2 + b^2 }*Y.Z
prettySimpleParametricQSprayABCXYZ ::
[String] -- ^ usually some letters, to denote the parameters of the spray
-> [String] -- ^ usually some letters, to denote the variables of the spray
[String] -- ^ usually some letters, to denote the parameters of the spray
-> [String] -- ^ usually some letters, to denote the variables of the spray
-> SimpleParametricQSpray -- ^ a parametric rational spray
-> String
prettySimpleParametricQSprayABCXYZ abc xyz =
showSpray (prettyQSprayXYZ abc) ("{ ", " }") (showMonomialsXYZ xyz)
prettySimpleParametricQSprayABCXYZ abc xyz spray =
showSpray sprayShower ("{ ", " }") (showMonomialsXYZ xyz) spray
where
sprayShower = if numberOfParameters spray <= length abc
then prettyQSprayXYZ abc
else prettyQSprayX1X2X3 (abc !! 0)

-- | Pretty form of a simple parametric rational spray
--
-- prop> prettySimpleParametricQSpray spray == prettySimpleParametricQSprayABCXYZ ["a"] ["X","Y","Z"] spray
prettySimpleParametricQSpray :: SimpleParametricQSpray -> String
prettySimpleParametricQSpray =
prettySimpleParametricQSprayABCXYZ ["a"] ["X", "Y", "Z"]
showSpray (prettyQSprayX1X2X3 "a") ("{ ", " }") (showMonomialsXYZ ["X", "Y", "Z"])
27 changes: 25 additions & 2 deletions tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ import Math.Algebra.Hspray ( Spray,
substituteParameters,
evalParametricSpray,
asSimpleParametricSpray,
parametricSprayToOneParameterSpray
parametricSprayToOneParameterSpray,
prettyParametricQSprayABCXYZ
)
import MathObj.Matrix ( fromRows )
import qualified MathObj.Matrix as MathMatrix
Expand All @@ -104,13 +105,35 @@ import Test.Tasty.HUnit ( assertEqual
, testCase
)

type PQS = ParametricQSpray

main :: IO ()
main = defaultMain $ testGroup

"Testing hspray"

[
testCase "substituteParameters in Jacobi polynomial -> Legendre" $ do
testCase "prettyParametricQSprayABCXYZ" $ do
let
f :: (QSpray, QSpray) -> (PQS, PQS, PQS) -> PQS
f (a, b) (x, y, z) =
(a %:% (a ^+^ unitSpray)) *^ x^**^2 ^+^ (b %:% (a ^+^ b)) *^ (y ^*^ z)
pqs = f (lone 1, lone 2) (lone 1, lone 2, lone 3)
s1 = prettyParametricQSprayABCXYZ ["a","b"] ["X","Y","Z"] pqs
s2 = prettyParametricQSprayABCXYZ ["a"] ["X","Y","Z"] pqs
s3 = prettyParametricQSprayABCXYZ ["a","b"] ["X","Y"] pqs
assertEqual ""
[
s1, s2, s3
]
[
"{ [ a ] %//% [ a + 1 ] }*X^2 + { [ b ] %//% [ a + b ] }*Y.Z",
"{ [ a1 ] %//% [ a1 + 1 ] }*X^2 + { [ a2 ] %//% [ a1 + a2 ] }*Y.Z",
"{ [ a ] %//% [ a + 1 ] }*X1^2 + { [ b ] %//% [ a + b ] }*X2.X3"
]


, testCase "substituteParameters in Jacobi polynomial -> Legendre" $ do
let
x = qlone 1
jacobi = jacobiPolynomial 5
Expand Down

0 comments on commit 86d41b5

Please sign in to comment.