mirror of
https://codeberg.org/ProgramSnail/prog_synthesis.git
synced 2025-12-05 21:18:42 +00:00
02: unique exprs: use reduced exprs set in next steps
This commit is contained in:
parent
99b0b9d672
commit
07195be85e
1 changed files with 5 additions and 3 deletions
8
02.hs
8
02.hs
|
|
@ -157,7 +157,9 @@ upSyntesis examples steps = upSyntesisRec examples steps $ nextSimpleExprs termi
|
|||
|
||||
-----
|
||||
|
||||
upSyntesisStep' :: [Example] -> [Expr] -> [Expr] -> Either [Expr] Expr
|
||||
data ExprsPair = ExprsPair [Expr] [Expr]
|
||||
|
||||
upSyntesisStep' :: [Example] -> [Expr] -> [Expr] -> Either ExprsPair Expr
|
||||
upSyntesisStep' examples newExprs oldExprs =
|
||||
case find (isCorrect examples) newExprs of
|
||||
Just answer -> Right answer
|
||||
|
|
@ -166,13 +168,13 @@ upSyntesisStep' examples newExprs oldExprs =
|
|||
let newExprs'' = foldl (\acc expr -> if any (areSame examples expr) acc then acc else expr : acc) [] newExprs' in -- merge same values
|
||||
Left $
|
||||
-- nextSimpleExprs $
|
||||
nextExprs' newExprs'' oldExprs
|
||||
ExprsPair (nextExprs' newExprs'' oldExprs) newExprs''
|
||||
|
||||
upSyntesisRec' :: [Example] -> Int -> [Expr] -> [Expr] -> Maybe Expr
|
||||
upSyntesisRec' _ 0 _ _ = Nothing
|
||||
upSyntesisRec' examples steps newExprs oldExprs = case upSyntesisStep' examples newExprs oldExprs of
|
||||
Right answer -> Just answer
|
||||
Left exprs -> upSyntesisRec' examples (steps - 1) exprs (newExprs ++ oldExprs)
|
||||
Left (ExprsPair newExprs' oldExprs') -> upSyntesisRec' examples (steps - 1) newExprs' (oldExprs' ++ oldExprs)
|
||||
|
||||
upSyntesis' :: [Example] -> Int -> Maybe Expr
|
||||
upSyntesis' examples steps = upSyntesisRec' examples steps (nextSimpleExprs terminals) []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue