If an atom A is double-bonded to an atom B, A is treated as being singly bonded to two atoms: B and a "phantom atom" that is a duplicate of B (has the same atomic number) but is not attached to anything except A. When B is replaced with a list of attached atoms, A itself, but not its "phantom", is excluded in accordance with the general principle of not doubling back along a bond that has just been followed. A triple bond is handled the same way except that A and B are each connected to two phantom atoms of the other.