0

In the lecture for Week 1, Professor Malan said that in an if statement, the third boolean expression (else if (x ==y)) is redundant or implied, since logically, if it is false that a number is neither greater than nor less than another number, it must be equal to that number.

But I wondered (just logically) is it possible that x could be a complex number, of the form z = x + iy, where the real number x is the real part of z and the real number y is the imaginary part of z and is traditionally plotted "in a rectangular coordinate system called the complex plane" (Briggs, William L.. Calculus: Early Transcendentals. Pearson Education. p. C-1) or displayed in an an Argand diagram which is a plot of complex numbers as points (which is the same thing)?

In that case, then is there another possibility that makes it logically possible for x to not equal y, in the case that it is neither greater than nor less than, but is rather located on the complex plane?

So in this case, am I right in thinking that in order to omit the third boolean expression (else if (x==y)), we have to assume that x and y are real numbers on the real number line, otherwise we may not capture the possibility of it being complex?

If statement example from lecture

1

That example doesn't say what data type x and y are, but generally you can assume that numerical variables are real numbers in programming, unless specified otherwise.

There is a way to work with complex numbers in C, but you'd only use it for applications specific to complex numbers. Also, if x and y were complex, x < y isn't defined in the standard complex.h library, so that code would not compile.

| improve this answer | |
0

in a c compiler, to treat two numbers as complex we must define them as such, if you have knowledge about complexes you will know that the real numbers are part of the complexes (R is a subset of C), it is an extension of the real ones where there is a solution for negative roots, but we lose the property of the order, therefore we cannot compare with ">" or with "<", it doesn't make sense, we can only compare its norm or module, which is a real number. Maybe you mean if a complex number has a real and imaginary part, to check crazy theory, we just have to write a program and see what happens, I wrote this little program so you can see that it doesn't work:

#include <stdio.h>      /* Standard Library of Input and Output */
#include <complex.h>    /* Standard Library of Complex Numbers */

    int main(void)
    {
    
        double complex z1 = 1.0 + 3.0 * I;
        double complex z2 = 1.0 - 4.0 * I;
    
        if (z1 < z2)
        {
            printf("z1 is less than z2\n");
        }
    
        else if (z1 > z2)
        {
            printf("z1 is greater than z2\n");
        }
    
        else
            printf("z1 and z2 are complex\n");
    
        return 0;
    }

The output is:

~/ $ make complexc
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow    complexc.c  -lcrypt -lcs50 -lm -o complexc
complexc.c:10:12: error: invalid operands to binary expression ('_Complex double' and '_Complex double')
    if (z1 < z2)
        ~~ ^ ~~
complexc.c:15:17: error: invalid operands to binary expression ('_Complex double' and '_Complex double')
    else if (z1 > z2)
             ~~ ^ ~~
2 errors generated.
<builtin>: recipe for target 'complexc' failed
make: *** [complexc] Error 1
| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .