Skip to content

Commit

Permalink
code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
vsoftco committed Sep 19, 2023
1 parent 4ab1bc0 commit 390c97a
Show file tree
Hide file tree
Showing 22 changed files with 592 additions and 133 deletions.
36 changes: 31 additions & 5 deletions include/grid_synth/complex.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
#ifndef COMPLEX_HPP
#define COMPLEX_HPP
/*
* This file is part of staq.
*
* Copyright (c) 2019 - 2023 softwareQ Inc. All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef GRID_SYNTH_COMPLEX_HPP_
#define GRID_SYNTH_COMPLEX_HPP_

#include <gmpxx.h>
#include <iomanip>
#include <iostream>

#include <gmpxx.h>

#include "gmp_functions.hpp"

namespace staq {
Expand Down Expand Up @@ -144,12 +171,11 @@ inline complex<mpf_class> operator*(complex<double> x, complex<mpf_class> z) {
z.a() * x.b() + z.b() * x.a());
}


inline mpf_class abs(const complex<mpf_class>& z) {
return gmpf::sqrt(z.real() * z.real() + z.imag() * z.imag());
}

} // namespace grid_synth
} // namespace staq

#endif // COMPLEX_HPP
#endif // GRID_SYNTH_COMPLEX_HPP_
50 changes: 38 additions & 12 deletions include/grid_synth/constants.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
#ifndef CONSTANTS_HPP
#define CONSTANTS_HPP
/*
* This file is part of staq.
*
* Copyright (c) 2019 - 2023 softwareQ Inc. All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef GRID_SYNTH_CONSTANTS_HPP_
#define GRID_SYNTH_CONSTANTS_HPP_

#include <cmath>
#include <iostream>

#include "types.hpp"
#include "gmp_functions.hpp"
#include "complex.hpp"
#include "gmp_functions.hpp"
#include "types.hpp"

namespace staq {
namespace grid_synth {


struct MultiPrecisionConstants {
real_t tol;
real_t pi;
Expand All @@ -37,14 +62,15 @@ inline MultiPrecisionConstants initialize_constants(long int prec) {
real_t half_inv_sqrt2 = real_t(real_t(1) / (real_t(2) * sqrt2));
cplx_t omega = cplx_t(inv_sqrt2, inv_sqrt2);
cplx_t omega_conj = cplx_t(inv_sqrt2, -inv_sqrt2);
real_t log_lambda = gmpf::log10(real_t(1)+sqrt2);
real_t sqrt_lambda = gmpf::sqrt(real_t(1)+sqrt2);
real_t log_lambda = gmpf::log10(real_t(1) + sqrt2);
real_t sqrt_lambda = gmpf::sqrt(real_t(1) + sqrt2);
real_t sqrt_lambda_inv = sqrt(-real_t(1) + sqrt2);
cplx_t im = cplx_t(real_t(0), real_t(1));

return MultiPrecisionConstants{
tol,pi,default_gmp_prec,sqrt2,inv_sqrt2,half_inv_sqrt2,omega,omega_conj,im,
log_lambda, sqrt_lambda, sqrt_lambda_inv};
return MultiPrecisionConstants{tol, pi, default_gmp_prec,
sqrt2, inv_sqrt2, half_inv_sqrt2,
omega, omega_conj, im,
log_lambda, sqrt_lambda, sqrt_lambda_inv};
}

inline MultiPrecisionConstants MP_CONSTS = initialize_constants(10);
Expand Down Expand Up @@ -75,10 +101,10 @@ const int MOD_SQRT_MAX_DEPTH = 20;
const int MAX_ITERATIONS_FERMAT_TEST = 5;
const str_t DEFAULT_TABLE_FILE = "./.s3_table_file.csv";

// on average we only need 2 attempts so 5 is playing it safe
// on average, we only need 2 attempts so 5 is playing it safe
const int MAX_ATTEMPTS_SQRT_NEG_ONE = 100;

} // namespace grid_synth
} // namespace staq

#endif // CONSTANTS_HPP
#endif // GRID_SYNTH_CONSTANTS_HPP_
33 changes: 29 additions & 4 deletions include/grid_synth/diophantine_solver.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
#ifndef DIOPHANTINE_SOLVER_HPP
#define DIOPHANTINE_SOLVER_HPP
/*
* This file is part of staq.
*
* Copyright (c) 2019 - 2023 softwareQ Inc. All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef GRID_SYNTH_DIOPHANTINE_SOLVER_HPP_
#define GRID_SYNTH_DIOPHANTINE_SOLVER_HPP_

#include <algorithm>
#include <cmath>
Expand Down Expand Up @@ -178,7 +204,6 @@ inline bool pollard_rho(int_t& factor, const int_t& n,
factor = d;
return true;
}
return false;
}

inline bool prime_factorize_int(int_vec_t& prime_factors, const int_t& n) {
Expand Down Expand Up @@ -353,4 +378,4 @@ inline bool diophantine_solver(ZOmega& answer, const ZSqrt2& xi) {
} // namespace grid_synth
} // namespace staq

#endif // DIOPHANTINE_SOLVER_HPP
#endif // GRID_SYNTH_DIOPHANTINE_SOLVER_HPP_
76 changes: 47 additions & 29 deletions include/grid_synth/exact_synthesis.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
#ifndef EXACT_SYNTHESIS_HPP
#define EXACT_SYNTHESIS_HPP
/*
* This file is part of staq.
*
* Copyright (c) 2019 - 2023 softwareQ Inc. All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef GRID_SYNTH_EXACT_SYNTHESIS_HPP_
#define GRID_SYNTH_EXACT_SYNTHESIS_HPP_

#include <cstdlib>

#include "matrix.hpp"
#include "types.hpp"
Expand All @@ -10,43 +38,33 @@ namespace grid_synth {
// Returns known common cases for multiples of theta = pi/4. w =
// 1/(sqrt(omega)).
inline str_t check_common_cases(real_t theta, const real_t& eps) {
while(theta > real_t("2"))
theta = theta - real_t("2");
while(theta < 0)
theta = theta + real_t("2");
if(abs(theta-real_t("0.25")) < eps) {

while (theta > real_t("2"))
theta = theta - real_t("2");
while (theta < 0)
theta = theta + real_t("2");

if (abs(theta - real_t("0.25")) < eps) {
return "T w";
}
else if(abs(theta-real_t("0.5")) < eps) {
} else if (abs(theta - real_t("0.5")) < eps) {
return "S W W W W W W W";
}
else if(abs(theta-real_t("0.75")) < eps) {
return "S T W W W W W W W w";
}
else if(abs(theta-real_t("1")) < eps) {
} else if (abs(theta - real_t("0.75")) < eps) {
return "S T W W W W W W W w";
} else if (abs(theta - real_t("1")) < eps) {
return "S S W W W W W W";
}
else if(abs(theta-real_t("1.25")) < eps) {
} else if (abs(theta - real_t("1.25")) < eps) {
return "S S T W W W W W W w";
}
else if(abs(theta-real_t("1.5")) < eps) {
} else if (abs(theta - real_t("1.5")) < eps) {
return "S S S W W W W W";
}
else if(abs(theta-real_t("1.75")) < eps) {
} else if (abs(theta - real_t("1.75")) < eps) {
return "S S S T W W W W W w";
}
else if(abs(theta-real_t("2")) < eps) {
} else if (abs(theta - real_t("2")) < eps) {
return "W W W W";
}
else {
} else {
return "";
}
return "";
}


inline str_t synthesize(const DOmegaMatrix& D,
const domega_matrix_table_t& s3_table) {
using namespace std;
Expand Down Expand Up @@ -91,4 +109,4 @@ inline str_t synthesize(const DOmegaMatrix& D,
} // namespace grid_synth
} // namespace staq

#endif // EXACT_SYNTHESIS_HPP
#endif // GRID_SYNTH_EXACT_SYNTHESIS_HPP_
37 changes: 32 additions & 5 deletions include/grid_synth/gmp_functions.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
#ifndef GMP_FUNCTIONS_HPP
#define GMP_FUNCTIONS_HPP
/*
* This file is part of staq.
*
* Copyright (c) 2019 - 2023 softwareQ Inc. All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef GRID_SYNTH_GMP_FUNCTIONS_HPP
#define GRID_SYNTH_GMP_FUNCTIONS_HPP

#include <cmath>
#include <gmpxx.h>
#include <iostream>
#include <string>

#include <gmpxx.h>

#include "utils.hpp"

namespace staq {
Expand Down Expand Up @@ -202,7 +229,7 @@ inline mpf_class sin(const mpf_class& theta) {
}

inline mpf_class cos(const mpf_class& theta) {
long int initial_prec = theta.get_prec();
// long int initial_prec = theta.get_prec();
long int tol_exp = std::log10(2) * theta.get_prec();
mpf_class phi = reduce_angle(theta);
mpz_class i(0);
Expand Down Expand Up @@ -246,4 +273,4 @@ inline mpf_class sqrt(const mpf_class& x) {
} // namespace gmpf
} // namespace staq

#endif // GMP_FUNCTIONS_HPP
#endif // GRID_SYNTH_GMP_FUNCTIONS_HPP
32 changes: 29 additions & 3 deletions include/grid_synth/grid_operators.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
#ifndef GRID_OPERATORS_H
#define GRID_OPERATORS_H
/*
* This file is part of staq.
*
* Copyright (c) 2019 - 2023 softwareQ Inc. All rights reserved.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef GRID_SYNTH_GRID_OPERATORS_H_
#define GRID_SYNTH_GRID_OPERATORS_H_

#define MATOUTPUT_WIDTH 10

Expand Down Expand Up @@ -269,4 +295,4 @@ inline SpecialGridOperator B(int_t n) {
} // namespace grid_synth
} // namespace staq

#endif // GRID_OPERATORS_H
#endif // GRID_SYNTH_GRID_OPERATORS_H_
Loading

0 comments on commit 390c97a

Please sign in to comment.