<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_fragment(self, fragment, as_last=True):
 """ Add the given sync map fragment, as the first or last child of the root node of the sync map tree. :param fragment: the sync map fragment to be added :type fragment: :class:`~aeneas.syncmap.fragment.SyncMapFragment` :param bool as_last: if ``True``, append fragment; otherwise prepend it :raises: TypeError: if ``fragment`` is ``None`` or it is not an instance of :class:`~aeneas.syncmap.fragment.SyncMapFragment` """

        if not isinstance(fragment, SyncMapFragment):
            self.log_exc(u"fragment is not an instance of SyncMapFragment", None, True, TypeError)
        self.fragments_tree.add_child(Tree(value=fragment), as_last=as_last)