# Minimal subset of $x_1, x_2, …, x_{100}$ that XORs to $y$

Given a 64-bit positive integer $y$ and a set of $100$ $64$-bit positive integers: $X = \{ x_1, x_2, \dots, x_{100} \}$

I want to find a smallest possible $Z = \{z_1, z_2, \dots, z_n\} \subset X$, such that:

$$\begin{align} y = z_1 ⊕ z_2 ⊕ \dots ⊕ z_n \end{align}$$

if such a $Z$ exists.

Clearly there are $2^{100}$ possible subsets of $X$, so iterating through them would take too long.

Does anyone know of, or can anyone think of, some sort of dynamic programming solution or other feasible algorithm?

-

– user2468 Apr 1 '12 at 1:00
@J.D.: No, I think because it's XOR and not addition that it is not NP-Complete.  I'm sure there is a solution that takes advantage of the independence of the bit positions in XOR, I just can't see it. – user1131467 Apr 1 '12 at 1:19

## 1 Answer

If you introduce binary variables $c_i$ that are $1$ when $x_i\in Z$ and $0$ otherwise, you can write

$$y=\bigoplus_ic_ix_i\;.$$

This is a $64\times100$ system of linear equations over the field $\mathbb F_2$ for the $c_i$ that you can easily solve using Gaussian elimination; the number of steps is of the order of a million. If the $x_i$ have full rank $64$, which is almost certain to be the case if they're randomly chosen with uniform distribution, the solution space will have $36$ dimensions, so you just need to enumerate $2^{36}$ different solutions to find the optimal one; this is doable in reasonable time on a present-day computer.

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 21, "mathjax_display_tex": 2, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9361369013786316, "perplexity_flag": "head"}