/** @brief Test if dual SVP reduction returns reduced basis. @param A input lattice @param b shortest dual vector @return */ template <class ZT> int test_dsvp_reduce(ZZ_mat<ZT> &A, IntVect &b) { IntMatrix u; int d = A.get_rows(); Float normb; if (dual_length(normb, A, b)) { return 1; } int status = lll_reduction(A, u, LLL_DEF_DELTA, LLL_DEF_ETA, LM_WRAPPER, FT_DEFAULT, 0, LLL_DEFAULT); if (status != RED_SUCCESS) { cerr << "LLL reduction failed: " << get_red_status_str(status) << endl; return status; } IntMatrix empty_mat; MatGSO<Integer, Float> gso(A, empty_mat, empty_mat, GSO_INT_GRAM); LLLReduction<Integer, Float> lll_obj(gso, LLL_DEF_DELTA, LLL_DEF_ETA, LLL_DEFAULT); vector<Strategy> strategies; BKZParam dummy(d, strategies); BKZReduction<Float> bkz_obj(gso, lll_obj, dummy); bool clean = true; bkz_obj.svp_reduction_ex(0, d, dummy, clean, true); status = bkz_obj.status; if (status != RED_SUCCESS) { cerr << "Failure: " << get_red_status_str(status) << endl; return status; } Float norm_sol; Integer zero; zero = 0; IntVect e_n(d, zero); e_n[d - 1] = 1; if (dual_length(norm_sol, A, e_n)) { return 1; } Float error; error = 1; error.mul_2si(error, -(int)error.get_prec()); normb += error; if (norm_sol > normb) { cerr << "Last dual vector too long by more than " << error << endl; return 1; } return 0; }
template <class ZT> int test_dual_svp(ZZ_mat<ZT> &A, IntVect &b) { IntVect sol_coord; // In the LLL-reduced basis IntVect solution; IntMatrix u; Float normb; if (dual_length(normb, A, b)) { return 1; } int status = lll_reduction(A, u, LLL_DEF_DELTA, LLL_DEF_ETA, LM_WRAPPER, FT_DEFAULT, 0, LLL_DEFAULT); if (status != RED_SUCCESS) { cerr << "LLL reduction failed: " << get_red_status_str(status) << endl; return status; } status = shortest_vector(A, sol_coord, SVPM_FAST, SVP_DUAL); if (status != RED_SUCCESS) { cerr << "Failure: " << get_red_status_str(status) << endl; return status; } Float norm_sol; if (dual_length(norm_sol, A, sol_coord)) { return 1; } Float error; error = 1; error.mul_2si(error, -(int)error.get_prec()); normb += error; if (norm_sol > normb) { cerr << "Returned dual vector too long by more than " << error << endl; return 1; } return 0; }