Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
| Download
Logic of "all" + verbs + relative clauses, for a class at Indiana University
Project: moss notebooks
Views: 7214module ProofTreeNumbers (PTree(..), lineNumberHelp, near, full_reverse, tree_reverse)1where234data PTree a = T a [PTree a]5deriving (Show, Eq)6get1 (aa,b,c) = aa7get2 (aa,b,c) = b8get3 (aa,b,c) = c91011lineNumberHelp :: [(a, [Int], Int)] -> [(a, [Int], Int)] -> [(a, [Int], Int)]12lineNumberHelp firstseq secondseq =13let14n = if null firstseq then 0 else (get3 $ head firstseq)15modify w = map ( \ (x, listofInts, k) -> (x, (map (\ i -> 1 + n+i) listofInts), k)) w16in (firstseq ++ modify secondseq)1718------ near of a PTree lists the nodes in depth-first order, along with an extra list for each node.19------ for the node n in the tree it lists the addresses of the children of n in the same tree, again in the20------ depth-first order of the tree overall. Getting this right was probably the hardest part of this whole exercise.21------ Note also that what we want in the end is not the depth-first listing of the PTree but rather the 'bottom-up' listing,22------ and these are related by23------24------ bottom_up t = reverse (depth_first ( tree_reverse t))2526near :: (PTree a) -> [(a, [Int], Int)]27near (T x l) = [(x,s, k+1 )] ++ extrastuff28where29k = sum r30--extrastuff :: [(a, [Int], Int)]31extrastuff = foldl lineNumberHelp [] (map near l)32--q :: [(a, [Int], Int)]33q = map head $ map near l34r :: [Int]35r = map get3 q36s = init( scanl (+) 2 r)3738tree_reverse (T n t) = T n (map tree_reverse (reverse t))3940full_reverse :: [(a, [Int], Int)] -> [(Int, a, [Int])]41full_reverse h =42let43n = length h44p = [(i, reverse( map (\ x -> n + 1 - x) j )) | (i,j,k) <- h]45q = reverse p46w = [1..n]47mergeMe :: [Int] -> [(a,[Int])] -> [(Int,a,[Int])]48mergeMe [] [] = []49mergeMe (i:wMore) (pair:pMore) = (i, (fst pair), (snd pair)) : (mergeMe wMore pMore)50in mergeMe w q515253