text:
RpcApi.SimpleOrganism(0x0000000000063235,:(function (o::Creature.Organism)
     local var_33::Int16 = -17711
     function func_24(var_23::Int8=28)
         local var_27::Int64 = 7619797539999258533
         Creature.eatDown(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatRight(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         var_27 = var_27 / var_27
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepLeft(o)
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         return var_23
     end
     local var_21::Int8 = 88
     local var_20::Int16 = -11365
     function func_17(var_15::String="Dy4HZerj",var_16::Int16=3937)
         return var_15
     end
     local var_3::Int16 = 32203
     local var_2::Int8 = 83
     Creature.eatLeft(o,Int(var_2))
     Creature.eatLeft(o,Int(var_2))
     if var_21 > var_2
         Creature.stepDown(o)
     end
     var_2 = func_24(var_21)
     Creature.stepLeft(o)
     var_21 = func_24(var_21)
     Creature.stepLeft(o)
     var_21 = func_24(var_21)
     Creature.stepLeft(o)
     var_20 = if haskey(o.mem,var_3)
             o.mem[var_3]
         else
             var_20
         end
     o.mem[var_20] = var_3
     var_21 = func_24(var_2)
     var_20 = if haskey(o.mem,var_20)
             o.mem[var_20]
         else
             var_20
         end
     if var_3 === var_3
         Creature.stepDown(o)
         Creature.stepLeft(o)
     end
     Creature.eatLeft(o,Int(var_2))
     Creature.eatLeft(o,Int(var_2))
     var_2 = func_24(var_21)
     var_20 = var_3 - var_3
     var_3 = if haskey(o.mem,var_3)
             o.mem[var_3]
         else
             var_3
         end
     Creature.stepLeft(o)
     var_21 = func_24(var_2)
     o.mem[var_3] = var_20
     Creature.eatLeft(o,Int(var_2))
     Creature.stepRight(o)
     Creature.stepDown(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.eatRight(o,Int(var_2))
     Creature.eatUp(o,Int(var_2))
     Creature.eatRight(o,Int(var_2))
     Creature.stepRight(o)
     for i::Int8 = 1:div(var_2,_LOOP_STEPS_DIVIDER)
         Creature.stepLeft(o)
         Creature.stepLeft(o)
     end
     Creature.stepDown(o)
     var_21 = var_2 + var_2
     Creature.stepRight(o)
     return true
 end),[100,300,95,0,1,1,1],1,9586,1,655790,0x01576620,Dict(0=>0,-6815=>-6815,32203=>0,-8455=>32203,-12751=>-6815),[43,996],73)

#------------------------------------------------------------------------------------------------------------------------------

RpcApi.SimpleOrganism(0x000000000006840b,:(function (o::Creature.Organism,)
     local var_33::Int16 = -17711
     function func_24(var_23::Int8=28)
         local var_27::Int64 = 7619797539999258533
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepLeft(o)
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         return var_23
     end
     local var_21::Int8 = 88
     local var_20::Int16 = -11365
     function func_17(var_15::String="Dy4HZerj",var_16::Int16=3937)
         o.mem[var_16] = var_16
         o.mem[var_16] = var_16
         return var_15
     end
     local var_3::Int16 = 32203
     local var_2::Int8 = 83
     Creature.stepRight(o)
     Creature.eatLeft(o,Int(var_2))
     if var_21 > var_2
         Creature.stepDown(o)
         Creature.stepLeft(o)
     end
     var_2 = func_24(var_21)
     Creature.stepLeft(o)
     var_21 = func_24(var_21)
     Creature.stepLeft(o)
     var_21 = func_24(var_21)
     Creature.stepLeft(o)
     var_20 = if haskey(o.mem,var_3)
             o.mem[var_3]
         else
             var_20
         end
     o.mem[var_20] = var_3
     var_21 = func_24(var_2)
     var_2 = func_24(var_21)
     if var_3 === var_3
         local var_26::Int64 = 4052005204377763992
         Creature.stepLeft(o)
     end
     Creature.eatLeft(o,Int(var_2))
     var_21 = func_24(var_2)
     var_2 = func_24(var_21)
     var_20 = var_3 - var_3
     var_3 = if haskey(o.mem,var_3)
             o.mem[var_3]
         else
             var_3
         end
     var_21 = func_24(var_2)
     o.mem[var_3] = var_20
     Creature.eatLeft(o,Int(var_2))
     Creature.stepDown(o)
     Creature.stepDown(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.eatRight(o,Int(var_2))
     Creature.stepRight(o)
     Creature.eatRight(o,Int(var_2))
     Creature.stepRight(o)
     for i::Int8 = 1:div(var_2,_LOOP_STEPS_DIVIDER)
         Creature.stepDown(o)
         Creature.stepRight(o)
         Creature.stepLeft(o)
     end
     Creature.stepDown(o)
     var_21 = var_2 + var_2
     Creature.stepRight(o)
     return true
 end),[100,300,95,0,1,1,1],1,9586,59,2521319,0x015ee860,Dict(0=>0,-6815=>-6815,32203=>0,-8455=>32203,-12751=>-6815),[21,998],82)

#------------------------------------------------------------------------------------------------------------------------------

[RpcApi.SimpleOrganism(0x000000000007c887,:(function (o::Creature.Organism,)
     function func_35(var_33::Bool=false,var_34::Int16=22779)
         local var_45::String = "C5qJrm41"
         return var_33
     end
     function func_24(var_23::Int8=28)
         local var_44::Bool = false
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatRight(o,Int(var_23))
         Creature.stepLeft(o)
         Creature.stepLeft(o)
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.stepLeft(o)
         Creature.eatLeft(o,Int(var_23))
         if var_44 !== var_44
             Creature.stepLeft(o)
         end
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatRight(o,Int(var_23))
         Creature.stepLeft(o)
         Creature.eatUp(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         return var_23
     end
     local var_21::Int8 = 88
     local var_20::Int16 = -11365
     function func_17(var_15::String="Dy4HZerj",var_16::Int16=3937)
         Creature.stepRight(o)
         Creature.stepUp(o)
         return var_15
     end
     local var_3::Int16 = 32203
     local var_2::Int8 = 83
     Creature.eatUp(o,Int(var_21))
     if var_21 < var_21
     end
     Creature.eatLeft(o,Int(var_2))
     Creature.eatLeft(o,Int(var_2))
     if var_21 > var_2
         Creature.stepRight(o)
         Creature.stepUp(o)
         Creature.stepRight(o)
     end
     var_2 = func_24(var_21)
     Creature.stepLeft(o)
     Creature.eatUp(o,Int(var_21))
     var_20 = var_3 * var_20
     var_21 = func_24(var_21)
     Creature.stepLeft(o)
     var_21 = func_24(var_21)
     o.mem[var_20] = var_20
     Creature.stepUp(o)
     var_21 = func_24(var_2)
     var_20 = if haskey(o.mem,var_20)
             o.mem[var_20]
         else
             var_20
         end
     if var_3 != var_20
         Creature.stepLeft(o)
     end
     var_21 = func_24(var_21)
     Creature.eatLeft(o,Int(var_2))
     var_3 = if haskey(o.mem,var_3)
             o.mem[var_3]
         else
             var_3
         end
     Creature.stepLeft(o)
     var_21 = func_24(var_2)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.eatRight(o,Int(var_2))
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.eatLeft(o,Int(var_21))
     Creature.eatDown(o,Int(var_2))
     Creature.stepRight(o)
     Creature.stepRight(o)
     return true
 end),[100,300,95,0,1,1,1],9,5699,1,4236892,0x017f2950,Dict(0=>32203,-11365=>32203,-6815=>-6815,32203=>0,-8455=>32203,-12751=>-6815,31465=>31465),[86,1],86)

#------------------------------------------------------------------------------------------------------------------------------

[RpcApi.SimpleOrganism(0x00000000000874a5,:(function (o::Creature.Organism,)
     function func_47(var_45::Bool=true,var_46::Int16=10622)
         var_46 = var_46 - var_46
         if var_45 === var_45
         end
         o.mem[var_46] = var_46
         return var_45
     end
     function func_35(var_33::Bool=false,var_34::Int16=22779)
         var_33 = var_33 & var_33
         return var_33
     end
     function func_24(var_23::Int8=28)
         local var_52::Int64 = 2425467459860682992
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatRight(o,Int(var_23))
         var_52 = var_52 / var_52
         Creature.eatDown(o,Int(var_23))
         Creature.eatRight(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.stepDown(o)
         if var_23 >= var_23
             Creature.stepLeft(o)
         end
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.stepRight(o)
         Creature.stepLeft(o)
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.stepLeft(o)
         Creature.eatUp(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         return var_23
     end
     local var_21::Int8 = 88
     local var_20::Int16 = -11365
     function func_17(var_15::String="Dy4HZerj",var_16::Int16=3937)
         var_16 = if haskey(o.mem,var_16)
                 o.mem[var_16]
             else
                 var_16
             end
         Creature.stepUp(o)
         return var_15
     end
     local var_3::Int16 = 32203
     local var_2::Int8 = 83
     Creature.eatUp(o,Int(var_21))
     if var_21 < var_21
         local var_50::Int64 = 6585452198095506637
     end
     Creature.eatLeft(o,Int(var_2))
     Creature.eatLeft(o,Int(var_2))
     if var_21 > var_2
         Creature.stepUp(o)
         Creature.stepLeft(o)
         Creature.stepUp(o)
         Creature.stepRight(o)
     end
     var_2 = func_24(var_21)
     Creature.stepLeft(o)
     Creature.eatUp(o,Int(var_21))
     var_20 = var_3 * var_20
     var_21 = func_24(var_21)
     var_21 = func_24(var_21)
     o.mem[var_20] = var_20
     o.mem[var_20] = var_3
     var_21 = func_24(var_2)
     if var_3 != var_20
         Creature.stepLeft(o)
     end
     var_21 = func_24(var_21)
     Creature.eatLeft(o,Int(var_2))
     Creature.eatUp(o,Int(var_21))
     Creature.stepLeft(o)
     var_21 = func_24(var_2)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.eatLeft(o,Int(var_2))
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.eatRight(o,Int(var_2))
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.eatDown(o,Int(var_2))
     o.mem[var_20] = var_3
     Creature.stepRight(o)
     Creature.stepRight(o)
     return true
 end),[100,300,95,0,1,1,1],3,4844,1,3145530,0x01965ed0,Dict(0=>32203,-11365=>32203,-6815=>-6815,32203=>0,-8455=>32203,-12751=>-6815,31465=>32203),[18,934],96)

#------------------------------------------------------------------------------------------------------------------------------

[RpcApi.SimpleOrganism(0x000000000008e556,:(function (o::Creature.Organism,)
     function func_47(var_45::Bool=true,var_46::Int16=10622)
         Creature.stepRight(o)
         if var_45 != var_45
         end
         return var_45
     end
     function func_35(var_33::Bool=false,var_34::Int16=22779)
         var_34 = if haskey(o.mem,var_34)
                 o.mem[var_34]
             else
                 var_34
             end
         return var_33
     end
     function func_24(var_23::Int8=28)
         local var_52::Int64 = 2425467459860682992
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatRight(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatRight(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.stepDown(o)
         if var_23 >= var_23
             Creature.stepLeft(o)
         end
         Creature.eatLeft(o,Int(var_23))
         var_52 = var_52 - var_52
         Creature.eatUp(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.stepRight(o)
         Creature.stepLeft(o)
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.stepLeft(o)
         Creature.eatUp(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         return var_23
     end
     local var_21::Int8 = 88
     local var_20::Int16 = -11365
     function func_17(var_15::String="Dy4HZerj",var_16::Int16=3937)
         var_15 = var_15[if length(var_15) > length(var_15)
                         1
                     else
                         length(var_15)
                     end:if length(var_15) > length(var_15) > 0
                         0
                     else
                         end
                     end]
         return var_15
     end
     local var_3::Int16 = 32203
     local var_2::Int8 = 83
     Creature.eatUp(o,Int(var_21))
     if var_21 < var_21
         Creature.stepDown(o)
     end
     Creature.eatLeft(o,Int(var_2))
     Creature.eatLeft(o,Int(var_2))
     if var_21 > var_2
         Creature.stepUp(o)
         Creature.stepUp(o)
         Creature.stepUp(o)
         Creature.stepRight(o)
     end
     var_2 = func_24(var_21)
     Creature.stepLeft(o)
     Creature.eatUp(o,Int(var_21))
     var_20 = var_3 * var_20
     var_21 = func_24(var_21)
     var_21 = func_24(var_21)
     o.mem[var_20] = var_20
     o.mem[var_20] = var_3
     var_21 = func_24(var_2)
     if var_3 != var_20
         Creature.stepLeft(o)
     end
     var_21 = func_24(var_21)
     Creature.eatLeft(o,Int(var_2))
     Creature.eatUp(o,Int(var_21))
     Creature.stepLeft(o)
     var_21 = func_24(var_2)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.eatLeft(o,Int(var_2))
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.eatDown(o,Int(var_2))
     o.mem[var_20] = var_3
     Creature.stepRight(o)
     Creature.stepRight(o)
     return true
 end),[100,300,95,0,1,1,1],3,4844,1,2081716,0x019f95f0,Dict(0=>32203,-11365=>32203,-6815=>-6815,32203=>0,-8455=>32203,-12751=>-6815,31465=>32203),[295,3],92)

#------------------------------------------------------------------------------------------------------------------------------

[RpcApi.SimpleOrganism(0x000000000009d049,:(function (o::Creature.Organism,)
     local var_46::Bool = true
     function func_35(var_33::Bool=false,var_34::Int16=22779)
         var_34 = var_34 + var_34
         Creature.stepRight(o)
         if var_33 == var_33
         end
         Creature.stepDown(o)
         Creature.stepLeft(o)
         Creature.stepLeft(o)
         Creature.stepRight(o)
         return var_33
     end
     function func_24(var_23::Int8=28)
         local var_49::String = "WlX2dxq4"
         local var_44::Int64 = -8745441503928347880
         Creature.eatUp(o,Int(var_23))
         Creature.eatRight(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         if var_23 < var_23
         end
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         var_44 = var_44 - var_44
         Creature.stepLeft(o)
         Creature.eatDown(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.stepUp(o)
         Creature.stepLeft(o)
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepUp(o)
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepLeft(o)
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         return var_23
     end
     local var_21::Int8 = 88
     local var_20::Int16 = -11365
     function func_17(var_15::String="Dy4HZerj",var_16::Int16=3937)
         return var_15
     end
     local var_3::Int16 = 32203
     local var_2::Int8 = 83
     Creature.eatUp(o,Int(var_21))
     Creature.eatLeft(o,Int(var_2))
     Creature.eatLeft(o,Int(var_2))
     if var_21 > var_2
         local var_47::Bool = false
         Creature.stepRight(o)
         Creature.stepRight(o)
         Creature.stepUp(o)
         Creature.stepDown(o)
     end
     var_2 = func_24(var_21)
     Creature.stepUp(o)
     o.mem[var_20] = var_20
     var_21 = func_24(var_21)
     o.mem[var_20] = var_3
     if var_21 === var_21
         Creature.stepLeft(o)
     end
     o.mem[var_20] = var_20
     Creature.stepLeft(o)
     var_21 = func_24(var_21)
     var_21 = var_21 + var_21
     o.mem[var_20] = var_3
     var_21 = func_24(var_2)
     Creature.stepUp(o)
     Creature.eatRight(o,Int(var_21))
     Creature.stepLeft(o)
     var_21 = func_24(var_21)
     Creature.eatLeft(o,Int(var_2))
     var_21 = func_24(var_2)
     Creature.eatUp(o,Int(var_21))
     var_21 = func_24(var_2)
     o.mem[var_3] = var_20
     Creature.stepRight(o)
     var_3 = if haskey(o.mem,var_3)
             o.mem[var_3]
         else
             var_3
         end
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepLeft(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.eatRight(o,Int(var_21))
     Creature.eatDown(o,Int(var_21))
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     o.mem[var_20] = var_3
     Creature.stepRight(o)
     Creature.stepRight(o)
     var_21 = var_21 / var_2
     Creature.stepLeft(o)
     Creature.stepUp(o)
     Creature.eatLeft(o,Int(var_21))
     if var_20 < var_20
         o.mem[var_40] = var_40
     end
     Creature.stepRight(o)
     Creature.stepRight(o)
     return true
 end),[100,300,95,0,1,1,1],1,5208,1,6209333,0x019790a0,Dict(0=>32203,-11365=>-11365,-6815=>-6815,32203=>-11365,-8455=>32203,-12751=>-6815),[123,1],111)

 #------------------------------------------------------------------------------------------------------------------------------

[RpcApi.SimpleOrganism(0x00000000000aa5cc,:(function (o::Creature.Organism,)
     local var_46::Bool = true
     function func_35(var_33::Bool=false,var_34::Int16=22779)
         local var_51::String = "ptpmddp1"
         local var_52::String = "ftwMEhZ0"
         Creature.stepDown(o)
         Creature.stepDown(o)
         Creature.stepRight(o)
         var_33 = var_33 | var_33
         Creature.stepDown(o)
         var_34 = var_34 / var_34
         return var_33
     end
     function func_24(var_23::Int8=28)
         local var_44::Int64 = -8745441503928347880
         Creature.eatUp(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepUp(o)
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepDown(o)
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepUp(o)
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepUp(o)
         Creature.eatRight(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         var_44 = var_44 + var_44
         Creature.stepDown(o)
         Creature.eatDown(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         var_44 = var_44 / var_44
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepLeft(o)
         Creature.eatUp(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         return var_23
     end
     local var_21::Int8 = 88
     local var_20::Int16 = -11365
     function func_17(var_15::String="Dy4HZerj",var_16::Int16=3937)
         Creature.stepDown(o)
         return var_15
     end
     local var_3::Int16 = 32203
     local var_2::Int8 = 83
     Creature.eatUp(o,Int(var_21))
     Creature.eatLeft(o,Int(var_21))
     Creature.eatLeft(o,Int(var_2))
     Creature.eatLeft(o,Int(var_21))
     var_2 = func_24(var_21)
     Creature.eatRight(o,Int(var_21))
     Creature.stepLeft(o)
     var_21 = func_24(var_21)
     Creature.eatDown(o,Int(var_21))
     Creature.stepLeft(o)
     if var_21 === var_21
         Creature.stepRight(o)
         Creature.stepLeft(o)
     end
     var_21 = func_24(var_21)
     var_21 = func_24(var_21)
     var_21 = var_21 + var_21
     var_21 = func_24(var_2)
     Creature.stepUp(o)
     o.mem[var_3] = var_20
     Creature.eatDown(o,Int(var_21))
     Creature.stepDown(o)
     var_21 = func_24(var_21)
     Creature.eatLeft(o,Int(var_2))
     var_21 = func_24(var_2)
     Creature.stepLeft(o)
     var_21 = func_24(var_2)
     o.mem[var_3] = var_20
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     var_20 = var_20 * var_3
     var_20 = var_20 - var_3
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     var_21 = var_2 + var_21
     Creature.stepUp(o)
     Creature.stepRight(o)
     var_3 = if haskey(o.mem,var_20)
             o.mem[var_20]
         else
             var_3
         end
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepDown(o)
     o.mem[var_20] = var_3
     Creature.stepRight(o)
     Creature.stepDown(o)
     var_46 = func_35(var_46)
     if var_46 !== var_46
     end
     Creature.stepLeft(o)
     Creature.eatLeft(o,Int(var_21))
     Creature.stepRight(o)
     return true
 end),[100,300,95,0,1,1,1],1,5208,1,1424734,0x01a50bf0,Dict(0=>32203,-11365=>32203,-6815=>-6815,32203=>-11365,-8455=>32203,-12751=>-6815,-738=>32203,1=>1),[600,6],113)

#------------------------------------------------------------------------------------------------------------------------------

[RpcApi.SimpleOrganism(0x00000000000aea0a,:(function (o::Creature.Organism,)
     local var_46::Bool = true
     function func_35(var_33::Bool=false,var_34::Int16=22779)
         local var_51::String = "ptpmddp1"
         local var_52::String = "ftwMEhZ0"
         Creature.stepDown(o)
         Creature.stepRight(o)
         Creature.stepDown(o)
         Creature.stepDown(o)
         Creature.stepDown(o)
         Creature.stepDown(o)
         Creature.stepRight(o)
         Creature.stepRight(o)
         Creature.stepDown(o)
         Creature.stepDown(o)
         return var_33
     end
     function func_24(var_23::Int8=28)
         local var_44::Int64 = -8745441503928347880
         Creature.eatUp(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepUp(o)
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatRight(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepUp(o)
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepUp(o)
         Creature.eatRight(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         var_44 = var_44 + var_44
         Creature.eatDown(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         var_44 = var_44 / var_44
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepLeft(o)
         Creature.eatRight(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         return var_23
     end
     local var_21::Int8 = 88
     local var_20::Int16 = -11365
     function func_17(var_15::String="Dy4HZerj",var_16::Int16=3937)
         local var_54::Bool = false
         return var_15
     end
     local var_3::Int16 = 32203
     local var_2::Int8 = 83
     Creature.eatUp(o,Int(var_21))
     Creature.eatLeft(o,Int(var_2))
     Creature.eatLeft(o,Int(var_21))
     var_2 = func_24(var_21)
     Creature.eatRight(o,Int(var_21))
     Creature.stepLeft(o)
     var_21 = func_24(var_21)
     Creature.eatDown(o,Int(var_21))
     Creature.stepLeft(o)
     if var_21 === var_21
         Creature.stepRight(o)
         Creature.stepLeft(o)
     end
     var_21 = func_24(var_21)
     var_21 = func_24(var_21)
     var_21 = var_21 + var_21
     var_21 = func_24(var_2)
     Creature.stepUp(o)
     o.mem[var_3] = var_20
     Creature.stepLeft(o)
     Creature.stepDown(o)
     var_21 = func_24(var_21)
     Creature.eatLeft(o,Int(var_2))
     var_21 = func_24(var_2)
     Creature.stepLeft(o)
     var_21 = func_24(var_2)
     o.mem[var_3] = var_20
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     var_20 = var_20 * var_3
     var_20 = var_20 - var_3
     Creature.stepRight(o)
     Creature.stepRight(o)
     Creature.stepRight(o)
     var_46 = func_35(var_46)
     Creature.stepDown(o)
     var_21 = var_2 + var_21
     Creature.stepUp(o)
     Creature.stepRight(o)
     var_3 = if haskey(o.mem,var_20)
             o.mem[var_20]
         else
             var_3
         end
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepDown(o)
     o.mem[var_20] = var_3
     Creature.stepRight(o)
     for i::Int8 = 1:div(var_21,_LOOP_STEPS_DIVIDER)
     end
     var_46 = func_35(var_46)
     var_46 = func_35(var_46)
     Creature.stepLeft(o)
     Creature.eatLeft(o,Int(var_21))
     Creature.stepRight(o)
     return true
 end),[100,300,95,0,1,1,1],1,5208,1,1974284,0x01a8cd10,Dict(0=>32203,-11365=>32203,-6815=>-6815,32203=>-11365,-8455=>32203,-12751=>-6815,-738=>32203,1=>1),[1916,9],118)

 #------------------------------------------------------------------------------------------------------------------------------

[RpcApi.SimpleOrganism(0x00000000000b7473,:(function (o::Creature.Organism,)
     local var_46::Bool = true
     function func_35(var_33::Bool=false,var_34::Int16=22779)
         local var_56::Int16 = 458
         local var_53::Int16 = 17107
         local var_51::String = "ptpmddp1"
         local var_52::String = "ftwMEhZ0"
         Creature.stepDown(o)
         Creature.stepRight(o)
         Creature.stepDown(o)
         Creature.stepDown(o)
         Creature.stepDown(o)
         if var_33 < var_33
         end
         Creature.stepDown(o)
         Creature.stepRight(o)
         Creature.stepRight(o)
         Creature.stepDown(o)
         Creature.stepDown(o)
         return var_33
     end
     function func_24(var_23::Int8=28)
         local var_57::Int64 = 8532844564146531811
         local var_44::Int64 = -8745441503928347880
         Creature.eatDown(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepUp(o)
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatRight(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.stepUp(o)
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepUp(o)
         Creature.stepLeft(o)
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         var_44 = var_44 + var_44
         Creature.eatUp(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.stepLeft(o)
         Creature.eatRight(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         Creature.eatDown(o,Int(var_23))
         Creature.eatLeft(o,Int(var_23))
         Creature.eatUp(o,Int(var_23))
         return var_23
     end
     local var_21::Int8 = 88
     local var_20::Int16 = -11365
     function func_17(var_15::String="Dy4HZerj",var_16::Int16=3937)
         Creature.stepLeft(o)
         var_16 = if haskey(o.mem,var_16)
                 o.mem[var_16]
             else
                 var_16
             end
         Creature.stepDown(o)
         return var_15
     end
     local var_3::Int16 = 32203
     local var_2::Int8 = 83
     Creature.eatUp(o,Int(var_21))
     Creature.eatLeft(o,Int(var_2))
     var_2 = func_24(var_21)
     Creature.eatRight(o,Int(var_21))
     Creature.stepLeft(o)
     var_21 = func_24(var_21)
     Creature.eatDown(o,Int(var_21))
     Creature.stepLeft(o)
     if var_21 === var_21
         Creature.stepLeft(o)
     end
     var_21 = func_24(var_21)
     var_21 = func_24(var_21)
     o.mem[var_20] = var_3
     var_21 = var_21 + var_21
     var_21 = func_24(var_2)
     Creature.stepUp(o)
     Creature.stepLeft(o)
     Creature.stepLeft(o)
     Creature.stepDown(o)
     var_21 = func_24(var_21)
     Creature.eatLeft(o,Int(var_2))
     var_21 = func_24(var_2)
     Creature.stepLeft(o)
     var_21 = func_24(var_2)
     o.mem[var_3] = var_20
     Creature.stepRight(o)
     var_46 = func_35(var_46,var_20)
     Creature.stepUp(o)
     Creature.stepRight(o)
     var_46 = var_46 | var_46
     var_20 = var_20 - var_3
     Creature.stepRight(o)
     Creature.stepRight(o)
     var_21 = var_21 / var_21
     var_46 = func_35(var_46)
     var_21 = var_2 + var_21
     Creature.stepRight(o)
     var_3 = if haskey(o.mem,var_20)
             o.mem[var_20]
         else
             var_3
         end
     Creature.stepRight(o)
     Creature.stepUp(o)
     Creature.stepUp(o)
     Creature.stepRight(o)
     Creature.stepDown(o)
     o.mem[var_20] = var_3
     Creature.stepRight(o)
     Creature.stepDown(o)
     var_46 = func_35(var_46)
     var_46 = func_35(var_46)
     Creature.eatLeft(o,Int(var_21))
     Creature.stepRight(o)
     return true
 end),[100,300,95,0,1,1,1],1,5208,1,1203218,0x01b04f50,Dict(0=>32203,21968=>32203,-11365=>32203,-6815=>-6815,32203=>-11365,-8455=>32203,-12751=>-6815,-738=>32203,1=>1),[22,917],118)

 #------------------------------------------------------------------------------------------------------------------------------

 [RpcApi.SimpleOrganism(0x00000000000cd2ba,:(function (o::Creature.Organism,)
        function func_61(var_59::Bool=false,var_60::Int16=32538)
            if var_60 == var_60
            end
            Creature.stepLeft(o)
            return var_59
        end
        local var_46::Bool = true
        function func_35(var_33::Bool=false,var_34::Int16=22779)
            local var_56::Int16 = 458
            local var_53::Int16 = 17107
            local var_51::String = "ptpmddp1"
            local var_52::String = "ftwMEhZ0"
            Creature.stepDown(o)
            Creature.stepDown(o)
            if var_51 >= var_51
                Creature.stepRight(o)
            end
            Creature.stepDown(o)
            Creature.stepDown(o)
            var_53 = var_56 - var_34
            Creature.stepRight(o)
            o.mem[var_56] = var_34
            Creature.stepDown(o)
            return var_33
        end
        function func_24(var_23::Int8=28)
            local var_44::Int64 = -8745441503928347880
            Creature.eatLeft(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            Creature.eatDown(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.stepUp(o)
            Creature.eatLeft(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            Creature.stepUp(o)
            Creature.eatLeft(o,Int(var_23))
            if var_23 <= var_23
            end
            Creature.eatUp(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.stepUp(o)
            Creature.stepLeft(o)
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatDown(o,Int(var_23))
            Creature.eatDown(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.stepLeft(o)
            Creature.eatLeft(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            return var_23
        end
        local var_21::Int8 = 88
        local var_20::Int16 = -11365
        local var_3::Int16 = 32203
        local var_2::Int8 = 83
        Creature.eatLeft(o,Int(var_2))
        var_20 = var_3 * var_3
        var_2 = func_24(var_21)
        Creature.eatRight(o,Int(var_21))
        Creature.stepLeft(o)
        Creature.stepUp(o)
        Creature.stepLeft(o)
        if var_21 === var_21
            Creature.stepLeft(o)
        end
        o.mem[var_3] = var_3
        var_21 = func_24(var_21)
        o.mem[var_20] = var_3
        o.mem[var_20] = var_20
        var_21 = func_24(var_2)
        Creature.stepUp(o)
        Creature.stepLeft(o)
        Creature.stepLeft(o)
        Creature.stepDown(o)
        var_21 = func_24(var_21)
        var_3 = var_20 + var_3
        Creature.eatLeft(o,Int(var_2))
        var_21 = func_24(var_2)
        var_20 = var_20 + var_20
        var_21 = func_24(var_2)
        o.mem[var_3] = var_20
        o.mem[var_3] = var_20
        var_21 = func_24(var_2)
        Creature.eatRight(o,Int(var_21))
        var_21 = var_21 + var_21
        Creature.stepRight(o)
        var_46 = func_35(var_46,var_20)
        Creature.stepRight(o)
        var_46 = var_46 | var_46
        var_20 = var_20 - var_3
        Creature.stepRight(o)
        Creature.stepRight(o)
        var_21 = var_21 + var_21
        var_21 = var_21 / var_21
        var_46 = func_35(var_46)
        var_21 = var_2 + var_21
        Creature.stepRight(o)
        Creature.eatRight(o,Int(var_21))
        var_3 = if haskey(o.mem,var_3)
                o.mem[var_3]
            else
                var_3
            end
        Creature.stepRight(o)
        Creature.stepRight(o)
        var_21 = var_21 / var_21
        Creature.stepRight(o)
        Creature.stepDown(o)
        Creature.stepRight(o)
        Creature.stepDown(o)
        var_46 = func_35(var_46)
        var_46 = func_35(var_46)
        Creature.eatLeft(o,Int(var_21))
        Creature.stepRight(o)
        return true
    end),[100,300,95,0,1,1,1],1,5208,1,2624889,0x01be7960,Dict(21968=>32203,-22730=>-22730,23748=>-16910,11823=>-11365,0=>32203,-11365=>-11365,-22321=>22779,458=>22779,-738=>32203,23188=>-22730,-6815=>-6815,32203=>32203,-8455=>-8455,-12751=>-6815,1=>1),[19,555],129)

#------------------------------------------------------------------------------------------------------------------------------

[RpcApi.SimpleOrganism(0x00000000000d984b,:(function (o::Creature.Organism,)
        local var_70::Int8 = -75
        local var_65::Bool = true
        function func_61(var_59::Bool=false,var_60::Int16=32538)
            Creature.stepLeft(o)
            return var_59
        end
        local var_46::Bool = true
        function func_35(var_33::Bool=false,var_34::Int16=22779)
            local var_72::Int16 = -20135
            local var_52::String = "ftwMEhZ0"
            local var_67::Int16 = 32063
            local var_68::Int8 = 92
            Creature.eatDown(o,Int(var_68))
            var_33 = var_33 & var_33
            Creature.stepRight(o)
            Creature.eatRight(o,Int(var_68))
            o.mem[var_67] = var_67
            if var_68 > var_68
            end
            Creature.eatRight(o,Int(var_68))
            var_52 = var_52[1:if length(var_52) > length(var_52)
                            0
                        else
                            length(var_52) - length(var_52)
                        end]
            Creature.eatRight(o,Int(var_68))
            return var_33
        end
        function func_24(var_23::Int8=28)
            local var_69::Int8 = -102
            local var_64::Int16 = -29512
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatRight(o,Int(var_23))
            for i::Int8 = 1:div(var_69,_LOOP_STEPS_DIVIDER)
                Creature.stepRight(o)
            end
            Creature.eatLeft(o,Int(var_23))
            Creature.stepLeft(o)
            Creature.eatUp(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.stepLeft(o)
            Creature.eatLeft(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            var_23 = var_23 * var_69
            Creature.stepDown(o)
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.stepLeft(o)
            Creature.stepUp(o)
            Creature.stepUp(o)
            Creature.eatRight(o,Int(var_23))
            for i::Int8 = 1:div(var_69,_LOOP_STEPS_DIVIDER)
            end
            Creature.eatRight(o,Int(var_23))
            Creature.stepUp(o)
            Creature.eatLeft(o,Int(var_23))
            var_69 = var_69 + var_23
            Creature.eatRight(o,Int(var_23))
            Creature.eatUp(o,Int(var_69))
            Creature.stepUp(o)
            Creature.eatUp(o,Int(var_23))
            Creature.stepRight(o)
            o.mem[var_64] = var_64
            Creature.eatUp(o,Int(var_23))
            for i::Int8 = 1:div(var_23,_LOOP_STEPS_DIVIDER)
                local var_73::Int64 = -1174901014922562206
                Creature.stepDown(o)
            end
            Creature.eatLeft(o,Int(var_23))
            var_64 = if haskey(o.mem,var_64)
                    o.mem[var_64]
                else
                    var_64
                end
            o.mem[var_64] = var_64
            for i::Int8 = 1:div(var_23,_LOOP_STEPS_DIVIDER)
                local var_71::String = "J0uBz06k"
            end
            Creature.eatLeft(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            var_69 = var_23 / var_69
            Creature.eatUp(o,Int(var_23))
            Creature.eatDown(o,Int(var_23))
            Creature.eatLeft(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            Creature.eatUp(o,Int(var_23))
            var_64 = var_64 + var_64
            Creature.stepLeft(o)
            o.mem[var_64] = var_64
            var_64 = if haskey(o.mem,var_64)
                    o.mem[var_64]
                else
                    var_64
                end
            var_23 = var_23 * var_69
            return var_23
        end
        local var_21::Int8 = 88
        local var_20::Int16 = -11365
        local var_3::Int16 = 32203
        local var_2::Int8 = 83
        var_46 = func_35(var_46,var_20)
        o.mem[var_20] = var_3
        Creature.eatDown(o,Int(var_21))
        var_21 = func_24(var_21)
        var_46 = var_46 & var_46
        Creature.stepDown(o)
        var_21 = func_24(var_21)
        var_21 = func_24(var_21)
        var_46 = var_46 * var_46
        var_21 = func_24(var_2)
        var_20 = var_3 - var_20
        var_2 = func_24(var_2)
        Creature.stepLeft(o)
        Creature.eatDown(o,Int(var_21))
        var_21 = func_24(var_21)
        if var_2 < var_21
            local var_75::String = "k8rd2EVQ"
            Creature.stepRight(o)
        end
        var_21 = func_24(var_21)
        var_20 = var_20 / var_20
        var_20 = var_3 / var_3
        Creature.eatLeft(o,Int(var_2))
        Creature.stepUp(o)
        var_21 = func_24(var_2)
        Creature.stepDown(o)
        o.mem[var_3] = var_20
        var_21 = func_24(var_2)
        Creature.stepDown(o)
        Creature.stepRight(o)
        for i::Int8 = 1:div(var_21,_LOOP_STEPS_DIVIDER)
            local var_74::Int8 = 53
        end
        var_3 = var_20 + var_20
        var_46 = func_35(var_46,var_20)
        Creature.stepRight(o)
        Creature.stepUp(o)
        Creature.stepRight(o)
        var_2 = var_2 / var_2
        var_46 = var_46 * var_46
        var_65 = func_35(var_46,var_20)
        var_46 = func_35(var_46)
        Creature.eatLeft(o,Int(var_21))
        var_2 = var_70 / var_21
        Creature.stepDown(o)
        Creature.stepRight(o)
        Creature.stepRight(o)
        var_21 = var_21 / var_21
        Creature.stepUp(o)
        var_46 = func_35(var_46)
        Creature.stepRight(o)
        Creature.eatRight(o,Int(var_21))
        Creature.stepDown(o)
        var_46 = func_35(var_46)
        Creature.eatLeft(o,Int(var_21))
        Creature.stepRight(o)
        return true
    end),[100,300,95,0,1,1,1],95,7941,50,132311,0x01f6ca40,Dict(1=>1,-22730=>-22730,-29512=>-29512,0=>32203,-7100=>-7100,22779=>22779,-22321=>22779,-24878=>-24878,458=>22779,-738=>32203,13024=>13024,32203=>1,-8455=>-8455,32063=>32063,21968=>32203,6512=>6512,-21968=>-21968,-11365=>32203,-14080=>-14080,23188=>-22730,-6815=>-6815,-12751=>-12751,11823=>-11365),[1752,817],135)

max_stars_repo_name: tmptrash/jevo

max_issues_repo_name: tmptrash/jevo

max_forks_repo_name: tmptrash/jevo


text:
struct AudioLocation
  azimuth::Int # ∈ -179:180
  elevation::Int # ∈ -90:90
end

ext: jl


text:
module Cr3bpWrapper

using JavaCall

const AbsoluteDate = @jimport org.orekit.time.AbsoluteDate
const AbstractForceModel = @jimport org.orekit.forces.AbstractForceModel
const AbstractMultipleShooting = @jimport org.orekit.utils.AbstractMultipleShooting
const AdditionalEquations = @jimport org.orekit.propagation.integration.AdditionalEquations
const CR3BPForceModel = @jimport org.orekit.propagation.numerical.cr3bp.CR3BPForceModel
const CR3BPMultipleShooter = @jimport org.orekit.propagation.numerical.cr3bp.CR3BPMultipleShooter
const CR3BPSystem = @jimport org.orekit.bodies.CR3BPSystem
const Class = @jimport java.lang.Class
const DerivativeStructure = @jimport org.hipparchus.analysis.differentiation.DerivativeStructure
const Field = @jimport org.hipparchus.Field
const FieldDerivativeStructure = @jimport org.hipparchus.analysis.differentiation.FieldDerivativeStructure
const FieldSpacecraftState = @jimport org.orekit.propagation.FieldSpacecraftState
const FieldTimeDerivativesEquations = @jimport org.orekit.propagation.numerical.FieldTimeDerivativesEquations
const FieldVector3D = @jimport org.hipparchus.geometry.euclidean.threed.FieldVector3D
const ForceModel = @jimport org.orekit.forces.ForceModel
const JString = @jimport java.lang.String
const List = @jimport java.util.List
const Object = @jimport java.lang.Object
const ParameterDriver = @jimport org.orekit.utils.ParameterDriver
const RealFieldElement = @jimport org.hipparchus.RealFieldElement
const RealMatrix = @jimport org.hipparchus.linear.RealMatrix
const STMEquations = @jimport org.orekit.propagation.numerical.cr3bp.STMEquations
const SpacecraftState = @jimport org.orekit.propagation.SpacecraftState
const Stream = @jimport java.util.stream.Stream
const TimeDerivativesEquations = @jimport org.orekit.propagation.numerical.TimeDerivativesEquations
const Vector3D = @jimport org.hipparchus.geometry.euclidean.threed.Vector3D

export CR3BPConstants
export CR3BPForceModel
export CR3BPMultipleShooter
export STMEquations
export acceleration
export add_constraint
export add_contribution
export compute
export compute_derivatives
export depends_on_position_only
export equals
export get_class
export get_events_detectors
export get_field_events_detectors
export get_name
export get_parameter_driver
export get_parameters
export get_parameters_drivers
export get_potential
export get_state_transition_matrix
export hash_code
export init
export is_supported
export notify
export notify_all
export set_closed_orbit_constraint
export set_epoch_freedom
export set_initial_phi
export set_patch_point_component_freedom
export to_string
export wait

include("c_r3_bp_constants.jl")
include("c_r3_bp_force_model.jl")
include("c_r3_bp_multiple_shooter.jl")
include("stm_equations.jl")

end


text:
include_string(Main.Load2, """
module AltModule
using ReTest
@testset "AltModule" begin end
end
""")

max_issues_repo_name: rfourquet/InlineTest

max_forks_repo_name: rfourquet/InlineTest


text:
InputFolder = './Images/Tissue/';
OutputFolder = './Results/Images/Tissue/';

@iA = '*.tif';

@fxg_mWaterTiles [iA] > [M];
params.GRad = 4;
params.ExtendedMinThr = 5;
/endf

/show iA > M;
/keep M > tif;

max_stars_repo_name: SebastienTs/LOBSTER

max_issues_repo_name: SebastienTs/LOBSTER

max_forks_repo_name: SebastienTs/LOBSTER


text:
include("CSD.jl")

"""
Epochs of Channel Sample.
"""
function epochsample(x,fs,epochs,chs;whiten=nothing,fun=nothing)
    nepoch = size(epochs,1)
    epochis = round.(Int,epochs.*SecondPerUnit.*fs)
    minepochlength = minimum(diff(epochis,dims=2))
    ys=Array{Float64}(undef,length(chs),minepochlength,nepoch)
    for i in 1:nepoch
        y = x[chs,range(max(1,epochis[i,1]),length=minepochlength)]
        isnothing(whiten) || (y=whiten*y)
        isnothing(fun) || (y=fun(y))
        ys[:,:,i] = y
    end
    return nepoch==1 ? dropdims(ys,dims=3) : ys
end

"fill data in the shape of mask, where masked channels are replaced with local average"
function fill2mask(ys, mask;chmap=1:size(ys,1), replacemask = true,randreplace=false)
    nrow, ncol = size(mask)
    yss = zeros(nrow, ncol, size(ys)[2:end]...)
    for i in eachindex(chmap)
        r,c = chshapenp(chmap[i],nrow,ncol)
        @views yss[r,c,:,:] = ys[i,:,:]
    end
    if replacemask # Local unmasked channels averaging replacement for masked channels
        rmask = copy(mask)
        for (r, c) in Tuple.(findall(mask))
            rd = r - 1;ru = r + 1
            while 1 <= rd && rmask[rd, c]
                rd -= 1
            end
            while ru <= nrow && rmask[ru, c]
                ru += 1
            end
            if rd < 1
                if ru > nrow
                    @error "No Unmasked Channels in Data to Replace Masked Channel[$r, $c]."
                else
                    yss[r, c, :, :] = yss[ru, c, :, :]
                end
            else
                if ru > nrow
                    yss[r, c, :, :] = yss[rd, c, :, :]
                else
                    @views yss[r, c, :, :] = (yss[rd, c, :, :] .+ yss[ru, c, :, :]) / 2
                end
            end
            if randreplace
                @views yss[r,c,:,:] = yss[r,c,:,:] .+ randn(size(yss)[3:end]...)*3*std(yss[r,c,:,:])
            end
            rmask[r, c] = false
        end
    end
    return yss
end

"Spatial and Temporal filter of data stream"
function stfilter(rm;spatialtype=:none,ir=1,or=2,temporaltype=:none,ti=1:size(rm,2),hbordervalue=nothing)
    nd = ndims(rm)
    if nd==3
        nr,nc,n = size(rm)
        y = Array{Float64}(undef,nr,nc,n)
        for i in 1:n
            y[:,:,i] = stfilter(rm[:,:,i],spatialtype=spatialtype,ir=ir,or=or,temporaltype=temporaltype,ti=ti,hbordervalue=hbordervalue)
        end
        return y
    else
        if spatialtype==:all
            rm .-= mean(rm,dims=1)
        elseif spatialtype==:annulus
            foreach(i->rm[i,:] .-= dropdims(mean(rm[filter(j-> 1<=j<=size(rm,1),union(i-or:i-ir,i+ir:i+or)),:],dims=1),dims=1),1:size(rm,1))
        end
        if temporaltype == :all
            rm .-= mean(rm,dims=2)
        elseif temporaltype == :sub
            rm .-= mean(rm[:,ti],dims=2)
        elseif temporaltype == :rc
            rm = rm ./ mean(rm[:,ti],dims=2) .- 1
        elseif temporaltype == :z
            rm = (rm .- mean(rm[:,ti],dims=2)) ./ std(rm[:,ti],dims=2)
        end
        if !isnothing(hbordervalue)
            rm[[1,end],:].=hbordervalue
        end
        return rm
    end
end

"Remove line noise and its harmonics by notch filter"
function rmline(y,fs;freq=60,nh=3,bw=3)
    fy = similar(y,Float64)
    copy!(fy,y)
    rmline!(fy,fs;freq,nh,bw)
end
function rmline!(y,fs;freq=60,nh=3,bw=3)
    for i=1:nh
        f = iirnotch(freq*i,bw;fs=fs)
        for j=1:size(y,1)
            @views y[j,:]=filtfilt(f,y[j,:])
        end
    end
    return y
end

"High pass and low pass filtering"
function hlpass(y,fs;high=0,low=Inf)
    fy = similar(y,Float64)
    copy!(fy,y)
    hlpass!(fy,fs;high,low)
end
function hlpass!(y,fs;high=0,low=Inf)
    if high>0
        f = digitalfilter(Highpass(high;fs=fs), Butterworth(4))
        for j=1:size(y,1)
            @views y[j,:]=filtfilt(f,y[j,:])
        end
    end
    if low<Inf
        f = digitalfilter(Lowpass(low;fs=fs), Butterworth(4))
        for j=1:size(y,1)
            @views y[j,:]=filtfilt(f,y[j,:])
        end
    end
    return y
end

"time to sample index"
time2sampleindex(t,fs;secondperunit=1,minsampleindex::Integer=0,maxsampleindex::Integer=typemax(Int64)) = clamp(round(Int,t*secondperunit*fs),minsampleindex,maxsampleindex)
"sample index to time"
sampleindex2time(s,fs;secondperunit=1,mintime::Real=0,maxtime::Real=typemax(Float64)) = clamp(s/fs/secondperunit,mintime,maxtime)

"Convert epochs in time to sample index"
function epoch2sampleindex(epochs,fs;minsampleindex::Integer=1,maxsampleindex::Integer=typemax(Int64))
    nepoch = size(epochs,1)
    epochis = time2sampleindex.(epochs,fs;secondperunit=SecondPerUnit,minsampleindex,maxsampleindex)
    minepochlength = minimum(diff(epochis,dims=2))
    si = [range(epochis[i,1],length=minepochlength) for i in 1:nepoch]
    return nepoch==1 ? si[1] : si
end

"""
Get digital rising and falling edges in a analog stream
return di: edges index
       dv: edges active/inactive state
"""
function parsedigitalinanalog(x,ht,lt=ht,n=length(x);activehigh=true)
    di=Int[];dv=Bool[]
    if activehigh
        cs=x[1]>ht
        for i in 2:n
            t = x[i]
            if t > ht && !cs
                cs=true;push!(di,i);push!(dv,cs)
            elseif t < lt && cs
                cs=false;push!(di,i);push!(dv,cs)
            end
        end
    else
        cs=x[1]<lt
        for i in 2:n
            t = x[i]
            if t < lt && !cs
                cs=true;push!(di,i);push!(dv,cs)
            elseif t > ht && cs
                cs=false;push!(di,i);push!(dv,cs)
            end
        end
    end
    return di,dv
end

"Multi-Taper power spectrum estimation"
function powerspectrum(x,fs;freqrange=[0,100],nw=4)
    nd=ndims(x)
    if nd==3
        n=size(x,1);ne=size(x,3)
        @views ps = mt_pgram(x[1,:,1],fs=fs,nw=nw)
        fi = first(freqrange).<=freq(ps).<=last(freqrange)
        freqs = freq(ps)[fi]
        p = Array{Float64}(undef,n,length(freqs),ne)
        for i in 1:n,j in 1:ne
            @views p[i,:,j] = power(mt_pgram(x[i,:,j],fs=fs,nw=nw))[fi]
        end
    elseif nd == 2
        @views ps = mt_pgram(x[1,:],fs=fs,nw=nw)
        fi = first(freqrange).<=freq(ps).<=last(freqrange)
        freqs = freq(ps)[fi];n = size(x,1)
        p = Array{Float64}(undef,n,length(freqs))
        p[1,:]=power(ps)[fi]
        for i in 2:n
            @views p[i,:]=power(mt_pgram(x[i,:],fs=fs,nw=nw))[fi]
        end
    else
        ps = mt_pgram(x,fs=fs,nw=nw)
        fi = first(freqrange).<=freq(ps).<=last(freqrange)
        freqs = freq(ps)[fi];p = power(ps)[fi]
    end
    return p,freqs
end

"Multi-Taper channel pair-wise coherence spectrum estimation"
function coherencespectrum(x,fs;freqrange=[0,100],nw=4,ismean=false)
    nd=ndims(x)
    if nd==3
        n=size(x,1);ne=size(x,3)
        @views c1,freqs = coherencespectrum(x[:,:,1],fs;freqrange,nw,ismean)
        c = Array{Float64}(undef,n,n,length(freqs),ne)
        c[:,:,:,1]=c1
        for i in 2:ne
            @views ci,freqs = coherencespectrum(x[:,:,i],fs;freqrange,nw,ismean)
            c[:,:,:,i]=ci
        end
    elseif nd == 2
        cs = mt_coherence(x;freq_range=freqrange,fs,nw)
        c = coherence(cs);freqs=freq(cs)
        if ismean
            c = mean(c,dims=3)
            freqs=mean(freqs)
        end
    else
        @error "No coherence for one signal."
    end
    length(freqs)==1 && (c=dropdims(c,dims=3))
    return c,freqs
end

"Weighted average of banded masked matrix"
function bandmean(x;r=5,s=1)
    mask = BandedMatrix(Ones(size(x)...),(r,r))

    g = OffsetArray(gaussianf.(-r:r,σ=s),-r:r)
    g[0] = 0
    g ./= sum(g)
    foreach(i->mask[band(i)].=g[i],-r:r)

    bm = dropdims(sum(x.*Matrix(mask),dims=1),dims=1)
end

@doc raw"""
Discrete Fourier Transform at frequencies

```math
DFT[k] = \sum_{n=0}^{N-1} x[n] e^{\frac{-2\Pi ink}{N}}, k = 0:N-1, N = length(x), fₛ sampling x, fₖ = fₛ/N sampling DTFT
```

1. signal
2. simpling frequency of signal
3. at which frequencies DFT are directly evaluated
"""
function dft(x,fs,f...)
    N = length(x)
    fₖ = fs/N
    ks = round.(Int,f./fₖ)
    Fs = [zero(ComplexF64) for _ in f]
    Ω = [exp(-im*2π*n/N) for n in 0:(N-1)]
    @inbounds for n in 0:(N-1)
        @inbounds for i in eachindex(f)
            Fs[i] += x[n+1] * Ω[((n*ks[i])%N)+1]
        end
    end
    return Fs
end


text:
abstract type GammaGibbsProvider <: MyXMLElement end

mutable struct NormalGammaPrecisionOperatorXMLElement <: OperatorXMLElement
    el::XMLOrNothing
    ggp::GammaGibbsProvider
    prior_provider::MyXMLElement
    indices::Vector{Int}
    weight::Float64
end

function NormalGammaPrecisionOperatorXMLElement(ggp::GammaGibbsProvider,
                    prior::T) where T <: MyXMLElement
    return NormalGammaPrecisionOperatorXMLElement(nothing, ggp, prior, Int[], 1.0)
end

function NormalGammaPrecisionOperatorXMLElement(
            ext_xml::ModelExtensionXMLElement,
            td_xml::TraitLikelihoodXMLElement)
    return NormalGammaPrecisionOperatorXMLElement(nothing,
                NormalExtentsionGibbsProvider(ext_xml, td_xml),
                ext_xml, Int[], 1.0)
end

# function NormalGammaPrecisionOperatorXMLElement(msl::MatrixShrinkageLikelihoods,
#                                                 row::Int)
#     gpp = MultipilcativeGammaGibbsProvider(msl, row)
#     return NormalGammaPrecisionOperatorXMLElement(nothing, gpp, gpp, 1.0)
# end

function get_parameter(ngpo::NormalGammaPrecisionOperatorXMLElement)
    return get_parameter(ngpo.ggp)
end

mutable struct NormalExtentsionGibbsProvider <: GammaGibbsProvider
    el::XMLOrNothing
    ext::ModelExtensionXMLElement
    tdl::TraitLikelihoodXMLElement

    function NormalExtentsionGibbsProvider(ext::ModelExtensionXMLElement,
                                           tdl::TraitLikelihoodXMLElement)
        return new(nothing, ext, tdl)
    end
end

function get_parameter(negp::NormalExtentsionGibbsProvider)
    return get_precision(negp.ext)
end

function make_xml(negp::NormalExtentsionGibbsProvider)
    el = new_element(bn.NORMAL_EXTENSION)

    set_attribute(el, bn.TREE_TRAIT_NAME, negp.tdl.attrs[bn.TRAIT_NAME])
    add_ref_el(el, negp.ext)
    add_ref_el(el, negp.tdl)

    negp.el = el
    return el
end

mutable struct MultipilcativeGammaGibbsProvider <: GammaGibbsProvider
    el::XMLOrNothing
    param::MyXMLElement
    likelihood::MyXMLElement

    function MultipilcativeGammaGibbsProvider(param::MyXMLElement,
                                              likelihood::MyXMLElement)
        return new(nothing, param, likelihood)
    end
end

# function multiplicative_gamma_gibbs_proivders(msl::MatrixShrinkageLikelihoods)
#     k = get_fac_dim(msl)
#     mggs = Vector{MultipilcativeGammaGibbsProvider}(undef, k)
#     for i = 1:k
#         mggs[i] = MultipilcativeGammaGibbsProvider(msl, i)
#     end
#     return mggs
# end

function get_parameter(mggp::MultipilcativeGammaGibbsProvider)
    return mggp.param
end

function make_xml(mgg::MultipilcativeGammaGibbsProvider)
    make_xml(mgg.param)
    make_xml(mgg.likelihood)

    el = new_element(bn.MULTIPLICATIVE_GAMMA_GIBBS)
    add_ref_el(el, mgg.param.el)
    add_ref_el(el, mgg.likelihood.el)

    mgg.el = el
end

# function get_precision_prior(mgg::MultipilcativeGammaGibbsProvider)
#     make_xml(mgg.msl)
#     return mgg.msl.global_prior_els[mgg.row]
# end

function make_xml(ngpxml::NormalGammaPrecisionOperatorXMLElement)
    make_xml(ngpxml.ggp)
    make_xml(ngpxml.prior_provider)

    el = new_element(bn.NGP_OPERATOR)
    set_attribute(el, bn.WEIGHT, ngpxml.weight)
    if length(ngpxml.indices) > 0
        set_attribute(el, bn.INDICES, join(ngpxml.indices, ' '))
    end
    prior_el = new_child(el, bn.PRIOR)
    add_ref_el(prior_el, get_precision_prior(ngpxml.prior_provider))

    add_child(el, ngpxml.ggp.el)

    ngpxml.el = el
    return el
end

function set_indices!(ngp::NormalGammaPrecisionOperatorXMLElement,
                     inds::Vector{Int})
    ngp.indices = inds
end


text:
using Test
using DFTK: load_psp, list_psp

@testset "Check reading all HGH pseudos" begin
    for record in list_psp()
        psp = load_psp(record.identifier)
        @test psp.identifier == record.identifier
        @test psp.Zion == record.n_elec_valence
    end
end


text:
function _differentiate(A::Union{Tensor{T, 0}, ConstantTensor{T, 0}}, y::VariableTensor{0}, difffn) where T
    return A.value == y || A.value == [y] ? ConstantTensor(1) : ZeroTensor()
end

function _differentiate(A::VariableTensor{0}, y::VariableTensor{0}, difffn)
    return A == y ? ConstantTensor(1) : ZeroTensor()
end

function _differentiate(Z::ZeroTensor{0}, y::VariableTensor{0}, difffn)
    return Z
end

function _differentiate(add::AddOperation{0}, y::VariableTensor{0}, difffn)
    return +([difffn(child) for child in add.children]...)
end

function _differentiate(op::OuterProductOperation{0}, y::VariableTensor{0}, difffn)
    A, B = op.children
    return A*difffn(B) + difffn(A)*B
end

function _differentiate(div::DivisionOperation{0}, y::VariableTensor, difffn)
    A, B = div.children
    return (difffn(A)*B - A*difffn(B))/(B^2)
end

function _differentiate(si::SineOperation{0}, y::VariableTensor{0}, difffn)
    return Base.cos(si.children[1]) * difffn(si.children[1])
end

function _differentiate(co::CosineOperation{0}, y::VariableTensor{0}, difffn)
    return - Base.sin(co.children[1]) * difffn(co.children[1])
end

function _differentiate(ta::TangentOperation{0}, y::VariableTensor{0}, difffn)
    return difffn(ta.children[1]) / (cos(ta.children[1])^2)
end

function _differentiate(asi::ArcsineOperation{0}, y::VariableTensor{0}, difffn)
    return difffn(asi.children[1]) / sqrt(Tensor(1) - asi.children[1]^2)
end

function _differentiate(aco::ArccosineOperation{0}, y::VariableTensor{0}, difffn)
    return - difffn(aco.children[1]) / sqrt(Tensor(1) - aco.children[1]^2)
end

function _differentiate(ata::ArctangentOperation{0}, y::VariableTensor{0}, difffn)
    return difffn(ata.children[1]) / (Tensor(1) + ata.children[1]^2)
end

function _differentiate(root::RootNode, y::VariableTensor{0}, diffn)
    return RootNode(diffn(root.children[1]))
end

"""
    differentiate(A::AbstractTensor{0}, x::VariableTensor{0})

Differentiates A w.r.t x.
"""
function differentiate(A::AbstractTensor{0}, x::VariableTensor{0})
    return traversal(A, x -> x, _differentiate, nothing, x, nothing, true)
end

function differentiate(y::Number, x::VariableTensor{0})
    return 0
end

function _divergence(A::Tensor{T, 1}, vars::Tuple{Vararg{VariableTensor{0}}}, divergencefn) where T
    return +([Tensor(differentiate(A.value[i], vars[i])) for i in 1:length(vars)]...)
end

function  _divergence(A::ConstantTensor{T, 1}, vars::Tuple{Vararg{VariableTensor{0}}}, divergencefn) where T
    return +([differentiate(A.value, var) for var in vars]...)
end

function _divergence(A::TerminalTensor{1}, vars::Tuple{Vararg{VariableTensor{0}}}, divergencefn)
    return ZeroTensor(A.shape...)
end

function _divergence(op::OuterProductOperation{1}, vars::Tuple{Vararg{VariableTensor{0}}}, divergencefn)
    x, A = op.children
    if length(A.shape) == 0
        x, A = A, x
    end
    if A isa AddOperation
        return divergencefn(+([x*child for child in A.children]...))
    elseif A isa Tensor{T,1} where T
        return divergencefn(Tensor([y*x for y in A.value], A.shape...))
    elseif A isa ConstantTensor{T, 1} where T
        return divergencefn(ConstantTensor(A.value * x, A.shape...))
    elseif A isa ZeroTensor{T, 1} where T
        return ZeroTensor()
    elseif A isa OuterProductOperation
        y, B = A.children
        if length(B.shape) == 0
            y, B = B, y
        end
        return divergencefn((x * y) * B)
    else
        throw(DomainError(op, "Cannot be differentiated further"))
    end
end

function _divergence(A::AddOperation{1}, vars::Tuple{Vararg{VariableTensor{0}}}, divergencefn)
    return +([divergencefn(child) for child in A.children]...)
end

function _divergence(A::RootNode, vars::Tuple{Vararg{VariableTensor{0}}}, divergencefn)
    return RootNode(divergencefn(A.children[1]))
end

"""
    divergence(A::AbstractTensor{1}, vars::Vararg{VariableTensor{0}})

Computes the divergence of a vector-shaped tensor A w.r.t vars.
"""
function divergence(A::AbstractTensor{1}, vars::Vararg{VariableTensor{0}})
    if dim(A.shape[1]) != length(vars)
        throw(DimensionMismatch(string(vars, " does not have enough variables to gradient ", A)))
    end
    return traversal(A, x -> x, _divergence, nothing, vars, nothing, true)
end

max_stars_repo_name: Sohva/oolong

max_issues_repo_name: Sohva/oolong

max_forks_repo_name: oolongtensor/oolong


text:
"
    tline_z(Rdc,Rs,L0,epsilon,C0)

tline_fd generates a frequency-domain representation of the characteristic
impedance of a transmission line using a popular model of R(w), L(w), G(w), and
C(w). Rs is a skin-effect resistance quantity (units of Ohms/sqrt(Hz)) and
epsilon is the imaginary part of the loss tangent (dielectric loss).
"
function tline_z(Rdc,Rs,L0,epsilon,C0)
    zr(rdc,rs) = f -> rdc+(1+im*sign(f))*rs*sqrt(abs(f))
    zl(l0) = f -> 2*pi*im*f*l0
    zg(ep,c0) = f-> 2*pi*f*sign(f)*ep*c0
    zc(c0) = f -> 1/(2*pi*im*f*c0)
    frac(f) = (zr(Rdc,Rs)(f)+zl(L0)(f)) / (zg(epsilon,C0)(f) + zc(C0)(f))
    return function(f)
        f==0?sqrt(Rdc):abs(frac(f))^(.5)*cis(angle(frac(f))/2)
    end
end


text:
# Sets

# Note: When adding a new set, also add it to Utilities.Model.

"""
    AbstractSet

Abstract supertype for set objects used to encode constraints. A set object
should not contain any [`VariableIndex`](@ref) or [`ConstraintIndex`](@ref)
as the set is passed unmodifed during [`copy_to`](@ref).
"""
abstract type AbstractSet end

"""
    dimension(s::AbstractSet)

Return the [`output_dimension`](@ref) that an [`AbstractFunction`](@ref) should have to be used with the set `s`.

### Examples

```julia-repl
julia> dimension(Reals(4))
4

julia> dimension(LessThan(3.0))
1

julia> dimension(PositiveSemidefiniteConeTriangle(2))
3
```

"""
function dimension end

"""
    dual_set(s::AbstractSet)

Return the dual set of `s`, that is the dual cone of the set. This follows the
definition of duality discussed in [Duality](@ref).

See [Dual cone](https://en.wikipedia.org/wiki/Dual_cone_and_polar_cone) for more
information.

If the dual cone is not defined it returns an error.

### Examples

```jldocstest
julia> dual_set(Reals(4))
Zeros(4)

julia> dual_set(SecondOrderCone(5))
SecondOrderCone(5)

julia> dual_set(ExponentialCone())
DualExponentialCone()
```
"""
function dual_set end

dual_set(s::AbstractSet) = error("Dual of $s is not implemented.")

"""
    dual_set_type(S::Type{<:AbstractSet})

Return the type of dual set of sets of type `S`, as returned by
[`dual_set`](@ref). If the dual cone is not defined it returns an error.

### Examples

```jldocstest
julia> dual_set_type(Reals)
Zeros

julia> dual_set_type(SecondOrderCone)
SecondOrderCone

julia> dual_set_type(ExponentialCone)
DualExponentialCone
```
"""
function dual_set_type end

function dual_set_type(S::Type{<:AbstractSet})
    return error("Dual type of $S is not implemented.")
end

"""
    AbstractScalarSet

Abstract supertype for subsets of ``\\mathbb{R}``.
"""
abstract type AbstractScalarSet <: AbstractSet end

Base.broadcastable(set::AbstractScalarSet) = Ref(set)

dimension(s::AbstractScalarSet) = 1

"""
    AbstractVectorSet

Abstract supertype for subsets of ``\\mathbb{R}^n`` for some ``n``.
"""
abstract type AbstractVectorSet <: AbstractSet end

dimension(s::AbstractVectorSet) = s.dimension # .dimension field is conventional, overwrite this method if not applicable

"""
    Reals(dimension)

The set ``\\mathbb{R}^{dimension}`` (containing all points) of dimension `dimension`.
"""
struct Reals <: AbstractVectorSet
    dimension::Int
end

dual_set(s::Reals) = Zeros(dimension(s))
dual_set_type(::Type{Reals}) = Zeros

"""
    Zeros(dimension)

The set ``\\{ 0 \\}^{dimension}`` (containing only the origin) of dimension `dimension`.
"""
struct Zeros <: AbstractVectorSet
    dimension::Int
end

dual_set(s::Zeros) = Reals(dimension(s))
dual_set_type(::Type{Zeros}) = Reals

"""
    Nonnegatives(dimension)

The nonnegative orthant ``\\{ x \\in \\mathbb{R}^{dimension} : x \\ge 0 \\}`` of dimension `dimension`.
"""
struct Nonnegatives <: AbstractVectorSet
    dimension::Int
end

dual_set(s::Nonnegatives) = copy(s)
dual_set_type(::Type{Nonnegatives}) = Nonnegatives

"""
    Nonpositives(dimension)

The nonpositive orthant ``\\{ x \\in \\mathbb{R}^{dimension} : x \\le 0 \\}`` of dimension `dimension`.
"""
struct Nonpositives <: AbstractVectorSet
    dimension::Int
end

dual_set(s::Nonpositives) = copy(s)
dual_set_type(::Type{Nonpositives}) = Nonpositives

"""
    GreaterThan{T <: Real}(lower::T)

The set ``[lower,\\infty) \\subseteq \\mathbb{R}``.
"""
struct GreaterThan{T<:Real} <: AbstractScalarSet
    lower::T
end

# guimarqu
struct ExtendedGreaterThan{T<:Real} <: AbstractScalarSet
    lower::T
end

"""
    LessThan{T <: Real}(upper::T)

The set ``(-\\infty,upper] \\subseteq \\mathbb{R}``.
"""
struct LessThan{T<:Real} <: AbstractScalarSet
    upper::T
end

# guimarqu
struct ExtendedLessThan{T<:Real} <: AbstractScalarSet
    lower::T
end

"""
    EqualTo{T <: Number}(value::T)

The set containing the single point ``x \\in \\mathbb{R}`` where ``x`` is given by `value`.
"""
struct EqualTo{T<:Number} <: AbstractScalarSet
    value::T
end

function Base.:(==)(
    set1::S,
    set2::S,
) where {S<:Union{GreaterThan,LessThan,EqualTo}}
    return constant(set1) == constant(set2)
end

"""
    Interval{T <: Real}(lower::T,upper::T)

The interval ``[lower, upper] \\subseteq \\mathbb{R}``.
If `lower` or `upper` is `-Inf` or `Inf`, respectively, the set is interpreted as a one-sided interval.

    Interval(s::GreaterThan{<:AbstractFloat})

Construct a (right-unbounded) `Interval` equivalent to the given [`GreaterThan`](@ref) set.

    Interval(s::LessThan{<:AbstractFloat})

Construct a (left-unbounded) `Interval` equivalent to the given [`LessThan`](@ref) set.

    Interval(s::EqualTo{<:Real})

Construct a (degenerate) `Interval` equivalent to the given [`EqualTo`](@ref) set.
"""
struct Interval{T<:Real} <: AbstractScalarSet
    lower::T
    upper::T
end
Interval(s::GreaterThan{<:AbstractFloat}) = Interval(s.lower, typemax(s.lower))
Interval(s::LessThan{<:AbstractFloat}) = Interval(typemin(s.upper), s.upper)
Interval(s::EqualTo{<:Real}) = Interval(s.value, s.value)
Interval(s::Interval) = s

"""
    constant(s::Union{EqualTo, GreaterThan, LessThan})

Returns the constant of the set.
"""
constant(s::EqualTo) = s.value
constant(s::GreaterThan) = s.lower
constant(s::LessThan) = s.upper

"""
    NormInfinityCone(dimension)

The ``\\ell_\\infty``-norm cone ``\\{ (t,x) \\in \\mathbb{R}^{dimension} : t \\ge \\lVert x \\rVert_\\infty = \\max_i \\lvert x_i \\rvert \\}`` of dimension `dimension`.
"""
struct NormInfinityCone <: AbstractVectorSet
    dimension::Int
end

dual_set(s::NormInfinityCone) = NormOneCone(dimension(s))
dual_set_type(::Type{NormInfinityCone}) = NormOneCone

"""
    NormOneCone(dimension)

The ``\\ell_1``-norm cone ``\\{ (t,x) \\in \\mathbb{R}^{dimension} : t \\ge \\lVert x \\rVert_1 = \\sum_i \\lvert x_i \\rvert \\}`` of dimension `dimension`.
"""
struct NormOneCone <: AbstractVectorSet
    dimension::Int
end

dual_set(s::NormOneCone) = NormInfinityCone(dimension(s))
dual_set_type(::Type{NormOneCone}) = NormInfinityCone

"""
    SecondOrderCone(dimension)

The second-order cone (or Lorenz cone or ``\\ell_2``-norm cone) ``\\{ (t,x) \\in \\mathbb{R}^{dimension} : t \\ge \\lVert x \\rVert_2 \\}`` of dimension `dimension`.
"""
struct SecondOrderCone <: AbstractVectorSet
    dimension::Int
end

dual_set(s::SecondOrderCone) = copy(s)
dual_set_type(::Type{SecondOrderCone}) = SecondOrderCone

"""
    RotatedSecondOrderCone(dimension)

The rotated second-order cone ``\\{ (t,u,x) \\in \\mathbb{R}^{dimension} : 2tu \\ge \\lVert x \\rVert_2^2, t,u \\ge 0 \\}`` of dimension `dimension`.
"""
struct RotatedSecondOrderCone <: AbstractVectorSet
    dimension::Int
end

dual_set(s::RotatedSecondOrderCone) = copy(s)
dual_set_type(::Type{RotatedSecondOrderCone}) = RotatedSecondOrderCone

"""
    GeometricMeanCone(dimension)

The geometric mean cone ``\\{ (t,x) \\in \\mathbb{R}^{n+1} : x \\ge 0, t \\le \\sqrt[n]{x_1 x_2 \\cdots x_n} \\}`` of dimension `dimension```{}=n+1``.

### Duality note

The dual of the geometric mean cone is
``\\{ (u, v) \\in \\mathbb{R}^{n+1} : u \\le 0, v \\ge 0, -u \\le n \\sqrt[n]{\\prod_i v_i} \\}`` of dimension `dimension```{}=n+1``.
"""
struct GeometricMeanCone <: AbstractVectorSet
    dimension::Int
end

"""
    ExponentialCone()

The 3-dimensional exponential cone ``\\{ (x,y,z) \\in \\mathbb{R}^3 : y \\exp (x/y) \\le z, y > 0 \\}``.
"""
struct ExponentialCone <: AbstractVectorSet end

dual_set(s::ExponentialCone) = DualExponentialCone()
dual_set_type(::Type{ExponentialCone}) = DualExponentialCone

"""
    DualExponentialCone()

The 3-dimensional dual exponential cone ``\\{ (u,v,w) \\in \\mathbb{R}^3 : -u \\exp (v/u) \\le \\exp(1) w, u < 0 \\}``.
"""
struct DualExponentialCone <: AbstractVectorSet end

dual_set(s::DualExponentialCone) = ExponentialCone()
dual_set_type(::Type{DualExponentialCone}) = ExponentialCone

"""
    PowerCone{T <: Real}(exponent::T)

The 3-dimensional power cone ``\\{ (x,y,z) \\in \\mathbb{R}^3 : x^{exponent} y^{1-exponent} \\ge |z|, x \\ge 0, y \\ge 0 \\}`` with parameter `exponent`.
"""
struct PowerCone{T<:Real} <: AbstractVectorSet
    exponent::T
end

dual_set(s::PowerCone{T}) where {T<:Real} = DualPowerCone{T}(s.exponent)
dual_set_type(::Type{PowerCone{T}}) where {T<:Real} = DualPowerCone{T}

"""
    DualPowerCone{T <: Real}(exponent::T)

The 3-dimensional power cone ``\\{ (u,v,w) \\in \\mathbb{R}^3 : (\\frac{u}{exponent})^{exponent} (\\frac{v}{1-exponent})^{1-exponent} \\ge |w|, u \\ge 0, v \\ge 0 \\}`` with parameter `exponent`.
"""
struct DualPowerCone{T<:Real} <: AbstractVectorSet
    exponent::T
end

dual_set(s::DualPowerCone{T}) where {T<:Real} = PowerCone{T}(s.exponent)
dual_set_type(::Type{DualPowerCone{T}}) where {T<:Real} = PowerCone{T}

function dimension(
    s::Union{ExponentialCone,DualExponentialCone,PowerCone,DualPowerCone},
)
    return 3
end

function Base.:(==)(set1::S, set2::S) where {S<:Union{PowerCone,DualPowerCone}}
    return set1.exponent == set2.exponent
end

"""
    RelativeEntropyCone(dimension)

The relative entropy cone ``\\{ (u, v, w) \\in \\mathbb{R}^{1+2n} : u \\ge \\sum_{i=1}^n w_i \\log (\\frac{w_i}{v_i}), v_i \\ge 0, w_i \\ge 0 \\}`` of dimension `dimension```{}=2n+1``.

### Duality note

The dual of the relative entropy cone is
``\\{ (u, v, w) \\in \\mathbb{R}^{1+2n} : \\forall i, w_i \\ge u (\\log (\\frac{u}{v_i}) - 1), v_i \\ge 0, u > 0 \\}`` of dimension `dimension```{}=2n+1``.
"""
struct RelativeEntropyCone <: AbstractVectorSet
    dimension::Int
end

"""
    NormSpectralCone(row_dim, column_dim)

The epigraph of the matrix spectral norm (maximum singular value function) ``\\{ (t, X) \\in \\mathbb{R}^{1 + row_dim \\times column_dim} : t \\ge \\sigma_1(X) \\}`` where ``\\sigma_i`` is the ``i``th singular value of the matrix ``X`` of row dimension `row_dim` and column dimension `column_dim`.
The matrix X is vectorized by stacking the columns, matching the behavior of Julia's `vec` function.
"""
struct NormSpectralCone <: AbstractVectorSet
    row_dim::Int
    column_dim::Int
end

dual_set(s::NormSpectralCone) = NormNuclearCone(s.row_dim, s.column_dim)
dual_set_type(::Type{NormSpectralCone}) = NormNuclearCone

"""
    NormNuclearCone(row_dim, column_dim)

The epigraph of the matrix nuclear norm (sum of singular values function) ``\\{ (t, X) \\in \\mathbb{R}^{1 + row_dim \\times column_dim} : t \\ge \\sum_i \\sigma_i(X) \\}`` where ``\\sigma_i`` is the ``i``th singular value of the matrix ``X`` of row dimension `row_dim` and column dimension `column_dim`.
The matrix X is vectorized by stacking the columns, matching the behavior of Julia's `vec` function.
"""
struct NormNuclearCone <: AbstractVectorSet
    row_dim::Int
    column_dim::Int
end

dual_set(s::NormNuclearCone) = NormSpectralCone(s.row_dim, s.column_dim)
dual_set_type(::Type{NormNuclearCone}) = NormSpectralCone

function dimension(s::Union{NormSpectralCone,NormNuclearCone})
    return 1 + s.row_dim * s.column_dim
end

"""
    abstract type AbstractSymmetricMatrixSetTriangle <: AbstractVectorSet end

Abstract supertype for subsets of the (vectorized) cone of symmetric matrices,
with [`side_dimension`](@ref) rows and columns. The entries of the upper-right
triangular part of the matrix are given column by column (or equivalently, the
entries of the lower-left triangular part are given row by row). A vectorized
cone of [`dimension`](@ref) ``n`` corresponds to a square matrix with side
dimension ``\\sqrt{1/4 + 2 n} - 1/2``. (Because a ``d \\times d`` matrix has
``d(d + 1) / 2`` elements in the upper or lower triangle.)

### Examples

The matrix
```math
\\begin{bmatrix}
  1 & 2 & 4\\\\
  2 & 3 & 5\\\\
  4 & 5 & 6
\\end{bmatrix}
```
has [`side_dimension`](@ref) 3 and vectorization ``(1, 2, 3, 4, 5, 6)``.

### Note

Two packed storage formats exist for symmetric matrices, the respective orders
of the entries are:
- upper triangular column by column (or lower triangular row by row);
- lower triangular column by column (or upper triangular row by row).

The advantage of the first format is the mapping between the `(i, j)` matrix
indices and the `k` index of the vectorized form. It is simpler and does not
depend on the side dimension of the matrix.
Indeed,
- the entry of matrix indices `(i, j)` has vectorized index
  `k = div((j - 1) * j, 2) + i` if ``i \\leq j`` and
  `k = div((i - 1) * i, 2) + j` if ``j \\leq i``;
- and the entry with vectorized index `k` has matrix indices
  `i = div(1 + isqrt(8k - 7), 2)` and `j = k - div((i - 1) * i, 2)` or
  `j = div(1 + isqrt(8k - 7), 2)` and `i = k - div((j - 1) * j, 2)`.

### Duality note

The scalar product for the symmetric matrix in its vectorized form is the sum of
the pairwise product of the diagonal entries plus twice the sum of the pairwise
product of the upper diagonal entries; see [p. 634, 1].
This has important consequence for duality.

Consider for example the following problem
([`PositiveSemidefiniteConeTriangle`](@ref) is a subtype of
[`AbstractSymmetricMatrixSetTriangle`](@ref))
```math
\\begin{align*}
    & \\max_{x \\in \\mathbb{R}} & x
    \\\\
    & \\;\\;\\text{s.t.} &
    (1, -x, 1) & \\in \\text{PositiveSemidefiniteConeTriangle}(2).
\\end{align*}
```
The dual is the following problem
```math
\\begin{align*}
    & \\min_{x \\in \\mathbb{R}^3} & y_1 + y_3
    \\\\
    & \\;\\;\\text{s.t.} & 2y_2 & = 1\\\\
    & & y & \\in \\text{PositiveSemidefiniteConeTriangle}(2).
\\end{align*}
```
Why do we use ``2y_2`` in the dual constraint instead of ``y_2`` ?
The reason is that ``2y_2`` is the scalar product between ``y`` and the symmetric
matrix whose vectorized form is ``(0, 1, 0)``. Indeed, with our modified scalar
products we have
```math
\\langle
(0, 1, 0),
(y_1, y_2, y_3)
\\rangle
=
\\mathrm{trace}
\\begin{pmatrix}
  0 & 1\\\\
  1 & 0
\\end{pmatrix}
\\begin{pmatrix}
  y_1 & y_2\\\\
  y_2 & y_3
\\end{pmatrix}
= 2y_2.
```

### References

[1] Boyd, S. and Vandenberghe, L.. *Convex optimization*. Cambridge university press, 2004.
"""
abstract type AbstractSymmetricMatrixSetTriangle <: AbstractVectorSet end

function dimension(set::AbstractSymmetricMatrixSetTriangle)
    d = side_dimension(set)
    return div(d * (d + 1), 2)
end

"""
    abstract type AbstractSymmetricMatrixSetSquare <: AbstractVectorSet end

Abstract supertype for subsets of the (vectorized) cone of symmetric matrices,
with [`side_dimension`](@ref) rows and columns. The entries of the matrix are
given column by column (or equivalently, row by row). The matrix is both
constrained to be symmetric and to have its [`triangular_form`](@ref) belong
to the corresponding set. That is, if the functions in entries ``(i, j)`` and
``(j, i)`` are different, then a constraint will be added to make sure that the
entries are equal.

### Examples

[`PositiveSemidefiniteConeSquare`](@ref) is a subtype of
[`AbstractSymmetricMatrixSetSquare`](@ref) and constraining the matrix
```math
\\begin{bmatrix}
  1 & -y\\\\
  -z & 0\\\\
\\end{bmatrix}
```
to be symmetric positive semidefinite can be achieved by constraining the vector
``(1, -z, -y, 0)`` (or ``(1, -y, -z, 0)``) to belong to the
`PositiveSemidefiniteConeSquare(2)`. It both constrains ``y = z`` and
``(1, -y, 0)`` (or ``(1, -z, 0)``) to be in
`PositiveSemidefiniteConeTriangle(2)`, since
`triangular_form(PositiveSemidefiniteConeSquare)` is
`PositiveSemidefiniteConeTriangle`.
"""
abstract type AbstractSymmetricMatrixSetSquare <: AbstractVectorSet end

dimension(set::AbstractSymmetricMatrixSetSquare) = side_dimension(set)^2

"""
    side_dimension(set::Union{AbstractSymmetricMatrixSetTriangle,
                              AbstractSymmetricMatrixSetSquare})

Side dimension of the matrices in `set`. By convention, it should be stored in
the `side_dimension` field but if it is not the case for a subtype of
[`AbstractSymmetricMatrixSetTriangle`](@ref), the method should be implemented
for this subtype.
"""
function side_dimension(
    set::Union{
        AbstractSymmetricMatrixSetTriangle,
        AbstractSymmetricMatrixSetSquare,
    },
)
    return set.side_dimension
end

"""
    triangular_form(S::Type{<:AbstractSymmetricMatrixSetSquare})
    triangular_form(set::AbstractSymmetricMatrixSetSquare)

Return the [`AbstractSymmetricMatrixSetTriangle`](@ref) corresponding to the
vectorization of the upper triangular part of matrices in the
[`AbstractSymmetricMatrixSetSquare`](@ref) set.
"""
function triangular_form end
function triangular_form(set::AbstractSymmetricMatrixSetSquare)
    return triangular_form(typeof(set))(side_dimension(set))
end

"""
    PositiveSemidefiniteConeTriangle(side_dimension) <: AbstractSymmetricMatrixSetTriangle

The (vectorized) cone of symmetric positive semidefinite matrices, with
`side_dimension` rows and columns. See
[`AbstractSymmetricMatrixSetTriangle`](@ref) for more details on the vectorized
form.
"""
struct PositiveSemidefiniteConeTriangle <: AbstractSymmetricMatrixSetTriangle
    side_dimension::Int
end

dual_set(s::PositiveSemidefiniteConeTriangle) = copy(s)
function dual_set_type(::Type{PositiveSemidefiniteConeTriangle})
    return PositiveSemidefiniteConeTriangle
end

"""
    PositiveSemidefiniteConeSquare(side_dimension) <: AbstractSymmetricMatrixSetSquare

The cone of symmetric positive semidefinite matrices, with side length `side_dimension`.
 See [`AbstractSymmetricMatrixSetSquare`](@ref) for more details on the vectorized
form.

The entries of the matrix are given column by column (or equivalently, row by row).
The matrix is both constrained to be symmetric and to be positive semidefinite.
That is, if the functions in entries ``(i, j)`` and ``(j, i)`` are different, then a constraint will be added to make sure that the entries are equal.

### Examples

Constraining the matrix
```math
\\begin{bmatrix}
  1 & -y\\\\
  -z & 0\\\\
\\end{bmatrix}
```
to be symmetric positive semidefinite can be achieved by constraining the vector ``(1, -z, -y, 0)`` (or ``(1, -y, -z, 0)``)
to belong to the `PositiveSemidefiniteConeSquare(2)`.
It both constrains ``y = z`` and ``(1, -y, 0)`` (or ``(1, -z, 0)``) to be in `PositiveSemidefiniteConeTriangle(2)`.
"""
struct PositiveSemidefiniteConeSquare <: AbstractSymmetricMatrixSetSquare
    side_dimension::Int
end

function _dual_set_square_error()
    return error(
        """Dual of `PositiveSemidefiniteConeSquare` is not defined in MathOptInterface.
           For more details see the comments in `src/Bridges/Constraint/square.jl`.""",
    )
end
function dual_set(::PositiveSemidefiniteConeSquare)
    return _dual_set_square_error()
end
function dual_set_type(::Type{PositiveSemidefiniteConeSquare})
    return _dual_set_square_error()
end

function triangular_form(::Type{PositiveSemidefiniteConeSquare})
    return PositiveSemidefiniteConeTriangle
end

"""
    LogDetConeTriangle(side_dimension)

The log-determinant cone ``\\{ (t, u, X) \\in \\mathbb{R}^{2 + d(d+1)/2} : t \\le u \\log(\\det(X/u)), u > 0 \\}`` where the matrix `X` is represented in the same symmetric packed format as in the `PositiveSemidefiniteConeTriangle`.
The argument `side_dimension` is the side dimension of the matrix `X`, i.e., its number of rows or columns.
"""
struct LogDetConeTriangle <: AbstractVectorSet
    side_dimension::Int
end

function dimension(s::LogDetConeTriangle)
    return 2 + div(s.side_dimension * (s.side_dimension + 1), 2)
end

"""
    LogDetConeSquare(side_dimension)

The log-determinant cone ``\\{ (t, u, X) \\in \\mathbb{R}^{2 + d^2} : t \\le u \\log(\\det(X/u)), X \\text{ symmetric}, u > 0 \\}`` where the matrix `X` is represented in the same format as in the `PositiveSemidefiniteConeSquare`.
Similarly to `PositiveSemidefiniteConeSquare`, constraints are added to ensures that `X` is symmetric.
The argument `side_dimension` is the side dimension of the matrix `X`, i.e., its number of rows or columns.
"""
struct LogDetConeSquare <: AbstractVectorSet
    side_dimension::Int
end

dimension(s::LogDetConeSquare) = 2 + s.side_dimension^2

"""
    RootDetConeTriangle(side_dimension)

The root-determinant cone ``\\{ (t, X) \\in \\mathbb{R}^{1 + d(d+1)/2} : t \\le \\det(X)^{1/d} \\}`` where the matrix `X` is represented in the same symmetric packed format as in the `PositiveSemidefiniteConeTriangle`.
The argument `side_dimension` is the side dimension of the matrix `X`, i.e., its number of rows or columns.
"""
struct RootDetConeTriangle <: AbstractVectorSet
    side_dimension::Int
end

function dimension(s::RootDetConeTriangle)
    return 1 + div(s.side_dimension * (s.side_dimension + 1), 2)
end

"""
    RootDetConeSquare(side_dimension)

The root-determinant cone ``\\{ (t, X) \\in \\mathbb{R}^{1 + d^2} : t \\le \\det(X)^{1/d}, X \\text{ symmetric} \\}`` where the matrix `X` is represented in the same format as in the `PositiveSemidefiniteConeSquare`.
Similarly to `PositiveSemidefiniteConeSquare`, constraints are added to ensure that `X` is symmetric.
The argument `side_dimension` is the side dimension of the matrix `X`, i.e., its number of rows or columns.
"""
struct RootDetConeSquare <: AbstractVectorSet
    side_dimension::Int
end

dimension(s::RootDetConeSquare) = 1 + s.side_dimension^2

"""
    Integer()

The set of integers ``\\mathbb{Z}``.
"""
struct Integer <: AbstractScalarSet end

"""
    ZeroOne()

The set ``\\{ 0, 1 \\}``.
"""
struct ZeroOne <: AbstractScalarSet end

"""
    Semicontinuous{T <: Real}(lower::T,upper::T)

The set ``\\{0\\} \\cup [lower,upper]``.
"""
struct Semicontinuous{T<:Real} <: AbstractScalarSet
    lower::T
    upper::T
end

"""
    Semiinteger{T <: Real}(lower::T,upper::T)

The set ``\\{0\\} \\cup \\{lower,lower+1,\\ldots,upper-1,upper\\}``.
"""
struct Semiinteger{T<:Real} <: AbstractScalarSet
    lower::T
    upper::T
end

function Base.:(==)(
    set1::S,
    set2::S,
) where {S<:Union{Interval,Semicontinuous,Semiinteger}}
    return set1.lower == set2.lower && set1.upper == set2.upper
end

"""
    SOS1{T <: Real}(weights::Vector{T})

The set corresponding to the special ordered set (SOS) constraint of type 1.
Of the variables in the set, at most one can be nonzero.
The `weights` induce an ordering of the variables; as such, they should be unique values.
The *k*th element in the set corresponds to the *k*th weight in `weights`.
See [here](http://lpsolve.sourceforge.net/5.5/SOS.htm) for a description of SOS constraints and their potential uses.
"""
struct SOS1{T<:Real} <: AbstractVectorSet
    weights::Vector{T}
end

"""
    SOS2{T <: Real}(weights::Vector{T})

The set corresponding to the special ordered set (SOS) constraint of type 2.
Of the variables in the set, at most two can be nonzero, and if two are nonzero, they must be adjacent in the ordering of the set.
The `weights` induce an ordering of the variables; as such, they should be unique values.
The *k*th element in the set corresponds to the *k*th weight in `weights`.
See [here](http://lpsolve.sourceforge.net/5.5/SOS.htm) for a description of SOS constraints and their potential uses.
"""
struct SOS2{T<:Real} <: AbstractVectorSet
    weights::Vector{T}
end

Base.:(==)(a::T, b::T) where {T<:Union{SOS1,SOS2}} = a.weights == b.weights
function Base.isapprox(a::T, b::T; kwargs...) where {T<:Union{SOS1,SOS2}}
    return isapprox(a.weights, b.weights; kwargs...)
end

dimension(s::Union{SOS1,SOS2}) = length(s.weights)

"""
	ActivationCondition

Activation condition for an indicator constraint.
The enum value is used as first type parameter of `IndicatorSet{A,S}`.
"""
@enum ActivationCondition begin
    ACTIVATE_ON_ZERO
    ACTIVATE_ON_ONE
end

"""
    IndicatorSet{A, S <: AbstractScalarSet}(set::S)

``\\{(y, x) \\in \\{0, 1\\} \\times \\mathbb{R}^n : y = 0 \\implies x \\in set\\}``
when `A` is `ACTIVATE_ON_ZERO` and
``\\{(y, x) \\in \\{0, 1\\} \\times \\mathbb{R}^n : y = 1 \\implies x \\in set\\}``
when `A` is `ACTIVATE_ON_ONE`.

`S` has to be a sub-type of `AbstractScalarSet`.
`A` is one of the value of the `ActivationCond` enum.
`IndicatorSet` is used with a `VectorAffineFunction` holding
the indicator variable first.

Example: ``\\{(y, x) \\in \\{0, 1\\} \\times \\mathbb{R}^2 : y = 1 \\implies x_1 + x_2 \\leq 9 \\} ``

```julia
f = MOI.VectorAffineFunction(
    [MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(1.0, y)),
     MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(1.0, x1)),
     MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(1.0, x2)),
    ],
    [0.0, 0.0],
)

indicator_set = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0))

MOI.add_constraint(model, f, indicator_set)
```
"""
struct IndicatorSet{A,S<:AbstractScalarSet} <: AbstractVectorSet
    set::S
    IndicatorSet{A}(set::S) where {A,S<:AbstractScalarSet} = new{A,S}(set)
end

dimension(::IndicatorSet) = 2

function Base.copy(set::IndicatorSet{A,S}) where {A,S}
    return IndicatorSet{A}(copy(set.set))
end

function Base.:(==)(
    set1::IndicatorSet{A,S},
    set2::IndicatorSet{A,S},
) where {A,S}
    return set1.set == set2.set
end

"""
    Complements(dimension::Int)

The set corresponding to a mixed complementarity constraint.

Complementarity constraints should be specified with an
[`AbstractVectorFunction`](@ref)-in-`Complements(dimension)` constraint.

The dimension of the vector-valued function `F` must be `2 * dimension`. This
defines a complementarity constraint between the scalar function `F[i]` and the
variable in `F[i + dimension]`. Thus, `F[i + dimension]` must be interpretable
as a single variable `x_i` (e.g., `1.0 * x + 0.0`).

The mixed complementarity problem consists of finding `x_i` in the interval
`[lb, ub]` (i.e., in the set `Interval(lb, ub)`), such that the following holds:

  1. `F_i(x) == 0` if `lb_i < x_i < ub_i`
  2. `F_i(x) >= 0` if `lb_i == x_i`
  3. `F_i(x) <= 0` if `x_i == ub_i`

Classically, the bounding set for `x_i` is `Interval(0, Inf)`, which recovers:
`0 <= F_i(x) ⟂ x_i >= 0`, where the `⟂` operator implies `F_i(x) * x_i = 0`.

### Examples

The problem:

    x -in- Interval(-1, 1)
    [-4 * x - 3, x] -in- Complements(1)

defines the mixed complementarity problem where the following holds:

  1. `-4 * x - 3 == 0` if `-1 < x < 1`
  2. `-4 * x - 3 >= 0` if `x == -1`
  3. `-4 * x - 3 <= 0` if `x == 1`

There are three solutions:

  1. `x = -3/4` with `F(x) = 0`
  2. `x = -1` with `F(x) = 1`
  3. `x = 1` with `F(x) = -7`

The function `F` can also be defined in terms of single variables. For example,
the problem:

    [x_3, x_4] -in- Nonnegatives(2)
    [x_1, x_2, x_3, x_4] -in- Complements(2)

defines the complementarity problem where `0 <= x_1 ⟂ x_3 >= 0` and
`0 <= x_2 ⟂ x_4 >= 0`.
"""
struct Complements <: AbstractVectorSet
    dimension::Int
end

dimension(set::Complements) = 2 * set.dimension

# isbits types, nothing to copy
function Base.copy(
    set::Union{
        Reals,
        Zeros,
        Nonnegatives,
        Nonpositives,
        GreaterThan,
        LessThan,
        EqualTo,
        Interval,
        NormInfinityCone,
        NormOneCone,
        SecondOrderCone,
        RotatedSecondOrderCone,
        GeometricMeanCone,
        ExponentialCone,
        DualExponentialCone,
        PowerCone,
        DualPowerCone,
        RelativeEntropyCone,
        NormSpectralCone,
        NormNuclearCone,
        PositiveSemidefiniteConeTriangle,
        PositiveSemidefiniteConeSquare,
        LogDetConeTriangle,
        LogDetConeSquare,
        RootDetConeTriangle,
        RootDetConeSquare,
        Complements,
        Integer,
        ZeroOne,
        Semicontinuous,
        Semiinteger,
    },
)
    return set
end
Base.copy(set::S) where {S<:Union{SOS1,SOS2}} = S(copy(set.weights))

"""
    supports_dimension_update(S::Type{<:MOI.AbstractVectorSet})

Return a `Bool` indicating whether the elimination of any dimension of
`n`-dimensional sets of type `S` give an `n-1`-dimensional set `S`.
By default, this function returns `false` so it should only be implemented
for sets that supports dimension update.

For instance, `supports_dimension_update(MOI.Nonnegatives}` is `true` because
the elimination of any dimension of the `n`-dimensional nonnegative orthant
gives the `n-1`-dimensional nonnegative orthant. However
`supports_dimension_update(MOI.ExponentialCone}` is `false`.
"""
function supports_dimension_update(::Type{<:AbstractVectorSet})
    return false
end
function supports_dimension_update(
    ::Type{<:Union{Reals,Zeros,Nonnegatives,Nonpositives}},
)
    return true
end

"""
    update_dimension(s::AbstractVectorSet, new_dim)

Returns a set with the dimension modified to `new_dim`.
"""
function update_dimension end
function update_dimension(
    set::Union{Reals,Zeros,Nonnegatives,Nonpositives},
    new_dim,
)
    return typeof(set)(new_dim)
end


text:
# test multiple components broken
# upper bound tests
using Distributed;
addprocs(30);
@everywhere include("loadMod.jl");
@everywhere const GUROBI_ENV = Gurobi.Env();
#pmap(i -> importIpopt(),1:30);

dataList = Dict();
iterMax = 20;

caseList = [13,33,123];
T = 24;
Δt = 0.25;
N = 5;
ci = 3;
NN = 1000;

# obtain an N-1 policy
τ = Int64(1/6*T);
for j in procs()
    remotecall_fetch(readInData,j,ci,caseList,T,τ);
end

startT = time();
# cutDict,LBHist,UBHist,UBuHist,UBlHist,timeHist = solveMain(τ, T, Δt, N, true, false,
#     Int64(round(100/N)),Int64(round(100/N)), cutDictPG, false, 200, [], 0, pathDict);
cutDict,LBHist,UBHist,UBuHist,UBlHist,timeHist = solveMain(T, Δt, N, false, false,
    max(Int64(round(500/N)),20), max(Int64(round(500/N)),20), Dict(), false, 500, [], 0, Dict());
elapsedT = time() - startT;

cutDictN1 = deepcopy(cutDict);

for j in procs()
    remotecall_fetch(readInData_tau,j,ci,caseList,T,1e4,0,"Multi",τ);
end

# get multiple disruption cuts
startT = time();
# cutDict,LBHist,UBHist,UBuHist,UBlHist,timeHist = solveMain(τ, T, Δt, N, true, false,
#     Int64(round(100/N)),Int64(round(100/N)), cutDictPG, false, 200, [], 0, pathDict);
cutDict,LBHistm,UBHistm,UBuHistm,UBlHistm,timeHistm = solveMain(T, Δt, N, false, false,
    max(Int64(round(500/N)),20), max(Int64(round(500/N)),20), Dict(), false, 500, [], 0, Dict());
elapsedT = time() - startT;
dataList = [LBHist,UBHist,UBuHist,UBlHist,timeHist,
            LBHistm,UBHistm,UBuHistm,UBlHistm,timeHistm,elapsedT];
cutDictNM = deepcopy(cutDict);

# plug in the N-1 policy in the multi-disruption case
# sample 1000 scenarios
pathDict = pmap(i -> simuPath(T,pDistr), 1:1000);
solDet,costDet = exeDet(T, Δt, fData, bData, dData, pDistr, NN, pathDict);
for j in procs()
    remotecall_fetch(cutIni,j,cutDictN1);
end
solSDDP1, LBSDDP1, costSDDP1 = exeForward(T, Δt, NN, false, pathDict);
for j in procs()
    remotecall_fetch(cutIni,j,cutDictNM);
end
solSDDPM, LBSDDPM, costSDDPM = exeForward(T, Δt, NN, false, pathDict);

save("MultiResults.jld","MultiOut",dataList,
    #"N1Cuts",cutDictN1,"MultiCuts",cutDict,
    "Results",[solDet, costDet, solSDDP1, LBSDDP1, costSDDP1, solSDDPM, LBSDDPM, costSDDPM]);