use list comprehensions for creating the following sets in haskell
- $A = \{ x \,:\, x \in \mathbb{N},\, x \text{ odd}\}$ (only showing the first 5 elements)
- $B = \{ -x \,:\, x \in \mathbb{N},\, 3|x ,\, x < 10\}$ ($3|x$ : 3 is a divisor of x)
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 4
Create the set of all odd numbers smaller than 500, which are dividable through 5 and 7.
$S=\{x : x \neq 0 \land 5|x \land 7|x\}$
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
#problem 5
# problem 5
Let $A=\{1,2,3\}$, $B=\{3,4,5\}$. Calculate the intersection and the union of $A$ and $B$.
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 6
let `lesser` and `greater` be functions which have a value `v` and a list of values `l` of the same type as `v`. return a list of all values which are lesser or greater as `v`.
Let `less` and `greater` be functions which have a value `v` and a list of values `l` of the same type as `v`. Return a list of all values which are less or greater as `v`.
$\text{lesser}(v,l) = \{x : x \in l, x < v\}$
$\text{less}(v,l) = \{x : x \in l, x < v\}$
do the implementation with list comprehensions.
Implement the functions using list comprehensions.
Test: `5 [1..10]`
%% Cell type:code id: tags:
``` haskell
```
%% Cell type:markdown id: tags:
## problem 7
the list generated with `[0.1,0.3..0.9]` has problems with precision (has roundingerror). Do it better via using list comprehensions. (Tip: ranges of integral types do not have rounding errors).
and then create an `aLPHABET` with upper case characters and add it to the existing one
%% Cell type:code id: tags:
``` haskell
alphabet=['a'..'z']
aLPHABET=['A'..'Z']
lengthalphabet
take3alphabet
alphabet!!12
take(10-7)$drop6alphabet
reverse$take5$reversealphabet
alphabet++aLPHABET
```
%% Cell type:markdown id: tags:
## problem 2
implement a function `hasVocal` which checks if a string contains a vocal character. Test the function with "foo", "bar" and "bz".
implement a function `hasVowel` which checks if a string contains a vowel character. Test the function with "foo", "bar" and "bz".
%% Cell type:code id: tags:
``` haskell
-- simple
hatVokalx=elem'a'x||elem'e'x||elem'i'x||elem'o'x||elem'u'x||elem'A'x||elem'E'x||elem'I'x||elem'O'x||elem'U'x--nicht so gut
hasVowelx=elem'a'x||elem'e'x||elem'i'x||elem'o'x||elem'u'x||elem'A'x||elem'E'x||elem'I'x||elem'O'x||elem'U'x--nicht so gut
-- better :
hatVokalx=maximum[elemvokalx|vokal<-"aeiouAEIOU"]
hasVowelx=maximum[elemvokalx|vokal<-"aeiouAEIOU"]
hatVokal"foo"
hatVokal"bar"
hatVokal"bz"
hasVowel"foo"
hasVowel"bar"
hasVowel"bz"
```
%%%% Output: display_data
%%%% Output: display_data
%%%% Output: display_data
%% Cell type:markdown id: tags:
## problem 3
use list comprehensions for creating the following sets in haskell
- $A = \{ x \,:\, x \in \mathbb{N},\, x \text{ odd}\}$ (only showing the first 5 elements)
- $B = \{ -x \,:\, x \in \mathbb{N},\, 3|x ,\, x < 10\}$ ($3|x$ : 3 is a divisor of x)
%% Cell type:code id: tags:
``` haskell
take5[x|x<-[1..],oddx]
take5[1,3..]
[negatex|x<-[1..10],x`mod`3==0]
```
%% Cell type:markdown id: tags:
## problem 4
Create the set of all odd numbers smaller than 500, which are dividable through 5 and 7.
$S=\{x : x \neq 0 \land 5|x \land 7|x\}$
%% Cell type:code id: tags:
``` haskell
[a|a<-[1,3..500],moda5==0,moda7==0]
```
%% Cell type:markdown id: tags:
#problem 5
# problem 5
Let $A=\{1,2,3\}$, $B=\{3,4,5\}$. Calculate the intersection and the union of $A$ and $B$.
%% Cell type:code id: tags:
``` haskell
a=[1,2,3]
b=[3,4,5]
[x|x<-a,x`elem`b]
a++[x|x<-b,x`notElem`a]
```
%% Cell type:markdown id: tags:
## problem 6
let `lesser` and `greater` be functions which have a value `v` and a list of values `l` of the same type as `v`. return a list of all values which are lesser or greater as `v`.
Let `less` and `greater` be functions which have a value `v` and a list of values `l` of the same type as `v`. Return a list of all values which are less or greater as `v`.
$\text{lesser}(v,l) = \{x : x \in l, x < v\}$
$\text{less}(v,l) = \{x : x \in l, x < v\}$
do the implementation with list comprehensions.
Implement the functions using list comprehensions.
Test: `5 [1..10]`
%% Cell type:code id: tags:
``` haskell
greatercxs=[x|x<-xs,x>c]
lessercxs=[x|x<-xs,x<c]
lesscxs=[x|x<-xs,x<c]
lesser5[1..10]
less5[1..10]
greater5[1..10]
```
%%%% Output: display_data
%%%% Output: display_data
%% Cell type:markdown id: tags:
## problem 7
the list generated with `[0.1,0.3..0.9]` has problems with precision (has roundingerror). Do it better via using list comprehensions. (Tip: ranges of integral types do not have rounding errors).