How can we determine if two LWE ciphertexts are equal?

There are ways of determining greater than or less in the example but how do we determine equality when we introduce random error

If you write a circuit/look-up table only using LWE ciphertexts in an exact scheme such as FHEW, you can check equality. If you want to achieve this through an intermediate conversion through an approximate scheme such as CKKS, then you can only achieve equality up to some precision, because by definition CKKS has approximation errors. In the latter case, you could compute |x - y| <= eps instead of x==y.

If I use TFHE, can I calculate the difference between two values and then use that to create a LUT?
Because the function parameter type is NativeInteger, I’m not sure if can determine it as 0.
m = x-y;
auto fp = (NativeInteger m, NativeInteger p1) → NativeInteger {
if (m == 0)
return 1;
else
return 0;
};

// Generate LUT from function f(x)
auto lut = cc.GenerateLUTviaFunction(fp, p);

The problem is that it doesn’t work when the difference is very large.

int p = cc.GetMaxPlaintextSpace().ConvertToInt();  // Obtain the maximum plaintext space

    // Initialize Function f(x) = x^3 % p
    auto fp = [](NativeInteger m, NativeInteger p1) -> NativeInteger {
        if (m == 0)
            return 1;
        else
            return 0;
    };

    // Generate LUT from function f(x)
    auto lut = cc.GenerateLUTviaFunction(fp, p);

    auto ct1 = cc.Encrypt(sk, 1024, FRESH, p);
    auto ct2 = cc.Encrypt(sk, 0, FRESH, p);

    cc.GetLWEScheme()->EvalSubEq(ct1, ct2);

    auto ct_cube = cc.EvalFunc(ct1, lut);


    LWEPlaintext result;

    cc.Decrypt(sk, ct_cube, &result, 2);

    std::cout << "Evaluated = " << result << std::endl;

It works correctly with cc.Decrypt(sk, ct_cube, &result, p). Also recall that you are computing x - y % p, so if for instance, p = 8, then the expected result is 1 for x = 1024 and y = 0.

Is the value of p modifiable? The documentation on GitHub says that it can be supported up to 8 using the LUT method.

It is the same answer as in your previous question Is there a way to make the plaintext modulus greater than 8 in GenerateLUTviaFunction?.