A programming boolean algebra question

The question

For all integers a,ba,b between [231,231][-2^{31}, 2^{31}], with the operators +,,×,ab,/,,÷+,-,\times, a^b,/,\setminus,\div are defined as follows:

a+b=max(231,min(a+Zb,231))ab=max(231,min(aZb,231))a×b=max(231,min(ab,231))ab=max(231,min(aaaab,231))a/b=max(231,min(ab,231))ab=max(231,min(ab,231))a÷b=max(231,min(round(ab),231))\newcommand{\ceil}[1]{\lceil #1 \rceil} \newcommand{\floor}[1]{\lfloor #1 \rfloor} \begin{aligned} a+b&=\max(-2^{31}, \min(a+_\mathbb{Z}b, 2^{31}))\\ a-b&=\max(-2^{31}, \min(a-_\mathbb{Z}b, 2^{31}))\\ a\times b&=\max(-2^{31}, \min(ab, 2^{31}))\\ a^b&=\max(-2^{31}, \min(\floor{\underbrace{aaa\dots a}_b}, 2^{31}))\\ a / b&=\max(-2^{31}, \min(\ceil{\frac{a}{b}}, 2^{31}))\\ a\setminus b&=\max(-2^{31}, \min(\floor{\frac{a}{b}}, 2^{31}))\\ a\div b&=\max(-2^{31}, \min(\operatorname{round}({\frac{a}{b}}), 2^{31}))\\ \end{aligned}

where operators with subscript Z\mathbb{Z} denote the default operator of integers. the result of the operators will give a result as an integer within the range [231,231][-2^{31}, 2^{31}]. For example the operators behave like the following table

aabba+ba+baba-ba×ba\times baba^ba/ba/baba\setminus ba÷ba \div b
231-2^{31}2312^{31}0231- 2^{31}231- 2^{31}2312^{31}-1-1-1

The question is, using any constant between [231,231][-2^{31},2^{31}] and operators +,,×,ab,/,,÷+,-,\times, a^b,/,\setminus,\div defined above, construct all comparison and logic operators on integers between [231,231][-2^{31},2^{31}] that will output 0,10,1 only, which represent a false or true result respectively. The operators to construct are ,≢,<,,,>,¬,,\equiv,\not\equiv,<,\le,\ge,>,\neg,\lor,\land, which represent equals, not equals, less than, less than or equal, greater than or equal, greater than, logic not, logic or and logic and respectively, that is

ab={1(a=b)0(otherwise)a≢b={1(ab)0(otherwise)a<b={1(a less than b)0(otherwise)ab={1(a less than or equal b)0(otherwise)ab={1(a greater than or equal b)0(otherwise)a>b={1(a greater than b)0(otherwise)¬a={1(a=0)0(otherwise)ab={1(a0 or b0)0(otherwise)ab={1(a0 and b0)0(otherwise)\begin{aligned} a\equiv b &= \begin{cases} 1&(a=b)\\0&(\text{otherwise})\end{cases}\\ a\not\equiv b &= \begin{cases} 1&(a\neq b)\\0&(\text{otherwise})\end{cases}\\ a < b &= \begin{cases} 1&(a\text{ less than }b)\\0&(\text{otherwise})\end{cases}\\ a \le b &= \begin{cases} 1&(a\text{ less than or equal }b)\\0&(\text{otherwise})\end{cases}\\ a \ge b &= \begin{cases} 1&(a\text{ greater than or equal }b)\\0&(\text{otherwise})\end{cases}\\ a > b &= \begin{cases} 1&(a\text{ greater than }b)\\0&(\text{otherwise})\end{cases}\\ \neg a &= \begin{cases} 1&(a=0)\\0&(\text{otherwise})\end{cases}\\ a \lor b &= \begin{cases} 1&(a\neq 0 \text{ or } b\neq 0)\\0&(\text{otherwise})\end{cases}\\ a \land b &= \begin{cases} 1&(a\neq 0 \text{ and } b\neq 0)\\0&(\text{otherwise})\end{cases}\\ \end{aligned}

For example the operators should behave like the following table

aabbaba\equiv ba≢ba\not \equiv ba<ba < baba \le baba \ge ba>ba > b¬a\neg aaba\lor baba \land b

Story behind

During secondary school I was making games using twf (an unofficial name I gave to the game making feature inside Twilight Wars, a Taiwan online flash game, where twf is the file extension it used), I developed quite a number of techniques to bypass its limitations and optimize the flow, and made a website twftechniques with my friends. In particular, there was a hack to do branching in twf since there was no if-else support until very late stage. For example when we are placing an NPC ch0001 depending on some boolean value x, that is x either 0 or 1, we can do it by

A.0 = (0,0)
A.1 = (1,1)
move ch0001 to A.{x}

Twf will replace the {x} with the actual value of x, so when x is 0, it will move ch0001 to (0,0), and when x is 1, it will move ch0001 to (1,1). See, no if is needed, but we achieved branching here!

However, twf only supported arithmetic operators on integers, we could not do arithmetics on comparison result nor logic calculation, there is no such thing bool b = z && (x > y) || (j != k) in twf, not even bool b = x == y , unlike what we can do in modern programming language. Therefore I developed some techniques to do boolean algebra in terms of integers and ordinary arithmetics only, and this is the origin of the question.


The answer is actually quite short

¬a=1a2/231ab=(ab)2/231ab=(a2+b2)/231ab=¬(ab)a≢b=1(ab)a<b=(ba)/231a>b=(ab)/231ab=1(a>b)ab=1(a<b)\begin{aligned} \neg a &= 1 - a^2/2^{31} \\ a\land b &= (a*b)^2/2^{31} \\ a\lor b &= (a^2+b^2)/2^{31}\\ a \equiv b &= \neg(a-b)\\ a \not \equiv b &= 1 - (a\equiv b)\\ a < b &= (b-a)/2^{31}\\ a > b &= (a-b)/2^{31}\\ a \le b &= 1-(a>b)\\ a \ge b &= 1-(a<b) \end{aligned}