← Back to context

Comment by nomel

13 hours ago

For the downvoters, I think giving examples of what's NOT a function would start an interesting conversation, especially if you don't know how it could possibly be interesting!

In the mathematical sense, all functions are relations, but not all relations are functions.

  • What are relations, if not an indicator function of a cartesian product?

I think it depends on what you mean by "is a function". You can think of a constant, `x` as `x_: () -> {x}` (i.e. everything can be indirected). It could be argued that this is "philosophically" "useful" since getting (using) the value of `x`, even as an actual constant, requires at the least loading it as an immediate into the ALU (or whatever execution unit).

Even non-functional relations can be turned into functions (domain has to change). Like a circle, which is not a function of the x-axis, can be parameterized by an angle theta (... `0 <= theta < 2pi`)

  • That we can add structure to something doesn't mean the something is the structure. Part of the problem is op didn't define their domain. Is a civil war a function? A dog? Okay, keep it within math/programming, fair enough. A set is not a function. It just isn't. Can you wrap it in a function that maps NULL->set()? Sure, but that is a different thing. It is a function that returns a set, it is not a set. Is 3 a set because I can construct {3}? No, 3 is a natural number, which in that construct is an element of the set. A group is a set of elements with a certain properties (binary op, unity/neutral element, inverse, etc). That doesn't make the group equal to a field (the elements might be members of a field, such as the reals). It is composed of elements of a field. Different things.

    I'm taking a more mathematical than programming stance here, but op didn't define their domain, and all this originally came from math, so I'm comfortable with that choice.

    But, take rand(), which programmers call a function. Is that a function? Certainly not in the mathematical definition, which requires a unique output for every input. We can use your null wrapper to force it to take an input, but the codomain is not a one-to-one mapping, to say the least.

    Or even take an array. I disagree it is a function. A const array, sure. My arrays tend to mutate, and there goes that 1->1 mapping.

For me, a x86 interrupt service routine that services a hardware interrupt[1] doesn't strike me as something I'd consider a function. It shouldn't return a value, and it typically has side effects. So why is it a function?

I mean trivially you could say it's a function from (entire machine state) to (entire machine state), but typically we ignore the trivial solution because it's not interesting.

[1]: https://alex.dzyoba.com/blog/os-interrupts/

Take a parabola and rotate it 90 degrees. The forumula for that is not a function of the x axis: it has two values for all but one point on the curve.

not a downvoter (actually, an upvoter), so grain of salt, but in my experience people cannot stand this framing. my best guess is that they dislike how impractical it is. obviously it's too abstract to be useful for most practical application. but that doesn't make it any less true.

it's a bit like saying "everything is a process", or "everything is a part of the same singular process that has been playing out since observable history". there's some interesting uses you can get out of that framing, but it's not generally applicable in the way that something like "all programs are unable to tell when a process will halt" is.

but if you really want to harvest the downvotes, I haven't found a better lure than "everything, including the foundations of mathematics, is just a story we are telling each other/ourselves." I know it's true and I still hate it, myself. really feels like it's not true. but, obviously, that's just the english major's version of "everything is a function".

I didn't downvote but I'd be interested to know what the domain is here -- I'm not going to play dumb and be like, 'rocks are not functions', but I'm not sure exactly what class of thing you're asking for examples of.

  • I think it's just that you can make alternative (to set theory) formalizations of mathematics in terms of functions and in consequence anything that is thinkable of in terms of mathematics (which includes all computation).

Closures and fexprs

  • Well a closure is a kind of a record with a function hiding inside it and a record is a function which returns its contents.

    An fexpr is a function.

    • If you extend the definition of functions to include state, sure, closures are functions. It would be more correct to call them procedures though, which are a superset of functions and operators with side effects.

      > An fexpr is a function.

      Try to implement a short circuiting logical `and` operator as a function :-)