mirror of
https://gitlab.com/sheaf/metabrush.git
synced 2024-11-27 09:24:08 +00:00
fix bug in partitions function
This commit is contained in:
parent
dd503df126
commit
86874882e4
|
@ -5,8 +5,6 @@
|
|||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# LANGUAGE UndecidableInstances #-}
|
||||
|
||||
{-# OPTIONS_GHC -ddump-splices -ddump-to-file #-}
|
||||
|
||||
module Math.Monomial
|
||||
( Mon(..)
|
||||
, MonomialBasis(..), Deg, Vars
|
||||
|
@ -188,27 +186,30 @@ partitions :: forall k n
|
|||
. Word -- ^ number of parts
|
||||
-> Mon k n -- ^ monomial to sum to
|
||||
-> [ [ ( Mon k n, Word ) ] ]
|
||||
partitions n_parts0 mon0 = go n_parts0 mon0 mon0
|
||||
partitions n_parts0 mon0 = go n_parts0 Nothing mon0
|
||||
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
|
||||
| isZeroMonomial mon
|
||||
= [ [] ]
|
||||
| otherwise
|
||||
= []
|
||||
go 1 maxSub mon
|
||||
go 1 mbMaxMon mon
|
||||
| isZeroMonomial mon
|
||||
|| mon >= maxSub
|
||||
|| case mbMaxMon of { Just maxMon -> mon >= maxMon ; _ -> False }
|
||||
= []
|
||||
| otherwise
|
||||
= [ [ ( mon, 1 ) ] ]
|
||||
go n_parts maxSub mon
|
||||
go n_parts mbMaxMon mon
|
||||
= [ ( part, l ) : parts
|
||||
| ( part, l_max ) <- subs mon
|
||||
, 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 ]
|
||||
, 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
|
||||
|
|
Loading…
Reference in a new issue