If a person is thinking of another woman during intercourse, what is it considered?
Does it matter if it is his wife or not? (Could it be considered adultery if committed with let's say a girlfriend?)
The Talmud (Nedarim 20b) expresses this in a slight riddle.
Says Rebbi: Once should not drink from a cup whilst thinking about another cup. Based on the verse (Num. 15:39) ‘do not stray after your heart and eyes’.
Ravina qualifies: Even if he has two wives; this is still inappropriate.
Rambam Issurei Biah 21:12
"וְכֵן אָסְרוּ חֲכָמִים שֶׁלֹּא יְשַׁמֵּשׁ אָדָם מִטָּתוֹ וְלִבּוֹ מְחַשֵּׁב בְּאִשָּׁה אַחֶרֶת."
"Similarly, the sages forbade a man to have marital relations while thinking of another woman."
Also, thinking of adultery is not adultery.
Midrash Rabbah Bamidbar 9:34 (note that this is a Midrash, not Halacha):
אָמְרוּ רַבּוֹתֵינוּ בִּזְּמַן שֶׁהָאִשָּׁה מִיַּחֶדֶת עִם בַּעֲלָהּ וְהִיא מְשַׁמֶּשֶׁת עִמּוֹ וְלִבָּהּ לְאִישׁ אַחֵר שֶׁרָאֲתָה בַּדֶּרֶךְ, אֵין לְךָ נִאוּף גָּדוֹל מִזֶּה, שֶׁנֶּאֱמַר (יחזקאל טז, לב): הָאִשָּׁה הַמְנָאֶפֶת תַּחַת אִישָׁהּ תִּקַּח אֶת זָרִים, וְכִי יֵשׁ אִשָּׁה שֶׁמְנָאֶפֶת תַּחַת אִישָׁהּ, אֶלָּא זוֹ הִיא שֶׁפָּגְעָה בְּאִישׁ אַחֵר וְנָתְנָה עֵינֶיהָ בּוֹ, וְהִיא מְשַׁמֶּשֶׁת עִם בַּעֲלָהּ וְלִבָּהּ עָלָיו
Our masters taught: When a wife is alone with her husband and is engaged in intercourse with him, and her heart is with another man she saw on the road, there is no greater adultery, for it is said, "[you were like] the adulterous wife who welcomes strangers instead of [lit. under] her husband." (Yechezkel 16:32). But is there a woman commits adultery under her husband? Rather, we're referring to a case where she met another man and set her eyes on him, and while she is engaged in intercourse with her husband, her heart is with that man."