help to change an equation to remove an undefined error

the first thing that comes to mind is adding a very small number to the denominator to prevent it from becoming 0

let x=a-b

x / ( |x| + 0.0001 )

then when doing calculations you can basically ignore that small number

Or you can use a simple piecewise function to take care of the extreme case
The function you want, also know as sign(a-b), is discontinuous at x=0.

Addition, subtraction, multiplication, division (except by 0), and the absolute value function are all continuous  (as are many other standard functions).   And the composition of continuous functions is continuous.

So you'll never be able to produce the expression sin(a-b) using a combination of any of those operations and functions which is defined everywhere.   As you noticed, if you allow division by expressions which might equal zero then you can come close but your expression will be undefined at those points where you allowed division by zero.

**Edit:** If you allow the floor() function which is already discontinuous, then you can do something like sign(x) = floor((2+|2+x|-|x|)/4) - floor((2+|2-x|-|x|)/4).    Just replace x with (a-b) for your specific case.
Why do you want to remove the undefined error? It's perfectly sensible to keep it.

The function you deceived (technically called the "sign" function, but not to be confused with the "sine" function) makes perfect sense with the error. Think about it like this:

You want the function to return a "sign" indicating which number is larger than the other, if they are equal then this question makes no sense and an error is rightly returned.

If you need a function that say, returns 0 when they are equal, just use a piecewise:

signoreqaual(a, b) = (a-b)/|a-b| if a ≠ b, or 0 if a=b

Likewise, if you want a function that returns +1 if one is greater than the other, or 0 otherwise:

greaterthan(a, b) = 0.5 + ((a-b)/|a-b| if a ≠ b, or -1 if a=b)/2

Or simply:

greaterthan(a, b) = 1 if a>b, otherwise 0

0 like 0 dislike