Recogize characters that are okay in the "tails" of identifiers: letters, numbers, and underscores.
Function:
(defun idtail-char-p (x) (declare (xargs :guard t)) (and (characterp x) (or (letter-char-p x) (number-char-p x) (eql x #\_))))
Theorem:
(defthm booleanp-of-idtail-char-p (booleanp (idtail-char-p x)) :rule-classes :type-prescription)
Theorem:
(defthm characterp-when-idtail-char-p (implies (idtail-char-p x) (characterp x)) :rule-classes :compound-recognizer)