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

What is the basis for reason? And mathematics?

Moderators: AMod, iMod

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:16 am
Holy dumb fuckwaffles! You are tripping up over Python's syntax.
Python was your own choice of languages. I could make the same argument in a dozen other languages.
Skepdick wrote: Sun Aug 08, 2021 7:16 am x=5 is EXACTLY THE SAME Mathematical object as assign('x', 5)
Whatever, man. I see you didn't look up what a Python function is, and don't know.

Neither of those expressions are mathematical objects. You don't know what those are, either. A mathematical function is a set of ordered pairs.
Skepdick
Posts: 14364
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:19 am Python was your own choice of languages. I could make the same argument in a dozen other languages.
YES! You could make the exact same argument in EVERY PROGRAMMING LANGUAGE.

Because this is not a precise statement about a particular model of computation (Python), this is a general Mathematical statement about ALL models Computation.

x=5 is EXACTLY THE SAME ABSTRACT MATHEMATICAL OBJECT as assign('x', 5)
wtf wrote: Sun Aug 08, 2021 7:19 am Whatever, man. I see you didn't look up what a Python function is, and don't know.
That seems to be the general answer when Philosophers get caught with their pants down.
Last edited by Skepdick on Sun Aug 08, 2021 7:41 am, edited 1 time in total.
Skepdick
Posts: 14364
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:19 am Neither of those expressions are mathematical objects. You don't know what those are, either. A mathematical function is a set of ordered pairs.
Ahahaha. Move the goal posts some more, won't you.

The command x = 5; or assign('x', 5) has the side-effect of mutating memory. It creates/synthesizes/manufactures the ordered pair (x, 5) which is then appended to the set of ordered pairs known as "global variables".

Which is represented in Python as a key-value lookup map { "x" : 5 }

Code: Select all

In [1]: 'x' in globals()
Out[1]: False

In [2]: x = 5

In [3]: 'x' in globals()
Out[3]: True

In [4]: globals()['x']
Out[4]: 5
A set of ordered pairs is not even a function! It's just an array of tuples. It's a data type. Is just an Excell spreadsheet with two columns.
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:23 am That seems to be the general answer when Philosophers get caught with their pants down.
I'm a philosopher now? I'm not sure if I should be insulted or flattered. How do you know I'm even wearing pants?

Skepdick wrote: Sun Aug 08, 2021 7:28 am
The command x = 5; or assign('x', 5) has the side-effect of mutating memory. It creates/synthesizes/manufactures the ordered pair (x, 5) which is then appended to the set of ordered pairs known as "global variables".
You originally asked me to explain what a side effect is, and I gave you an example. Ever since then you've been using my example but forgetting why I showed it, which was in direct response to your question about what is a side effect.

Even if for sake of argument I agreed with whatever point you're trying to make ... what exactly is your point? I'm not sure you even remember anymore.
Skepdick
Posts: 14364
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 11:27 pm I'm a philosopher now? I'm not sure if I should be insulted or flattered. How do you know I'm even wearing pants?
I didn't say you are a philosopher. I pointed out my general observation of the kinds of responses I get from philosophers (who get caught with their pants down).

If the shoe fits...
wtf wrote: Sun Aug 08, 2021 11:27 pm You originally asked me to explain what a side effect is, and I gave you an example.
I know how to conceptualise side-effects in a number of different ways. Thank you very much.

Communitation, global state mutation, information transfer, side effects, causality. Those are all different definitions/conceptions for the exact same empirical phenomenon.
wtf wrote: Sun Aug 08, 2021 11:27 pm Ever since then you've been using my example but forgetting why I showed it, which was in direct response to your question about what is a side effect.

Even if for sake of argument I agreed with whatever point you're trying to make ... what exactly is your point? I'm not sure you even remember anymore.
I am pointing out that function output IS a side-effect. Because function non-output is NOT a side-effect.
output-is-side-effect.png
output-is-side-effect.png (35.66 KiB) Viewed 2997 times
Which is precisely what I said in my original post.
Skepdick wrote: Tue Jul 20, 2021 1:40 pm Inputs/Outputs ARE side-effects!

...

If one takes an extensional view of functions, thereare no such things as pure functions!
Skepdick wrote: Tue Aug 03, 2021 8:11 am I am disagreeing with the distinction between inputs/outputs and side-effects on the grounds that they are the exact same thing, so the distinction is a case of special pleading. The distinction is an (unnecessary) double standard.
wtf
Posts: 1178
Joined: Tue Sep 08, 2015 11:36 pm

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

Post by wtf »

Skepdick wrote: Mon Aug 09, 2021 9:27 am I am disagreeing with the distinction between inputs/outputs and side-effects on the grounds that they are the exact same thing, so the distinction is a case of special pleading. The distinction is an (unnecessary) double standard.
I understand that you think a function return is a side effect. Your definition disagrees with the Wiki definition of a pure function. I wonder why you are not taking this up with them? You can make your comments to the Wiki community on the Talk page at that link.

It's perfectly ok with me if you have your own private definition of a standard technical term. That doesn't change the meaning of pure function, it just means you have your own private definition.
Skepdick
Posts: 14364
Joined: Fri Jun 14, 2019 11:16 am

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

Post by Skepdick »

wtf wrote: Tue Aug 10, 2021 1:53 am I understand that you think a function return is a side effect. Your definition disagrees with the Wiki definition of a pure function. I wonder why you are not taking this up with them? You can make your comments to the Wiki community on the Talk page at that link.

It's perfectly ok with me if you have your own private definition of a standard technical term. That doesn't change the meaning of pure function, it just means you have your own private definition.
Q.E.D - you don't get it. Which meaning of "meaning" are you using? The formal or informal meaning of "meaning"?

In a paradigm where function side-effects are first-class citizens (objects) of the universe of discourse there is no such thing as pure/impure distinction. There happens to be such a paradigm: algebraic effects
Algebraic effects, on which Eff is built, give rise to a uniform representation of all computational effects. Effects are thus first-class citizens of Eff and can be seamlessly combined. There is no need for the do notation, no need for monad transformers, and no need to reshuffle your whole program just to read a global flag.
I am sure you think you understand the meaning of the Wiki definition, but that's just the thing with English. It's open to (mis?) interpretation. And it's even more obvious that this is true since you are classifying as "pure" the exact same real-world function that I am classifying as "impure". Exact same real-world existent - two different judgments about its properties. Weird, eh?

I am taking it up with you because you are the one USING the definition. And you are clearly USING it differently to the way I am USING it.

But, of course. I was just using buzzwords like "algebraic effects". So you are actually blind to the semantic difference between the two different types of effects (in the syntax of Eff):

Code: Select all

effect Fail : empty   (* Equivalent to the type unit -> empty *)
effect Decide : bool (* Equivalent to the type unit -> bool *)
And their equivalent (in the syntax of Python)

Code: Select all

def equal(x): x == x
def g(x): return x == x
Skepdick
Posts: 14364
Joined: Fri Jun 14, 2019 11:16 am

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

Post by Skepdick »

wtf wrote: Tue Aug 10, 2021 1:53 am I understand that you think a function return is a side effect. Your definition disagrees with the Wiki definition of a pure function. I wonder why you are not taking this up with them? You can make your comments to the Wiki community on the Talk page at that link.

It's perfectly ok with me if you have your own private definition of a standard technical term. That doesn't change the meaning of pure function, it just means you have your own private definition.
Let me spare you further verbiage... Having discussed writing/allocating memory ad nauseaum with the x=5 example.

https://en.wikipedia.org/wiki/Effect_system#Examples
Some examples of the behaviors that can be described by effect systems include:

Reading, writing or allocating memory: the effect kind is read, write, allocate or free, and the region is the point of the program where allocation was performed (i.e., each program point where allocation is performed is assigned a unique label, and region information is statically propagated along the dataflow). Most functions working with memory will actually be polymorphic in the region variable: for example, a function that swaps two locations in memory will have type forall r1 r2, unit ! {read r1, read r2, write r1, write r2}.
https://arxiv.org/pdf/1306.6316.pdf
An effect system supplements a traditional type system for a programming language with
information about which computational effects may, will, or will not happen when a piece of
code is executed.
wtf
Posts: 1178
Joined: Tue Sep 08, 2015 11:36 pm

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

Post by wtf »

Skepdick wrote: Tue Aug 10, 2021 9:44 am Which meaning of "meaning" are you using?
That depends on what the meaning of "is" is.
Skepdick
Posts: 14364
Joined: Fri Jun 14, 2019 11:16 am

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

Post by Skepdick »

wtf wrote: Tue Aug 10, 2021 8:31 pm That depends on what the meaning of "is" is.
Yep. Apparently they don't teach polymorphism in Mathematics.

You can't even tell that x=5 is 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: Tue Aug 10, 2021 10:42 pm Yep. Apparently they don't teach polymorphism in Mathematics.
What? Total non sequitur.
Skepdick wrote: Tue Aug 10, 2021 10:42 pm You can't even tell that x=5 is a function.
I'll let you have the last word. You're no longer even attempting to simulate coherence.
Skepdick
Posts: 14364
Joined: Fri Jun 14, 2019 11:16 am

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

Post by Skepdick »

wtf wrote: Tue Aug 10, 2021 11:04 pm
Skepdick wrote: Tue Aug 10, 2021 10:42 pm Yep. Apparently they don't teach polymorphism in Mathematics.
What? Total non sequitur.
Q.E.D! You can't even connect the dots! Even though there's a wikipedia page written in plain English about this stuff.

It depends on what the meaning of "is" is. This implies the verb "is" has multiple possible meanings.
It depends on what the meaning of "+" is. This implies the verb "+" has multiple possible meanings.

Verbs are functions. Functions which have different denotation/meaning for different objects upon which the verb operates is precisely what polymorphism is.

Code: Select all

def +(x: integer, y: integer) -> integer # Addition. As in arithmetic
def +(string, y:string) -> string # Concatenation. As in appending strings
You know - that silly game kids play in primary school.

1+1 = 2 (for base-10 integer types)
1+1 = 10 (for base-2 integer types)
1+1 = 11 (for string types)

Apparently 8 year olds understand polymorphism better than Mathematicians.
wtf wrote: Tue Aug 10, 2021 11:04 pm I'll let you have the last word. You're no longer even attempting to simulate coherence.
Why, thank you for the thinly veiled attempt at courtesy. I am perfectly coherent, thank you. Your parser/lexer must be faulty.
PeteOlcott
Posts: 1514
Joined: Mon Jul 25, 2016 6:55 pm

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

Post by PeteOlcott »

wtf wrote: Tue Aug 03, 2021 3:17 am
Skepdick wrote: Tue Jul 20, 2021 1:40 pm Mathematicians keep talking about "pure" functions.
I wonder if you could name them. I've never heard the term used in math, only in computer science. Never in math, not once. Can you name any of these mathematicians who "keep talking" about something that there is zero evidence they're talking about?

Skepdick wrote: Tue Jul 20, 2021 1:40 pm A pure function is a function that has no external input and no external output (no side-effects). What incoherent nonsense is this?
It's your understanding that's incoherent. According to Wiki, a pure function is " a function that has the following properties:[1][2]

The function return values are identical for identical arguments (no variation with local static variables, non-local variables, mutable reference arguments or input streams).
The function application has no side effects (no mutation of local static variables, non-local variables, mutable reference arguments or input/output streams)."

There's no restriction on external input or output. On the contrary, any function must receive some input (even if null) and must return some output value, even if null. You are misunderstanding side effects.

A pure function in Python3 would be

Code: Select all

def pure_squarer(x) : 
    return x * x
It always returns the same output for the same input, and has no external or side effects.


Skepdick wrote: Tue Jul 20, 2021 1:40 pm An Input is the universe affecting the function.
An output is the function affecting the universe.
Please read the Wiki page on pure functions. Every function takes an input and returns an output. A pure function does so without creating side effects, and without relying on anything outside the function to determine the output.

For example a non-pure function would be

Code: Select all

import datetime()
def not_pure :
    return datetime.datetime.now()
As you can see, the function returns a different value each time it's called, and depends on the time of day.
Skepdick wrote: Tue Jul 20, 2021 1:40 pm Inputs/Outputs ARE side-effects!
For gosh sakes, man. That's nonsense.
Skepdick wrote: Tue Jul 20, 2021 1:40 pm If we use Python as a model of computation this is a pure function, but it does nothing:

Code: Select all

   def f(): pass # Mathematical equivalent unknown 
The only way you could have a pure function by your definition is that if it does nothing. Obviously that's wrong.
Skepdick wrote: Tue Jul 20, 2021 1:40 pm This is NOT a pure function. It has outputs.

Code: Select all

   def g(): return 1 #Mathematical equivalent f() = 1 
That's a pure function. Always returns the same on the same input, no reliance on external state, no side effects.
Skepdick wrote: Tue Jul 20, 2021 1:40 pm This is NOT a pure function. It mandates input.

Code: Select all

   def h(x): pass # Mathematical equivalent unknown 
That's pathetic. How do you manage to have such wrong ideas? That's a pure function.
Skepdick wrote: Tue Jul 20, 2021 1:40 pm This is NOT a pure function - it mandates input and produces output:

Code: Select all

   def j(x): return x. # Mathematical equivalent f(x) = x 
That's a classic example of a pure function.
Skepdick wrote: Tue Jul 20, 2021 1:40 pm This is a pure function. It calculates the answer to 2+2, but doesn't give you the answer.

Code: Select all

   def k(): 2+2 # Mathematical equivalent unknown 
Then it's absolutely useless. Surely you can see that nobody would bother to invent a concept like pure functions if they were no-ops.
Skepdick wrote: Tue Jul 20, 2021 1:40 pm If one takes an extensional view of functions, thereare no such things as pure functions!
So wrong. Read the Wiki page. Read a book.
Skepdick wrote: Tue Jul 20, 2021 1:40 pm Mathematicians, do you even know what you are talking about when you talk about "pure functions"?
I have never seen a mathematician talk about pure functions. Pure functions are part of computer science. Of course if you call computer science a branch of math, as some do, then mathematicians talk about pure functions: namely, those mathematicians who are computer scientists.

I expect the usual incoherent insults in reply. Go.
Good answer !
Flannel Jesus
Posts: 2574
Joined: Mon Mar 28, 2022 7:09 pm

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

Post by Flannel Jesus »

There's a lot of pages so I apologize if I'm rehashing a point that was already made, but...

the OPs definition of a "pure function" is not correct. I say this as an active professional software dev. A pure function absolutely can have inputs and an output. There's been an equivocation of a "side effect" and an output, but those things do not mean the same thing.

__edit

Just noticed the post above mine, which goes into detail on the same point. Good one, glad I'm not the only one seeing this.
Skepdick
Posts: 14364
Joined: Fri Jun 14, 2019 11:16 am

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

Post by Skepdick »

Flannel Jesus wrote: Sat Jul 16, 2022 7:11 pm the OPs definition of a "pure function" is not correct.
Just as well then. You have misunderstood the point - we are not bickering over definitions. That's a stupid game.

I am pointing out a misconception - the sort of stuff that happens in your head. Before you define anything.
Flannel Jesus wrote: Sat Jul 16, 2022 7:11 pm I say this as an active professional software dev. A pure function absolutely can have inputs and an output.
Yes. That is what you have been indoctrinated to parrot. I am perfectly familiar with the status quo on the matter.
Forget the definitions and give your intuition a chance. Everyone knows what a function is. Input -> Magic -> Output.

Now observe THAT an input is an effect ON the Magic. An output is an effect FROM the Magic. As in a causal effect.
Flannel Jesus wrote: Sat Jul 16, 2022 7:11 pm There's been an equivocation of a "side effect" and an output, but those things do not mean the same thing.
It's not equivocation. I am pointing out that distinguishing between outputs and side-effects is special pleading. Distinction without a difference.

Outputs are causal on the environment.
"Side effects" are causal on the environment.

The status quo will tell you that exceptions are side-effects. A function which generates excetptions is not referentially transparent.
And so the 1st function is "pure" and the 2nd function is "impure" (it has side effects).

Absolute nonsense. They are exactly the same function.

Code: Select all

bool f(x){
   if x == 1:
       return true;
   else:
       return false;
}

Code: Select all

void f(x){
   if x == 1:
       throw Yes;
   else:
       throw False;
}
Flannel Jesus wrote: Sat Jul 16, 2022 7:11 pm Just noticed the post above mine, which goes into detail on the same point. Good one, glad I'm not the only one seeing this.
I don't really care about your point. You are peddling the status quo. I understand the status quo.

I am pointing out an error in the status quo.
Last edited by Skepdick on Sat Jul 16, 2022 9:46 pm, edited 2 times in total.
Post Reply