text:
using JuMP, EAGO

                     m = Model()

                     EAGO.register_eago_operators!(m)

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

                     @variable(m, -1.263105417837706 <= q <= 2.4766737340949954)

                     add_NL_constraint(m, :((0.7635571507341847 + -0.35250618093605723*(0.5051094873509578 + -0.17934163301535788*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9610191438924418*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)*(1 + erf((0.5051094873509578 + -0.17934163301535788*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9610191438924418*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)/sqrt(2)))/2 + 0.1709251594821839*(0.058205314222445015 + 0.7954955842799771*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9762293687340509*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)*(1 + erf((0.058205314222445015 + 0.7954955842799771*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9762293687340509*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)/sqrt(2)))/2)*(1 + erf((0.7635571507341847 + -0.35250618093605723*(0.5051094873509578 + -0.17934163301535788*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9610191438924418*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)*(1 + erf((0.5051094873509578 + -0.17934163301535788*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9610191438924418*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)/sqrt(2)))/2 + 0.1709251594821839*(0.058205314222445015 + 0.7954955842799771*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9762293687340509*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)*(1 + erf((0.058205314222445015 + 0.7954955842799771*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9762293687340509*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)/sqrt(2)))/2)/sqrt(2)))/2 + (-0.29663194049169395 + 0.013502946151282558*(0.5051094873509578 + -0.17934163301535788*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9610191438924418*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)*(1 + erf((0.5051094873509578 + -0.17934163301535788*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9610191438924418*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)/sqrt(2)))/2 + -0.2459643040595232*(0.058205314222445015 + 0.7954955842799771*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9762293687340509*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)*(1 + erf((0.058205314222445015 + 0.7954955842799771*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9762293687340509*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)/sqrt(2)))/2)*(1 + erf((-0.29663194049169395 + 0.013502946151282558*(0.5051094873509578 + -0.17934163301535788*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9610191438924418*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)*(1 + erf((0.5051094873509578 + -0.17934163301535788*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9610191438924418*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)/sqrt(2)))/2 + -0.2459643040595232*(0.058205314222445015 + 0.7954955842799771*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9762293687340509*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)*(1 + erf((0.058205314222445015 + 0.7954955842799771*(-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((-0.331542222824047 + 0.7450661875335634*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + -0.10668129539960924*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2 + -0.9762293687340509*(0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)*(1 + erf((0.6781688636512797 + -0.22580923517577522*(0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))*(1 + erf((0.04378671584682481 + 0.6928572029860351*$(x[1]) + 0.8337172801246142*$(x[2]) + 0.1196869024103484*$(x[3]) + -0.7815194586429408*$(x[4]))/sqrt(2)))/2 + 0.2965219706242044*(0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))*(1 + erf((0.8574467662893772 + -0.06659837723966744*$(x[1]) + -0.15959391344635332*$(x[2]) + -0.6414263171723844*$(x[3]) + 0.9253455779716249*$(x[4]))/sqrt(2)))/2)/sqrt(2)))/2)/sqrt(2)))/2)/sqrt(2)))/2 - $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:
using Query
using TypedTables
using NamedTuples
using DataFrames

df = @Table(name=Nullable{String}["John", "Sally", "Kirk"], age=Nullable{Float64}[23., 42., 59.], children=Nullable{Int64}[3,5,2])

x = @from i in df begin
    @where i.age>30 && i.children >2
    @select {Name=lowercase(get(i.name))}
    @collect DataFrame
end

println(x)

ext: jl


text:
#=
Implements the Kalman filter for a linear Gaussian state space model.

@author : Spencer Lyon <spencer.lyon@nyu.edu>

@date: 2014-07-29

References
----------

https://lectures.quantecon.org/jl/kalman.html

TODO: Do docstrings here after implementing LinerStateSpace
=#

mutable struct Kalman
    A
    G
    Q
    R
    k
    n
    cur_x_hat
    cur_sigma
end

# Initializes current mean and cov to zeros
function Kalman(A, G, Q, R)
    k = size(G, 1)
    n = size(G, 2)
    xhat = n == 1 ? zero(eltype(A)) : zeros(n)
    Sigma = n == 1 ? zero(eltype(A)) : zeros(n, n)
    return Kalman(A, G, Q, R, k, n, xhat, Sigma)
end

function set_state!(k::Kalman, x_hat, Sigma)
    k.cur_x_hat = x_hat
    k.cur_sigma = Sigma
    Void
end

doc"""
Updates the moments (`cur_x_hat`, `cur_sigma`) of the time ``t`` prior to the
time ``t`` filtering distribution, using current measurement ``y_t``.
The updates are according to

```math
    \hat{x}^F = \hat{x} + \Sigma G' (G \Sigma G' + R)^{-1}
                    (y - G \hat{x}) \\

    \Sigma^F = \Sigma - \Sigma G' (G \Sigma G' + R)^{-1} G
               \Sigma
```

#### Arguments

- `k::Kalman` An instance of the Kalman filter
- `y` The current measurement

"""
function prior_to_filtered!(k::Kalman, y)
    # simplify notation
    G, R = k.G, k.R
    x_hat, Sigma = k.cur_x_hat, k.cur_sigma

    # and then update
    if k.k > 1
        reshape(y, k.k, 1)
    end
    A = Sigma * G'
    B = G * Sigma' * G' + R
    M = A * inv(B)
    k.cur_x_hat = x_hat + M * (y - G * x_hat)
    k.cur_sigma = Sigma - M * G * Sigma
    Void
end

"""
Updates the moments of the time ``t`` filtering distribution to the
moments of the predictive distribution, which becomes the time
``t+1`` prior

#### Arguments
- `k::Kalman` An instance of the Kalman filter

"""
function filtered_to_forecast!(k::Kalman)
    # simplify notation
    A, Q = k.A, k.Q
    x_hat, Sigma = k.cur_x_hat, k.cur_sigma

    # and then update
    k.cur_x_hat = A * x_hat
    k.cur_sigma = A * Sigma * A' + Q
    Void
end

"""
Updates `cur_x_hat` and `cur_sigma` given array `y` of length `k`.  The full
update, from one period to the next

#### Arguments

- `k::Kalman` An instance of the Kalman filter
- `y` An array representing the current measurement

"""
function update!(k::Kalman, y)
    prior_to_filtered!(k, y)
    filtered_to_forecast!(k)
    Void
end

function stationary_values(k::Kalman)
    # simplify notation
    A, Q, G, R = k.A, k.Q, k.G, k.R

    # solve Riccati equation, obtain Kalman gain
    Sigma_inf = solve_discrete_riccati(A', G', Q, R)
    K_inf = A * Sigma_inf * G' * inv(G * Sigma_inf * G' + R)
    return Sigma_inf, K_inf
end


text:
input = parse.(Int, split(readline(stdin)))
println(stdout, sum(input))

max_stars_repo_name: ethansaxenian/RosettaDecode

max_issues_repo_name: ethansaxenian/RosettaDecode

max_forks_repo_name: ethansaxenian/RosettaDecode


text:
dicta = @compat Dict(
	:a => 2332,
	:b => 777,
	:c => 999,
)

dictb = @compat Dict(
	:a => 2332,
	:b => 777,
	:c => 999,
)

@materialize a,b,c = dicta
@test a == dicta[:a]
@test b == dicta[:b]
@test c == dicta[:c]

@materialize! a,b,c = dictb
@test a == dicta[:a]
@test b == dicta[:b]
@test c == dicta[:c]
@test isempty(dictb)

@materialize a,b,c = @compat Dict(
	:a => 2332,
	:b => 777,
	:c => 999,
)
@test a == dicta[:a]
@test b == dicta[:b]
@test c == dicta[:c]


text:
module ESGIWeatherLogistics2021

include("Data.jl")

using DataFrames: sort!, combine, groupby, transform
using Dates: Date
using Statistics: mean

function aggregate_daily_obs(obs)
    return sort!(
        combine(
            groupby(
                transform(obs, :date => x -> Date.(x); renamecols=false),
                [:country, :area, :date],
            ),
            :precipitation => sum,
            :temperature => mean,
            :temperature => minimum,
            :temperature => maximum,
        ),
        [:country, :area, :date],
    )
end

end


text:
export LogNeighborhood

struct LogNeighborhood <: NeighborhoodAlgorithm
    base::Float64
end

function LogNeighborhood()
    return LogNeighborhood(2)
end

function optimize_neighborhood!(algo::LogNeighborhood, index::SearchGraph{T}, dist::Function, perf, recall) where T
end

function neighborhood(algo::LogNeighborhood, index::SearchGraph{T}, dist::Function, item::T) where T
    n = length(index.db)
    k = max(1, log(algo.base, n) |> ceil |> Int)

    knn = search(index, dist, item, KnnResult(k))
    nbuffer::Vector{Int32} = Vector{Int32}(undef, length(knn))

    for (i, p) in enumerate(knn)
        nbuffer[i] = p.objID
    end

    return knn, nbuffer
end


text:
using BISC195
using Test

@testset "BISC195.jl" begin
    # Write your tests here.
end


text:
include("../utils.jl")
include("group_utils.jl")

@testset "Circle group" begin
    G = CircleGroup()
    @test repr(G) == "CircleGroup()"

    @test base_manifold(G) === Circle{ℂ}()

    @testset "identity overloads" begin
        @test identity(G, Identity(G)) === Identity(G)
        @test inv(G, Identity(G)) === Identity(G)
        y = [Complex(0.0)]
        @test identity!(G, y, [Complex(1.0)]) === y
        @test y == [Complex(1.0)]
        y = [1.0 * im]
        v = [Complex(0.5)]
        @test translate_diff(G, Identity(G), y, v) === v
    end

    @testset "scalar points" begin
        pts = [1.0 + 0.0im, 0.0 + 1.0im, (1.0 + 1.0im) / √2]
        vpts = [0.0 + 0.5im]
        @test compose(G, pts[2], pts[1]) ≈ pts[2] * pts[1]
        @test translate_diff(G, pts[2], pts[1], vpts[1]) ≈ pts[2] * vpts[1]
        test_group(G, pts, vpts; test_diff = true, test_mutating = false)
    end

    @testset "vector points" begin
        pts = [[1.0 + 0.0im], [0.0 + 1.0im], [(1.0 + 1.0im) / √2]]
        vpts = [[0.0 + 0.5im]]
        @test compose(G, pts[2], pts[1]) ≈ pts[2] .* pts[1]
        @test translate_diff(G, pts[2], pts[1], vpts[1]) ≈ pts[2] .* vpts[1]
        test_group(G, pts, vpts; test_diff = true, test_mutating = true)
    end

    @testset "Group forwards to decorated" begin
        pts = [[1.0 + 0.0im], [0.0 + 1.0im], [(1.0 + 1.0im) / √2]]
        test_manifold(
            G,
            pts,
            test_forward_diff = false,
            test_reverse_diff = false,
            test_vector_spaces = false,
            test_project_tangent = true,
            test_musical_isomorphisms = false,
            test_vector_transport = true,
            is_mutating = true,
            exp_log_atol_multiplier = 2.0,
            is_tangent_atol_multiplier = 2.0,
        )
    end
end


text:
module PolygonArea

# IMPORT/EXPORT
using StaticArrays

import Base.==, Base.isapprox
import Base.in, Base.isempty
import Base.union, Base.intersect, Base.\
import Base.convert, Base.promote_rule
import Base.show

export HalfPlane, ConvexPolygon
export rectangle, circle, area

# TYPES
abstract type Surface end

# CODE
include("points.jl")
include("half_planes.jl")
include("unions_and_intersections.jl")

include("polygons.jl")
include("example_polygons.jl")

include("io.jl")
include("plot_recipes.jl")

# Curried functions
rotate(ϕ::Number; kw...) = x -> rotate(x, ϕ; kw...)

const _VectorLike = Union{SVector{2, T}, Vector{T}} where T
translate(v::_VectorLike) = x -> translate(x, v)
scale(v::Union{Real, _VectorLike}; center=Point(0.0, 0.0)) = x -> scale(x, v; center)

end # module


text:
module TestStructuredGraphicalLinearAlgebra
using Test

using Catlab, Catlab.Doctrines
using Catlab.LinearAlgebra.StructuredGraphicalLinearAlgebra

R = ℝ(FreeStructuredLinearFunctions.Ob)
A, B = Ob(FreeStructuredLinearFunctions, :A, :B)
f, g = Hom(:f, A, B), Hom(:g, A, B)
u, v = Hom(:u, R, A), Hom(:g, R, B)

# Domains and codomains
@test dom(plus(f,g)) == A
@test codom(plus(f,g)) == B

# Unicode syntax
@test f+g == plus(f,g)

# Banded Matrices
Dᵤ = diag(u)
@test dom(Dᵤ) == A
@test codom(Dᵤ) == A

Dᵥ = diag(v)
@test dom(Dᵥ) == B
@test codom(Dᵥ) == B

@test dom(Dᵥ⋅Dᵥ) == B
@test codom(Dᵥ⋅Dᵥ) == B

@test dom(Dᵥ⊕Dᵥ) == B⊕B
@test codom(Dᵥ⊕Dᵥ) == B⊕B
@test dom(Dᵤ⊕Dᵥ) == A⊕B
@test codom(Dᵤ⊕Dᵥ) == A⊕B

end


text:
# Generate the distribution
N = 80
dt = 0.5
T = N*dt
d = Domain([1,1], [100,100])
cov = 0.010 * eye(2)
phi = zeros(100,100,N+1)
for i = 1:N+1
    mui = (.7*(i-1)/N + .15) * ones(2)
    phi[:,:,i] = gaussian(d, mui, cov)
end
ErgodicControl.normalize!(phi, d.cell_size / (N+1))

# Now let's create the ergodic manager in R3
K = 5
em = ErgodicManagerR2T(d, phi, K)

# trajectory params
x0 = [0.49, 0.01]
tm = TrajectoryManager(x0, dt, N, ConstantInitializer([0.,0.]))
tm.R = .1*eye(2)

# I call this second Armijo
tm.descender = ArmijoLineSearch(1,1e-4)

# trajectory generation and plotting
mi = 1000
ddc = 1e-5
v = true
xd,ud = pto_trajectory(em, tm, dd_crit=ddc, max_iters=mi, verbose=v)


text:
################
# General Math #
################

# unary #
#-------#

@define_diffrule Base.:+(x)                   = :(  1                                  )
@define_diffrule Base.:-(x)                   = :( -1                                  )
@define_diffrule Base.sqrt(x)                 = :(  inv(2 * sqrt($x))                  )
@define_diffrule Base.cbrt(x)                 = :(  inv(3 * cbrt($x)^2)                )
@define_diffrule Base.abs2(x)                 = :(  $x + $x                            )
@define_diffrule Base.inv(x)                  = :( -abs2(inv($x))                      )
@define_diffrule Base.log(x)                  = :(  inv($x)                            )
@define_diffrule Base.log10(x)                = :(  inv($x) / log(10)                  )
@define_diffrule Base.log2(x)                 = :(  inv($x) / log(2)                   )
@define_diffrule Base.log1p(x)                = :(  inv($x + 1)                        )
@define_diffrule Base.exp(x)                  = :(  exp($x)                            )
@define_diffrule Base.exp2(x)                 = :(  exp2($x) * log(2)                  )
@define_diffrule Base.exp10(x)                = :(  exp10($x) * log(10)                )
@define_diffrule Base.expm1(x)                = :(  exp($x)                            )
@define_diffrule Base.sin(x)                  = :(  cos($x)                            )
@define_diffrule Base.cos(x)                  = :( -sin($x)                            )
@define_diffrule Base.tan(x)                  = :(  1 + tan($x)^2                      )
@define_diffrule Base.sec(x)                  = :(  sec($x) * tan($x)                  )
@define_diffrule Base.csc(x)                  = :( -csc($x) * cot($x)                  )
@define_diffrule Base.cot(x)                  = :( -(1 + cot($x)^2)                    )
@define_diffrule Base.sind(x)                 = :(  (π / 180) * cosd($x)               )
@define_diffrule Base.cosd(x)                 = :( -(π / 180) * sind($x)               )
@define_diffrule Base.tand(x)                 = :(  (π / 180) * (1 + tand($x)^2)       )
@define_diffrule Base.secd(x)                 = :(  (π / 180) * secd($x) * tand($x)    )
@define_diffrule Base.cscd(x)                 = :( -(π / 180) * cscd($x) * cotd($x)    )
@define_diffrule Base.cotd(x)                 = :( -(π / 180) * (1 + cotd($x)^2)       )
@define_diffrule Base.sinpi(x)                = :(  π * cospi($x)                      )
@define_diffrule Base.cospi(x)                = :( -π * sinpi($x)                      )
@define_diffrule Base.asin(x)                 = :(  inv(sqrt(1 - $x^2))                )
@define_diffrule Base.acos(x)                 = :( -inv(sqrt(1 - $x^2))                )
@define_diffrule Base.atan(x)                 = :(  inv(1 + $x^2)                      )
@define_diffrule Base.asec(x)                 = :(  inv(abs($x) * sqrt($x^2 - 1))      )
@define_diffrule Base.acsc(x)                 = :( -inv(abs($x) * sqrt($x^2 - 1))      )
@define_diffrule Base.acot(x)                 = :( -inv(1 + $x^2)                      )
@define_diffrule Base.asind(x)                = :(  180 / π / sqrt(1 - $x^2)           )
@define_diffrule Base.acosd(x)                = :( -180 / π / sqrt(1 - $x^2)           )
@define_diffrule Base.atand(x)                = :(  180 / π / (1 + $x^2)               )
@define_diffrule Base.asecd(x)                = :(  180 / π / abs($x) / sqrt($x^2 - 1) )
@define_diffrule Base.acscd(x)                = :( -180 / π / abs($x) / sqrt($x^2 - 1) )
@define_diffrule Base.acotd(x)                = :( -180 / π / (1 + $x^2)               )
@define_diffrule Base.sinh(x)                 = :(  cosh($x)                           )
@define_diffrule Base.cosh(x)                 = :(  sinh($x)                           )
@define_diffrule Base.tanh(x)                 = :(  1 - tanh($x)^2                     )
@define_diffrule Base.sech(x)                 = :( -tanh($x) * sech($x)                )
@define_diffrule Base.csch(x)                 = :( -coth($x) * csch($x)                )
@define_diffrule Base.coth(x)                 = :( -(csch($x)^2)                       )
@define_diffrule Base.asinh(x)                = :(  inv(sqrt($x^2 + 1))                )
@define_diffrule Base.acosh(x)                = :(  inv(sqrt($x^2 - 1))                )
@define_diffrule Base.atanh(x)                = :(  inv(1 - $x^2)                      )
@define_diffrule Base.asech(x)                = :( -inv($x * sqrt(1 - $x^2))           )
@define_diffrule Base.acsch(x)                = :( -inv(abs($x) * sqrt(1 + $x^2))      )
@define_diffrule Base.acoth(x)                = :(  inv(1 - $x^2)                      )
@define_diffrule Base.deg2rad(x)              = :(  π / 180                            )
@define_diffrule Base.mod2pi(x)               = :(  isinteger($x / 2pi) ? NaN : 1      )
@define_diffrule Base.rad2deg(x)              = :(  180 / π                            )
@define_diffrule SpecialFunctions.gamma(x) =
    :(  SpecialFunctions.digamma($x) * SpecialFunctions.gamma($x)  )
@define_diffrule SpecialFunctions.loggamma(x) =
    :(  SpecialFunctions.digamma($x)  )
@define_diffrule Base.transpose(x)            = :(  1                                  )
@define_diffrule Base.abs(x)                  = :( DiffRules._abs_deriv($x)            )

# We provide this hook for special number types like `Interval`
# that need their own special definition of `abs`.
_abs_deriv(x) = signbit(x) ? -one(x) : one(x)

# binary #
#--------#

@define_diffrule Base.:+(x, y) = :( 1                  ), :(  1                 )
@define_diffrule Base.:-(x, y) = :( 1                  ), :( -1                 )
@define_diffrule Base.:*(x, y) = :( $y                 ), :(  $x                )
@define_diffrule Base.:/(x, y) = :( inv($y)            ), :( -($x / $y / $y)    )
@define_diffrule Base.:\(x, y) = :( -($y / $x / $x)    ), :( inv($x)            )
@define_diffrule Base.:^(x, y) = :( $y * ($x^($y - 1)) ), :(  ($x^$y) * log($x) )

if VERSION < v"0.7-"
    @define_diffrule Base.atan2(x, y)   = :( $y / ($x^2 + $y^2)                                 ), :( -$x / ($x^2 + $y^2)                                                     )
else
    @define_diffrule Base.atan(x, y)    = :( $y / ($x^2 + $y^2)                                 ), :( -$x / ($x^2 + $y^2)                                                     )
end
@define_diffrule Base.hypot(x, y)  = :( $x / hypot($x, $y)                                      ), :(  $y / hypot($x, $y)                                                     )
@define_diffrule Base.mod(x, y)    = :( first(promote(ifelse(isinteger($x / $y), NaN, 1), NaN)) ), :(  z = $x / $y; first(promote(ifelse(isinteger(z), NaN, -floor(z)), NaN)) )
@define_diffrule Base.rem(x, y)    = :( first(promote(ifelse(isinteger($x / $y), NaN, 1), NaN)) ), :(  z = $x / $y; first(promote(ifelse(isinteger(z), NaN, -trunc(z)), NaN)) )
@define_diffrule Base.rem2pi(x, r) = :( 1                                                       ), :NaN
@define_diffrule Base.max(x, y)    = :( $x > $y ? one($x) : zero($x)                            ), :( $x > $y ? zero($y) : one($y)                                            )
@define_diffrule Base.min(x, y)    = :( $x > $y ? zero($x) : one($x)                            ), :( $x > $y ? one($y) : zero($y)                                            )

####################
# SpecialFunctions #
####################

# unary #
#-------#

@define_diffrule SpecialFunctions.erf(x)         = :(  (2 / sqrt(π)) * exp(-$x * $x)       )
@define_diffrule SpecialFunctions.erfinv(x)      =
    :(  (sqrt(π) / 2) * exp(SpecialFunctions.erfinv($x)^2)  )
@define_diffrule SpecialFunctions.erfc(x)        = :( -(2 / sqrt(π)) * exp(-$x * $x)       )
@define_diffrule SpecialFunctions.erfcinv(x)     =
    :( -(sqrt(π) / 2) * exp(SpecialFunctions.erfcinv($x)^2)  )
@define_diffrule SpecialFunctions.erfi(x)        = :(  (2 / sqrt(π)) * exp($x * $x)        )
@define_diffrule SpecialFunctions.erfcx(x)       =
    :(  (2 * $x * SpecialFunctions.erfcx($x)) - (2 / sqrt(π))  )
@define_diffrule SpecialFunctions.dawson(x)      =
    :(  1 - (2 * $x * SpecialFunctions.dawson($x))  )
@define_diffrule SpecialFunctions.digamma(x) =
    :(  SpecialFunctions.trigamma($x)  )
@define_diffrule SpecialFunctions.invdigamma(x)  =
    :(  inv(SpecialFunctions.trigamma(SpecialFunctions.invdigamma($x)))  )
@define_diffrule SpecialFunctions.trigamma(x)    =
    :(  SpecialFunctions.polygamma(2, $x)  )
@define_diffrule SpecialFunctions.airyai(x)      =
    :(  SpecialFunctions.airyaiprime($x)  )
@define_diffrule SpecialFunctions.airyaiprime(x) =
    :(  $x * SpecialFunctions.airyai($x)  )
@define_diffrule SpecialFunctions.airybi(x)      =
    :(  SpecialFunctions.airybiprime($x)  )
@define_diffrule SpecialFunctions.airybiprime(x) =
    :(  $x * SpecialFunctions.airybi($x)  )
@define_diffrule SpecialFunctions.besselj0(x)    =
    :( -SpecialFunctions.besselj1($x)  )
@define_diffrule SpecialFunctions.besselj1(x)    =
    :(  (SpecialFunctions.besselj0($x) - SpecialFunctions.besselj(2, $x)) / 2  )
@define_diffrule SpecialFunctions.bessely0(x)    =
    :( -SpecialFunctions.bessely1($x)  )
@define_diffrule SpecialFunctions.bessely1(x)    =
    :(  (SpecialFunctions.bessely0($x) - SpecialFunctions.bessely(2, $x)) / 2 )

# TODO:
#
# eta
# zeta
# airyaix
# airyaiprimex
# airybix
# airybiprimex

# binary #
#--------#

@define_diffrule SpecialFunctions.besselj(ν, x)   =
    :NaN, :(  (SpecialFunctions.besselj($ν - 1, $x) - SpecialFunctions.besselj($ν + 1, $x)) / 2  )
@define_diffrule SpecialFunctions.besseli(ν, x)   =
    :NaN, :(  (SpecialFunctions.besseli($ν - 1, $x) + SpecialFunctions.besseli($ν + 1, $x)) / 2  )
@define_diffrule SpecialFunctions.bessely(ν, x)   =
    :NaN, :(  (SpecialFunctions.bessely($ν - 1, $x) - SpecialFunctions.bessely($ν + 1, $x)) / 2  )
@define_diffrule SpecialFunctions.besselk(ν, x)   =
    :NaN, :( -(SpecialFunctions.besselk($ν - 1, $x) + SpecialFunctions.besselk($ν + 1, $x)) / 2  )
@define_diffrule SpecialFunctions.hankelh1(ν, x)  =
    :NaN, :(  (SpecialFunctions.hankelh1($ν - 1, $x) - SpecialFunctions.hankelh1($ν + 1, $x)) / 2  )
@define_diffrule SpecialFunctions.hankelh2(ν, x)  =
    :NaN, :(  (SpecialFunctions.hankelh2($ν - 1, $x) - SpecialFunctions.hankelh2($ν + 1, $x)) / 2  )
@define_diffrule SpecialFunctions.polygamma(m, x) =
    :NaN, :(  SpecialFunctions.polygamma($m + 1, $x)  )
@define_diffrule SpecialFunctions.beta(a, b)      =
    :( SpecialFunctions.beta($a, $b)*(SpecialFunctions.digamma($a) - SpecialFunctions.digamma($a + $b)) ), :(  SpecialFunctions.beta($a, $b)*(SpecialFunctions.digamma($b) - SpecialFunctions.digamma($a + $b))     )
@define_diffrule SpecialFunctions.logbeta(a, b)     =
    :( SpecialFunctions.digamma($a) - SpecialFunctions.digamma($a + $b)  ), :(  SpecialFunctions.digamma($b) - SpecialFunctions.digamma($a + $b)  )

# TODO:
#
# zeta
# besseljx
# besselyx
# besselix
# besselkx
# besselh
# besselhx
# hankelh1x
# hankelh2
# hankelh2x

# ternary #
#---------#

# TODO:
#
# besselh
# besselhx

###########
# NaNMath #
###########

# unary #
#-------#

@define_diffrule NaNMath.sqrt(x)   = :(  inv(2 * NaNMath.sqrt($x))                  )
@define_diffrule NaNMath.sin(x)    = :(  NaNMath.cos($x)                            )
@define_diffrule NaNMath.cos(x)    = :( -NaNMath.sin($x)                            )
@define_diffrule NaNMath.tan(x)    = :(  1 + NaNMath.pow(NaNMath.tan($x), 2)        )
@define_diffrule NaNMath.asin(x)   = :(  inv(NaNMath.sqrt(1 - NaNMath.pow($x, 2)))  )
@define_diffrule NaNMath.acos(x)   = :(  -inv(NaNMath.sqrt(1 - NaNMath.pow($x, 2))) )
@define_diffrule NaNMath.acosh(x)  = :(  inv(NaNMath.sqrt(NaNMath.pow($x, 2) - 1))  )
@define_diffrule NaNMath.atanh(x)  = :(  inv(1 - NaNMath.pow($x, 2))                )
@define_diffrule NaNMath.log(x)    = :(  inv($x)                                    )
@define_diffrule NaNMath.log2(x)   = :(  inv($x) / NaNMath.log(2)                   )
@define_diffrule NaNMath.log10(x)  = :(  inv($x) / NaNMath.log(10)                  )
@define_diffrule NaNMath.log1p(x)  = :(  inv($x + 1)                                )
@define_diffrule NaNMath.lgamma(x) = :(  SpecialFunctions.digamma($x)               )

# binary #
#--------#

@define_diffrule NaNMath.pow(x, y) = :( $y * NaNMath.pow($x, ($y - 1)) ), :( NaNMath.pow($x, $y) * NaNMath.log($x) )
@define_diffrule NaNMath.max(x, y) = :(ifelse(($y > $x) | (signbit($y) < signbit($x)), ifelse(isnan($y), one($x), zero($x)), ifelse(isnan($x), zero($x), one($x)))),
                                     :(ifelse(($y > $x) | (signbit($y) < signbit($x)), ifelse(isnan($y), zero($y), one($y)), ifelse(isnan($x), one($y), zero($y))))
@define_diffrule NaNMath.min(x, y) = :(ifelse(($y < $x) | (signbit($y) > signbit($x)), ifelse(isnan($y), one($x), zero($x)), ifelse(isnan($x), zero($x), one($x)))),
                                     :(ifelse(($y < $x) | (signbit($y) > signbit($x)), ifelse(isnan($y), zero($y), one($y)), ifelse(isnan($x), one($x), zero($x))))


text:
################################################################################
#
#  Embeddings of simple relative extensions
#
################################################################################

# If we have a relative extension L/K with defining polynomial f, we
# parametrize the complex_embeddings of L using tuples (p, a), where p is an embedding of K
# and a is a root of p(g).
#
# We store the the following data on the field L itself, which can be accessed via
# _conjugate_data_arb_new(L, prec)):
#   Vector{Tuple{Emb{base_field(L)}, Vector{acb}, Vector{arb}, Vector{acb}}
#
# We use the following ordering, which is very important and must not be changed:
# Let (p, rts, r_rts, c_rts) be such an entry.
#
# if p is real, then rts contains
#   - the real roots (isreal returning true), ordered from -oo to oo
#   - then all complex roots with positive imaginary part, order from 0 to oo
# if p is complex, then rts contains
#   - all complex roots with positive imaginary part, ordered -oo to oo
#
# For each place p of K, we have a tuple
#   (p, roots of p(g), arb[], acb[]) if p is complex, and
#   (p, roots of p(g), real roots of g(a), complex roots of g(a) (one per pair))
#   if p is real.
#
# To compute the conjugates of an element represented by g, we iterate over the
# (p, rts, r_rts, c_rts) and first add [ p(g)(r) for r in r_rts if isreal(p)]
# and then [p(g)(rts) for r in r_rts if !isreal(p)]
mutable struct NumFieldEmbNfRel{S, T} <: NumFieldEmb{T}
  field::T              # Number field.
  base_field_emb::S     # Embedding of base field.
  isreal::Bool          # Whether the embedding is real.
  i::Int                # Index of the root of p(g) to which the embedding
                        # is corresponding to.
  r::acb                # The root of p(g)
  absolute_index::Int   # Absolute index for bookkeeping.
  conjugate::Int        # Absolute index of the conjugate embedding.
end

function embedding_type(::Type{NfRel{T}}) where {T}
  return NumFieldEmbNfRel{embedding_type(parent_type(T)), NfRel{T}}
end

embedding_type(K::NfRel{T}) where {T} = embedding_type(NfRel{T})

_absolute_index(f::NumFieldEmbNfRel) = f.absolute_index

number_field(f::NumFieldEmbNfRel) = f.field

isreal(P::NumFieldEmbNfRel) = P.isreal

################################################################################
#
#  Equality
#
################################################################################

function Base.:(==)(f::NumFieldEmbNfRel, g::NumFieldEmbNfRel)
  return number_field(f) === number_field(g) &&
      _absolute_index(f) == _absolute_index(g)
end

################################################################################
#
#  Conjugate embedding
#
################################################################################

function conj(f::NumFieldEmbNfRel)
  return complex_embeddings(number_field(f))[f.conjugate]
end

################################################################################
#
#  Construction of complex_embeddings
#
################################################################################

function complex_embeddings(L::NfRel{T}; conjugates::Bool = true) where {T}
  S = embedding_type(parent_type(T))
  _res = get_attribute(L, :complex_embeddings)
  if _res !== nothing
    res = _res::Vector{embedding_type(L)}
  else
    res = _complex_embeddings(L)
    set_attribute!(L, :complex_embeddings => res)
  end
  if conjugates
    return res
  else
    r, s = signature(L)
    return res[1:(r + s)]
  end
end

# It is easier to construct all complex_embeddings at one
function _complex_embeddings(L::NfRel{T}) where {T}
  K = base_field(L)
  data = _conjugates_data_new(L, 32)
  r, s = signature(L)
  embs = Vector{embedding_type(L)}(undef, absolute_degree(L))
  S = embedding_type(parent_type(T))
  r_cnt = 1
  c_cnt = 1
  for (P, rts, r_rts, c_rts) in data
    if isreal(P)
      for i in 1:length(r_rts)
        embs[r_cnt] = NumFieldEmbNfRel{S, typeof(L)}(L, P, true, i,
                                                     rts[i], r_cnt, r_cnt)
        r_cnt += 1
      end
      rr = length(r_rts)
      ss = length(c_rts)
      for i in 1:length(c_rts)
        embs[r + c_cnt] =
            NumFieldEmbNfRel{S, typeof(L)}(L, P, false, rr + i, rts[rr + i],
                                           r + c_cnt, r + s + c_cnt)
        embs[r + s + c_cnt] =
            NumFieldEmbNfRel{S, typeof(L)}(L, conj(P), false, rr + ss + i,
                                           conj(rts[rr + i]), r + s + c_cnt,
                                           r + c_cnt)
        c_cnt +=1
      end
    else
      for i in 1:length(rts)
        embs[r + c_cnt] =
            NumFieldEmbNfRel{S, typeof(L)}(L, P, false, i, rts[i],
                                           r + c_cnt, r + s + c_cnt)
        embs[r + s + c_cnt] =
            NumFieldEmbNfRel{S, typeof(L)}(L, conj(P), false, i, conj(rts[i]),
                                           r + s + c_cnt, r + c_cnt)
        c_cnt += 1
      end
    end
  end
  return embs
end

################################################################################
#
#  I/O
#
################################################################################

function Base.show(io::IO, ::MIME"text/plain",  P::NumFieldEmbNfRel)
  print(io, "Embedding of\n")
  println(io, number_field(P))
  print(io, "extending the embedding\n", P.base_field_emb, "\n")
  print(io, "with root ≈ ")
  _print_acb_neatly(io, P.r)
end

function Base.show(io::IO, f::NumFieldEmbNfRel)
  print(io, "Embedding corresponding to (", f.base_field_emb, ") and ≈ ")
  _print_acb_neatly(io, f.r)
end

################################################################################
#
#  Evaluation
#
################################################################################

function (f::NumFieldEmbNfRel)(a::NfRelElem, prec::Int = 32)
  @req number_field(f) === parent(a) "Parent mismatch"
  r, s = signature(parent(a))
  if _absolute_index(f) > r + s
    return conj(conj(f)(a, prec))
  end

  L = parent(a)
  g = defining_polynomial(L)
  K = base_field(L)
  wprec = prec
  d = absolute_degree(L)

  while true
    data = _conjugates_data_new(L, wprec)

    CC = AcbField(wprec, cached = false)
    CCy, y = PolynomialRing(CC, cached = false)

    _r, _s = signature(K)
    real_cnt = 1
    compl_cnt = r + 1

    for i in 1:length(data)
      P, rts, real_rts, compl_rts = data[i]
      if P !== f.base_field_emb
        continue
      end
      a_as_poly = Hecke.data(a)
      da = degree(a_as_poly)
      poly_evaluated = map_coefficients(let wprec = wprec
                                          x -> evaluate(x, P, wprec)
                                        end,
                                        a_as_poly, parent = CCy)
      _conj = evaluate(poly_evaluated, rts[f.i])
      if radiuslttwopower(_conj, -prec)
        return expand!(_conj, -prec)
      end
    end

    wprec = 2 * wprec
  end
end

evaluate(x::NfRelElem, f::NumFieldEmbNfRel, p::Int) = f(x, p)

################################################################################
#
#  Restrict
#
################################################################################

function restrict(f::NumFieldEmbNfRel, K::NumField)
  if K === number_field(f)
    return f
  end
  @req _appears_as_base_field(K, number_field(f)) "Number field is not a base field"
  if K === base_field(number_field(f))
    return f.base_field_emb
  else
    return restrict(f.base_field_emb, K)
  end
end

function restrict(e::NumFieldEmb, f::NumFieldMor{<: NfRel, <: Any, <: Any})
  @req number_field(e) === codomain(f) "Number fields do not match"
  L = domain(f)
  emb = complex_embeddings(L)
  # I need to find the embedding of the base_field of L
  K = base_field(L)
  # This is the natural map K -> L
  KtoL = hom(K, L)
  res_base_field = restrict(e, KtoL * f)
  cn = [ overlaps(ee.r, e(f(gen(L)))) && ee.base_field_emb === res_base_field for ee in emb]
  @assert count(cn) == 1
  i = findfirst(cn)
  return emb[i]
end


text:
function DiffusionDefinition.diffusion_message(::Val{:Lorenz})
    println("* * * * * * *")
    println("Lorenz system")
    println("* * * * * * *")
    println("Description")
    println("------------")
    println("A three-dimensional elliptic diffusion")
    println("dXₜ = θ₁(Yₜ-Xₜ)dt + σdW¹ₜ,")
    println("dYₜ = [Xₜ(θ₂ - Zₜ)-Yₜ]dt + σdW²ₜ,")
    println("dZₜ = (XₜYₜ - θ₃Zₜ)dt + σdW³ₜ.")
    println("The model has four parameters:")
    println("\tθ1, θ2, θ3, σ")
    println("\nConstructors")
    println("------------")
    println("You may initialize the process either by passing the parameters")
    println("in the order above, as in:")
    println("θ₁, θ₂, θ₃, σ = ...")
    println("P = Lorenz(θ₁, θ₂, θ₃, σ)")
    println("or by keyword arguments")
    println("p = (θ1=..., θ2=..., θ3=..., σ=...)")
    println("P = Lorenz(;p...)")
    println()
end

@diffusion_process Lorenz{T} begin
    :dimensions
    process --> 3
    wiener --> 3

    :parameters
    _ --> (3, T)
    σ --> T

    :additional
    constdiff --> true
    sparsediff --> true
end

function DiffusionDefinition.b(t, x, P::Lorenz)
    @SVector [
        P.p1*(x[2]-x[1]),
        P.p2*x[1] - x[2] - x[1]*x[3],
        x[1]*x[2] - P.p3*x[3]
    ]
end

DiffusionDefinition.σ(t, x, P::Lorenz) = SDiagonal(P.σ, P.σ, P.σ)


text:
using Documenter, Soss

makedocs(;
    modules=[Soss],
    format=Documenter.HTML(),
    pages=[
        "Home" => "index.md",
    ],
    repo="https://github.com/cscherrer/Soss.jl/blob/{commit}{path}#L{line}",
    sitename="Soss.jl",
    authors="Chad Scherrer",
    assets=String[],
)

deploydocs(;
    repo="github.com/cscherrer/Soss.jl",
    push_preview=true
)


text:
using Test
using LinearFractional
using LinearAlgebra
using Clp
using JuMP

mytests = ["simpletest.jl", "arrayvars.jl"]

for mytest in mytests
    include(mytest)
end


text:
"""
Copyright Marcus Greiff 2020

Tests of the continuous attitude FSF controller on SU(2)
"""

# Include modules and recompile if running test standalone
if !isdefined(Main, :runAllTests)
    using Test, AerialVehicleControl, LinearAlgebra
    recompile();
end

# Testing fixture
function fixture()

    qref = rand(4,1);
    qref = qref./norm(qref);
    wref = rand(3,1);
    aref = rand(3,1);
    fref = 0.5;
    R = ref_state_qw_t(hcat(qref), hcat(wref), hcat(aref), fref);

    q = rand(4,1);
    q = q./norm(q);
    w = rand(3,1);
    S = dyn_state_qw_t(hcat(q), hcat(w))

    J  = rand(3,3); J  = J + J'; J  = J + I*maximum(abs.(eigvals(J)));
    kX = 1.0;
    kw = 1.0;
    kc = 0.5 * maximal_feasible_kc_SU2(kX, kw, J);

    C  = con_state_qw_fsf_t(J, kX, kc, kw);

    return R, S, C, qref, wref, aref, q, w, kX, kc, kw, J
end

@verbose(1, "Testing continuous FSF on SU(2)...")
@testset "Test the continuous FSF controller on SU(2)" begin
    @testset "Good inputs" begin
        # Fixture
        Rstruct, Sstruct, Cstruct, qref, wref, aref, q, w, kX, kc, kw, J = fixture()
        Rstruct_copy = deepcopy(Rstruct)
        Sstruct_copy = deepcopy(Sstruct)
        Cstruct_copy = deepcopy(Cstruct)

        # Compute what the controls/distances should be based on the current memory
        X   = quat_2_SU2(q   );
        Xr  = quat_2_SU2(qref);
        R   = quat_2_SO3(q );
        Rr  = quat_2_SO3(qref);

        Xe = Xr'*X;

        eX = SU2_vee(Xe - tr(Xe)*Matrix{Float64}(I, 2, 2)) / 2.0
        ew = w -  SU2_vee(Xe'*SU2_hat(wref)*Xe)

        ff = SO3_hat(w) * (J * w) + J*SU2_vee(
            -SU2_hat(ew/2.0)*Xe'*SU2_hat(wref)*Xe
            +Xe'*SU2_hat(aref)*Xe
            +Xe'*SU2_hat(wref)*Xe*SU2_hat(ew/2.0)
        )

        tau = -kX * eX - kw * ew + ff;

        Psi   = 0.5 * tr(Matrix{Float64}(I, 3, 3) - Rr'*R);
        Gamma = 0.5 * tr(Matrix{Float64}(I, 2, 2) - Xr'*X);
        attpart  = kX * Gamma;
        crosspart= kc * ew' * eX;
        ratepart = ew'*J*ew / 2.0;
        Lyap     = attpart + crosspart[1,1] + ratepart[1,1];

        # Test
        status = ccall((:update_attitude_FSF_SU2_continuous, AerialVehicleControl.CONT_LIB_PATH),
            Cint,
            (Ref{ref_state_qw_t}, Ref{dyn_state_qw_t}, Ref{con_state_qw_fsf_t},),
            Rstruct,
            Sstruct,
            Cstruct)

        # Test that the computations passed
        @test isapprox(status, 1);

        # Check that all of the values in the controller memory that should remain constant are unchanged
        allFieldsEqual(Sstruct, Sstruct_copy);
        allFieldsEqual(Rstruct, Rstruct_copy);
        allFieldsEqual(Cstruct, Cstruct_copy, false);

        # Check that the distances have changed
        @test !isapprox(Cstruct.dist_Psi,       Cstruct_copy.dist_Psi );
        @test !isapprox(Cstruct.dist_Gamma,     Cstruct_copy.dist_Gamma );
        @test !isapprox(Cstruct.dist_lyapunov,  Cstruct_copy.dist_lyapunov );

        # Check that the values of the controller structure that should be
        # updated is updated, and that these values corresponds to the above
        # computed torques and distances
        for i = 1:3
            @test isapprox(Cstruct.torques[i], tau[i,1]);
        end
        @test isapprox(Cstruct.dist_Psi, Psi );
        @test isapprox(Cstruct.dist_Gamma, Gamma );
        @test isapprox(Cstruct.dist_lyapunov, Lyap  );

    end
end


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

@doc raw"""
    ObjsComments(;
    )

"""
mutable struct ObjsComments <: SwaggerModel

    function ObjsComments(;)
        o = new()
        o
    end
end # type ObjsComments

const _property_map_ObjsComments = Dict{Symbol,Symbol}()
const _property_types_ObjsComments = Dict{Symbol,String}()
Base.propertynames(::Type{ ObjsComments }) = collect(keys(_property_map_ObjsComments))
Swagger.property_type(::Type{ ObjsComments }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_ObjsComments[name]))}
Swagger.field_name(::Type{ ObjsComments }, property_name::Symbol) =  _property_map_ObjsComments[property_name]

function check_required(o::ObjsComments)
    true
end

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


text:
import ..UncertainValues.AbstractUncertainValue
import ..UncertainValues.AbstractUncertainScalarKDE

"""
Fallback constraints. This is necessary when sampling constraints are not compatible. For example,
the `TruncatedStd` constraint is not implemented for `UncertainScalarKDE`, so we need a fallback.

The default is to fall back to `NoConstraint()``.
"""
function fallback(s::SamplingConstraint, v::AbstractUncertainValue)
    NoConstraint()
end

"""
    fallback(uv::UncertainScalarKDE, constraint::TruncateStd)

Fallback constraint for a `TruncateStd` constraint applied to an
`UncertainScalarKDE` instance.
"""
function fallback(uv::AbstractUncertainScalarKDE, constraint::TruncateStd)
    @warn "TruncateStd constraint is incompatible with UncertainScalarKDE. Falling back to TruncateQuantiles(0.33, 0.67)."
    TruncateQuantiles(0.33, 0.67)
end

export fallback


text:
using OED
using Base.Test
using jInv.Utils
using jInv.Mesh

domain = [0 10 0 2.]; n = [8 9]
Mr     = getRegularMesh(domain,n)
xc     = getCellCenteredGrid(Mr)
w = 22/pi;
c = vec((domain[2:2:end]+domain[1:2:end])./2)

y = rotation2D(w,xc,c=c)

function testFun(w,v=[])
	y,dy = rotation2D(w,xc,c=c,doDerivative=true)
	if isempty(v)
		return y
	else
		return y,dy*v
	end
end
chkDer, = checkDerivative(testFun,0.1)
@test chkDer


text:
function wave_forward_operater(f, x, t, R, N_ϕ)
    N_b = size(f)[1]
    x_end = x[end]
    x2 = 2x_end
    N_t = length(t)        # Number of elements of vector t
    N_x = length(x)        # Number of elements of vector x
    N_x2 = 2N_x
    half_N_x = Int64(N_x/2)
    dt = t[2]-t[1]

    #outer larger grid for solution of wave equation
    g_x = range(-x2, stop=x2 - (2x2)/N_x2, length=N_x2)

    #frequency vectors
    k = range(-N_x, stop=N_x-1, length=N_x2) .* ( pi / x2)
    K = k.^2 .+ (k.^2)'
    KM2 = ifftshift(K)
    KM = sqrt.(KM2)

    #initial pressure field
    #P = zeros(N_b, N_x2, N_x2)
    #P[:, half_N_x:3half_N_x-1, half_N_x:3half_N_x-1] = f
    P = zeros(N_x2, N_x2)
    P[half_N_x:3half_N_x-1, half_N_x:3half_N_x-1] = f

    # k-space
    #W = zeros(N_b, N_t+1, N_x2, N_x2)
    #W[:, 2, :, :] = P
    #W[:, 1, :, :] = P   #t=-1일 때의 W
    W = zeros(N_x2, N_x2, N_t+1)
    W[:, :, 2] = P
    W[:, :, 1] = P   #t=-1일 때의 W

    detector_angle = 0: 2pi/N_ϕ : 2pi-2pi/N_ϕ
    detector_x = R * cos.(detector_angle)
    detector_y = R * sin.(detector_angle)

    #Wf = zeros(N_b, N_t, N_ϕ)
    Wf = zeros(N_t, N_ϕ)
    sin_term = @. -4(sin(dt*KM/2))^2
    #sin_term = reshape(sin_term, (1,size(sin_term)[1], size(sin_term)[2]))

    #for i ∈ 2:N_t
    #    LW = ifft(sin_term.*fft(W[:, i, :, :]))
    #    real_LW  = real(LW)
    #    W[:, i+1, :, :] = 2W[:, i, :, :] - W[:, i-1,: ,:] + real_LW
    #    #W[:, i+1, :, :] = 2*W[:, i, :, :] - W[:, i-1,: ,:] + cx*LW1
    #
    #    Wf[:, i, : ] = interp(g_x, W[:, i+1, :, :], detector_x, detector_y)
    #end
    for i ∈ 2:N_t
        LW = ifft(sin_term.*fft(W[:, :, i]))
        real_LW  = real(LW)
        W[:, :, i+1] = 2W[:, :, i] - W[:, :, i-1] + real_LW
        #W[:, i+1, :, :] = 2*W[:, i, :, :] - W[:, i-1,: ,:] + cx*LW1

        Wf[i, :] = interp(g_x, W[:, :, i+1], detector_x, detector_y)
    end
    return Wf, W
end


text:
include("integrands.jl")

using PyPlot

function plot_1d(integrand, xmin, xmax, xdivs, name, outdir)
    println("plotting 1D ", name, "...")
    xs = linspace(xmin, xmax, xdivs)
    ys = [integrand(x) for x = xs]
    fig = figure(figsize=(8, 6))
    plot(xs, ys)
    title("integrand 1D $(name)")
    savefig("$(outdir)/out_integrand_1D_$(name).png")
    close(fig)
end

function plot_2d(integrand, xmin, xmax, xdivs, name, outdir)
    println("plotting 2D ", name, "...")
    x1 = linspace(xmin, xmax, xdivs)
    x2 = linspace(xmin, xmax, xdivs)
    x1grid = repmat(x1', xdivs, 1)
    x2grid = repmat(x2 , 1, xdivs)
    z = [integrand([x1[i] x2[j]]) for i in 1:xdivs, j in 1:xdivs]
    fig = figure(figsize=(8, 6))
    ax = fig[:add_subplot](1, 1, 1,  projection = "3d")
    ax[:plot_surface](x1grid, x2grid, z, edgecolors="k", cmap=ColorMap("jet"),
                      alpha=0.8, linewidth=0.25)
    title("integrand 2D $(name)")
    tight_layout()
    savefig("$(outdir)/out_integrand_2D_$(name).png")
    close(fig)
end

function plot_1d_2d(integrand, xmin, xmax, xdivs, name)
    plot_1d(integrand, xmin, xmax, xdivs, name, outdir)
    plot_2d(integrand, xmin, xmax, xdivs, name, outdir)
end

outdir = "output"
if ~isdir(outdir)
    mkdir(outdir)
end

plot_1d_2d(integrands.constant, -2, 2, 100, "constant")
plot_1d_2d(integrands.linear, -2, 2, 100, "linear")
plot_1d_2d(integrands.sinus, -8, 8, 100, "sinus")
plot_1d_2d(integrands.sinusc, -8, 8, 100, "sinusc")
plot_1d_2d(integrands.sphere, -2, 2, 100, "sphere")
plot_1d_2d(integrands.oscillatory, -5, 5, 100, "oscillatory")
plot_1d_2d(integrands.productpeak, -1, 1, 100, "productpeak")
plot_1d_2d(integrands.cornerpeak, 0, 1, 100, "cornerpeak")
plot_1d_2d(integrands.gaussian, -4, 4, 100, "gaussian")
plot_1d_2d(integrands.continuous, -4, 4, 100, "continuous")
plot_1d_2d(integrands.discontinuous, -4, 4, 100, "discontinuous")

max_stars_repo_name: florianLepretre/ucbature

max_issues_repo_name: florianLepretre/ucbature

max_forks_repo_name: florianLepretre/ucbature


text:
using Plots; pyplot(fmt = :png)
using SolidStateDetectors
using Unitful

T = Float32
simulation = Simulation{T}(SSD_examples[:InvertedCoax])

plot(simulation.detector, size=(700, 700))

apply_initial_state!(simulation, ElectricPotential) # optional
plot(
    plot(simulation.electric_potential), # initial electric potential (boundary conditions)
    plot(simulation.point_types), # map of different point types: fixed point / inside or outside detector volume / depleted/undepleted
    plot(simulation.ρ), # charge density distribution
    plot(simulation.ϵ), # dielectric distribution
    layout = (1, 4), size = (1400, 700)
)

calculate_electric_potential!( simulation,
                               max_refinements = 3)

calculate_electric_field!(simulation, n_points_in_φ = 72)

charge_drift_model = ADLChargeDriftModel()
set_charge_drift_model!(simulation, charge_drift_model)

calculate_drift_fields!(simulation)

starting_positions = [ CylindricalPoint{T}( 0.020, deg2rad(10), 0.015 ),
                       CylindricalPoint{T}( 0.015, deg2rad(20), 0.045 ),
                       CylindricalPoint{T}( 0.025, deg2rad(30), 0.025 ) ]
energy_depos = T[1460, 609, 1000] * u"keV" # are needed later in the signal generation

event = Event(starting_positions, energy_depos);

time_step = 5u"ns"
drift_charges!(event, simulation, Δt = time_step)

plot(simulation.detector, size = (700, 700))
plot!(event.drift_paths)

for contact in simulation.detector.contacts
    calculate_weighting_potential!(simulation, contact.id, max_refinements = 3, n_points_in_φ = 2, verbose = false)
end

plot(
    plot(simulation.weighting_potentials[1]),
    plot(simulation.weighting_potentials[2]),
    size = (900, 700)
)

simulate!(event, simulation) # drift_charges + signal generation of all channels

p_pc_signal = plot( event.waveforms[1], lw = 1.5, xlims = (0, 2000), xlabel = "Time / ns",
                    legend = false, tickfontsize = 12, ylabel = "Energy / eV", guidefontsize = 14)

max_stars_repo_name: rjtayl/NDP

max_issues_repo_name: rjtayl/NDP

max_forks_repo_name: rjtayl/NDP


text:
function findenaechstesBild(Aufloesung,prozent)

Phantom = echteCTDaten(Aufloesung);
nrows,ncols = size(Phantom);
f_nahBild = zeros(size(Phantom,1),size(Phantom,2));
PhantomVec = reshape(Phantom,(Int(nrows)*Int(ncols),1));

x0,y0,N,JJ,nx,ny,x1,y1,verschx,verschy,a,b,A,theta1,counter = Dateneinlesen(Aufloesung);
A2 = erstelleA(x0,x1,y0,y1,N,JJ,nx,ny,verschx,verschy);
Messwerte =  A2*PhantomVec;

MesswerteMitFehler = erzeugeFehlerbehafteteDaten(Messwerte,prozent);

f_nah = (transpose(A2)*A2)\(transpose(A2)*MesswerteMitFehler)
for i = 1:size(f_nah,1)
    if f_nah[i] < 0
        f_nah[i] = 0;
    elseif f_nah[i] > 1
        f_nah[i] = 1;
    end
end
ObjektNaiv = reshape(f_nah,(nrows,ncols));
    #print(ObjektNaiv)
f_nahBild = convert(Array{Gray{Normed{UInt8,8}},2},ObjektNaiv);

return PhantomVec,f_nah,Messwerte,MesswerteMitFehler,A2,f_nahBild;
end