{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Kanren.Data.Binary (
Bit (..),
_O,
_I,
_O',
_I',
Binary,
zeroo,
poso,
gtlo,
binaryo,
addo,
subo,
lesso,
mulo,
divo,
logo,
example,
) where
import Control.DeepSeq (NFData)
import Control.Lens.TH (makePrisms)
import Data.Bifunctor (bimap)
import Data.Function ((&))
import GHC.Generics (Generic)
import Kanren.Core
import Kanren.Goal
import Kanren.LogicalBase
import Kanren.Match
import Kanren.TH
data Bit = O | I deriving (Bit -> Bit -> Bool
(Bit -> Bit -> Bool) -> (Bit -> Bit -> Bool) -> Eq Bit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Bit -> Bit -> Bool
== :: Bit -> Bit -> Bool
$c/= :: Bit -> Bit -> Bool
/= :: Bit -> Bit -> Bool
Eq, Int -> Bit -> ShowS
[Bit] -> ShowS
Bit -> String
(Int -> Bit -> ShowS)
-> (Bit -> String) -> ([Bit] -> ShowS) -> Show Bit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Bit -> ShowS
showsPrec :: Int -> Bit -> ShowS
$cshow :: Bit -> String
show :: Bit -> String
$cshowList :: [Bit] -> ShowS
showList :: [Bit] -> ShowS
Show, (forall x. Bit -> Rep Bit x)
-> (forall x. Rep Bit x -> Bit) -> Generic Bit
forall x. Rep Bit x -> Bit
forall x. Bit -> Rep Bit x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Bit -> Rep Bit x
from :: forall x. Bit -> Rep Bit x
$cto :: forall x. Rep Bit x -> Bit
to :: forall x. Rep Bit x -> Bit
Generic, Bit -> ()
(Bit -> ()) -> NFData Bit
forall a. (a -> ()) -> NFData a
$crnf :: Bit -> ()
rnf :: Bit -> ()
NFData)
instance Logical Bit
makePrisms ''Bit
makeExhaustivePrisms ''Bit
type Binary = [Bit]
instance Num Binary where
fromInteger :: Integer -> [Bit]
fromInteger Integer
0 = []
fromInteger Integer
1 = [Bit
I]
fromInteger Integer
x | Integer
x Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> Integer
1 = Bit
bit Bit -> [Bit] -> [Bit]
forall a. a -> [a] -> [a]
: Integer -> [Bit]
forall a. Num a => Integer -> a
fromInteger (Integer
x Integer -> Integer -> Integer
forall a. Integral a => a -> a -> a
`div` Integer
2)
where
bit :: Bit
bit
| Integer -> Bool
forall a. Integral a => a -> Bool
even Integer
x = Bit
O
| Bool
otherwise = Bit
I
fromInteger Integer
_ = String -> [Bit]
forall a. HasCallStack => String -> a
error String
"Binary numbers cannot be negative"
+ :: [Bit] -> [Bit] -> [Bit]
(+) = [Bit] -> [Bit] -> [Bit]
forall a. HasCallStack => a
undefined
* :: [Bit] -> [Bit] -> [Bit]
(*) = [Bit] -> [Bit] -> [Bit]
forall a. HasCallStack => a
undefined
abs :: [Bit] -> [Bit]
abs = [Bit] -> [Bit]
forall a. a -> a
id
signum :: [Bit] -> [Bit]
signum = [Bit] -> [Bit]
forall a. HasCallStack => a
undefined
negate :: [Bit] -> [Bit]
negate = [Bit] -> [Bit]
forall a. HasCallStack => a
undefined
zeroo :: Term Binary -> Goal ()
zeroo :: Term [Bit] -> Goal ()
zeroo Term [Bit]
n = Term [Bit]
n Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
0
poso :: Term Binary -> Goal ()
poso :: Term [Bit] -> Goal ()
poso Term [Bit]
n = do
(x, xs) <- Goal (Term Bit, Term [Bit])
forall v. Fresh v => Goal v
fresh
n === Value (LogicCons x xs)
gtlo :: Term Binary -> Goal ()
gtlo :: Term [Bit] -> Goal ()
gtlo Term [Bit]
n = do
(x, y, ys) <- Goal (Term Bit, Term Bit, Term [Bit])
forall v. Fresh v => Goal v
fresh
n === Value (LogicCons x (Value (LogicCons y ys)))
binaryo :: Term Binary -> Goal ()
binaryo :: Term [Bit] -> Goal ()
binaryo = Matched (Checked, Checked) [Bit] -> Goal ()
forall m a x. Exhausted m => Matched m a -> Goal x
matche'
(Matched (Checked, Checked) [Bit] -> Goal ())
-> ((Matched (Checked, Checked) [Bit] -> Goal ())
-> Matched (Remaining, Checked) [Bit] -> Goal ())
-> Matched (Remaining, Checked) [Bit]
-> Goal ()
forall a b. a -> (a -> b) -> b
& ExhaustivePrism
(Logic [Bit])
(Remaining, Checked)
(Checked, Checked)
()
Remaining
Checked
-> (() -> Goal ())
-> (Matched (Checked, Checked) [Bit] -> Goal ())
-> Matched (Remaining, Checked) [Bit]
-> Goal ()
forall a v m m' x.
(Logical a, Fresh v) =>
ExhaustivePrism (Logic a) m m' v Remaining Checked
-> (v -> Goal x)
-> (Matched m' a -> Goal x)
-> Matched m a
-> Goal x
on' p (Tagged Remaining ()) (f (Tagged Checked ()))
-> p (Tagged (Remaining, Checked) (Logic [Bit]))
(f (Tagged (Checked, Checked) (Logic [Bit])))
p (Tagged Remaining ()) (f (Tagged Checked ()))
-> p (Tagged (Remaining, Checked) (LogicList Bit))
(f (Tagged (Checked, Checked) (LogicList Bit)))
forall a logicNil logicCons logicNil' (p :: * -> * -> *)
(f :: * -> *).
(Choice p, Applicative f) =>
p (Tagged logicNil ()) (f (Tagged logicNil' ()))
-> p (Tagged (logicNil, logicCons) (LogicList a))
(f (Tagged (logicNil', logicCons) (LogicList a)))
ExhaustivePrism
(Logic [Bit])
(Remaining, Checked)
(Checked, Checked)
()
Remaining
Checked
_LogicNil' () -> Goal ()
forall a. a -> Goal a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Matched (Remaining, Checked) [Bit] -> Goal ())
-> ((Matched (Remaining, Checked) [Bit] -> Goal ())
-> Matched (Remaining, Remaining) [Bit] -> Goal ())
-> Matched (Remaining, Remaining) [Bit]
-> Goal ()
forall a b. a -> (a -> b) -> b
& ExhaustivePrism
(Logic [Bit])
(Remaining, Remaining)
(Remaining, Checked)
(Term Bit, Term [Bit])
Remaining
Checked
-> ((Term Bit, Term [Bit]) -> Goal ())
-> (Matched (Remaining, Checked) [Bit] -> Goal ())
-> Matched (Remaining, Remaining) [Bit]
-> Goal ()
forall a v m m' x.
(Logical a, Fresh v) =>
ExhaustivePrism (Logic a) m m' v Remaining Checked
-> (v -> Goal x)
-> (Matched m' a -> Goal x)
-> Matched m a
-> Goal x
on' p (Tagged Remaining (Term Bit, Term [Bit]))
(f (Tagged Checked (Term Bit, Term [Bit])))
-> p (Tagged (Remaining, Remaining) (Logic [Bit]))
(f (Tagged (Remaining, Checked) (Logic [Bit])))
p (Tagged Remaining (Term Bit, Term [Bit]))
(f (Tagged Checked (Term Bit, Term [Bit])))
-> p (Tagged (Remaining, Remaining) (LogicList Bit))
(f (Tagged (Remaining, Checked) (LogicList Bit)))
forall a logicNil logicCons logicCons' (p :: * -> * -> *)
(f :: * -> *).
(Choice p, Applicative f) =>
p (Tagged logicCons (Term a, Term [a]))
(f (Tagged logicCons' (Term a, Term [a])))
-> p (Tagged (logicNil, logicCons) (LogicList a))
(f (Tagged (logicNil, logicCons') (LogicList a)))
ExhaustivePrism
(Logic [Bit])
(Remaining, Remaining)
(Remaining, Checked)
(Term Bit, Term [Bit])
Remaining
Checked
_LogicCons' (\(Term Bit
b, Term [Bit]
bs) -> do
Term Bit
b Term Bit -> (Term Bit -> Goal ()) -> Goal ()
forall a b. a -> (a -> b) -> b
& (Matched (Checked, Checked) Bit -> Goal ()
forall m a x. Exhausted m => Matched m a -> Goal x
matche'
(Matched (Checked, Checked) Bit -> Goal ())
-> ((Matched (Checked, Checked) Bit -> Goal ())
-> Matched (Checked, Remaining) Bit -> Goal ())
-> Matched (Checked, Remaining) Bit
-> Goal ()
forall a b. a -> (a -> b) -> b
& ExhaustivePrism
(Logic Bit)
(Checked, Remaining)
(Checked, Checked)
()
Remaining
Checked
-> (() -> Goal ())
-> (Matched (Checked, Checked) Bit -> Goal ())
-> Matched (Checked, Remaining) Bit
-> Goal ()
forall a v m m' x.
(Logical a, Fresh v) =>
ExhaustivePrism (Logic a) m m' v Remaining Checked
-> (v -> Goal x)
-> (Matched m' a -> Goal x)
-> Matched m a
-> Goal x
on' p (Tagged Remaining ()) (f (Tagged Checked ()))
-> p (Tagged (Checked, Remaining) (Logic Bit))
(f (Tagged (Checked, Checked) (Logic Bit)))
p (Tagged Remaining ()) (f (Tagged Checked ()))
-> p (Tagged (Checked, Remaining) Bit)
(f (Tagged (Checked, Checked) Bit))
forall o i i' (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (Tagged i ()) (f (Tagged i' ()))
-> p (Tagged (o, i) Bit) (f (Tagged (o, i') Bit))
ExhaustivePrism
(Logic Bit)
(Checked, Remaining)
(Checked, Checked)
()
Remaining
Checked
_I' () -> Goal ()
forall a. a -> Goal a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Matched (Checked, Remaining) Bit -> Goal ())
-> ((Matched (Checked, Remaining) Bit -> Goal ())
-> Matched (Remaining, Remaining) Bit -> Goal ())
-> Matched (Remaining, Remaining) Bit
-> Goal ()
forall a b. a -> (a -> b) -> b
& ExhaustivePrism
(Logic Bit)
(Remaining, Remaining)
(Checked, Remaining)
()
Remaining
Checked
-> (() -> Goal ())
-> (Matched (Checked, Remaining) Bit -> Goal ())
-> Matched (Remaining, Remaining) Bit
-> Goal ()
forall a v m m' x.
(Logical a, Fresh v) =>
ExhaustivePrism (Logic a) m m' v Remaining Checked
-> (v -> Goal x)
-> (Matched m' a -> Goal x)
-> Matched m a
-> Goal x
on' p (Tagged Remaining ()) (f (Tagged Checked ()))
-> p (Tagged (Remaining, Remaining) (Logic Bit))
(f (Tagged (Checked, Remaining) (Logic Bit)))
p (Tagged Remaining ()) (f (Tagged Checked ()))
-> p (Tagged (Remaining, Remaining) Bit)
(f (Tagged (Checked, Remaining) Bit))
forall o i o' (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (Tagged o ()) (f (Tagged o' ()))
-> p (Tagged (o, i) Bit) (f (Tagged (o', i) Bit))
ExhaustivePrism
(Logic Bit)
(Remaining, Remaining)
(Checked, Remaining)
()
Remaining
Checked
_O' (\() -> Term [Bit] -> Goal ()
poso Term [Bit]
bs)
(Matched (Remaining, Remaining) Bit -> Goal ())
-> ((Matched (Remaining, Remaining) Bit -> Goal ())
-> Term Bit -> Goal ())
-> Term Bit
-> Goal ()
forall a b. a -> (a -> b) -> b
& (Matched (Remaining, Remaining) Bit -> Goal ())
-> Term Bit -> Goal ()
forall m a x. (Matched m a -> Goal x) -> Term a -> Goal x
enter')
Term [Bit] -> Goal ()
binaryo Term [Bit]
bs)
(Matched (Remaining, Remaining) [Bit] -> Goal ())
-> ((Matched (Remaining, Remaining) [Bit] -> Goal ())
-> Term [Bit] -> Goal ())
-> Term [Bit]
-> Goal ()
forall a b. a -> (a -> b) -> b
& (Matched (Remaining, Remaining) [Bit] -> Goal ())
-> Term [Bit] -> Goal ()
forall m a x. (Matched m a -> Goal x) -> Term a -> Goal x
enter'
lesslo :: Term Binary -> Term Binary -> Goal ()
lesslo :: Term [Bit] -> Term [Bit] -> Goal ()
lesslo Term [Bit]
n Term [Bit]
m =
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term [Bit] -> Goal ()
zeroo Term [Bit]
n
Term [Bit] -> Goal ()
poso Term [Bit]
m
, do
Term [Bit]
n Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
Term [Bit] -> Goal ()
gtlo Term [Bit]
m
, do
(a, x, b, y) <- Goal (Term Bit, Term [Bit], Term Bit, Term [Bit])
forall v. Fresh v => Goal v
fresh
n === Value (LogicCons a x)
poso x
m === Value (LogicCons b y)
poso y
lesslo x y
]
samelo :: Term Binary -> Term Binary -> Goal ()
samelo :: Term [Bit] -> Term [Bit] -> Goal ()
samelo Term [Bit]
n Term [Bit]
m =
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term [Bit] -> Goal ()
zeroo Term [Bit]
n
Term [Bit] -> Goal ()
zeroo Term [Bit]
m
, do
Term [Bit]
n Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
Term [Bit]
m Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
, do
(a, x, b, y) <- Goal (Term Bit, Term [Bit], Term Bit, Term [Bit])
forall v. Fresh v => Goal v
fresh
n === Value (LogicCons a x)
poso x
m === Value (LogicCons b y)
poso y
samelo x y
]
lessl3o :: Term Binary -> Term Binary -> Term Binary -> Term Binary -> Goal ()
lessl3o :: Term [Bit] -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
lessl3o Term [Bit]
q Term [Bit]
c Term [Bit]
a Term [Bit]
b =
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term [Bit] -> Goal ()
zeroo Term [Bit]
q
Term [Bit] -> Goal ()
poso Term [Bit]
c
, do
(a0, a1, a2, a3, x, (y, z)) <- Goal
(Term Bit, Term Bit, Term Bit, Term Bit, Term [Bit],
(Term [Bit], Term [Bit]))
forall v. Fresh v => Goal v
fresh
q === Value (LogicCons a0 x)
c === Value (LogicCons a1 y)
disjMany
[ do
zeroo a
b === Value (LogicCons a2 z)
lessl3o x y z (inject' 0)
, do
a === Value (LogicCons a3 z)
lessl3o x y z b
]
]
appendo :: (Logical a) => Term [a] -> Term [a] -> Term [a] -> Goal ()
appendo :: forall a. Logical a => Term [a] -> Term [a] -> Term [a] -> Goal ()
appendo Term [a]
xs Term [a]
ys Term [a]
zs =
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term [a]
xs Term [a] -> Term [a] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [a] -> Term [a]
forall a. Logical a => a -> Term a
inject' []
Term [a]
ys Term [a] -> Term [a] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Term [a]
zs
, do
(x, xs', zs') <- Goal (Term a, Term [a], Term [a])
forall v. Fresh v => Goal v
fresh
xs === Value (LogicCons x xs')
zs === Value (LogicCons x zs')
appendo xs' ys zs'
]
full1Addero :: Term Bit -> Term Bit -> Term Bit -> Term Bit -> Term Bit -> Goal ()
full1Addero :: Term Bit -> Term Bit -> Term Bit -> Term Bit -> Term Bit -> Goal ()
full1Addero Term Bit
carryIn Term Bit
a Term Bit
b Term Bit
s Term Bit
carryOut =
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term Bit
carryIn Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term Bit
a Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O
[[Goal ()]] -> Goal ()
conde
[ [Term Bit
b Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O, Term Bit
s Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O, Term Bit
carryOut Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O]
, [Term Bit
b Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I, Term Bit
s Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I, Term Bit
carryOut Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O]
]
, do
Term Bit
a Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I
[[Goal ()]] -> Goal ()
conde
[ [Term Bit
b Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O, Term Bit
s Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I, Term Bit
carryOut Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O]
, [Term Bit
b Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I, Term Bit
s Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O, Term Bit
carryOut Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I]
]
]
, do
Term Bit
carryIn Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term Bit
a Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O
[[Goal ()]] -> Goal ()
conde
[ [Term Bit
b Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O, Term Bit
s Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I, Term Bit
carryOut Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O]
, [Term Bit
b Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I, Term Bit
s Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O, Term Bit
carryOut Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I]
]
, do
Term Bit
a Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I
[[Goal ()]] -> Goal ()
conde
[ [Term Bit
b Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O, Term Bit
s Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O, Term Bit
carryOut Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I]
, [Term Bit
b Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I, Term Bit
s Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I, Term Bit
carryOut Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I]
]
]
]
fullNAddero :: Term Bit -> Term Binary -> Term Binary -> Term Binary -> Goal ()
fullNAddero :: Term Bit -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
fullNAddero Term Bit
carryIn Term [Bit]
a Term [Bit]
b Term [Bit]
r =
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term Bit
carryIn Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O
Term [Bit] -> Goal ()
zeroo Term [Bit]
b
Term [Bit]
a Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Term [Bit]
r
, do
Term Bit
carryIn Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O
Term [Bit] -> Goal ()
zeroo Term [Bit]
a
Term [Bit]
b Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Term [Bit]
r
Term [Bit] -> Goal ()
poso Term [Bit]
b
, do
Term Bit
carryIn Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I
Term [Bit] -> Goal ()
zeroo Term [Bit]
b
Term Bit -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
fullNAddero (Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O) Term [Bit]
a ([Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1) Term [Bit]
r
, do
Term Bit
carryIn Term Bit -> Term Bit -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
I
Term [Bit] -> Goal ()
zeroo Term [Bit]
a
Term [Bit] -> Goal ()
poso Term [Bit]
b
Term Bit -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
fullNAddero (Logic Bit -> Term Bit
forall a. Logic a -> Term a
Value Logic Bit
Bit
O) ([Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1) Term [Bit]
b Term [Bit]
r
, do
Term [Bit]
a Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
Term [Bit]
b Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
(d, c) <- Goal (Term Bit, Term Bit)
forall v. Fresh v => Goal v
fresh
r === Value (LogicCons d (Value (LogicCons c (Value LogicNil))))
full1Addero carryIn (Value I) (Value I) d c
, do
Term [Bit]
a Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
Term Bit -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
genFullNAddero Term Bit
carryIn Term [Bit]
a Term [Bit]
b Term [Bit]
r
, do
Term [Bit]
b Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
Term [Bit] -> Goal ()
gtlo Term [Bit]
a
Term [Bit] -> Goal ()
gtlo Term [Bit]
r
Term Bit -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
fullNAddero Term Bit
carryIn ([Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1) Term [Bit]
a Term [Bit]
r
, do
Term [Bit] -> Goal ()
gtlo Term [Bit]
a
Term Bit -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
genFullNAddero Term Bit
carryIn Term [Bit]
a Term [Bit]
b Term [Bit]
r
]
genFullNAddero :: Term Bit -> Term Binary -> Term Binary -> Term Binary -> Goal ()
genFullNAddero :: Term Bit -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
genFullNAddero Term Bit
carryIn Term [Bit]
n Term [Bit]
m Term [Bit]
r = do
(a, b, c, e, x, (y, z)) <- Goal
(Term Bit, Term Bit, Term Bit, Term Bit, Term [Bit],
(Term [Bit], Term [Bit]))
forall v. Fresh v => Goal v
fresh
n === Value (LogicCons a x)
m === Value (LogicCons b y)
poso y
r === Value (LogicCons c z)
poso z
full1Addero carryIn a b c e
fullNAddero e x y z
addo
:: Term Binary
-> Term Binary
-> Term Binary
-> Goal ()
addo :: Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
addo = Term Bit -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
fullNAddero (Bit -> Term Bit
forall a. Logical a => a -> Term a
inject' Bit
O)
subo
:: Term Binary
-> Term Binary
-> Term Binary
-> Goal ()
subo :: Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
subo Term [Bit]
a Term [Bit]
b Term [Bit]
c = Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
addo Term [Bit]
b Term [Bit]
c Term [Bit]
a
lesso
:: Term Binary
-> Term Binary
-> Goal ()
lesso :: Term [Bit] -> Term [Bit] -> Goal ()
lesso Term [Bit]
a Term [Bit]
b =
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term [Bit] -> Term [Bit] -> Goal ()
lesslo Term [Bit]
a Term [Bit]
b
, do
Term [Bit] -> Term [Bit] -> Goal ()
samelo Term [Bit]
a Term [Bit]
b
x <- Goal (Term [Bit])
forall v. Fresh v => Goal v
fresh
poso x
addo a x b
]
mulo
:: Term Binary
-> Term Binary
-> Term Binary
-> Goal ()
mulo :: Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
mulo Term [Bit]
a Term [Bit]
b Term [Bit]
c =
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term [Bit] -> Goal ()
zeroo Term [Bit]
a
Term [Bit] -> Goal ()
zeroo Term [Bit]
c
, do
Term [Bit] -> Goal ()
poso Term [Bit]
a
Term [Bit] -> Goal ()
zeroo Term [Bit]
b
Term [Bit] -> Goal ()
zeroo Term [Bit]
c
, do
Term [Bit]
a Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
Term [Bit] -> Goal ()
poso Term [Bit]
b
Term [Bit]
b Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Term [Bit]
c
, do
Term [Bit] -> Goal ()
gtlo Term [Bit]
a
Term [Bit]
b Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
Term [Bit]
a Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Term [Bit]
c
, do
(x, z) <- Goal (Term [Bit], Term [Bit])
forall v. Fresh v => Goal v
fresh
a === Value (LogicCons (Value O) x)
poso x
c === Value (LogicCons (Value O) z)
poso z
gtlo b
mulo x b z
, do
(x, y) <- Goal (Term [Bit], Term [Bit])
forall v. Fresh v => Goal v
fresh
a === Value (LogicCons (Value I) x)
poso x
b === Value (LogicCons (Value O) y)
poso y
mulo b a c
, do
(x, y) <- Goal (Term [Bit], Term [Bit])
forall v. Fresh v => Goal v
fresh
a === Value (LogicCons (Value I) x)
poso x
b === Value (LogicCons (Value I) y)
poso y
q <- fresh
lessl3o q c a b
mulo x b q
addo (Value (LogicCons (Value O) q)) b c
]
divo
:: Term Binary
-> Term Binary
-> Term Binary
-> Term Binary
-> Goal ()
divo :: Term [Bit] -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
divo Term [Bit]
n Term [Bit]
m Term [Bit]
q Term [Bit]
r =
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term [Bit]
n Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Term [Bit]
r
Term [Bit] -> Goal ()
zeroo Term [Bit]
q
Term [Bit] -> Term [Bit] -> Goal ()
lesso Term [Bit]
n Term [Bit]
m
, do
Term [Bit]
q Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
Term [Bit] -> Term [Bit] -> Goal ()
samelo Term [Bit]
n Term [Bit]
m
Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
addo Term [Bit]
r Term [Bit]
m Term [Bit]
n
Term [Bit] -> Term [Bit] -> Goal ()
lesso Term [Bit]
r Term [Bit]
m
, do
Term [Bit] -> Term [Bit] -> Goal ()
lesslo Term [Bit]
m Term [Bit]
n
Term [Bit] -> Term [Bit] -> Goal ()
lesso Term [Bit]
r Term [Bit]
m
Term [Bit] -> Goal ()
poso Term [Bit]
q
(n1, n2, q1, q2, q2m, (q2mr, rr, r1)) <- Goal
(Term [Bit], Term [Bit], Term [Bit], Term [Bit], Term [Bit],
(Term [Bit], Term [Bit], Term [Bit]))
forall v. Fresh v => Goal v
fresh
splito n r n1 n2
splito q r q1 q2
disjMany
[ do
zeroo n1
zeroo q1
subo n2 r q2m
mulo q2 m q2m
, do
poso n1
mulo q2 m q2m
addo q2m r q2mr
subo q2mr n2 rr
splito rr r r1 (inject' 0)
divo n1 m q1 r1
]
]
splito :: Term Binary -> Term Binary -> Term Binary -> Term Binary -> Goal ()
splito :: Term [Bit] -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
splito Term [Bit]
n Term [Bit]
r Term [Bit]
n1 Term [Bit]
n2 =
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term [Bit] -> Goal ()
zeroo Term [Bit]
n
Term [Bit] -> Goal ()
zeroo Term [Bit]
n1
Term [Bit] -> Goal ()
zeroo Term [Bit]
n2
, do
(b, n') <- Goal (Term Bit, Term [Bit])
forall v. Fresh v => Goal v
fresh
n === Value (LogicCons (Value O) (Value (LogicCons b n')))
zeroo r
n1 === Value (LogicCons b n')
zeroo n2
, do
n' <- Goal (Term [Bit])
forall v. Fresh v => Goal v
fresh
n === Value (LogicCons (Value I) n')
zeroo r
n1 === n'
n2 === inject' 1
, do
(b, n', a, r') <- Goal (Term Bit, Term [Bit], Term Bit, Term [Bit])
forall v. Fresh v => Goal v
fresh
n === Value (LogicCons (Value O) (Value (LogicCons b n')))
r === Value (LogicCons a r')
zeroo n2
splito (Value (LogicCons b n')) r' n1 (inject' 0)
, do
(n', a, r') <- Goal (Term [Bit], Term Bit, Term [Bit])
forall v. Fresh v => Goal v
fresh
n === Value (LogicCons (Value I) n')
r === Value (LogicCons a r')
n2 === inject' 1
splito n' r' n1 (inject' 0)
, do
(b, n', a, r', n2') <- Goal (Term Bit, Term [Bit], Term Bit, Term [Bit], Term [Bit])
forall v. Fresh v => Goal v
fresh
n === Value (LogicCons b n')
r === Value (LogicCons a r')
n2 === Value (LogicCons b n2')
poso n2'
splito n' r' n1 n2'
]
exp2o :: Term Binary -> Term Binary -> Term Binary -> Goal ()
exp2o :: Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
exp2o Term [Bit]
n Term [Bit]
b Term [Bit]
q =
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term [Bit]
n Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
Term [Bit] -> Goal ()
zeroo Term [Bit]
q
, do
Term [Bit] -> Goal ()
gtlo Term [Bit]
n
Term [Bit]
q Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
_n2 <- Goal (Term [Bit])
forall v. Fresh v => Goal v
fresh
splito n b (inject' 1) _n2
, do
(q1, b2) <- Goal (Term [Bit], Term [Bit])
forall v. Fresh v => Goal v
fresh
q === Value (LogicCons (Value O) q1)
poso q1
lesslo b n
appendo b (Value (LogicCons (Value I) b)) b2
exp2o n b2 q1
, do
(q1, n1, b2, _n2) <- Goal (Term [Bit], Term [Bit], Term [Bit], Term [Bit])
forall v. Fresh v => Goal v
fresh
q === Value (LogicCons (Value I) q1)
poso q1
poso n1
splito n b n1 _n2
appendo b (Value (LogicCons (Value I) b)) b2
exp2o n1 b2 q1
]
repeatedMulo :: Term Binary -> Term Binary -> Term Binary -> Goal ()
repeatedMulo :: Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
repeatedMulo Term [Bit]
n Term [Bit]
q Term [Bit]
nq =
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term [Bit] -> Goal ()
poso Term [Bit]
n
Term [Bit] -> Goal ()
zeroo Term [Bit]
q
Term [Bit]
nq Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
, do
Term [Bit]
q Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
Term [Bit]
n Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Term [Bit]
nq
, do
Term [Bit] -> Goal ()
gtlo Term [Bit]
q
(q1, nq1) <- Goal (Term [Bit], Term [Bit])
forall v. Fresh v => Goal v
fresh
addo q1 (inject' 1) q
repeatedMulo n q1 nq1
mulo nq1 n nq
]
logo
:: Term Binary
-> Term Binary
-> Term Binary
-> Term Binary
-> Goal ()
logo :: Term [Bit] -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
logo Term [Bit]
n Term [Bit]
b Term [Bit]
q Term [Bit]
r =
[Goal ()] -> Goal ()
forall x. [Goal x] -> Goal x
disjMany
[ do
Term [Bit]
n Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
Term [Bit] -> Goal ()
poso Term [Bit]
b
Term [Bit] -> Goal ()
zeroo Term [Bit]
q
Term [Bit] -> Goal ()
zeroo Term [Bit]
r
, do
Term [Bit] -> Goal ()
zeroo Term [Bit]
q
Term [Bit] -> Term [Bit] -> Goal ()
lesso Term [Bit]
n Term [Bit]
b
Term [Bit] -> Goal ()
poso Term [Bit]
r
Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
addo Term [Bit]
r ([Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1) Term [Bit]
n
, do
Term [Bit]
q Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
Term [Bit] -> Goal ()
gtlo Term [Bit]
b
Term [Bit] -> Term [Bit] -> Goal ()
samelo Term [Bit]
n Term [Bit]
b
Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
addo Term [Bit]
r Term [Bit]
b Term [Bit]
n
, do
Term [Bit]
b Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1
Term [Bit] -> Goal ()
poso Term [Bit]
q
Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
addo Term [Bit]
r ([Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
1) Term [Bit]
n
, do
Term [Bit] -> Goal ()
zeroo Term [Bit]
b
Term [Bit] -> Goal ()
poso Term [Bit]
q
Term [Bit]
n Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== Term [Bit]
r
, do
Term [Bit]
b Term [Bit] -> Term [Bit] -> Goal ()
forall a. Logical a => Term a -> Term a -> Goal ()
=== [Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
2
(_b1, _b2, n1) <- Goal (Term Bit, Term Bit, Term [Bit])
forall v. Fresh v => Goal v
fresh
poso n1
n === Value (LogicCons _b1 (Value (LogicCons _b2 n1)))
exp2o n (inject' 0) q
_r1 <- fresh
splito n n1 _r1 r
, do
(b1, b2, b3, br) <- Goal (Term Bit, Term Bit, Term Bit, Term [Bit])
forall v. Fresh v => Goal v
fresh
disjMany
[ b === inject' 3
, b === Value (LogicCons b1 (Value (LogicCons b2 (Value (LogicCons b3 br)))))
]
lesslo b n
(bw1, bw, nw1, nw, ql, (ql1, _r)) <- fresh
exp2o b (inject' 0) bw1
addo bw1 (inject' 1) bw
lesslo q n
(q1, bwq1) <- fresh
addo q (inject' 1) q1
mulo bw q1 bwq1
lesso nw1 bwq1
exp2o n (inject' 0) nw1
addo nw1 (inject' 1) nw
divo nw bw ql1 _r
addo ql (inject' 1) ql1
disjMany [samelo q ql, lesslo ql q]
(bql, qh, _r', qdh, qd) <- fresh
repeatedMulo b ql bql
divo nw bw1 qh _r'
addo ql qdh qh
addo ql qd q
disjMany [qd === qdh, lesso qd qdh]
(bqd, bq, bq1) <- fresh
repeatedMulo b qd bqd
mulo bql bqd bq
mulo b bq bq1
addo bq r n
lesso n bq1
]
example :: IO ()
example :: IO ()
example = do
String -> IO ()
putStrLn String
"addo 3 5 x:"
(Maybe [Bit] -> IO ()) -> [Maybe [Bit]] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Maybe [Bit] -> IO ()
forall a. Show a => a -> IO ()
print ([Maybe [Bit]] -> IO ()) -> [Maybe [Bit]] -> IO ()
forall a b. (a -> b) -> a -> b
$ Term [Bit] -> Maybe [Bit]
forall a. Logical a => Term a -> Maybe a
extract' (Term [Bit] -> Maybe [Bit]) -> [Term [Bit]] -> [Maybe [Bit]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Term [Bit] -> Goal ()) -> [Term [Bit]]
forall v. Fresh v => (v -> Goal ()) -> [v]
run (Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
addo ([Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
3) ([Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
5))
String -> IO ()
putStrLn String
"\nmulo 3 4 x:"
(Maybe [Bit] -> IO ()) -> [Maybe [Bit]] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Maybe [Bit] -> IO ()
forall a. Show a => a -> IO ()
print ([Maybe [Bit]] -> IO ()) -> [Maybe [Bit]] -> IO ()
forall a b. (a -> b) -> a -> b
$ Term [Bit] -> Maybe [Bit]
forall a. Logical a => Term a -> Maybe a
extract' (Term [Bit] -> Maybe [Bit]) -> [Term [Bit]] -> [Maybe [Bit]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Term [Bit] -> Goal ()) -> [Term [Bit]]
forall v. Fresh v => (v -> Goal ()) -> [v]
run (Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
mulo ([Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
3) ([Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
4))
String -> IO ()
putStrLn String
"\ndivo 15 4 q r:"
((Maybe [Bit], Maybe [Bit]) -> IO ())
-> [(Maybe [Bit], Maybe [Bit])] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Maybe [Bit], Maybe [Bit]) -> IO ()
forall a. Show a => a -> IO ()
print ([(Maybe [Bit], Maybe [Bit])] -> IO ())
-> [(Maybe [Bit], Maybe [Bit])] -> IO ()
forall a b. (a -> b) -> a -> b
$ (Term [Bit] -> Maybe [Bit])
-> (Term [Bit] -> Maybe [Bit])
-> (Term [Bit], Term [Bit])
-> (Maybe [Bit], Maybe [Bit])
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap Term [Bit] -> Maybe [Bit]
forall a. Logical a => Term a -> Maybe a
extract' Term [Bit] -> Maybe [Bit]
forall a. Logical a => Term a -> Maybe a
extract' ((Term [Bit], Term [Bit]) -> (Maybe [Bit], Maybe [Bit]))
-> [(Term [Bit], Term [Bit])] -> [(Maybe [Bit], Maybe [Bit])]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Term [Bit], Term [Bit]) -> Goal ()) -> [(Term [Bit], Term [Bit])]
forall v. Fresh v => (v -> Goal ()) -> [v]
run ((Term [Bit] -> Term [Bit] -> Goal ())
-> (Term [Bit], Term [Bit]) -> Goal ()
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (Term [Bit] -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
divo ([Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
15) ([Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
4)))
let exps :: [(Integer, Integer, [Term [Bit]])]
exps =
[ (Integer
b, Integer
p, (Term [Bit] -> Goal ()) -> [Term [Bit]]
forall v. Fresh v => (v -> Goal ()) -> [v]
run (\Term [Bit]
n -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Term [Bit] -> Goal ()
logo Term [Bit]
n ([Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' (Integer -> [Bit]
forall a. Num a => Integer -> a
fromInteger Integer
b)) ([Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' (Integer -> [Bit]
forall a. Num a => Integer -> a
fromInteger Integer
p)) ([Bit] -> Term [Bit]
forall a. Logical a => a -> Term a
inject' [Bit]
0)))
| Integer
b <- [Integer
1 .. Integer
3]
, Integer
p <- [Integer
1 .. Integer
6]
]
((Integer, Integer, [Term [Bit]]) -> IO ())
-> [(Integer, Integer, [Term [Bit]])] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_
( \(Integer
b, Integer
p, [Term [Bit]]
bp) -> do
String -> IO ()
putStrLn (String
"\nlogo n " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Integer -> String
forall a. Show a => a -> String
show Integer
b String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Integer -> String
forall a. Show a => a -> String
show Integer
p String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" 0:")
(Maybe [Bit] -> IO ()) -> [Maybe [Bit]] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Maybe [Bit] -> IO ()
forall a. Show a => a -> IO ()
print (Term [Bit] -> Maybe [Bit]
forall a. Logical a => Term a -> Maybe a
extract' (Term [Bit] -> Maybe [Bit]) -> [Term [Bit]] -> [Maybe [Bit]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Term [Bit]]
bp)
)
[(Integer, Integer, [Term [Bit]])]
exps