Skip to content

Commit

Permalink
Add new function traverseCoeffs for WeightedSum type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Huffman committed Nov 13, 2019
1 parent cfdd2a2 commit 7af361d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions what4/src/What4/Expr/WeightedSum.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module What4.Expr.WeightedSum
, asAffineVar
, isZero
, traverseVars
, traverseCoeffs
, add
, addVar
, addVars
Expand Down Expand Up @@ -237,6 +238,17 @@ traverseVars f w =
Map.fromListWith (SR.add sr) <$>
traverse (_1 (traverseWrap f)) (Map.toList (_sumMap w))

-- | Traverse the coefficients in a weighted sum.
traverseCoeffs :: forall m f sr.
(Applicative m, HashableF f) =>
(SR.Coefficient sr -> m (SR.Coefficient sr)) ->
WeightedSum f sr ->
m (WeightedSum f sr)
traverseCoeffs f w = mkSum <$> traverse f (_sumMap w) <*> f (_sumOffset w)
where
sr = sumRepr w
mkSum m = unfilteredSum sr (Map.filter (not . SR.eq sr (SR.zero sr)) m)

-- | Traverse the expressions in a product.
traverseProdVars :: forall k j m sr.
(Applicative m, Tm k) =>
Expand Down

0 comments on commit 7af361d

Please sign in to comment.