mirror of
https://gitlab.com/sheaf/metabrush.git
synced 2024-11-05 23:03:38 +00:00
fix bug in partitions function
This commit is contained in:
parent
dd503df126
commit
86874882e4
|
@ -5,8 +5,6 @@
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
{-# LANGUAGE UndecidableInstances #-}
|
{-# LANGUAGE UndecidableInstances #-}
|
||||||
|
|
||||||
{-# OPTIONS_GHC -ddump-splices -ddump-to-file #-}
|
|
||||||
|
|
||||||
module Math.Monomial
|
module Math.Monomial
|
||||||
( Mon(..)
|
( Mon(..)
|
||||||
, MonomialBasis(..), Deg, Vars
|
, MonomialBasis(..), Deg, Vars
|
||||||
|
@ -188,27 +186,30 @@ partitions :: forall k n
|
||||||
. Word -- ^ number of parts
|
. Word -- ^ number of parts
|
||||||
-> Mon k n -- ^ monomial to sum to
|
-> Mon k n -- ^ monomial to sum to
|
||||||
-> [ [ ( Mon k n, Word ) ] ]
|
-> [ [ ( Mon k n, Word ) ] ]
|
||||||
partitions n_parts0 mon0 = go n_parts0 mon0 mon0
|
partitions n_parts0 mon0 = go n_parts0 Nothing mon0
|
||||||
where
|
where
|
||||||
go :: Word -> Mon k n -> Mon k n -> [ [ ( Mon k n , Word ) ] ]
|
go :: Word -> Maybe ( Mon k n ) -> Mon k n -> [ [ ( Mon k n , Word ) ] ]
|
||||||
go 0 _ mon
|
go 0 _ mon
|
||||||
| isZeroMonomial mon
|
| isZeroMonomial mon
|
||||||
= [ [] ]
|
= [ [] ]
|
||||||
| otherwise
|
| otherwise
|
||||||
= []
|
= []
|
||||||
go 1 maxSub mon
|
go 1 mbMaxMon mon
|
||||||
| isZeroMonomial mon
|
| isZeroMonomial mon
|
||||||
|| mon >= maxSub
|
|| case mbMaxMon of { Just maxMon -> mon >= maxMon ; _ -> False }
|
||||||
= []
|
= []
|
||||||
| otherwise
|
| otherwise
|
||||||
= [ [ ( mon, 1 ) ] ]
|
= [ [ ( mon, 1 ) ] ]
|
||||||
go n_parts maxSub mon
|
go n_parts mbMaxMon mon
|
||||||
= [ ( part, l ) : parts
|
= [ ( part, l ) : parts
|
||||||
| ( part, l_max ) <- subs mon
|
| ( part, l_max ) <- subs mon
|
||||||
, not ( isZeroMonomial part ) -- parts must be non-empty
|
, not ( isZeroMonomial part ) -- parts must be non-empty
|
||||||
, part < maxSub -- use a total ordering on monomials to ensure uniqueness
|
-- use a total ordering on monomials to ensure uniqueness
|
||||||
|
, case mbMaxMon of
|
||||||
|
Just maxMon -> part < maxMon
|
||||||
|
Nothing -> True
|
||||||
, l <- [ 1 .. min n_parts l_max ]
|
, l <- [ 1 .. min n_parts l_max ]
|
||||||
, parts <- go ( n_parts - l ) part ( subPart l mon part )
|
, parts <- go ( n_parts - l ) ( Just part ) ( subPart l mon part )
|
||||||
]
|
]
|
||||||
|
|
||||||
subPart :: Word -> Mon k n -> Mon k n -> Mon k n
|
subPart :: Word -> Mon k n -> Mon k n -> Mon k n
|
||||||
|
|
Loading…
Reference in a new issue