relu inequality: Nonlinear Function
Created: February 12, 2023
Modified: February 13, 2023

relu inequality

This page is from my personal notes, and has not been specifically reviewed for public consumption. It might be incomplete, wrong, outdated, or stupid. Caveat lector.

Suppose we want a transformer to evaluate the inequality

c=x0,c = x \le 0,

returning c=1c=1 if x0x\le 0 and c=0c=0 otherwise. For integer xx, this can be done with a feedforward ReLU network computing

c=1ReLU(x)+ReLU(x1).c = 1 - \text{ReLU}(x) + \text{ReLU}(x - 1).

Observe that for x1x \ge 1 this is simply c=1x+(x1)=0c = 1 - x + (x - 1) = 0. For x0x \le 0 this is 10+0=11 - 0 + 0 = 1. Thus this expression computes the inequality.

If xx fails to be an integer and we have 0<x<10 < x < 1, then the expression evaluates to c=1xc = 1 - x, which smoothly interpolates between the discrete outcomes of 11 and 00.