When can transformers reason with abstract symbols?