@@ -143,40 +143,6 @@ fixedLoopRollExisting x = x
143143fixedLoopRoll :: (Eq a , Ord a ) => PRule a
144144fixedLoopRoll pt = fixedLoopRollExisting $ fixedLoopRollSingle pt
145145
146- -- remove when probLoopRoll converted to sim-merge style
147- loopRollEndPattern :: (Eq a ) => PPTree a -> Float -> POper1 -> PPTree a
148- loopRollEndPattern prev ct poper
149- | ct > 1 = Node1 poper prev ct (weight prev)
150- | ct <= 1 = prev
151-
152-
153- -- Not in the paper and not currently used
154- -- no loops of subseq >= 2
155- probLoopRoll :: Eq a => PRule a
156- probLoopRoll (NodeN Seq (u1: ptl) w)
157- | nptl /= ptl = NodeN Seq nptl w
158- where nptl = probLoopRollList ptl u1 1
159- probLoopRoll x = x
160-
161- probLoopRollList :: (Eq a ) => [PPTree a ] -> PPTree a -> Float -> [PPTree a ]
162- probLoopRollList ((Node1 PLoop u1 r1 w1): ptl) prev ct
163- | u1 =~= prev = probLoopRollList ptl (seqMerge u1 prev) (ct+ r1- 1 )
164- | not (u1 =~= prev) = probLoopRollEndPattern prev ct:
165- probLoopRollList ptl u1 r1
166- probLoopRollList (u1: ptl) prev ct
167- | u1 =~= prev = probLoopRollList ptl (seqMerge u1 prev) (ct+ 1 )
168- | not (u1 =~= prev) = probLoopRollEndPattern prev ct:
169- probLoopRollList ptl u1 1
170- probLoopRollList [] prev ct = [probLoopRollEndPattern prev ct]
171-
172-
173- probLoopRollEndPattern :: (Eq a ) => PPTree a -> Float -> PPTree a
174- probLoopRollEndPattern prev ct = loopRollEndPattern prev ct PLoop
175-
176-
177- loopFixToProb :: PRule a
178- loopFixToProb (Node1 FLoop x m w) = Node1 PLoop x m w
179- loopFixToProb x = x
180146
181147loopNest :: PRule a
182148loopNest (Node1 FLoop (Node1 FLoop x r1 w1) r2 w2) = Node1 FLoop x (r1* r2) w2
@@ -190,14 +156,31 @@ loopGeo :: (Eq a, Ord a) => PRule a
190156loopGeo = choiceChildMR loopGeoList
191157
192158loopGeoList :: (Eq a ) => LRule a
193- loopGeoList ((Node1 FLoop u1 r1 w1): (Node1 FLoop u2 r2 w2): ptl)
159+ loopGeoList ((Node1 op1 u1 r1 w1): (Node1 op2 u2 r2 w2): ptl)
194160 | u1 =~= u2 = loopGeoList (
195161 Node1 PLoop (merge u1 u2)
196162 (((r1* w1)+ (r2* w2))/ (w1+ w2))
197163 (w1+ w2)
198164 : ptl)
199- | otherwise = (Node1 FLoop u1 r1 w1) :
200- loopGeoList ( (Node1 FLoop u2 r2 w2) : ptl)
165+ | otherwise = (Node1 op1 u1 r1 w1) :
166+ loopGeoList ( (Node1 op2 u2 r2 w2) : ptl)
167+ loopGeoList ((Node1 op1 u1 r1 w1): u2: ptl)
168+ | u1 =~= u2 = loopGeoList
169+ ((Node1 PLoop (merge u1 u2)
170+ (((r1* w1)+ w2)/ (w1+ w2))
171+ (w1+ w2) )
172+ : ptl )
173+ | otherwise = (Node1 op1 u1 r1 w1) :
174+ loopGeoList (u2: ptl)
175+ where w2 = weight u2
176+ loopGeoList (u1: (Node1 op2 u2 r2 w2): ptl)
177+ | u1 =~= u2 = loopGeoList (
178+ (Node1 PLoop (merge u1 u2)
179+ (((w1)+ (r2* w2))/ (w1+ w2))
180+ (w1+ w2) )
181+ : ptl)
182+ | otherwise = u1: loopGeoList ( (Node1 op2 u2 r2 w2) : ptl)
183+ where w1 = weight u1
201184loopGeoList (pt1: ptl) = pt1: loopGeoList ptl
202185loopGeoList pt = pt
203186
@@ -622,8 +605,7 @@ baseRuleList = [
622605 TRule {rulename= " loopConcFromChoice" ,trule= loopConcFromChoice},
623606 TRule {rulename= " loopConcFromChoiceSuffix" ,
624607 trule= loopConcFromChoiceSuffix},
625- TRule {rulename= " loopConcSubsume" ,trule= loopConcSubsume},
626- TRule {rulename= " loopFixToProb" , trule= loopFixToProb}
608+ TRule {rulename= " loopConcSubsume" ,trule= loopConcSubsume}
627609 ]
628610
629611
@@ -642,23 +624,33 @@ transform :: (Show a, Eq a, Ord a) => PPTree a -> PPTree a
642624transform = transformRuleOrdered
643625
644626transformNoise :: (Show a , Eq a , Ord a ) => PPTree a -> Float -> PPTree a
645- transformNoise pt noise = maxTransformRuleOrder pt (denoiseRuleList noise)
627+ transformNoise pt noise =
628+ maxTransformRuleOrder firstPass (denoiseRuleList noise)
629+ where firstPass = maxTransformRuleOrder pt baseRuleList
646630
647631-- transformClean x = maxTransformBreadth x ruleList
648632transformRuleOrdered :: (Show a , Eq a , Ord a ) => PPTree a -> PPTree a
649633transformRuleOrdered pt = maxTransformRuleOrder pt ruleList
650634
635+ exhaustTransform :: (Show a , Eq a ) => PPTree a -> TRule a -> PPTree a
636+ exhaustTransform pt r | pt == tpt = pt
637+ | otherwise = exhaustTransform tpt r
638+ where tpt = transformPT pt r
639+
640+
651641transformInRuleOrder :: (Show a , Eq a ) => PPTRuleTransform a
652- transformInRuleOrder pt [r] = transformPT pt r
642+ -- transformInRuleOrder pt [r] = transformPT pt r
643+ transformInRuleOrder pt [r] = exhaustTransform pt r
653644transformInRuleOrder pt (r: rs) =
654645 transformInRuleOrder (transformInRuleOrder pt [r]) rs
655646transformInRuleOrder x _ = x
656647
657648maxTransformRuleOrder :: (Show a , Eq a ) => PPTRuleTransform a
658- maxTransformRuleOrder x rules | x == y = x
659- | otherwise = maxTransformRuleOrder y rules
660- where y = debug (" === Count:" ++ show (ncount x)
661- ++ " ===" ) (transformInRuleOrder x rules)
649+ maxTransformRuleOrder x rules
650+ | x == y = x
651+ | otherwise = maxTransformRuleOrder y rules
652+ where y = debug (" === Count:" ++ show (ncount x)
653+ ++ " ===" ) (transformInRuleOrder x rules)
662654
663655
664656
0 commit comments