operator: map
description:
map[fn, op] sp
map a function operator to a literal operator
eg: map[fn, op] (|x> + |y> + |z>)
runs:
op |x> => fn |_self>
op |y> => fn |_self>
op |z> => fn |_self>
examples:
-- define the star operator:
star-op |*> #=> apply( supported-ops |_self>, |_self>)
map[star-op, star] rel-kets[*]
-- define a binary tree:
-- define the head:
left |x> => |0>
right |x> => |1>
-- define our operators:
child |*> #=> left |_self> + right |_self>
left-op |*> #=> |_self> _ |0>
right-op |*> #=> |_self> _ |1>
-- now build the tree:
map[left-op, left] child |x>
map[right-op, right] child |x>
map[left-op, left] child^2 |x>
map[right-op, right] child^2 |x>
map[left-op, left] child^3 |x>
map[right-op, right] child^3 |x>
map[left-op, left] child^4 |x>
map[right-op, right] child^4 |x>
...
-- approximate implementation using multi-line stored rules:
-- makes use of the linearity of |*> rules
map-fn-to-op |*> #=>
op |__self> => fn |__self>
-- then invoke it:
map-fn-to-op (|x> + |y> + |z>)
see also:
tree.sw, copy-map, smap
Home