# need to find an example that F* is not a subset in the largest hyperplane
# see https://coauthor.tcsuestc.com/My%20Group/m/mQN2RfiLxYzQ7jAeg for counterexample
from sage.all import *
from sage.matroids.all import *
from sage.graphs.all import *

def check(M):
    # collect the largest hyperplane and optimal F*
    Hset=[]
    Hsize=0
    Fset=[]
    Fstrength=1000000
    for r in range(0,M.rank()):
        #enumerate all flats
        rank_deficiency=M.rank()-r
        for F in M.flats(r):
            size_deficiency=M.size()-len(F)
            strength=size_deficiency/rank_deficiency
            if strength < Fstrength:
                Fstrength = strength
                Fset = [F]
            elif strength == Fstrength:
                Fset.append(F)
            if r==M.rank()-1:
                if Hsize < len(F):
                    Hsize = len(F)
                    Hset = [F]
                elif Hsize == len(F):
                    Hset.append(F)
    # print(Hsize, Fstrength)
    # input()
    for H in Hset:
        for F in Fset:
            if F<=H:
                return False
    return True
    

f = lambda g: g.is_connected()
for N in range(4,10):
    #enumerage connect graphs
    for g in filter(f, graphs(N)):
        print(g.size())
        MG=Matroid(g)
        if check(MG):
            print("found one example!!")
            print(g.edges())
            exit()
            