-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconstant_weight_encodable_bits.cpp
More file actions
30 lines (25 loc) · 1.06 KB
/
constant_weight_encodable_bits.cpp
File metadata and controls
30 lines (25 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#define NUM_BITS_REAL_MANTISSA 128
#include <cstdint>
#include <cmath>
#include <NTL/ZZ.h>
#include "binomials.hpp"
int main(int argc, char* argv[]){
if(argc != 3){
std::cout << "Calculator to derive the length of the encodable bit string via CW-enc" << std::endl << " Usage "
<< argv[0] << " <codeword_size> <number_of_errors> " << std::endl;
return -1;
}
InitBinomials();
NTL::RR::SetPrecision(NUM_BITS_REAL_MANTISSA);
pi = NTL::ComputePi_RR();
uint32_t n = atoi(argv[1]);
uint32_t t = atoi(argv[2]);
/* reduce by a factor matching the QC block size */
NTL::RR encodable_length;
encodable_length = lnBinom(NTL::to_RR(n), NTL::to_RR(t))/NTL::log(NTL::RR(2));
NTL::RR d = NTL::to_RR( 0.69315 * ((double)n - ( (double)t - 1.0)/2.0) /((double) t) );
std::cout << "Maximum safely encoded: " << t*NTL::conv<unsigned long int>(NTL::floor(NTL::log(d)/NTL::log(NTL::RR(2))+1)) << std::endl;
std::cout << "#define MAX_ENCODABLE_BIT_SIZE_CW_ENCODING (" << NTL::conv<unsigned long int>(encodable_length) << ")" ;
std::cout << std::endl;
return 0;
}