TITLE: Formal logic behind defining variables in a proof (not E.I. or U.G, etc.)
QUESTION [7 upvotes]: This is something I have been curious about and hopefully has a simple answer. Often when looking at proofs I will come upon a step that goes along the lines of "define   y  = ..." and then proceed to use the defined y to show some conclusion. 
For example in Euclids infinity of primes theorem 
he defines " let k be the product of  all the prime  numbers less  than  n"
followed by "now let  m = k + 1".
and proceeds to reason with these definitions to arrive at the desired results. My question is to what sort of constraints are there to defining new objects to a proof? I am aware of universal generalization rule which requires some restrictions in introducing an arbitrary constant as well well as the other quantifier rules of inference such as existential instantiation and so on. However this whole defining a variable does not seem to be any of these rules.
So at the end of the day can you simply define objects like this all willy nilly like? What sort of justification can you write for such a step? It seems problematic to me because I feel like you need to ensure the existence of such objects before you can introduce them like this, and in particular a step such as  " let k be the product of  all the prime  numbers less  than  n" seems to define an object that has more meaning than simply a definition given by an equation that defines the object of previously defined terms (like "define m = k + 1").
So this begs the question of whether you can arbitrarily define objects that have unconfirmed properties. This does not seem right because then you could be reasoning with statements that are false but since you "defined" them without restriction you mistakenly inferred something that turns out to be false.
So long story short: what is this method known as formally and what sort of restrictions are associated with it?

REPLY [4 votes]: The newly-defined objects are valid if and only if they exist. That is, if you define an object $o$ that satisfies predicate $P$, you must prove that $\exists a, P(a)$.
Explanations: The newly-defined objects in a proof already exist before you define them, it's just that sometimes you don't think about them because they are irrelevant. But if you define absurd objects ("let $n$ be an integer that is both even and odd") then you can derive a contradiction.