How do you symbolize something is not equal to something else? What mathematical codeset is the symbolism from?
May 20, 2004 2:00 PM   Subscribe

I often see the idea "[this] is equal/equivalent to [that]" expressed in shorthand as [this] == [that]. That's pretty easy to grasp, and I've assumed that the double = is some sort of coder/geek thing.
But what about "[this] is not equal/equivalent to [that]?" Is it !=, or would that be =|= or =/=? And what computer or mathmatical codeset is this pulled from?
posted by me3dia to Writing & Language (23 answers total)
It dates at least as far back as C, and is also used in C++, Perl, and a big mess of other related languages...

!= is not equals. == is equals. = alone is the assignment operator.
posted by profwhat at 2:03 PM on May 20, 2004

Best answer: Ah, looks like it goes as far back as "B", the little-discussed predecessor to C:

== equal to (".EQ." to Fortraners)
!= not equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to

posted by profwhat at 2:11 PM on May 20, 2004

Response by poster: I had a feeling this would be a quick answer. Thanks, profwhat.

I'm not a coder, so it was always a wonder to me. I've often been surprised that there's no ASCII character code for a diagonal-slashed equal sign.
posted by me3dia at 2:18 PM on May 20, 2004

the = versus == is to avoid inadvertantly making x be 3 (x=3) when you want to say "if x is 3" (if x==3). I've also seen this addressed by using "< - and ->" as assignment operators.

For "x ain't 3," I've seen x != 3, x .ne. 3 or x .neq. 3, and x <> 3 or x >< 3, depending on the software.
posted by ROU_Xenophobe at 2:18 PM on May 20, 2004

ROU's dropping some FORTRAN on us!
posted by dogwelder at 2:25 PM on May 20, 2004

!= and <> are the common ones.

In C++ -> is a pointer assignment.
posted by falconred at 2:30 PM on May 20, 2004

I'll occasionally also see people use s/foo/bar/ in chat, which represents substituting the word "bar" for "foo" in a previous sentence. It's used alot in Perl.

s/alot/a lot/
posted by waxpancake at 2:54 PM on May 20, 2004

The s/foo/bar/ is much older than Perl. It goes at least as far back as ed, the command line editor from UNIX. I don't think that the use of /= and == come from ancient FORTRAN. The original FORTRANs used .EQ. and .NE. as in ROU_Xenophobe's examples. My guess is that you had to wait until after people stopped using punch cards for the introduction of !=, <>, and stuff.
posted by rdr at 3:55 PM on May 20, 2004

A lot of scripting languages like Perl use "eq" and "ne" instead if you're comparing strings rather than numbers. But you generally only run into that when your code doesn't work -- because you forgot that fact.
posted by smackfu at 4:30 PM on May 20, 2004

Didn't Pascal and its successor languages (Modula-n, Oberon) use := as the equality operator?

<> is the old BASIC operator for inequality. In Perl, it's an infix operator to identify an input stream (eg ).

I am puzzled though. I would swear that using != as hacker shorthand is much, much more common than ==.

posted by i_am_joe's_spleen at 5:33 PM on May 20, 2004

These are the symbols I used the first time I studied boolean logic. Notice the corner shaped symbol for NOT.
Since the symbol is not available on the US keyboard, I think ! was chosen to replace it. Hence, we have != as "NOT Equal to".
posted by MzB at 5:41 PM on May 20, 2004

Don't forget e.g. MATLAB: ~=.

~ is popular for 'not' in some circumstances, even C (although there it's logical not).

Joe's Spleen: The := operator is assignment in Pascal, not the equality test.
posted by tss at 5:59 PM on May 20, 2004

My guess: APL.
posted by five fresh fish at 8:48 PM on May 20, 2004

PHP has a === sign as well. It matches values and object type (I think).
posted by lkc at 9:18 PM on May 20, 2004

I realized a little while back that I was using '==' to imply equivalence in every day IM conversations with non-geeks, without even considering its specialized nature.
posted by Space Coyote at 11:32 PM on May 20, 2004

Thank you, tss: it's been a long, long time since I had anything to do with WirthSpawn.
posted by i_am_joe's_spleen at 11:58 PM on May 20, 2004

Personally I have to say that I prefer <> as inequality, and I occasionally find that my PHP isn't working because I've decided it was time to reintroduce it. Oops. ;)

When I'm writing stuff for non techs to read i do tend to use =/= because it's often more obvious and readable to people with high school maths knowledge.
posted by twine42 at 1:07 AM on May 21, 2004

As a side, a lot of programmers can make a mistake with test and assignment. Consider the line:

if (a == 3) { print "YES!"; }

this will (in Perl) print "YES!" if a is equal to 3. But if you accidently put only one = like so:

if (a = 3) { print "a is 3"; }

then it'll assign 3 to a, consider that true and always print "YES!" for any value of 3.

To counter this, programmers flip the test the other way around:

if (3 == a) { print "YES!"; }

which works correctly. The difference being that if you accidently use

if (3 = a) { print "YES!"; }

the compiler will spew out an error because you can't assign a to the number 3.
posted by ralawrence at 2:59 AM on May 21, 2004

Whoops, the second line is wrong. Should say "YES!" instead of "a is 3"
posted by ralawrence at 3:00 AM on May 21, 2004

"To avoide the tediouse repetition of these woordes: is equalle to: I will settle as I doe often in woorke use, a paire of paralleles, or gemowe [twin] lines of one lengthe: =====, bicause noe .2. thynges, can be moare equalle." --Robert Recorde, The Whetstone of Witte (1557).
posted by MzB at 4:33 AM on May 21, 2004

Last November, there was an attempt to introduce a "backdoor" into the Linux kernel. The following snippet of code was discovered:

if ((options == (__WCLONE|__WALL)) && (current->uid = 0)) retval = -EINVAL;

(For info, _WCLONE and _WALL are boolean flags, and | means boolean OR. && is boolean AND.)

If you don't read this carefully, it appears to read "If either the _WCLONE or _WALL flag is set, and the current process is owned by root, then return -EINVAL."

It actually says "If either _WCLONE or _WALL are set, then assign the current process to be root." An easy one to miss, and very sneaky.
posted by salmacis at 5:33 AM on May 21, 2004

MzB's little corner-shaped symbol is from the EBCDIC character set, used on IBM mainframes. Many languages on these mainframes use (corner)= instead of !=.

Also, EBCDIC contains a cent sign, which I find much more useful for adding my $0.02.
posted by Daddio at 10:59 AM on May 21, 2004

/= is from lisp, in case anyone was wondering....
posted by electro at 11:14 AM on May 21, 2004

« Older 25 year old B&W film. Can I use it? What to expect...   |   What should I look for in a cat sitter? Newer »
This thread is closed to new comments.