From 9c3825e0d4fe49b591c0a34418e2c3cac5e98965 Mon Sep 17 00:00:00 2001 From: ProgramSnail Date: Wed, 26 Nov 2025 12:36:22 +0300 Subject: [PATCH] fix: do not exclude expressions with new examples from the pool (do not consider them nonequal to any other) --- escher/Eval.hs | 2 +- escher/Main.hs | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/escher/Eval.hs b/escher/Eval.hs index 647e1d8..175afc8 100644 --- a/escher/Eval.hs +++ b/escher/Eval.hs @@ -103,7 +103,7 @@ eval conf (SelfE es) = do recInput <- foldM (\es e -> consValsM es (eval conf e) case (oracleFunc $ confOracle conf) recInput of Just recOutput -> if recInput `elem` confExamples conf || not (confTryFindExamples conf) -- TODO: better way then return recOutput - else NewExamples $ trace ("New example: " ++ show [(recInput, recOutput)]) [(recInput, recOutput)] + else NewExamples {- $ trace ("New example: " ++ show [(recInput, recOutput)]) -} [(recInput, recOutput)] Nothing -> FatalError $ "no oracle output on " ++ show recInput where consValsM :: [Value] -> Result Value -> Result [Value] consValsM vs (Result v) = Result $ v : vs diff --git a/escher/Main.hs b/escher/Main.hs index 8cab43b..bb68f41 100644 --- a/escher/Main.hs +++ b/escher/Main.hs @@ -52,6 +52,10 @@ calcExprOutputs :: Expr -> SyntState [Result Value] calcExprOutputs expr = do examples <- gets syntExamples mapM (`syntEval` expr) examples -- OR: syntCacheEval (slower?) +calcExprExOutputs :: Expr -> SyntState [Result Value] +calcExprExOutputs expr = do examples <- gets syntExamples + mapM (`syntEvalEx` expr) examples + calcTemporaryExprOutputs :: Expr -> SyntState [Result Value] calcTemporaryExprOutputs expr = do examples <- gets syntExamples mapM (`syntEval` expr) examples @@ -61,7 +65,7 @@ matchAnyOutputs outputs = do exprs <- gets syntExprs foldM step False $ map fst exprs where step :: Bool -> Expr -> SyntState Bool step True _ = return True - step False expr = do exprOutputs <- calcExprOutputs expr + step False expr = do exprOutputs <- calcExprExOutputs expr -- NOTE: compare with examples to not throw out elements that possibly diffenernt on new examples return $ outputs == exprOutputs -- and $ zipWith sameResults outputs exprOutputs sameResults (Result left) (Result right) = left == right sameResults (RecError {}) (RecError {}) = True @@ -74,7 +78,7 @@ forwardStep comp args = do let expr = fillHoles comp args if isNothing $ checkType typeConf expr then return Nothing else do - outputs <- calcTemporaryExprOutputs expr + outputs <- calcExprExOutputs expr -- NOTE: compare with examples to not throw out elements that possibly diffenernt on new examples matchedExisting <- matchAnyOutputs outputs -- TODO: all RecErrors example could be useful on future cases ? if matchedExisting || any isFatalError outputs || all isRecError outputs @@ -346,7 +350,8 @@ idOracle [x] = Just x idOracle _ = Nothing main = do steps <- readLn :: IO Int - print $ fst $ syntesis steps (listOracleOf reverseOracle $ ListT IntT) allExamples + -- print $ fst $ syntesis steps (listOracleOf reverseOracle $ ListT IntT) allExamples + print $ fst $ syntesis steps (listOracleOf stutterOracle $ ListT IntT) allExamples -- main = print $ (SelfE (TailE (InputE ZeroE) ::: EmptyListE) :++: (HeadE (InputE ZeroE) ::: EmptyListE)) `elem` (map fst $ syntExprs $ snd $ syntesis 10 reverseOracle allExamples) -- Just (IfE {ifCond = IsEmptyE (InputE ZeroE), ifDoThen = InputE ZeroE :++: TailE (InputE ZeroE :++: (InputE ZeroE :++: (ZeroE ::: EmptyListE))), ifDoElse = SelfE (TailE (InputE ZeroE) ::: EmptyListE) :++: (HeadE (InputE ZeroE) ::: EmptyListE)})