def UV_H(Hg,gw):
    """
    Constructs implications and intents based on H
    gw = g width
    Hg = H(g), g is the binary coding of the attribute set
    UV = all non-trivial (!V⊂U) implications U->V with UuV closed; in ternary coding (1=V,2=U)
    K = all closed sets
    """
    lefts = set()
    K = []
    UV = []
    p = Hwidth(gw)
    pp = 2**p
    while p:
        pp = pp>>1
        p = p-1
        if Hg&pp:
            y = istr(p,3,gw)
            yy = y.replace('1','0')
            if yy not in lefts: 
                if y.find('1') == -1:#y∈{0,2}^n
                    K.append(y)
                else:
                    UV.append(y)
                    lefts.add(yy)
    return (UV,K)
def UV_H ( Hg , gw ) : lefts = set ( ) K = [ ] UV = [ ] p = Hwidth ( gw ) pp = 2 ** p while p : pp = pp >> 1 p = p - 1 if Hg & pp : y = istr ( p , 3 , gw ) yy = y . replace ( '1' , '0' ) if yy not in lefts : if y . find ( '1' ) == - 1 : K . append ( y ) else : UV . append ( y ) lefts . add ( yy ) return ( UV , K )
Constructs implications and intents based on H
    gw = g width
    Hg = H(g), g is the binary coding of the attribute set
    UV = all non-trivial (!V⊂U) implications U->V with UuV closed; in ternary coding (1=V,2=U)
    K = all closed sets