  Pulse-pileup affects most photon counting systems and occurs when photon
detections occur faster than the detector's registration and recovery time. At
high input rates, shaped pulses interfere and the source spectrum, as well as
intensity information, get distorted. For instruments using bipolar pulse
shaping there are two aspects to consider: `peak' and `tail' pileup effects,
which raise and lower the measured energy, respectively. Peak effects have been
extensively modeled in the past. Tail effects have garnered less attention due
to the increased complexity: bipolar tails mean the tail pulse-height
measurement depends on events in more than one time interval. We leverage
previous work to derive an accurate, semi-analytical prediction for peak and
tail pileup, up to high orders. We use the true pulse shape from the detectors
of the Fermi Gamma-ray Burst Monitor. The measured spectrum is calculated by
writing exposure time as a state-space expansion of overlapping pileup states
and is valid up to very high rates. This expansion models losses due to fixed
and extendable deadtime by averaging overlap configurations. Additionally, the
model correctly predicts energy-dependent losses due to tail subtraction
(sub-threshold) effects. We discuss pileup losses in terms of the true rate of
photon detections versus the recorded count rate.
