  We describe a class of programmable devices that can discriminate between two
quantum states. We consider two cases. In the first, both states are unknown.
One copy of each of the unknown states is provided as input, or program, for
the two program registers, and the data state, which is guaranteed to be
prepared in one of the program states, is fed into the data register of the
device. This device will then tell us, in an optimal way, which of the
templates stored in the program registers the data state matches. In the second
case, we know one of the states while the other is unknown. One copy of the
unknown state is fed into the single program register, and the data state which
is guaranteed to be prepared in either the program state or the known state, is
fed into the data register. The device will then tell us, again optimally,
whether the data state matches the template or is the known state. We determine
two types of optimal devices. The first performs discrimination with minimum
error, the second performs optimal unambiguous discrimination. In all cases we
first treat the simpler problem of only one copy of the data state and then
generalize the treatment to n copies. In comparison to other works we find that
providing n > 1 copies of the data state yields higher success probabilities
than providing n > 1 copies of the program states.
