<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _collect_derived_entries(state, traces, identifiers):
 """Produce a mapping containing all candidates derived from `identifiers`. `identifiers` should provide a collection of requirement identifications from a section (i.e. `packages` or `dev-packages`). This function uses `trace` to filter out candidates in the state that are present because of an entry in that collection. """

    identifiers = set(identifiers)
    if not identifiers:
        return {}

    entries = {}
    extras = {}
    for identifier, requirement in state.mapping.items():
        routes = {trace[1] for trace in traces[identifier] if len(trace) > 1}
        if identifier not in identifiers and not (identifiers & routes):
            continue
        name = requirement.normalized_name
        if requirement.extras:
            # Aggregate extras from multiple routes so we can produce their
            # union in the lock file. (sarugaku/passa#24)
            try:
                extras[name].extend(requirement.extras)
            except KeyError:
                extras[name] = list(requirement.extras)
        entries[name] = next(iter(requirement.as_pipfile().values()))
    for name, ext in extras.items():
        entries[name]["extras"] = ext

    return entries