Last active
August 31, 2017 18:43
-
-
Save marcoonroad/c26ee7a9c19b16d93f0d to your computer and use it in GitHub Desktop.
...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- para matrizes de rank 2 -- | |
-- implementando-as como arvores -- | |
data Tree a = Leaf | Node (Tree a) a (Tree a) deriving Eq | |
{- | |
| | | |
| A11 A12 A13 | | |
a = | | | |
| A21 A23 A23 | | |
| | | |
========================================== | |
A11 --------- A12 --------- A13 -- Leaf | |
| | | | |
| | | | |
A21 -- Leaf A22 -- Leaf A23 -- Leaf | |
| | | | |
Leaf Leaf Leaf | |
-} | |
ttranspose Leaf = Leaf | |
ttranspose (Node left value right) = Node (ttranspose right) value (ttranspose left) | |
{- | |
| | | |
| A11 A12 A13 | | |
a = | | | |
| A21 A23 A23 | | |
| | | |
========================================== | |
A11 ---------- A12 ---------- A13 -- Leaf | |
| | | | |
| | | | |
A21 -- Leaf A22 -- Leaf A23 -- Leaf | |
| | | | |
Leaf Leaf Leaf | |
------ | |
|| | |
|| | |
ttranspose | |
|| | |
|| | |
\||/ | |
\/ | |
A11 ------ A21 -- Leaf | |
| | | |
| Leaf | |
| | |
| | |
a' = A12 ------ A22 -- Leaf | |
| | | |
| Leaf | |
| | |
| | |
A13 ------ A23 -- Leaf | |
| | | |
Leaf Leaf | |
-} | |
tjoin Leaf mtrx = mtrx | |
tjoin (Node left value right) mtrx = Node left value (tjoin right mtrx) | |
{- | |
A11 ------ A21 -- Leaf | |
| | | |
| Leaf | |
| | |
| | |
a' = A12 ------ A22 -- Leaf | |
| | | |
| Leaf | |
| | |
| | |
A13 ------ A23 -- Leaf | |
| | | |
Leaf Leaf | |
--------------------------------------- | |
C11 -- Leaf | |
| | |
| | |
C12 -- Leaf | |
c' = | | |
| | |
C13 -- Leaf | |
| | |
Leaf | |
------ | |
|| | |
|| | |
tjoin a' | |
|| | |
|| | |
\||/ | |
\/ | |
A11 ------ A21 ---------- C11 -- Leaf | |
| | | | |
| Leaf | | |
| | | |
| | | |
a'c' = A12 ------ A22 -- Leaf C12 -- Leaf | |
| | | | |
| Leaf | | |
| | | |
| | | |
A13 ------ A23 -- Leaf C13 -- Leaf | |
| | | | |
Leaf Leaf Leaf | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment