2

If we have a function, would we assume/declare the codomain from the beginning, along with when we define the domain and operations, or would we determine the codomain afterwards, like after we have already chosen the domain and valid operations? Also, if we had equations or formulas or definitions, then would we assume/declare the number system of the "output" variable from the beginning (at the same time when we define the domain and operations for the equation/formula) (meaning that the "output" variable's number system is something we have to define beforehand as a part of the function/equation/formula and it cannot be determined afterwards)? Or would we find/determine the number system for the "output" variable after we have already defined the number system for the "input" variable and its operations, and after we evaluate that part of the equation/formula (on one side of the equals sign), so we know what the "output" variable will be equal to? Also, from what I understand (please correct me if I am wrong), the codomain basically states/defines the general/overall number system that the output will be in (like the real numbers, complex numbers, etc.) (so we know that we can treat the equation/equality as a valid real number or complex number), and the range is the specific numbers that the output can actually be (which we find later as a specific subset of the codomain), right?

For example, if we have a function $f(x)=\sqrt{x}$, then I think that this function, just alone, would not be properly defined since its domain and operations aren't declared. But if we declare that the domain for $f(x)$ is $\Bbb R^+$ and the operations also take place in $\Bbb R$, then which of the following is correct (1 or 2)?

  1. We also have to declare beforehand that the codomain of $f(x)$ is $\Bbb R$ as a definition of the function, along with its domain and operations. So basically, we state/declare/assume that $f(x)$ is a real-valued function beforehand. This way, we ensure that we have an equality $(f(x)=\sqrt{x})$ between real numbers on the LHS and RHS.

  2. We determine afterwards that the codomain of $f(x)$ must be in the real numbers after we declare that the domain of $f(x)$ is the real numbers and the operations are also in the real numbers. So basically, we determine that $f(x)$ is a real-valued function after evaluating $\sqrt{x}$.

Also, how would this apply to other mathematical equalities, like equations or formulas? Because I know that when we solve or rearrange equations for a variable, then we must assume/declare that the variable, equation, and operations take place in a specific number system for this to be valid (I asked this question before here, here, and here) (ex. If we have $x^2=-4$, we must declare beforehand that our variable $(x)$, operations, and equation take place in the complex number system to get a valid answer of $x=±2i$). So, for example, let's say we have $V=IR$ (ohm's law) or $A(r)=\pi r^2$ (area of a circle).

  1. So, for $V=IR$, do we determine that $V$ must be in the real numbers after we declare that $I$ and $R$ are reals and our operation of multiplication is taking place in the real numbers? Or do we already have to assume beforehand that $V$ must be a real number, along with us assuming that $I$ and $R$ are real numbers (so then this way, we already declared that $V$, $I$, and $R$ are real numbers, and then since we know that $IR$ must also be a real number (since we are doing the multiplication operation in the real numbers), we know that our equality between $V$ and $IR$ will be valid in the real numbers, so it's a valid equation that can be used as a formula (to find the value of an unknown variable ($V$, $I$, or $R$) in the real numbers))?

  2. And for $A(r)=\pi r^2$, when we assume that $r \in \Bbb{R}^+$ as its domain, does that tell us/prove that the area is a real number as well, or do we have to assume/declare beforehand that $A(r)$ will also be a real number to use the formula (so that we know we have a true equality between real numbers, and we can use it as a formula for the area of a circle)?

Also, how would this apply to mathematical definitions? Like, would this same process of defining the codomain of a function $f(x)$ also apply to mathematical definitions (like the definition of a derivative or integral)? Like, let's say we define the derivative to be the limit of the difference quotient, or we define the integral to be the limit of a Riemann sum. So then, from the beginning, would we have to assume/declare that the derivative ($\frac{\mathrm{d}y}{\mathrm{d}x}$) or integral ($\int_{a}^{b} f(x) \, \mathrm{d}x$) are a part of the real numbers (meaning we just defined the codomain, where $\frac{\mathrm{d}y}{\mathrm{d}x}$ or $\int_{a}^{b} f(x) \, \mathrm{d}x$ would represent the function $f(x)$), along with also defining from the beginning that the input and operations in the limits/sums are in the real numbers (meaning we just defined the domain and operations, where the limit of the different quotient (for defining $\frac{\mathrm{d}y}{\mathrm{d}x}$) or the limit of a Riemann sum (for defining $\int_{a}^{b} f(x) \, \mathrm{d}x$) would be the operations defining the function $f(x)$), to fully define the derivative or integral?

So, overall, I would like to know more about these assumptions that are required when defining the equality in a function, formula, equation, or definition. Any help regarding these assumptions for functions/equations/formulas/definitions would be greatly appreciated! Thank you! (Sorry for the long question, please let me know if any clarifications are needed.)

jd27
  • 3,623
  • 6
    You declare the codomain from the beginning, and you determine the range afterward. – Karl Sep 28 '25 at 16:46
  • @Karl so would this also apply when we are using equations or formulas like $V=IR$ or $A(r)=\pi r^2$ or if we are using definitions, like when we define derivatives or integrals through limits? – Aaditya Visavadiya Sep 28 '25 at 19:09
  • 1
    It doesn't matter. If you are solving a problem where you define the function, you are free to define that function any way you see fit. The formal definitions are for the presentation, not the solution of a problem. – John Douma Sep 28 '25 at 21:33
  • 2
    (1) I'd say $V=IR$ doesn't define a function, it expresses a relationship that holds between three quantities. (2) If you know that the radius of a circle determines its area, then you know there is a function $A:\Bbb R_+\to\Bbb R_+$, and the formula $A(r)=\pi r^2$ just gives you the rule for computing that function. (3) The derivative and limit operations can be thought of as functions, but their domain is not the real numbers, it is a set whose elements are themselves functions. But nothing requires us to view every definition as a function. – Karl Sep 29 '25 at 00:29
  • Are you at all concerned with the category theory context? And/or are you at all concerned with the axiomatic set theory context? There can be different answers to your question depending on the context. – Lee Mosher Sep 29 '25 at 03:42
  • @LeeMosher I'm not really familiar with category or axiomatic theory, sorry. I just wanted to ask this question as a general mathematics topic, which would basically cover all of basic (algebra) math to advanced (like calculus, discrete, analysis, etc. and above) math. – Aaditya Visavadiya Sep 30 '25 at 00:42
  • @LeeMosher I also have one more question related to this (I also posted this as a comment to another answer below). How do we define the operations in a function? Do we define its operations (like what number system (eg. R, C, Z) the operations take place in) along with the domain/rule/codomain from the start, or do we determine that afterwards? Like do we choose/define the number system our operations(+ - / * ^ √) take place in beforehand, or do we determine that afterwards, like after we already define the domain, codomain, rule of f(x) (ex. if codomain is R, then operations also in R)? – Aaditya Visavadiya Sep 30 '25 at 00:44
  • Well, there is no answer which all practitioners of all branches of basic math would agree with, as you can see pretty clearly from the answers already given. Each answer picks a point of view first, even if they do so only implicitly; for instance the answer of @Taladris picks the category theory point of view. – Lee Mosher Sep 30 '25 at 13:41
  • As for your most recent comment, burying new questions in the comments to an old question is not an effective use of stackexchange. There might be a good question in that comment, if you can formulate it well, in which case you can post it as a new question. – Lee Mosher Sep 30 '25 at 13:43

3 Answers3

8

I find this a confusing question because it is hard to tell whether it is talking about the way mathematics is or about the way we do mathematics.

When you do mathematics, there are likely to be a lot of false starts and dead ends. You think you have a useful idea but it doesn't work out well. You start trying one thing but then you think of something else and decide to do that instead.

You might start out thinking you're working on a problem in real analysis but later decide that this would be better as a problem in complex analysis.

So it doesn't seem practical to make all the choices you're going to need to make "at the beginning." We need some flexibility in how we do mathematics.

But when you finally are ready to write a proof of something, you can't have the codomain of a function mysteriously change during the proof. In that context you need to complete the definitions of things when you define them; the definition of an object is the "beginning" from which all the necessary assumptions and declarations of that definition should be in place. You don't want to be saying "I forgot to mention" explicitly or implicitly.

David K
  • 111,757
  • To muddy the water, I would add that the exact codomain of a function typically has much less practical impact than the exact domain of the function, and this is sometimes reflected in writers' vagueness or sloppiness about it. – Stef Sep 29 '25 at 11:12
  • 2
    @Stef I remember when first being introduced to functions the word "codomain" wasn't even used. The textbook said "range" but meant "codomain." I could have mentioned that a lot (almost all?) of mathematical writing comes with some context with implicit assumptions. For example in first semester calculus all functions might have the reals as codomain by default. Some other textbook might be more explicit about codomains but implicitly assumes it's only doing standard analysis. And so forth. – David K Sep 29 '25 at 15:43
7

Edit: the fact that the codomain is not properly taught in high school maths has bothered me for a long time. Here is an old question of mine on MathsEducation.SE.

This is a complement of @Michael_1812's excellent answer on what a function is.

Before starting, note that there may be different definitions of functions depending on the area of maths you are. I will focus on the precalculus/calculus.

First of all, it seems that there is a misunderstanding about what a function is. The definition of a function is:

Let $A$ and $B$ be two sets. A function $f$ from $A$ to $B$ is a relation that associates t each element of $A$ a unique element of $B$. $A$ is called the domain and $B$ the codomain of $f$. We write $f:A \to B$ to show that the domain is $A$ and the codomain is $B$.

So a function is more than a formula or expression, it is a way to associate the elements of one set to another. The intuitive way of describing a function as a "machine" that takes some input $x$ from $A$ and transforms it into an output $f(x)$ in $B$ is I think how all mathematicians think about functions.

And you can see from the definition that the domain and the codomain are integral parts of the definition. If you change the domain, you change the definition. For example, the functions $f:[0,\infty)\to\mathbb R$ and $g:\mathbb R\to\mathbb R$ defined by $f(x)=x^2$ and $g(x)=x^2$ are different functions. Simply because they have different domains. In particular, $f(-1)$ is undefined. More importantly, they have different properties, $f$ being increasing, hence having an inverse; while $g$ is not.


In Precalculus, the domain $A$ and the codomain $B$ will be subsets of $\mathbb R$, bare a few examples. But they don't need to, and it is important, that many things in mathematics can be described as a function. For example, the area of a triangle can be described as a function, from the set $T$ of all triangles in the plane (the domain) to the set of all real numbers.

The fact that in Precalculus, the domain and the range of a function will always be subsets of $\mathbb R$ lead people to adopt a shorter notation like simply writing $f(x)$ as a formula, for example, $f(x)=x^2$, or an expression like $y=x^2$. When this is done, one has to keep two conventions in mind:

  1. if the domain is not explicitly given, the domain is the largest subset of $\mathbb R$ such that the expression makes sense. For example, the domain of $y=x^2$ is $\mathbb R$ while the domain of $y=\frac{1}{\sqrt{x}}$ is $(0,\infty)$. Some books call this the implicit domain
  2. If the codomain is not explicitly given, the codomain is the range. This allows to write things like "a function has an inverse if and only if it is one-to-one".
Taladris
  • 12,519
  • 3
    "f the codomain is not explicitly given, the codomain is the range." << I've never seen this convention before and I wouldn't expect it unless it was stated explicitly. Instead, I've always seen the much simpler convention "If the codomain is not explicitly given, the codomain is $\mathbb R$". – Stef Sep 29 '25 at 11:05
  • @Stef How can f(2n) := “EVEN”, f(2n+1) := “ODD” for n ∈ ℕ have a codomain of ℝ? – user3840170 Sep 29 '25 at 12:52
  • Then though, the usual set-theoretic definition of a function is as a set of pairs (with some conditions) and under that definition, f = g, since they are (represented by) the same set of pairs. The domain can be recovered from such a set of pairs as { x : ∃x∃y: (x, y) ∈ f }, but the codomain cannot. – user3840170 Sep 29 '25 at 12:53
  • Thank you! I just have one more question. So we must define the domain, codomain, and rule (like the actual operation/formula) of f(x) beforehand, but what about its operations? Do we define its operations (like what number system (eg. R, C, Z) the operations take place in) along with the codomain from the start, or do we determine that afterwards? Like do we choose/define the number system our operations(+ - / * ^ √) take place in beforehand, or do we determine that afterwards, like after we already define the domain, codomain, rule of f(x) (ex. if codomain is R, then operations also in R)? – Aaditya Visavadiya Sep 29 '25 at 15:49
  • 1
    @Stef: yes, but Precalculus textbooks (at least the ones I know: Stewart's Precalculus, Larson's Precalculus, and Axler's Algebra and Trigonometry) all claim that a function is invertible if and only if it is one-to-one. This makes only sense if a function is onto by default, that is the range and the codomain are the same. – Taladris Sep 30 '25 at 00:09
  • @user3840170: many precalculus textbooks give a general definition of functions, then assume without saying it that the domain and the codomain are subsets of $\mathbb R$. So they would ignore your example. – Taladris Sep 30 '25 at 00:11
  • 2
    @AadityaVisavadiya: the operations are part of the definition of $\mathbb R$ and other "named" sets. You usually take them for granted when starting precalculus. If you want to know more about how these operations are defined, and most importantly, why they satisfy the properties they have, this is done in more advanced classes. You can ask another question on this website too (way too long to answer in a comment) – Taladris Sep 30 '25 at 00:14
5

"which of the following is correct (1 or 2)?"

Correct is No 1.

We define a function, or mapping, as $$ f:~X\longrightarrow Y\;, $$ the domain $X$ and codomain $Y$ being some sets. This being said, we do not imply that each element of $Y$ has a preimage.

If the mapping is onto, we say that the image of $X$ or, the same, the range of $f$ coincides with the codomain $Y$.

If the mapping is into, the image of $X$ (the range of values of $f$) is residing in $Y$ but is not identical to it.

This picture from Wikipedia illustrates the concept. The codomain is blue, the image (range) is yellow.

enter image description here

Michael_1812
  • 2,178
  • 1
    Okay, thank you so much for your answer! I think this makes sense! Also, would this same concept also apply when we are using equations or formulas like $V=IR$ or $A(r)=\pi r^2$, or if we are using definitions, like when we define derivatives or integrals through limits? – Aaditya Visavadiya Sep 28 '25 at 19:08
  • 1
    @AadityaVisavadiya The concept is general and applies also to the functions you mentioned. For a further generalisation of the concept, see the good answer suggested by Taladris. – Michael_1812 Sep 29 '25 at 12:35
  • 1
    Thank you!! I just have one more question. So we must define the domain, codomain, and rule (like the actual operation/formula) of f(x) beforehand, but what about its operations? Do we define its operations (like what number system (eg. R, C, Z) the operations take place in) along with the codomain from the start, or do we determine that afterwards? Like do we choose/define the number system our operations(+ - / * ^ √) take place in beforehand, or do we determine that afterwards, like after we already define the domain, codomain, rule of f(x) (ex. if codomain is R, then operations also in R)? – Aaditya Visavadiya Sep 29 '25 at 15:50
  • 1
    @AadityaVisavadiya A definition must be consistent. For this, the range of values must reside in the codomain. This imposes constraints on the "rule of f(x)". If, say, we wish the codomain to be R, the operations comprised by f(x) must be such that in the end we get a real number -- a natural restriction. This being said, our f(x) may include operations with complex numbers, matrices, etc. Everything goes, insofar as f(x) renders us a real number. For example, $\sqrt{|\exp(4 + i x)|}$ incorporates operations with complex numbers -- but it produces a real number. So all is fine. – Michael_1812 Sep 29 '25 at 17:34