-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDealgebrizer.hs
25 lines (18 loc) · 1.37 KB
/
Dealgebrizer.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import Expression
-- Temporary --
import Algebrizer
---------------
alphabet :: String
alphabet = ['a'..'z']
base26 :: (Integral a) => a -> String
base26 x
| x < 26 = (alphabet !! (fromIntegral x)):[]
| otherwise = (alphabet !! (fromIntegral (mod x 26))):(base26$ (quot x 26)-1)
makeArguments :: (Integral a) => a -> String -> String
makeArguments x name = "("++concat[name ++ '_':base26 a++":"|a<-[0..x-1]]++"__" ++ name ++ ")"
destack :: [Integer] -> String -> String
destack polynomial name = concat ["(" ++ show coefficient ++ "*" ++ name ++ "_" ++ base26 index ++ ")+" |(index,coefficient) <- zip [0..] polynomial,coefficient /= 0]
semidealgebrize :: [Expression] -> String
semidealgebrize stack = concat["(" ++ destack (onStack e) "left" ++ destack (offStack e) "right" ++ destack (sstack e) "third" ++ "(" ++ show (rawvalue e) ++ ")):"|e<-stack]
dealgebrize :: (([Expression], [Expression], [Expression]), (Integer, Integer, Integer), Bool) -> String -> String
dealgebrize ((left,right,third),(d1,d2,d3),True) name = name ++ " :: ([Integer],[Integer],[Integer]) -> (Integer,Integer) -> ([Integer],[Integer],[Integer])\n" ++ name ++ "(" ++ (makeArguments d1 "left") ++ "," ++ (makeArguments d2 "right") ++ "," ++ (makeArguments d3 "third") ++ ") (_lh,_rh) = (" ++ semidealgebrize left ++ "__left," ++ semidealgebrize right ++ "__right," ++ semidealgebrize third ++ "__third)" ++ "\n"