text:
using JuMP, EAGO

                     m = Model()

                     EAGO.register_eago_operators!(m)

                     @variable(m, -1 <= x[i=1:4] <= 1)

                     @variable(m, -41.21023060076703 <= q <= 39.01192102445897)

                     add_NL_constraint(m, :(sigmoid(-0.296746779395487 + 0.5509866377924739*sigmoid(-0.36537726371933 + -0.13236748618316563*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.8938439926067105*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.2026514795524368*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.4969096390589627*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))) + -0.850208463612319*sigmoid(-0.13805861779585626 + 0.8324190447258686*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.45691763611374503*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.0018061937798208305*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.06838129719944464*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))) + 0.14361846152386626*sigmoid(0.892089992500452 + -0.9262441239021939*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.1220711338530176*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.013243228467184842*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.22830737094249542*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))) + 0.12455164844812394*sigmoid(-0.09971606472325156 + 0.22050596868305217*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.9537528744420904*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.13795746696872868*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.0643190431003462*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + sigmoid(-0.7906046812278151 + -0.2168623555923963*sigmoid(-0.36537726371933 + -0.13236748618316563*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.8938439926067105*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.2026514795524368*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.4969096390589627*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))) + 0.3937942437507238*sigmoid(-0.13805861779585626 + 0.8324190447258686*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.45691763611374503*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.0018061937798208305*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.06838129719944464*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))) + 0.013414887338259796*sigmoid(0.892089992500452 + -0.9262441239021939*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.1220711338530176*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.013243228467184842*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.22830737094249542*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))) + -0.20160941359718088*sigmoid(-0.09971606472325156 + 0.22050596868305217*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.9537528744420904*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.13795746696872868*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.0643190431003462*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + sigmoid(0.21825887860627402 + 0.23342217391611308*sigmoid(-0.36537726371933 + -0.13236748618316563*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.8938439926067105*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.2026514795524368*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.4969096390589627*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))) + 0.7638006108327029*sigmoid(-0.13805861779585626 + 0.8324190447258686*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.45691763611374503*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.0018061937798208305*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.06838129719944464*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))) + 0.4051674738413942*sigmoid(0.892089992500452 + -0.9262441239021939*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.1220711338530176*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.013243228467184842*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.22830737094249542*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))) + 0.17219310126869347*sigmoid(-0.09971606472325156 + 0.22050596868305217*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.9537528744420904*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.13795746696872868*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.0643190431003462*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + sigmoid(0.8210746038366681 + -0.06951431198870361*sigmoid(-0.36537726371933 + -0.13236748618316563*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.8938439926067105*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.2026514795524368*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.4969096390589627*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))) + 0.9856384884704164*sigmoid(-0.13805861779585626 + 0.8324190447258686*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.45691763611374503*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.0018061937798208305*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.06838129719944464*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))) + -0.2856111885860577*sigmoid(0.892089992500452 + -0.9262441239021939*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.1220711338530176*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.013243228467184842*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.22830737094249542*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))) + 0.04937870878523665*sigmoid(-0.09971606472325156 + 0.22050596868305217*sigmoid(0.24726246482452874 + -0.2513871312104543*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.4677853214537917*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + -0.10088601735084568*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.6507022966434817*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.9537528744420904*sigmoid(0.30866893537934104 + -0.11067617174498023*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.7749548972944802*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.44318801341623093*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + 0.23547099627350976*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + -0.13795746696872868*sigmoid(-0.39572563026399044 + -0.2902839675147266*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + 0.2975675315855191*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.808554335286296*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.2217074058396178*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))) + 0.0643190431003462*sigmoid(0.8092602903578396 + -0.8861475410157751*sigmoid(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])) + -0.38211269748902854*sigmoid(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])) + 0.47211467596801615*sigmoid(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])) + -0.8428121402295612*sigmoid(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) - $q <= 0.0))

                     @objective(m, Min, q)

                     return m

max_stars_repo_name: PSORLab/RSActivationFunctions

max_issues_repo_name: PSORLab/RSActivationFunctions

max_forks_repo_name: PSORLab/RSActivationFunctions


text:
# at the moment, this only serves the purpose of putting the boundary tags into type space.
"""
    IntervalTopology(mesh::IntervalMesh)

A sequential topology on an [`Meshes.IntervalMesh`](@ref).
"""
struct IntervalTopology{M <: Meshes.IntervalMesh, B} <: AbstractTopology
    mesh::M
    boundaries::B
end

function IntervalTopology(mesh::Meshes.IntervalMesh)
    if isnothing(mesh.domain.boundary_names)
        boundaries = NamedTuple()
    elseif mesh.domain.boundary_names[1] == mesh.domain.boundary_names[2]
        boundaries = NamedTuple{(mesh.domain.boundary_names[1],)}(1)
    else
        boundaries = NamedTuple{mesh.domain.boundary_names}((1, 2))
    end
    IntervalTopology(mesh, boundaries)
end

function Base.show(io::IO, topology::IntervalTopology)
    print(io, "IntervalTopology on ", topology.mesh)
end

domain(topology::IntervalTopology) = topology.mesh.domain
nlocalelems(topology::IntervalTopology) = length(topology.mesh.faces) - 1

vertex_coordinates(topology::IntervalTopology, elem) =
    (topology.mesh.faces[elem], topology.mesh.faces[elem + 1])

function opposing_face(topology::IntervalTopology, elem, face)
    n = length(topology.mesh.faces) - 1
    if face == 1
        if elem == 1
            if isempty(mesh.boundaries) # periodic
                opelem = n
            else
                return (0, 1, false)
            end
        else
            opelem = elem - 1
        end
        opface = 2
    else
        if elem == n
            if isempty(mesh.boundaries) # periodic
                opelem = 1
            else
                return (0, 2, false)
            end
        end
        opface = 1
    end
    return (opelem, opface, false)
end

function Base.length(fiter::InteriorFaceIterator{<:IntervalTopology})
    topology = fiter.topology
    if isempty(topology.boundaries)
        length(topology.mesh.faces) - 1
    else
        length(topology.mesh.faces) - 2
    end
end

function Base.iterate(fiter::InteriorFaceIterator{<:IntervalTopology}, i = 1)
    topology = fiter.topology
    periodic = isempty(topology.boundaries)
    n = length(topology.mesh.faces) - 1
    if i < n
        return (i + 1, 1, i, 2, false), i + 1
    elseif i == n && periodic
        return (1, 1, i, 2, false), i + 1
    else
        return nothing
    end
end

ext: jl


text:
# TODO make it yield enodes only? ping pavel and marisa
# TODO STAGE IT! FASTER!
module EMatchCompiler

using AutoHashEquals
using TermInterface
using Metatheory: alwaystrue, binarize, binarize_rec
using Metatheory.Patterns

abstract type Instruction end
export Instruction

const Register = Int32

mutable struct Program
  instructions::Vector{Instruction}
  first_nonground::Int
  memsize::Int
  regs::Vector{Register}
  ground_terms::Dict{Any,Register}
end
export Program

function Program()
  Program(Instruction[], 0, 0, [], Dict{AbstractPat,Register}())
end

hasregister(prog::Program, i) = (prog.regs[i] != -1)
getregister(prog::Program, i) = prog.regs[i]
setregister(prog::Program, i, v) = (prog.regs[i] = v)
increment(prog::Program, i) = (prog.memsize += i)
memsize(prog::Program) = prog.memsize

Base.getindex(p::Program, i) = p.instructions[i]
Base.length(p::Program) = length(p.instructions)

@auto_hash_equals struct ENodePat
  exprhead::Union{Symbol,Nothing}
  operation::Any
  # args::Vector{Register}
  args::UnitRange{Register}
  checkop::Function # function that checks both symbol or func. object as op
end
export ENodePat

TermInterface.operation(p::ENodePat) = p.operation
TermInterface.exprhead(p::ENodePat) = p.exprhead
TermInterface.arguments(p::ENodePat) = p.args
TermInterface.arity(p::ENodePat) = length(p.args)

@auto_hash_equals struct Bind <: Instruction
  reg::Register
  enodepat::ENodePat
end
export Bind

@auto_hash_equals struct CheckClassEq <: Instruction
  left::Register
  right::Register
end
export CheckClassEq

@auto_hash_equals struct CheckType <: Instruction
  reg::Register
  type::Any
end
export CheckType

@auto_hash_equals struct CheckPredicate <: Instruction
  reg::Register
  predicate::Function
end
export CheckPredicate

@auto_hash_equals struct Yield <: Instruction
  yields::Vector{Register}
end
export Yield

@auto_hash_equals struct Filter <: Instruction
  reg::Register
  operation::Any
  arity::Int
end
TermInterface.operation(x::Filter) = x.operation
export Filter

@auto_hash_equals struct Lookup <: Instruction
  reg::Register
  p::Any # pattern
end
export Lookup

@auto_hash_equals struct Fail <: Instruction
  err::Exception
end
export Fail

# =============================================
# ========= GROUND patterns ================
# =============================================

function compile_ground!(reg, p::PatTerm, prog)
  if haskey(prog.ground_terms, p)
    # push!(prog.instructions, CheckClassEq(reg, prog.ground_terms[p]))
    return nothing
  end

  if isground(p)
    prog.ground_terms[p] = reg
    push!(prog.instructions, Lookup(reg, p))
    increment(prog, 1)
  else
    for p2 in p.args
      compile_ground!(prog.memsize, p2, prog)
    end
  end
end

function compile_ground!(reg, p::PatVar, prog)
  nothing
end

function compile_ground!(reg, p::AbstractPat, prog)
  push!(prog.instructions, Fail(UnsupportedPatternException(p)))
end

# A literal that is not a pattern
function compile_ground!(reg, p::Any, prog)
  if haskey(prog.ground_terms, p)
    return nothing
  end
  prog.ground_terms[p] = reg
  push!(prog.instructions, Lookup(reg, p))
  increment(prog, 1)
end

# =============================================
# ========= NONGROUND patterns ================
# =============================================

function compile_pat!(reg, p::PatTerm, prog)
  if haskey(prog.ground_terms, p)
    push!(prog.instructions, CheckClassEq(reg, prog.ground_terms[p]))
    return nothing
  end
  # a = [gensym() for i in 1:length(p.args)]
  c = memsize(prog)
  nargs = arity(p)
  # registers unit range
  regrange = c:(c + nargs - 1)

  exhead = exprhead(p)
  op = operation(p)
  checkop = x -> isequal(x, op)

  if op isa Symbol
    checkop = try
      fobj = getproperty(p.mod, op)
      (x) -> (isequal(x, op) || isequal(x, fobj))
    catch e
      e isa UndefVarError ? checkop : rethrow(e)
    end
  end

  increment(prog, nargs)

  push!(prog.instructions, Bind(reg, ENodePat(exhead, op, regrange, checkop)))
  for (reg, p2) in zip(regrange, arguments(p))
    compile_pat!(reg, p2, prog)
  end
end

function compile_pat!(reg, p::PatVar, prog)
  if hasregister(prog, p.idx)
    push!(prog.instructions, CheckClassEq(reg, getregister(prog, p.idx)))
  else # Variable is new
    setregister(prog, p.idx, reg)
    if p.predicate isa Function && p.predicate != alwaystrue
      push!(prog.instructions, CheckPredicate(reg, p.predicate))
    elseif p.predicate isa Type
      push!(prog.instructions, CheckType(reg, p.predicate))
    end
  end
end

function compile_pat!(reg, p::AbstractPat, prog)
  push!(prog.instructions, Fail(UnsupportedPatternException(p)))
end

# Literal values
function compile_pat!(reg, p::Any, prog)
  if haskey(prog.ground_terms, p)
    push!(prog.instructions, CheckClassEq(reg, prog.ground_terms[p]))
    return nothing
  end
  @error "This shouldn't be printed. Report an issue for ematching literals" p
end

#= ====================================================================================== =#

# EXPECTS INDEXES OF PATTERN VARIABLES TO BE ALREADY POPULATED
function compile_pat(p)
  p = binarize_rec(p)
  pvars = patvars(p)
  nvars = length(pvars)

  # The program will try to match against ground terms first
  prog = Program(Instruction[], 1, 1, fill(-1, nvars), Dict{AbstractPat,Register}())
  compile_ground!(1, p, prog)
  prog.first_nonground = prog.memsize
  prog.memsize += 1

  # And then try to match against other patterns
  compile_pat!(prog.first_nonground, p, prog)
  push!(prog.instructions, Yield(prog.regs))
  return prog
end

export compile_pat

end


text:
using SandDance
using Test


text:
# automatically generated by the FlatBuffers compiler, do not modify

# module: Example

module Example
    include("Color.jl")
    include("Test.jl")
    include("Vec3.jl")
    include("Stat.jl")
    include("Ability.jl")
    include("Referrable.jl")
    include("TestSimpleTableWithEnum.jl")
    # include("AnyUniqueAliases.jl")
    # include("AnyAmbiguousAliases.jl")
    include("Monster.jl")
    include("Any_.jl")
    include("TypeAliases.jl")
end


text:
abstract type TreeOptions end
abstract type AbstractNode end
## Box tree
# Implements quad- (2D) and oct-tree (3D) cluster strategies
include("boundingbox.jl")
include("boxtree.jl")

## KMeans-Tree
include("kmeans.jl")

## Default functions
function create_tree(points::Vector{SVector{D,T}}) where {D,T}
    create_tree(points, BoxTreeOptions())
end

max_stars_repo_name: sbadrian/FastBEAST

max_issues_repo_name: sbadrian/FastBEAST

max_forks_repo_name: sbadrian/FastBEAST


text:
module OutputWriters

export
    write_output, read_output,
    JLD2OutputWriter, FieldOutput, FieldOutputs,
    NetCDFOutputWriter, write_grid,
    Checkpointer, restore_from_checkpoint

using Oceananigans
using Oceananigans.Grids
using Oceananigans.Architectures

using Oceananigans: AbstractOutputWriter, @hascuda

@hascuda using CUDAnative, CuArrays

include("output_writer_utils.jl")
include("jld2_output_writer.jl")
include("netcdf_output_writer.jl")
include("checkpointer.jl")

end


text:
# NOTE: set the following variable to point to the shared CPLEX library
# available on your machine. This will be named something like
# "libcplex2010.so" or "libcplex12100.dylib".
const CPLEX_PATH = ""


text:
module POMDPExamples

end # module


text:
struct Copy{P} end
function (::Copy{P})(p::Ptr{UInt}) where {P}
  _, (ptry,ptrx,N) = ThreadingUtilities.load(p, P, 2*sizeof(UInt))
  N > 0 || throw("This function throws if N == 0 for testing purposes.")
  @simd ivdep for n ∈ 1:N
    vstore!(ptry, vload(ptrx, (n,)), (n,))
  end
end
@generated function copy_ptr(::A, ::B) where {A,B}
  c = Copy{Tuple{A,B,Int}}()
  quote
    @cfunction($c, Cvoid, (Ptr{UInt},))
  end
end
function setup_copy!(p, y, x)
  N = length(y)
  @assert length(x) == N
  py = stridedpointer(y)
  px = stridedpointer(x)
  fptr = copy_ptr(py, px)
  offset = ThreadingUtilities.store!(p, fptr, sizeof(UInt))
  ThreadingUtilities.store!(p, (py,px,N), offset)
end

@inline launch_thread_copy!(tid, y, x) = ThreadingUtilities.launch(setup_copy!, tid, y, x)

function test_copy(tid, N = 100_000)
  a = rand(N);
  b = rand(N);
  c = rand(N);
  x = similar(a) .= NaN;
  y = similar(b) .= NaN;
  z = similar(c) .= NaN;
  GC.@preserve a b c x y z begin
    launch_thread_copy!(tid, x, a)
    yield()
    @assert !ThreadingUtilities.wait(tid)
    launch_thread_copy!(tid, y, b)
    yield()
    @assert !ThreadingUtilities.wait(tid)
    launch_thread_copy!(tid, z, c)
    yield()
    @assert !ThreadingUtilities.wait(ThreadingUtilities.taskpointer(tid))
  end
  @test a == x
  @test b == y
  @test c == z
end

@testset "ThreadingUtilities.jl" begin
  for tid ∈ eachindex(ThreadingUtilities.TASKS)
    @test unsafe_load(Ptr{UInt32}(ThreadingUtilities.taskpointer(tid))) == 0x00000001
  end
  @test all(eachindex(ThreadingUtilities.TASKS)) do tid
    ThreadingUtilities.load(ThreadingUtilities.taskpointer(tid), ThreadingUtilities.ThreadState) === ThreadingUtilities.WAIT
  end
  @test all(eachindex(ThreadingUtilities.TASKS)) do tid
    ThreadingUtilities._atomic_load(reinterpret(Ptr{UInt32}, ThreadingUtilities.taskpointer(tid))) === reinterpret(UInt32, ThreadingUtilities.WAIT)
  end
  foreach(test_copy, eachindex(ThreadingUtilities.TASKS))

  x = rand(UInt, 3);
  GC.@preserve x begin
    ThreadingUtilities._atomic_store!(pointer(x), zero(UInt))
    @test ThreadingUtilities._atomic_xchg!(pointer(x), ThreadingUtilities.WAIT) == ThreadingUtilities.TASK
    @test ThreadingUtilities._atomic_umax!(pointer(x), ThreadingUtilities.TASK) == ThreadingUtilities.WAIT
    @test ThreadingUtilities._atomic_umax!(pointer(x), ThreadingUtilities.SPIN) == ThreadingUtilities.WAIT
    @test ThreadingUtilities.load(pointer(x), ThreadingUtilities.ThreadState) == ThreadingUtilities.SPIN
  end
  for tid ∈ eachindex(ThreadingUtilities.TASKS)
    launch_thread_copy!(tid, Float64[], Float64[])
  end
  yield()
  @test all(istaskfailed, ThreadingUtilities.TASKS)
  @test all(ThreadingUtilities.wait, eachindex(ThreadingUtilities.TASKS))
  @test !any(istaskfailed, ThreadingUtilities.TASKS)
  # test copy on the reinitialized tasks
  foreach(test_copy, eachindex(ThreadingUtilities.TASKS))
end


text:
using Arblib, Test

@testset "Arblib" begin
    @test isa(Arb(π), Arb)
end

@testset "setprecision" begin
    x = Arb("0.1")
    @test precision(x) == 256
    @test precision(Arb) == 256
    @test string(x) == "[0.1000000000000000000000000000000000000000000000000000000000000000000000000000 +/- 1.95e-78]"

    setprecision(Arb, 64)
    @test precision(x) == 256
    @test precision(Arb) == 64
    y = Arb("0.1")
    @test precision(y) == 64
    @test string(y) == "[0.100000000000000000 +/- 1.22e-20]"

    setprecision(Arb, 256)
end

@testset "Examples" begin
    @testset "Naive sin" begin
        function sin_naive!(res, x)
            s, t, u = zero(x), zero(x), zero(x)
            tol = one(x)
            Arblib.mul_2exp!(tol, tol, -precision(tol))
            # @show tol
            k = 0
            while true
                Arblib.pow!(t, x, 2k + 1)
                Arblib.fac!(u, UInt(2k + 1))
                Arblib.div!(t, t, u)
                Arblib.abs!(u, t)

                if u ≤ tol
                    # @show u
                    Arblib.add_error!(s, u)
                    break
                end
                if iseven(k)
                    Arblib.add!(s, s, t)
                else
                    Arblib.sub!(s, s, t)
                end
                k += 1
            end
            Arblib.set!(res, s)
        end

        @test let
            str = ""
            prec = 64
            while true
                x = Arb("2016.1"; prec = prec)
                y = zero(x)
                y = sin_naive!(y, x)
                str *= sprint(print, "Using $(lpad(prec, 5)) bits, sin(x) = ")
                str *= sprint(println, Arblib.string_nice(y, 10))
                y < zero(y) && break
                prec *= 2
            end
            str
        end == """
        Using    64 bits, sin(x) = [+/- 2.67e+859]
        Using   128 bits, sin(x) = [+/- 1.30e+840]
        Using   256 bits, sin(x) = [+/- 3.60e+801]
        Using   512 bits, sin(x) = [+/- 3.01e+724]
        Using  1024 bits, sin(x) = [+/- 2.18e+570]
        Using  2048 bits, sin(x) = [+/- 1.22e+262]
        Using  4096 bits, sin(x) = [-0.7190842207 +/- 1.20e-11]
        """
    end
end


text:
### A Pluto.jl notebook ###
# v0.17.1

using Markdown
using InteractiveUtils

# ╔═╡ 4fa0f050-4b8b-11ec-24d5-1f995fc27946
begin
    using Chain: @chain
    using DataFrames: DataFrame, rename
    using OrderedCollections: OrderedDict
    using PlutoUI: TableOfContents
end

# ╔═╡ 1d3d6cd4-d99c-4256-a907-05529519e2d8
md"""# Đối phó với tên cột tiếng Nhật

Dữ liệu dự án có nhiều tên cột tiếng Nhật.
Làm thế nào để các thành viên biết và không biết tiếng Nhật
cùng làm việc hiệu quả trên dữ liệu này?
Cùng làm việc hiệu quả có nghĩa là có thể đọc được source code do người khác viết,
và có thể hội thoại một cách trơn tru.

> Ở đây chúng ta đề cập về tiếng Nhật như là một tượng trưng cho một ngôn ngũ mà toàn thể đội dự án, đặc biệt là chuyên gia lập trình, phân tích dữ liệu và học máy không thông thạo.

*Tokyo 23/11/2021, Võ Chí Công*
"""

# ╔═╡ 96e97932-44ce-48b3-818e-db4a6f453414
TableOfContents()

# ╔═╡ 4c680cf3-d884-49e5-8b36-650f7117a6ea

md"""Hơn nữa, mỗi lần khách hàng cung cấp dữ liệu cập nhật,
các tên cột thỉnh thoảng lại bị  thay đổi.
Làm thế nào để đối phó một cách linh động với sự thay đổi tên cột ở
bước tiền xử lý,
để không cần phải thay đổi source code trong các công đoạn
phân tích, học và dự đoán dữ liệu?

Cuối cùng làm thế nào để có thể làm báo cáo với tên cột là các thuật ngữ tiếng Nhật *chuẩn*? Thuật ngữ chuẩn ở đây có nghĩa là tuân theo quy định mới nhất trong dự án về cách gọi tên cột, vì trong quá trình xúc tiến dự án, tên cột có thể bị thay đổi nhiều lần.

"""

# ╔═╡ 5681fa85-15c9-4463-be8e-e223bbd4df77
md"""# Vấn đề khi sử dụng tên tiếng Nhật

Chúng ta cùng nhìn nhận những vấn đề cụ thể sẽ gặp phải khi xử lý dữ liệu
một cách trực tiếp đối với các tên cột tiếng Nhật.

Lấy ví dụ đơn giản,
giả sử chúng ta có một bảng dữ liệu cá nhân
(danh sách đội hình thỉnh kinh Tây Du Ký)
`df_in` chỉ có hai cột là tên và tuổi.
"""

# ╔═╡ 75c185d1-c284-4443-b6bf-551079ce1a27
df_in = DataFrame(名 = ["孫 悟空", "猪 八戒", "沙 悟浄", "玄奘 三蔵"], 歳 = [22, 19, 18, 30])

# ╔═╡ 534af33b-7104-4d29-8e02-5cd6d866265a
md"""Chúng ta háo hức muốn bắt tay vào EDA phân tích dữ liệu ngay. Rất nhanh chóng, nhiều đoạn code viết 名 và 歳 sinh sôi nảy nở. Tôi đã đọc nhiều Jupyter notebooks do người Nhật hoặc người Việt viết mà trong đó có rất nhiều tên biến (hay cột dữ liệu, features, index) là tiếng Nhật.

Những vấn đề phát sinh:

1. Trong source code có tiếng Nhật vào nhìn rối rắm. Những người không biết tiếng Nhật nhìn vào code có tiếng Nhật có lẽ sẽ cảm thấy như bị *mù*.
2. Những lập trình viên chuyên nghiệp thích gõ phím nhanh mà không cần chuyển bàn phím Nhật/Anh chỉ để gọi tên biến. Chức năng *code completion* của editor cũng chỉ hỗ trợ cho tiếng Anh.
3. Nhiều khi tên tiếng Nhật gốc hoặc có ý nghĩa không rõ ràng, hoặc quá ngắn gọn, hoặc quá chi tiết, nói chung là tên gọi không được tốt.
"""

# ╔═╡ ccd45783-6a7f-4824-b83f-599de8a8a85a
md"""
# Chuẩn hoá bằng tên tiếng Anh
Để tránh những vấn đề trên, chúng ta nên có một bước tiền xử lý,
sử dụng thống nhất một mapping `names_j2e`
để chuyển đổi các tên cột từ tiếng Nhật sang tiếng Anh.
Trong bước này chú ý:

1. Chuẩn hoá các tên cột tiếng Anh. Các tên cột này sẽ là xương sống xuyên suốt các bước phân tích, học và dự đoán dữ liệu. Về nguyên tắc chỉ thay đổi tên cột tiếng Anh khi bản chất của cột dữ liệu tương ứng đã thay đổi.
2. Cho phép mapping nhiều tên cột tiếng Nhật khác nhau lên cùng một tên cột tiếng Anh duy nhất. Trong quá trình xúc tiến dự án, tên tiếng Nhật có thể thay đổi và được bổ sung vào danh sách mapping.
"""

# ╔═╡ 8d7fa112-2add-40dd-9c0e-1bd2e43e9d15
names_j2e = OrderedDict(
    :フルネーム => :full_name,
    :名 => :full_name,
    :氏名 => :full_name,
    :歳 => :age,
    :年齢 => :age,
)

# ╔═╡ 3df0b8ab-5989-4597-82fa-e2650f61640f
md"""
Sau bước tiền xử lý, chúng ta có bảng dữ liệu `df_work` chỉ sử dụng các tên cột tiếng Anh đã chuẩn hóa.
Bảng này dùng cho các bước phân tích, học và dự đoán dữ liệu, thuận tiện cho hội thoại giữa các team members, tốc độ viết code cũng nhanh hơn. Sự thay đổi tên cột tiếng Nhật được hấp thu ở bước tiền xử lý, không ảnh hưởng đến code ở những bước quan trọng sau đó.
"""

# ╔═╡ 396fe249-8780-4f62-aa78-7840736af09c
md"""
# Báo cáo dùng tên cột tiếng Nhật

Khi làm báo cáo cho khách hàng, đương nhiên các tên cột dữ liệu phải là tiếng Nhật. Hơn nữa, phải là tiếng Nhật *chuẩn* theo qui định mới nhất của dự án, bất kể tên cột đó ở đầu vào đã có thể thay đổi nhiều lần, hoặc thậm chí có thể vẫn đang ở tình trạng không chuẩn (chưa được cập nhật).
"""

# ╔═╡ 1de46b8e-0343-4d76-9d21-c80e00146255
md"""
Để đưa các tên cột tiếng Anh mà đội dự án sử dụng về tên cột tiếng Nhật chuẩn, chúng ta cần duy trì một mapping `names_e2j` chuẩn. Mapping này được tính ra từ mapping `names_j2e` ở trên, nhưng không cần chứa thông tin về các trường hợp không chuẩn.
"""

# ╔═╡ a1bb122f-4add-4e49-b60e-60ad110d86c0
names_e2j = OrderedDict(e => j for (j, e) in names_j2e)

# ╔═╡ 6168b981-e2c2-45d1-8055-b8bb674155d1
md"""# Tóm lại

Nguyên tắc xử lý tên cột dữ liệu tiếng Nhật

1. Tiền xử lý: chuyển đối tên cột tiếng Nhật về tên tiếng Anh chuẩn.
2. Phân tích, học, dự đoán dữ liệu: chỉ sử dụng tên cột tiếng Anh chuẩn.
3. Xuất báo cáo: chuyển tên cột về tên tiếng Nhật chuẩn.

Links:
- [Tên biến tiếng Nhật trong phân tích dữ liệu và học máy](t.ly/AgAv)
- [Julia sample code](https://github.com/vochicong/dataframe-i18n)
- Pandas/Python sample code: TBA
"""

# ╔═╡ 51c51dc1-a946-4217-81e0-8730d40b7557
function rename_j2e(df::DataFrame)
    names_map = filter(p -> first(p) ∈ (propertynames(df)), names_j2e)
    rename(df, names_map)
end

# ╔═╡ a00e0383-0e83-428c-8b77-9b1293a7bd62
df_work = rename_j2e(df_in)

# ╔═╡ 96808cd0-6eaf-4d48-b095-038dbbe585ce
function rename_e2j(df::DataFrame)
    names_map = filter(p -> first(p) ∈ (propertynames(df)), names_e2j)
    rename(df, names_map)
end

# ╔═╡ c53d5a8c-d3c8-4653-9dce-e6659861dfb6
df_out = rename_e2j(df_work)

# ╔═╡ 44bc0d4e-f1d6-4904-ab85-bb424124e12f
page_break() = html"""
<script>
let cell = currentScript.closest("pluto-cell");
cell.style.pageBreakAfter = "always";
</script>
"""

# ╔═╡ ab2b0e2e-362e-4a8d-8087-45a082b44426
page_break()

# ╔═╡ 36e88abc-395b-401a-a0bb-2cb8a3ed9e4d
page_break()

# ╔═╡ c41c3013-4a58-4fc8-8d11-861fa7136714
page_break()

# ╔═╡ 99dc35a3-cf58-443e-ac17-7d378432a07e
page_break()

# ╔═╡ 0df4917c-28f2-457f-bc41-80fac9ca33ba
page_break()

# ╔═╡ 16029a4c-1141-456c-9a17-81ae24aedbbc
page_break()

# ╔═╡ 454c47e0-0bc9-4274-80c3-3b4e8da1a580
page_break()

# ╔═╡ c3d8d161-752c-4b52-b2f0-3e81bc492988
page_break()

# ╔═╡ f1c2afca-7978-442b-9c86-a2c6f895b878
page_break()

# ╔═╡ 9b985a9c-683f-4371-a02e-7b4ff12f3a95
page_break()

# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"

[compat]
Chain = "~0.4.8"
DataFrames = "~1.2.2"
OrderedCollections = "~1.4.1"
PlutoUI = "~0.7.19"
"""

# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised

[[AbstractPlutoDingetjes]]
deps = ["Pkg"]
git-tree-sha1 = "0bc60e3006ad95b4bb7497698dd7c6d649b9bc06"
uuid = "6e696c72-6542-2067-7265-42206c756150"
version = "1.1.1"

[[ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"

[[Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[Chain]]
git-tree-sha1 = "cac464e71767e8a04ceee82a889ca56502795705"
uuid = "8be319e6-bccf-4806-a6f7-6fae938471bc"
version = "0.4.8"

[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "dce3e3fea680869eaa0b774b2e8343e9ff442313"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.40.0"

[[Crayons]]
git-tree-sha1 = "3f71217b538d7aaee0b69ab47d9b7724ca8afa0d"
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
version = "4.0.4"

[[DataAPI]]
git-tree-sha1 = "cc70b17275652eb47bc9e5f81635981f13cea5c8"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.9.0"

[[DataFrames]]
deps = ["Compat", "DataAPI", "Future", "InvertedIndices", "IteratorInterfaceExtensions", "LinearAlgebra", "Markdown", "Missings", "PooledArrays", "PrettyTables", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"]
git-tree-sha1 = "d785f42445b63fc86caa08bb9a9351008be9b765"
uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
version = "1.2.2"

[[DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "7d9d316f04214f7efdbb6398d545446e246eff02"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.10"

[[DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
version = "1.0.0"

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[Downloads]]
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"

[[Formatting]]
deps = ["Printf"]
git-tree-sha1 = "8339d61043228fdd3eb658d86c926cb282ae72a8"
uuid = "59287772-0a20-5a39-b81b-1366585eb4c0"
version = "0.4.2"

[[Future]]
deps = ["Random"]
uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"

[[Hyperscript]]
deps = ["Test"]
git-tree-sha1 = "8d511d5b81240fc8e6802386302675bdf47737b9"
uuid = "47d2ed2b-36de-50cf-bf87-49c2cf4b8b91"
version = "0.0.4"

[[HypertextLiteral]]
git-tree-sha1 = "2b078b5a615c6c0396c77810d92ee8c6f470d238"
uuid = "ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2"
version = "0.9.3"

[[IOCapture]]
deps = ["Logging", "Random"]
git-tree-sha1 = "f7be53659ab06ddc986428d3a9dcc95f6fa6705a"
uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
version = "0.2.2"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[InvertedIndices]]
git-tree-sha1 = "bee5f1ef5bf65df56bdd2e40447590b272a5471f"
uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f"
version = "1.1.0"

[[IteratorInterfaceExtensions]]
git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856"
uuid = "82899510-4779-5014-852e-03e436cf321d"
version = "1.0.0"

[[JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "8076680b162ada2a031f707ac7b4953e30667a37"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.2"

[[LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"

[[LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"

[[LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[LinearAlgebra]]
deps = ["Libdl"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"

[[Missings]]
deps = ["DataAPI"]
git-tree-sha1 = "bf210ce90b6c9eed32d25dbcae1ebc565df2687f"
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
version = "1.0.2"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"

[[NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"

[[OrderedCollections]]
git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.4.1"

[[Parsers]]
deps = ["Dates"]
git-tree-sha1 = "ae4bbcadb2906ccc085cf52ac286dc1377dceccc"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "2.1.2"

[[Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[PlutoUI]]
deps = ["AbstractPlutoDingetjes", "Base64", "Dates", "Hyperscript", "HypertextLiteral", "IOCapture", "InteractiveUtils", "JSON", "Logging", "Markdown", "Random", "Reexport", "UUIDs"]
git-tree-sha1 = "e071adf21e165ea0d904b595544a8e514c8bb42c"
uuid = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
version = "0.7.19"

[[PooledArrays]]
deps = ["DataAPI", "Future"]
git-tree-sha1 = "db3a23166af8aebf4db5ef87ac5b00d36eb771e2"
uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
version = "1.4.0"

[[PrettyTables]]
deps = ["Crayons", "Formatting", "Markdown", "Reexport", "Tables"]
git-tree-sha1 = "d940010be611ee9d67064fe559edbb305f8cc0eb"
uuid = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
version = "1.2.3"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[Reexport]]
git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "1.2.2"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[SharedArrays]]
deps = ["Distributed", "Mmap", "Random", "Serialization"]
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[SortingAlgorithms]]
deps = ["DataStructures"]
git-tree-sha1 = "b3363d7460f7d098ca0912c69b082f75625d7508"
uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
version = "1.0.1"

[[SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[TOML]]
deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[[TableTraits]]
deps = ["IteratorInterfaceExtensions"]
git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39"
uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c"
version = "1.0.1"

[[Tables]]
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
git-tree-sha1 = "fed34d0e71b91734bf0a7e10eb1bb05296ddbcd0"
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
version = "1.6.0"

[[Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"

[[Test]]
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"

[[nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"

[[p7zip_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
"""

# ╔═╡ Cell order:
# ╟─1d3d6cd4-d99c-4256-a907-05529519e2d8
# ╟─ab2b0e2e-362e-4a8d-8087-45a082b44426
# ╟─96e97932-44ce-48b3-818e-db4a6f453414
# ╟─36e88abc-395b-401a-a0bb-2cb8a3ed9e4d
# ╟─4c680cf3-d884-49e5-8b36-650f7117a6ea
# ╟─c41c3013-4a58-4fc8-8d11-861fa7136714
# ╟─5681fa85-15c9-4463-be8e-e223bbd4df77
# ╠═75c185d1-c284-4443-b6bf-551079ce1a27
# ╟─99dc35a3-cf58-443e-ac17-7d378432a07e
# ╠═534af33b-7104-4d29-8e02-5cd6d866265a
# ╟─0df4917c-28f2-457f-bc41-80fac9ca33ba
# ╟─ccd45783-6a7f-4824-b83f-599de8a8a85a
# ╟─8d7fa112-2add-40dd-9c0e-1bd2e43e9d15
# ╟─16029a4c-1141-456c-9a17-81ae24aedbbc
# ╟─3df0b8ab-5989-4597-82fa-e2650f61640f
# ╟─a00e0383-0e83-428c-8b77-9b1293a7bd62
# ╟─454c47e0-0bc9-4274-80c3-3b4e8da1a580
# ╟─396fe249-8780-4f62-aa78-7840736af09c
# ╟─c53d5a8c-d3c8-4653-9dce-e6659861dfb6
# ╟─c3d8d161-752c-4b52-b2f0-3e81bc492988
# ╟─1de46b8e-0343-4d76-9d21-c80e00146255
# ╟─a1bb122f-4add-4e49-b60e-60ad110d86c0
# ╟─f1c2afca-7978-442b-9c86-a2c6f895b878
# ╠═6168b981-e2c2-45d1-8055-b8bb674155d1
# ╟─9b985a9c-683f-4371-a02e-7b4ff12f3a95
# ╟─4fa0f050-4b8b-11ec-24d5-1f995fc27946
# ╟─51c51dc1-a946-4217-81e0-8730d40b7557
# ╟─96808cd0-6eaf-4d48-b095-038dbbe585ce
# ╟─44bc0d4e-f1d6-4904-ab85-bb424124e12f
# ╟─00000000-0000-0000-0000-000000000001
# ╟─00000000-0000-0000-0000-000000000002


text:
function alexnet(name::Symbol; kwargs...)
    assert_name_present_in(name, (:alexnet,))
    model = Lux.transform(AlexNet().layers)
    return initialize_model(name, model; kwargs...)
end

function resnet(name::Symbol; kwargs...)
    assert_name_present_in(name, (:resnet18, :resnet34, :resnet50, :resnet101, :resnet152))
    model = if name == :resnet18
        Lux.transform(ResNet(18).layers)
    elseif name == :resnet34
        Lux.transform(ResNet(34).layers)
    elseif name == :resnet50
        Lux.transform(ResNet(50).layers)
    elseif name == :resnet101
        Lux.transform(ResNet(101).layers)
    elseif name == :resnet152
        Lux.transform(ResNet(152).layers)
    end
    return initialize_model(name, model; kwargs...)
end

function resnext(name::Symbol; kwargs...)
    assert_name_present_in(name, (:resnext50, :resnext101, :resnext152))
    model = if name == :resnext50
        Lux.transform(ResNeXt(50).layers)
    elseif name == :resnext101
        Lux.transform(ResNeXt(101).layers)
    elseif name == :resnext152
        Lux.transform(ResNeXt(152).layers)
    end
    return initialize_model(name, model; kwargs...)
end

function googlenet(name::Symbol; kwargs...)
    assert_name_present_in(name, (:googlenet,))
    model = Lux.transform(GoogLeNet().layers)
    return initialize_model(name, model; kwargs...)
end

function densenet(name::Symbol; kwargs...)
    assert_name_present_in(name, (:densenet121, :densenet161, :densenet169, :densenet201))
    model = if name == :densenet121
        Lux.transform(DenseNet(121).layers)
    elseif name == :densenet161
        Lux.transform(DenseNet(161).layers)
    elseif name == :densenet169
        Lux.transform(DenseNet(169).layers)
    elseif name == :densenet201
        Lux.transform(DenseNet(201).layers)
    end
    return initialize_model(name, model; kwargs...)
end

function mobilenet(name::Symbol; kwargs...)
    assert_name_present_in(name,
                           (:mobilenet_v1, :mobilenet_v2, :mobilenet_v3_small,
                            :mobilenet_v3_large))
    model = if name == :mobilenet_v1
        Lux.transform(MobileNetv1().layers)
    elseif name == :mobilenet_v2
        Lux.transform(MobileNetv2().layers)
    elseif name == :mobilenet_v3_small
        Lux.transform(MobileNetv3(:small).layers)
    elseif name == :mobilenet_v3_large
        Lux.transform(MobileNetv3(:large).layers)
    end
    return initialize_model(name, model; kwargs...)
end

function convmixer(name::Symbol; kwargs...)
    assert_name_present_in(name, (:base, :large, :small))
    model = Lux.transform(ConvMixer(name).layers)
    return initialize_model(name, model; kwargs...)
end


text:
#=using Pkg
import Pkg; Pkg.add("MathOptInterface")
import Pkg; Pkg.add("Statistics")
import Pkg; Pkg.add("QuantEcon")
import Pkg; Pkg.add("Interpolations")
import Pkg; Pkg.add("NLsolve")
import Pkg; Pkg.add("Optim")
import Pkg; Pkg.add("Random")
import Pkg; Pkg.add("IterTools")
import Pkg; Pkg.add("JuMP")
import Pkg; Pkg.add("Ipopt")=#

using MathOptInterface, LinearAlgebra, Statistics, QuantEcon, Interpolations, NLsolve, Optim, Random, IterTools, JuMP, Ipopt;

u(x) = sum(log(x[i]) for i in 1:numSectors)
w(x) = sum(5*log(x[i]) for i in 1:numSectors)

β = 0.96
α = 0.4
f(x) = x^α
γ = 0.5

numSectors = 2
numPoints1D = 4

grid = Vector{Vector{Float64}}(undef,(numPoints1D)^numSectors)

gridMax = 5
gridMin = 1
gridHood = 0

iter=1
for p in product(LinRange(gridMin,gridMax,numPoints1D),LinRange(gridMin,gridMax,numPoints1D))
    grid[iter] = collect(p)
    global iter += 1
end
wVal = zeros(length(grid))
for i in 1:length(grid)
	wVal[i] = w(grid[i])
end
wVals = zeros(numPoints1D, numPoints1D)
for j in 1:numPoints1D
        for i in 1:numPoints1D
		wVals[i,j] = wVal[i + numPoints1D * (j-1)]
        end
end
function brent(f::Function, x0::Number, x1::Number, args::Tuple=();
               xtol::AbstractFloat=1e-7, ytol=2eps(Float64),
               maxiter::Integer=50)
    EPS = eps(Float64)
    y0 = f(x0,args...)
    y1 = f(x1,args...)
    if abs(y0) < abs(y1)
        # Swap lower and upper bounds.
        x0, x1 = x1, x0
        y0, y1 = y1, y0
    end
    x2 = x0
    y2 = y0
    x3 = x2
    bisection = true
    for _ in 1:maxiter
        # x-tolerance.
        if abs(x1-x0) < xtol
            return x1
        end

        # Use inverse quadratic interpolation if f(x0)!=f(x1)!=f(x2)
        # and linear interpolation (secant method) otherwise.
        if abs(y0-y2) > ytol && abs(y1-y2) > ytol
            x = x0*y1*y2/((y0-y1)*(y0-y2)) +
                x1*y0*y2/((y1-y0)*(y1-y2)) +
                x2*y0*y1/((y2-y0)*(y2-y1))
        else
            x = x1 - y1 * (x1-x0)/(y1-y0)
        end

        # Use bisection method if satisfies the conditions.
        delta = abs(2EPS*abs(x1))
        min1 = abs(x-x1)
        min2 = abs(x1-x2)
        min3 = abs(x2-x3)
        if (x < (3x0+x1)/4 && x > x1) ||
           (bisection && min1 >= min2/2) ||
           (!bisection && min1 >= min3/2) ||
           (bisection && min2 < delta) ||
           (!bisection && min3 < delta)
            x = (x0+x1)/2
            bisection = true
        else
            bisection = false
        end

        y = f(x,args...)
        # y-tolerance.
        if abs(y) < ytol
            return x
        end
        x3 = x2
        x2 = x1
        if sign(y0) != sign(y)
            x1 = x
            y1 = y
        else
            x0 = x
            y0 = y
        end
        if abs(y0) < abs(y1)
            # Swap lower and upper bounds.
            x0, x1 = x1, x0
            y0, y1 = y1, y0
        end
    end
    error("Max iteration exceeded")
end

max_stars_repo_name: uq-aibe/aim

max_issues_repo_name: uq-aibe/aim

max_forks_repo_name: uq-aibe/aim


text:
####################################################################################################
# propagate getter and functions on ContIterable
getIterCont(it::AbstractContinuationIterable) = it
getIterCont(it) = it.itr

getParams(it) = getParams(it.itr)
done(it, s) = done(it.itr, s)
plotBranchCont(contres::ContResult, state::AbstractContinuationState, it) = plotBranchCont(contres, state, getIterCont(it))
save!(br, it, state) = save!(br, it.itr, state)
####TODO TOTO
# faire getter for maxSteps
####################################################################################################
struct HaltingIterable{I, F}
	itr::I
	fun::F
end

function iterate(iter::HaltingIterable)
	next = iterate(iter.itr)
	return dispatch(iter, next)
end

function iterate(iter::HaltingIterable, (instruction, state))
	if instruction == :halt return nothing end
	next = iterate(iter.itr, state)
	return dispatch(iter, next)
end

function dispatch(iter::HaltingIterable, next)
	if next === nothing return nothing end
	return next[1], (iter.fun(iter, next[1]) ? :halt : :continue, next[2])
end

halt(iter::I, fun::F) where {I, F} = HaltingIterable{I, F}(iter, fun)
####################################################################################################
struct TeeIterable{I, F}
	itr::I
	fun::F
end

function iterate(iter::TeeIterable, args...)
	next = iterate(iter.itr, args...)
	if next !== nothing iter.fun(next[1]) end
	return next
end

tee(iter::I, fun::F) where {I, F} = TeeIterable{I, F}(iter, fun)
####################################################################################################
@with_kw_noshow mutable struct ContState2{Tv, T, Teigvals, Teigvec, Tcb} <: AbstractContinuationState
	z_pred::Tv								# predictor solution
	tau::Tv									# tangent predictor
	z_old::Tv								# current solution

	isconverged::Bool						# Boolean for newton correction
	itnewton::Int64 = 0						# Number of newton iteration (in corrector)
	itlinear::Int64 = 0						# Number of linear iteration (in newton corrector)

	step::Int64 = 0							# current continuation step
	ds::T									# step size
	theta::T								# theta parameter for constraint equation in PALC

	stopcontinuation::Bool = false			# Boolean to stop continuation
	stepsizecontrol::Bool = true			# Perform step size adaptation

	n_unstable::Tuple{Int64,Int64}  = (-1, -1)	# (current, previous)
	n_imag::Tuple{Int64,Int64} 		= (-1, -1)	# (current, previous)

	eigvals::Teigvals = nothing				# current eigenvalues
	eigvecs::Teigvec = nothing				# current eigenvectors

	event::Tcb = nothing
end

function Base.copy(state::ContState2)
	return ContState2(
		z_pred 	= _copy(state.z_pred),
		tau = _copy(state.tau),
		z_old 	= _copy(state.z_old),
		isconverged = state.isconverged,
		itnewton 	= state.itnewton,
		step 		= state.step,
		ds 			= state.ds,
		theta 		= state.theta,
		stopcontinuation = state.stopcontinuation,
		stepsizecontrol  = state.stepsizecontrol,
		n_unstable 		 = state.n_unstable,
		n_imag 			 = state.n_imag,
		event		 	 = state.event,
		eigvals			 = state.eigvals
	)
end

function copy2(state::ContState)
	return ContState2(
		z_pred 	= _copy(state.z_pred),
		tau = _copy(state.tau),
		z_old 	= _copy(state.z_old),
		isconverged = state.isconverged,
		itnewton 	= state.itnewton,
		step 		= state.step,
		ds 			= state.ds,
		theta 		= state.theta,
		stopcontinuation = state.stopcontinuation,
		stepsizecontrol  = state.stepsizecontrol,
		n_unstable 		 = state.n_unstable,
		n_imag 			 = state.n_imag,
		event		 	 = state.event,
		eigvals			 = state.eigvals
	)
end

# condition for halting the continuation procedure (i.e. when returning false)
@inline done(it::AbstractContinuationIterable, state::ContState2) =
			(state.step <= it.contParams.maxSteps) &&
			((it.contParams.pMin < state.z_old.p < it.contParams.pMax) || state.step == 0) &&
			(state.stopcontinuation == false)
####################################################################################################
function iterate(it::AbstractContinuationIterable, state::ContState2; _verbosity = it.verbosity)
	@warn "Iterate qcq"
	# if !done(it, state) return nothing end
	# next line is to overwrite verbosity behaviour, like when locating bifurcations
	verbosity = min(it.verbosity, _verbosity) > 0
	verbose = verbosity > 0

	@unpack step, ds, theta = state

	# Predictor: state.z_pred. The following method only mutates z_pred
	getPredictor!(state, it)
	verbose && print("#"^35*"\nStart of Continuation Step $step:\nParameter $(getLensParam(it.lens))");
	verbose && @printf(" = %2.4e ⟶  %2.4e [guess]\n", state.z_old.p, state.z_pred.p)
	verbose && @printf("Step size = %2.4e\n", ds)

	# Corrector, ie newton correction. This does not mutate the arguments
	z_newton, fval, state.isconverged, state.itnewton, state.itlinear = corrector(it,
			state.z_old, state.tau, state.z_pred,
			ds, theta,
			it.tangentAlgo, it.linearAlgo;
			normC = it.normC, callback = it.callbackN, iterationC = step, z0 = state.z_old)

	# Successful step
	if state.isconverged
		verbose && printstyled("--> Step Converged in $(state.itnewton) Nonlinear Iterations\n", color=:green)

		# Get tangent, it only mutates tau
		getTangent!(state.tau, z_newton, state.z_old, it,
					ds, theta, it.tangentAlgo, verbosity)

		# record previous parameter (cheap) and update current solution
		state.z_pred.p = state.z_old.p
		copyto!(state.z_old, z_newton)
	else
		verbose && printstyled("Newton correction failed\n", color=:red)
		verbose && (println("--> Newton Residuals history = ");display(fval))
	end

	# Step size control
	if ~state.stopcontinuation && stepsizecontrol(state)
		# we update the PALC paramters ds and theta, they are in the state variable
		state.ds, state.theta, state.stopcontinuation = stepSizeControl(ds, theta, it.contParams, state.isconverged, state.itnewton, state.tau, it.tangentAlgo, verbosity)
	end

	state.step += 1
	return state, state
end
####################################################################################################
# construction of iterator
function continuation2(Fhandle, Jhandle, x0, par, lens::Lens, contParams::ContinuationPar;
					linearAlgo = nothing, kwargs...)
	# Create a bordered linear solver using the newton linear solver provided by the user
	if isnothing(linearAlgo)
		_linearAlgo = BorderingBLS(contParams.newtonOptions.linsolver)
	else
		# no linear solver has been specified
		if isnothing(linearAlgo.solver)
			_linearAlgo = @set linearAlgo.solver = contParams.newtonOptions.linsolver
		else
			_linearAlgo = linearAlgo
		end
	end
	return continuation2(Fhandle, Jhandle, x0, par, lens, contParams, _linearAlgo; kwargs...)
end

function continuation2(it)
	## !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	# The result type of this method
	# is not known at compile time so we
	# need a function barrier to resolve it
	## !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

	# we compute the cache for the continuation, i.e. state::ContState
	# In this call, we also compute the initial point on the branch (and its stability) and the initial tangent
	if 1==0
		_state, rest = Base.Iterators.peel(it)
		isnothing(_state) && return nothing, nothing, nothing
		@show _state
		contRes = ContResult(getIterCont(it), _state)
		return continuation2!(rest, copy2(_state), contRes)
	else
		_states = iterate(it)
		_state = copy2(_states[1])
		states = (_state, copy(_state))
		isnothing(states) && return nothing, nothing, nothing

		# variable to hold the result from continuation, i.e. a branch
		contRes = ContResult(getIterCont(it), states[1])

		# perform the continuation
		return continuation2!(it, (_states[2][1], _state), contRes)
	end
end

function continuation2(Fhandle, Jhandle, x0, par, lens::Lens, contParams::ContinuationPar, linearAlgo::AbstractBorderedLinearSolver; bothside = false, kwargs...)
	it = ContIterable(Fhandle, Jhandle, x0, par, lens, contParams, linearAlgo; kwargs...)
	# add the stoping criterion
	it = halt(it, (i,s) -> ~done(i,s))
	return continuation2(it)
end

function continuation2!(iterCont, _state, contRes::ContResult)
	maxSteps = getParams(getIterCont(iterCont)).maxSteps
	it2 = Base.Iterators.rest(iterCont, _state)
	# limit steps number
	it2 = Base.Iterators.take(it2, maxSteps+1)
	for state in it2
		plotBranchCont(contRes, state, iterCont)
		state.step <= maxSteps && save!(contRes, iterCont, state)
	end
	return contRes, 1
end


text: lcm(m,n)

max_stars_repo_name: ethansaxenian/RosettaDecode

max_issues_repo_name: ethansaxenian/RosettaDecode

max_forks_repo_name: ethansaxenian/RosettaDecode


text:
# structs (also known as classes)
struct Prism
    # field values
    length::Real
    width::Real
    height::Real

    # struct constructor -- no arguments
    function Prism()
        new(1, 1, 1)
    end

    # constructor -- 3 arguments
    function Prism(l::Real, w::Real, h::Real)

        # catching errors for the user
        if l < 0 || w < 0 || h < 0
            error("Can't have negative values for lengths.")
        elseif l < w
            error("Can't have shorter length than width.")
        else
            new(l, w, h)
        end
    end
end

# passing structs to functions
function volume(p::Prism)
    # accessing a struct's field values
    v = p.length * p.width * p.height
end

function surface_area(p::Prism)
    s1 = p.length * p.width
    s2 = p.length * p.height
    s3 = p.width * p.height

    sa = 2 * (s1 + s2 + s3)
end

# mutable struct
# can alter field values after creating
mutable struct Circle
    radius
end

# constructor
function Circle_const(r::Real)
    Circle(r)
end

function main()

    # using first constructor of Prism struct
    p = Prism()
    # using second constructor of Prism struct
    p1 = Prism(1, 2, 3)

    # constructing a Circle
    c = Circle_const(5)

end

main()

max_stars_repo_name: nunesmelo/djs-office-hours

max_issues_repo_name: nunesmelo/djs-office-hours

max_forks_repo_name: nunesmelo/djs-office-hours


text:
"""
A module which provides common astrodynamics
calculations.

# Extended help

**Exports**

$(EXPORTS)

**Imports**

$(IMPORTS)
"""
module Calculations

export Circular, Elliptical, Parabolic, Hyperbolic
export conic, keplerian, cartesian
export perifocal, semimajor_axis
export kepler, lambert, lambert_universal, lambert_lancaster_blanchard
export specific_angular_momentum_vector, specific_angular_momentum
export specific_energy, C3, v_infinity, specific_potential_energy
export eccentricity_vector, eccentricity, semi_parameter
export distance, speed, periapsis_radius, apoapsis_radius, period
export true_anomoly, mean_motion, time_since_periapsis
export hohmann, SOI, SOA, normalize, redimension, analyticalhalo

using DocStringExtensions
using Unitful
using Requires
using Contour
using StaticArrays
using AstroTime
using LinearAlgebra

import Dates
import Roots: find_zero

@template (FUNCTIONS, METHODS, MACROS) =
    """
    $(SIGNATURES)
    $(DOCSTRING)
    $(METHODLIST)
    """

@template (TYPES, CONSTANTS) =
    """
    $(TYPEDEF)
    $(DOCSTRING)
    """

Unitful.@derived_dimension MassParameter Unitful.𝐋^3/Unitful.𝐓^2

@doc """
A unit dimension alias for length^3 / time^2. This is a common
dimension used in astrodynamics calculations.
"""
MassParameter

include(joinpath("R2BP",  "Conics.jl"))
include(joinpath("R2BP",  "R2BPCalculations.jl"))
include(joinpath("R2BP",  "Kepler.jl"))
include(joinpath("R2BP",  "Lambert.jl"))
include(joinpath("CR3BP", "CR3BPCalculations.jl"))

end # module


text:
# This file was generated by the Julia Swagger Code Generator
# Do not modify this file directly. Modify the swagger specification instead.

mutable struct EncryptionSettingsCollection <: SwaggerModel
    enabled::Any # spec type: Union{ Nothing, Bool } # spec name: enabled
    encryptionSettings::Any # spec type: Union{ Nothing, Vector{EncryptionSettingsElement} } # spec name: encryptionSettings
    encryptionSettingsVersion::Any # spec type: Union{ Nothing, String } # spec name: encryptionSettingsVersion

    function EncryptionSettingsCollection(;enabled=nothing, encryptionSettings=nothing, encryptionSettingsVersion=nothing)
        o = new()
        validate_property(EncryptionSettingsCollection, Symbol("enabled"), enabled)
        setfield!(o, Symbol("enabled"), enabled)
        validate_property(EncryptionSettingsCollection, Symbol("encryptionSettings"), encryptionSettings)
        setfield!(o, Symbol("encryptionSettings"), encryptionSettings)
        validate_property(EncryptionSettingsCollection, Symbol("encryptionSettingsVersion"), encryptionSettingsVersion)
        setfield!(o, Symbol("encryptionSettingsVersion"), encryptionSettingsVersion)
        o
    end
end # type EncryptionSettingsCollection

const _property_map_EncryptionSettingsCollection = Dict{Symbol,Symbol}(Symbol("enabled")=>Symbol("enabled"), Symbol("encryptionSettings")=>Symbol("encryptionSettings"), Symbol("encryptionSettingsVersion")=>Symbol("encryptionSettingsVersion"))
const _property_types_EncryptionSettingsCollection = Dict{Symbol,String}(Symbol("enabled")=>"Bool", Symbol("encryptionSettings")=>"Vector{EncryptionSettingsElement}", Symbol("encryptionSettingsVersion")=>"String")
Base.propertynames(::Type{ EncryptionSettingsCollection }) = collect(keys(_property_map_EncryptionSettingsCollection))
Swagger.property_type(::Type{ EncryptionSettingsCollection }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_EncryptionSettingsCollection[name]))}
Swagger.field_name(::Type{ EncryptionSettingsCollection }, property_name::Symbol) =  _property_map_EncryptionSettingsCollection[property_name]

function check_required(o::EncryptionSettingsCollection)
    (getproperty(o, Symbol("enabled")) === nothing) && (return false)
    true
end

function validate_property(::Type{ EncryptionSettingsCollection }, name::Symbol, val)
end