Differentiability of BitXor function

In summary, "BitXor" is a function used in solving the game of Nim, which takes the XOR of each pair of terms and forms a new number. It can only be applied to integers and not general real numbers. However, there is a way to extend the function to all real numbers, creating the "RealBitXor" function. This function is not differentiable for some values of c, and has issues with ambiguity and continuity. It is primarily a mathematical concept and not easily defined in terms of computer representations of numbers.
  • #1
matiasmorant
39
0
in many programming languages there is a function of two variables called BitXor (which is also known as nim-sum, since it is used in solving de nim game) which represents each number as a string of its binary digits and then takes the Xor of each pair of terms, forming a new number.

For Example :

5*7= 1 0 1 * 1 1 1 (binary) =0 1 0 (binary) = 2

(where '*' is the BitXor operator)

and 2.5*1.5=10.1*1.1 (binary)=11(binary)=3


Ok. So let f(x)=c*x (where '*' is the BitXor operator and c a real number).

is f differentiable??
 
Physics news on Phys.org
  • #2
"BitXor" can be applied only to integers, not to general real numbers. Since the domain is discrete, the derivative cannot be defined and your question does not make sense.
 
  • #3
HallsofIvy said:
"BitXor" can be applied only to integers, not to general real numbers.

yes,I know that. but it's simple to see how to extend the function to all real numbers, that's why I gave the example 2.5*1.5=10.1*1.1(binary)=11(binary)=3. I don't see there is any problem in doing that, it seems pretty straight forward. we can call it the realbitxor function, or whatever.

here is a code for the 'RealBitXor' function, written for mathematica:

RealBitXor[x_, y_] := N[FromDigits[BitXor[First[#], Last[#]] &[
PadRight[
{ArrayPad[
First[RealDigits[Min[x, y],
2]], {Last[RealDigits[Max[x, y], 2]] -
Last[RealDigits[Min[x, y], 2]], 0}],
First[RealDigits[Max[x, y], 2]]}
]
], 2]/2^Length[First[PadRight[
{ArrayPad[
First[RealDigits[Min[x, y],
2]], {Last[RealDigits[Max[x, y], 2]] -
Last[RealDigits[Min[x, y], 2]], 0}],
First[RealDigits[Max[x, y], 2]]}
]]] - Last[RealDigits[Max[x, y], 2]]]

not very tidy, but well... and I didn't take the signs into account, but it's correct for positive real numbers.

if you graph the function f(x)=c*x, you will see that it is differentiable for some values of c; while it looks like a fractal for some others, which amazed me.


for the particular case where c=0; f(x)=x and f'(x)=1. obvious.
and for integer values of c, it seems to be differentiable by parts
 
Last edited:
  • #4
Between 0.0000 and 0.1111111...
we can only express 2^n numbers. The only numbers we can express exactly in binary have 2^n in the denominator. To be on the safe side, the precision for the domain should be several more digits (3 binary digits?) than the precision for taking the derivative. What you've done may work well.

I would trust a difference quotient, closely related to a derivative, more thoroughly. It is intended for discrete domains.

I only have WolframAlpha.com, not Mathematica, but I'm sure the pictures/fractals are cool.
 
  • #5
matiasmorant said:
yes,I know that. but it's simple to see how to extend the function to all real numbers, that's why I gave the example 2.5*1.5=10.1*1.1(binary)=11(binary)=3. I don't see there is any problem in doing that, it seems pretty straight forward. we can call it the realbitxor function, or whatever.

It's an interesting idea. However, you need some additional work to make the definition consistent.
For example, 1.000... and 0.1111... (in binary) both represent the same real number (1).
Then 1.000... xor 0.111... = 1.111... = 2,
but 0.111... xor 0.111... = 0.000 = 0, which is a contradiction.
 
  • #6
0.1111... = 1.0 ??
The regular decimal system has the same issue. Considering computers don't store an infinite number of digits whether decimals or binary, this shouldn't be a major issue.
 
  • #7
nickalh said:
0.1111... = 1.0 ??
The regular decimal system has the same issue. Considering computers don't store an infinite number of digits whether decimals or binary, this shouldn't be a major issue.

I see your point, but I was considering the original question as a mathematical one (with the programming part just to confirm/disprove OP's hypothesis). Notions of continuity and differentiability don't make much sense to me when working with numbers represented by computers.
 
  • #8
nickalh said:
0.1111... = 1.0 ??
The regular decimal system has the same issue. Considering computers don't store an infinite number of digits whether decimals or binary, this shouldn't be a major issue.
This is a huge issue, and it destroys the concept of differentiability of this function. A function that is nowhere continuous (and this one is) is not differentiable.

That 0.111...2 = 1.02 introduces a huge ambiguity in the definition of this function. Example: What is c*x, where * is our "real bit xor" operator, for c=1/3, x=1/4? In binary, c is 0.01(01)... An ambiguity exists for x: do we represent it as 0.01 or 0.001(1)... ? We need to pick a rule for terminating binary numbers so that our function is well-defined. There are two possibilities:
  • Use the terminating representation for x.
    With this choice, c*x=0.01(01)...*0.01=0.0001(01)...=1/1210.
  • Use the repeating representation for x.
    With this choice, c*x=0.01(01)...*0.001(1)...=0.01(10)...=5/1210.

With regard to differentiability, it doesn't really matter which choice is made. The function is discontinuous at x=1/4. A number slightly less than 1/4 will have a representation that starts with 0.0011, so 1/3 bitxor (1/4-ε) is approximately equal to 5/12. A number slightly greater than 1/4 will have a representation that starts with 0.0100, so 1/3 bitxor (1/4-ε) is approximately equal to 1/12. Make epsilon approach zero and those "approximately equal to" become exact. There is a discontinuity at x=1/4. Similarly, there is a discontinuity at every number that has a terminating binary representation. Since the set of numbers with a terminating binary representation is a dense subset of the reals, this function is nowhere continuous.
 
Last edited:

FAQ: Differentiability of BitXor function

1. What is the BitXor function?

The BitXor function, also known as the bitwise exclusive OR (XOR) function, is a logical operation that compares two binary numbers and returns a 1 if the bits are different, and a 0 if they are the same. It is denoted by the symbol "^".

2. Is the BitXor function differentiable?

No, the BitXor function is not differentiable. Differentiability requires that a function have a well-defined slope at each point, but the BitXor function has a discontinuous slope at every point, making it non-differentiable.

3. Why is the BitXor function not differentiable?

The BitXor function is not differentiable because it is a discontinuous function. This means that there is a sharp change or jump in the output for a small change in the input. In the case of the BitXor function, a small change in the input can result in a large change in the output, making it impossible to define a slope or derivative at any point.

4. Can the BitXor function be approximated by a differentiable function?

Yes, the BitXor function can be approximated by a differentiable function using a variety of techniques such as piecewise linear interpolation or smoothing functions. However, these approximations may not accurately represent the behavior of the function, especially in cases where the input values are close to each other.

5. Are there any practical applications of the BitXor function?

Yes, the BitXor function has various applications in computer science and digital electronics. It is commonly used in cryptography for encrypting and decrypting data, as well as in error correction codes for detecting and correcting errors in data transmission. It is also used in computer graphics and image processing for operations such as blending and filtering.

Similar threads

Replies
1
Views
1K
Replies
6
Views
1K
Replies
2
Views
2K
Replies
1
Views
1K
Replies
2
Views
2K
Replies
2
Views
2K
Back
Top