Ausdruck

Transcription

Ausdruck
Michael Stollberg
# 3449410 , Gruppe 26
Informatik A WS 99/00
Berlin, 24.11.1999
4. Übung
Aufgabe 1:
a)
Wenn gilt:
d ist gemeinsamer Teiler von a und b <=> d ist gemeinsamer Teiler von b und (a-b)
dann ist bewiesen, daß ggT(a,b) = ggT(a-b,b)
Also:
d teilt a
a = q1 * d + r1
a = q1 * d
d = a / q1
^
^
^
^
d teilt b
b = q2 * d + r2
b = q2 * d
d = b / q2
<=> d teilt b
<=> b = q2 * d + r2
<=> b = q2 * d
<=> d = b / q2
^
^
^
^
da die Reste r1 gleich sind, gilt die gestellte Bedingung der Äquivalenz.
b)
{- Haskell Algorithmus für ggT(a,b) -}
ggTantieffektiv:: Int-> Int->Int
ggTantieffektiv a b
| abs a < abs b = ggTantieffektiv b a
| b == 0
=a
| otherwise
= ggTantieffektiv (a-b) b
c)
Beispiele mit Aufruf-Unterschied 2:
a=5 , b=2 ; a=3, b=2 ; etc.
mehr als 100-fache Effizienz der VL-Variante:
a= 333 , b = 3 [hier muß ggTantieffektiv 110 mal substrahieren !!]
Aufgabe 2
a)
{- Funktion zur Prüfung, ob Punkt (px,py) auf der Geraden g: y = a *x +b liegt -}
pol::Float-> Float-> Float-> Float-> Bool
pol a b px py
| (a * px + b) == py
= True
| otherwise
= False
{- Funktion zur Prüfung, ob Punkt (px,py) über Gerade liegt -}
pal:: Float-> Float-> Float-> Float-> Bool
pal a b px py
| (a * px + b) < py
= True
| otherwise
= False
d teilt (a-b)
(a-b) = q3 * d + r1
(a-b) = q3 * d
d = (a-b) / q3
b)
{- Funktion zur Bestimmung von c mit g: y = a * x + c , Gerade parallel zu der aus a) -}
c:: Float-> Float-> Float-> Float-> Float
c a b px py = py – a* px
c)
{- Funktion zur Berechnung des Geradenschnittpunktes von g1: y = ax + b ; g2: y = cx + d -}
sp:: Float-> Float-> Float-> Float->Float
sp a b c d
| ((c==a) && (b==d)) == True
| ((c==a) && (b/=d)) == True
| otherwise
= error ´´kein eindeutiger Schnittpunkt´´
= error ´´ kein Schnittpunkt´´
= (d-b) / (a-c)
Aufgabe 3
a)
{- Funktion isTriangle bestimmt, ob ein Dreieck mit gegebenen Seitenwerten existiert -}
isTriangle::Float->Float->Float->Bool
isTriangle a b c
| (a+b > c) || (b+c > a) || (a+c > b)
| otherwise
= True
= False
b)
{- gleiche Funktion unter Verwendung von treeMax und ohne Boolsche Operatoren -}
threeMax:: Float->Float->Float->Float
threeMax a b c
| (a >= b) && (a >= c)
=a
| b >= c
=b
| otherwise
=c
threeMid:: Float->Float->Float->Float
threeMid a b c
| ( (a <= b) && (a >= c) ) || ((a >= b) && (a <= c)) = a
| ( (b <= a) && (b >= c) ) || ((b >= a) && (b <= c)) = b
| ( (c <= b) && (c >= a) ) || ((c >= b) && (c <= a)) = c
threeMin::Float->Float->Float->Float
threeMin a b c
| (a <= b) && (a <= c)
=a
| b <= c
=b
| otherwise
=c
isDreieck:: Float->Float->Float-> Bool
isDreieck a b c
| (threeMax a b c > = (threeMid a b c + threeMin a b c))
| otherwise
== True
= True
= False

Documents pareils