A woman who prays Shaĥarit, Minĥa, or both on a regular basis and is not sure on a particular day whether or not she recited one of these prayers, as long as the time for its recitation has not yet passed, she recites the prayer and makes mental stipulation: “If I already prayed, this prayer is considered a voluntary prayer, and if not, this is an obligatory prayer.” It is unnecessary to introduce any personal requests into that Amida, since the fact that she is avoiding safek is itself something novel. Even though we do not recite voluntary prayers nowadays, we are permitted to do so in order to avoid uncertainty. If, in the middle of that Amida, she remembers that she already prayed, she continues to recite the Amida until the end and adds a personal request to demonstrate that it is, indeed, a voluntary prayer.
If one starts to pray on the basis that her prayer is obligatory, thinking that she did not yet pray, but suddenly remembers in the middle of her Amida that she already did, she must stop immediately. Her prayer cannot become voluntary, for just like there is no offering that is partly obligatory and partly voluntary, so too, there is no prayer that begins as obligatory and ends as voluntary (SA 107:1).
One who is daydreaming in the middle of her prayer to the point where she is unsure what part of the Amida she is reciting, for instance, one who is pondering whether she is reciting the sixth berakha or the tenth, must return to the sixth berakha and start to pray from that point on (according to most poskim, as cited in Peninei Halakha: Prayer, ch. 18 n. 3).