this post was submitted on 05 Dec 2024
227 points (93.2% liked)

Science Memes

11442 readers
1764 users here now

Welcome to c/science_memes @ Mander.xyz!

A place for majestic STEMLORD peacocking, as well as memes about the realities of working in a lab.



Rules

  1. Don't throw mud. Behave like an intellectual and remember the human.
  2. Keep it rooted (on topic).
  3. No spam.
  4. Infographics welcome, get schooled.

This is a science community. We use the Dawkins definition of meme.



Research Committee

Other Mander Communities

Science and Research

Biology and Life Sciences

Physical Sciences

Humanities and Social Sciences

Practical and Applied Sciences

Memes

Miscellaneous

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] stevedice@sh.itjust.works 6 points 3 weeks ago* (last edited 3 weeks ago) (2 children)

No, they're not.

Let's assume they are. Let funky function be defined as:

int funky() {
    a=0
    b=1
    if ( a==1 ) {
        b=1
    }
    return(a)
}

Since a==1 if, and only if, b=1, in particular a==1 if b=1. We have b=1, therefore a==1. It follows funky will always return 1 but... it doesn't. QED.

[–] nickwitha_k@lemmy.sdf.org 13 points 3 weeks ago* (last edited 3 weeks ago) (2 children)

I'm pretty sure that funky() would always return 0, as defined. I'll pseudocode that up:

funky takes no args, returns int {
  a is assigned the value 0
  b is assigned the value 1

  test if a is equal to 1, if it is {
    b is assigned the value 1
  }

  return a
}

The if in your function can never be reached, without some weird manipulation of the value of a that breaks variable scoping in most syntaxes.

I think that I see your logic but it is syntactically incorrect:

    if ( a==1 ) {
        b=1
    }

In most syntaxes, this is a conditional execution and value assignment. That is, the code in curly braces only gets executed, if the conditional evaluates as true. If the conditional evaluates as true, the code is executed, assigning the value 1 to the variable b.

It does NOT imply that the assignment of the value 1 to the variable b is a conditional requiring the assignment of the value 1 to the variable b.

Remember: = in most programming is NOT an equality symbol but a value-assigment symbol. It would be nice if people creating the initial syntaxes used something else that is harder to confuse but they didn't.

[–] ikilledlaurapalmer@lemmy.world 10 points 3 weeks ago

Yeah, I’m not sure what the original intent was here. If we’re missing something I’d like to know

[–] stevedice@sh.itjust.works 4 points 3 weeks ago* (last edited 3 weeks ago) (1 children)

Yes, I know, that's the point. Funky is specifically constructed to always return 0. Then we assume "if" and "if, and only if" are equivalent and by following that assumption to its logical conclusion, we deduce that funky returns 1. Therefore, our assumption was incorrect because 0≠1. It follows that "if" isn't equivalent to "if, and only if". Also, it's just a shitpost.

[–] nickwitha_k@lemmy.sdf.org 2 points 3 weeks ago (1 children)

If reading the code as non-programming logic, that conclusion makes sense, yes. However, if, in most syntaxes, is a type of flow control. What it wraps has no meaning to the if statement itself. Reading it through the lens of an interpreter/compiler makes it clear. The statement is approximately:

If and only if a is equal to 1, do the thing {
  The thing is: assign the variable b with the value 1
}

To one not familiar with how programs are executed, it would make sense that the return value could be 1. But understanding how flow control works in programming, makes this interpretation a challenge.

[–] stevedice@sh.itjust.works 4 points 3 weeks ago (1 children)

I don't think you're picking up what I'm putting down. I'm not arguing that the return value can be 1, I'm well aware that it can't — I wrote the function so that it will always return 0. It only returns 1 if we make an incorrect assumption (and mix up semantics with formal logic, but that's another conversation), the incorrect assumption being "if is equivalent to if, and only if"

[–] nickwitha_k@lemmy.sdf.org 2 points 2 weeks ago (1 children)

Sorry! I sometimes get carried away on correctness.

[–] stevedice@sh.itjust.works 2 points 2 weeks ago* (last edited 2 weeks ago)

I mean, making an assumption and arriving to a contradiction is as correct as a proof gets.

[–] ninja@lemmy.world 5 points 3 weeks ago (1 children)

Translating structured logic into spoken language is iffy. (I'm sorry. I couldn't help myself)

The code reads to match OP if stated as: "If and only if the value of 'a' equals 1 then set the value of 'b' to equal one." Placing the conditional at the beginning of the sentence maintains the correct dependency.

[–] stevedice@sh.itjust.works 3 points 3 weeks ago

I agree but it's also what the original meme is doing. I thought we were all shitposting here.