mirror of
https://codeberg.org/ProgramSnail/prog_synthesis.git
synced 2025-12-06 13:38:42 +00:00
02: unique exprs: merge lists manually
This commit is contained in:
parent
da9ceb714e
commit
bffbf6e0b2
1 changed files with 30 additions and 26 deletions
56
02.hs
56
02.hs
|
|
@ -71,19 +71,20 @@ concatShuffle xxs = let xxs' = filter (not . null) xxs in
|
||||||
map head xxs' ++ concatShuffle (map tail xxs')
|
map head xxs' ++ concatShuffle (map tail xxs')
|
||||||
|
|
||||||
nextSimpleExprsLists :: [Expr] -> [[Expr]]
|
nextSimpleExprsLists :: [Expr] -> [[Expr]]
|
||||||
nextSimpleExprsLists exprs = [[Succ e | e <- exprs, typeOf e == IntT],
|
nextSimpleExprsLists exprs = let listExprs = [ e | e <- exprs, typeOf e == ListT] in
|
||||||
[Sort e | e <- exprs, typeOf e == ListT],
|
[[Succ e | e <- exprs, typeOf e == IntT],
|
||||||
[Recursive e | e <- exprs, typeOf e == ListT],
|
map Sort listExprs,
|
||||||
[FirstZero e | e <- exprs, typeOf e == ListT],
|
map Recursive listExprs,
|
||||||
[Len e | e <- exprs, typeOf e == ListT]]
|
map FirstZero listExprs,
|
||||||
|
map Len listExprs]
|
||||||
|
|
||||||
nextExprsLists :: [Expr] -> [[Expr]]
|
nextExprsLists :: [Expr] -> [[Expr]]
|
||||||
nextExprsLists exprs = nextSimpleExprsLists exprs ++
|
nextExprsLists exprs = let listExprs = [ e | e <- exprs, typeOf e == ListT] in
|
||||||
[[e :+: e' | e <- exprs, typeOf e == ListT,
|
let intExprs = [ e | e <- exprs, typeOf e == IntT] in
|
||||||
e' <- exprs, typeOf e' == ListT],
|
nextSimpleExprsLists exprs ++
|
||||||
[SubList e from to | e <- exprs, typeOf e == ListT,
|
[[e :+: e' | e <- listExprs,
|
||||||
from <- exprs, typeOf from == IntT,
|
e' <- listExprs],
|
||||||
to <- exprs, typeOf to == IntT]]
|
[SubList e from to | e <- listExprs, from <- intExprs, to <- intExprs]]
|
||||||
|
|
||||||
nextSimpleExprs :: [Expr] -> [Expr]
|
nextSimpleExprs :: [Expr] -> [Expr]
|
||||||
nextSimpleExprs exprs = (++) exprs $ concatShuffle $ nextSimpleExprsLists exprs
|
nextSimpleExprs exprs = (++) exprs $ concatShuffle $ nextSimpleExprsLists exprs
|
||||||
|
|
@ -107,20 +108,22 @@ nextSimpleExprs' = concatShuffle . nextSimpleExprsLists
|
||||||
|
|
||||||
-- TODO: check formula for three args
|
-- TODO: check formula for three args
|
||||||
nextExprsLists' :: [Expr] -> [Expr] -> [[Expr]]
|
nextExprsLists' :: [Expr] -> [Expr] -> [[Expr]]
|
||||||
nextExprsLists' prevExprs allExprs = nextSimpleExprsLists prevExprs ++
|
nextExprsLists' prevExprs allExprs = let notPrevExprs = [e | e <- allExprs, e `notElem` prevExprs] in
|
||||||
[[e :+: e' | e <- prevExprs, typeOf e == ListT,
|
let listPrevExprs = [ e | e <- prevExprs, typeOf e == ListT] in
|
||||||
e' <- allExprs, typeOf e' == ListT],
|
let intPrevExprs = [ e | e <- prevExprs, typeOf e == IntT] in
|
||||||
[e :+: e' | e <- allExprs, typeOf e == ListT, e `notElem` prevExprs,
|
let listNotPrevExprs = [ e | e <- notPrevExprs, typeOf e == ListT] in
|
||||||
e' <- prevExprs, typeOf e' == ListT],
|
let intNotPrevExprs = [ e | e <- notPrevExprs, typeOf e == IntT] in
|
||||||
[SubList e from to | e <- prevExprs, typeOf e == ListT,
|
nextSimpleExprsLists prevExprs ++
|
||||||
from <- allExprs, typeOf from == IntT,
|
[[e :+: e' | e <- listPrevExprs, e' <- listPrevExprs],
|
||||||
to <- allExprs, typeOf to == IntT],
|
[e :+: e' | e <- listPrevExprs, e' <- listNotPrevExprs],
|
||||||
[SubList e from to | e <- allExprs, typeOf e == ListT, e `notElem` prevExprs,
|
[e :+: e' | e <- listNotPrevExprs, e' <- listPrevExprs],
|
||||||
from <- prevExprs, typeOf from == IntT,
|
[SubList e from to | e <- listPrevExprs, from <- intPrevExprs, to <- intPrevExprs],
|
||||||
to <- allExprs, typeOf to == IntT],
|
[SubList e from to | e <- listNotPrevExprs, from <- intPrevExprs, to <- intPrevExprs],
|
||||||
[SubList e from to | e <- allExprs, typeOf e == ListT, e `notElem` prevExprs,
|
[SubList e from to | e <- listPrevExprs, from <- intNotPrevExprs, to <- intPrevExprs],
|
||||||
from <- allExprs, typeOf from == IntT, from `notElem` prevExprs,
|
[SubList e from to | e <- listPrevExprs, from <- intPrevExprs, to <- intNotPrevExprs],
|
||||||
to <- prevExprs, typeOf to == IntT]]
|
[SubList e from to | e <- listNotPrevExprs, from <- intNotPrevExprs, to <- intPrevExprs],
|
||||||
|
[SubList e from to | e <- listNotPrevExprs, from <- intPrevExprs, to <- intNotPrevExprs],
|
||||||
|
[SubList e from to | e <- listPrevExprs, from <- intNotPrevExprs, to <- intNotPrevExprs]]
|
||||||
|
|
||||||
nextExprs' :: [Expr] -> [Expr] -> [Expr]
|
nextExprs' :: [Expr] -> [Expr] -> [Expr]
|
||||||
nextExprs' prevExprs allExprs = concatShuffle $ nextExprsLists' prevExprs allExprs
|
nextExprs' prevExprs allExprs = concatShuffle $ nextExprsLists' prevExprs allExprs
|
||||||
|
|
@ -141,7 +144,8 @@ areSame examples exprLeft exprRight | typeOf exprLeft == IntT = False
|
||||||
| typeOf exprRight == IntT = False
|
| typeOf exprRight == IntT = False
|
||||||
| otherwise = all (\Example {exampleInput, exampleOutput} -> let Just resLeft = execProg exampleInput exprLeft in
|
| otherwise = all (\Example {exampleInput, exampleOutput} -> let Just resLeft = execProg exampleInput exprLeft in
|
||||||
let Just resRight = execProg exampleInput exprRight in
|
let Just resRight = execProg exampleInput exprRight in
|
||||||
resLeft /= [] && resLeft == resRight) examples
|
resLeft /= [] -- NOTE: not in the base algorithm, way to remove rec deletion (?)
|
||||||
|
&& resLeft == resRight) examples
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue