De presentatie wordt gedownload. Even geduld aub

De presentatie wordt gedownload. Even geduld aub

Functies op Proposities evalueer:: Bedeling  Prop  Bool tautologie:: Prop  Bool contradictie:: Prop  Bool equivalentie:: Prop  Prop  Bool vervulbaar::

Verwante presentaties


Presentatie over: "Functies op Proposities evalueer:: Bedeling  Prop  Bool tautologie:: Prop  Bool contradictie:: Prop  Bool equivalentie:: Prop  Prop  Bool vervulbaar::"— Transcript van de presentatie:

1 Functies op Proposities evalueer:: Bedeling  Prop  Bool tautologie:: Prop  Bool contradictie:: Prop  Bool equivalentie:: Prop  Prop  Bool vervulbaar:: Prop  [Bedeling] eenvoudig:: Prop  Prop normaalvorm:: Prop  Prop toon:: Prop  String ontleed:: String  Prop

2 Functies voor ontleden type Parser a= String  [(String,a)] symbol :: String  Parser String seq:: Parser a  Parser b  Parser (a,b) orelse :: Parser a  Parser a  Parser a haakjes :: Parser Tree data Expr = Con Int | Var String |.... expr, factor :: Parser Expr expr = foldr gen factor [addis, multis]

3 Vandaag nUitwerking proeftentamen tentamen is “open appendix D” ! nVergelijking

4 Vraag 1 nWat is het type van A.[Bool] B.[Int  Bool] C.[Int]  [Bool] D.typeringsfout filter div [1,2,3] filter:: ( a  Bool )  [a]  [a] div:: (Int  (Int  Int)) [1,2,3] :: [Int]

5 Vraag 2 nWat is niet equivalent aan A.all p = and. map p B.all p = and (map p) C.all p xs = (and. map p) xs D.all = \p xs  and (map ps xs) all p xs = and (map p xs)

6 Vraag 3 nWat is de waarde van A.[False, True, False, True] B.[12, 72] C.[True, False, True, False] D.[10, 4] filter ( (/=0). (\x  x`mod`3)) [12,10,72,4] [0, 1, 0, 1]  [ 10, 4 ]

7 Vraag 4 nWat is type van A.[Char]  [String] B.[String] C.[Char]  [Char] D.String map box “de zon schijnt” box :: Char  String

8 Vraag 5 nWat is de waarde van A.[3, 4, 2, 2, 3, 1] B.[0, 0, 0, 0, 0, 0] C.[3, 4, 2] D.[3, 2, 4, 3, 2, 1] [ div x y | x  [10,12,6], y  [3..4] div 10 3 div 10 4 div 12 3 div 12 4 div 6 3 div 6 4

9 Vraag 6 nWat is type van A.MyList Char B.Char  MyList Char C.a  MyList a D.typeringsfout Cons ’a’ data MyList a = Cons (MyList a) a | Nil

10 Vraag 7 nSchrijf vaakste :: [Int]  Int vaakste xs = where tel e =filter (==e) xslength ( ) map tel xsmaximum ( ) filter xs ((==m). tel)head ( ) m =

11 Vraag 8 nSchrijf elemBoom die kijkt of een waarde voorkomt in een zoekboom elemBoom :: a  (Boom a)  Bool data Boom a = Blad | Tak a (Boom a) (Boom a) (a  a  Ordering)  elemBoom cmp e Blad = elemBoom cmp e (Tax x li re) = False cmp e xf ( ) where f LT = f EQ = f GT = True elemBoom cmp e li elemBoom cmp e re

12 Vraag 9 nSchrijf length met behulp van foldr length ::[a]  Int length = foldr where op e op x r= e= 1 + r 0 length = foldr (\ x r  1+r) 0

13 Vraag 10 nSchrijf eval :: [(String,Int)]  Expr  Int data Expr = ConstInt | VarString | PlusExpr Expr | MaalExpr Expr eval t (Const i) = eval t (Var s) = eval t (Plus a b) = eval t (Maal a b) =

14 Functie-aanroep sqrt 2.0 sqrt (exp 1.0) (sqrt 2.0) (sqrt (exp 1.0))

15 Functies / operatoren f 1 2 1 + 2 x <= y x + y*z x * (y+z) a+b+c+d+e (f 1 2) (+ 1 2) (<= x y) (+ x (* y z)) (* x (+ y z)) (+ a b c d e)

16 Lijsten [1, 2, 3] [ ] length [1,2,3] 1:2:3:4:[] [1,2,3] ++ [4,5] ’ (1 2 3) ( ) (length ’(1 2 3)) (cons 1 (cons 2 (cons 3 (cons 4 ( ) ) ) ) ) (append ’(1 2 3) ’(4 5))

17 Functies definiëren kwadraat x = x * x (defun kwadraat (x) (* x x) ) boven n k = fac n / (fac k * fac (n-k)) (defun boven (n k) ( / (fac n) (* (fac k) (fac (- n k)))))

18 Gevalsonderscheid signum x | x < 0 = -1 | x==0= 0 | x > 0= 1 (defun signum (x) (cond ( (< x 0) -1) ( (==x 0) 0) ( (> x 0) 1))) lengte [ ] = 0 lengte (x:xs) = 1 + lengte xs (defun lengte (xs) (cond ( (null xs) 0) ( true (+ 1 (lengte (rest xs))))))

19 Oneindige lijsten repeat x = x : repeat x (defun repeat (x) (cons x (repeat x))) > repeat 3 [3,3,3,3,3,3,3,3,3,3,3 > (repeat 3) Stack overflow > head (repeat 3) 3 > (first (repeat 3)) Stack overflow lazy eager

20 Typering 1 <= ’a’(<= 1 ’a ) 2 <= 3 || 1 <= ’a’ (or (<= 2 3 ) (<= 1 ’a )) compile- fout runtime- fout OK ! typering beschermt programma programma kan verborgen fouten hebben

21 Typering van lijsten [1, 2, 3] (1, ”aap”) ’(1 2 3) ’(1 ”aap”) :: [Int] :: (Int,Str) [[1,2,3],[4,5]] ::[[Int]] :: list ’(’(1 2 3) ’(4 5)) :: list [ 1,[4,5] ] :: error ’( 1 ’(4 5)) :: list Tak 3 Blad Blad :: Boom Int ’( 3 ( ) ( ) ) :: list

22 Typering van lijsten zoek :: (a  a  Ord)  [(a,b)]  a  b zoek :: (function list atom)  atom

23 Vergelijking nHandige notaties (definitie, patroon, lijst) nSterk getypeerd, at compile-time nLijsten, tupels, bomen nLazy evaluatie nZuiver functioneel n Weinig notaties, veel haakjes n Zwak getypeerd, at run-time n Lijsten, lijsten, lijsten n Eager evaluatie n Side-effects

24 Vergelijking nProgramma: definitie van functies n Programma: definitie van relaties (oftewel predicaten ) drie x = 3drie (x, 3). f x = h (g x) f (x, z)  g (x, y)  h (y, z).

25 Lijsten [1, 2, 3] [5] [ ] [1, 2, 3] [5] [ ] ( x : xs )[ x | xs ] [ x:xs ][ [x|xs] ] =

26 Patronen append ([ ], ys, ). append ( [x|xs], ys, ) . ys [ ] ++ ys = ys (x:xs) ++ ys = x : (xs++ys) [x|zs] append (xs,ys,zs) tussenresultaten moeten een naam hebben

27 Patronen ins (x, [ ], ). ins (x, [y|ys], ) . [x] ins x [ ] = [ x ] ins x (y:ys) | x<y = x : y : ys | x>=y = y : ins x ys x<y [x|y|ys] ins (x, [y|ys], )  x>=y [y|zs]  ins (x,ys,zs).

28 Gebruik > [1,2] ++ [3,4] [1, 2, 3, 4] > app ([1,2],[3,4],Z). Z = [1, 2, 3, 4] > app (X, Y, [1,2,3]). X=[ ] Y=[1,2,3] X=[1] Y=[2,3] X=[1,2] Y=[3] X=[1,2,3] Y=[ ]

29 Vergelijking nDefinitie van functies nResultaat van functie gebruiken bij aanroep nParameter  resultaat n Definitie van relaties n Tussenresultaten een naam geven n Twee kanten op bruikbaar! eenrichtingverkeer

30


Download ppt "Functies op Proposities evalueer:: Bedeling  Prop  Bool tautologie:: Prop  Bool contradictie:: Prop  Bool equivalentie:: Prop  Prop  Bool vervulbaar::"

Verwante presentaties


Ads door Google