Hylomorphisms in practice Hylomorphism (computer science)



in previous example (written in haskell, purely functional programming language) can seen function, applied given valid input, generate linear call tree isomorphic list. example, given n = 5 produce following:



factorial 5 = 5 * (factorial 4) = 120
factorial 4 = 4 * (factorial 3) = 24
factorial 3 = 3 * (factorial 2) = 6
factorial 2 = 2 * (factorial 1) = 2
factorial 1 = 1 * (factorial 0) = 1
factorial 0 = 1

in example, anamorphic part of process generation of call tree isomorphic list [1, 1, 2, 3, 4, 5]. catamorphism, then, calculation of product of elements of list. thus, in notation given above, factorial function may written




factorial

=
[

[
(
1
,
×
)
,
(
g
,
p
)
]

]


{\displaystyle {\text{factorial}}=[\![(1,\times ),(g,p)]\!]}





g
 
n
=
(
n
,
n

1
)


{\displaystyle g\ n=(n,n-1)}

,



p
 
n
=
(
n
=
0
)


{\displaystyle p\ n=(n=0)}

.


trees

however, term hylomorphism not apply solely functions acting upon isomorphisms of lists. example, hylomorphism may defined generating non-linear call tree collapsed. example of such function function generate n term of fibonacci sequence.




call tree fibonacci 4.


this function, again applied valid input, generate call tree non-linear. in example on right, call tree generated applying fibonacci function input 4.


this time, anamorphism generation of call tree isomorphic tree leaf nodes 0, 1, 1, 0, 1 , catamorphism summation of these leaf nodes.







Comments

Popular posts from this blog

Ice Age List of Ice Age characters

Beiyang clique in power .281911.E2.80.9315.29 Beiyang Army

R172 .282011.E2.80.93Present.29 Mercedes-Benz SLK-Class