Commit 8e3ad8de authored by Michael Hanus 's avatar Michael Hanus
Browse files

Some examples updates

parent affc40f7
......@@ -39,10 +39,10 @@ Loading program "family_fun"...
{child=Susan} success
{child=Peter} success
grandfather g c
{g=Antony, c=Susan} success
{g=Antony, c=Peter} success
{g=Bill, c=Andrew} success
{g=Antony, c=Andrew} success
{g=Antony, c=Susan} True
{g=Antony, c=Peter} True
{g=Bill, c=Andrew} True
{g=Antony, c=Andrew} True
Loading program "horseman"...
horseman m h (int2nat 8) (int2nat 20)
{m=S (S (S (S (S (S O))))), h=S (S O)} success
......@@ -169,7 +169,7 @@ Loading program "maxtree"...
goal2
Node (Node (Leaf 3) (Leaf 3)) (Node (Leaf 3) (Leaf 3))
Loading program "assembler"...
goal
main
[9,4,9,0]
Loading program "ralign"...
goal1
......
......@@ -39,10 +39,10 @@ Loading program "family_fun"...
{child=Susan} success
{child=Peter} success
grandfather g c
{g=Antony, c=Susan} success
{g=Antony, c=Peter} success
{g=Bill, c=Andrew} success
{g=Antony, c=Andrew} success
{g=Antony, c=Susan} True
{g=Antony, c=Peter} True
{g=Bill, c=Andrew} True
{g=Antony, c=Andrew} True
Loading program "horseman"...
horseman m h (int2nat 8) (int2nat 20)
{m=S (S (S (S (S (S O))))), h=S (S O)} success
......@@ -169,7 +169,7 @@ Loading program "maxtree"...
goal2
Node (Node (Leaf 3) (Leaf 3)) (Node (Leaf 3) (Leaf 3))
Loading program "assembler"...
goal
main
[9,4,9,0]
Loading program "ralign"...
goal1
......@@ -188,22 +188,22 @@ Ihr Name?
Hallo michael, rueckwaerts lautet Ihr Name: leahcim
Loading program "england"...
q1 x
{x=Gloucester} success
{x=Bath} success
{x=Gloucester} True
{x=Bath} True
q2 x y
{x=Bristol, y=Bath} success
{x=Sherbourne, y=Shaftesbury} success
{x=Dorchester, y=Sherbourne} success
{x=Cirencester, y=Cheltenham} success
{x=Cheltenham, y=Gloucester} success
{x=Bristol, y=Bath} True
{x=Sherbourne, y=Shaftesbury} True
{x=Dorchester, y=Sherbourne} True
{x=Cirencester, y=Cheltenham} True
{x=Cheltenham, y=Gloucester} True
q4l
[Bristol,Taunton,Bath,Bournemouth,Gloucester,Torquay,Penzance,Plymouth,Exeter,Winchester,Dorchester,Cirencester,Truro,Cheltenham,Shaftesbury,Sherbourne]
q5l
[Salisbury,Gloucester,Cirencester,Cheltenham]
q7 x
{x=Somerset} success
{x=Gloucestershire} success
{x=Avon} success
{x=Somerset} True
{x=Gloucestershire} True
{x=Avon} True
q10
6
Loading program "queens"...
......
......@@ -14,19 +14,18 @@ data LabelId = L0 | L1 | L2 | L3 | L4 | L5 | L6 | L7 | L8 | L9
type SymTab = [(LabelId,Int)]
assembler :: [Instruction] -> SymTab -> Int -> [Int]
assembler [] _ _ = []
assembler [] _ _ = []
assembler (Jump l : ins) st a
| lookupST l st label st1 = 9:label:assembler ins st1 (a+2)
| lookupST l st label st1 = 9:label:assembler ins st1 (a+2)
where label,st1 free
assembler (Label l : ins) st a
| st1 =:= insertST l a st = assembler ins st1 a
| st1 == insertST l a st = assembler ins st1 a
where st1 free
-- insert an address of a labelid in a symboltable:
insertST l a [] = [(l,a)]
insertST l a ((l1,a1):st) | (l==l1)=:=True & a=:=a1 = (l1,a1):st
insertST l a ((l1,a1):st) | (l==l1)=:=False = (l1,a1):(insertST l a st)
insertST l a ((l1,a1):st) | l==l1 && a==a1 = (l1,a1) : st
insertST l a ((l1,a1):st) | l/=l1 = (l1,a1) : (insertST l a st)
-- lookup an address of a labelid in a symboltable:
lookupST l [] a st1 = st1=:=[(l,a)]
......@@ -35,8 +34,8 @@ lookupST l ((l1,a1):st) a st1 =
else let st2 free in lookupST l st a st2 & st1=:=(l1,a1):st2
-- Goal:
-- Example evaluation:
goal = assembler [Label L0, Jump L1, Jump L0, Label L1] [] 0
main = assembler [Label L0, Jump L1, Jump L0, Label L1] [] 0
-----> Result: [9,4,9,0]
-- graph coloring with non-deterministic functions
-- exploiting the demand-driven search due to lazy evaluation in Curry
-- auxiliary function:
-- negation of ==:
diff x y = (x == y) =:= False
-- This is our actual map:
--
-- --------------------------
......@@ -29,8 +23,8 @@ aColor = Blue
-- correct coloring:
correct l1 l2 l3 l4
| diff l1 l2 & diff l1 l3 & diff l2 l3 & diff l2 l4 & diff l3 l4
| l1/=l2 && l1/=l3 && l2/=l3 && l2/=l4 && l3/=l4
= [l1,l2,l3,l4]
-- solution:
goal = correct aColor aColor aColor aColor
main = correct aColor aColor aColor aColor
......@@ -30,19 +30,19 @@ mother Andrew = Alice
father c = husband (mother c)
grandfather g c = g =:= father (father c)
grandfather g c = g =:= father (mother c)
grandfather g c | g == father (father c) = True
grandfather g c | g == father (mother c) = True
-- A is ancestor of P:
ancestor a p = a =:= father p
ancestor a p = a =:= mother p
ancestor a p = let p1 free in a =:= father p1 & ancestor p1 p
ancestor a p = let p1 free in a =:= mother p1 & ancestor p1 p
ancestor a p | a == father p = True
ancestor a p | a == mother p = True
ancestor a p | a == father p1 && ancestor p1 p = True where p1 free
ancestor a p | a == mother p1 && ancestor p1 p = True where p1 free
-- Example goals:
goal1 = father Peter
goal2 child = father child =:= John
goal2 child = solve $ father child == John
goal3 g c = grandfather g c
goal4 a = ancestor a Andrew
goal5 a p = ancestor a p
......
......@@ -43,11 +43,11 @@ mother Monica Peter = True
mother Alice Andrew = True
father f c | let m free in (married m f && mother m c) =:= True = True
father f c | married m f && mother m c = True where m free
grandfather g c | let f free in (father g f && father f c) =:= True = True
grandfather g c | let m free in (father g m && mother m c) =:= True = True
grandfather g c | father g f && father f c = True where f free
grandfather g c | father g m && mother m c = True where m free
-- goals:
......
......@@ -4,7 +4,7 @@ append [] ys = ys
append (x:xs) ys = x : append xs ys
last xs | append _ [x] =:= xs
last xs | append _ [x] == xs
= x where x free
......
......@@ -5,9 +5,8 @@ g _ (x:_) = x
h x = h x
-- the following goal does not terminate in Haskell,
-- but terminates in Curry (with optmatch option)
-- since the program is inductively sequential.
-- It terminates also in Haskell if the two rules for g are swapped
-- The following expression does not terminate in Haskell,
-- but terminates in Curry since the program is inductively sequential.
-- It terminates also in Haskell if the two rules for g are swapped.
goal = g (h 0) [1]
main = g (h 0) [1]
......@@ -6,7 +6,7 @@ import SetFunctions
queens x | y==permute x && isEmpty (set2 capture x y) = y where y free
permute [] = []
permute (x:xs) | u ++ v =:= permute xs = u ++ [x] ++ v
permute (x:xs) | u ++ v == permute xs = u ++ [x] ++ v
where u,v free
capture x y
......
......@@ -47,7 +47,7 @@ goal3 s where s free
:l maxtree
goal2
:l assembler
goal
main
:l ralign
goal1
goal2
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment