• Steve Dice@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    0
    ·
    11 months ago

    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.

  • raoul@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    0
    ·
    11 months ago

    The boolean operator ‘If and only if’ do not have a relation with the program instruction ‘if’.

    The programatic ‘if’ is a jump, not a boolean operator. It do not have truth table.

    In logic:, if and iff can be seen like functions taking two booleans and returning a boolean

    • ‘if a then b’ (noted a -> b): return true if a is false or b is true. Example: ‘if I eat pizza then I fart’ This is true even if I fart all the time (if b is true, we do not care about the value of a) as long as I fart when eating pizza (if a is true, b must be also true)

    • ‘a <-> b’ is equivalent to ‘a -> b and b -> a’: the two should be true at the same time. I can only fart will eating pizza and cannot fart otherwise.