<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def is_selection_inside_of_library_state(state_machine_m=None, selected_elements=None):
 """ Check if handed or selected elements are inside of library state If no state machine model or selected_elements are handed the method is searching for the selected state machine and its selected elements. If selected_elements list is handed handed state machine model is ignored. :param rafcon.gui.models.state_machine.StateMachineModel state_machine_m: Optional state machine model :param list selected_elements: Optional model list that is considered to be selected :return: True if elements inside of library state """

    if state_machine_m is None:
        state_machine_m = rafcon.gui.singleton.state_machine_manager_model.get_selected_state_machine_model()
    if state_machine_m is None and selected_elements is None:
        return False
    selection_in_lib = []
    selected_elements = state_machine_m.selection.get_all() if selected_elements is None else selected_elements
    for model in selected_elements:
        # check if model is element of child state or the root state (or its scoped variables) of a LibraryState
        state_m = model if isinstance(model.core_element, State) else model.parent
        selection_in_lib.append(state_m.state.get_next_upper_library_root_state() is not None)
        # check if model is part of the shell (io-port or outcome) of a LibraryState
        if not isinstance(model.core_element, State) and isinstance(state_m, LibraryStateModel):
            selection_in_lib.append(True)
    if any(selection_in_lib):
        return True
    return False