-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb9739f
commit 5919bb7
Showing
6 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ eg/sort | |
eg/subset | ||
eg/spec | ||
bench/carry-on | ||
bench/strategies | ||
bench/self | ||
bench/longshot | ||
bench/ill-hit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
4.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
-- carryon.hs: conjuring implementations of a factorial function | ||
-- | ||
-- Copyright (C) 2021-2024 Rudy Matela | ||
-- Distributed under the 3-Clause BSD licence (see the file LICENSE). | ||
import Conjure | ||
|
||
factorial :: Int -> Int | ||
factorial 1 = 1 | ||
factorial 2 = 2 | ||
factorial 3 = 6 | ||
factorial 4 = 24 | ||
|
||
|
||
mkStrategy :: String -> Args | ||
mkStrategy s = args | ||
{ rewriting = r | ||
, requireDescent = d | ||
, adHocRedundancy = a | ||
, copyBindings = c | ||
, uniqueCandidates = u | ||
} | ||
where | ||
itob 0 = False | ||
itob _ = True | ||
[r,d,a,c,u] = map itob $ | ||
case s of | ||
"unique candidates" -> [1,1,1,1,1] | ||
"default" -> [1,1,1,1,0] | ||
"without reasoning" -> [0,1,1,1,0] | ||
"without descent" -> [1,0,1,1,0] | ||
"without ad-hoc" -> [1,1,0,1,0] | ||
"without copy" -> [1,1,1,0,0] | ||
"only reasoning" -> [1,0,0,0,0] | ||
"only descent" -> [0,1,0,0,0] | ||
"only ad-hoc" -> [0,0,1,0,0] | ||
"only copy" -> [0,0,0,1,0] | ||
"only typed" -> [0,0,0,0,0] | ||
_ -> error "unknown strategy" | ||
|
||
conjureStrategy :: Conjurable f => String -> String -> f -> [Prim] -> IO () | ||
conjureStrategy name nm f prims = do | ||
putStrLn $ "-- strategy: " ++ name | ||
conjureWith (mkStrategy name) nm f prims | ||
|
||
strategies :: [String] | ||
strategies = | ||
[ "unique candidates" | ||
, "default" | ||
, "without reasoning" | ||
, "without descent" | ||
, "without ad-hoc" | ||
, "without copy" | ||
, "only reasoning" | ||
, "only descent" | ||
, "only ad-hoc" | ||
, "only copy" | ||
, "only typed" | ||
] | ||
|
||
main :: IO () | ||
main = do | ||
sequence_ | ||
[ conjureStrategy s "factorial n" factorial primitives | ||
| s <- strategies | ||
] | ||
|
||
primitives :: [Prim] | ||
primitives = | ||
[ pr (0::Int) | ||
, pr (1::Int) | ||
, prim "+" ((+) :: Int -> Int -> Int) | ||
, prim "*" ((*) :: Int -> Int -> Int) | ||
, prim "-" ((-) :: Int -> Int -> Int) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
-- strategy: unique candidates | ||
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 23 candidates of size 5 | ||
-- looking through 30 candidates of size 6 | ||
-- looking through 84 candidates of size 7 | ||
-- tested 84 candidates | ||
factorial 0 = 1 | ||
factorial x = x * factorial (x - 1) | ||
|
||
-- strategy: default | ||
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 179 candidates of size 7 | ||
-- tested 95 candidates | ||
factorial 0 = 1 | ||
factorial x = x * factorial (x - 1) | ||
|
||
-- strategy: without reasoning | ||
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 16 candidates of size 3 | ||
-- looking through 17 candidates of size 4 | ||
-- looking through 279 candidates of size 5 | ||
-- looking through 313 candidates of size 6 | ||
-- looking through 5763 candidates of size 7 | ||
-- tested 656 candidates | ||
factorial 0 = 1 | ||
factorial x = x * factorial (x - 1) | ||
|
||
-- strategy: without descent | ||
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 264 candidates of size 7 | ||
-- tested 148 candidates | ||
factorial 0 = 1 | ||
factorial x = x * factorial (x - 1) | ||
|
||
-- strategy: without ad-hoc | ||
factorial :: Int -> Int | ||
-- testing 4 combinations of argument values | ||
-- pruning with 27/65 rules | ||
-- looking through 3 candidates of size 1 | ||
-- looking through 6 candidates of size 2 | ||
-- looking through 9 candidates of size 3 | ||
-- looking through 18 candidates of size 4 | ||
-- looking through 31 candidates of size 5 | ||
-- looking through 59 candidates of size 6 | ||
-- looking through 183 candidates of size 7 | ||
-- tested 137 candidates | ||
factorial 0 = 1 | ||
factorial x = x * factorial (x - 1) | ||
|
||
-- strategy: without copy | ||
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 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 197 candidates of size 7 | ||
-- tested 107 candidates | ||
factorial 0 = 1 | ||
factorial x = x * factorial (x - 1) | ||
|
||
-- strategy: only reasoning | ||
factorial :: Int -> Int | ||
-- testing 4 combinations of argument values | ||
-- pruning with 27/65 rules | ||
-- looking through 3 candidates of size 1 | ||
-- looking through 6 candidates of size 2 | ||
-- looking through 12 candidates of size 3 | ||
-- looking through 24 candidates of size 4 | ||
-- looking through 47 candidates of size 5 | ||
-- looking through 82 candidates of size 6 | ||
-- looking through 354 candidates of size 7 | ||
-- tested 284 candidates | ||
factorial 0 = 1 | ||
factorial x = x * factorial (x - 1) | ||
|
||
-- strategy: only descent | ||
factorial :: Int -> Int | ||
-- testing 4 combinations of argument values | ||
-- pruning with 27/65 rules | ||
-- looking through 3 candidates of size 1 | ||
-- looking through 6 candidates of size 2 | ||
-- looking through 21 candidates of size 3 | ||
-- looking through 42 candidates of size 4 | ||
-- looking through 302 candidates of size 5 | ||
-- looking through 602 candidates of size 6 | ||
-- looking through 6115 candidates of size 7 | ||
-- tested 1001 candidates | ||
factorial 0 = 1 | ||
factorial x = x * factorial (x - 1) | ||
|
||
-- strategy: only ad-hoc | ||
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 18 candidates of size 3 | ||
-- looking through 19 candidates of size 4 | ||
-- looking through 289 candidates of size 5 | ||
-- looking through 323 candidates of size 6 | ||
-- looking through 6468 candidates of size 7 | ||
-- tested 1028 candidates | ||
factorial 0 = 1 | ||
factorial x = x * factorial (x - 1) | ||
|
||
-- strategy: only copy | ||
factorial :: Int -> Int | ||
-- testing 4 combinations of argument values | ||
-- pruning with 27/65 rules | ||
-- looking through 3 candidates of size 1 | ||
-- looking through 6 candidates of size 2 | ||
-- looking through 18 candidates of size 3 | ||
-- looking through 36 candidates of size 4 | ||
-- looking through 315 candidates of size 5 | ||
-- looking through 585 candidates of size 6 | ||
-- looking through 6915 candidates of size 7 | ||
-- tested 1876 candidates | ||
factorial 0 = 1 | ||
factorial x = x * factorial (x - 1) | ||
|
||
-- strategy: only typed | ||
factorial :: Int -> Int | ||
-- testing 4 combinations of argument values | ||
-- pruning with 27/65 rules | ||
-- looking through 3 candidates of size 1 | ||
-- looking through 6 candidates of size 2 | ||
-- looking through 21 candidates of size 3 | ||
-- looking through 42 candidates of size 4 | ||
-- looking through 330 candidates of size 5 | ||
-- looking through 630 candidates of size 6 | ||
-- looking through 7215 candidates of size 7 | ||
-- tested 1945 candidates | ||
factorial 0 = 1 | ||
factorial x = x * factorial (x - 1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters