def pre_ce(mas, agents, states, moves):
    """
    Return the set of states of mas such that there exists a move for agents
    in moves such that all reached states are in states.
    
    mas -- a multi-agent system;
    agents -- a subset of agents of mas;
    states -- a subset of states of mas;
    moves -- a set of moves for agents.
    """
    agents_cube = mas.inputs_cube_for_agents(agents)
    others_cube = mas.bddEnc.inputsCube - agents_cube
    states = states.forsome(mas.bddEnc.inputsCube)
    moves = moves.forsome(others_cube)
    states = states & mas.bddEnc.statesMask
    nstates = ~states & mas.bddEnc.statesMask
    moves = moves & mas.bddEnc.statesInputsMask
    return ((~mas.weak_pre(nstates).forsome(others_cube) & mas.weak_pre(
        states)).forsome(others_cube) & moves).forsome(mas.bddEnc.inputsCube)
