code-conjure 0.6.4 → 0.6.6
raw patch · 78 files changed
+1135/−874 lines, 78 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Conjure: [earlyTests] :: Args -> Bool
+ Conjure.Conjurable: conjureTestDefn :: Conjurable f => Int -> Int -> String -> f -> Defn
+ Conjure.Engine: [earlyTests] :: Args -> Bool
- Conjure: Args :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Args
+ Conjure: Args :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Args
- Conjure: Results :: [[Defn]] -> [[Defn]] -> [Expr] -> Thy -> [[Defn]] -> [Expr] -> Results
+ Conjure: Results :: [[Defn]] -> [[Defn]] -> Defn -> Thy -> [[Defn]] -> [Expr] -> Results
- Conjure: [bindings] :: Results -> [Expr]
+ Conjure: [bindings] :: Results -> Defn
- Conjure.Engine: Args :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Args
+ Conjure.Engine: Args :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Args
- Conjure.Engine: Results :: [[Defn]] -> [[Defn]] -> [Expr] -> Thy -> [[Defn]] -> [Expr] -> Results
+ Conjure.Engine: Results :: [[Defn]] -> [[Defn]] -> Defn -> Thy -> [[Defn]] -> [Expr] -> Results
- Conjure.Engine: [bindings] :: Results -> [Expr]
+ Conjure.Engine: [bindings] :: Results -> Defn
Files
- README.md +30/−28
- TODO.md +0/−48
- bench/carry-on.txt +6/−6
- bench/gps.txt +79/−79
- bench/gps2.txt +64/−64
- bench/ill-hit.txt +5/−5
- bench/lowtests.txt +6/−6
- bench/runtime/zero/bench/candidates.runtime +1/−1
- bench/runtime/zero/bench/carry-on.runtime +1/−1
- bench/runtime/zero/bench/erroneous.runtime +1/−1
- bench/runtime/zero/bench/gps.runtime +1/−1
- bench/runtime/zero/bench/gps2.runtime +1/−1
- bench/runtime/zero/bench/ill-hit.runtime +1/−1
- bench/runtime/zero/bench/lowtests.runtime +1/−1
- bench/runtime/zero/bench/p12.runtime +1/−1
- bench/runtime/zero/bench/redundants.runtime +1/−1
- bench/runtime/zero/bench/strategies.runtime +1/−1
- bench/runtime/zero/bench/terpret.runtime +1/−1
- bench/runtime/zero/bench/unique.runtime +1/−1
- bench/runtime/zero/eg/arith.runtime +1/−1
- bench/runtime/zero/eg/bits.runtime +1/−1
- bench/runtime/zero/eg/bools.runtime +1/−1
- bench/runtime/zero/eg/bst.runtime +1/−1
- bench/runtime/zero/eg/count.runtime +1/−1
- bench/runtime/zero/eg/dupos.runtime +1/−1
- bench/runtime/zero/eg/either.runtime +1/−1
- bench/runtime/zero/eg/factorial.runtime +1/−1
- bench/runtime/zero/eg/fib01.runtime +1/−1
- bench/runtime/zero/eg/fibonacci.runtime +1/−1
- bench/runtime/zero/eg/gcd.runtime +1/−1
- bench/runtime/zero/eg/higher.runtime +1/−1
- bench/runtime/zero/eg/ints.runtime +1/−1
- bench/runtime/zero/eg/list.runtime +1/−1
- bench/runtime/zero/eg/maybe.runtime +1/−1
- bench/runtime/zero/eg/peano.runtime +1/−1
- bench/runtime/zero/eg/pow.runtime +1/−1
- bench/runtime/zero/eg/replicate.runtime +1/−1
- bench/runtime/zero/eg/sort.runtime +1/−1
- bench/runtime/zero/eg/spec.runtime +1/−1
- bench/runtime/zero/eg/subset.runtime +1/−1
- bench/runtime/zero/eg/take-drop.runtime +1/−1
- bench/runtime/zero/eg/these.runtime +1/−1
- bench/runtime/zero/eg/tree.runtime +1/−1
- bench/runtime/zero/eg/tri.runtime +1/−1
- bench/self.txt +6/−6
- bench/strategies.txt +24/−24
- bench/terpret.txt +48/−48
- bench/weird.txt +3/−3
- changelog.md +13/−0
- code-conjure.cabal +2/−2
- eg/arith.txt +3/−3
- eg/bools.txt +12/−12
- eg/bst.txt +29/−28
- eg/colin/ListFuns.hs +93/−9
- eg/colin/ListFuns.txt +132/−51
- eg/count.txt +5/−5
- eg/dupos.txt +37/−37
- eg/either.txt +6/−6
- eg/fib01.txt +5/−5
- eg/fibonacci.txt +4/−4
- eg/higher.txt +3/−3
- eg/ints.txt +12/−12
- eg/list.txt +41/−41
- eg/peano.txt +11/−11
- eg/pow.txt +14/−14
- eg/replicate.txt +10/−10
- eg/setelem.txt +12/−12
- eg/sort.txt +74/−69
- eg/subset.txt +8/−8
- eg/take-drop.txt +16/−16
- eg/tapps.txt +13/−13
- eg/these.txt +26/−26
- eg/tree.txt +43/−43
- src/Conjure.hs +14/−13
- src/Conjure/Conjurable.hs +106/−1
- src/Conjure/Engine.hs +47/−58
- src/Conjure/Prim.hs +8/−8
- test/conjurable.hs +28/−0
README.md view
@@ -75,16 +75,16 @@ passing the function name, the partial definition and the list of primitives: factorial :: Int -> Int- -- testing 4 combinations of argument values- -- pruning with 27/65 rules- -- looking through 3 candidates of size 1- -- looking through 3 candidates of size 2- -- looking through 7 candidates of size 3- -- looking through 8 candidates of size 4- -- looking through 28 candidates of size 5- -- looking through 35 candidates of size 6- -- looking through 167 candidates of size 7- -- tested 95 candidates+ -- 0.1s, testing 4 combinations of argument values+ -- 0.8s, pruning with 27/65 rules+ -- 0.8s, 3 candidates of size 1+ -- 0.9s, 3 candidates of size 2+ -- 0.9s, 7 candidates of size 3+ -- 0.9s, 8 candidates of size 4+ -- 0.9s, 28 candidates of size 5+ -- 0.9s, 35 candidates of size 6+ -- 0.9s, 167 candidates of size 7+ -- 0.9s, tested 95 candidates factorial 0 = 1 factorial x = x * factorial (x - 1) @@ -128,11 +128,11 @@ > , prim "-" ((-) :: Int -> Int -> Int) > ] take :: Int -> [A] -> [A]- -- testing 153 combinations of argument values- -- pruning with 4/7 rules- -- ... ... ...- -- looking through 58 candidates of size 9- -- tested 104 candidates+ -- 0.2s, testing 153 combinations of argument values+ -- 0.2s, pruning with 4/7 rules+ -- ... ... ... ... ...+ -- 0.4s, 5 candidates of size 9+ -- 0.4s, tested 15 candidates take 0 xs = [] take x [] = [] take x (y:xs) = y:take (x - 1) xs@@ -181,13 +181,13 @@ duplicates' [1,2,3,3,3] = [3] duplicates' [1,2,2,3,3] = [2,3] -Here is what [`conjureWith`] prints:+Here is what [`conjure`] prints: - > conjureWith args{maxSize=18} "duplicates" duplicates primitives+ > conjure "duplicates" duplicates primitives duplicates :: [Int] -> [Int] -- testing 1 combinations of argument values -- pruning with 21/26 rules- -- looking through 2 candidates of size 1+ -- ... ... ... duplicates xs = xs The generated function clearly does not follow our specification.@@ -204,14 +204,13 @@ duplicates [0,1] = [] duplicates [1,0,1] = [1] -Here is what [`conjureWith`] now prints:+Here is what [`conjure`] now prints: - > conjureWith args{maxSize=18} "duplicates" duplicates primitives+ > conjure "duplicates" duplicates primitives duplicates :: [Int] -> [Int] -- testing 3 combinations of argument values -- pruning with 21/26 rules- -- ...- -- looking through 16 candidates of size 9+ -- ... ... ... duplicates [] = [] duplicates (x:xs) = if elem x xs then [x] else [] @@ -247,14 +246,17 @@ Now Conjure prints a correct implementation: - > conjureWith args{maxSize=18} "duplicates" duplicates primitives+ > conjure "duplicates" duplicates primitives duplicates :: [Int] -> [Int]- -- testing 6 combinations of argument values- -- ...- -- looking through 2189 candidates of size 17+ -- 0.2s, testing 6 combinations of argument values+ -- 0.3s, pruning with 21/26 rules+ -- ... ... ... ... ...+ -- 2.1s, 1723 candidates of size 17+ -- 2.1s, tested 1705 candidates duplicates [] = []- duplicates (x:xs) = if elem x xs && not (elem x (duplicates xs)) then x:duplicates xs else duplicates xs- (in 1.5s)+ duplicates (x:xs) = if elem x xs && not (elem x (duplicates xs))+ then x:duplicates xs+ else duplicates xs In this case, specifying the function with specific argument-result bindings
TODO.md view
@@ -3,10 +3,6 @@ A non-exhaustive list of things TO DO for Conjure. -* fix targetiers' lazyness--* rewrite after filling in recursions- * Better error reporting when `Listable` is out-of-scope when using `deriveConjurable`. This needs to be implemented on LeanCheck itself. @@ -15,50 +11,6 @@ * consider the size of patterns to thin-out each size partition * consider non top-level cases---## Rewrite after filling in recursions--When Conjure conjures length, it does it like so:-- length [] = 0- length (x:xs) = length xs + 1--However, the following would precede in term-rewriting order:-- length [] = 0- length (x:xs) = 1 + length xs--The problem is that `_ + 1` precedes `1 + _` in our term rewriting order,-so when we do the recursion fillings, we get the first version not the second.--Rewriting after filling in recursions would make it so that we get the wanted-second.--There's an opportunity for a late pruning rule here:--If we rewrite any of the RHS to a smaller expression. We can prune away that-candidate. Considering sub from `eg/colin/ListFuns.hs`:--We encounter the following candidate:-- sub xs [] = True- sub xs (x:ys) = sub ys ys && sub ys ys--It can be pruned away by simplifying the last RHS to `sub ys ys`:-`p && p` is `p`!-We need to do this pruning in the `fillingsFor` for the most performance gain.--Beware,-we can't really just check for normality: as we can have:-- length xs + 1--without having-- 1 + length xs--We may rewrite to a term of the same size that would not be generated! ## Forbid recursion into negatives
bench/carry-on.txt view
@@ -28,20 +28,20 @@ factorial 1 = 1 factorial x = x * factorial (x - 1) --- 1301 candidates of size 10--- 7201 candidates of size 11--- tested 3216 candidates+-- 1299 candidates of size 10+-- 7200 candidates of size 11+-- tested 3213 candidates factorial 0 = 1 factorial x = x + x * (factorial (x - 1) - 1) --- tested 3396 candidates+-- tested 3393 candidates factorial 0 = 1 factorial x = x - x * (1 - factorial (x - 1)) --- tested 3519 candidates+-- tested 3516 candidates factorial 0 = 1 factorial x = (0 - x) * (0 - factorial (x - 1)) --- tested 10004 candidates+-- tested 10001 candidates cannot conjure
bench/gps.txt view
@@ -39,7 +39,7 @@ -- 0 candidates of size 5 -- 1248 candidates of size 6 -- 0 candidates of size 7--- 18672 candidates of size 8+-- 17008 candidates of size 8 -- tested 12358 candidates gps3 x y z = enumFromThenTo x (x + z) (y - 1) @@ -68,22 +68,22 @@ -- 0 candidates of size 6 -- 0 candidates of size 7 -- 0 candidates of size 8--- 102 candidates of size 9--- 30 candidates of size 10+-- 51 candidates of size 9+-- 0 candidates of size 10 -- 15 candidates of size 11--- tested 141 candidates+-- tested 60 candidates gps4 cs ds es = length cs < length ds && length ds < length es gps5 :: [Char] -> [Char] -- testing 5 combinations of argument values -- pruning with 2/3 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 2 candidates of size 3--- 6 candidates of size 4+-- 0 candidates of size 4 -- 4 candidates of size 5--- 13 candidates of size 6--- tested 28 candidates+-- 0 candidates of size 6+-- tested 8 candidates cannot conjure gps6 :: Int -> Int@@ -147,12 +147,12 @@ -- 1 candidates of size 1 -- 0 candidates of size 2 -- 3 candidates of size 3--- 15 candidates of size 4+-- 0 candidates of size 4 -- 4 candidates of size 5--- 86 candidates of size 6+-- 0 candidates of size 6 -- 5 candidates of size 7--- 513 candidates of size 8--- tested 564 candidates+-- 1 candidates of size 8+-- tested 14 candidates wallisNext (x % y) = (y + 1) % (x + 1) wallisNext :: Ratio Integer -> Ratio Integer@@ -161,12 +161,12 @@ -- 1 candidates of size 1 -- 0 candidates of size 2 -- 4 candidates of size 3--- 16 candidates of size 4+-- 0 candidates of size 4 -- 3 candidates of size 5--- 71 candidates of size 6+-- 0 candidates of size 6 -- 5 candidates of size 7--- 393 candidates of size 8--- tested 451 candidates+-- 1 candidates of size 8+-- tested 14 candidates wallisNext (x % y) = (y + 1) % (x + 1) gps10 :: Int -> Ratio Integer@@ -200,11 +200,11 @@ -- 0 candidates of size 2 -- 0 candidates of size 3 -- 0 candidates of size 4--- 1 candidates of size 5+-- 0 candidates of size 5 -- 2 candidates of size 6 -- 0 candidates of size 7--- 2 candidates of size 8--- tested 5 candidates+-- 1 candidates of size 8+-- tested 4 candidates gps11 [] = [] gps11 (cs:css) = gps11 css ++ [length cs] @@ -212,31 +212,31 @@ -- testing 6 combinations of argument values -- pruning with 13/27 rules -- 2 candidates of size 1--- 5 candidates of size 2--- 2 candidates of size 3--- 9 candidates of size 4--- 22 candidates of size 5--- 41 candidates of size 6--- 125 candidates of size 7--- 262 candidates of size 8--- 816 candidates of size 9--- 1996 candidates of size 10--- 5925 candidates of size 11--- tested 6320 candidates+-- 1 candidates of size 2+-- 0 candidates of size 3+-- 3 candidates of size 4+-- 12 candidates of size 5+-- 13 candidates of size 6+-- 65 candidates of size 7+-- 102 candidates of size 8+-- 416 candidates of size 9+-- 956 candidates of size 10+-- 3073 candidates of size 11+-- tested 4404 candidates gps12 xs = (length xs - fromJust (findIndex (0 ==) (reverse xs))) - 1 gps13 :: [Ratio Integer] -> Ratio Integer -- testing 3 combinations of argument values -- pruning with 4/8 rules -- 1 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 2 candidates of size 3--- 10 candidates of size 4--- 13 candidates of size 5--- 51 candidates of size 6--- 103 candidates of size 7--- 360 candidates of size 8--- tested 267 candidates+-- 2 candidates of size 4+-- 9 candidates of size 5+-- 12 candidates of size 6+-- 67 candidates of size 7+-- 97 candidates of size 8+-- tested 179 candidates gps13 qs = foldr (+) 0 qs / fromIntegral (length qs) odd :: Int -> Bool@@ -264,13 +264,13 @@ -- testing 3 combinations of argument values -- pruning with 39/58 rules -- 3 candidates of size 1--- 9 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 27 candidates of size 4+-- 0 candidates of size 4 -- 30 candidates of size 5--- 240 candidates of size 6--- 453 candidates of size 7--- tested 353 candidates+-- 6 candidates of size 6+-- 345 candidates of size 7+-- tested 83 candidates gps14 [] = 0 gps14 (x:xs) = x + gps14 xs `mod` 2 @@ -315,15 +315,15 @@ -- testing 3 combinations of argument values -- pruning with 2/6 rules -- 3 candidates of size 1--- 8 candidates of size 2--- 11 candidates of size 3--- 23 candidates of size 4--- 86 candidates of size 5--- 84 candidates of size 6--- 354 candidates of size 7--- 353 candidates of size 8--- 1528 candidates of size 9--- tested 1409 candidates+-- 0 candidates of size 2+-- 0 candidates of size 3+-- 10 candidates of size 4+-- 25 candidates of size 5+-- 34 candidates of size 6+-- 138 candidates of size 7+-- 126 candidates of size 8+-- 743 candidates of size 9+-- tested 767 candidates gps18 [] xs = xs gps18 (x:xs) [] = xs gps18 (x:xs) (y:ys) = x + y:gps18 xs ys@@ -332,10 +332,10 @@ -- testing 3 combinations of argument values -- pruning with 2/7 rules -- 2 candidates of size 1--- 2 candidates of size 2--- 1 candidates of size 3+-- 0 candidates of size 2+-- 0 candidates of size 3 -- 10 candidates of size 4--- tested 13 candidates+-- tested 10 candidates gps18 xs ys = zipWith (+) xs ys gps19 :: Int -> [Char] -> [Char]@@ -389,14 +389,14 @@ -- 13 candidates of size 5 -- 28 candidates of size 6 -- 46 candidates of size 7--- 126 candidates of size 8+-- 125 candidates of size 8 -- 200 candidates of size 9--- 631 candidates of size 10--- 1068 candidates of size 11--- 3495 candidates of size 12--- 6381 candidates of size 13--- 20409 candidates of size 14--- tested 27895 candidates+-- 625 candidates of size 10+-- 1066 candidates of size 11+-- 3459 candidates of size 12+-- 6361 candidates of size 13+-- 20207 candidates of size 14+-- tested 27628 candidates pig1 "" = "ay" pig1 (c:cs) = if isVowel c then (c:cs) ++ "ay"@@ -416,16 +416,16 @@ -- testing 4 combinations of argument values -- pruning with 4/4 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 2 candidates of size 3--- 6 candidates of size 4+-- 0 candidates of size 4 -- 4 candidates of size 5--- 13 candidates of size 6+-- 0 candidates of size 6 -- 8 candidates of size 7--- 30 candidates of size 8--- 24 candidates of size 9--- 65 candidates of size 10--- tested 92 candidates+-- 0 candidates of size 8+-- 16 candidates of size 9+-- 4 candidates of size 10+-- tested 34 candidates gps21 [] = [] gps21 (x:xs) = (if x < 0 then 0 else x):gps21 xs @@ -452,16 +452,16 @@ -- testing 4 combinations of argument values -- pruning with 15/19 rules -- 1 candidates of size 1--- 2 candidates of size 2--- 3 candidates of size 3+-- 1 candidates of size 2+-- 0 candidates of size 3 -- 2 candidates of size 4--- 8 candidates of size 5--- 13 candidates of size 6--- 30 candidates of size 7--- 75 candidates of size 8--- 194 candidates of size 9--- 470 candidates of size 10--- tested 456 candidates+-- 2 candidates of size 5+-- 2 candidates of size 6+-- 14 candidates of size 7+-- 25 candidates of size 8+-- 71 candidates of size 9+-- 176 candidates of size 10+-- tested 245 candidates gps24 cs = chr (ord ' ' + sum (map ord cs) `mod` 64) gps25 :: Int -> [Int]@@ -531,9 +531,9 @@ -- 2 candidates of size 5 -- 6 candidates of size 6 -- 10 candidates of size 7--- 10 candidates of size 8+-- 8 candidates of size 8 -- 24 candidates of size 9--- tested 38 candidates+-- tested 36 candidates gps29 "" = 0 gps29 (c:cs) = gps29 cs + (if isVowel c then 1 else 0)
bench/gps2.txt view
@@ -32,10 +32,10 @@ -- testing 6 combinations of argument values -- pruning with 8/9 rules -- 4 candidates of size 1--- 24 candidates of size 2--- 75 candidates of size 3--- 216 candidates of size 4--- tested 319 candidates+-- 0 candidates of size 2+-- 11 candidates of size 3+-- 29 candidates of size 4+-- tested 44 candidates cannot conjure gps2 :: Double -> Double -> Int -> Double@@ -43,11 +43,11 @@ -- pruning with 2/6 rules -- 2 candidates of size 1 -- 2 candidates of size 2--- 18 candidates of size 3--- 66 candidates of size 4--- 316 candidates of size 5--- 1376 candidates of size 6--- tested 1780 candidates+-- 16 candidates of size 3+-- 64 candidates of size 4+-- 256 candidates of size 5+-- 1252 candidates of size 6+-- tested 1592 candidates cannot conjure gps3 :: [Char] -> Int@@ -121,8 +121,8 @@ -- testing 360 combinations of argument values -- pruning with 0/0 rules -- 0 candidates of size 1--- 1 candidates of size 2--- tested 1 candidates+-- 0 candidates of size 2+-- tested 0 candidates cannot conjure gps7 :: Integer -> Integer -> Ratio Integer@@ -151,15 +151,15 @@ -- testing 7 combinations of argument values -- pruning with 67/100 rules -- 4 candidates of size 1--- 16 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 68 candidates of size 4+-- 0 candidates of size 4 -- 80 candidates of size 5--- 980 candidates of size 6+-- 8 candidates of size 6 -- 1428 candidates of size 7--- 17324 candidates of size 8--- 30724 candidates of size 9--- tested 25024 candidates+-- 432 candidates of size 8+-- 30712 candidates of size 9+-- tested 7064 candidates gps10 [] = 0 gps10 (x:xs) = gps10 xs + (x `div` 3 - 2) @@ -191,18 +191,18 @@ -- testing 4 combinations of argument values -- pruning with 5/5 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 2 candidates of size 4+-- 0 candidates of size 4 -- 1 candidates of size 5--- 2 candidates of size 6+-- 0 candidates of size 6 -- 1 candidates of size 7--- 4 candidates of size 8+-- 0 candidates of size 8 -- 7 candidates of size 9--- 21 candidates of size 10--- 34 candidates of size 11--- 67 candidates of size 12--- tested 82 candidates+-- 4 candidates of size 10+-- 33 candidates of size 11+-- 18 candidates of size 12+-- tested 53 candidates gps13_leaders [] = [] gps13_leaders (x:xs) = if all (x >) xs then x:gps13_leaders xs@@ -225,18 +225,18 @@ -- testing 7 combinations of argument values -- pruning with 10/11 rules -- 2 candidates of size 1--- 3 candidates of size 2--- 6 candidates of size 3--- 10 candidates of size 4--- 19 candidates of size 5--- 32 candidates of size 6--- 59 candidates of size 7--- 124 candidates of size 8--- 305 candidates of size 9--- 822 candidates of size 10--- 2276 candidates of size 11--- 6273 candidates of size 12--- tested 3956 candidates+-- 2 candidates of size 2+-- 2 candidates of size 3+-- 3 candidates of size 4+-- 6 candidates of size 5+-- 11 candidates of size 6+-- 23 candidates of size 7+-- 62 candidates of size 8+-- 175 candidates of size 9+-- 489 candidates of size 10+-- 1346 candidates of size 11+-- 3709 candidates of size 12+-- tested 2390 candidates gps16_middle "" = "" gps16_middle (c:cs) = if length cs <= 1 then c:cs@@ -246,35 +246,35 @@ -- testing 5 combinations of argument values -- pruning with 29/40 rules -- 1 candidates of size 1--- 2 candidates of size 2--- 1 candidates of size 3--- 1 candidates of size 4--- 3 candidates of size 5--- tested 8 candidates+-- 1 candidates of size 2+-- 0 candidates of size 3+-- 0 candidates of size 4+-- 2 candidates of size 5+-- tested 4 candidates cannot conjure gps18_price :: [Double] -> [Double] -> Double -- testing 4 combinations of argument values -- pruning with 26/35 rules -- 2 candidates of size 1--- 8 candidates of size 2--- 32 candidates of size 3--- 74 candidates of size 4--- 433 candidates of size 5--- 1218 candidates of size 6--- tested 1767 candidates+-- 0 candidates of size 2+-- 2 candidates of size 3+-- 0 candidates of size 4+-- 33 candidates of size 5+-- 176 candidates of size 6+-- tested 213 candidates cannot conjure gps19_snowday :: Int -> Double -> Double -> Double -> Double -- testing 7 combinations of argument values -- pruning with 6/19 rules -- 3 candidates of size 1--- 6 candidates of size 2--- 27 candidates of size 3--- 138 candidates of size 4--- 435 candidates of size 5--- 2715 candidates of size 6--- tested 3324 candidates+-- 2 candidates of size 2+-- 21 candidates of size 3+-- 39 candidates of size 4+-- 312 candidates of size 5+-- 659 candidates of size 6+-- tested 1036 candidates cannot conjure gps20 :: [Char] -> Bool@@ -362,10 +362,10 @@ -- 10 candidates of size 7 -- 48 candidates of size 8 -- 134 candidates of size 9--- 224 candidates of size 10--- 314 candidates of size 11--- 479 candidates of size 12--- tested 908 candidates+-- 216 candidates of size 10+-- 308 candidates of size 11+-- 466 candidates of size 12+-- tested 881 candidates gps24 "" = Empty gps24 (c:cs) = if 140 > length cs then Tweet (length (c:cs))@@ -375,11 +375,11 @@ -- testing 6 combinations of argument values -- pruning with 31/59 rules -- 2 candidates of size 1--- 9 candidates of size 2--- 49 candidates of size 3--- 200 candidates of size 4--- 1104 candidates of size 5--- 5170 candidates of size 6--- tested 6534 candidates+-- 1 candidates of size 2+-- 5 candidates of size 3+-- 10 candidates of size 4+-- 76 candidates of size 5+-- 438 candidates of size 6+-- tested 532 candidates cannot conjure
bench/ill-hit.txt view
@@ -2,11 +2,11 @@ -- testing 4 combinations of argument values -- pruning with 14/25 rules -- 2 candidates of size 1--- 3 candidates of size 2--- 2 candidates of size 3--- 6 candidates of size 4--- 11 candidates of size 5--- tested 14 candidates+-- 1 candidates of size 2+-- 1 candidates of size 3+-- 2 candidates of size 4+-- 7 candidates of size 5+-- tested 7 candidates sum [] = 0 sum (x:xs) = x + sum xs
bench/lowtests.txt view
@@ -19,19 +19,19 @@ -- 4 candidates of size 4 -- 0 candidates of size 5 -- 0 candidates of size 6--- 10 candidates of size 7--- 10 candidates of size 8+-- 3 candidates of size 7+-- 2 candidates of size 8 -- 0 candidates of size 9--- 6 candidates of size 10--- 20 candidates of size 11--- 15 candidates of size 12+-- 4 candidates of size 10+-- 8 candidates of size 11+-- 4 candidates of size 12 -- 0 candidates of size 13 -- 0 candidates of size 14 -- 0 candidates of size 15 -- 0 candidates of size 16 -- 0 candidates of size 17 -- 0 candidates of size 18--- tested 67 candidates+-- tested 27 candidates cannot conjure subset :: [Int] -> [Int] -> Bool
bench/runtime/zero/bench/candidates.runtime view
@@ -1,1 +1,1 @@-16.4+17.7
bench/runtime/zero/bench/carry-on.runtime view
@@ -1,1 +1,1 @@-4.3+4.7
bench/runtime/zero/bench/erroneous.runtime view
@@ -1,1 +1,1 @@-4.9+5.7
bench/runtime/zero/bench/gps.runtime view
@@ -1,1 +1,1 @@-25.8+28.4
bench/runtime/zero/bench/gps2.runtime view
@@ -1,1 +1,1 @@-21.1+23.2
bench/runtime/zero/bench/ill-hit.runtime view
@@ -1,1 +1,1 @@-0.8+0.9
bench/runtime/zero/bench/lowtests.runtime view
@@ -1,1 +1,1 @@-0.5+0.8
bench/runtime/zero/bench/p12.runtime view
@@ -1,1 +1,1 @@-2.9+3.0
bench/runtime/zero/bench/redundants.runtime view
@@ -1,1 +1,1 @@-5.6+6.4
bench/runtime/zero/bench/strategies.runtime view
@@ -1,1 +1,1 @@-8.0+8.9
bench/runtime/zero/bench/terpret.runtime view
@@ -1,1 +1,1 @@-13.5+14.2
bench/runtime/zero/bench/unique.runtime view
@@ -1,1 +1,1 @@-4.0+4.8
bench/runtime/zero/eg/arith.runtime view
@@ -1,1 +1,1 @@-1.7+2.0
bench/runtime/zero/eg/bits.runtime view
@@ -1,1 +1,1 @@-5.6+6.3
bench/runtime/zero/eg/bools.runtime view
@@ -1,1 +1,1 @@-2.6+3.1
bench/runtime/zero/eg/bst.runtime view
@@ -1,1 +1,1 @@-8.8+7.4
bench/runtime/zero/eg/count.runtime view
@@ -1,1 +1,1 @@-0.5+0.7
bench/runtime/zero/eg/dupos.runtime view
@@ -1,1 +1,1 @@-6.3+6.0
bench/runtime/zero/eg/either.runtime view
@@ -1,1 +1,1 @@-0.2+0.3
bench/runtime/zero/eg/factorial.runtime view
@@ -1,1 +1,1 @@-2.2+2.6
bench/runtime/zero/eg/fib01.runtime view
@@ -1,1 +1,1 @@-1.4+1.0
bench/runtime/zero/eg/fibonacci.runtime view
@@ -1,1 +1,1 @@-5.9+6.2
bench/runtime/zero/eg/gcd.runtime view
@@ -1,1 +1,1 @@-0.2+0.3
bench/runtime/zero/eg/higher.runtime view
@@ -1,1 +1,1 @@-1.1+1.7
bench/runtime/zero/eg/ints.runtime view
@@ -1,1 +1,1 @@-0.9+1.0
bench/runtime/zero/eg/list.runtime view
@@ -1,1 +1,1 @@-1.0+1.1
bench/runtime/zero/eg/maybe.runtime view
@@ -1,1 +1,1 @@-0.5+0.6
bench/runtime/zero/eg/peano.runtime view
@@ -1,1 +1,1 @@-0.5+0.6
bench/runtime/zero/eg/pow.runtime view
@@ -1,1 +1,1 @@-7.3+5.3
bench/runtime/zero/eg/replicate.runtime view
@@ -1,1 +1,1 @@-0.3+0.4
bench/runtime/zero/eg/sort.runtime view
@@ -1,1 +1,1 @@-6.2+5.3
bench/runtime/zero/eg/spec.runtime view
@@ -1,1 +1,1 @@-1.1+1.5
bench/runtime/zero/eg/subset.runtime view
@@ -1,1 +1,1 @@-0.8+1.1
bench/runtime/zero/eg/take-drop.runtime view
@@ -1,1 +1,1 @@-0.5+0.6
bench/runtime/zero/eg/these.runtime view
@@ -1,1 +1,1 @@-1.3+1.7
bench/runtime/zero/eg/tree.runtime view
@@ -1,1 +1,1 @@-2.5+2.7
bench/runtime/zero/eg/tri.runtime view
@@ -1,1 +1,1 @@-0.4+0.5
bench/self.txt view
@@ -2,18 +2,18 @@ -- testing 360 combinations of argument values -- pruning with 0/0 rules -- 4 candidates of size 1--- 16 candidates of size 2--- 56 candidates of size 3--- tested 22 candidates+-- 6 candidates of size 2+-- 26 candidates of size 3+-- tested 12 candidates x ? y = x + y (?) :: Int -> Int -> Int -- testing 360 combinations of argument values -- pruning with 0/0 rules -- 4 candidates of size 1--- 16 candidates of size 2--- 56 candidates of size 3--- tested 34 candidates+-- 4 candidates of size 2+-- 31 candidates of size 3+-- tested 22 candidates x ? y = x * y i :: Int -> Int
bench/strategies.txt view
@@ -64,12 +64,12 @@ -- pruning with 27/65 rules -- 3 candidates of size 1 -- 6 candidates of size 2--- 12 candidates of size 3--- 24 candidates of size 4--- 37 candidates of size 5--- 72 candidates of size 6--- 196 candidates of size 7--- tested 165 candidates+-- 9 candidates of size 3+-- 18 candidates of size 4+-- 31 candidates of size 5+-- 59 candidates of size 6+-- 171 candidates of size 7+-- tested 137 candidates factorial 0 = 1 factorial x = x * factorial (x - 1) @@ -79,12 +79,12 @@ -- pruning with 27/65 rules -- 3 candidates of size 1 -- 6 candidates of size 2--- 12 candidates of size 3--- 24 candidates of size 4--- 47 candidates of size 5--- 82 candidates of size 6--- 342 candidates of size 7--- tested 284 candidates+-- 9 candidates of size 3+-- 18 candidates of size 4+-- 41 candidates of size 5+-- 64 candidates of size 6+-- 307 candidates of size 7+-- tested 251 candidates factorial 0 = 1 factorial x = x * factorial (x - 1) @@ -94,12 +94,12 @@ -- pruning with 27/65 rules -- 3 candidates of size 1 -- 6 candidates of size 2--- 21 candidates of size 3--- 42 candidates of size 4--- 302 candidates of size 5--- 602 candidates of size 6--- 6115 candidates of size 7--- tested 1001 candidates+-- 18 candidates of size 3+-- 36 candidates of size 4+-- 287 candidates of size 5+-- 571 candidates of size 6+-- 5843 candidates of size 7+-- tested 946 candidates factorial 0 = 1 factorial x = x * factorial (x - 1) @@ -124,12 +124,12 @@ -- pruning with 27/65 rules -- 3 candidates of size 1 -- 6 candidates of size 2--- 21 candidates of size 3--- 42 candidates of size 4--- 330 candidates of size 5--- 630 candidates of size 6--- 7215 candidates of size 7--- tested 1945 candidates+-- 18 candidates of size 3+-- 36 candidates of size 4+-- 315 candidates of size 5+-- 585 candidates of size 6+-- 6915 candidates of size 7+-- tested 1876 candidates factorial 0 = 1 factorial x = x * factorial (x - 1)
bench/terpret.txt view
@@ -4,12 +4,12 @@ -- testing 4 combinations of argument values -- pruning with 41/51 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 4 candidates of size 3--- 10 candidates of size 4--- 15 candidates of size 5--- 41 candidates of size 6--- tested 33 candidates+-- 0 candidates of size 4+-- 11 candidates of size 5+-- 5 candidates of size 6+-- tested 18 candidates invert [] = [] invert (p:ps) = not p:invert ps @@ -19,9 +19,9 @@ -- testing 3 combinations of argument values -- pruning with 41/51 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 4 candidates of size 3--- tested 4 candidates+-- tested 3 candidates prependZero ps = False:ps TerpreT benchmark #3: binary decrement@@ -30,15 +30,15 @@ -- testing 3 combinations of argument values -- pruning with 41/51 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 4 candidates of size 3--- 10 candidates of size 4--- 15 candidates of size 5--- 41 candidates of size 6--- 82 candidates of size 7--- 202 candidates of size 8--- 479 candidates of size 9--- tested 411 candidates+-- 0 candidates of size 4+-- 11 candidates of size 5+-- 5 candidates of size 6+-- 31 candidates of size 7+-- 52 candidates of size 8+-- 128 candidates of size 9+-- tested 154 candidates decrement [] = [] decrement (p:ps) = not p:(if p then ps else decrement ps) @@ -52,14 +52,14 @@ -- 0 candidates of size 2 -- 0 candidates of size 3 -- 10 candidates of size 4--- 125 candidates of size 5--- 225 candidates of size 6--- 625 candidates of size 7--- 1242 candidates of size 8--- 3087 candidates of size 9--- 8937 candidates of size 10--- 102200 candidates of size 11--- tested 39710 candidates+-- 0 candidates of size 5+-- 0 candidates of size 6+-- 40 candidates of size 7+-- 0 candidates of size 8+-- 0 candidates of size 9+-- 360 candidates of size 10+-- 4 candidates of size 11+-- tested 412 candidates cshift (p,q,r) = if p then (p,r,q) else (p,q,r)@@ -75,8 +75,8 @@ -- 225 candidates of size 5 -- 585 candidates of size 6 -- 1242 candidates of size 7--- 15183 candidates of size 8--- tested 15459 candidates+-- 3088 candidates of size 8+-- tested 5265 candidates cshift False p q = (False,p,q) cshift True p q = (True,q,p) @@ -90,10 +90,10 @@ -- 9 candidates of size 3 -- 18 candidates of size 4 -- 27 candidates of size 5--- 72 candidates of size 6--- 245 candidates of size 7--- 663 candidates of size 8--- tested 1034 candidates+-- 36 candidates of size 6+-- 45 candidates of size 7+-- 271 candidates of size 8+-- tested 406 candidates fadder False False False = (False,False) fadder False False True = (False,True) fadder False True False = (False,True)@@ -113,9 +113,9 @@ -- 0 candidates of size 2 -- 0 candidates of size 3 -- 8 candidates of size 4--- 128 candidates of size 5--- 408 candidates of size 6--- tested 544 candidates+-- 0 candidates of size 5+-- 0 candidates of size 6+-- tested 8 candidates cannot conjure TerpreT benchmark #7: access@@ -133,13 +133,13 @@ -- testing 5 combinations of argument values -- pruning with 4/7 rules -- 1 candidates of size 1--- 1 candidates of size 2--- 1 candidates of size 3--- 1 candidates of size 4--- 6 candidates of size 5--- 5 candidates of size 6--- 19 candidates of size 7--- tested 18 candidates+-- 0 candidates of size 2+-- 0 candidates of size 3+-- 0 candidates of size 4+-- 3 candidates of size 5+-- 0 candidates of size 6+-- 3 candidates of size 7+-- tested 5 candidates [] `access` x = undefined (x:xs) `access` 0 = x (x:xs) `access` y = xs `access` (y - 1)@@ -150,13 +150,13 @@ -- testing 3 combinations of argument values -- pruning with 3/23 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 2 candidates of size 3--- 7 candidates of size 4--- 8 candidates of size 5--- 29 candidates of size 6--- 39 candidates of size 7--- tested 51 candidates+-- 1 candidates of size 4+-- 6 candidates of size 5+-- 6 candidates of size 6+-- 19 candidates of size 7+-- tested 19 candidates decrelements [] = [] decrelements (x:xs) = x - 1:decrelements xs @@ -164,9 +164,9 @@ -- testing 3 combinations of argument values -- pruning with 5/26 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 2 candidates of size 3--- 8 candidates of size 4--- tested 7 candidates+-- 2 candidates of size 4+-- tested 6 candidates decrelements xs = map (subtract 1) xs
bench/weird.txt view
@@ -2,9 +2,9 @@ -- testing 360 combinations of argument values -- pruning with 56/91 rules -- 4 candidates of size 1--- 16 candidates of size 2--- 40 candidates of size 3--- tested 37 candidates+-- 6 candidates of size 2+-- 10 candidates of size 3+-- tested 19 candidates 0 ^^^ x = x x ^^^ 0 = x x ^^^ y = 0
changelog.md view
@@ -2,6 +2,19 @@ ============================ +v0.6.6 (February 2025)+----------------------++* (pruning) test candidate cases earlier and indepentently+ (can be disabled with `earlyTests=False`);+* (pruning) rewrite after filling in recursions;+* improve showing of test values;+* some internal refactoring and code cleanup;+* update documentation of new interfaces+ with runtimes in examples+ and removal of uneeded uses of maxSize.++ v0.6.4 (February 2025) ----------------------
code-conjure.cabal view
@@ -3,7 +3,7 @@ -- Copyright (C) 2021-2025 Rudy Matela -- Distributed under the 3-Clause BSD licence (see the file LICENSE). name: code-conjure-version: 0.6.4+version: 0.6.6 synopsis: synthesize Haskell functions out of partial definitions description: Conjure is a tool that synthesizes Haskell functions out of partial definitions.@@ -69,7 +69,7 @@ source-repository this type: git location: https://github.com/rudymatela/conjure- tag: v0.6.4+ tag: v0.6.6 library exposed-modules: Conjure
eg/arith.txt view
@@ -22,9 +22,9 @@ -- testing 4 combinations of argument values -- pruning with 14/25 rules -- 4 candidates of size 1--- 16 candidates of size 2--- 40 candidates of size 3--- tested 22 candidates+-- 6 candidates of size 2+-- 10 candidates of size 3+-- tested 12 candidates add x y = x + y square :: Int -> Int
eg/bools.txt view
@@ -2,11 +2,11 @@ -- testing 14 combinations of argument values -- pruning with 37/47 rules -- 2 candidates of size 1--- 4 candidates of size 2--- 2 candidates of size 3+-- 0 candidates of size 2+-- 0 candidates of size 3 -- 2 candidates of size 4 -- 4 candidates of size 5--- tested 14 candidates+-- tested 8 candidates and [] = True and (p:ps) = p && and ps @@ -14,11 +14,11 @@ -- testing 14 combinations of argument values -- pruning with 37/47 rules -- 2 candidates of size 1--- 4 candidates of size 2--- 2 candidates of size 3+-- 0 candidates of size 2+-- 0 candidates of size 3 -- 2 candidates of size 4 -- 4 candidates of size 5--- tested 11 candidates+-- tested 5 candidates or [] = False or (p:ps) = p || or ps @@ -26,19 +26,19 @@ -- testing 14 combinations of argument values -- pruning with 39/49 rules -- 2 candidates of size 1--- 4 candidates of size 2--- 2 candidates of size 3+-- 0 candidates of size 2+-- 0 candidates of size 3 -- 4 candidates of size 4--- tested 12 candidates+-- tested 6 candidates and ps = foldr (&&) True ps or :: [Bool] -> Bool -- testing 14 combinations of argument values -- pruning with 39/49 rules -- 2 candidates of size 1--- 4 candidates of size 2--- 2 candidates of size 3+-- 0 candidates of size 2+-- 0 candidates of size 3 -- 4 candidates of size 4--- tested 11 candidates+-- tested 5 candidates or ps = foldr (||) False ps
eg/bst.txt view
@@ -4,16 +4,16 @@ -- 1 candidates of size 1 -- 0 candidates of size 2 -- 0 candidates of size 3--- 3 candidates of size 4+-- 0 candidates of size 4 -- 0 candidates of size 5 -- 0 candidates of size 6 -- 0 candidates of size 7--- 31 candidates of size 8--- 92 candidates of size 9+-- 24 candidates of size 8+-- 72 candidates of size 9 -- 0 candidates of size 10--- 304 candidates of size 11--- 151 candidates of size 12--- tested 497 candidates+-- 240 candidates of size 11+-- 96 candidates of size 12+-- tested 362 candidates mem x Leaf = False mem x (Node t1 y t2) = mem x t1 || (mem x t2 || x == y) @@ -21,18 +21,18 @@ -- testing 360 combinations of argument values -- pruning with 1/2 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3 -- 0 candidates of size 4 -- 0 candidates of size 5 -- 0 candidates of size 6 -- 6 candidates of size 7--- 24 candidates of size 8+-- 0 candidates of size 8 -- 0 candidates of size 9 -- 192 candidates of size 10 -- 0 candidates of size 11 -- 384 candidates of size 12--- tested 371 candidates+-- tested 346 candidates mem x Leaf = False mem x (Node t1 y t2) = case x `compare` y of LT -> mem x t1@@ -43,18 +43,18 @@ -- testing 360 combinations of argument values -- pruning with 2/3 rules -- 2 candidates of size 1--- 2 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3 -- 4 candidates of size 4--- 21 candidates of size 5+-- 0 candidates of size 5 -- 0 candidates of size 6--- 74 candidates of size 7--- 335 candidates of size 8--- 32 candidates of size 9--- 1504 candidates of size 10--- 6708 candidates of size 11--- 1760 candidates of size 12--- tested 10442 candidates+-- 26 candidates of size 7+-- 0 candidates of size 8+-- 0 candidates of size 9+-- 200 candidates of size 10+-- 0 candidates of size 11+-- 32 candidates of size 12+-- tested 264 candidates cannot conjure before :: Int -> Tree -> Tree@@ -69,9 +69,9 @@ -- 239 candidates of size 8 -- 104 candidates of size 9 -- 1558 candidates of size 10--- 3555 candidates of size 11+-- 3543 candidates of size 11 -- 4028 candidates of size 12--- tested 9599 candidates+-- tested 9587 candidates cannot conjure before :: Int -> Tree -> Tree@@ -112,13 +112,14 @@ -- testing 360 combinations of argument values -- pruning with 6/8 rules -- 3 candidates of size 1--- 12 candidates of size 2--- 32 candidates of size 3--- 58 candidates of size 4--- 434 candidates of size 5--- 922 candidates of size 6--- 3088 candidates of size 7--- 14022 candidates of size 8--- tested 18571 candidates+-- 0 candidates of size 2+-- 0 candidates of size 3+-- 22 candidates of size 4+-- 0 candidates of size 5+-- 68 candidates of size 6+-- 240 candidates of size 7+-- 82 candidates of size 8+-- 3018 candidates of size 9+-- tested 3433 candidates cannot conjure
eg/colin/ListFuns.hs view
@@ -1,6 +1,6 @@---- 2021, 2025 Colin Runciman+-- 2021, 2025 Colin Runciman import Conjure-import Prelude hiding (sum, take, drop)+import Prelude hiding (sum, take, drop, zip) sum :: [Int] -> Int sum [] = 0@@ -65,7 +65,7 @@ -- sub :: [Int] -> [Int] -> Bool -- sub [] _ = True -- sub _ [] = False--- sub (x:xs) (y:ys) = x == y && sub xs ys || sub (x:xs) ys+-- sub (x:xs) (y:ys) = if x == y then sub xs ys else sub (x:xs) ys subBackground :: [Prim] subBackground =@@ -73,8 +73,7 @@ , pr False , prim ":" ((:) :: Int -> [Int] -> [Int]) , prim "==" ((==) :: Int -> Int -> Bool)- , prim "&&" ((&&) :: Bool -> Bool -> Bool)- , prim "||" ((||) :: Bool -> Bool -> Bool)+ , prif (undefined :: Bool) ] set :: [Int] -> Bool@@ -112,7 +111,7 @@ -- take x (y:ys) = y : take (x-1) ys takeBackground :: [Prim]-takeBackground =+takeBackground = [ pr (0 :: Int) , pr (1 :: Int) , pr ([] :: [A])@@ -134,20 +133,105 @@ -- drop x (y:ys) = drop (x-1) ys dropBackground :: [Prim]-dropBackground =+dropBackground = [ pr (0 :: Int) , pr (1 :: Int) , pr ([] :: [A]) , prim "-" ((-) :: Int -> Int -> Int) ] +ord :: [Int] -> Bool+ord [] = True+ord [0] = True+ord [0,1] = True+ord [1,0] = False+ord [0,1,0] = False+ord [0,1,1] = True++-- hoping for something like+-- ord [] = True+-- ord [x] = True+-- ord (x:y:ys) = x <= y && ord (y:ys)++ordBackground :: [Prim]+ordBackground =+ [ pr True+ , prim "null" (null :: [Int] -> Bool)+ , prim "head" (head :: [Int] -> Int)+ , prim "<=" ((<=) :: Int -> Int -> Bool)+ , prim "&&" (&&)+ , prim "||" (||)+ ]++merge :: [Int] -> [Int] -> [Int]+merge [] [0,1] = [0,1]+merge [0,1] [] = [0,1]+merge [0,2] [1,3] = [0,1,2,3]+merge [1,3] [0,2] = [0,1,2,3]++-- hoping for something like+merge [] ys = ys+merge xs [] = xs+merge (x:xs) (y:ys) = if x <= y+ then x : merge xs (y:ys)+ else y : merge (x:xs) ys++mergeBackground :: [Prim]+mergeBackground =+ [ prim "<=" ((<=) :: Int -> Int -> Bool)+ , pr ([] :: [Int])+ , prim ":" ((:) :: Int -> [Int] -> [Int])+ , prif (undefined :: [Int])+ ]++zip :: [A] -> [B] -> [(A,B)]+zip [] [] = []+zip [] [x,y] = []+zip [v,w] [] = []+zip [v,w] [x,y] = [(v,x),(w,y)]++-- hoping for something like+-- zip [] _ = []+-- zip (x:xs) [] = []+-- zip (x:xs) (y:ys) = (x,y) : zip xs ys++zipBackground :: [Prim]+zipBackground =+ [ pr ([] :: [(A,B)])+ , prim "(,)" ((,) :: A -> B -> (A,B))+ , prim ":" ((:) :: (A,B) -> [(A,B)] -> [(A,B)])+ ]++assocs :: Int -> [(Int,A)] -> [A]+assocs 1 [] = []+assocs 0 [(0,x),(1,y)] = [x]+assocs 1 [(0,x),(1,y)] = [y]+assocs 2 [(2,x),(2,y)] = [x,y]++-- hoping for something like+-- assocs _ [] = []+-- assocs n (x:xs) = if fst x == n then snd x : assocs n xs else assocs n xs++assocsBackground :: [Prim]+assocsBackground =+ [ pr ([] :: [A])+ , prim "==" ((==) :: Int -> Int -> Bool)+ , prim ":" ((:) :: A -> [A] -> [A])+ , prim "fst" (fst :: (Int,A) -> Int)+ , prim "snd" (snd :: (Int,A) -> A)+ , prif (undefined :: [A])+ ]+ main :: IO () main = do conjure "sum" sum sumBackground conjure "app" app appBackground conjure "mem" mem memBackground- conjureWith args{maxSize=15,showCandidates=False} "sub" sub subBackground+ conjure "sub" sub subBackground conjure "set" set setBackground conjure "take" take takeBackground conjure "drop" drop dropBackground-+ conjure "ord" ord ordBackground+ conjure "merge" merge mergeBackground+ conjure "zip" zip zipBackground+ conjure "assocs" assocs assocsBackground
eg/colin/ListFuns.txt view
@@ -2,11 +2,11 @@ -- testing 3 combinations of argument values -- pruning with 4/8 rules -- 1 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 1 candidates of size 4+-- 0 candidates of size 4 -- 1 candidates of size 5--- tested 4 candidates+-- tested 2 candidates sum [] = 0 sum (x:xs) = x + sum xs @@ -14,12 +14,12 @@ -- testing 3 combinations of argument values -- pruning with 0/0 rules -- 2 candidates of size 1--- 2 candidates of size 2--- 1 candidates of size 3--- 10 candidates of size 4--- 12 candidates of size 5--- 14 candidates of size 6--- tested 32 candidates+-- 0 candidates of size 2+-- 0 candidates of size 3+-- 6 candidates of size 4+-- 0 candidates of size 5+-- 10 candidates of size 6+-- tested 13 candidates app xs [] = xs app xs (x:ys) = x:app xs ys @@ -29,37 +29,38 @@ -- 1 candidates of size 1 -- 0 candidates of size 2 -- 0 candidates of size 3--- 1 candidates of size 4+-- 0 candidates of size 4 -- 0 candidates of size 5 -- 0 candidates of size 6 -- 0 candidates of size 7--- 12 candidates of size 8--- tested 13 candidates+-- 8 candidates of size 8+-- tested 8 candidates mem x [] = False mem x (y:xs) = mem x xs || x == y sub :: [Int] -> [Int] -> Bool -- testing 9 combinations of argument values--- pruning with 29/42 rules+-- pruning with 9/18 rules -- 2 candidates of size 1--- 4 candidates of size 2--- 6 candidates of size 3--- 1 candidates of size 4--- 18 candidates of size 5--- 7 candidates of size 6--- 26 candidates of size 7--- 95 candidates of size 8--- 228 candidates of size 9--- 191 candidates of size 10--- 954 candidates of size 11--- 957 candidates of size 12--- 4260 candidates of size 13--- 2687 candidates of size 14--- 17846 candidates of size 15--- tested 25802 candidates+-- 0 candidates of size 2+-- 0 candidates of size 3+-- 0 candidates of size 4+-- 4 candidates of size 5+-- 0 candidates of size 6+-- 16 candidates of size 7+-- 12 candidates of size 8+-- 68 candidates of size 9+-- 214 candidates of size 10+-- 184 candidates of size 11+-- 1400 candidates of size 12+-- 987 candidates of size 13+-- 5970 candidates of size 14+-- tested 8437 candidates sub [] xs = True sub (x:xs) [] = False-sub (x:xs) (y:ys) = sub xs ys && (sub (x:xs) ys || x == y)+sub (x:xs) (y:ys) = if x == y+ then sub xs ys+ else sub (x:xs) ys set :: [Int] -> Bool -- testing 8 combinations of argument values@@ -67,12 +68,12 @@ -- 0 candidates of size 1 -- 0 candidates of size 2 -- 0 candidates of size 3--- 2 candidates of size 4--- 1 candidates of size 5--- 1 candidates of size 6--- 3 candidates of size 7--- 5 candidates of size 8--- tested 11 candidates+-- 1 candidates of size 4+-- 0 candidates of size 5+-- 0 candidates of size 6+-- 1 candidates of size 7+-- 3 candidates of size 8+-- tested 4 candidates set [] = True set (x:xs) = set xs && not (elem x xs) @@ -80,15 +81,15 @@ -- testing 143 combinations of argument values -- pruning with 4/7 rules -- 2 candidates of size 1--- 3 candidates of size 2--- 4 candidates of size 3--- 6 candidates of size 4--- 8 candidates of size 5--- 13 candidates of size 6--- 24 candidates of size 7--- 31 candidates of size 8--- 59 candidates of size 9--- tested 111 candidates+-- 1 candidates of size 2+-- 0 candidates of size 3+-- 0 candidates of size 4+-- 0 candidates of size 5+-- 3 candidates of size 6+-- 2 candidates of size 7+-- 6 candidates of size 8+-- 5 candidates of size 9+-- tested 15 candidates take 0 xs = [] take x [] = [] take x (y:xs) = y:take (x - 1) xs@@ -97,14 +98,94 @@ -- testing 143 combinations of argument values -- pruning with 4/7 rules -- 2 candidates of size 1--- 3 candidates of size 2--- 4 candidates of size 3--- 4 candidates of size 4--- 4 candidates of size 5--- 4 candidates of size 6--- 12 candidates of size 7--- tested 24 candidates+-- 1 candidates of size 2+-- 0 candidates of size 3+-- 0 candidates of size 4+-- 2 candidates of size 5+-- 2 candidates of size 6+-- 3 candidates of size 7+-- tested 8 candidates drop 0 xs = xs drop x [] = [] drop x (y:xs) = drop (x - 1) xs++ord :: [Int] -> Bool+-- testing 6 combinations of argument values+-- pruning with 29/39 rules+-- 1 candidates of size 1+-- 1 candidates of size 2+-- 0 candidates of size 3+-- 0 candidates of size 4+-- 0 candidates of size 5+-- 2 candidates of size 6+-- 0 candidates of size 7+-- 4 candidates of size 8+-- 0 candidates of size 9+-- 0 candidates of size 10+-- 20 candidates of size 11+-- tested 12 candidates+ord [] = True+ord (x:xs) = ord xs && (null xs || x <= head xs)++merge :: [Int] -> [Int] -> [Int]+-- testing 360 combinations of argument values+-- pruning with 4/4 rules+-- 3 candidates of size 1+-- 0 candidates of size 2+-- 0 candidates of size 3+-- 10 candidates of size 4+-- 0 candidates of size 5+-- 16 candidates of size 6+-- 13 candidates of size 7+-- 22 candidates of size 8+-- 114 candidates of size 9+-- 36 candidates of size 10+-- 472 candidates of size 11+-- 604 candidates of size 12+-- 1442 candidates of size 13+-- 5188 candidates of size 14+-- 5474 candidates of size 15+-- tested 13394 candidates+cannot conjure++zip :: [A] -> [B] -> [(A,B)]+-- testing 360 combinations of argument values+-- pruning with 0/0 rules+-- 1 candidates of size 1+-- 0 candidates of size 2+-- 0 candidates of size 3+-- 0 candidates of size 4+-- 0 candidates of size 5+-- 0 candidates of size 6+-- 0 candidates of size 7+-- 0 candidates of size 8+-- 1 candidates of size 9+-- tested 2 candidates+zip [] xs = []+zip (x:xs) [] = []+zip (x:xs) (y:ys) = (,) x y:zip xs ys++assocs :: Int -> [(Int,A)] -> [A]+-- testing 67 combinations of argument values+-- pruning with 4/5 rules+-- 1 candidates of size 1+-- 0 candidates of size 2+-- 0 candidates of size 3+-- 0 candidates of size 4+-- 0 candidates of size 5+-- 0 candidates of size 6+-- 1 candidates of size 7+-- 1 candidates of size 8+-- 0 candidates of size 9+-- 3 candidates of size 10+-- 3 candidates of size 11+-- 0 candidates of size 12+-- 9 candidates of size 13+-- 7 candidates of size 14+-- 2 candidates of size 15+-- tested 26 candidates+assocs x [] = []+assocs x (xy:xys) = if x == fst xy+ then snd xy:assocs x xys+ else assocs x xys
eg/count.txt view
@@ -13,17 +13,17 @@ -- testing 13 combinations of argument values -- pruning with 8/13 rules -- 2 candidates of size 1--- 2 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3 -- 0 candidates of size 4 -- 0 candidates of size 5 -- 4 candidates of size 6--- 4 candidates of size 7+-- 0 candidates of size 7 -- 12 candidates of size 8--- 20 candidates of size 9+-- 16 candidates of size 9 -- 20 candidates of size 10--- 52 candidates of size 11--- tested 79 candidates+-- 44 candidates of size 11+-- tested 65 candidates count x [] = 0 count x (y:xs) = count x xs + (if x == y then 1 else 0)
eg/dupos.txt view
@@ -2,23 +2,23 @@ -- testing 6 combinations of argument values -- pruning with 21/26 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 2 candidates of size 4+-- 0 candidates of size 4 -- 1 candidates of size 5--- 2 candidates of size 6--- 3 candidates of size 7--- 8 candidates of size 8--- 16 candidates of size 9--- 25 candidates of size 10--- 36 candidates of size 11--- 63 candidates of size 12--- 133 candidates of size 13--- 299 candidates of size 14--- 602 candidates of size 15--- 1116 candidates of size 16--- 2031 candidates of size 17--- tested 2450 candidates+-- 0 candidates of size 6+-- 1 candidates of size 7+-- 6 candidates of size 8+-- 5 candidates of size 9+-- 22 candidates of size 10+-- 15 candidates of size 11+-- 48 candidates of size 12+-- 93 candidates of size 13+-- 188 candidates of size 14+-- 505 candidates of size 15+-- 706 candidates of size 16+-- 1723 candidates of size 17+-- tested 1705 candidates duplicates [] = [] duplicates (x:xs) = if elem x xs && not (elem x (duplicates xs)) then x:duplicates xs@@ -34,16 +34,16 @@ -- 2 candidates of size 6 -- 3 candidates of size 7 -- 8 candidates of size 8--- 16 candidates of size 9--- 25 candidates of size 10--- 36 candidates of size 11--- 63 candidates of size 12--- 133 candidates of size 13--- 299 candidates of size 14--- 602 candidates of size 15--- 1116 candidates of size 16--- 2031 candidates of size 17--- tested 2450 candidates+-- 15 candidates of size 9+-- 24 candidates of size 10+-- 35 candidates of size 11+-- 62 candidates of size 12+-- 129 candidates of size 13+-- 282 candidates of size 14+-- 559 candidates of size 15+-- 1036 candidates of size 16+-- 1899 candidates of size 17+-- tested 2274 candidates duplicates [] = [] duplicates (x:xs) = if elem x xs && not (elem x (duplicates xs)) then x:duplicates xs@@ -55,18 +55,18 @@ -- 1 candidates of size 1 -- 0 candidates of size 2 -- 2 candidates of size 3--- 5 candidates of size 4--- 9 candidates of size 5--- 16 candidates of size 6--- 43 candidates of size 7--- 73 candidates of size 8--- 185 candidates of size 9--- 285 candidates of size 10--- 722 candidates of size 11--- 1157 candidates of size 12--- 2847 candidates of size 13--- 4505 candidates of size 14--- tested 5484 candidates+-- 0 candidates of size 4+-- 7 candidates of size 5+-- 0 candidates of size 6+-- 34 candidates of size 7+-- 0 candidates of size 8+-- 133 candidates of size 9+-- 0 candidates of size 10+-- 510 candidates of size 11+-- 16 candidates of size 12+-- 1947 candidates of size 13+-- 104 candidates of size 14+-- tested 2653 candidates positionsFrom x y [] = [] positionsFrom x y (z:xs) = (if y == z then (x :) else id) (positionsFrom (x + 1) y xs)
eg/either.txt view
@@ -2,8 +2,8 @@ -- testing 4 combinations of argument values -- pruning with 0/0 rules -- 2 candidates of size 1--- 2 candidates of size 2--- tested 4 candidates+-- 1 candidates of size 2+-- tested 3 candidates isLeft (Left x) = True isLeft (Right x) = False @@ -11,7 +11,7 @@ -- testing 4 combinations of argument values -- pruning with 0/0 rules -- 2 candidates of size 1--- 2 candidates of size 2+-- 1 candidates of size 2 -- tested 3 candidates isRight (Left x) = False isRight (Right x) = True@@ -20,8 +20,8 @@ -- testing 5 combinations of argument values -- pruning with 0/0 rules -- 1 candidates of size 1--- 3 candidates of size 2--- tested 3 candidates+-- 1 candidates of size 2+-- tested 2 candidates fromLeft x (Left y) = y fromLeft x (Right y) = x @@ -29,7 +29,7 @@ -- testing 5 combinations of argument values -- pruning with 0/0 rules -- 1 candidates of size 1--- 3 candidates of size 2+-- 1 candidates of size 2 -- tested 2 candidates fromLeft x (Left y) = x fromLeft x (Right y) = y
eg/fib01.txt view
@@ -2,11 +2,11 @@ -- testing 8 combinations of argument values -- pruning with 6/10 rules -- 4 candidates of size 1--- 27 candidates of size 2--- 117 candidates of size 3--- 464 candidates of size 4--- 1564 candidates of size 5--- tested 2176 candidates+-- 14 candidates of size 2+-- 38 candidates of size 3+-- 111 candidates of size 4+-- 255 candidates of size 5+-- tested 422 candidates cannot conjure fib01 :: Int -> Int -> Int -> Int
eg/fibonacci.txt view
@@ -10,10 +10,10 @@ -- 116 candidates of size 7 -- 120 candidates of size 8 -- 552 candidates of size 9--- 540 candidates of size 10--- 2663 candidates of size 11--- 2675 candidates of size 12--- tested 4147 candidates+-- 538 candidates of size 10+-- 2661 candidates of size 11+-- 2661 candidates of size 12+-- tested 4133 candidates fibonacci 0 = 1 fibonacci 1 = 1 fibonacci x = fibonacci (x - 1) + fibonacci (x - 2)
eg/higher.txt view
@@ -58,10 +58,10 @@ -- 0 candidates of size 7 -- 17 candidates of size 8 -- 0 candidates of size 9--- 44 candidates of size 10+-- 43 candidates of size 10 -- 0 candidates of size 11--- 142 candidates of size 12--- tested 72 candidates+-- 141 candidates of size 12+-- tested 71 candidates filter f [] = [] filter f (x:xs) = if f x then x:filter f xs
eg/ints.txt view
@@ -21,11 +21,11 @@ -- testing 360 combinations of argument values -- pruning with 14/25 rules -- 2 candidates of size 1--- 4 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 6 candidates of size 4+-- 0 candidates of size 4 -- 6 candidates of size 5--- tested 13 candidates+-- tested 3 candidates sum [] = 0 sum (x:xs) = x + sum xs @@ -33,11 +33,11 @@ -- testing 360 combinations of argument values -- pruning with 14/25 rules -- 2 candidates of size 1--- 4 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 6 candidates of size 4+-- 0 candidates of size 4 -- 6 candidates of size 5--- tested 18 candidates+-- tested 8 candidates product [] = 1 product (x:xs) = x * product xs @@ -45,19 +45,19 @@ -- testing 360 combinations of argument values -- pruning with 15/26 rules -- 2 candidates of size 1--- 4 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 9 candidates of size 4--- tested 7 candidates+-- 3 candidates of size 4+-- tested 3 candidates sum xs = foldr (+) 0 xs product :: [Int] -> Int -- testing 360 combinations of argument values -- pruning with 15/26 rules -- 2 candidates of size 1--- 4 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 9 candidates of size 4--- tested 9 candidates+-- 3 candidates of size 4+-- tested 5 candidates product xs = foldr (*) 1 xs
eg/list.txt view
@@ -2,11 +2,11 @@ -- testing 360 combinations of argument values -- pruning with 4/8 rules -- 2 candidates of size 1--- 2 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 2 candidates of size 4+-- 0 candidates of size 4 -- 2 candidates of size 5--- tested 8 candidates+-- tested 4 candidates length [] = 0 length (x:xs) = length xs + 1 @@ -14,13 +14,13 @@ -- testing 360 combinations of argument values -- pruning with 4/4 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 1 candidates of size 3--- 3 candidates of size 4+-- 0 candidates of size 4 -- 4 candidates of size 5--- 7 candidates of size 6+-- 1 candidates of size 6 -- 10 candidates of size 7--- tested 26 candidates+-- tested 16 candidates reverse [] = [] reverse (x:xs) = reverse xs ++ [x] @@ -28,12 +28,12 @@ -- testing 360 combinations of argument values -- pruning with 0/0 rules -- 3 candidates of size 1--- 8 candidates of size 2--- 11 candidates of size 3--- 23 candidates of size 4--- 86 candidates of size 5--- 72 candidates of size 6--- tested 149 candidates+-- 0 candidates of size 2+-- 0 candidates of size 3+-- 10 candidates of size 4+-- 25 candidates of size 5+-- 34 candidates of size 6+-- tested 56 candidates [] ++ xs = xs (x:xs) ++ ys = x:(xs ++ ys) @@ -41,23 +41,23 @@ -- testing 360 combinations of argument values -- pruning with 2/2 rules -- 3 candidates of size 1--- 8 candidates of size 2--- 11 candidates of size 3--- 27 candidates of size 4--- tested 35 candidates+-- 0 candidates of size 2+-- 0 candidates of size 3+-- 14 candidates of size 4+-- tested 16 candidates xs ++ ys = foldr (:) ys xs last :: [Int] -> Int -- testing 360 combinations of argument values -- pruning with 5/5 rules -- 1 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3 -- 0 candidates of size 4 -- 0 candidates of size 5--- 2 candidates of size 6+-- 0 candidates of size 6 -- 4 candidates of size 7--- tested 5 candidates+-- tested 2 candidates last [] = undefined last (x:xs) = if null xs then x@@ -71,11 +71,11 @@ -- 0 candidates of size 3 -- 0 candidates of size 4 -- 0 candidates of size 5--- 2 candidates of size 6--- 6 candidates of size 7+-- 0 candidates of size 6+-- 0 candidates of size 7 -- 6 candidates of size 8--- 30 candidates of size 9--- tested 25 candidates+-- 23 candidates of size 9+-- tested 13 candidates zip [] xs = [] zip (x:xs) [] = [] zip (x:xs) (y:ys) = (x,y):zip xs ys@@ -84,12 +84,12 @@ -- testing 360 combinations of argument values -- pruning with 0/0 rules -- 3 candidates of size 1--- 8 candidates of size 2--- 11 candidates of size 3--- 23 candidates of size 4--- 86 candidates of size 5--- 72 candidates of size 6--- tested 151 candidates+-- 0 candidates of size 2+-- 0 candidates of size 3+-- 10 candidates of size 4+-- 25 candidates of size 5+-- 34 candidates of size 6+-- tested 58 candidates [] \/ xs = xs (x:xs) \/ ys = x:ys \/ xs @@ -97,17 +97,17 @@ -- testing 360 combinations of argument values -- pruning with 29/39 rules -- 2 candidates of size 1--- 2 candidates of size 2--- 2 candidates of size 3--- 2 candidates of size 4--- 4 candidates of size 5--- 12 candidates of size 6--- 20 candidates of size 7--- 30 candidates of size 8--- 56 candidates of size 9--- 112 candidates of size 10--- 200 candidates of size 11--- tested 319 candidates+-- 1 candidates of size 2+-- 1 candidates of size 3+-- 1 candidates of size 4+-- 1 candidates of size 5+-- 7 candidates of size 6+-- 13 candidates of size 7+-- 17 candidates of size 8+-- 25 candidates of size 9+-- 65 candidates of size 10+-- 115 candidates of size 11+-- tested 172 candidates ordered [] = True ordered (x:xs) = ordered xs && (null xs || x <= head xs)
eg/peano.txt view
@@ -2,11 +2,11 @@ -- testing 6 combinations of argument values -- pruning with 0/0 rules -- 3 candidates of size 1--- 11 candidates of size 2--- 38 candidates of size 3--- 87 candidates of size 4--- 218 candidates of size 5--- tested 140 candidates+-- 3 candidates of size 2+-- 3 candidates of size 3+-- 13 candidates of size 4+-- 19 candidates of size 5+-- tested 23 candidates p + Z = p p + S q = S p + q @@ -14,12 +14,12 @@ -- testing 7 combinations of argument values -- pruning with 6/10 rules -- 3 candidates of size 1--- 11 candidates of size 2--- 41 candidates of size 3--- 108 candidates of size 4--- 291 candidates of size 5--- 746 candidates of size 6--- tested 537 candidates+-- 3 candidates of size 2+-- 6 candidates of size 3+-- 6 candidates of size 4+-- 35 candidates of size 5+-- 86 candidates of size 6+-- tested 71 candidates p * Z = Z p * S q = p + p * q
eg/pow.txt view
@@ -2,14 +2,14 @@ -- testing 5 combinations of argument values -- pruning with 14/30 rules -- 4 candidates of size 1--- 16 candidates of size 2--- 46 candidates of size 3--- 159 candidates of size 4--- 433 candidates of size 5--- 1382 candidates of size 6--- 4136 candidates of size 7--- 13292 candidates of size 8--- tested 6383 candidates+-- 11 candidates of size 2+-- 31 candidates of size 3+-- 92 candidates of size 4+-- 244 candidates of size 5+-- 730 candidates of size 6+-- 2221 candidates of size 7+-- 6950 candidates of size 8+-- tested 3356 candidates pow x 0 = 1 pow x y = x * pow x (y - 1) @@ -17,11 +17,11 @@ -- testing 5 combinations of argument values -- pruning with 15/19 rules -- 4 candidates of size 1--- 18 candidates of size 2--- 58 candidates of size 3--- 174 candidates of size 4--- 485 candidates of size 5--- 1387 candidates of size 6--- tested 2126 candidates+-- 13 candidates of size 2+-- 40 candidates of size 3+-- 103 candidates of size 4+-- 259 candidates of size 5+-- 750 candidates of size 6+-- tested 1169 candidates cannot conjure
eg/replicate.txt view
@@ -5,11 +5,11 @@ -- 0 candidates of size 2 -- 1 candidates of size 3 -- 1 candidates of size 4--- 3 candidates of size 5--- 2 candidates of size 6--- 3 candidates of size 7--- 3 candidates of size 8--- tested 12 candidates+-- 2 candidates of size 5+-- 1 candidates of size 6+-- 1 candidates of size 7+-- 2 candidates of size 8+-- tested 8 candidates replicate 0 c = "" replicate x c = c:replicate (x - 1) c @@ -39,14 +39,14 @@ -- testing 360 combinations of argument values -- pruning with 4/4 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 1 candidates of size 3--- 4 candidates of size 4+-- 0 candidates of size 4 -- 1 candidates of size 5--- 12 candidates of size 6+-- 3 candidates of size 6 -- 1 candidates of size 7--- 34 candidates of size 8--- tested 24 candidates+-- 12 candidates of size 8+-- tested 10 candidates replicates "" x = "" replicates (c:cs) x = replicate x c ++ replicates cs x
eg/setelem.txt view
@@ -2,14 +2,14 @@ -- testing 360 combinations of argument values -- pruning with 40/53 rules -- 2 candidates of size 1--- 2 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 2 candidates of size 4--- 6 candidates of size 5+-- 0 candidates of size 4+-- 4 candidates of size 5 -- 0 candidates of size 6 -- 0 candidates of size 7--- 24 candidates of size 8--- tested 33 candidates+-- 16 candidates of size 8+-- tested 19 candidates elem x [] = False elem x (y:xs) = elem x xs || x == y @@ -17,14 +17,14 @@ -- testing 360 combinations of argument values -- pruning with 41/52 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 2 candidates of size 4--- 1 candidates of size 5--- 2 candidates of size 6--- 4 candidates of size 7--- 6 candidates of size 8--- tested 15 candidates+-- 1 candidates of size 4+-- 0 candidates of size 5+-- 0 candidates of size 6+-- 2 candidates of size 7+-- 4 candidates of size 8+-- tested 6 candidates set [] = True set (x:xs) = set xs && not (elem x xs)
eg/sort.txt view
@@ -2,11 +2,11 @@ -- testing 360 combinations of argument values -- pruning with 6/7 rules -- 2 candidates of size 1--- 3 candidates of size 2--- 4 candidates of size 3--- 11 candidates of size 4--- 23 candidates of size 5--- tested 22 candidates+-- 2 candidates of size 2+-- 2 candidates of size 3+-- 7 candidates of size 4+-- 14 candidates of size 5+-- tested 15 candidates sort [] = [] sort (x:xs) = insert x (sort xs) @@ -14,33 +14,33 @@ -- testing 360 combinations of argument values -- pruning with 1/2 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 4 candidates of size 4--- tested 5 candidates+-- 2 candidates of size 4+-- tested 4 candidates sort xs = foldr insert [] xs insert :: Int -> [Int] -> [Int] -- testing 4 combinations of argument values -- pruning with 4/4 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 2 candidates of size 3--- 6 candidates of size 4+-- 0 candidates of size 4 -- 2 candidates of size 5--- 19 candidates of size 6--- 6 candidates of size 7--- 44 candidates of size 8--- 62 candidates of size 9--- 91 candidates of size 10--- 334 candidates of size 11--- 220 candidates of size 12--- 1358 candidates of size 13--- 1019 candidates of size 14--- 4638 candidates of size 15--- 6332 candidates of size 16--- 14550 candidates of size 17--- tested 14943 candidates+-- 2 candidates of size 6+-- 2 candidates of size 7+-- 4 candidates of size 8+-- 2 candidates of size 9+-- 8 candidates of size 10+-- 18 candidates of size 11+-- 16 candidates of size 12+-- 102 candidates of size 13+-- 32 candidates of size 14+-- 426 candidates of size 15+-- 224 candidates of size 16+-- 1450 candidates of size 17+-- tested 991 candidates insert x [] = [x] insert x (y:xs) = if x <= y then x:insert y xs@@ -50,20 +50,20 @@ -- testing 360 combinations of argument values -- pruning with 8/8 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 1 candidates of size 3--- 3 candidates of size 4--- 6 candidates of size 5--- 9 candidates of size 6--- 22 candidates of size 7--- 37 candidates of size 8--- 84 candidates of size 9--- 169 candidates of size 10--- 352 candidates of size 11--- 767 candidates of size 12--- 1600 candidates of size 13--- 3499 candidates of size 14--- tested 3667 candidates+-- 0 candidates of size 4+-- 4 candidates of size 5+-- 3 candidates of size 6+-- 10 candidates of size 7+-- 21 candidates of size 8+-- 36 candidates of size 9+-- 105 candidates of size 10+-- 182 candidates of size 11+-- 471 candidates of size 12+-- 988 candidates of size 13+-- 2183 candidates of size 14+-- tested 2437 candidates qsort [] = [] qsort (x:xs) = filter (x >) (qsort xs) ++ (x:filter (x <=) (qsort xs)) @@ -71,20 +71,20 @@ -- testing 360 combinations of argument values -- pruning with 8/8 rules -- 2 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 1 candidates of size 3--- 3 candidates of size 4--- 6 candidates of size 5--- 9 candidates of size 6--- 28 candidates of size 7--- 51 candidates of size 8--- 128 candidates of size 9--- 303 candidates of size 10--- 648 candidates of size 11--- 1621 candidates of size 12--- 3592 candidates of size 13--- 8475 candidates of size 14--- tested 7794 candidates+-- 0 candidates of size 4+-- 4 candidates of size 5+-- 3 candidates of size 6+-- 16 candidates of size 7+-- 35 candidates of size 8+-- 80 candidates of size 9+-- 239 candidates of size 10+-- 478 candidates of size 11+-- 1325 candidates of size 12+-- 2980 candidates of size 13+-- 7159 candidates of size 14+-- tested 6564 candidates qsort [] = [] qsort (x:xs) = qsort (filter (x >) xs) ++ (x:qsort (filter (x <=) xs)) @@ -92,31 +92,36 @@ -- testing 360 combinations of argument values -- pruning with 4/4 rules -- 3 candidates of size 1--- 8 candidates of size 2--- 11 candidates of size 3--- 23 candidates of size 4--- 86 candidates of size 5--- 72 candidates of size 6--- 297 candidates of size 7--- 322 candidates of size 8--- 939 candidates of size 9--- tested 1761 candidates+-- 0 candidates of size 2+-- 0 candidates of size 3+-- 10 candidates of size 4+-- 0 candidates of size 5+-- 16 candidates of size 6+-- 13 candidates of size 7+-- 22 candidates of size 8+-- 114 candidates of size 9+-- 36 candidates of size 10+-- 472 candidates of size 11+-- 604 candidates of size 12+-- tested 1290 candidates cannot conjure merge :: [Int] -> [Int] -> [Int] -- testing 360 combinations of argument values -- pruning with 1/2 rules -- 2 candidates of size 1--- 2 candidates of size 2--- 3 candidates of size 3--- 10 candidates of size 4--- 21 candidates of size 5--- 26 candidates of size 6--- 61 candidates of size 7--- 92 candidates of size 8--- 203 candidates of size 9--- 430 candidates of size 10--- 1086 candidates of size 11--- tested 1936 candidates+-- 0 candidates of size 2+-- 0 candidates of size 3+-- 6 candidates of size 4+-- 0 candidates of size 5+-- 10 candidates of size 6+-- 7 candidates of size 7+-- 14 candidates of size 8+-- 41 candidates of size 9+-- 106 candidates of size 10+-- 144 candidates of size 11+-- 588 candidates of size 12+-- 958 candidates of size 13+-- tested 1876 candidates cannot conjure
eg/subset.txt view
@@ -2,14 +2,14 @@ -- testing 44 combinations of argument values -- pruning with 29/39 rules -- 2 candidates of size 1--- 4 candidates of size 2--- 8 candidates of size 3--- 10 candidates of size 4--- 64 candidates of size 5--- 40 candidates of size 6--- 64 candidates of size 7--- 522 candidates of size 8--- tested 553 candidates+-- 0 candidates of size 2+-- 0 candidates of size 3+-- 0 candidates of size 4+-- 13 candidates of size 5+-- 0 candidates of size 6+-- 6 candidates of size 7+-- 176 candidates of size 8+-- tested 176 candidates subset [] xs = True subset (x:xs) ys = subset xs ys && elem x ys
eg/take-drop.txt view
@@ -2,13 +2,13 @@ -- testing 360 combinations of argument values -- pruning with 4/7 rules -- 2 candidates of size 1--- 3 candidates of size 2--- 4 candidates of size 3--- 6 candidates of size 4--- 8 candidates of size 5--- 13 candidates of size 6--- 24 candidates of size 7--- tested 39 candidates+-- 1 candidates of size 2+-- 0 candidates of size 3+-- 0 candidates of size 4+-- 2 candidates of size 5+-- 5 candidates of size 6+-- 5 candidates of size 7+-- tested 11 candidates drop 0 xs = xs drop x [] = [] drop x (y:xs) = drop (x - 1) xs@@ -17,15 +17,15 @@ -- testing 153 combinations of argument values -- pruning with 4/7 rules -- 2 candidates of size 1--- 3 candidates of size 2--- 4 candidates of size 3--- 6 candidates of size 4--- 8 candidates of size 5--- 13 candidates of size 6--- 24 candidates of size 7--- 31 candidates of size 8--- 59 candidates of size 9--- tested 111 candidates+-- 1 candidates of size 2+-- 0 candidates of size 3+-- 0 candidates of size 4+-- 0 candidates of size 5+-- 3 candidates of size 6+-- 2 candidates of size 7+-- 6 candidates of size 8+-- 5 candidates of size 9+-- tested 15 candidates take 0 xs = [] take x [] = [] take x (y:xs) = y:take (x - 1) xs
eg/tapps.txt view
@@ -2,21 +2,21 @@ -- testing 360 combinations of argument values -- pruning with 14/25 rules -- 2 candidates of size 1--- 5 candidates of size 2--- 3 candidates of size 3--- 10 candidates of size 4--- tested 12 candidates+-- 1 candidates of size 2+-- 1 candidates of size 3+-- 4 candidates of size 4+-- tested 6 candidates third xs = head (tail (tail xs)) product :: [Int] -> Int -- testing 360 combinations of argument values -- pruning with 14/25 rules -- 2 candidates of size 1--- 5 candidates of size 2--- 3 candidates of size 3--- 10 candidates of size 4--- 18 candidates of size 5--- tested 26 candidates+-- 1 candidates of size 2+-- 1 candidates of size 3+-- 2 candidates of size 4+-- 10 candidates of size 5+-- tested 12 candidates product [] = 1 product (x:xs) = x * product xs @@ -24,9 +24,9 @@ -- testing 360 combinations of argument values -- pruning with 15/26 rules -- 2 candidates of size 1--- 5 candidates of size 2--- 3 candidates of size 3--- 13 candidates of size 4--- tested 14 candidates+-- 1 candidates of size 2+-- 1 candidates of size 3+-- 5 candidates of size 4+-- tested 8 candidates product xs = foldr (*) 1 xs
eg/these.txt view
@@ -10,8 +10,8 @@ -- 0 candidates of size 7 -- 0 candidates of size 8 -- 0 candidates of size 9--- 15 candidates of size 10--- tested 16 candidates+-- 1 candidates of size 10+-- tested 2 candidates fromThese x y None = (x,y) fromThese x y (This z) = (z,y) fromThese x y (That z) = (x,z)@@ -23,14 +23,14 @@ -- 1 candidates of size 1 -- 0 candidates of size 2 -- 0 candidates of size 3--- 4 candidates of size 4+-- 0 candidates of size 4 -- 0 candidates of size 5--- 11 candidates of size 6+-- 0 candidates of size 6 -- 0 candidates of size 7--- 26 candidates of size 8+-- 0 candidates of size 8 -- 0 candidates of size 9--- 57 candidates of size 10--- tested 83 candidates+-- 1 candidates of size 10+-- tested 2 candidates listhese None = [] listhese (This x) = [x] listhese (That x) = [x]@@ -43,14 +43,14 @@ -- 0 candidates of size 2 -- 0 candidates of size 3 -- 0 candidates of size 4--- 1 candidates of size 5+-- 0 candidates of size 5 -- 1 candidates of size 6 -- 2 candidates of size 7--- 2 candidates of size 8--- 3 candidates of size 9+-- 0 candidates of size 8+-- 1 candidates of size 9 -- 6 candidates of size 10--- 8 candidates of size 11--- tested 17 candidates+-- 6 candidates of size 11+-- tested 12 candidates cathis [] = [] cathis (t:ts) = if isThis t then fromThis t:cathis ts@@ -63,14 +63,14 @@ -- 0 candidates of size 2 -- 0 candidates of size 3 -- 0 candidates of size 4--- 1 candidates of size 5+-- 0 candidates of size 5 -- 1 candidates of size 6 -- 2 candidates of size 7--- 2 candidates of size 8--- 3 candidates of size 9+-- 0 candidates of size 8+-- 1 candidates of size 9 -- 6 candidates of size 10--- 8 candidates of size 11--- tested 17 candidates+-- 6 candidates of size 11+-- tested 12 candidates cathat [] = [] cathat (t:ts) = if isThat t then fromThat t:cathat ts@@ -83,17 +83,17 @@ -- 0 candidates of size 2 -- 0 candidates of size 3 -- 0 candidates of size 4--- 2 candidates of size 5+-- 0 candidates of size 5 -- 3 candidates of size 6 -- 4 candidates of size 7--- 8 candidates of size 8--- 17 candidates of size 9+-- 2 candidates of size 8+-- 9 candidates of size 9 -- 36 candidates of size 10--- 54 candidates of size 11--- 119 candidates of size 12--- 268 candidates of size 13--- 490 candidates of size 14--- 985 candidates of size 15--- tested 1987 candidates+-- 38 candidates of size 11+-- 75 candidates of size 12+-- 224 candidates of size 13+-- 422 candidates of size 14+-- 753 candidates of size 15+-- tested 1567 candidates cannot conjure
eg/tree.txt view
@@ -2,13 +2,13 @@ -- testing 360 combinations of argument values -- pruning with 3/3 rules -- 1 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3 -- 0 candidates of size 4 -- 0 candidates of size 5--- 4 candidates of size 6+-- 0 candidates of size 6 -- 16 candidates of size 7--- tested 7 candidates+-- tested 2 candidates leftmost Leaf = undefined leftmost (Node t1 x t2) = if nil t1 then x@@ -18,13 +18,13 @@ -- testing 360 combinations of argument values -- pruning with 3/3 rules -- 1 candidates of size 1--- 1 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3 -- 0 candidates of size 4 -- 0 candidates of size 5--- 4 candidates of size 6+-- 0 candidates of size 6 -- 16 candidates of size 7--- tested 16 candidates+-- tested 11 candidates rightmost Leaf = undefined rightmost (Node t1 x t2) = if nil t2 then x@@ -34,14 +34,14 @@ -- testing 360 combinations of argument values -- pruning with 4/8 rules -- 2 candidates of size 1--- 2 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 2 candidates of size 4+-- 0 candidates of size 4 -- 4 candidates of size 5--- 8 candidates of size 6+-- 4 candidates of size 6 -- 12 candidates of size 7--- 24 candidates of size 8--- tested 40 candidates+-- 16 candidates of size 8+-- tested 32 candidates size Leaf = 0 size (Node t1 x t2) = size t1 + (size t2 + 1) @@ -49,14 +49,14 @@ -- testing 360 combinations of argument values -- pruning with 49/65 rules -- 3 candidates of size 1--- 3 candidates of size 2+-- 0 candidates of size 2 -- 0 candidates of size 3--- 6 candidates of size 4+-- 0 candidates of size 4 -- 14 candidates of size 5--- 34 candidates of size 6+-- 6 candidates of size 6 -- 98 candidates of size 7--- 274 candidates of size 8--- tested 200 candidates+-- 86 candidates of size 8+-- tested 160 candidates height Leaf = -1 height (Node t1 x t2) = 1 + max (height t1) (height t2) @@ -66,16 +66,16 @@ -- 1 candidates of size 1 -- 0 candidates of size 2 -- 0 candidates of size 3--- 1 candidates of size 4+-- 0 candidates of size 4 -- 0 candidates of size 5 -- 0 candidates of size 6 -- 0 candidates of size 7--- 20 candidates of size 8+-- 16 candidates of size 8 -- 0 candidates of size 9 -- 0 candidates of size 10 -- 0 candidates of size 11--- 80 candidates of size 12--- tested 88 candidates+-- 36 candidates of size 12+-- tested 42 candidates mem x Leaf = False mem x (Node t1 y t2) = mem x t1 || (mem x t2 || x == y) @@ -83,18 +83,18 @@ -- testing 360 combinations of argument values -- pruning with 29/39 rules -- 2 candidates of size 1--- 2 candidates of size 2--- 2 candidates of size 3+-- 1 candidates of size 2+-- 0 candidates of size 3 -- 0 candidates of size 4--- 10 candidates of size 5--- 30 candidates of size 6+-- 2 candidates of size 5+-- 12 candidates of size 6 -- 0 candidates of size 7--- 68 candidates of size 8--- 216 candidates of size 9--- 56 candidates of size 10--- 802 candidates of size 11--- 2077 candidates of size 12--- tested 3265 candidates+-- 36 candidates of size 8+-- 104 candidates of size 9+-- 0 candidates of size 10+-- 418 candidates of size 11+-- 1064 candidates of size 12+-- tested 1639 candidates cannot conjure ordered :: Tree -> Bool@@ -112,12 +112,12 @@ -- 1 candidates of size 1 -- 0 candidates of size 2 -- 0 candidates of size 3--- 1 candidates of size 4+-- 0 candidates of size 4 -- 2 candidates of size 5--- 5 candidates of size 6+-- 4 candidates of size 6 -- 4 candidates of size 7--- 9 candidates of size 8--- tested 15 candidates+-- 8 candidates of size 8+-- tested 13 candidates preorder Leaf = [] preorder (Node t1 x t2) = x:(preorder t1 ++ preorder t2) @@ -127,12 +127,12 @@ -- 1 candidates of size 1 -- 0 candidates of size 2 -- 0 candidates of size 3--- 1 candidates of size 4+-- 0 candidates of size 4 -- 2 candidates of size 5--- 5 candidates of size 6+-- 4 candidates of size 6 -- 4 candidates of size 7--- 9 candidates of size 8--- tested 19 candidates+-- 8 candidates of size 8+-- tested 17 candidates inorder Leaf = [] inorder (Node t1 x t2) = inorder t1 ++ (x:inorder t2) @@ -142,14 +142,14 @@ -- 1 candidates of size 1 -- 0 candidates of size 2 -- 0 candidates of size 3--- 1 candidates of size 4+-- 0 candidates of size 4 -- 2 candidates of size 5--- 5 candidates of size 6+-- 4 candidates of size 6 -- 4 candidates of size 7--- 9 candidates of size 8+-- 8 candidates of size 8 -- 14 candidates of size 9--- 17 candidates of size 10--- tested 50 candidates+-- 16 candidates of size 10+-- tested 47 candidates posorder Leaf = [] posorder (Node t1 x t2) = posorder t1 ++ (posorder t2 ++ [x])
src/Conjure.hs view
@@ -30,16 +30,16 @@ -- -- > > conjure "factorial" factorial primitives -- > factorial :: Int -> Int--- > -- testing 3 combinations of argument values--- > -- pruning with 27/65 rules--- > -- looking through 3 candidates of size 1--- > -- looking through 3 candidates of size 2--- > -- looking through 9 candidates of size 3--- > -- looking through 10 candidates of size 4--- > -- looking through 32 candidates of size 5--- > -- looking through 39 candidates of size 6--- > -- looking through 185 candidates of size 7--- > -- tested 107 candidates+-- > -- 0.1s, testing 4 combinations of argument values+-- > -- 0.8s, pruning with 27/65 rules+-- > -- 0.8s, 3 candidates of size 1+-- > -- 0.9s, 3 candidates of size 2+-- > -- 0.9s, 7 candidates of size 3+-- > -- 0.9s, 8 candidates of size 4+-- > -- 0.9s, 28 candidates of size 5+-- > -- 0.9s, 35 candidates of size 6+-- > -- 0.9s, 167 candidates of size 7+-- > -- 0.9s, tested 95 candidates -- > factorial 0 = 1 -- > factorial x = x * factorial (x - 1) --@@ -71,9 +71,10 @@ -- > take :: Int -> [A] -> [A] -- > -- testing 153 combinations of argument values -- > -- pruning with 4/7 rules--- > -- ... ... ...--- > -- looking through 58 candidates of size 9--- > -- tested 104 candidates+-- > -- ... ... ... ... ... ...+-- > -- 0.4s, 6 candidates of size 8+-- > -- 0.4s, 5 candidates of size 9+-- > -- 0.4s, tested 15 candidates -- > take 0 xs = [] -- > take x [] = [] -- > take x (y:xs) = y:take (x - 1) xs
src/Conjure/Conjurable.hs view
@@ -28,6 +28,7 @@ , conjureGrounds , conjureAreEqual , conjureMkEquation+ , conjureTestDefn , A, B, C, D, E, F , conjureIsUnbreakable , conjureReification@@ -187,7 +188,14 @@ -- -- This is used in the implementation of 'conjureReification'. conjureReification1 :: Conjurable a => a -> Reification1-conjureReification1 x = (hole x, conjureEquality x, conjureTiers x, names x, conjureCases x, value "conjureSize" (conjureSize -:> x))+conjureReification1 x =+ ( hole x+ , conjureEquality x+ , conjureTiers x+ , names x+ , conjureCases x+ , value "conjureSize" (conjureSize -:> x)+ ) -- | Conjures a list of 'Reification1' -- for a 'Conjurable' type, its subtypes and 'Bool'.@@ -249,9 +257,11 @@ where exprE = value "expr" (expr -:> a) + mkExprTiers :: (Listable a, Show a, Typeable a) => a -> [[Expr]] mkExprTiers a = mapT val (tiers -: [[a]]) + -- | Computes a list of holes encoded as 'Expr's -- from a 'Conjurable' functional value. --@@ -259,10 +269,12 @@ conjureHoles :: Conjurable f => f -> [Expr] conjureHoles f = [eh | (eh,_,Just _,_,_,_) <- conjureReification f] + -- | Computes a function that makes an equation between two expressions. conjureMkEquation :: Conjurable f => f -> Expr -> Expr -> Expr conjureMkEquation f = mkEquation [eq | (_,Just eq,_,_,_,_) <- conjureReification f] + conjureDynamicEq :: Conjurable f => f -> Dynamic conjureDynamicEq f = case conjureMkEquation f efxs efxs of (Value "==" deq :$ _ :$ _) -> deq@@ -280,6 +292,99 @@ e1 === e2 = isTrue $ e1 -==- e2 isTrue = all (errorToFalse . eval False) . gs gs = take maxTests . conjureGrounds f+++-- | Compute a 'Defn' from the given partial definition.+--+-- With:+--+-- > fact :: Int -> Int+-- > fact 1 = 1+-- > fact 3 = 6+-- > fact 4 = 24+--+-- Then:+--+-- > > putStrLn $ showDefn $ conjureTestDefn 60 360 "fact n" fact+-- > fact :: Int -> Int+-- > fact 1 = 1+-- > fact 3 = 6+-- > fact 4 = 24+--+-- > > putStrLn $ showDefn $ conjureTestDefn 3 4 "-:-" ((:) :: Int -> [Int] -> [Int])+-- > 0 -:- [] = [0]+-- > 0 -:- [0] = [0,0]+-- > 1 -:- [] = [1]+conjureTestDefn :: Conjurable f => Int -> Int -> String -> f -> Defn+conjureTestDefn maxTests maxSearchTests nm f =+ [(fxys, exprExpr fxys) | fxys <- conjureTestApps maxTests maxSearchTests nm f]+ where+ -- the use of conjureExpress here is sort of a hack+ -- we "only" would need a conjureRevl :: Conjurable f => f -> Expr -> Expr+ -- which would generate (val . evl) for supported types+ exprExpr = conjureExpress f+++-- | Compute a test applications that yield non-undefined values.+--+-- With:+--+-- > fact :: Int -> Int+-- > fact 1 = 1+-- > fact 3 = 6+-- > fact 4 = 24+--+-- Then:+--+-- > > putStrLn $ showDefn $ conjureTestApps 60 360 "fact n" fact+-- > [fact 1 :: Int, fact 3 :: Int, fact 4 :: Int]+--+-- This function is internal and used in the implementation of 'conjureTestDefn'.+conjureTestApps :: Conjurable f => Int -> Int -> String -> f -> [Expr]+conjureTestApps maxTests maxSearchTests nm f =+ [fxys //- bs | bs <- conjureTestBinds maxTests maxSearchTests nm f]+ where+ fxys = conjureApplication nm f+++-- | Compute test bindings based on a partially defined function.+--+-- With:+--+-- > fact 1 = 1+-- > fact 3 = 6+-- > fact 4 = 24+--+-- Then:+--+-- > > conjureTestBinds 6 12 "factorial n" fact+-- > [ [(n :: Int,1 :: Int)]+-- > , [(n :: Int,3 :: Int)]+-- > , [(n :: Int,4 :: Int)]+-- > ]+--+-- Multiple arguments yield multiple bindins:+--+-- > > conjureTestBinds 3 4 ":" ((:) :: Int -> [Int] -> [Int])+-- > [ [(x :: Int,0 :: Int),(xs :: [Int],[] :: [Int])]+-- > , [(x :: Int,0 :: Int),(xs :: [Int],[0] :: [Int])]+-- > , [(x :: Int,1 :: Int),(xs :: [Int],[] :: [Int])]+-- > ]+--+-- The variable naming is consistent with 'conjureApplication' and 'conjureVarApplication'.+--+-- This function is internal and used in the implementation of 'conjureTestDefn'.+conjureTestBinds :: Conjurable f => Int -> Int -> String -> f -> [[(Expr,Expr)]]+conjureTestBinds maxTests maxSearchTests nm f = take maxTests+ [ bs+ | bs <- take maxSearchTests $ groundBinds tiersFor fxys+ , errorToFalse . eval False $ fxys -==- fxys //- bs+ ]+ where+ (-==-) = conjureMkEquation f+ tiersFor = conjureTiersFor f+ fxys = conjureApplication nm f+ -- | Compute 'tiers' of values encoded as 'Expr's -- of the type of the given 'Expr'.
src/Conjure/Engine.hs view
@@ -85,11 +85,12 @@ -- -- > > conjure "factorial" factorial primitives -- > factorial :: Int -> Int--- > -- testing 3 combinations of argument values--- > -- pruning with 27/65 rules--- > -- ... ... ...--- > -- looking through 185 candidates of size 7--- > -- tested 107 candidates+-- > -- 0.1s, testing 4 combinations of argument values+-- > -- 0.8s, pruning with 27/65 rules+-- > -- ... ... ... ... ... ...+-- > -- 0.9s, 35 candidates of size 6+-- > -- 0.9s, 167 candidates of size 7+-- > -- 0.9s, tested 95 candidates -- > factorial 0 = 1 -- > factorial x = x * factorial (x - 1) --@@ -112,12 +113,13 @@ -- -- Then: ----- > > conjureFromSpec "square" squareSpec primitives+-- > > conjureFromSpec "square" squareSpec [prim "*" ((*) :: Int -> Int -> Int)] -- > square :: Int -> Int--- > -- pruning with 14/25 rules--- > -- looking through 3 candidates of size 1--- > -- looking through 4 candidates of size 2--- > -- looking through 9 candidates of size 3+-- > -- 0.1s, pruning with 2/6 rules+-- > -- 0.1s, 1 candidates of size 1+-- > -- 0.1s, 0 candidates of size 2+-- > -- 0.1s, 1 candidates of size 3+-- > -- 0.1s, tested 2 candidates -- > square x = x * x -- -- This allows users to specify QuickCheck-style properties,@@ -144,39 +146,12 @@ -- | Like 'conjure' but allows setting the maximum size of considered expressions--- instead of the default value of 12.------ > conjureWithMaxSize 18 "function" function [...]------ For example, given the following partial definition for 'Data.List.insert':------ > insert' :: Int -> [Int] -> [Int]--- > insert' 0 [] = [0]--- > insert' 0 [1,2] = [0,1,2]--- > insert' 1 [0,2] = [0,1,2]--- > insert' 2 [0,1] = [0,1,2]------ Conjure is able to find an appropriate definition at size 17--- with the following primitives:+-- instead of the default value of 24. ----- > > conjureWithMaxSize 18 "insert" insert'--- > > [ prim "[]" ([] :: [Int])--- > > , prim ":" ((:) :: Int -> [Int] -> [Int])--- > > , prim "<=" ((<=) :: Int -> Int -> Bool)--- > > , prif (undefined :: [Int])--- > > ]--- > insert :: Int -> [Int] -> [Int]--- > -- testing 4 combinations of argument values--- > -- pruning with 4/4 rules--- > -- ... ... ...--- > -- looking through 14550 candidates of size 17--- > -- tested 14943 candidates--- > insert x [] = [x]--- > insert x (y:xs) = if x <= y--- > then x:insert y xs--- > else y:insert x xs+-- > conjureWithMaxSize 12 "function" function [...] ----- The default maximum size of 12 would not be enough for the above definition.+-- This function is a candidate for going away.+-- Please set maxSize in Args instead. conjureWithMaxSize :: Conjurable f => Int -> String -> f -> [Prim] -> IO () conjureWithMaxSize sz = conjureWith args { maxSize = sz@@ -212,6 +187,7 @@ , requireDescent :: Bool -- ^ require recursive calls to deconstruct arguments , adHocRedundancy :: Bool -- ^ ad-hoc redundancy checks , copyBindings :: Bool -- ^ copy partial definition bindings in candidates+ , earlyTests :: Bool -- ^ perform tests early-and-independently on each binding , atomicNumbers :: Bool -- ^ restrict constant/ground numeric expressions to atoms , requireZero :: Bool -- ^ require 0 as base case for Num recursions , uniqueCandidates :: Bool -- ^ unique-modulo-testing candidates@@ -258,6 +234,7 @@ , requireDescent = True , adHocRedundancy = True , copyBindings = True+ , earlyTests = True , atomicNumbers = True , requireZero = False , uniqueCandidates = False@@ -292,7 +269,7 @@ putWithTimeSince t0 $ "testing " ++ show (length ts) ++ " combinations of argument values" when (showTests args) $ do putStrLn $ "{-"- putStr $ unlines $ map show ts+ putStr $ showDefn ts putStrLn $ "-}" putWithTimeSince t0 $ "pruning with " ++ show nRules ++ "/" ++ show nREs ++ " rules" when (showTheory args) $ do@@ -356,7 +333,7 @@ data Results = Results { implementationss :: [[Defn]] -- ^ tiers of implementations , candidatess :: [[Defn]] -- ^ tiers of candidates- , bindings :: [Expr] -- ^ test bindings used to verify candidates+ , bindings :: Defn -- ^ test bindings used to verify candidates , theory :: Thy -- ^ the underlying theory , patternss :: [[Defn]] -- ^ tiers of allowed patterns , deconstructions :: [Expr] -- ^ the list of allowed deconstructions@@ -402,32 +379,22 @@ , deconstructions = deconstructions } where- tests = [ffxx //- bs | bs <- dbss] implementationsT = filterT implements candidatesT implements fx = defnApparentlyTerminates fx- && requal fx ffxx vffxx+ && test fx && errorToFalse (p (cevl maxEvalRecursions fx)) candidatesT = (if uniqueCandidates then nubCandidates args nm f else id) $ (if target > 0 then targetiers target else id) $ (if maxSize > 0 then take maxSize else id) $ candidatesTT (candidatesTT, thy, patternss, deconstructions) = candidateDefns args nm f es- ffxx = conjureApplication nm f- vffxx = conjureVarApplication nm f - requal dfn e1 e2 = isTrueWhenDefined dfn (e1 -==- e2)+ test dfn = all (errorToFalse . deval (conjureExpress f) maxEvalRecursions dfn False)+ $ [funToVar lhs -==- rhs | (lhs, rhs) <- tests]+ tests = conjureTestDefn maxTests maxSearchTests nm f (-==-) = conjureMkEquation f - isTrueWhenDefined dfn e = all (errorToFalse . deval (conjureExpress f) maxEvalRecursions dfn False)- $ map (e //-) dbss - bss, dbss :: [[(Expr,Expr)]]- bss = take maxSearchTests $ groundBinds (conjureTiersFor f) ffxx- dbss = take maxTests [bs | bs <- bss, errorToFalse . eval False $ e //- bs]- where- e = ffxx -==- ffxx-- -- | Just prints the underlying theory found by "Test.Speculate" -- without actually synthesizing a function. conjureTheory :: Conjurable f => String -> f -> [Prim] -> IO ()@@ -544,6 +511,9 @@ keep | rewriting = isRootNormalC thy . fastMostGeneralVariation | otherwise = const True + keepBndn | rewriting = \b@(_,rhs) -> isBaseCase b || size (normalize thy rhs) >= size rhs+ | otherwise = const True+ appsWith :: Expr -> [Expr] -> [[Expr]] appsWith eh vs = enumerateAppsFor eh k $ vs ++ es where@@ -563,6 +533,10 @@ isNumeric = conjureIsNumeric f + (-==-) = conjureMkEquation f+ tests = conjureTestDefn maxTests maxSearchTests nm f+ exprExpr = conjureExpress f+ ps2fss :: [Expr] -> [[Defn]] ps2fss pats = discardT isRedundant . products -- alt: use delayedProducts@@ -575,10 +549,24 @@ -- simply use its return value as the only possible result p2eess pat | copyBindings && isGroundPat f pat = [[(pat, toValPat f pat)]] p2eess pat = mapT (pat,)+ . filterT keepBase . appsWith pat . drop 1 -- this excludes the function name itself $ vars pat ++ [eh | any (uncurry should) (zip aess aes)] where+ keepBase+ | not earlyTests = const True+ | all isVar (unfoldApp pat) = const True+ | otherwise = \e -> hasHole e || reallyKeepBase e+ reallyKeepBase e = and+ [ errorToFalse $ eval False $ (e //- bs) -==- rhs+ | (lhs,rhs) <- tests+ -- filter test bindings that match the current pattern:+ , Just bs <- [lhs `matchArgs` pat]+ ]+ matchArgs efxs efys = fold (map exprExpr (drop 1 (unfoldApp efxs)))+ `match` fold (drop 1 (unfoldApp efys))+ -- computes whether we should include a recurse for this given argument -- numeric arguments additionally require 0 to be present as a case -- for recursion@@ -588,7 +576,8 @@ aess = transpose $ map (tail . unfoldApp . rehole) pats fillingsFor1 :: Bndn -> [[Bndn]]- fillingsFor1 (ep,er) = mapT (\es -> (ep,fill er es))+ fillingsFor1 (ep,er) = filterT keepBndn+ . mapT (\es -> (ep,fill er es)) . products . replicate (length $ holes er) $ recs' ep
src/Conjure/Prim.hs view
@@ -87,9 +87,11 @@ -- > > , prim "undefined" (undefined :: Int) -- > > ] -- > last :: [Int] -> Int--- > -- ... ... ...--- > -- looking through 4 candidates of size 7--- > -- tested 5 candidates+-- > -- 0.0s, testing 360 combinations of argument values+-- > -- 0.0s, pruning with 5/5 rules+-- > -- ... ... ... ... ...+-- > -- 0.0s, 4 candidates of size 7+-- > -- 0.0s, tested 2 candidates -- > last [] = undefined -- > last (x:xs) = if null xs -- > then x@@ -109,16 +111,14 @@ -- > > , primOrdCaseFor (undefined :: Bool) -- > > ] -- > mem :: Int -> Tree -> Bool--- > -- ... ... ...--- > -- looking through 384 candidates of size 12--- > -- tested 371 candidates+-- > -- ... ... ... ... ...+-- > -- 0.0s, 384 candidates of size 12+-- > -- 0.0s, tested 346 candidates -- > mem x Leaf = False -- > mem x (Node t1 y t2) = case x `compare` y of -- > LT -> mem x t1 -- > EQ -> True -- > GT -> mem x t2-- primOrdCaseFor :: Conjurable a => a -> Prim primOrdCaseFor x = (caseForOrd x, conjureType x)
test/conjurable.hs view
@@ -293,6 +293,26 @@ -- little sanity check (conjurableOK should catch it anyway) , take 6 (conjureListFor (undefined :: Int) i_) == [zero, one, minusOne, two, minusTwo, three]++ , conjureTestDefn 6 12 "factorial n" fact+ == [ (value "factorial" fact :$ one, one)+ , (value "factorial" fact :$ two, two)+ , (value "factorial" fact :$ three, six)+ , (value "factorial" fact :$ four, val (24 :: Int))+ ]++ , conjureTestDefn 4 6 "sum" (sum :: [Int] -> Int)+ == [ (sum' nil, zero)+ , (sum' (val [0 :: Int]), zero)+ , (sum' (val [0, 0 :: Int]), zero)+ , (sum' (val [1 :: Int]), one)+ ]++ , conjureTestDefn 3 4 ":" ((:) :: Int -> [Int] -> [Int])+ == [ (zero -:- nil, zero -:- nil)+ , (zero -:- val [0::Int], zero -:- zero -:- nil)+ , (one -:- nil, one -:- nil)+ ] ] isNumeric :: Expr -> Bool@@ -321,3 +341,11 @@ (==) = eval err . fromMaybe err $ conjureEquality x err = error "<==>: could not conjure" infix 4 <==>+++-- to be used in the test of conjureTestBinds and related functions+fact :: Int -> Int+fact 1 = 1+fact 2 = 2+fact 3 = 6+fact 4 = 24