def ternary_feedback(sensing, collision):
    """ Count 1 iff the sensing authorized to communicate and no collision was observed, 0 if no communication, and -1 iff communication but a collision was observed.

    .. math::

       \\mathrm{reward}(\\text{user}\\;j, \\text{time}\\;t) &:= F_{m,t} \\times (2 r_{m,t} - 1), \\\\
       \\text{where}\\;\\; r_{j,t} &:= F_{m,t} \\times (1 - c_{m,t}), \\\\
       \\text{and}  \\;\\; F_{m,t} &\\; \\text{is the sensing feedback (1 iff channel is free)}, \\\\
       \\text{and}  \\;\\; c_{m,t} &\\; \\text{is the collision feedback (1 iff user j experienced a collision)}.
    """
    assert 0 <= sensing <= 1, "Error: 'sensing' argument was not in [0, 1] (was {:.3g}).".format(
        sensing)
    if sensing not in [0, 1]:
        print(
            "Warning: 'sensing' argument was not 0 or 1, but this policy rhoLearnExp3 was only designed for binary sensing model... (was {:.3g})."
            .format(sensing))
    assert collision in [0, 1
        ], "Error: 'collision' argument was not binary, it can only be 0 or 1 (was {:.3g}).".format(
        collision)
    first_reward = sensing * (1 - collision)
    assert 0 <= first_reward <= 1, "Error: variable 'first_reward' should have been only binary 0 or 1 (was {:.3g}).".format(
        first_reward)
    reward = sensing * (2 * first_reward - 1)
    assert -1 <= reward <= 1, "Error: variable 'reward' should have been only binary 0 or 1 (was {:.3g}).".format(
        reward)
    if reward not in {-1, 0, 1}:
        print(
            "Warning: 'reward' argument was not -1, 0 or 1, but this function should give ternary reward... (was {:.3g})."
            .format(reward))
    return reward
