def define_objective_with_I(I, *args):
objective = I[<NUM_LIT:0>][<NUM_LIT:0>]<EOL>if len(args) > <NUM_LIT:2> or len(args) == <NUM_LIT:0>:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>elif len(args) == <NUM_LIT:1>:<EOL><INDENT>A = args[<NUM_LIT:0>].parties[<NUM_LIT:0>]<EOL>B = args[<NUM_LIT:0>].parties[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>A = args[<NUM_LIT:0>]<EOL>B = args[<NUM_LIT:1>]<EOL><DEDENT>i, j = <NUM_LIT:0>, <NUM_LIT:1>  <EOL>for m_Bj in B:  <EOL><INDENT>for Bj in m_Bj:<EOL><INDENT>objective += I[i][j] * Bj<EOL>j += <NUM_LIT:1><EOL><DEDENT><DEDENT>i += <NUM_LIT:1><EOL>for m_Ai in A:<EOL><INDENT>for Ai in m_Ai:<EOL><INDENT>objective += I[i][<NUM_LIT:0>] * Ai<EOL>j = <NUM_LIT:1><EOL>for m_Bj in B:<EOL><INDENT>for Bj in m_Bj:<EOL><INDENT>objective += I[i][j] * Ai * Bj<EOL>j += <NUM_LIT:1><EOL><DEDENT><DEDENT>i += <NUM_LIT:1><EOL><DEDENT><DEDENT>return -objective<EOL>
Define a polynomial using measurements and an I matrix describing a Bell
    inequality.

    :param I: The I matrix of a Bell inequality in the Collins-Gisin notation.
    :type I: list of list of int.
    :param args: Either the measurements of Alice and Bob or a `Probability`
                 class describing their measurement operators.
    :type A: tuple of list of list of
             :class:`sympy.physics.quantum.operator.HermitianOperator` or
             :class:`ncpol2sdpa.Probability`

    :returns: :class:`sympy.core.expr.Expr` -- the objective function to be
              solved as a minimization problem to find the maximum quantum
              violation. Note that the sign is flipped compared to the Bell
              inequality.