#
# This module contains some operations on lattices. Most depend on the
# assumption that the lattice has a single root.
#
# Copyright (C) 2007-2010 Dennis Furey
#
# bwi                                         (1045)
# edges                                        (273)
# fswi                                        (2623)
# fwi                                         (2447)
# grid                                        (8385)
# ldis                                         (576)
# ldiz                                         (372)
# levels                                       (360)
# lfold                                        (595)
# lmap                                         (535)
# lnodes                                       (369)
# lzip                                         (686)
# sever                                       (1058)
# swi                                         (2682)
#
# compressed with granularity 91
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
{iwiwNiwwhsizpgKwqQghooZhbQEoJaxsiaZEWKFnwyVRcnkjhEXppjzp\QFcWnvxiksVsgh\tIG>R\
vsIxgNkseMgG>wP{OckQeFfpkqjVERahoDlwCIgQRPkoVowMNAkOfvOwAiEJXhg[GOKkzfIWWKr^Wsa
Vj_Kp^kQdp>N{IwogpxgKMKZfQQ`eML[nfriPvhgRw[FIENIoV{\fKnkI\_b>[p^p`ukOgKvxgzfEti
J@oIPNxl^FkKM<Bvgj_Kg<_FomFSsOWNGNjzHVnOKj_rvfd[yFeML[gdhnR^vjhjzoJfPQM?fnIXrx`
k?H\]{Fob>[gYFlnh[KowOQdoOJTvvxfmUNnDo]DdawGI@<WeP^knzAOIOqijYoIdqQinp`^i`e<KND
cuGF]{htoq>InOgnS`ki[{Hc^fQOE<WZp^_QELS^oDDSjXnttEUIQhk@mHjc{yvnAH]_POHo`^Xnf[w
DfSrafkKOXdAhtfjLq`[a{s{Ho_EhGPW@^x]b[GnDavNnnIEVqok@rOqGhecn[a{{Yvgf`@mDN=KF\<
AnfacxcFfh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