When we write a mathematical formula, the rule $a=42$ (when we say let $a=42$) and testing them (when we write something like $\ldots \mathrm{if} x=42$) is written in a same equal sign. I think that both of them are representing some relation. However, while programming, we write =
for the first circumstance and ==
for the second, and ==
is actually the infix representation of the equivalent testing function. Should they be treated as the same thing?
Previous question:
Are programming languages confounding relations and functions?
p.s. I have been asking this a few hours ago on StackOverflow, but they told me that it was on a wrong venue.
For example, the equivalent sign =
has a lot of meanings, including returning a boolean value that tests whether to expressions are equal to some extent, setting up a rule that both side are equal, and assign the right side to the left side. And notations such as <
and ||
are generally parsed as boolean operators. What's more, they do not distinguish predicates and boolean functions.
In my opinion, this is not a very elegant way to treat the 'rules'. I think notations like ≤
should be thought to be a relation, which means a≤b
implies $(a,b)\in R_\leq$, where $R_\leq \subset S^2$ and $S$ is the domain of $a$ and $b$. Mathematically, ≤
is not a function at all (If it is, it should be something maps from a subset of $S^2$ to $\{True, False\}$). It is just representing some rules.
However, while programming, we generally do not realize the difference between them. We may consider k = a < b
as a simpler way to write something like k = True for a<b, False otherwise
. However, I believe that this makes things confusing in some circumstances, for example, the use of =
.
I have seen a lot of imperative and functional language that do not seem to respect these differences. Am I correct in this point of view? Is there a better way to solve this?
<=
should mean the same as mathematical $\leq$. That's why I'm saying your expectations are the issue. Programming languages are not equivalent to the language of mathematics. $\endgroup$ – Raphael♦ Oct 14 '17 at 10:55:=
, too. And, just to skrew with us, different PLs mean different things by==
, and some have===
to compensate. $\endgroup$ – Raphael♦ Oct 14 '17 at 11:15