Pure functions? What the heck are those ?!?!

What is the basis for reason? And mathematics?

Moderators: AMod, iMod

Skepdick
Posts: 14366
Joined: Fri Jun 14, 2019 11:16 am

Re: Pure functions? What the heck are those ?!?!

Post by Skepdick »

Averroes wrote: Sat Aug 07, 2021 7:33 pm I am as intellectually honest as the one I am exchanging with.
Are you? Where did I partially quote you?
Averroes wrote: Sat Aug 07, 2021 7:33 pm Besides, I like keeping myself motivated in life. Looking at the blessings that we have been given keep us in a grateful and proactive state. That's much better than complaining when things don't turn out one's way or when one meet "unexpected" things.
Perhaps you want to state your motivations. Intellectual honesty and all?

Or perhaps you want to answer why the same function is not the same as itself?

You know, having cleared the intellectual landscape of any variable assignments.

Code: Select all

>>> def f(x): return x
>>> type(f(None)) == type(f(1))
False
>>>
Last edited by Skepdick on Sat Aug 07, 2021 7:42 pm, edited 1 time in total.
Averroes
Posts: 535
Joined: Thu Jul 20, 2017 8:48 pm

Re: Pure functions? What the heck are those ?!?!

Post by Averroes »

Skepdick wrote: Sat Aug 07, 2021 7:36 pm
Averroes wrote: Sat Aug 07, 2021 7:33 pm I am as intellectually honest as the one I am exchanging with.
Are you? Where did I partially quote you?
Intellectual honesty is not just about partial quote. Don't you agree? Or is that unexpected too for you?
Skepdick
Posts: 14366
Joined: Fri Jun 14, 2019 11:16 am

Re: Pure functions? What the heck are those ?!?!

Post by Skepdick »

Averroes wrote: Sat Aug 07, 2021 7:42 pm Intellectual honesty is not just about partial quote. Don't you agree? Or is that unexpected too for you?
Of course it's not just about that. But in this case it's a necessary, but insufficient condition.

It is indeed unexpected to me, that somebody would begin misquoting me when I am engaging them in good faith.
Averroes
Posts: 535
Joined: Thu Jul 20, 2017 8:48 pm

Re: Pure functions? What the heck are those ?!?!

Post by Averroes »

Skepdick wrote: Sat Aug 07, 2021 7:43 pm
Averroes wrote: Sat Aug 07, 2021 7:42 pm Intellectual honesty is not just about partial quote. Don't you agree? Or is that unexpected too for you?
Of course it's not just about that.
Exactly. That's why I think that if we want to be treated fairly, we must treat others fairly as well. For example, by not having a track record of redefining common words and concepts to suit one's whims and caprices. Otherswise, unexpected things comes one's way.
Skepdick
Posts: 14366
Joined: Fri Jun 14, 2019 11:16 am

Re: Pure functions? What the heck are those ?!?!

Post by Skepdick »

Averroes wrote: Sat Aug 07, 2021 8:01 pm Exactly. That's why I think that if we want to be treated fairly, we must treat others fairly as well. For example, by not having a track record of redefining common words and concepts to suit one's whims and caprices. Otherswise, unexpected things comes one's way.
OK. Now I have sufficient evidence to say it: You are an intellectually dishonest bullshitter. I neither defined nor undefined anything.

I showed you a thing. I used an ostensive definition. It is a reification of the abstract analogue f(x) = x.
Skepdick wrote: Sat Aug 07, 2021 5:19 pm It's not meant to express anything. It stands before you as function! A real-world existent that you can study empirically. It is what it is!

Any adjective you ascribe to it (such as Mathematical or Computational) is entirely subjective.

Code: Select all

def f(x): return x
And then I also pointed out to you that given the standard definition of purity assignment function is NOT pure.
The variable x is not even in scope (the object doesn't exist in the domain of discourse) right until the moment of assignment!
THIS is a side-effect (impurity) disguised in syntax:

Code: Select all

>>> x
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'x' is not defined
>>> x = None
x is a null-pointer and you are (de)referencing it.

I think that's precisely why you are obfuscating.
Averroes
Posts: 535
Joined: Thu Jul 20, 2017 8:48 pm

Re: Pure functions? What the heck are those ?!?!

Post by Averroes »

Skepdick wrote: Sat Aug 07, 2021 8:12 pm OK. Now I have sufficient evidence to say it: You are an intellectually dishonest bullshitter.
That's not very nice. But it's ok, I understand you got something unexpected coming your way. As one may colloquially say, the sh*t has hit the fan!
Skepdick wrote: Sat Aug 07, 2021 8:12 pm I neither defined nor undefined anything.
I didn't accuse you yet of anything, remark! I was just giving an example! Others reading this will understand!!
Anyway, this was a fruitful exchange. No hard feelings please. We are of all here either lovers or much invested in programming and/or mathematics, let's not unnecessarily step on our toes. Thank you for the exchange.
Skepdick
Posts: 14366
Joined: Fri Jun 14, 2019 11:16 am

Re: Pure functions? What the heck are those ?!?!

Post by Skepdick »

Averroes wrote: Sat Aug 07, 2021 8:36 pm That's not very nice. But it's ok, I understand you got something unexpected coming your way. As one may colloquially say, the sh*t has hit the fan!
Colloquially, you might say that.

Formally, I might say that I have received new information about you.

A falsifcation to my hypothesis: that you are charitable.
wtf
Posts: 1178
Joined: Tue Sep 08, 2015 11:36 pm

Re: Pure functions? What the heck are those ?!?!

Post by wtf »

Skepdick wrote: Sat Aug 07, 2021 6:13 am But I will still ask you a yes/no question so as to avoid endless back-and-forth with definitions: do you see x=5 as a pure function?
It's not a function at all, it's a line of code. You haven't shown a function. A function in Python starts with "def". Surely you agree to that. x = 5 is an assignment statement. It could live in a pure function or an impure function. You haven't shown a function.
wtf
Posts: 1178
Joined: Tue Sep 08, 2015 11:36 pm

Re: Pure functions? What the heck are those ?!?!

Post by wtf »

Skepdick wrote: Sat Aug 07, 2021 7:42 am The purpose of the discussion is whether the functions I am pointing out satisfy the definition.

You say "yes - they satisfy it".
I say "no - they don't".
You've convinced me that a function that does not return anything is a corner case of the definition of pure function. It's a small matter in any case.
Skepdick wrote: Sat Aug 07, 2021 7:42 am We seem to be interpreting the definition differently.
I agree with you that a function that doesn't return anything is a corner case of the definition.

Note that in general, a function in a programming language always returns a value. A function that doesn't return a value is sometimes called a procedure. In Python that distinction is not made. In C for example one explicitly declares a function that doesn't return a value as

Code: Select all

void foo() ...
The keyword void signals the caller not to expect a return value.

So the definition of a pure function is ambiguous in Python because of this corner case; but it's not ambiguous in all languages.
Skepdick wrote: Sat Aug 07, 2021 7:42 am That's precisely where we are diverging. The definition only talks about functions which return a value. I am pointing out functions which fail to return a value.
I already said in my earlier post that on reflection, I've come around to your point of view that a Python function that doesn't return a value is a corner case of the definition. The Wiki page on pure functions doesn't consider this case at all, so you have a point. But I already said earlier that I see your point, did you perhaps miss that?
Skepdick wrote: Sat Aug 07, 2021 7:42 am And it appears that you are insisting that the non-return of value (or the return of no value) is a value. That's a tautology.
I already said earlier that you convinced me. Why are you acting like you didn't read what I wrote?

For the record: The Wiki definition of pure function does not discuss the case of a function that doesn't return a value. Some programming languages, such as C, explicitly label these functions with a return value of "void" so that callers don't accidentally expect a return value.

In Python, there is no such distinction. Therefore in Python there is a corner case in the definition of pure function that doesn't cover a function that doesn't return a value.

This seems like a small point, I'm not sure why it concerns you so much. And I'm especially puzzled as to why you started the thread by talking about mathematical functions, since in math all functions are pure functions. All mathematical functions return outputs and the concept of side effect or external state is meaningless.

Skepdick wrote: Sat Aug 07, 2021 3:31 pm Great. So what's the domain of f(x) = x ?
To be mathematically precise, note that in math, a function is characterized by its domain and range as well as its inputs/outputs. So the function f(x) = x defined on the natural numbers is actually a different function than f(x) = x defined on the real numbers.

That's because set-theoretically, a function is a set of ordered pairs (x, f(x)). So the identity function on the reals includes the pair (pi, pi), whereas the identity function on the natural numbers does not include that pair.


Averroes wrote: Sat Aug 07, 2021 3:00 pm
In the Python programming language, even when the keyword "return" is not used in the definition of a function, the function still returns a value! In that case, it returns the value "None". "None" is an object in Python! In Python everything is an object. The value "None" in Python is of the type NoneType. So, technically, every Python function defined in this thread, whether they explicitly used a return statement or not,were returning a value. Hence, they were functions and not procedures!
Good point! Thanks for the clarification.
Skepdick
Posts: 14366
Joined: Fri Jun 14, 2019 11:16 am

Re: Pure functions? What the heck are those ?!?!

Post by Skepdick »

wtf wrote: Sun Aug 08, 2021 3:16 am It's not a function at all, it's a line of code. You haven't shown a function. A function in Python starts with "def". Surely you agree to that. x = 5 is an assignment statement. It could live in a pure function or an impure function. You haven't shown a function.
OK. Wow. This is a massive gap in world-views. From where I am looking it genuinely seems like you do not understand the syntax/semantics distinction!

Given two snippets of Python code:

Code: Select all

x=5
AND

Code: Select all

def set_x_to_5():
      global x
      x = 5
set_x_to_5()
Do you see how/why both snippets mean exactly the same thing?

The syntax is different. The semantics are identical. It's just two different ways of expressing precisely the same computation.

Here is a general function which takes the variable name and value as parameters:

Code: Select all

def assign(name, value): globals()[name] = value
Here is the semantic equivalent to wtf=25

Code: Select all

In [2]: assign('wtf', 25) 
In [3]: wtf
Out[3]: 25
Or can express the exact same thing using metaprogramming/reflection:

Code: Select all

In [1]: import sys
In [2]: setattr(sys.modules[__name__], 'skepdick', 50)
In [3]: skepdick
Out[3]: 50
wtf
Posts: 1178
Joined: Tue Sep 08, 2015 11:36 pm

Re: Pure functions? What the heck are those ?!?!

Post by wtf »

Skepdick wrote: Sun Aug 08, 2021 6:44 am

Code: Select all

x=5
AND

Code: Select all

def set_x_to_5():
      global x
      x = 5
set_x_to_5()
Do you see how/why both snippets mean exactly the same thing?
One's packaged as a function and the other's not. In languages that require declaration of variables (as Python doesn't), the first assignment would throw a compile-time error. You're stretching a point past making one. Why have you chosen this particular hobby horse? Why did you frame it as something having to do with what "mathematicians are always saying," when the entire subject is something that no mathematician would ever talk about?
Last edited by wtf on Sun Aug 08, 2021 7:11 am, edited 2 times in total.
Skepdick
Posts: 14366
Joined: Fri Jun 14, 2019 11:16 am

Re: Pure functions? What the heck are those ?!?!

Post by Skepdick »

wtf wrote: Sun Aug 08, 2021 7:07 am One's packaged as a function and one's not. You're stretching a point past making one.
They are both exactly the same function!

The x=5 syntax just makes that utterly unclear.

x=5 is an impure function. It has side-effects.
wtf
Posts: 1178
Joined: Tue Sep 08, 2015 11:36 pm

Re: Pure functions? What the heck are those ?!?!

Post by wtf »

Skepdick wrote: Sun Aug 08, 2021 7:09 am
wtf wrote: Sun Aug 08, 2021 7:07 am One's packaged as a function and one's not. You're stretching a point past making one.
They are both exactly the same function!

The x=5 syntax just makes that utterly unclear.

x=5 is an impure function. It has side-effects.
x = 5 is not a function. You seem confused about what a Python function is. I suggest you look it up.
Averroes
Posts: 535
Joined: Thu Jul 20, 2017 8:48 pm

Re: Pure functions? What the heck are those ?!?!

Post by Averroes »

wtf wrote: Sun Aug 08, 2021 3:23 am
Averroes wrote: Sat Aug 07, 2021 3:00 pm
In the Python programming language, even when the keyword "return" is not used in the definition of a function, the function still returns a value! In that case, it returns the value "None". "None" is an object in Python! In Python everything is an object. The value "None" in Python is of the type NoneType. So, technically, every Python function defined in this thread, whether they explicitly used a return statement or not,were returning a value. Hence, they were functions and not procedures!
Good point! Thanks for the clarification.
The pleasure was all mine. Mathematics and programming requires razor sharp precision in the use and understanding of language, otherwise we can get easily lost. For example, if someone fails to recognize the difference between a statement and a function definition despite clear explanations provided to them and persists in saying that they are the same, then there is not much we can do. We have to move on.
Skepdick
Posts: 14366
Joined: Fri Jun 14, 2019 11:16 am

Re: Pure functions? What the heck are those ?!?!

Post by Skepdick »

wtf wrote: Sun Aug 08, 2021 7:12 am x = 5 is not a function. You seem confused about what a Python function is. I suggest you look it up.
Holy dumb fuckwaffles! You are tripping up over Python's syntax.

x=5 is EXACTLY THE SAME Mathematical object as assign('x', 5)
Post Reply