void validate_reciprocal( const circuit& circ, unsigned bitwidth, const properties::ptr& settings, const properties::ptr& statistics ) { /* settings */ const auto rounds = get( settings, "rounds", 100u ); /* statistics */ properties_timer t( statistics ); for ( auto i = 0u; i < rounds; ++i ) { const auto assignment = random_bitset( bitwidth ); boost::dynamic_bitset<> output; partial_simulation( output, circ, assignment ); assert( output.size() == bitwidth ); const auto x = to_multiprecision<boost::multiprecision::uint256_t>( assignment ); const auto y = to_multiprecision<boost::multiprecision::uint256_t>( output ); boost::multiprecision::uint256_t N = 1; N = N << bitwidth; if ( x != 0 && N / x != y ) { std::cout << "[w] inconsistency detected:" << std::endl; std::cout << "[w] x = " << x << ", y = " << y << ", x * y = " << ( x * y ) << std::endl; std::cout << "[w] N / x = " << ( N / x ) << std::endl; } else { std::cout << "[i] x = " << x << " y = " << y << std::endl; } } }
void create_random_gate( gate& g, unsigned lines, bool negative, std::default_random_engine& generator ) { std::uniform_int_distribution<unsigned> dist( 0u, lines - 1u ); std::uniform_int_distribution<unsigned> bdist( 0u, 1u ); auto controls = random_bitset( lines, generator ); auto target = dist( generator ); g.set_type( toffoli_tag() ); g.add_target( target ); auto pos = controls.find_first(); while ( pos != controls.npos ) { if ( pos != target ) { g.add_control( make_var( pos, negative ? ( bdist( generator ) == 1u ) : true ) ); } pos = controls.find_next( pos ); } }