fix: do not exclude expressions with new examples from the pool (do not consider them nonequal to any other)

This commit is contained in:
ProgramSnail 2025-11-26 12:36:22 +03:00
parent 75dafdab5e
commit 9c3825e0d4
2 changed files with 9 additions and 4 deletions

View file

@ -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)})