News for hackers. Stuff that matters.
Re:Functions are Vectors by matteoraso on Saturday July 29, 2023 @04:47PM (#36924388)
This touches on the actual definition of a function, which is a mapping between sets where every element of the first set maps to exactly one element of the second set. The problem with using vectors is that vectors aren't as general as sets, so there's functions that can't be expressed using vectors. For example, vectors can't be used to handle undefined values or non-numeric elements.
Re:Functions are Vectors by adammarples on Saturday July 29, 2023 @06:37PM (#36925488)
That's not the definition of a function, what you're describing would be called a bijective function. A simple function that is not bijective and maps to two distinct values would be sqrt(x)
Re:Functions are Vectors by tlb on Saturday July 29, 2023 @08:24PM (#36926344)
"In mathematics, a function from a set X to a set Y assigns to each element of X exactly one element of Y." [0]

[0] https://en.wikipedia.org/wiki/Function_(mathematics)

Re:Functions are Vectors by eternityforest on Sunday July 30, 2023 @01:19AM (#36928082)
Which doesn't mean each element of Y has exactly one matching counterpart in X, two elements in X can share one in Y
Re:Functions are Vectors by ElFitz on Sunday July 30, 2023 @02:54AM (#36928572)
e.g. hash collisions.
Re:Functions are Vectors by slavik81 on Saturday July 29, 2023 @08:31PM (#36926388)
You may be confused because a bijective function must be one-to-one, while in general, a function may be many-to-one. However, the standard definition of a function excludes one-to-many mappings.

> A function f from a set X to a set Y, denoted f: X -> Y, is a relation from X, the domain, to Y, the co-domain, that satisfies two properties: (1) every element in X is related to some element in Y, and (2) no element in X is related to more than one element in Y.

Susanna S. Epp. 2010. Discrete Mathematics with Applications (4th. ed.). p.384

Re:Functions are Vectors by thaumasiotes on Saturday July 29, 2023 @08:40PM (#36926453)
That is the definition of a function, but it's purely a formalism. In reality, and in theoretical math, we are frequently interested in functions that generate multiple values, and it's very easy to represent those in terms of the formal definition. When we want to consider both positive and negative square roots, we can just say that instead of the function sqrt(x): ℝ ⟶ ℝ which always gives a positive real number, we are using a function full_sqrt(x): ℝ ⟶ ℝ² which gives an ordered pair of real numbers.

So you're wrong about the definition of a function, except that you're right in spirit; the way we normally think about functions, as opposed to the way we define them, definitely allows them to yield multiple values for one input.

You're catastrophically wrong about bijective functions; those are an important concept and your definition is not related to the actual one. A bijective function is one for which all values in the target set are reached by exactly one, no more and no less, value in the source set.

Re:Functions are Vectors by cgio on Saturday July 29, 2023 @08:49PM (#36926511)
My pedant nature strikes but I think your definition of bijective can also be confusing. Did you mean for each value in the target set rather than all values in the target set?
Re:Functions are Vectors by thaumasiotes on Saturday July 29, 2023 @08:56PM (#36926552)
A bijective function f: A ⟶ B satisfies ∀b∈B ∃a∈A ∀x∈A (f(a) = b ∧ (f(x) = b ⟶ x = a)).

(In fact, this definition is incomplete: it must also be the case that the function is defined over the entire set A; each value in A maps to a value in B.† This is a common assumption to make about functions, but since I violate it earlier by talking about sqrt(x): ℝ ⟶ ℝ, I really should make it explicit. The definition I gave is motivated by the synonymous term "invertible function".)

"All values in the target set have property X" and "Each value in the target set has property X" are exactly equivalent English-language statements.

† "f: A ⟶ B satisfies ∀b∈B ∃a∈A ∀x∈A (f(a) = b ∧ f(x) ∈ B ∧ (f(x) = b ⟶ x = a))", but while that technically works, it feels kludgy.

Re:Functions are Vectors by cykotic on Saturday July 29, 2023 @09:12PM (#36926654)
We don’t allow multiple values for a given input of a function. Ever. This is never done. f(x) = x^2 is not invertible as a real valued function of a real variable. On the restricted domain of [0, infinity) it is invertible and that inverse is sqrt(x). If you want to talk about negative roots you use the function -1*sqrt(x). You can construct a new function as you did to encapsulate this fact but one never has a function with multiple values for a given input. I don’t know of any mathematician that thinks of functions as allowing them to have multiple values for a given input. You will not find this in the literature.
Re:Functions are Vectors by thaumasiotes on Sunday July 30, 2023 @12:28AM (#36927806)
Don't be ridiculous. It's a common need, it's easily satisfied, and so it is commonly done. Compare the concept of the "inverse element" of a value given by an invertible function with the "inverse image" of a value given by a non-invertible function. Of course the function that gives you inverse images is nothing more than an inverse function that is allowed to give multiple values. Why do we do that? Because our need to invert functions has nothing to do with whether those functions are one-to-one, and because in most contexts it isn't actually important that functions yield a single value. It's a formalism.

There is no high principle that says "collecting multiple values and giving them a collective name that implies they are a single value is metaphysically superior to collecting multiple values and admitting that they are multiple values".

Re:Functions are Vectors by eternityforest on Sunday July 30, 2023 @01:37AM (#36928183)
Seems like a useful formalism though, at least coming from a programming background.

Maybe some kind of "it's all of them at once" mental model is useful in math, but object oriented programming gives you a hierarchal mindset, everything is in a container of some sort, so multiple return values having a container like a set makes perfect sense and just a bunch of loose values isn't a very familiar concept.

But perhaps if you're actually doing math, things are different?

Re:Functions are Vectors by thaumasiotes on Sunday July 30, 2023 @02:05AM (#36928334)
It's useful in many places and less useful in others.

Over in the programming world, Common Lisp allows you to return multiple values without wrapping them in a container. If you want the primary value, you just treat the function as if it returned one value. If you want additional return values, you use multiple-value-bind.

(I believe the general idea is along these lines: your function does a certain amount of computation, producing a set of related values. Most of the time, the caller will be interested in just one of those, which you return as the primary value. But some of the time, the caller will be interested in more than just that one value, and you have to compute the secondary values whether the caller wants them or not, so you return those too.)

Re:Functions are Vectors by AmpsterMan on Sunday July 30, 2023 @03:04PM (#36934758)
I can think of two simple, practical answers to your query:

The expressive power of single value functions is very powerful and the constraint is not necessarily restrictive but may even drive a stronger analysis. (Where does this function have multiple returns? Is it for the whole domain? Etc)

By contrast the expressive power of negation and implication are relatively low given very intuitive and well defined alternatives exist.

Second, there already exist good enough paradigms for dealing with multi-valued functions. Splitting the function up into multiple functions, mapping to an ordered pair, etc.

Defining a function the traditional way is more than just notational convenience. The single value constraint allows for many simplifying assumptions, enough that is worth to pay the cost when dealing with relations that you want to talk about in functional ways

Re:Functions are Vectors by adrian_b on Sunday July 30, 2023 @04:07AM (#36928970)
In mathematics (and in programming) it is essential to use non-ambiguous names, i.e. names whose meaning is certain when you see them independently of any context, without having to add an explanation of what is meant by them.

The concept of a special kind of mapping between two sets, where to any element of the first set corresponds a unique element of the second set is very important and it needs a special name.

The choice of the names is arbitrary and one could use for instance the term "univocal function" to mean a mapping like described above and "function" for any mapping between two sets.

Nevertheless, by far the most widespread convention in mathematics is to use the term "relation" for any mapping between two sets and the term "function" only for those relations where to any element of the first set corresponds a unique element of the second set.

There exists no reason for not following this convention, from which it also results that an invertible function is a function where for any element of the second set corresponds a unique element of the first set, so this convention also provides a simple meaningful name for another important concept that needs a special name.

The functions in programming languages that return multiple values, unless they return partially or totally random values (in which case they are not functions of only the input arguments, but also of an internal state or of time), are just functions that return values which belong to the set that is the Cartesian product of the types of the individual values. So the name "function" is usually correct in the mathematical sense even for such functions. If they had not been functions, the programmer would not have known what values to return, when writing them.

Moreover, I disagree that in most contexts when you want to invert a function "it isn't actually important that functions yield a single value".

In the overwhelming majority of the cases that appear in engineering and science when you want to solve equations a.k.a. to invert functions, you want to obtain a unique solution that can be directly implemented in practice. Whenever you cannot obtain a unique solution, you need to add extra criteria that allow the selection of a unique solution that is usable. Those extra criteria are actually equivalent with transforming the original non-invertible function into a function that can be inverted.

Re:Functions are Vectors by cykotic on Sunday July 30, 2023 @09:16AM (#36930871)
There is no high principle other than the agreed upon definition of what a function is.

Of course the function that gives you inverse images is nothing more than an inverse function that is allowed to give multiple values.

You can’t use the word function for something that isn’t a function. It makes no sense to say inverse function that is allowed to give multiple values. Hence the need for terms like pre-image of a set.

In all contexts it is important that a function yield a single value for a given input because that is the definition of the word.

Re:Functions are Vectors by tsimionescu on Sunday July 30, 2023 @04:37AM (#36929137)
The point GP was making is that you can also define the function sqrt(x) as a function from reals to pairs of reals, and say that the sqrt(4) is the pair (-2, 2). With a proper definition of squaring a pair of reals, you could even have this be the inverse of the square function (we could define square((x, y)) = x²-xy+y², so square((-2,2))=4-4+4=4).

Of course, these are still functions which take exactlt one element in their input set (the reals for sqrt, or pairs of reals for square) and return for each a single element in their output sets (the pairs of reals for sqrt, or the reals for square).

Re:Functions are Vectors by bigbillheck on Sunday July 30, 2023 @08:21AM (#36930439)
> You will not find this in the literature.

It would have cost you nothing except a minute or so of your time to have refuted yourself before posting: https://arxiv.org/abs/1912.08274 https://arxiv.org/abs/1703.01700

(See also: https://en.wikipedia.org/wiki/Multivalued_function)

Re:Functions are Vectors by cykotic on Sunday July 30, 2023 @09:09AM (#36930826)
A multivalued function is not a function. Hence the need to call it something else. In complex analysis you have branch cuts and things like that. We don’t call something a function that doesn’t have a unique output for a given input.
Re:Functions are Vectors by bigbillheck on Sunday July 30, 2023 @11:02AM (#36931842)
A set-valued function is a perfectly valid kind of function, and a multivalued function in complex analysis is just a set-valued function with certain continuity and other restrictions.
Re:Functions are Vectors by cykotic on Sunday July 30, 2023 @11:20AM (#36932097)
If set up that way then yes it meets the definition of a function. I’m not a complex analyst but I imagine they think of a function from C to C on a given branch rather than multi-function being a function from C to the countable product of C (or however one wants to formally define the set value). I think this because they tend to care about analytic properties and saying function from C to countable product of C includes far too many functions. Saying multifunction will immediately make one think of branch cuts.

They don’t think of Log(z) as a set of values. At least I don’t. I assume one means the principal branch when writing Log(z) unless specifically stated otherwise. Maybe in their mind they do think of an infinite set when seeing Log(z). I’m skeptical of this possibility though.

Re:Functions are Vectors by Tainnor on Monday July 31, 2023 @12:15PM (#36944854)
From the amount of complex analysis I've seen, I think I agree with you.

The insight behind multi-valued functions seems to be that for certain types of functions that seem unambiguous in the real case (roots, logarithms, ...) there's no clear candidate for which one is "the" logarithm function etc. So theorems look more like "let l be a logarithm function".

If you actually want to do complex analysis, it would not be very useful to have a vector valued function (even if that's technically possible) for logarithm etc. because most of the theory is developed for (in particular, differentiable) functions C -> C. So you'd rather just pick a branch.

Re:Functions are Vectors by lying4fun on Saturday July 29, 2023 @09:37PM (#36926836)
> That is the definition of a function, but it's purely a formalism...

Isn’t the function definition meant to be interpreted as “maps consistently to exactly one element of the codomain”? So an ordered pair of R^2 is still one element of R^2

It seems the parent has just mixed up the domain and codomain, because under that assumption he would be right about both the definition and bijectivity

Re:Functions are Vectors by thaumasiotes on Sunday July 30, 2023 @12:33AM (#36927829)
I can't tell what you mean by your emphasis on the word "consistently". Functions are not stochastic; f(y) is f(y) regardless of how many times you ask what f(y) is.

An ordered pair drawn from ℝ² is in some sense a single value. In another sense, it is two values. Which way you want to think about it depends on what you're going to do with it; if you're thinking about square roots of real numbers, it will be more useful to think of it as two values.

> It seems the parent has just mixed up the domain and codomain, because under that assumption he would be right about both the definition and bijectivity

He still wouldn't be right about bijectivity; the condition that an element of the codomain can have no more than one inverse only describes an injective function.

Re:Functions are Vectors by lying4fun on Sunday July 30, 2023 @06:56AM (#36929882)
>is in some sense a single value. In another sense, it is two values.

What I tryed to say is that the sense in which “exactly one element” is used in the definition of function is inclusive of codomain being R^n, so it confused me why you would provide a function that has a codomain of R^2 as something that suggests deviation from the formalism. It just seemed misleading to phrase it that way

I thought consistently would convey the idea I had, nevermind if it doesn’t

My bad about bijectivity, I see it now, you’re right

Re:Functions are Vectors by 0x264 on Sunday July 30, 2023 @06:16AM (#36929671)
Hi thaumasiotes, Mathematician here, and somewhow interested in this discussion. I am curious of your definition of full_sqrt, what would be the value of full_sqrt(-3) ?
Re:Functions are Vectors by Tainnor on Tuesday August 01, 2023 @12:16AM (#36952229)
I feel like you're being technically correct but in a kind of useless way.

Yes, nothing stops you from defining the square root function such that it returns an element of R^2. It's perfectly legal mathematics, functions can map arbitrary domains to arbitrary codomains after all.

But I've never seen it used anywhere. Maybe there is an area where such a definition makes sense... but regular real (or complex) analysis doesn't really normally do such a kind of thing.

The problem is that you want your typical functions like square root (and logarithms, which in the complex case also aren't unique) to be functions R -> R (or C -> C). Otherwise you can't compose them and then everything is kinda weird.

When working in a structure, one often doesn't want to leave that structure and go to another one, but keep the same structure (or at least one that is related in an interesting way, such as a quotient structure). That just leads to more interesting mathematics.

Re:Functions are Vectors by kimburgess on Saturday July 29, 2023 @08:58PM (#36926561)
As others comments have pointed out - you may want to brush up on those definitions. Correct semantics are crucial. They're a form of compression with no/low error correction.

Any claims of injective or surjective properties (and by extension bijection) are moot without the domain and co-domain being specified.

To map math ↦ dev semantics: functions need to be pure, deterministic and declared with strong types. The properties of square root in particular will vary wildly based on what those types are.

Re:Functions are Vectors by tsimionescu on Sunday July 30, 2023 @04:28AM (#36929094)
Are you defining sqrt(x²) to be +x and -x? If you are, then sqrt(x) is indeed not a function.

You could make it a function by defining sqrt : N -> Z×Z, so sqrt(4) = (-2,2), and we're back to the property that any value in the domain (the natural numbers) is mapped to a single value in the co-domain (a unique pair of integers). Of course, this is not the traditional sqrt function that people normally use, since it doesn't obey the property (sqrt(x))² = x (since obviously taking the square of a pair of integers will not return an integer, for usual definitions of squaring).

Note that a bijective function has both this property and the opposite, that for any value in the co-domain there is also a unique value in the domain that maps to it. Sqrt, both in the traditional definition where it only returns positive roots, and in this definition where it returns a pair of roots, is actually also bijective. Squaring is a non-bijective function, though.

Re:Functions are Vectors by adammarples on Monday July 31, 2023 @07:52AM (#36941289)
That's a very good point
Re:Functions are Vectors by daynthelife on Monday July 31, 2023 @03:53PM (#36947883)
The codomain should not be Z×Z — firstly, the square root is usually not an integer, but more importantly, there is not a canonical ordering of the pairs you get, especially if we allow negative/complex inputs. The map we really want is

sqrt: C -> (C×C)/~,

where C is the complex numbers and ~ is the equivalence relation generated by (a,b) ~ (b,a) for all a,b in C.

Re:Functions are Vectors by tsimionescu on Monday July 31, 2023 @04:04PM (#36948031)
You're right, I should have said sqrt : N -> R×R. I don't think the order is a problem, we can define the function such that sqrt(x)={a | a²=x}. Sets are inherently unordered, {-2,2} = {2,-2}.

Of course, this is not a surjective function, but it is a function nevertheless.

Re:Functions are Vectors by daynthelife on Monday July 31, 2023 @10:54PM (#36951770)
The issue with sets is that they don’t capture the notion of multiplicity. One would like to say sqrt(0) = {0,0}, but {0,0} is just equal to {0} as a set. The CxC/~ formalism captures the possibility of multiplicity as well as the fact that the output always has size 2.

As an aside, the notation R x R means ordered pairs of reals. So for your definition, you would instead want 2^R as the codomain (i.e. the set of subsets of R).

Re:Functions are Vectors by cykotic on Saturday July 29, 2023 @09:03PM (#36926585)
Functions can’t be used to handle undefined values either. A function is a mapping, f, from one set to another such that each element of the originating set gets mapped to one and only one element of the target set. This, by definition, requires that all values in the originating set get mapped to something in the target set. So there are no undefined values as such.

Function spaces can’t always be viewed as vector spaces because there may be no concept of addition of functions or a concept of scalar multiplication on the functions that behaves well with whatever notion of addition the functions satisfy.