<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def filter_doctree_for_slides(doctree):
 """Given a doctree, remove all non-slide related elements from it."""


    current = 0
    num_children = len(doctree.children)
    while current < num_children:

        child = doctree.children[current]
        child.replace_self(
            child.traverse(no_autoslides_filter)
        )

        if len(doctree.children) == num_children:
            # nothing removed, increment current
            current += 1
        else:
            # a node was removed; retain current and update length
            num_children = len(doctree.children)