From 6446a0128cd9a24fc570cc5052f9f7a6455f29d9 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Mon, 10 Dec 2012 15:49:00 -0500 Subject: [PATCH] Restore inverse math; drop arity from OPGetArgsIf --- src/Dyna/Analysis/RuleMode.hs | 49 +++++++++++++++++++---------------- src/Dyna/Backend/Python.hs | 2 +- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/Dyna/Analysis/RuleMode.hs b/src/Dyna/Analysis/RuleMode.hs index a672da9..11e5286 100644 --- a/src/Dyna/Analysis/RuleMode.hs +++ b/src/Dyna/Analysis/RuleMode.hs @@ -124,10 +124,10 @@ cruxVars cr = case cr of data DOpAMine = OPAssign DVar NTV -- -+ | OPCheck DVar DVar -- ++ - | OPGetArgsIf [DVar] DVar DFunct Int -- -+ + | OPGetArgsIf [DVar] DVar DFunct -- -+ | OPBuild DVar [DVar] DFunct -- -+ - | OPCall DVar [NTV] DFunct -- -+ + | OPCall DVar [DVar] DFunct -- -+ | OPIter (ModedVar) [ModedVar] DFunct -- ?? | OPIndirEval DVar DVar -- -+ deriving (Eq,Ord,Show) @@ -139,13 +139,13 @@ data Det = Det -- ^ Exactly one answer detOfDop :: DOpAMine -> Det detOfDop x = case x of - OPAssign _ _ -> Det - OPCheck _ _ -> DetSemi - OPGetArgsIf _ _ _ _ -> DetSemi - OPBuild _ _ _ -> Det - OPIndirEval _ _ -> DetSemi - OPCall _ _ _ -> Det - OPIter o is _ -> -- XXX + OPAssign _ _ -> Det + OPCheck _ _ -> DetSemi + OPGetArgsIf _ _ _ -> DetSemi + OPBuild _ _ _ -> Det + OPIndirEval _ _ -> DetSemi + OPCall _ _ _ -> Det + OPIter o is _ -> -- XXX case (modeOf o, foldr min MBound (map modeOf is)) of (MFree, MBound) -> DetSemi _ -> DetNon @@ -186,7 +186,7 @@ possible cr = case cr of else [] -- On the other hand, if the output is known, then any subset -- of the inputs may be known and will be checked. - MB o' -> [ (OPGetArgsIf is' o' funct $ length is) + MB o' -> [ (OPGetArgsIf is' o' funct) : map (\(c,x) -> (OPCheck c x)) cis ] where @@ -201,7 +201,7 @@ possible cr = case cr of CFCall o is funct | isMath funct -> if not $ all isBound is then inv funct is o - else let is' = map (NTVar . varOfMV) is in + else let is' = map varOfMV is in case o of MF o' -> [[OPCall o' is' funct]] MB o' -> let cv = "_chk" @@ -215,18 +215,21 @@ possible cr = case cr of where - {- - inv "+" is' (MB o') | length is' == 2 - = case L.partition isFree is' of - ([MF fi],bis) -> Just ("-",o':map ntvOfMNT bis,fi) - _ -> Nothing + -- XXX this really ought to be done some other way + inv :: DFunct -> [ModedVar] -> ModedVar -> [Action] + inv "+" is (MB o) + = case L.partition isFree is of + ([MF fi],bis) -> let cv = "_tmp" + bis' = map varOfMV bis + in [[ OPCall cv bis' "+" + , OPCall fi [o, cv] "-"]] + _ -> [] - inv "-" [(MB x),(MF y)] (MB o') - = Just ("-",[x,o'],y) + inv "-" [(MB x),(MF y)] (MB o) + = [[ OPCall y [x,o] "-" ]] - inv "-" [(MF x),(MB y)] (MB o') - = Just ("+",[o',y],x) - -} + inv "-" [(MF x),(MB y)] (MB o) + = [[ OPCall x [o,y] "+" ]] inv _ _ _ = [] @@ -267,7 +270,7 @@ simpleCost (PP { pp_score = osc, pp_plan = pfx }) act = stepCost x = case x of OPAssign _ _ -> 1 OPCheck _ _ -> 2 - OPGetArgsIf _ _ _ _ -> 1 + OPGetArgsIf _ _ _ -> 1 OPBuild _ _ _ -> 1 OPCall _ _ _ -> 1 OPIter o is _ -> 2 * (fromIntegral $ length $ filter isFree (o:is)) @@ -316,7 +319,7 @@ stepAgenda st sc = go initialPlanForCrux :: DVar -> DVar -> Crux DVar a -> Action initialPlanForCrux hi v cr = case cr of - CFCall o is f -> [ OPGetArgsIf is hi f $ length is, OPAssign o (NTVar v) ] + CFCall o is f -> [ OPGetArgsIf is hi f, OPAssign o (NTVar v) ] _ -> error "Don't know how to initially plan !CFCall" -- | Given a normalized form and an initial crux, saturate the graph and diff --git a/src/Dyna/Backend/Python.hs b/src/Dyna/Backend/Python.hs index f96b329..765f61f 100644 --- a/src/Dyna/Backend/Python.hs +++ b/src/Dyna/Backend/Python.hs @@ -58,7 +58,7 @@ pdope :: DOpAMine -> Doc e pdope (OPIndirEval _ _) = error "indirect evaluation not implemented" pdope (OPAssign v val) = pretty v <+> equals <+> pretty val pdope (OPCheck v val) = hsep ["assert", pretty v, "==", pretty val] -pdope (OPGetArgsIf vs id f a) = -- XXX: arity is implied; drop extra variable to avoid possible inconsistencies? +pdope (OPGetArgsIf vs id f) = tupled (map pretty vs) <+> equals <+> functorIndirect "peel" f vs <> (parens $ pretty id) -- 2.50.1