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, :(log(1 + exp(-0.296746779395487 + 0.5509866377924739*log(1 + exp(-0.36537726371933 + -0.13236748618316563*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.8938439926067105*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.2026514795524368*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.4969096390589627*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.850208463612319*log(1 + exp(-0.13805861779585626 + 0.8324190447258686*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.45691763611374503*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.0018061937798208305*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.06838129719944464*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.14361846152386626*log(1 + exp(0.892089992500452 + -0.9262441239021939*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.1220711338530176*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.013243228467184842*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.22830737094249542*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.12455164844812394*log(1 + exp(-0.09971606472325156 + 0.22050596868305217*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.9537528744420904*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.13795746696872868*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.0643190431003462*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))))) + log(1 + exp(-0.7906046812278151 + -0.2168623555923963*log(1 + exp(-0.36537726371933 + -0.13236748618316563*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.8938439926067105*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.2026514795524368*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.4969096390589627*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.3937942437507238*log(1 + exp(-0.13805861779585626 + 0.8324190447258686*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.45691763611374503*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.0018061937798208305*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.06838129719944464*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.013414887338259796*log(1 + exp(0.892089992500452 + -0.9262441239021939*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.1220711338530176*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.013243228467184842*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.22830737094249542*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.20160941359718088*log(1 + exp(-0.09971606472325156 + 0.22050596868305217*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.9537528744420904*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.13795746696872868*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.0643190431003462*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))))) + log(1 + exp(0.21825887860627402 + 0.23342217391611308*log(1 + exp(-0.36537726371933 + -0.13236748618316563*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.8938439926067105*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.2026514795524368*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.4969096390589627*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.7638006108327029*log(1 + exp(-0.13805861779585626 + 0.8324190447258686*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.45691763611374503*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.0018061937798208305*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.06838129719944464*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.4051674738413942*log(1 + exp(0.892089992500452 + -0.9262441239021939*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.1220711338530176*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.013243228467184842*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.22830737094249542*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.17219310126869347*log(1 + exp(-0.09971606472325156 + 0.22050596868305217*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.9537528744420904*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.13795746696872868*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.0643190431003462*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))))) + log(1 + exp(0.8210746038366681 + -0.06951431198870361*log(1 + exp(-0.36537726371933 + -0.13236748618316563*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.8938439926067105*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.2026514795524368*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.4969096390589627*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.9856384884704164*log(1 + exp(-0.13805861779585626 + 0.8324190447258686*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.45691763611374503*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.0018061937798208305*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.06838129719944464*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.2856111885860577*log(1 + exp(0.892089992500452 + -0.9262441239021939*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.1220711338530176*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.013243228467184842*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.22830737094249542*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.04937870878523665*log(1 + exp(-0.09971606472325156 + 0.22050596868305217*log(1 + exp(0.24726246482452874 + -0.2513871312104543*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.4677853214537917*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + -0.10088601735084568*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.6507022966434817*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.9537528744420904*log(1 + exp(0.30866893537934104 + -0.11067617174498023*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.7749548972944802*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.44318801341623093*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + 0.23547099627350976*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + -0.13795746696872868*log(1 + exp(-0.39572563026399044 + -0.2902839675147266*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + 0.2975675315855191*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.808554335286296*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.2217074058396178*log(1 + exp(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))) + 0.0643190431003462*log(1 + exp(0.8092602903578396 + -0.8861475410157751*log(1 + exp(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4]))) + -0.38211269748902854*log(1 + exp(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4]))) + 0.47211467596801615*log(1 + exp(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4]))) + -0.8428121402295612*log(1 + exp(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:
function init_pot_harm_3d( pw::PWGrid, dr::Array{Float64,1} )
    Npoints = size(dr)[1]
    V = zeros( Npoints )
    for ip = 1:Npoints
        V[ip] = 2.0*(dr[ip]^2)
    end
    return V
end

ext: jl


text:
function extract_params!(pm)
    if haskey(pm, "user_defined_params")
        params = Dict{Symbol,Dict{String,Any}}()
        for key in keys(pm["user_defined_params"])
            params[Symbol(key)] = pm["user_defined_params"][key]
        end
        delete!(pm, "user_defined_params")
    end
    return params
end

function check_powermodels_data!(pm)
    if pm["correct_pm_network_data"]
        _PM.correct_network_data!(pm)
    end
    if haskey(pm, "simplify_net")
        if pm["simplify_net"]
            _PM.simplify_network!(pm)
            _PM.deactivate_isolated_components!(pm)
            _PM.propagate_topology_status!(pm)
        end
    end
    return pm
end

function active_powermodels_silence!(pm)
    if pm["silence"]
        _PM.silence()
    end
end

function check_current_limit!(pm)
    cl = 0
    for (i,branch) in pm["branch"]
        if "c_rating_a" in keys(branch)
            cl += 1
        end
    end
    return cl
end

# function calculate_current!(flows)
# # calculate branch current
# for (i, l) in flows["branch"]
#     flows["branch"][i]["if"] = abs(flows["branch"][i]["pt"] / 1 / sqrt(3))
#     flows["branch"][i]["it"] = abs(flows["branch"][i]["pf"] / 1 / sqrt(3))
#     flows["branch"][i]["i_ka"] = max.(flows["branch"][i]["if"], flows["branch"][i]["it"])
# end


text:
"""
    ParameterSet

A set of parameters with which the model will be run.
"""
Base.@kwdef mutable struct ParameterSet
    group_size::Int
    parliament::AbstractDict
    parliament_size::Int
    parliament_majority::Int
    required_consensus::Float64
    parties::AbstractArray
end
# Note on Base.@kwdef:
#   * macro for automatically creating a constructor with keyword arguments
#   * apparently, it's not certain whether this will break in the future
#     (although it seems to be in common use, so it might not)
#     -> https://discourse.julialang.org/t/what-does-kwdef-do/51973

function Base.show(io::IO, params::ParameterSet)
    print(
        """
        ParameterSet with negotiator groups of size $(params.group_size)
        parliament: $(params.parliament_size) seats, required majority is $(params.parliament_majority)
        parties included in the negotiations: $(params.parties)
        """
    )
end

"""
    parameter_set_from_config(config_path::String)

Factory method to create a `ParameterSet` from a YAML configuration file.
"""
function parameter_set_from_config(config_path::String)
    config_dict = YAML.load_file(config_path)
    params = ParameterSet(
        group_size = config_dict["group_size"],
        parliament = config_dict["parliament"],
        parliament_size = calculate_parliament_size(config_dict),
        parliament_majority = config_dict["parliament_majority"],
        required_consensus = config_dict["required_consensus"],
        parties = config_dict["parties"]
    )
    return params
end

"""
    load_database(db_path::String)

Load a database from a given path while making sure that it conforms to the model standard.
"""
function load_database(db_path::String)
    db = SQLite.DB(db_path)
    @assert conforms_to_schema(db) "The database you provided is not suitable for this model."
    return db
end

# TODO: implement properly
"""
    conforms_to_schema(db::SQLite.DB)

Check if a given database conforms to the schema required by Negotiations.jl.
"""
function conforms_to_schema(db::SQLite.DB)
    schema_df = DBInterface.execute(db, """
        SELECT name
        FROM sqlite_master
        WHERE type='table'
        ORDER BY name
    """) |> DataFrame
    return (
        ("opinion" in schema_df.name)
        & ("party" in schema_df.name)
        & ("results" in schema_df.name)
        & ("sequences" in schema_df.name)
        & ("statement" in schema_df.name)
        # UPDATE with new tables if required
    )
end

"""
    calculate_parliament_size(config_dict::AbstractDict)

Calculate the number of seats of the parliament given by a `config_dict`.
The `config_dict` is a parsed YAML file (see `read_config`).
"""
function calculate_parliament_size(config_dict::AbstractDict)
    return sum(values(config_dict["parliament"]))
end


text:
using Gadfly, Colors

set_default_plot_size(6inch, 3inch)

x = repeat(collect(1:10), inner=[10])
y = repeat(collect(1:10), outer=[10])
plot(x=x, y=y, color=x+y, Geom.rectbin,
     Scale.color_continuous(colormap=p->RGB(0,p,0)))


text:
module MapsMocks

using Gridap
using TensorValues

export MockMap
export TestMap

import Gridap: evaluate!
import Gridap: return_size

struct MockMap{P} <: Map{VectorValue,1,P,1}
  val::P
end

function evaluate!(
  this::MockMap{P}, points::AbstractVector{<:VectorValue}, v::AbstractVector{P}) where P
  for (i,qi) in enumerate(points)
    v[i] = qi+this.val
  end
end

return_size(::MockMap, psize::Tuple{Int}) = psize

struct TestMap{P<:VectorValue} <: Map{VectorValue,1,P,2}
  val::P
  dim::Int
end

function evaluate!(
  this::TestMap{P}, points::AbstractVector{<:VectorValue}, v::AbstractMatrix{P}) where P
  for j in 1:this.dim
    for (i,qi) in enumerate(points)
      v[j,i] = j*qi+this.val
    end
  end
end

return_size(this::TestMap, psize::Tuple{Int}) = (this.dim, psize[1])

end # module


text:
module CommunalHelperResetCrystal

using ..Ahorn, Maple

@mapdef Entity "CommunalHelper/ResetStateCrystal" ResetCrystal(
    x::Integer,
    y::Integer,
    oneUse::Bool=false,
)

const placements = Ahorn.PlacementDict(
    "Reset State Crystal (Communal Helper)" => Ahorn.EntityPlacement(
        ResetCrystal,
    ),
)

const sprite = "objects/CommunalHelper/resetStateCrystal/ghostIdle00"

function Ahorn.selection(entity::ResetCrystal)
    x, y = Ahorn.position(entity)

    return Ahorn.getSpriteRectangle(sprite, x, y)
end

Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::ResetCrystal) =
    Ahorn.drawSprite(ctx, sprite, 0, 0; tint=(0.35, 0.35, 0.35, 1.0))

end


text:
__precompile__()

module Solvers

    using ..Utils

    include("utils/macro_utils.jl")

    export LinearSolver, LUSolver, LUSolverLAPACK,
           factorize!, solve!

    include("solvers/linear/linear_solvers.jl")
    include("solvers/linear/lu_solver.jl")
    include("solvers/linear/lu_solver_lapack.jl")

    export NonlinearSolver, AbstractNewtonSolver, NewtonSolver, QuasiNewtonSolver,
           NonlinearFunctionParameters, solverStatusOK,
           solve!, function_stages!

    include("solvers/nonlinear/nonlinear_solvers.jl")
    include("solvers/nonlinear/jacobian.jl")
    include("solvers/nonlinear/abstract_fixed_point_solver.jl")
    include("solvers/nonlinear/abstract_newton_solver.jl")
    include("solvers/nonlinear/fixed_point_solver.jl")
    include("solvers/nonlinear/newton_solver.jl")
    include("solvers/nonlinear/quasi_newton_solver.jl")

end


text:
###
### Groups with 1 generators, cyclic groups
###

"""
    drawpointorbit(f, z0 [; preiterations, iterations])

Return the drawing of the orbit of \$z_0\$ under a complex invertible function.

The orbit of \$D\$ under \$f\$ is defined as
  \$\\big<f\\big>z_0=\\{\\dots,f^{-n}(z_0),\\dots,f^{-1}(z_0),z_0,f^(z_0),\\dots,f^n(z_0),\\dots\\}\$

#### Arguments
- `f::AbstractComplexInvertibleFunction`: A Möbius transformation or inversion.
- `z0::Number`: A complex number.
- `preiterations::Integer`: Number of first iterations to calculate but not to draw.
- `iterations::Integer`: Number of iterations to calculate (after `preiterations`).
"""
function drawpointorbit(f::AbstractComplexInvertibleFunction, z0::Number;
  preiterations::Int=0, iterations::Int=20)

  finv = inverse(f)

  SDDGraphics.newdrawing()
  SDDGraphics.updatecolorarray(iterations)

  zn = z0
  zninv = z0

  for n in 1:preiterations
      zn = f(zn)
      zninv = finv(zninv)
  end # for n preiterations

  for n in 1:iterations
      SDDGraphics.color(n)

      if SDDGraphics.insiderectregion(zn)
          SDDGraphics.drawpoint(zn)
      end # if
      zn = f(zn)

      if SDDGraphics.insiderectregion(zninv)
          SDDGraphics.drawpoint(zninv)
      end # if
      zninv = finv(zninv)
  end # for n iterations

  SDDGraphics.drawing()
end # function drawpointorbit

function drawpointssetorbit(f::AbstractComplexInvertibleFunction,
  ps::Array{N,1}; preiterations::Int=0, iterations::Int=20) where N <: Number

  finv = inverse(f)

  SDDGraphics.newdrawing()
  SDDGraphics.updatecolorarray(iterations)

  pns = deepcopy(ps)
  pnsinv = deepcopy(ps)

  for n in 1:preiterations
      pns = f.(pns)
      pnsinv = finv.(pnsinv)
  end # for n preiterations

  npns = length(pns)

  for n in 1:iterations
      SDDGraphics.color(n)

      for k in 1:npns
          if SDDGraphics.insiderectregion(pns[k])
              SDDGraphics.drawpoint(pns[k])
          end # if
          pns[k] = f(pns[k])

          if SDDGraphics.insiderectregion(pnsinv[k])
              SDDGraphics.drawpoint(pnsinv[k])
          end # if
          pnsinv[k] = finv(pnsinv[k])
      end # for k pns
  end # for n iterations

  SDDGraphics.drawing()
end # function drawpointssetorbit

function drawcircleorbit(f::AbstractComplexInvertibleFunction,
  c0::AbstractCircularLinearCurve; preiterations::Int=0, iterations::Int=20)

  finv = inverse(f)

  SDDGraphics.newdrawing()
  SDDGraphics.updatecolorarray(iterations)

  cn = c0
  cninv = c0

  for n in 1:preiterations
      cn = f(cn)
      cninv = finv(cninv)
  end # for n preiterations

  for n in 1:iterations
      SDDGraphics.color(n)

      if cn isa Circle
          SDDGraphics.drawcircle(cn)
      else
          SDDGraphics.drawline(cn)
      end # if
      cn = f(cn)

      if cninv isa Circle
          SDDGraphics.drawcircle(cninv)
      else
          SDDGraphics.drawline(cninv)
      end # if
      cninv = finv(cninv)
  end # for n iterations

  SDDGraphics.drawing()
end # function drawcircleorbit

function drawcirclessetorbit(f::AbstractComplexInvertibleFunction, cs::Vector{C};
  preiterations::Int=0, iterations::Int=20) where C <: AbstractCircularLinearCurve

  finv = inverse(f)

  SDDGraphics.newdrawing()
  SDDGraphics.updatecolorarray(iterations)

  cns = deepcopy(cs)
  cnsinv = deepcopy(cs)

  for n in 1:preiterations
    cns = f.(cns)
    cnsinv = finv.(cnsinv)
  end # for n preiterations

  ncns = length(cns)

  for n in 1:iterations
    SDDGraphics.color(n)

    for k in 1:ncns
      if cns[k] isa Circle
        SDDGraphics.drawcircle(cns[k])
      else
        SDDGraphics.drawline(cnk[k])
      end # if
      cns[k] = f(cns[k])

      if cnsinv[k] isa Circle
        SDDGraphics.drawcircle(cnsinv[k])
      else
        SDDGraphics.drawline(cnsinv[k])
      end # if
      cnsinv[k] = finv(cnsinv[k])
    end
  end # for n iterations

  SDDGraphics.drawing()
end # function drawcircleorbit

#=
"""
    drawdiscorbit(f, disc [; preiterations, iterations])

Return the drawing of the orbit of a disc \$D\$ under a complex invertible function.

The orbit of \$D\$ under \$f\$ is defined as
  \$\\big<f\\big>D=\\{\\dots,f^{-n}(D),\\dots,f^{-1}(D),D,f^(D),\\dots,f^n(D),\\dots\\}\$

#### Arguments
- `f::AbstractComplexInvertibleFunction`: A Möbius transformation or inversion.
- `disc::AbstractDisc`: A disc in the Riemann sphere
- `preiterations::Integer`: Number of first iterations to calculate but not to draw.
- `iterations::Integer`: Number of iterations to calculate (after `preiterations`).
"""
function drawdiscorbit(f::AbstractComplexInvertibleFunction, d0::AbstractDisc;
  preiterations::Int=0, iterations::Int=20)

  finv = inverse(f)

  SDDGraphics.newdrawing()
  SDDGraphics.updatecolorarray(iterations)

  dn = d0
  dninv = d0

  for n in 1:preiterations
      dn = f(dn)
      dninv = finv(dninv)
  end # for n preiterations

  for n in 1:iterations
      SDDGraphics.color(n)

      if iscircle(cn)
          SDDGraphics.drawcircle(cn)
      else
          SDDGraphics.drawline(cn)
      end # if
      cn = f(cn)

      if iscircle(cninv)
          SDDGraphics.drawcircle(cninv)
      else
          SDDGraphics.drawline(cninv)
      end # if
      cninv = finv(cninv)
  end # for n iterations

  SDDGraphics.drawing()
end
=#

###
### Groups with n generators
###

function drawpointorbit(generators::Vector{F}, z0::Number=0;
  preiterations::Int=0, iterations::Int=5) where F <: AbstractComplexInvertibleFunction

  SDDGraphics.newdrawing()

  levels = preiterations + iterations + 1
  SDDGraphics.updatecolorarray(levels)

  function procedure(zn::Number, genindex::Int, level::Int, levels::Int)
    if SDDGraphics.insiderectregion(zn) && level > preiterations
      SDDGraphics.color(level)
      SDDGraphics.drawpoint(zn)
    end
  end

  traversegroupfirstdepth(generators, levels, z0, procedure)

  SDDGraphics.drawing()
end

function drawpointssetorbit(generators::Vector{F}, ps::Vector{N};
  preiterations::Int=0, iterations::Int=5)  where {F <: AbstractMobiusTransformation, N <: Number}

  SDDGraphics.newdrawing()

  levels = preiterations + iterations + 1
  SDDGraphics.updatecolorarray(levels)

  function procedure(psn::Vector{N}, genindex::Int, level::Int, levels::Int) where N <: Number
    if level > preiterations
      SDDGraphics.color(level)
      for z in psn
        if SDDGraphics.insiderectregion(z)
          SDDGraphics.drawpoint(z)
        end
      end
    end
  end

  traversegroupfirstdepth(generators, levels, ps, procedure)

  SDDGraphics.drawing()
end

function drawcircleorbit(generators::Vector{F}, c0::AbstractCircularLinearCurve;
  preiterations::Int=0, iterations::Int=5, ε::Float64=0.0001) where F <: AbstractComplexInvertibleFunction

  SDDGraphics.newdrawing()

  levels = preiterations + iterations + 1
  SDDGraphics.updatecolorarray(levels)

  function procedure(cn, genindex::Int, level::Int, levels::Int)
    if cn isa Circle && radius(cn) < ε
      return
    end
    if level > preiterations
      SDDGraphics.color(level)
      if cn isa Circle
        SDDGraphics.drawcircle(cn)
      else cn isa Line
        SDDGraphics.drawline(cn)
      end
    end
  end

  traversegroupfirstdepth(generators, levels, c0, procedure)

  SDDGraphics.drawing()
end

function drawcirclessetorbit(generators::Vector{F}, cs::Vector{C};
  preiterations::Int=0, iterations::Int=5, ε::Float64=0.0001, color=:levels,
  traverse=:firstdepth, paired::Bool=false) where {F <: AbstractComplexInvertibleFunction,
  C <: AbstractCircularLinearCurve}

  SDDGraphics.newdrawing()

  levels = preiterations + iterations + 1

  if color == :generators
    SDDGraphics.updatecolorarray(2length(generators))
  elseif color == :circles
    SDDGraphics.updatecolorarray(length(cs))
  else
    SDDGraphics.updatecolorarray(levels)
  end

  function procedure(cns, genindex::Int, level::Int, levels::Int)
    if level > preiterations
      if color == :generators
        if genindex == 0
          SDDGraphics.color(SDDGraphics.fgcolor())
        else
          SDDGraphics.color(genindex)
        end
      elseif color == :levels
        SDDGraphics.color(level)
      end
      for cn in cns
        if cn isa Circle
          if radius(cn) < ε
            continue
          end
          SDDGraphics.drawcircle(cn)
        else cn isa Line
          SDDGraphics.drawline(cn)
        end
      end
    end
  end

  if traverse == :firstbreath
    traversegroupfirstbreath(generators, levels, cs, procedure, paired)
  elseif traverse == :semigroup
    traversesemigroup(generators, levels, cs, procedure)
  else
    traversegroupfirstdepth(generators, levels, cs, procedure, paired)
  end

  SDDGraphics.drawing()
end


text:
#= -------------------------------------------------------------------------
# @file test.jl
#
# @date 03/10/16 10:38:00
# @author Martin Noblia
# @email martin.noblia@openmailbox.org
#
# @brief
#
# @detail
#
  Licence:
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License

---------------------------------------------------------------------------=#
N = length(readlines(STDIN))
re = r"\+?\d+" # regular expresion for find numbers
for i = 2:10
    for j = 1:3
        for line in readlines(STDIN)
        #println(chomp(line))
        line = chomp(line)
        #line = filter(x-> x != ' ', line)
        @show s = [parse(Int, s) for s in matchall(re, line)]
        end
    end
end

max_stars_repo_name: elsuizo/CodeJam

max_issues_repo_name: elsuizo/CodeJam

max_forks_repo_name: elsuizo/CodeJam


text:
__precompile__()

module PyPlot

using PyCall
import PyCall: PyObject, pygui, pycall, pyexists
import Base: convert, ==, isequal, hash, getindex, setindex!, haskey, keys, show, mimewritable
export Figure, plt, matplotlib, pygui, withfig

using Compat
@compat import Base.show

# Wrapper around matplotlib Figure, supporting graphics I/O and pretty display
type Figure
    o::PyObject
end

###########################################################################
# Julia 0.4 help system: define a documentation object
# that lazily looks up help from a PyObject via zero or more keys.
# This saves us time when loading PyPlot, since we don't have
# to load up all of the documentation strings right away.
immutable LazyHelp
    o::PyObject
    keys::Tuple{Vararg{Compat.String}}
    LazyHelp(o::PyObject) = new(o, ())
    LazyHelp(o::PyObject, k::AbstractString) = new(o, (k,))
    LazyHelp(o::PyObject, k1::AbstractString, k2::AbstractString) = new(o, (k1,k2))
    LazyHelp(o::PyObject, k::Tuple{Vararg{AbstractString}}) = new(o, k)
end
@compat function show(io::IO, ::MIME"text/plain", h::LazyHelp)
    o = h.o
    for k in h.keys
        o = o[k]
    end
    if haskey(o, "__doc__")
        print(io, convert(AbstractString, o["__doc__"]))
    else
        print(io, "no Python docstring found for ", h.k)
    end
end
Base.show(io::IO, h::LazyHelp) = @compat show(io, "text/plain", h)
function Base.Docs.catdoc(hs::LazyHelp...)
    Base.Docs.Text() do io
        for h in hs
            @compat show(io, MIME"text/plain"(), h)
        end
    end
end

###########################################################################
# global PyObject constants that get initialized at runtime.  We
# initialize them here (rather than via "global const foo = ..." in __init__)
# so that their type is known at compile-time.

# remove this once we tag and require a newer PyCall version:
if isdefined(PyCall,:PyNULL)
    PyNULL() = PyCall.PyNULL()
else
    PyNULL() = PyCall.PyObject()
end

const matplotlib = PyNULL()
const plt = PyNULL()
const Gcf = PyNULL()
const orig_draw = PyNULL()
const orig_gcf = PyNULL()
const orig_figure = PyNULL()
const orig_show = PyNULL()
const mplot3d = PyNULL()
const axes3D = PyNULL()
const art3D = PyNULL()

###########################################################################
# file formats supported by Agg backend, from MIME types
const aggformats = Dict("application/eps" => "eps",
                        "image/eps" => "eps",
                        "application/pdf" => "pdf",
                        "image/png" => "png",
                        "application/postscript" => "ps",
                        "image/svg+xml" => "svg")

function isdisplayok()
    for mime in keys(aggformats)
        if displayable(mime)
            return true
        end
    end
    false
end

###########################################################################
# We allow the user to turn on or off the Python gui interactively via
# pygui(true/false).  This is done by loading pyplot with a GUI backend
# if possible, then switching to a Julia-display backend (if available)

# return (backend,gui) tuple
function find_backend(matplotlib::PyObject)
    gui2matplotlib = Dict(:wx=>"WXAgg",:gtk=>"GTKAgg",:gtk3=>"GTK3Agg",
                          :qt=>"Qt4Agg",:tk=>"TkAgg")
    conda = PyCall.conda || !isempty(PyCall.anaconda_conda())
    if is_linux()
        guis = [:tk, :gtk3, :gtk, :qt, :wx]
    elseif is_apple() && conda # partially work around #164
        guis = [:qt, :tk, :wx, :gtk, :gtk3]
    else
        guis = [:tk, :qt, :wx, :gtk, :gtk3]
    end
    options = [(g,gui2matplotlib[g]) for g in guis]

    matplotlib2gui = Dict("wx"=>:wx, "wxagg"=>:wx,
                          "gtkagg"=>:gtk, "gtk"=>:gtk,"gtkcairo"=>:gtk,
                          "gtk3agg"=>:gtk3, "gtk3"=>:gtk3,"gtk3cairo"=>:gtk3,
                          "qt4agg"=>:qt, "tkagg"=>:tk,
                          "agg"=>:none,"ps"=>:none,"pdf"=>:none,
                          "svg"=>:none,"cairo"=>:none,"gdk"=>:none,
                          "module://gr.matplotlib.backend_gr"=>:gr)

    qt2gui = Dict("pyqt4"=>:qt_pyqt4, "pyside"=>:qt_pyside)

    rcParams = PyDict(matplotlib["rcParams"])
    default = lowercase(get(ENV, "MPLBACKEND",
                            get(rcParams, "backend", "none")))
    if haskey(matplotlib2gui,default)
        defaultgui = matplotlib2gui[default]

        # if the user explicitly requested a particular GUI,
        # it makes sense to ensure that the relevant Conda
        # package is installed (if we are using Conda).
        if conda
            if defaultgui == :qt
                # default to pyqt rather than pyside, as below:
                defaultgui = haskey(rcParams,"backend.qt4") ? qt2gui[lowercase(rcParams["backend.qt4"])] : :qt_pyqt4
                if defaultgui == :qt_pyside
                    pyimport_conda("PySide", "pyside")
                else
                    pyimport_conda("PyQt4", "pyqt")
                end
            elseif defaultgui == :wx
                pyimport_conda("wx", "wxpython")
            end
        end

        insert!(options, 1, (defaultgui,default))
    end

    try
        # We will get an exception when we import pyplot below (on
        # Unix) if an X server is not available, even though
        # pygui_works and matplotlib.use(backend) succeed, at
        # which point it will be too late to switch backends.  So,
        # throw exception (drop to catch block below) if DISPLAY
        # is not set.  [Might be more reliable to test
        # success(`xdpyinfo`), but only if xdpyinfo is installed.]

        if options[1][1] != :none
            @static if is_unix()
                @static if is_apple()
                    nothing
                else
                    ENV["DISPLAY"]
                end
            end
        end

        if PyCall.gui == :default
            # try to ensure that GUI both exists and has a matplotlib backend
            for (g,b) in options
                if g == :none # Matplotlib is configured to be non-interactive
                    pygui(:default)
                    matplotlib["use"](b)
                    matplotlib["interactive"](false)
                    return (b, g)
                elseif g == :gr
                    return (b, g)
                elseif PyCall.pygui_works(g)
                    # must call matplotlib.use *before* loading backends module
                    matplotlib["use"](b)
                    if g == :qt
                        if haskey(rcParams,"backend.qt4")
                            g = qt2gui[lowercase(rcParams["backend.qt4"])]
                        elseif !PyCall.pygui_works(:qt_pyqt4)
                            # both Matplotlib and PyCall default to PyQt4
                            # if it is available, but we need to tell
                            # Matplotlib to use PySide otherwise.
                            rcParams["backend.qt4"] = "PySide"
                        end
                    end
                    if pyexists("matplotlib.backends.backend_" * lowercase(b))
                        isjulia_display[1] || pygui_start(g)
                        matplotlib["interactive"](!isjulia_display[1] && Base.isinteractive())
                        return (b, g)
                    end
                end
            end
            error("no gui found") # go to catch clause below
        else # the user specified a desired backend via pygui(gui)
            gui = pygui()
            matplotlib["use"](gui2matplotlib[gui])
            if (gui==:qt && !PyCall.pygui_works(:qt_pyqt4)) || gui==:qt_pyside
                rcParams["backend.qt4"] = "PySide"
            end
            isjulia_display[1] || pygui_start(gui)
            matplotlib["interactive"](!isjulia_display[1] && Base.isinteractive())
            return (gui2matplotlib[gui], gui)
        end
    catch
        if !isjulia_display[1]
            warn("No working GUI backend found for matplotlib.")
            isjulia_display[1] = true
        end
        pygui(:default)
        matplotlib["use"]("Agg") # GUI not available
        matplotlib["interactive"](false)
        return ("Agg", :none)
    end
end

# initialization -- anything that depends on Python has to go here,
# so that it occurs at runtime (while the rest of PyPlot can be precompiled).
function __init__()
    global const isjulia_display = Bool[isdisplayok()]
    copy!(matplotlib, pyimport_conda("matplotlib", "matplotlib"))
    global const version = try
        convert(VersionNumber, matplotlib[:__version__])
    catch
        v"0.0" # fallback
    end

    backend_gui = find_backend(matplotlib)
    # workaround JuliaLang/julia#8925
    global const backend = backend_gui[1]
    global const gui = backend_gui[2]

    copy!(plt, pyimport("matplotlib.pyplot")) # raw Python module

    pytype_mapping(plt["Figure"], Figure)

    copy!(Gcf, pyimport("matplotlib._pylab_helpers")["Gcf"])
    copy!(orig_gcf, plt["gcf"])
    copy!(orig_figure, plt["figure"])
    plt["gcf"] = gcf
    plt["figure"] = figure

    if isdefined(Main, :IJulia) && Main.IJulia.inited
        Main.IJulia.push_preexecute_hook(force_new_fig)
        Main.IJulia.push_postexecute_hook(display_figs)
        Main.IJulia.push_posterror_hook(close_figs)
    end

    if isjulia_display[1] && gui != :gr && backend != "Agg"
        plt["switch_backend"]("Agg")
        plt["ioff"]()
    end

    copy!(mplot3d, pyimport("mpl_toolkits.mplot3d"))
    copy!(axes3D, pyimport("mpl_toolkits.mplot3d.axes3d"))

    copy!(art3D, pyimport("mpl_toolkits.mplot3d.art3d"))

    init_colormaps()
end

function pygui(b::Bool)
    if !b != isjulia_display[1]
        if backend != "Agg"
            plt["switch_backend"](b ? backend : "Agg")
            if b
                pygui_start(gui) # make sure event loop is started
                Base.isinteractive() && plt["ion"]()
            else
                plt["ioff"]()
            end
        elseif b
            error("No working GUI backend found for matplotlib.")
        end
        isjulia_display[1] = !b
    end
    return b
end

###########################################################################
# Figure methods

PyObject(f::Figure) = f.o
convert(::Type{Figure}, o::PyObject) = Figure(o)
==(f::Figure, g::Figure) = f.o == g.o
==(f::Figure, g::PyObject) = f.o == g
==(f::PyObject, g::Figure) = f == g.o
hash(f::Figure) = hash(f.o)
pycall(f::Figure, args...; kws...) = pycall(f.o, args...; kws...)
@compat (f::Figure)(args...; kws...) = pycall(f.o, PyAny, args...; kws...)
Base.Docs.doc(f::Figure) = Base.Docs.doc(f.o)

getindex(f::Figure, x) = getindex(f.o, x)
setindex!(f::Figure, v, x) = setindex!(f.o, v, x)
haskey(f::Figure, x) = haskey(f.o, x)
keys(f::Figure) = keys(f.o)

for (mime,fmt) in aggformats
    @eval @compat function show(io::IO, m::MIME{Symbol($mime)}, f::Figure)
        if !haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict),
                   $fmt)
            throw(MethodError(@static(VERSION < v"0.5.0-dev+4340" ? writemime : show), (io, m, f)))
        end
        f.o["canvas"]["print_figure"](io, format=$fmt, bbox_inches="tight")
    end
    if fmt != "svg"
        @eval mimewritable(::MIME{Symbol($mime)}, f::Figure) = !isempty(f) && haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict), $fmt)
    end
end

# disable SVG output by default, since displaying large SVGs (large datasets)
# in IJulia is slow, and browser SVG display is buggy.  (Similar to IPython.)
const SVG = [false]
mimewritable(::MIME"image/svg+xml", f::Figure) = SVG[1] && !isempty(f) && haskey(pycall(f.o["canvas"]["get_supported_filetypes"], PyDict), "svg")
svg() = SVG[1]
svg(b::Bool) = (SVG[1] = b)

###########################################################################
# In IJulia, we want to automatically display any figures
# at the end of cell execution, and then close them.   However,
# we don't want to display/close figures being used in withfig,
# since the user is keeping track of these in some other way,
# e.g. for interactive widgets.

Base.isempty(f::Figure) = isempty(pycall(f["get_axes"], PyVector))

# We keep a set of figure numbers for the figures used in withfig, because
# for these figures we don't want to auto-display or auto-close them
# when the cell finishes executing.   (We store figure numbers, rather
# than Figure objects, since the latter would prevent the figures from
# finalizing and hence closing.)  Closing the figure removes it from this set.
const withfig_fignums = Set{Int}()

function display_figs() # called after IJulia cell executes
    if isjulia_display[1]
        for manager in Gcf["get_all_fig_managers"]()
            f = manager["canvas"]["figure"]
            if f[:number] ∉ withfig_fignums
                fig = Figure(f)
                isempty(fig) || display(fig)
                pycall(plt["close"], PyAny, f)
            end
        end
    end
end

function close_figs() # called after error in IJulia cell
    if isjulia_display[1]
        for manager in Gcf["get_all_fig_managers"]()
            f = manager["canvas"]["figure"]
            if f[:number] ∉ withfig_fignums
                pycall(plt["close"], PyAny, f)
            end
        end
    end
end

# hook to force new IJulia cells to create new figure objects
const gcf_isnew = [false] # true to force next gcf() to be new figure
force_new_fig() = gcf_isnew[1] = true

# monkey-patch gcf() and figure() so that we can force the creation
# of new figures in new IJulia cells (e.g. after @manipulate commands
# that leave the figure from the previous cell open).

@doc LazyHelp(orig_figure) function figure(args...; kws...)
    gcf_isnew[1] = false
    pycall(orig_figure, PyAny, args...; kws...)
end

@doc LazyHelp(orig_gcf) function gcf()
    if isjulia_display[1] && gcf_isnew[1]
        return figure()
    else
        return pycall(orig_gcf, PyAny)
    end
end

###########################################################################

# export documented pyplot API (http://matplotlib.org/api/pyplot_api.html)
export acorr,annotate,arrow,autoscale,autumn,axes,axhline,axhspan,axis,axvline,axvspan,bar,barbs,barh,bone,box,boxplot,broken_barh,cla,clabel,clf,clim,cohere,colorbar,colors,contour,contourf,cool,copper,csd,delaxes,disconnect,draw,errorbar,eventplot,figaspect,figimage,figlegend,figtext,figure,fill_between,fill_betweenx,findobj,flag,gca,gcf,gci,get_current_fig_manager,get_figlabels,get_fignums,get_plot_commands,ginput,gray,grid,hexbin,hist2D,hlines,hold,hot,hsv,imread,imsave,imshow,ioff,ion,ishold,jet,legend,locator_params,loglog,margins,matshow,minorticks_off,minorticks_on,over,pause,pcolor,pcolormesh,pie,pink,plot,plot_date,plotfile,polar,prism,psd,quiver,quiverkey,rc,rc_context,rcdefaults,rgrids,savefig,sca,scatter,sci,semilogx,semilogy,set_cmap,setp,show,specgram,spectral,spring,spy,stackplot,stem,step,streamplot,subplot,subplot2grid,subplot_tool,subplots,subplots_adjust,summer,suptitle,table,text,thetagrids,tick_params,ticklabel_format,tight_layout,title,tricontour,tricontourf,tripcolor,triplot,twinx,twiny,vlines,waitforbuttonpress,winter,xkcd,xlabel,xlim,xscale,xticks,ylabel,ylim,yscale,yticks

# The following pyplot functions must be handled specially since they
# overlap with standard Julia functions:
#          close, connect, fill, hist, xcorr
import Base: close, connect, fill, step

const plt_funcs = (:acorr,:annotate,:arrow,:autoscale,:autumn,:axes,:axhline,:axhspan,:axis,:axvline,:axvspan,:bar,:barbs,:barh,:bone,:box,:boxplot,:broken_barh,:cla,:clabel,:clf,:clim,:cohere,:colorbar,:colors,:contour,:contourf,:cool,:copper,:csd,:delaxes,:disconnect,:draw,:errorbar,:eventplot,:figaspect,:figimage,:figlegend,:figtext,:fill_between,:fill_betweenx,:findobj,:flag,:gca,:gci,:get_current_fig_manager,:get_figlabels,:get_fignums,:get_plot_commands,:ginput,:gray,:grid,:hexbin,:hlines,:hold,:hot,:hsv,:imread,:imsave,:imshow,:ioff,:ion,:ishold,:jet,:legend,:locator_params,:loglog,:margins,:matshow,:minorticks_off,:minorticks_on,:over,:pause,:pcolor,:pcolormesh,:pie,:pink,:plot,:plot_date,:plotfile,:polar,:prism,:psd,:quiver,:quiverkey,:rc,:rc_context,:rcdefaults,:rgrids,:savefig,:sca,:scatter,:sci,:semilogx,:semilogy,:set_cmap,:setp,:specgram,:spectral,:spring,:spy,:stackplot,:stem,:streamplot,:subplot,:subplot2grid,:subplot_tool,:subplots,:subplots_adjust,:summer,:suptitle,:table,:text,:thetagrids,:tick_params,:ticklabel_format,:tight_layout,:title,:tricontour,:tricontourf,:tripcolor,:triplot,:twinx,:twiny,:vlines,:waitforbuttonpress,:winter,:xkcd,:xlabel,:xlim,:xscale,:xticks,:ylabel,:ylim,:yscale,:yticks)

for f in plt_funcs
    sf = string(f)
    @eval @doc LazyHelp(plt,$sf) function $f(args...; kws...)
        if !haskey(plt, $sf)
            error("matplotlib ", version, " does not have pyplot.", $sf)
        end
        return pycall(plt[$sf], PyAny, args...; kws...)
    end
end

@doc LazyHelp(plt,"step") step(x, y; kws...) = pycall(plt["step"], PyAny, x, y; kws...)

Base.show() = begin pycall(plt["show"], PyObject); nothing; end

close(f::Figure) = close(f[:number])
function close(f::Integer)
    pop!(withfig_fignums, f, f)
    pycall(plt["close"], PyAny, f)
end
close(f::Union{AbstractString,Symbol}) = pycall(plt["close"], PyAny, f)
@doc LazyHelp(plt,"close") close() = pycall(plt["close"], PyAny)

@doc LazyHelp(plt,"connect") connect(s::Union{AbstractString,Symbol}, f::Function) = pycall(plt["connect"], PyAny, s, f)

@doc LazyHelp(plt,"fill") fill(x::AbstractArray,y::AbstractArray, args...; kws...) =
    pycall(plt["fill"], PyAny, x, y, args...; kws...)

# consistent capitalization with mplot3d, avoid conflict with Base.hist2d
@doc LazyHelp(plt,"hist2d") hist2D(args...; kws...) = pycall(plt["hist2d"], PyAny, args...; kws...)

# no way to use method dispatch for hist or xcorr, since their
# argument signatures look too much like Julia's -- just use plt[:hist]

include("colormaps.jl")

###########################################################################
# Support array of string labels in bar chart

function bar{T<:AbstractString}(x::AbstractVector{T}, y; kws...)
    xi = 1:length(x)
    if !any(kw -> kw[1] == :align, kws)
        push!(kws, (:align, "center"))
    end
    p = bar(xi, y; kws...)
    ax = any(kw -> kw[1] == :orientation && lowercase(kw[2]) == "horizontal",
             kws) ? gca()["yaxis"] : gca()["xaxis"]
    ax["set_ticks"](xi)
    ax["set_ticklabels"](x)
    return p
end

bar{T<:Symbol}(x::AbstractVector{T}, y; kws...) =
    bar(map(string, x), y; kws...)

###########################################################################
# Include mplot3d for 3d plotting.

export art3D, Axes3D, surf, mesh, bar3D, contour3D, contourf3D, plot3D, plot_surface, plot_trisurf, plot_wireframe, scatter3D, text2D, text3D, zlabel, zlim, zscale, zticks

const mplot3d_funcs = (:bar3d, :contour3D, :contourf3D, :plot3D, :plot_surface,
                       :plot_trisurf, :plot_wireframe, :scatter3D,
                       :text2D, :text3D)

for f in mplot3d_funcs
    fs = string(f)
    @eval @doc LazyHelp(axes3D,"Axes3D", $fs) function $f(args...; kws...)
        ax = gca(projection="3d")
        pycall(ax[$fs], PyAny, args...; kws...)
    end
end

# TODO: in Julia 0.4, change this to a callable object
@doc LazyHelp(axes3D,"Axes3D") Axes3D(args...; kws...) = pycall(axes3D["Axes3D"], PyAny, args...; kws...)

# correct for annoying mplot3d inconsistency
@doc LazyHelp(axes3D,"Axes3D", "bar3d") bar3D(args...) = bar3d(args...)

# it's annoying to have xlabel etc. but not zlabel
const zlabel_funcs = (:zlabel, :zlim, :zscale, :zticks)
for f in zlabel_funcs
    fs = string("set_", f)
    @eval @doc LazyHelp(axes3D,"Axes3D", $fs) function $f(args...; kws...)
        ax = gca(projection="3d")
        pycall(ax[$fs], PyAny, args...; kws...)
    end
end

# export Matlab-like names

function surf(Z::AbstractMatrix; kws...)
    plot_surface([1:size(Z,1);]*ones(1,size(Z,2)),
                 ones(size(Z,1))*[1:size(Z,2);]', Z; kws...)
end

@doc LazyHelp(axes3D,"Axes3D", "plot_surface") function surf(X, Y, Z::AbstractMatrix, args...; kws...)
    plot_surface(X, Y, Z, args...; kws...)
end

function surf(X, Y, Z::AbstractVector, args...; kws...)
    plot_trisurf(X, Y, Z, args...; kws...)
end

@doc LazyHelp(axes3D,"Axes3D", "plot_wireframe") mesh(args...; kws...) = plot_wireframe(args...; kws...)

function mesh(Z::AbstractMatrix; kws...)
    plot_wireframe([1:size(Z,1);]*ones(1,size(Z,2)),
                   ones(size(Z,1))*[1:size(Z,2);]', Z; kws...)
end

###########################################################################
# Allow plots with 2 independent variables (contour, surf, ...)
# to accept either 2 1d arrays or a row vector and a 1d array,
# to simplify construction of such plots via broadcasting operations.
# (Matplotlib is inconsistent about this.)

for f in (:contour, :contourf)
    @eval function $f(X::AbstractMatrix, Y::AbstractVector, args...; kws...)
        if size(X,1) == 1 || size(X,2) == 1
            $f(reshape(X, length(X)), Y, args...; kws...)
        elseif size(X,1) > 1 && size(X,2) > 1 && isempty(args)
            $f(X; levels=Y, kws...) # treat Y as contour levels
        else
            throw(ArgumentError("if 2nd arg is column vector, 1st arg must be row or column vector"))
        end
    end
end

for f in (:surf,:mesh,:plot_surface,:plot_wireframe,:contour3D,:contourf3D)
    @eval begin
        function $f(X::AbstractVector, Y::AbstractVector, Z::AbstractMatrix, args...; kws...)
            m, n = length(X), length(Y)
            $f(repmat(reshape(X,1,m),n,1), repmat(Y,1,m), Z, args...; kws...)
        end
        function $f(X::AbstractMatrix, Y::AbstractVector, Z::AbstractMatrix, args...; kws...)
            if size(X,1) != 1 && size(X,2) != 1
                throw(ArgumentError("if 2nd arg is column vector, 1st arg must be row or column vector"))
            end
            m, n = length(X), length(Y)
            $f(repmat(reshape(X,1,m),n,1), repmat(Y,1,m), Z, args...; kws...)
        end
    end
end

# Already work: barbs, pcolor, pcolormesh, quiver

# Matplotlib pcolor* functions accept 1d arrays but not ranges
for f in (:pcolor, :pcolormesh)
    @eval begin
        $f(X::Range, Y::Range, args...; kws...) = $f([X...], [Y...], args...; kws...)
        $f(X::Range, Y::AbstractArray, args...; kws...) = $f([X...], Y, args...; kws...)
        $f(X::AbstractArray, Y::Range, args...; kws...) = $f(X, [Y...], args...; kws...)
    end
end

###########################################################################
# a more pure functional style, that returns the figure but does *not*
# have any display side-effects.  Mainly for use with @manipulate (Interact.jl)

function withfig(actions::Function, f::Figure; clear=true)
    ax_save = gca()
    push!(withfig_fignums, f[:number])
    figure(f[:number])
    finalizer(f, close)
    try
        if clear && !isempty(f)
            clf()
        end
        actions()
    catch
        rethrow()
    finally
        try
            sca(ax_save) # may fail if axes were overwritten
        end
        Main.IJulia.undisplay(f)
    end
    return f
end

###########################################################################

using LaTeXStrings
export LaTeXString, latexstring, @L_str, @L_mstr

end # module PyPlot