mirror of
https://codeberg.org/ProgramSnail/prog_synthesis.git
synced 2025-12-06 05:28:42 +00:00
fix: do not exclude expressions with new examples from the pool (do not consider them nonequal to any other)
This commit is contained in:
parent
75dafdab5e
commit
9c3825e0d4
2 changed files with 9 additions and 4 deletions
|
|
@ -103,7 +103,7 @@ eval conf (SelfE es) = do recInput <- foldM (\es e -> consValsM es (eval conf e)
|
||||||
case (oracleFunc $ confOracle conf) recInput of
|
case (oracleFunc $ confOracle conf) recInput of
|
||||||
Just recOutput -> if recInput `elem` confExamples conf || not (confTryFindExamples conf) -- TODO: better way
|
Just recOutput -> if recInput `elem` confExamples conf || not (confTryFindExamples conf) -- TODO: better way
|
||||||
then return recOutput
|
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
|
Nothing -> FatalError $ "no oracle output on " ++ show recInput
|
||||||
where consValsM :: [Value] -> Result Value -> Result [Value]
|
where consValsM :: [Value] -> Result Value -> Result [Value]
|
||||||
consValsM vs (Result v) = Result $ v : vs
|
consValsM vs (Result v) = Result $ v : vs
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,10 @@ calcExprOutputs :: Expr -> SyntState [Result Value]
|
||||||
calcExprOutputs expr = do examples <- gets syntExamples
|
calcExprOutputs expr = do examples <- gets syntExamples
|
||||||
mapM (`syntEval` expr) examples -- OR: syntCacheEval (slower?)
|
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 -> SyntState [Result Value]
|
||||||
calcTemporaryExprOutputs expr = do examples <- gets syntExamples
|
calcTemporaryExprOutputs expr = do examples <- gets syntExamples
|
||||||
mapM (`syntEval` expr) examples
|
mapM (`syntEval` expr) examples
|
||||||
|
|
@ -61,7 +65,7 @@ matchAnyOutputs outputs = do exprs <- gets syntExprs
|
||||||
foldM step False $ map fst exprs
|
foldM step False $ map fst exprs
|
||||||
where step :: Bool -> Expr -> SyntState Bool
|
where step :: Bool -> Expr -> SyntState Bool
|
||||||
step True _ = return True
|
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
|
return $ outputs == exprOutputs -- and $ zipWith sameResults outputs exprOutputs
|
||||||
sameResults (Result left) (Result right) = left == right
|
sameResults (Result left) (Result right) = left == right
|
||||||
sameResults (RecError {}) (RecError {}) = True
|
sameResults (RecError {}) (RecError {}) = True
|
||||||
|
|
@ -74,7 +78,7 @@ forwardStep comp args = do let expr = fillHoles comp args
|
||||||
if isNothing $ checkType typeConf expr
|
if isNothing $ checkType typeConf expr
|
||||||
then return Nothing
|
then return Nothing
|
||||||
else do
|
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
|
matchedExisting <- matchAnyOutputs outputs
|
||||||
-- TODO: all RecErrors example could be useful on future cases ?
|
-- TODO: all RecErrors example could be useful on future cases ?
|
||||||
if matchedExisting || any isFatalError outputs || all isRecError outputs
|
if matchedExisting || any isFatalError outputs || all isRecError outputs
|
||||||
|
|
@ -346,7 +350,8 @@ idOracle [x] = Just x
|
||||||
idOracle _ = Nothing
|
idOracle _ = Nothing
|
||||||
|
|
||||||
main = do steps <- readLn :: IO Int
|
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)
|
-- 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)})
|
-- 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)})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue