summaryrefslogtreecommitdiffstats
path: root/AufgabeFFP6.hs
diff options
context:
space:
mode:
Diffstat (limited to 'AufgabeFFP6.hs')
-rw-r--r--AufgabeFFP6.hs4
1 files changed, 4 insertions, 0 deletions
diff --git a/AufgabeFFP6.hs b/AufgabeFFP6.hs
index 1fde756..c60053d 100644
--- a/AufgabeFFP6.hs
+++ b/AufgabeFFP6.hs
@@ -91,22 +91,26 @@ yield_bt f w = map (\(_, _, _, g) -> listArray (1, length g) g) nodes
91yield_gtf :: F -> W -> [G] 91yield_gtf :: F -> W -> [G]
92yield_gtf = filt . transform . generate 92yield_gtf = filt . transform . generate
93 93
94-- produce [G] by using get_combinations
94generate :: F -> W -> (F, W, [G]) 95generate :: F -> W -> (F, W, [G])
95generate f w = (f, w, [ array (1,n) entries | entries <- get_combinations n ] ) 96generate f w = (f, w, [ array (1,n) entries | entries <- get_combinations n ] )
96 where 97 where
97 n = (snd $ bounds f) - 1 98 n = (snd $ bounds f) - 1
98 99
100-- provide all selections of length n, work recursively and attach index for level (convenient for creating arrays)
99get_combinations :: Int -> [[(Int, Op)]] 101get_combinations :: Int -> [[(Int, Op)]]
100get_combinations 1 = [[(1,(+))], [(1, (-))], [(1, (*))], [(1,(./.))]] 102get_combinations 1 = [[(1,(+))], [(1, (-))], [(1, (*))], [(1,(./.))]]
101get_combinations n = [ (up i) ++ entr | entr <- get_combinations (n-1), i <- get_combinations 1 ] 103get_combinations n = [ (up i) ++ entr | entr <- get_combinations (n-1), i <- get_combinations 1 ]
102 where 104 where
103 up = map (\(num, x) -> ((num+n-1), x)) 105 up = map (\(num, x) -> ((num+n-1), x))
104 106
107-- attaches a list of results
105transform :: (W -> (F,W,[G])) -> W -> ((F, W, [G]), [W]) 108transform :: (W -> (F,W,[G])) -> W -> ((F, W, [G]), [W])
106transform fun w = ((f, w, g), map (eval f) g ) 109transform fun w = ((f, w, g), map (eval f) g )
107 where 110 where
108 (f, w, g) = fun w 111 (f, w, g) = fun w
109 112
113-- take those, where the entry in the result list corresponds to
110filt :: (W -> ((F,W,[G]),[W]) ) -> W -> [G] 114filt :: (W -> ((F,W,[G]),[W]) ) -> W -> [G]
111filt fun w = [ g!!i | i <- [0..n], res!!i == w ] 115filt fun w = [ g!!i | i <- [0..n], res!!i == w ]
112 where 116 where