text:
module NB5I

using NBodyIPs.FastPolys
using StaticArrays
# using BenchmarkTools: @btime

# import NBodyIPs.tdegrees

# NBodyIPs.BLInvariants.tdegrees(::Val{5}) =
#           (@SVector [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, ]),
#     (@SVector [0,
#                3, 3,
#                4, 4, 4, 4, 4,
#                5, 5, 5, 5, 5, 5, 5, 5,
#                6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
#                7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
#                8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
#                8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
#                9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
#                9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
#                9, 9,
#                10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
#                10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
#                10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
#                10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
#                11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
#                11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
#                11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
#                11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
#                11, 11, 11, 11, 11, 11, 11, 11, ])

# Primary invariants for NBody=5and deg=12
 # : definitions at the beginning of the file
const P1_1 = (1,2,3,4,5,6,7,8,9,10,)

const P2_1 = (1,1,1,2,2,3,1,1,1,2,3,4,2,2,3,4,3,4,5,5,6,5,5,6,7,6,7,8,8,9,)
const P2_2 = (2,3,4,3,4,4,5,6,7,5,6,7,8,9,8,9,10,10,6,7,7,8,9,8,9,10,10,9,10,10,)

const P3_1 = (1,2,3,4,5,6,7,8,9,10,)

const P4_1 = (1,1,1,2,1,1,1,2,2,3,4,3,4,2,3,4,5,5,6,7,)
const P4_2 = (2,2,3,3,5,5,6,5,5,6,7,6,7,8,8,9,6,8,8,9,)
const P4_3 = (3,4,4,4,6,7,7,8,9,8,9,10,10,9,10,10,7,9,10,10,)

const P5_1 = (1,2,3,4,5,6,7,8,9,10,)

const P6_1 = (1,1,2,3,4,)
const P6_2 = (2,5,5,6,7,)
const P6_3 = (3,6,8,8,9,)
const P6_4 = (4,7,9,10,10,)

const P7_1 = (1,2,3,4,5,6,7,8,9,10,)

const P8_1 = (1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,1,1,1,2,2,3,4,3,4,2,3,4,)
const P8_2 = (2,2,2,2,2,2,2,3,4,2,3,4,3,4,3,4,4,4,5,5,5,5,5,5,5,6,6,5,6,7,)
const P8_3 = (3,3,3,3,3,3,5,5,5,5,6,7,5,5,6,7,6,7,6,6,6,6,7,6,7,7,7,8,8,8,)
const P8_4 = (4,4,4,4,4,4,6,6,6,8,8,9,8,8,8,9,8,9,7,7,7,8,8,8,9,8,9,9,9,9,)
const P8_5 = (5,6,7,8,9,10,7,7,7,9,10,10,9,9,10,10,10,10,8,9,10,9,9,10,10,10,10,10,10,10,)

const P9_1 = (1,2,3,4,5,6,7,8,9,10,)

const P10_1 = (1,2,3,4,5,6,7,8,9,10,)

# Irreducible secondaries for NBody=5and deg=12
 # : definitions at the beginning of the file
const IS1_1 = (1,1,1,2,3,4,2,2,3,4,3,4,1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,5,6,7,8,9,8,9,10,10,5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,)
const IS1_2 = (2,3,4,1,1,1,3,4,2,2,4,3,5,6,7,5,6,7,8,9,8,9,10,10,1,1,1,2,3,4,2,2,3,4,3,4,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,)

const IS2_1 = (1,1,1,2,2,3,5,5,6,8,)
const IS2_2 = (2,3,4,3,4,4,6,7,7,9,)
const IS2_3 = (5,6,7,8,9,10,8,9,10,10,)

const IS3_1 = (1,1,1,2,3,4,2,2,3,4,3,4,1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,5,6,7,8,9,8,9,10,10,5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,)
const IS3_2 = (2,3,4,1,1,1,3,4,2,2,4,3,5,6,7,5,6,7,8,9,8,9,10,10,1,1,1,2,3,4,2,2,3,4,3,4,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,)

const IS4_1 = (1,1,1,2,2,3,1,1,1,2,3,4,2,2,3,4,3,4,5,5,6,5,5,6,7,6,7,8,8,9,)
const IS4_2 = (2,3,4,3,4,4,5,6,7,5,6,7,8,9,8,9,10,10,6,7,7,8,9,8,9,10,10,9,10,10,)

const IS5_1 = (1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,8,9,10,5,5,6,7,6,7,8,9,10,8,9,10,)
const IS5_2 = (2,3,4,1,1,1,3,4,2,2,4,3,1,1,1,2,2,3,6,7,5,5,7,6,5,5,6,9,8,8,)
const IS5_3 = (5,6,7,5,6,7,8,9,8,9,10,10,2,3,4,3,4,4,8,9,8,9,10,10,6,7,7,10,10,9,)

const IS6_1 = (1,1,1,2,2,3,4,3,4,2,3,4,1,1,1,2,2,3,4,3,4,2,3,4,5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,5,6,7,5,6,7,8,9,8,9,10,10,)
const IS6_2 = (2,2,3,1,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,10,10,)
const IS9_2 = (2,3,4,1,1,1,3,4,2,2,4,3,5,6,7,5,6,7,8,9,8,9,10,10,1,1,1,2,3,4,2,2,3,4,3,4,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,)

const IS10_1 = (1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,8,9,10,5,5,6,7,6,7,8,9,10,8,9,10,)
const IS10_2 = (2,3,4,1,1,1,3,4,2,2,4,3,1,1,1,2,2,3,6,7,5,5,7,6,5,5,6,9,8,8,)
const IS10_3 = (5,6,7,5,6,7,8,9,8,9,10,10,2,3,4,3,4,4,8,9,8,9,10,10,6,7,7,10,10,9,)

const IS11_1 = (1,1,1,2,2,3,1,1,1,2,3,4,2,2,3,4,3,4,5,5,6,5,5,6,7,6,7,8,8,9,)
const IS11_2 = (2,3,4,3,4,4,5,6,7,5,6,7,8,9,8,9,10,10,6,7,7,8,9,8,9,10,10,9,10,10,)
const IS11_3 = (5,6,7,8,9,10,2,3,4,1,1,1,3,4,2,2,4,3,8,9,10,6,7,5,5,7,6,10,9,8,)

const IS12_1 = (1,1,1,2,2,3,4,3,4,2,3,4,1,1,1,2,2,3,4,3,4,2,3,4,5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,5,6,7,5,6,7,8,9,8,9,10,10,)
const IS12_2 = (2,2,3,1,1,1,1,1,1,3,2,2,5,5,6,5,5,6,7,6,7,8,8,9,1,1,1,1,1,1,2,2,3,4,3,4,2,2,3,4,3,4,2,2,3,4,3,4,6,5,5,8,8,9,5,5,6,7,6,7,)
const IS12_3 = (3,4,4,3,4,2,2,4,3,4,4,3,6,7,7,8,9,8,9,10,10,9,10,10,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,7,7,6,9,10,10,9,8,10,10,8,9,)

const IS13_1 = (1,1,1,1,1,1,2,2,3,2,2,3,1,1,1,1,1,1,2,2,3,4,3,4,2,2,3,4,3,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5,6,7,8,9,8,9,10,10,5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,)
const IS17_2 = (2,3,4,1,1,1,3,4,2,2,4,3,5,6,7,5,6,7,8,9,8,9,10,10,1,1,1,2,3,4,2,2,3,4,3,4,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,)

const IS18_1 = (1,1,1,2,2,3,1,1,1,2,3,4,2,2,3,4,3,4,5,5,6,5,5,6,7,6,7,8,8,9,)
const IS18_2 = (2,3,4,3,4,4,5,6,7,5,6,7,8,9,8,9,10,10,6,7,7,8,9,8,9,10,10,9,10,10,)

const IS19_1 = (1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,8,9,10,5,5,6,7,6,7,8,9,10,8,9,10,)
const IS19_2 = (2,3,4,1,1,1,3,4,2,2,4,3,1,1,1,2,2,3,6,7,5,5,7,6,5,5,6,9,8,8,)
const IS19_3 = (5,6,7,5,6,7,8,9,8,9,10,10,2,3,4,3,4,4,8,9,8,9,10,10,6,7,7,10,10,9,)

const IS20_1 = (1,1,1,2,3,4,2,2,3,4,3,4,1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,5,6,7,8,9,8,9,10,10,5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,)
const IS20_2 = (2,3,4,1,1,1,3,4,2,2,4,3,5,6,7,5,6,7,8,9,8,9,10,10,1,1,1,2,3,4,2,2,3,4,3,4,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,)
const IS20_3 = (5,6,7,5,6,7,8,9,8,9,10,10,2,3,4,1,1,1,3,4,2,2,4,3,2,3,4,1,1,1,3,4,2,2,4,3,8,9,8,9,10,10,6,7,5,5,7,6,6,7,5,5,7,6,10,10,9,8,9,8,)

const IS21_1 = (1,1,1,2,2,3,5,5,6,8,)
const IS21_2 = (2,3,4,3,4,4,6,7,7,9,)
const IS21_3 = (5,6,7,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,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,)

const IS30_1 = (1,1,1,2,3,4,2,2,3,4,3,4,1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,5,6,7,8,9,8,9,10,10,5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,)
const IS30_2 = (2,3,4,1,1,1,3,4,2,2,4,3,5,6,7,5,6,7,8,9,8,9,10,10,1,1,1,2,3,4,2,2,3,4,3,4,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,)

const IS31_1 = (1,1,1,2,3,4,2,2,3,4,3,4,1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,5,6,7,8,9,8,9,10,10,5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,)
const IS31_2 = (2,3,4,1,1,1,3,4,2,2,4,3,5,6,7,5,6,7,8,9,8,9,10,10,1,1,1,2,3,4,2,2,3,4,3,4,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,)

const IS32_1 = (1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,8,9,10,5,5,6,7,6,7,8,9,10,8,9,10,)
const IS32_2 = (2,3,4,1,1,1,3,4,2,2,4,3,1,1,1,2,2,3,6,7,5,5,7,6,5,5,6,9,8,8,)
const IS32_3 = (5,6,7,5,6,7,8,9,8,9,10,10,2,3,4,3,4,4,8,9,8,9,10,10,6,7,7,10,10,9,)

const IS33_1 = (1,1,1,2,3,4,2,2,3,4,3,4,1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,5,6,7,8,9,8,9,10,10,5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,)
const IS33_2 = (2,3,4,1,1,1,3,4,2,2,4,3,5,6,7,5,6,7,8,9,8,9,10,10,1,1,1,2,3,4,2,2,3,4,3,4,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,)
const IS33_3 = (5,6,7,5,6,7,8,9,8,9,10,10,2,3,4,1,1,1,3,4,2,2,4,3,2,3,4,1,1,1,3,4,2,2,4,3,8,9,8,9,10,10,6,7,5,5,7,6,6,7,5,5,7,6,10,10,9,8,9,8,)

const IS34_1 = (1,1,1,2,2,3,1,1,1,2,3,4,2,2,3,4,3,4,5,5,6,5,5,6,7,6,7,8,8,9,)
const IS34_2 = (2,3,4,3,4,4,5,6,7,5,6,7,8,9,8,9,10,10,6,7,7,8,9,8,9,10,10,9,10,10,)
const IS34_3 = (5,6,7,8,9,10,2,3,4,1,1,1,3,4,2,2,4,3,8,9,10,6,7,5,5,7,6,10,9,8,)

const IS35_1 = (1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,8,9,10,5,5,6,7,6,7,8,9,10,8,9,10,)
const IS35_2 = (2,3,4,1,1,1,3,4,2,2,4,3,1,1,1,2,2,3,6,7,5,5,7,6,5,5,6,9,8,8,)
const IS35_3 = (5,6,7,5,6,7,8,9,8,9,10,10,2,3,4,3,4,4,8,9,8,9,10,10,6,7,7,10,10,9,)

const IS36_1 = (1,1,1,2,2,3,4,3,4,2,3,4,1,1,1,2,2,3,4,3,4,2,3,4,5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,5,6,7,5,6,7,8,9,8,9,10,10,)
const IS36_2 = (2,2,3,1,1,1,1,1,1,3,2,2,5,5,6,5,5,6,7,6,7,8,8,9,1,1,1,1,1,1,2,2,3,4,3,4,2,2,3,4,3,4,2,2,3,4,3,4,6,5,5,8,8,9,5,5,6,7,6,7,)
const IS36_3 = (3,4,4,3,4,2,2,4,3,4,4,3,6,7,7,8,9,8,9,10,10,9,10,10,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,7,7,6,9,10,10,9,8,10,10,8,9,)

const IS37_1 = (1,1,1,1,1,1,2,2,3,4,3,4,2,2,3,4,3,4,2,2,3,4,3,4,1,1,1,1,1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6,7,6,7,5,5,6,7,6,7,8,8,8,9,8,9,2,2,3,4,3,4,2,2,3,4,3,4,3,4,3,4,4,4,3,4,3,4,4,4,6,7,5,5,7,6,6,7,5,5,7,6,5,5,5,5,6,6,9,8,9,8,8,8,7,7,7,6,7,6,8,8,8,9,8,9,6,7,6,7,7,7,9,8,9,8,8,8,)
const IS40_4 = (5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,6,7,6,7,7,7,8,9,8,9,10,10,8,9,8,9,10,10,9,9,10,10,10,10,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,8,9,8,9,10,10,8,9,8,9,10,10,6,7,6,7,7,7,10,10,10,10,9,9,8,9,8,9,10,10,9,9,10,10,10,10,9,8,10,10,8,9,10,10,10,10,9,9,)

const IS41_1 = (1,2,3,4,5,6,7,8,9,10,)

const IS42_1 = (1,1,1,2,3,4,2,2,3,4,3,4,1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,5,6,7,8,9,8,9,10,10,5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,)
const IS42_2 = (2,3,4,1,1,1,3,4,2,2,4,3,5,6,7,5,6,7,8,9,8,9,10,10,1,1,1,2,3,4,2,2,3,4,3,4,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,)

const IS43_1 = (1,1,1,2,3,4,2,2,3,4,3,4,1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,5,6,7,8,9,8,9,10,10,5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,)
const IS43_2 = (2,3,4,1,1,1,3,4,2,2,4,3,5,6,7,5,6,7,8,9,8,9,10,10,1,1,1,2,3,4,2,2,3,4,3,4,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,)

const IS44_1 = (1,1,1,2,3,4,2,2,3,4,3,4,1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,5,6,7,8,9,8,9,10,10,5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,)
const IS44_2 = (2,3,4,1,1,1,3,4,2,2,4,3,5,6,7,5,6,7,8,9,8,9,10,10,1,1,1,2,3,4,2,2,3,4,3,4,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,)

const IS45_1 = (1,2,3,4,5,6,7,8,9,10,)

const IS46_1 = (1,1,1,2,3,4,2,2,3,4,3,4,1,1,1,2,3,4,2,2,3,4,3,4,5,6,7,5,6,7,8,9,8,9,10,10,5,5,6,7,6,7,5,5,6,7,6,7,8,9,8,9,10,10,8,9,8,9,10,10,)
const IS46_2 = (2,3,4,1,1,1,3,4,2,2,4,3,5,6,7,5,6,7,8,9,8,9,10,10,1,1,1,2,3,4,2,2,3,4,3,4,6,7,5,5,7,6,8,9,8,9,10,10,5,5,6,7,6,7,9,8,10,10,8,9,)

# Primary invariants for NBody=5and deg=12
 # : definitions of the types at the beginning of the file
const P1 = Val((P1_1,))
const P2 = Val((P2_1,P2_2,))
const P3 = Val((P3_1,))
const P4 = Val((P4_1,P4_2,P4_3,))
const P5 = Val((P5_1,))
const P6 = Val((P6_1,P6_2,P6_3,P6_4,))
const P7 = Val((P7_1,))
const P8 = Val((P8_1,P8_2,P8_3,P8_4,P8_5,))
const P9 = Val((P9_1,))
const P10 = Val((P10_1,))
# Irreducible secondaries for NBody=5and deg=12
 # : definitions of the types at the beginning of the file
const IS1 = Val((IS1_1,IS1_2,))
const IS2 = Val((IS2_1,IS2_2,IS2_3,))
const IS3 = Val((IS3_1,IS3_2,))
const IS4 = Val((IS4_1,IS4_2,))
const IS5 = Val((IS5_1,IS5_2,IS5_3,))
const IS6 = Val((IS6_1,IS6_2,IS6_3,))
const IS7 = Val((IS7_1,IS7_2,IS7_3,))
const IS8 = Val((IS8_1,IS8_2,))
const IS9 = Val((IS9_1,IS9_2,))
const IS10 = Val((IS10_1,IS10_2,IS10_3,))
const IS11 = Val((IS11_1,IS11_2,IS11_3,))
const IS12 = Val((IS12_1,IS12_2,IS12_3,))
const IS13 = Val((IS13_1,IS13_2,IS13_3,))
const IS14 = Val((IS14_1,IS14_2,IS14_3,))
const IS15 = Val((IS15_1,IS15_2,IS15_3,IS15_4,))
const IS16 = Val((IS16_1,IS16_2,))
const IS17 = Val((IS17_1,IS17_2,))
const IS18 = Val((IS18_1,IS18_2,))
const IS19 = Val((IS19_1,IS19_2,IS19_3,))
const IS20 = Val((IS20_1,IS20_2,IS20_3,))
const IS21 = Val((IS21_1,IS21_2,IS21_3,))
const IS22 = Val((IS22_1,IS22_2,IS22_3,))
const IS23 = Val((IS23_1,IS23_2,IS23_3,))
const IS24 = Val((IS24_1,IS24_2,IS24_3,))
const IS25 = Val((IS25_1,IS25_2,IS25_3,IS25_4,))
const IS26 = Val((IS26_1,IS26_2,IS26_3,IS26_4,))
const IS27 = Val((IS27_1,IS27_2,IS27_3,))
const IS28 = Val((IS28_1,))
const IS29 = Val((IS29_1,IS29_2,))
const IS30 = Val((IS30_1,IS30_2,))
const IS31 = Val((IS31_1,IS31_2,))
const IS32 = Val((IS32_1,IS32_2,IS32_3,))
const IS33 = Val((IS33_1,IS33_2,IS33_3,))
const IS34 = Val((IS34_1,IS34_2,IS34_3,))
const IS35 = Val((IS35_1,IS35_2,IS35_3,))
const IS36 = Val((IS36_1,IS36_2,IS36_3,))
const IS37 = Val((IS37_1,IS37_2,IS37_3,))
const IS38 = Val((IS38_1,IS38_2,IS38_3,))
const IS39 = Val((IS39_1,IS39_2,IS39_3,))
const IS40 = Val((IS40_1,IS40_2,IS40_3,IS40_4,))
const IS41 = Val((IS41_1,))
const IS42 = Val((IS42_1,IS42_2,))
const IS43 = Val((IS43_1,IS43_2,))
const IS44 = Val((IS44_1,IS44_2,))
const IS45 = Val((IS45_1,))
const IS46 = Val((IS46_1,IS46_2,))

function invariants_gen(x1::SVector{10, T}) where {T}
   x2 = x1.*x1
   x3 = x2.*x1
   x4 = x3.*x1
   x5 = x4.*x1
   x6 = x5.*x1
   x7 = x6.*x1
   x8 = x7.*x1
   x9 = x8.*x1
   #------------------------------------------------
   # Primaries
   #------------------------------------------------

# Primary invariants for NBody=5and deg=12
 # : what goes in the function for the evaluation
P1 = fpoly((x1,) , NB5I.P1)
P2 = fpoly((x1,x1,) , NB5I.P2)
P3 = fpoly((x2,) , NB5I.P3)
P4 = fpoly((x1,x1,x1,) , NB5I.P4)
P5 = fpoly((x3,) , NB5I.P5)
P6 = fpoly((x1,x1,x1,x1,) , NB5I.P6)
P7 = fpoly((x4,) , NB5I.P7)
P8 = fpoly((x1,x1,x1,x1,x1,) , NB5I.P8)
P9 = fpoly((x5,) , NB5I.P9)
P10 = fpoly((x6,) , NB5I.P10)

   #------------------------------------------------
   # Irreducible secondaries
   #------------------------------------------------

# Irreducible secondaries for NBody=5and deg=12
 # : what goes in the function for the evaluation
IS1 = fpoly((x2,x1,) , NB5I.IS1)
IS2 = fpoly((x1,x1,x1,) , NB5I.IS2)
IS3 = fpoly((x3,x1,) , NB5I.IS3)
IS4 = fpoly((x2,x2,) , NB5I.IS4)
IS5 = fpoly((x2,x1,x1,) , NB5I.IS5)
IS6 = fpoly((x2,x1,x1,) , NB5I.IS6)
IS7 = fpoly((x2,x1,x1,) , NB5I.IS7)
IS8 = fpoly((x4,x1,) , NB5I.IS8)
IS9 = fpoly((x3,x2,) , NB5I.IS9)
IS10 = fpoly((x3,x1,x1,) , NB5I.IS10)
IS11 = fpoly((x2,x2,x1,) , NB5I.IS11)
IS12 = fpoly((x3,x1,x1,) , NB5I.IS12)
IS13 = fpoly((x2,x2,x1,) , NB5I.IS13)
IS14 = fpoly((x3,x1,x1,) , NB5I.IS14)
IS15 = fpoly((x2,x1,x1,x1,) , NB5I.IS15)
IS16 = fpoly((x5,x1,) , NB5I.IS16)
IS17 = fpoly((x4,x2,) , NB5I.IS17)
IS18 = fpoly((x3,x3,) , NB5I.IS18)
IS19 = fpoly((x4,x1,x1,) , NB5I.IS19)
IS20 = fpoly((x3,x2,x1,) , NB5I.IS20)
IS21 = fpoly((x2,x2,x2,) , NB5I.IS21)
IS22 = fpoly((x4,x1,x1,) , NB5I.IS22)
IS23 = fpoly((x3,x2,x1,) , NB5I.IS23)
IS24 = fpoly((x4,x1,x1,) , NB5I.IS24)
IS25 = fpoly((x3,x1,x1,x1,) , NB5I.IS25)
IS26 = fpoly((x2,x2,x1,x1,) , NB5I.IS26)
IS27 = fpoly((x3,x2,x1,) , NB5I.IS27)
IS28 = fpoly((x7,) , NB5I.IS28)
IS29 = fpoly((x6,x1,) , NB5I.IS29)
IS30 = fpoly((x5,x2,) , NB5I.IS30)
IS31 = fpoly((x4,x3,) , NB5I.IS31)
IS32 = fpoly((x5,x1,x1,) , NB5I.IS32)
IS33 = fpoly((x4,x2,x1,) , NB5I.IS33)
IS34 = fpoly((x3,x3,x1,) , NB5I.IS34)
IS35 = fpoly((x3,x2,x2,) , NB5I.IS35)
IS36 = fpoly((x5,x1,x1,) , NB5I.IS36)
IS37 = fpoly((x4,x2,x1,) , NB5I.IS37)
IS38 = fpoly((x3,x3,x1,) , NB5I.IS38)
IS39 = fpoly((x5,x1,x1,) , NB5I.IS39)
IS40 = fpoly((x4,x1,x1,x1,) , NB5I.IS40)
IS41 = fpoly((x8,) , NB5I.IS41)
IS42 = fpoly((x7,x1,) , NB5I.IS42)
IS43 = fpoly((x6,x2,) , NB5I.IS43)
IS44 = fpoly((x5,x3,) , NB5I.IS44)
IS45 = fpoly((x9,) , NB5I.IS45)
IS46 = fpoly((x8,x1,) , NB5I.IS46)

   #------------------------------------------------
   # All secondaries
   #------------------------------------------------

 SEC1  = 1
 SEC2  = IS1
 SEC3  = IS2
 SEC4  = IS3
 SEC5  = IS4
 SEC6  = IS5
 SEC7  = IS6
 SEC8  = IS7
 SEC9  = IS8
 SEC10  = IS9
 SEC11  = IS10
 SEC12  = IS11
 SEC13  = IS12
 SEC14  = IS13
 SEC15  = IS14
 SEC16  = IS15
 SEC17  = IS1 *IS1
 SEC18  = IS1 *IS2
 SEC19  = IS2 *IS2
 SEC20  = IS16
 SEC21  = IS17
 SEC22  = IS18
 SEC23  = IS19
 SEC24  = IS20
 SEC25  = IS21
 SEC26  = IS22
 SEC27  = IS23
 SEC28  = IS24
 SEC29  = IS25
 SEC30  = IS26
 SEC31  = IS27
 SEC32  = IS1 *IS3
 SEC33  = IS2 *IS3
 SEC34  = IS1 *IS4
 SEC35  = IS2 *IS4
 SEC36  = IS1 *IS5
 SEC37  = IS2 *IS5
 SEC38  = IS1 *IS6
 SEC39  = IS2 *IS6
 SEC40  = IS1 *IS7
 SEC41  = IS2 *IS7
 SEC42  = IS28
 SEC43  = IS29
 SEC44  = IS30
 SEC45  = IS31
 SEC46  = IS32
 SEC47  = IS33
 SEC48  = IS34
 SEC49  = IS35
 SEC50  = IS36
 SEC51  = IS37
 SEC52  = IS38
 SEC53  = IS39
 SEC54  = IS40
 SEC55  = IS4 *IS4
 SEC56  = IS3 *IS5
 SEC57  = IS4 *IS5
 SEC58  = IS5 *IS5
 SEC59  = IS3 *IS6
 SEC60  = IS4 *IS6
 SEC61  = IS5 *IS6
 SEC62  = IS6 *IS6
 SEC63  = IS3 *IS7
 SEC64  = IS4 *IS7
 SEC65  = IS5 *IS7
 SEC66  = IS6 *IS7
 SEC67  = IS7 *IS7
 SEC68  = IS1 *IS8
 SEC69  = IS2 *IS8
 SEC70  = IS1 *IS9
 SEC71  = IS2 *IS9
 SEC72  = IS1 *IS10
 SEC73  = IS2 *IS10
 SEC74  = IS1 *IS11
 SEC75  = IS2 *IS11
 SEC76  = IS1 *IS12
 SEC77  = IS2 *IS12
 SEC78  = IS1 *IS13
 SEC79  = IS2 *IS13
 SEC80  = IS1 *IS14
 SEC81  = IS2 *IS14
 SEC82  = IS1 *IS15
 SEC83  = IS2 *IS15
 SEC84  = IS41
 SEC85  = IS42
 SEC86  = IS43
 SEC87  = IS44
 SEC88  = IS3 *IS12
 SEC89  = IS4 *IS12
 SEC90  = IS5 *IS12
 SEC91  = IS6 *IS12
 SEC92  = IS7 *IS12
 SEC93  = IS3 *IS13
 SEC94  = IS4 *IS13
 SEC95  = IS5 *IS13
 SEC96  = IS6 *IS13
 SEC97  = IS7 *IS13
 SEC98  = IS3 *IS14
 SEC99  = IS4 *IS14
 SEC100  = IS5 *IS14
 SEC101  = IS6 *IS14
 SEC102  = IS7 *IS14
 SEC103  = IS3 *IS15
 SEC104  = IS4 *IS15
 SEC105  = IS5 *IS15
 SEC106  = IS6 *IS15
 SEC107  = IS7 *IS15
 SEC108  = IS1 *IS16
 SEC109  = IS2 *IS16
 SEC110  = IS1 *IS17
 SEC111  = IS2 *IS17
 SEC112  = IS1 *IS18
 SEC113  = IS2 *IS18
 SEC114  = IS1 *IS19
 SEC115  = IS2 *IS19
 SEC116  = IS1 *IS20
 SEC117  = IS2 *IS20
 SEC118  = IS1 *IS21
 SEC119  = IS2 *IS21
 SEC120  = IS1 *IS22
 SEC121  = IS2 *IS22
 SEC122  = IS1 *IS23
 SEC123  = IS2 *IS23
 SEC124  = IS1 *IS24
 SEC125  = IS2 *IS24
 SEC126  = IS1 *IS25
 SEC127  = IS2 *IS25
 SEC128  = IS1 *IS26
 SEC129  = IS2 *IS26
 SEC130  = IS1 *IS27
 SEC131  = IS2 *IS27
 SEC132  = IS45
 SEC133  = IS46
 SEC134  = IS3 *IS21
 SEC135  = IS4 *IS21
 SEC136  = IS5 *IS21
 SEC137  = IS6 *IS21
 SEC138  = IS7 *IS21
 SEC139  = IS3 *IS22
 SEC140  = IS4 *IS22
 SEC141  = IS5 *IS22
 SEC142  = IS6 *IS22
 SEC143  = IS7 *IS22
 SEC144  = IS3 *IS23
 SEC145  = IS4 *IS23
 SEC146  = IS5 *IS23
 SEC147  = IS6 *IS23
 SEC148  = IS7 *IS23
 SEC149  = IS3 *IS24
 SEC150  = IS4 *IS24
 SEC151  = IS5 *IS24
 SEC152  = IS6 *IS24
 SEC153  = IS7 *IS24
 SEC154  = IS3 *IS25
 SEC155  = IS4 *IS25
 SEC156  = IS5 *IS25
 SEC157  = IS6 *IS25
 SEC158  = IS7 *IS25
 SEC159  = IS3 *IS26
 SEC160  = IS4 *IS26
 SEC161  = IS5 *IS26
 SEC162  = IS6 *IS26
 SEC163  = IS7 *IS26
 SEC164  = IS3 *IS27
 SEC165  = IS4 *IS27
 SEC166  = IS5 *IS27
 SEC167  = IS6 *IS27
 SEC168  = IS7 *IS27
 SEC169  = IS1 *IS28
 SEC170  = IS2 *IS28
 SEC171  = IS1 *IS29
 SEC172  = IS2 *IS29
 SEC173  = IS1 *IS30
 SEC174  = IS2 *IS30
 SEC175  = IS1 *IS31
 SEC176  = IS2 *IS31
 SEC177  = IS1 *IS32
 SEC178  = IS2 *IS32
 SEC179  = IS1 *IS33
 SEC180  = IS2 *IS33
 SEC181  = IS1 *IS34
 SEC182  = IS2 *IS34
 SEC183  = IS1 *IS35
 SEC184  = IS2 *IS35
 SEC185  = IS1 *IS36
 SEC186  = IS2 *IS36
 SEC187  = IS1 *IS37
 SEC188  = IS2 *IS37
 SEC189  = IS1 *IS38
 SEC190  = IS2 *IS38
 SEC191  = IS1 *IS39
 SEC192  = IS2 *IS39
 SEC193  = IS1 *IS40
 SEC194  = IS2 *IS40
 SEC195  = IS4 *IS28
 SEC196  = IS5 *IS28
 SEC197  = IS6 *IS28
 SEC198  = IS7 *IS28
 SEC199  = IS3 *IS29
 SEC200  = IS4 *IS29
 SEC201  = IS5 *IS29
 SEC202  = IS6 *IS29
 SEC203  = IS7 *IS29
 SEC204  = IS3 *IS30
 SEC205  = IS4 *IS30
 SEC206  = IS5 *IS30
 SEC207  = IS6 *IS30
 SEC208  = IS7 *IS30
 SEC209  = IS3 *IS31
 SEC210  = IS4 *IS31
 SEC211  = IS5 *IS31
 SEC212  = IS6 *IS31
 SEC213  = IS7 *IS31
 SEC214  = IS3 *IS32
 SEC215  = IS4 *IS32
 SEC216  = IS5 *IS32
 SEC217  = IS6 *IS32
 SEC218  = IS7 *IS32
 SEC219  = IS3 *IS33
 SEC220  = IS4 *IS33
 SEC221  = IS5 *IS33
 SEC222  = IS6 *IS33
 SEC223  = IS7 *IS33
 SEC224  = IS3 *IS34
 SEC225  = IS4 *IS34
 SEC226  = IS5 *IS34
 SEC227  = IS6 *IS34
 SEC228  = IS7 *IS34
 SEC229  = IS3 *IS35
 SEC230  = IS4 *IS35
 SEC231  = IS5 *IS35
 SEC232  = IS6 *IS35
 SEC233  = IS7 *IS35
 SEC234  = IS3 *IS36
 SEC235  = IS4 *IS36
 SEC236  = IS5 *IS36
 SEC237  = IS6 *IS36
 SEC238  = IS7 *IS36
 SEC239  = IS3 *IS37
 SEC240  = IS4 *IS37
 SEC241  = IS5 *IS37
 SEC242  = IS6 *IS37
 SEC243  = IS7 *IS37
 SEC244  = IS3 *IS38
 SEC245  = IS4 *IS38
 SEC246  = IS5 *IS38
 SEC247  = IS6 *IS38
 SEC248  = IS7 *IS38
 SEC249  = IS3 *IS39
 SEC250  = IS4 *IS39
 SEC251  = IS5 *IS39
 SEC252  = IS6 *IS39
 SEC253  = IS7 *IS39
 SEC254  = IS3 *IS40
 SEC255  = IS4 *IS40
 SEC256  = IS5 *IS40
 SEC257  = IS6 *IS40
 SEC258  = IS7 *IS40
 SEC259  = IS1 *IS41
 SEC260  = IS2 *IS41
 SEC261  = IS1 *IS42
 SEC262  = IS2 *IS42
 SEC263  = IS1 *IS43
 SEC264  = IS2 *IS43
 SEC265  = IS1 *IS44
 SEC266  = IS2 *IS44

return (@SVector [P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,]), (@SVector [SEC1,SEC2,SEC3,SEC4,SEC5,SEC6,SEC7,SEC8,SEC9,SEC10,SEC11,SEC12,SEC13,SEC14,SEC15,SEC16,SEC17,SEC18,SEC19,SEC20,SEC21,SEC22,SEC23,SEC24,SEC25,SEC26,SEC27,SEC28,SEC29,SEC30,SEC31,SEC32,SEC33,SEC34,SEC35,SEC36,SEC37,SEC38,SEC39,SEC40,SEC41,SEC42,SEC43,SEC44,SEC45,SEC46,SEC47,SEC48,SEC49,SEC50,SEC51,SEC52,SEC53,SEC54,SEC55,SEC56,SEC57,SEC58,SEC59,SEC60,SEC61,SEC62,SEC63,SEC64,SEC65,SEC66,SEC67,SEC68,SEC69,SEC70,SEC71,SEC72,SEC73,SEC74,SEC75,SEC76,SEC77,SEC78,SEC79,SEC80,SEC81,SEC82,SEC83,SEC84,SEC85,SEC86,SEC87,SEC88,SEC89,SEC90,SEC91,SEC92,SEC93,SEC94,SEC95,SEC96,SEC97,SEC98,SEC99,SEC100,SEC101,SEC102,SEC103,SEC104,SEC105,SEC106,SEC107,SEC108,SEC109,SEC110,SEC111,SEC112,SEC113,SEC114,SEC115,SEC116,SEC117,SEC118,SEC119,SEC120,SEC121,SEC122,SEC123,SEC124,SEC125,SEC126,SEC127,SEC128,SEC129,SEC130,SEC131,SEC132,SEC133,SEC134,SEC135,SEC136,SEC137,SEC138,SEC139,SEC140,SEC141,SEC142,SEC143,SEC144,SEC145,SEC146,SEC147,SEC148,SEC149,SEC150,SEC151,SEC152,SEC153,SEC154,SEC155,SEC156,SEC157,SEC158,SEC159,SEC160,SEC161,SEC162,SEC163,SEC164,SEC165,SEC166,SEC167,SEC168,SEC169,SEC170,SEC171,SEC172,SEC173,SEC174,SEC175,SEC176,SEC177,SEC178,SEC179,SEC180,SEC181,SEC182,SEC183,SEC184,SEC185,SEC186,SEC187,SEC188,SEC189,SEC190,SEC191,SEC192,SEC193,SEC194,SEC195,SEC196,SEC197,SEC198,SEC199,SEC200,SEC201,SEC202,SEC203,SEC204,SEC205,SEC206,SEC207,SEC208,SEC209,SEC210,SEC211,SEC212,SEC213,SEC214,SEC215,SEC216,SEC217,SEC218,SEC219,SEC220,SEC221,SEC222,SEC223,SEC224,SEC225,SEC226,SEC227,SEC228,SEC229,SEC230,SEC231,SEC232,SEC233,SEC234,SEC235,SEC236,SEC237,SEC238,SEC239,SEC240,SEC241,SEC242,SEC243,SEC244,SEC245,SEC246,SEC247,SEC248,SEC249,SEC250,SEC251,SEC252,SEC253,SEC254,SEC255,SEC256,SEC257,SEC258,SEC259,SEC260,SEC261,SEC262,SEC263,SEC264,SEC265,SEC266,])
 end

function invariants_d_gen(x1::SVector{10, T}) where {T}
   x2 = x1.*x1
   x3 = x2.*x1
   x4 = x3.*x1
   x5 = x4.*x1
   x6 = x5.*x1
   x7 = x6.*x1
   x8 = x7.*x1
   x9 = x8.*x1

   dx1 = @SVector ones(10)
   dx2 = 2 * x1
   dx3 = 3 * x2
   dx4 = 4 * x3
   dx5 = 5 * x4
   dx6 = 6 * x5
   dx7 = 7 * x6
   dx8 = 8 * x7
   dx9 = 9 * x8
   #------------------------------------------------
   # Primaries
   #------------------------------------------------

# Primary invariants for NBody=5and deg=12
 # : what goes in the function for the derivatives
dP1 = fpoly_d((x1,),(dx1,) , NB5I.P1)
dP2 = fpoly_d((x1,x1,),(dx1,dx1,) , NB5I.P2)
dP3 = fpoly_d((x2,),(dx2,) , NB5I.P3)
dP4 = fpoly_d((x1,x1,x1,),(dx1,dx1,dx1,) , NB5I.P4)
dP5 = fpoly_d((x3,),(dx3,) , NB5I.P5)
dP6 = fpoly_d((x1,x1,x1,x1,),(dx1,dx1,dx1,dx1,) , NB5I.P6)
dP7 = fpoly_d((x4,),(dx4,) , NB5I.P7)
dP8 = fpoly_d((x1,x1,x1,x1,x1,),(dx1,dx1,dx1,dx1,dx1,) , NB5I.P8)
dP9 = fpoly_d((x5,),(dx5,) , NB5I.P9)
dP10 = fpoly_d((x6,),(dx6,) , NB5I.P10)

   #------------------------------------------------
   # Irreducible secondaries
   #------------------------------------------------

# Irreducible secondaries for NBody=5and deg=12
 # : what goes in the function for the evaluation
IS1 = fpoly((x2,x1,) , NB5I.IS1)
IS2 = fpoly((x1,x1,x1,) , NB5I.IS2)
IS3 = fpoly((x3,x1,) , NB5I.IS3)
IS4 = fpoly((x2,x2,) , NB5I.IS4)
IS5 = fpoly((x2,x1,x1,) , NB5I.IS5)
IS6 = fpoly((x2,x1,x1,) , NB5I.IS6)
IS7 = fpoly((x2,x1,x1,) , NB5I.IS7)
IS8 = fpoly((x4,x1,) , NB5I.IS8)
IS9 = fpoly((x3,x2,) , NB5I.IS9)
IS10 = fpoly((x3,x1,x1,) , NB5I.IS10)
IS11 = fpoly((x2,x2,x1,) , NB5I.IS11)
IS12 = fpoly((x3,x1,x1,) , NB5I.IS12)
IS13 = fpoly((x2,x2,x1,) , NB5I.IS13)
IS14 = fpoly((x3,x1,x1,) , NB5I.IS14)
IS15 = fpoly((x2,x1,x1,x1,) , NB5I.IS15)
IS16 = fpoly((x5,x1,) , NB5I.IS16)
IS17 = fpoly((x4,x2,) , NB5I.IS17)
IS18 = fpoly((x3,x3,) , NB5I.IS18)
IS19 = fpoly((x4,x1,x1,) , NB5I.IS19)
IS20 = fpoly((x3,x2,x1,) , NB5I.IS20)
IS21 = fpoly((x2,x2,x2,) , NB5I.IS21)
IS22 = fpoly((x4,x1,x1,) , NB5I.IS22)
IS23 = fpoly((x3,x2,x1,) , NB5I.IS23)
IS24 = fpoly((x4,x1,x1,) , NB5I.IS24)
IS25 = fpoly((x3,x1,x1,x1,) , NB5I.IS25)
IS26 = fpoly((x2,x2,x1,x1,) , NB5I.IS26)
IS27 = fpoly((x3,x2,x1,) , NB5I.IS27)
IS28 = fpoly((x7,) , NB5I.IS28)
IS29 = fpoly((x6,x1,) , NB5I.IS29)
IS30 = fpoly((x5,x2,) , NB5I.IS30)
IS31 = fpoly((x4,x3,) , NB5I.IS31)
IS32 = fpoly((x5,x1,x1,) , NB5I.IS32)
IS33 = fpoly((x4,x2,x1,) , NB5I.IS33)
IS34 = fpoly((x3,x3,x1,) , NB5I.IS34)
IS35 = fpoly((x3,x2,x2,) , NB5I.IS35)
IS36 = fpoly((x5,x1,x1,) , NB5I.IS36)
IS37 = fpoly((x4,x2,x1,) , NB5I.IS37)
IS38 = fpoly((x3,x3,x1,) , NB5I.IS38)
IS39 = fpoly((x5,x1,x1,) , NB5I.IS39)
IS40 = fpoly((x4,x1,x1,x1,) , NB5I.IS40)
IS41 = fpoly((x8,) , NB5I.IS41)
IS42 = fpoly((x7,x1,) , NB5I.IS42)
IS43 = fpoly((x6,x2,) , NB5I.IS43)
IS44 = fpoly((x5,x3,) , NB5I.IS44)
IS45 = fpoly((x9,) , NB5I.IS45)
IS46 = fpoly((x8,x1,) , NB5I.IS46)

# Irreducible secondaries for NBody=5and deg=12
 # : what goes in the function for the derivatives
dIS1 = fpoly_d((x2,x1,),(dx2,dx1,) , NB5I.IS1)
dIS2 = fpoly_d((x1,x1,x1,),(dx1,dx1,dx1,) , NB5I.IS2)
dIS3 = fpoly_d((x3,x1,),(dx3,dx1,) , NB5I.IS3)
dIS4 = fpoly_d((x2,x2,),(dx2,dx2,) , NB5I.IS4)
dIS5 = fpoly_d((x2,x1,x1,),(dx2,dx1,dx1,) , NB5I.IS5)
dIS6 = fpoly_d((x2,x1,x1,),(dx2,dx1,dx1,) , NB5I.IS6)
dIS7 = fpoly_d((x2,x1,x1,),(dx2,dx1,dx1,) , NB5I.IS7)
dIS8 = fpoly_d((x4,x1,),(dx4,dx1,) , NB5I.IS8)
dIS9 = fpoly_d((x3,x2,),(dx3,dx2,) , NB5I.IS9)
dIS10 = fpoly_d((x3,x1,x1,),(dx3,dx1,dx1,) , NB5I.IS10)
dIS11 = fpoly_d((x2,x2,x1,),(dx2,dx2,dx1,) , NB5I.IS11)
dIS12 = fpoly_d((x3,x1,x1,),(dx3,dx1,dx1,) , NB5I.IS12)
dIS13 = fpoly_d((x2,x2,x1,),(dx2,dx2,dx1,) , NB5I.IS13)
dIS14 = fpoly_d((x3,x1,x1,),(dx3,dx1,dx1,) , NB5I.IS14)
dIS15 = fpoly_d((x2,x1,x1,x1,),(dx2,dx1,dx1,dx1,) , NB5I.IS15)
dIS16 = fpoly_d((x5,x1,),(dx5,dx1,) , NB5I.IS16)
dIS17 = fpoly_d((x4,x2,),(dx4,dx2,) , NB5I.IS17)
dIS18 = fpoly_d((x3,x3,),(dx3,dx3,) , NB5I.IS18)
dIS19 = fpoly_d((x4,x1,x1,),(dx4,dx1,dx1,) , NB5I.IS19)
dIS20 = fpoly_d((x3,x2,x1,),(dx3,dx2,dx1,) , NB5I.IS20)
dIS21 = fpoly_d((x2,x2,x2,),(dx2,dx2,dx2,) , NB5I.IS21)
dIS22 = fpoly_d((x4,x1,x1,),(dx4,dx1,dx1,) , NB5I.IS22)
dIS23 = fpoly_d((x3,x2,x1,),(dx3,dx2,dx1,) , NB5I.IS23)
dIS24 = fpoly_d((x4,x1,x1,),(dx4,dx1,dx1,) , NB5I.IS24)
dIS25 = fpoly_d((x3,x1,x1,x1,),(dx3,dx1,dx1,dx1,) , NB5I.IS25)
dIS26 = fpoly_d((x2,x2,x1,x1,),(dx2,dx2,dx1,dx1,) , NB5I.IS26)
dIS27 = fpoly_d((x3,x2,x1,),(dx3,dx2,dx1,) , NB5I.IS27)
dIS28 = fpoly_d((x7,),(dx7,) , NB5I.IS28)
dIS29 = fpoly_d((x6,x1,),(dx6,dx1,) , NB5I.IS29)
dIS30 = fpoly_d((x5,x2,),(dx5,dx2,) , NB5I.IS30)
dIS31 = fpoly_d((x4,x3,),(dx4,dx3,) , NB5I.IS31)
dIS32 = fpoly_d((x5,x1,x1,),(dx5,dx1,dx1,) , NB5I.IS32)
dIS33 = fpoly_d((x4,x2,x1,),(dx4,dx2,dx1,) , NB5I.IS33)
dIS34 = fpoly_d((x3,x3,x1,),(dx3,dx3,dx1,) , NB5I.IS34)
dIS35 = fpoly_d((x3,x2,x2,),(dx3,dx2,dx2,) , NB5I.IS35)
dIS36 = fpoly_d((x5,x1,x1,),(dx5,dx1,dx1,) , NB5I.IS36)
dIS37 = fpoly_d((x4,x2,x1,),(dx4,dx2,dx1,) , NB5I.IS37)
dIS38 = fpoly_d((x3,x3,x1,),(dx3,dx3,dx1,) , NB5I.IS38)
dIS39 = fpoly_d((x5,x1,x1,),(dx5,dx1,dx1,) , NB5I.IS39)
dIS40 = fpoly_d((x4,x1,x1,x1,),(dx4,dx1,dx1,dx1,) , NB5I.IS40)
dIS41 = fpoly_d((x8,),(dx8,) , NB5I.IS41)
dIS42 = fpoly_d((x7,x1,),(dx7,dx1,) , NB5I.IS42)
dIS43 = fpoly_d((x6,x2,),(dx6,dx2,) , NB5I.IS43)
dIS44 = fpoly_d((x5,x3,),(dx5,dx3,) , NB5I.IS44)
dIS45 = fpoly_d((x9,),(dx9,) , NB5I.IS45)
dIS46 = fpoly_d((x8,x1,),(dx8,dx1,) , NB5I.IS46)

   #------------------------------------------------
   # All secondaries
   #------------------------------------------------

 dSEC1   = @SVector zeros(10)
 dSEC2  = dIS1
 dSEC3  = dIS2
 dSEC4  = dIS3
 dSEC5  = dIS4
 dSEC6  = dIS5
 dSEC7  = dIS6
 dSEC8  = dIS7
 dSEC9  = dIS8
 dSEC10  = dIS9
 dSEC11  = dIS10
 dSEC12  = dIS11
 dSEC13  = dIS12
 dSEC14  = dIS13
 dSEC15  = dIS14
 dSEC16  = dIS15
 dSEC17   =  dIS1 *IS1 + IS1 *dIS1
 dSEC18   =  dIS1 *IS2 + IS1 *dIS2
 dSEC19   =  dIS2 *IS2 + IS2 *dIS2
 dSEC20  = dIS16
 dSEC21  = dIS17
 dSEC22  = dIS18
 dSEC23  = dIS19
 dSEC24  = dIS20
 dSEC25  = dIS21
 dSEC26  = dIS22
 dSEC27  = dIS23
 dSEC28  = dIS24
 dSEC29  = dIS25
 dSEC30  = dIS26
 dSEC31  = dIS27
 dSEC32   =  dIS1 *IS3 + IS1 *dIS3
 dSEC33   =  dIS2 *IS3 + IS2 *dIS3
 dSEC34   =  dIS1 *IS4 + IS1 *dIS4
 dSEC35   =  dIS2 *IS4 + IS2 *dIS4
 dSEC36   =  dIS1 *IS5 + IS1 *dIS5
 dSEC37   =  dIS2 *IS5 + IS2 *dIS5
 dSEC38   =  dIS1 *IS6 + IS1 *dIS6
 dSEC39   =  dIS2 *IS6 + IS2 *dIS6
 dSEC40   =  dIS1 *IS7 + IS1 *dIS7
 dSEC41   =  dIS2 *IS7 + IS2 *dIS7
 dSEC42  = dIS28
 dSEC43  = dIS29
 dSEC44  = dIS30
 dSEC45  = dIS31
 dSEC46  = dIS32
 dSEC47  = dIS33
 dSEC48  = dIS34
 dSEC49  = dIS35
 dSEC50  = dIS36
 dSEC51  = dIS37
 dSEC52  = dIS38
 dSEC53  = dIS39
 dSEC54  = dIS40
 dSEC55   =  dIS4 *IS4 + IS4 *dIS4
 dSEC56   =  dIS3 *IS5 + IS3 *dIS5
 dSEC57   =  dIS4 *IS5 + IS4 *dIS5
 dSEC58   =  dIS5 *IS5 + IS5 *dIS5
 dSEC59   =  dIS3 *IS6 + IS3 *dIS6
 dSEC60   =  dIS4 *IS6 + IS4 *dIS6
 dSEC61   =  dIS5 *IS6 + IS5 *dIS6
 dSEC62   =  dIS6 *IS6 + IS6 *dIS6
 dSEC63   =  dIS3 *IS7 + IS3 *dIS7
 dSEC64   =  dIS4 *IS7 + IS4 *dIS7
 dSEC65   =  dIS5 *IS7 + IS5 *dIS7
 dSEC66   =  dIS6 *IS7 + IS6 *dIS7
 dSEC67   =  dIS7 *IS7 + IS7 *dIS7
 dSEC68   =  dIS1 *IS8 + IS1 *dIS8
 dSEC69   =  dIS2 *IS8 + IS2 *dIS8
 dSEC70   =  dIS1 *IS9 + IS1 *dIS9
 dSEC71   =  dIS2 *IS9 + IS2 *dIS9
 dSEC72   =  dIS1 *IS10 + IS1 *dIS10
 dSEC73   =  dIS2 *IS10 + IS2 *dIS10
 dSEC74   =  dIS1 *IS11 + IS1 *dIS11
 dSEC75   =  dIS2 *IS11 + IS2 *dIS11
 dSEC76   =  dIS1 *IS12 + IS1 *dIS12
 dSEC77   =  dIS2 *IS12 + IS2 *dIS12
 dSEC78   =  dIS1 *IS13 + IS1 *dIS13
 dSEC79   =  dIS2 *IS13 + IS2 *dIS13
 dSEC80   =  dIS1 *IS14 + IS1 *dIS14
 dSEC81   =  dIS2 *IS14 + IS2 *dIS14
 dSEC82   =  dIS1 *IS15 + IS1 *dIS15
 dSEC83   =  dIS2 *IS15 + IS2 *dIS15
 dSEC84  = dIS41
 dSEC85  = dIS42
 dSEC86  = dIS43
 dSEC87  = dIS44
 dSEC88   =  dIS3 *IS12 + IS3 *dIS12
 dSEC89   =  dIS4 *IS12 + IS4 *dIS12
 dSEC90   =  dIS5 *IS12 + IS5 *dIS12
 dSEC91   =  dIS6 *IS12 + IS6 *dIS12
 dSEC92   =  dIS7 *IS12 + IS7 *dIS12
 dSEC93   =  dIS3 *IS13 + IS3 *dIS13
 dSEC94   =  dIS4 *IS13 + IS4 *dIS13
 dSEC95   =  dIS5 *IS13 + IS5 *dIS13
 dSEC96   =  dIS6 *IS13 + IS6 *dIS13
 dSEC97   =  dIS7 *IS13 + IS7 *dIS13
 dSEC98   =  dIS3 *IS14 + IS3 *dIS14
 dSEC99   =  dIS4 *IS14 + IS4 *dIS14
 dSEC100   =  dIS5 *IS14 + IS5 *dIS14
 dSEC101   =  dIS6 *IS14 + IS6 *dIS14
 dSEC102   =  dIS7 *IS14 + IS7 *dIS14
 dSEC103   =  dIS3 *IS15 + IS3 *dIS15
 dSEC104   =  dIS4 *IS15 + IS4 *dIS15
 dSEC105   =  dIS5 *IS15 + IS5 *dIS15
 dSEC106   =  dIS6 *IS15 + IS6 *dIS15
 dSEC107   =  dIS7 *IS15 + IS7 *dIS15
 dSEC108   =  dIS1 *IS16 + IS1 *dIS16
 dSEC109   =  dIS2 *IS16 + IS2 *dIS16
 dSEC110   =  dIS1 *IS17 + IS1 *dIS17
 dSEC111   =  dIS2 *IS17 + IS2 *dIS17
 dSEC112   =  dIS1 *IS18 + IS1 *dIS18
 dSEC113   =  dIS2 *IS18 + IS2 *dIS18
 dSEC114   =  dIS1 *IS19 + IS1 *dIS19
 dSEC115   =  dIS2 *IS19 + IS2 *dIS19
 dSEC116   =  dIS1 *IS20 + IS1 *dIS20
 dSEC117   =  dIS2 *IS20 + IS2 *dIS20
 dSEC118   =  dIS1 *IS21 + IS1 *dIS21
 dSEC119   =  dIS2 *IS21 + IS2 *dIS21
 dSEC120   =  dIS1 *IS22 + IS1 *dIS22
 dSEC121   =  dIS2 *IS22 + IS2 *dIS22
 dSEC122   =  dIS1 *IS23 + IS1 *dIS23
 dSEC123   =  dIS2 *IS23 + IS2 *dIS23
 dSEC124   =  dIS1 *IS24 + IS1 *dIS24
 dSEC125   =  dIS2 *IS24 + IS2 *dIS24
 dSEC126   =  dIS1 *IS25 + IS1 *dIS25
 dSEC127   =  dIS2 *IS25 + IS2 *dIS25
 dSEC128   =  dIS1 *IS26 + IS1 *dIS26
 dSEC129   =  dIS2 *IS26 + IS2 *dIS26
 dSEC130   =  dIS1 *IS27 + IS1 *dIS27
 dSEC131   =  dIS2 *IS27 + IS2 *dIS27
 dSEC132  = dIS45
 dSEC133  = dIS46
 dSEC134   =  dIS3 *IS21 + IS3 *dIS21
 dSEC135   =  dIS4 *IS21 + IS4 *dIS21
 dSEC136   =  dIS5 *IS21 + IS5 *dIS21
 dSEC137   =  dIS6 *IS21 + IS6 *dIS21
 dSEC138   =  dIS7 *IS21 + IS7 *dIS21
 dSEC139   =  dIS3 *IS22 + IS3 *dIS22
 dSEC140   =  dIS4 *IS22 + IS4 *dIS22
 dSEC141   =  dIS5 *IS22 + IS5 *dIS22
 dSEC142   =  dIS6 *IS22 + IS6 *dIS22
 dSEC143   =  dIS7 *IS22 + IS7 *dIS22
 dSEC144   =  dIS3 *IS23 + IS3 *dIS23
 dSEC145   =  dIS4 *IS23 + IS4 *dIS23
 dSEC146   =  dIS5 *IS23 + IS5 *dIS23
 dSEC147   =  dIS6 *IS23 + IS6 *dIS23
 dSEC148   =  dIS7 *IS23 + IS7 *dIS23
 dSEC149   =  dIS3 *IS24 + IS3 *dIS24
 dSEC150   =  dIS4 *IS24 + IS4 *dIS24
 dSEC151   =  dIS5 *IS24 + IS5 *dIS24
 dSEC152   =  dIS6 *IS24 + IS6 *dIS24
 dSEC153   =  dIS7 *IS24 + IS7 *dIS24
 dSEC154   =  dIS3 *IS25 + IS3 *dIS25
 dSEC155   =  dIS4 *IS25 + IS4 *dIS25
 dSEC156   =  dIS5 *IS25 + IS5 *dIS25
 dSEC157   =  dIS6 *IS25 + IS6 *dIS25
 dSEC158   =  dIS7 *IS25 + IS7 *dIS25
 dSEC159   =  dIS3 *IS26 + IS3 *dIS26
 dSEC160   =  dIS4 *IS26 + IS4 *dIS26
 dSEC161   =  dIS5 *IS26 + IS5 *dIS26
 dSEC162   =  dIS6 *IS26 + IS6 *dIS26
 dSEC163   =  dIS7 *IS26 + IS7 *dIS26
 dSEC164   =  dIS3 *IS27 + IS3 *dIS27
 dSEC165   =  dIS4 *IS27 + IS4 *dIS27
 dSEC166   =  dIS5 *IS27 + IS5 *dIS27
 dSEC167   =  dIS6 *IS27 + IS6 *dIS27
 dSEC168   =  dIS7 *IS27 + IS7 *dIS27
 dSEC169   =  dIS1 *IS28 + IS1 *dIS28
 dSEC170   =  dIS2 *IS28 + IS2 *dIS28
 dSEC171   =  dIS1 *IS29 + IS1 *dIS29
 dSEC172   =  dIS2 *IS29 + IS2 *dIS29
 dSEC173   =  dIS1 *IS30 + IS1 *dIS30
 dSEC174   =  dIS2 *IS30 + IS2 *dIS30
 dSEC175   =  dIS1 *IS31 + IS1 *dIS31
 dSEC176   =  dIS2 *IS31 + IS2 *dIS31
 dSEC177   =  dIS1 *IS32 + IS1 *dIS32
 dSEC178   =  dIS2 *IS32 + IS2 *dIS32
 dSEC179   =  dIS1 *IS33 + IS1 *dIS33
 dSEC180   =  dIS2 *IS33 + IS2 *dIS33
 dSEC181   =  dIS1 *IS34 + IS1 *dIS34
 dSEC182   =  dIS2 *IS34 + IS2 *dIS34
 dSEC183   =  dIS1 *IS35 + IS1 *dIS35
 dSEC184   =  dIS2 *IS35 + IS2 *dIS35
 dSEC185   =  dIS1 *IS36 + IS1 *dIS36
 dSEC186   =  dIS2 *IS36 + IS2 *dIS36
 dSEC187   =  dIS1 *IS37 + IS1 *dIS37
 dSEC188   =  dIS2 *IS37 + IS2 *dIS37
 dSEC189   =  dIS1 *IS38 + IS1 *dIS38
 dSEC190   =  dIS2 *IS38 + IS2 *dIS38
 dSEC191   =  dIS1 *IS39 + IS1 *dIS39
 dSEC192   =  dIS2 *IS39 + IS2 *dIS39
 dSEC193   =  dIS1 *IS40 + IS1 *dIS40
 dSEC194   =  dIS2 *IS40 + IS2 *dIS40
 dSEC195   =  dIS4 *IS28 + IS4 *dIS28
 dSEC196   =  dIS5 *IS28 + IS5 *dIS28
 dSEC197   =  dIS6 *IS28 + IS6 *dIS28
 dSEC198   =  dIS7 *IS28 + IS7 *dIS28
 dSEC199   =  dIS3 *IS29 + IS3 *dIS29
 dSEC200   =  dIS4 *IS29 + IS4 *dIS29
 dSEC201   =  dIS5 *IS29 + IS5 *dIS29
 dSEC202   =  dIS6 *IS29 + IS6 *dIS29
 dSEC203   =  dIS7 *IS29 + IS7 *dIS29
 dSEC204   =  dIS3 *IS30 + IS3 *dIS30
 dSEC205   =  dIS4 *IS30 + IS4 *dIS30
 dSEC206   =  dIS5 *IS30 + IS5 *dIS30
 dSEC207   =  dIS6 *IS30 + IS6 *dIS30
 dSEC208   =  dIS7 *IS30 + IS7 *dIS30
 dSEC209   =  dIS3 *IS31 + IS3 *dIS31
 dSEC210   =  dIS4 *IS31 + IS4 *dIS31
 dSEC211   =  dIS5 *IS31 + IS5 *dIS31
 dSEC212   =  dIS6 *IS31 + IS6 *dIS31
 dSEC213   =  dIS7 *IS31 + IS7 *dIS31
 dSEC214   =  dIS3 *IS32 + IS3 *dIS32
 dSEC215   =  dIS4 *IS32 + IS4 *dIS32
 dSEC216   =  dIS5 *IS32 + IS5 *dIS32
 dSEC217   =  dIS6 *IS32 + IS6 *dIS32
 dSEC218   =  dIS7 *IS32 + IS7 *dIS32
 dSEC219   =  dIS3 *IS33 + IS3 *dIS33
 dSEC220   =  dIS4 *IS33 + IS4 *dIS33
 dSEC221   =  dIS5 *IS33 + IS5 *dIS33
 dSEC222   =  dIS6 *IS33 + IS6 *dIS33
 dSEC223   =  dIS7 *IS33 + IS7 *dIS33
 dSEC224   =  dIS3 *IS34 + IS3 *dIS34
 dSEC225   =  dIS4 *IS34 + IS4 *dIS34
 dSEC226   =  dIS5 *IS34 + IS5 *dIS34
 dSEC227   =  dIS6 *IS34 + IS6 *dIS34
 dSEC228   =  dIS7 *IS34 + IS7 *dIS34
 dSEC229   =  dIS3 *IS35 + IS3 *dIS35
 dSEC230   =  dIS4 *IS35 + IS4 *dIS35
 dSEC231   =  dIS5 *IS35 + IS5 *dIS35
 dSEC232   =  dIS6 *IS35 + IS6 *dIS35
 dSEC233   =  dIS7 *IS35 + IS7 *dIS35
 dSEC234   =  dIS3 *IS36 + IS3 *dIS36
 dSEC235   =  dIS4 *IS36 + IS4 *dIS36
 dSEC236   =  dIS5 *IS36 + IS5 *dIS36
 dSEC237   =  dIS6 *IS36 + IS6 *dIS36
 dSEC238   =  dIS7 *IS36 + IS7 *dIS36
 dSEC239   =  dIS3 *IS37 + IS3 *dIS37
 dSEC240   =  dIS4 *IS37 + IS4 *dIS37
 dSEC241   =  dIS5 *IS37 + IS5 *dIS37
 dSEC242   =  dIS6 *IS37 + IS6 *dIS37
 dSEC243   =  dIS7 *IS37 + IS7 *dIS37
 dSEC244   =  dIS3 *IS38 + IS3 *dIS38
 dSEC245   =  dIS4 *IS38 + IS4 *dIS38
 dSEC246   =  dIS5 *IS38 + IS5 *dIS38
 dSEC247   =  dIS6 *IS38 + IS6 *dIS38
 dSEC248   =  dIS7 *IS38 + IS7 *dIS38
 dSEC249   =  dIS3 *IS39 + IS3 *dIS39
 dSEC250   =  dIS4 *IS39 + IS4 *dIS39
 dSEC251   =  dIS5 *IS39 + IS5 *dIS39
 dSEC252   =  dIS6 *IS39 + IS6 *dIS39
 dSEC253   =  dIS7 *IS39 + IS7 *dIS39
 dSEC254   =  dIS3 *IS40 + IS3 *dIS40
 dSEC255   =  dIS4 *IS40 + IS4 *dIS40
 dSEC256   =  dIS5 *IS40 + IS5 *dIS40
 dSEC257   =  dIS6 *IS40 + IS6 *dIS40
 dSEC258   =  dIS7 *IS40 + IS7 *dIS40
 dSEC259   =  dIS1 *IS41 + IS1 *dIS41
 dSEC260   =  dIS2 *IS41 + IS2 *dIS41
 dSEC261   =  dIS1 *IS42 + IS1 *dIS42
 dSEC262   =  dIS2 *IS42 + IS2 *dIS42
 dSEC263   =  dIS1 *IS43 + IS1 *dIS43
 dSEC264   =  dIS2 *IS43 + IS2 *dIS43
 dSEC265   =  dIS1 *IS44 + IS1 *dIS44
 dSEC266   =  dIS2 *IS44 + IS2 *dIS44

return (dP1,dP2,dP3,dP4,dP5,dP6,dP7,dP8,dP9,dP10,), (dSEC1,dSEC2,dSEC3,dSEC4,dSEC5,dSEC6,dSEC7,dSEC8,dSEC9,dSEC10,dSEC11,dSEC12,dSEC13,dSEC14,dSEC15,dSEC16,dSEC17,dSEC18,dSEC19,dSEC20,dSEC21,dSEC22,dSEC23,dSEC24,dSEC25,dSEC26,dSEC27,dSEC28,dSEC29,dSEC30,dSEC31,dSEC32,dSEC33,dSEC34,dSEC35,dSEC36,dSEC37,dSEC38,dSEC39,dSEC40,dSEC41,dSEC42,dSEC43,dSEC44,dSEC45,dSEC46,dSEC47,dSEC48,dSEC49,dSEC50,dSEC51,dSEC52,dSEC53,dSEC54,dSEC55,dSEC56,dSEC57,dSEC58,dSEC59,dSEC60,dSEC61,dSEC62,dSEC63,dSEC64,dSEC65,dSEC66,dSEC67,dSEC68,dSEC69,dSEC70,dSEC71,dSEC72,dSEC73,dSEC74,dSEC75,dSEC76,dSEC77,dSEC78,dSEC79,dSEC80,dSEC81,dSEC82,dSEC83,dSEC84,dSEC85,dSEC86,dSEC87,dSEC88,dSEC89,dSEC90,dSEC91,dSEC92,dSEC93,dSEC94,dSEC95,dSEC96,dSEC97,dSEC98,dSEC99,dSEC100,dSEC101,dSEC102,dSEC103,dSEC104,dSEC105,dSEC106,dSEC107,dSEC108,dSEC109,dSEC110,dSEC111,dSEC112,dSEC113,dSEC114,dSEC115,dSEC116,dSEC117,dSEC118,dSEC119,dSEC120,dSEC121,dSEC122,dSEC123,dSEC124,dSEC125,dSEC126,dSEC127,dSEC128,dSEC129,dSEC130,dSEC131,dSEC132,dSEC133,dSEC134,dSEC135,dSEC136,dSEC137,dSEC138,dSEC139,dSEC140,dSEC141,dSEC142,dSEC143,dSEC144,dSEC145,dSEC146,dSEC147,dSEC148,dSEC149,dSEC150,dSEC151,dSEC152,dSEC153,dSEC154,dSEC155,dSEC156,dSEC157,dSEC158,dSEC159,dSEC160,dSEC161,dSEC162,dSEC163,dSEC164,dSEC165,dSEC166,dSEC167,dSEC168,dSEC169,dSEC170,dSEC171,dSEC172,dSEC173,dSEC174,dSEC175,dSEC176,dSEC177,dSEC178,dSEC179,dSEC180,dSEC181,dSEC182,dSEC183,dSEC184,dSEC185,dSEC186,dSEC187,dSEC188,dSEC189,dSEC190,dSEC191,dSEC192,dSEC193,dSEC194,dSEC195,dSEC196,dSEC197,dSEC198,dSEC199,dSEC200,dSEC201,dSEC202,dSEC203,dSEC204,dSEC205,dSEC206,dSEC207,dSEC208,dSEC209,dSEC210,dSEC211,dSEC212,dSEC213,dSEC214,dSEC215,dSEC216,dSEC217,dSEC218,dSEC219,dSEC220,dSEC221,dSEC222,dSEC223,dSEC224,dSEC225,dSEC226,dSEC227,dSEC228,dSEC229,dSEC230,dSEC231,dSEC232,dSEC233,dSEC234,dSEC235,dSEC236,dSEC237,dSEC238,dSEC239,dSEC240,dSEC241,dSEC242,dSEC243,dSEC244,dSEC245,dSEC246,dSEC247,dSEC248,dSEC249,dSEC250,dSEC251,dSEC252,dSEC253,dSEC254,dSEC255,dSEC256,dSEC257,dSEC258,dSEC259,dSEC260,dSEC261,dSEC262,dSEC263,dSEC264,dSEC265,dSEC266,)
 end

function invariants_ed_gen(x1::SVector{10, T}) where {T}
   x2 = x1.*x1
   x3 = x2.*x1
   x4 = x3.*x1
   x5 = x4.*x1
   x6 = x5.*x1
   x7 = x6.*x1
   x8 = x7.*x1
   x9 = x8.*x1

   dx1 = @SVector ones(10)
   dx2 = 2 * x1
   dx3 = 3 * x2
   dx4 = 4 * x3
   dx5 = 5 * x4
   dx6 = 6 * x5
   dx7 = 7 * x6
   dx8 = 8 * x7
   dx9 = 9 * x8
   #------------------------------------------------
   # Primaries
   #------------------------------------------------

# Primary invariants for NBody=5and deg=12
 # : what goes in the function for the evaluation and derivatives
P1, dP1 = fpoly_ed((x1,),(dx1,) , NB5I.P1)
P2, dP2 = fpoly_ed((x1,x1,),(dx1,dx1,) , NB5I.P2)
P3, dP3 = fpoly_ed((x2,),(dx2,) , NB5I.P3)
P4, dP4 = fpoly_ed((x1,x1,x1,),(dx1,dx1,dx1,) , NB5I.P4)
P5, dP5 = fpoly_ed((x3,),(dx3,) , NB5I.P5)
P6, dP6 = fpoly_ed((x1,x1,x1,x1,),(dx1,dx1,dx1,dx1,) , NB5I.P6)
P7, dP7 = fpoly_ed((x4,),(dx4,) , NB5I.P7)
P8, dP8 = fpoly_ed((x1,x1,x1,x1,x1,),(dx1,dx1,dx1,dx1,dx1,) , NB5I.P8)
P9, dP9 = fpoly_ed((x5,),(dx5,) , NB5I.P9)
P10, dP10 = fpoly_ed((x6,),(dx6,) , NB5I.P10)

   #------------------------------------------------
   # Irreducible secondaries
   #------------------------------------------------

# Irreducible secondaries for NBody=5and deg=12
 # : what goes in the function for the evaluation and derivatives
IS1, dIS1 = fpoly_ed((x2,x1,),(dx2,dx1,) , NB5I.IS1)
IS2, dIS2 = fpoly_ed((x1,x1,x1,),(dx1,dx1,dx1,) , NB5I.IS2)
IS3, dIS3 = fpoly_ed((x3,x1,),(dx3,dx1,) , NB5I.IS3)
IS4, dIS4 = fpoly_ed((x2,x2,),(dx2,dx2,) , NB5I.IS4)
IS5, dIS5 = fpoly_ed((x2,x1,x1,),(dx2,dx1,dx1,) , NB5I.IS5)
IS6, dIS6 = fpoly_ed((x2,x1,x1,),(dx2,dx1,dx1,) , NB5I.IS6)
IS7, dIS7 = fpoly_ed((x2,x1,x1,),(dx2,dx1,dx1,) , NB5I.IS7)
IS8, dIS8 = fpoly_ed((x4,x1,),(dx4,dx1,) , NB5I.IS8)
IS9, dIS9 = fpoly_ed((x3,x2,),(dx3,dx2,) , NB5I.IS9)
IS10, dIS10 = fpoly_ed((x3,x1,x1,),(dx3,dx1,dx1,) , NB5I.IS10)
IS11, dIS11 = fpoly_ed((x2,x2,x1,),(dx2,dx2,dx1,) , NB5I.IS11)
IS12, dIS12 = fpoly_ed((x3,x1,x1,),(dx3,dx1,dx1,) , NB5I.IS12)
IS13, dIS13 = fpoly_ed((x2,x2,x1,),(dx2,dx2,dx1,) , NB5I.IS13)
IS14, dIS14 = fpoly_ed((x3,x1,x1,),(dx3,dx1,dx1,) , NB5I.IS14)
IS15, dIS15 = fpoly_ed((x2,x1,x1,x1,),(dx2,dx1,dx1,dx1,) , NB5I.IS15)
IS16, dIS16 = fpoly_ed((x5,x1,),(dx5,dx1,) , NB5I.IS16)
IS17, dIS17 = fpoly_ed((x4,x2,),(dx4,dx2,) , NB5I.IS17)
IS18, dIS18 = fpoly_ed((x3,x3,),(dx3,dx3,) , NB5I.IS18)
IS19, dIS19 = fpoly_ed((x4,x1,x1,),(dx4,dx1,dx1,) , NB5I.IS19)
IS20, dIS20 = fpoly_ed((x3,x2,x1,),(dx3,dx2,dx1,) , NB5I.IS20)
IS21, dIS21 = fpoly_ed((x2,x2,x2,),(dx2,dx2,dx2,) , NB5I.IS21)
IS22, dIS22 = fpoly_ed((x4,x1,x1,),(dx4,dx1,dx1,) , NB5I.IS22)
IS23, dIS23 = fpoly_ed((x3,x2,x1,),(dx3,dx2,dx1,) , NB5I.IS23)
IS24, dIS24 = fpoly_ed((x4,x1,x1,),(dx4,dx1,dx1,) , NB5I.IS24)
IS25, dIS25 = fpoly_ed((x3,x1,x1,x1,),(dx3,dx1,dx1,dx1,) , NB5I.IS25)
IS26, dIS26 = fpoly_ed((x2,x2,x1,x1,),(dx2,dx2,dx1,dx1,) , NB5I.IS26)
IS27, dIS27 = fpoly_ed((x3,x2,x1,),(dx3,dx2,dx1,) , NB5I.IS27)
IS28, dIS28 = fpoly_ed((x7,),(dx7,) , NB5I.IS28)
IS29, dIS29 = fpoly_ed((x6,x1,),(dx6,dx1,) , NB5I.IS29)
IS30, dIS30 = fpoly_ed((x5,x2,),(dx5,dx2,) , NB5I.IS30)
IS31, dIS31 = fpoly_ed((x4,x3,),(dx4,dx3,) , NB5I.IS31)
IS32, dIS32 = fpoly_ed((x5,x1,x1,),(dx5,dx1,dx1,) , NB5I.IS32)
IS33, dIS33 = fpoly_ed((x4,x2,x1,),(dx4,dx2,dx1,) , NB5I.IS33)
IS34, dIS34 = fpoly_ed((x3,x3,x1,),(dx3,dx3,dx1,) , NB5I.IS34)
IS35, dIS35 = fpoly_ed((x3,x2,x2,),(dx3,dx2,dx2,) , NB5I.IS35)
IS36, dIS36 = fpoly_ed((x5,x1,x1,),(dx5,dx1,dx1,) , NB5I.IS36)
IS37, dIS37 = fpoly_ed((x4,x2,x1,),(dx4,dx2,dx1,) , NB5I.IS37)
IS38, dIS38 = fpoly_ed((x3,x3,x1,),(dx3,dx3,dx1,) , NB5I.IS38)
IS39, dIS39 = fpoly_ed((x5,x1,x1,),(dx5,dx1,dx1,) , NB5I.IS39)
IS40, dIS40 = fpoly_ed((x4,x1,x1,x1,),(dx4,dx1,dx1,dx1,) , NB5I.IS40)
IS41, dIS41 = fpoly_ed((x8,),(dx8,) , NB5I.IS41)
IS42, dIS42 = fpoly_ed((x7,x1,),(dx7,dx1,) , NB5I.IS42)
IS43, dIS43 = fpoly_ed((x6,x2,),(dx6,dx2,) , NB5I.IS43)
IS44, dIS44 = fpoly_ed((x5,x3,),(dx5,dx3,) , NB5I.IS44)
IS45, dIS45 = fpoly_ed((x9,),(dx9,) , NB5I.IS45)
IS46, dIS46 = fpoly_ed((x8,x1,),(dx8,dx1,) , NB5I.IS46)

   #------------------------------------------------
   # All secondaries
   #------------------------------------------------

 SEC1  = 1
 SEC2  = IS1
 SEC3  = IS2
 SEC4  = IS3
 SEC5  = IS4
 SEC6  = IS5
 SEC7  = IS6
 SEC8  = IS7
 SEC9  = IS8
 SEC10  = IS9
 SEC11  = IS10
 SEC12  = IS11
 SEC13  = IS12
 SEC14  = IS13
 SEC15  = IS14
 SEC16  = IS15
 SEC17  = IS1 *IS1
 SEC18  = IS1 *IS2
 SEC19  = IS2 *IS2
 SEC20  = IS16
 SEC21  = IS17
 SEC22  = IS18
 SEC23  = IS19
 SEC24  = IS20
 SEC25  = IS21
 SEC26  = IS22
 SEC27  = IS23
 SEC28  = IS24
 SEC29  = IS25
 SEC30  = IS26
 SEC31  = IS27
 SEC32  = IS1 *IS3
 SEC33  = IS2 *IS3
 SEC34  = IS1 *IS4
 SEC35  = IS2 *IS4
 SEC36  = IS1 *IS5
 SEC37  = IS2 *IS5
 SEC38  = IS1 *IS6
 SEC39  = IS2 *IS6
 SEC40  = IS1 *IS7
 SEC41  = IS2 *IS7
 SEC42  = IS28
 SEC43  = IS29
 SEC44  = IS30
 SEC45  = IS31
 SEC46  = IS32
 SEC47  = IS33
 SEC48  = IS34
 SEC49  = IS35
 SEC50  = IS36
 SEC51  = IS37
 SEC52  = IS38
 SEC53  = IS39
 SEC54  = IS40
 SEC55  = IS4 *IS4
 SEC56  = IS3 *IS5
 SEC57  = IS4 *IS5
 SEC58  = IS5 *IS5
 SEC59  = IS3 *IS6
 SEC60  = IS4 *IS6
 SEC61  = IS5 *IS6
 SEC62  = IS6 *IS6
 SEC63  = IS3 *IS7
 SEC64  = IS4 *IS7
 SEC65  = IS5 *IS7
 SEC66  = IS6 *IS7
 SEC67  = IS7 *IS7
 SEC68  = IS1 *IS8
 SEC69  = IS2 *IS8
 SEC70  = IS1 *IS9
 SEC71  = IS2 *IS9
 SEC72  = IS1 *IS10
 SEC73  = IS2 *IS10
 SEC74  = IS1 *IS11
 SEC75  = IS2 *IS11
 SEC76  = IS1 *IS12
 SEC77  = IS2 *IS12
 SEC78  = IS1 *IS13
 SEC79  = IS2 *IS13
 SEC80  = IS1 *IS14
 SEC81  = IS2 *IS14
 SEC82  = IS1 *IS15
 SEC83  = IS2 *IS15
 SEC84  = IS41
 SEC85  = IS42
 SEC86  = IS43
 SEC87  = IS44
 SEC88  = IS3 *IS12
 SEC89  = IS4 *IS12
 SEC90  = IS5 *IS12
 SEC91  = IS6 *IS12
 SEC92  = IS7 *IS12
 SEC93  = IS3 *IS13
 SEC94  = IS4 *IS13
 SEC95  = IS5 *IS13
 SEC96  = IS6 *IS13
 SEC97  = IS7 *IS13
 SEC98  = IS3 *IS14
 SEC99  = IS4 *IS14
 SEC100  = IS5 *IS14
 SEC101  = IS6 *IS14
 SEC102  = IS7 *IS14
 SEC103  = IS3 *IS15
 SEC104  = IS4 *IS15
 SEC105  = IS5 *IS15
 SEC106  = IS6 *IS15
 SEC107  = IS7 *IS15
 SEC108  = IS1 *IS16
 SEC109  = IS2 *IS16
 SEC110  = IS1 *IS17
 SEC111  = IS2 *IS17
 SEC112  = IS1 *IS18
 SEC113  = IS2 *IS18
 SEC114  = IS1 *IS19
 SEC115  = IS2 *IS19
 SEC116  = IS1 *IS20
 SEC117  = IS2 *IS20
 SEC118  = IS1 *IS21
 SEC119  = IS2 *IS21
 SEC120  = IS1 *IS22
 SEC121  = IS2 *IS22
 SEC122  = IS1 *IS23
 SEC123  = IS2 *IS23
 SEC124  = IS1 *IS24
 SEC125  = IS2 *IS24
 SEC126  = IS1 *IS25
 SEC127  = IS2 *IS25
 SEC128  = IS1 *IS26
 SEC129  = IS2 *IS26
 SEC130  = IS1 *IS27
 SEC131  = IS2 *IS27
 SEC132  = IS45
 SEC133  = IS46
 SEC134  = IS3 *IS21
 SEC135  = IS4 *IS21
 SEC136  = IS5 *IS21
 SEC137  = IS6 *IS21
 SEC138  = IS7 *IS21
 SEC139  = IS3 *IS22
 SEC140  = IS4 *IS22
 SEC141  = IS5 *IS22
 SEC142  = IS6 *IS22
 SEC143  = IS7 *IS22
 SEC144  = IS3 *IS23
 SEC145  = IS4 *IS23
 SEC146  = IS5 *IS23
 SEC147  = IS6 *IS23
 SEC148  = IS7 *IS23
 SEC149  = IS3 *IS24
 SEC150  = IS4 *IS24
 SEC151  = IS5 *IS24
 SEC152  = IS6 *IS24
 SEC153  = IS7 *IS24
 SEC154  = IS3 *IS25
 SEC155  = IS4 *IS25
 SEC156  = IS5 *IS25
 SEC157  = IS6 *IS25
 SEC158  = IS7 *IS25
 SEC159  = IS3 *IS26
 SEC160  = IS4 *IS26
 SEC161  = IS5 *IS26
 SEC162  = IS6 *IS26
 SEC163  = IS7 *IS26
 SEC164  = IS3 *IS27
 SEC165  = IS4 *IS27
 SEC166  = IS5 *IS27
 SEC167  = IS6 *IS27
 SEC168  = IS7 *IS27
 SEC169  = IS1 *IS28
 SEC170  = IS2 *IS28
 SEC171  = IS1 *IS29
 SEC172  = IS2 *IS29
 SEC173  = IS1 *IS30
 SEC174  = IS2 *IS30
 SEC175  = IS1 *IS31
 SEC176  = IS2 *IS31
 SEC177  = IS1 *IS32
 SEC178  = IS2 *IS32
 SEC179  = IS1 *IS33
 SEC180  = IS2 *IS33
 SEC181  = IS1 *IS34
 SEC182  = IS2 *IS34
 SEC183  = IS1 *IS35
 SEC184  = IS2 *IS35
 SEC185  = IS1 *IS36
 SEC186  = IS2 *IS36
 SEC187  = IS1 *IS37
 SEC188  = IS2 *IS37
 SEC189  = IS1 *IS38
 SEC190  = IS2 *IS38
 SEC191  = IS1 *IS39
 SEC192  = IS2 *IS39
 SEC193  = IS1 *IS40
 SEC194  = IS2 *IS40
 SEC195  = IS4 *IS28
 SEC196  = IS5 *IS28
 SEC197  = IS6 *IS28
 SEC198  = IS7 *IS28
 SEC199  = IS3 *IS29
 SEC200  = IS4 *IS29
 SEC201  = IS5 *IS29
 SEC202  = IS6 *IS29
 SEC203  = IS7 *IS29
 SEC204  = IS3 *IS30
 SEC205  = IS4 *IS30
 SEC206  = IS5 *IS30
 SEC207  = IS6 *IS30
 SEC208  = IS7 *IS30
 SEC209  = IS3 *IS31
 SEC210  = IS4 *IS31
 SEC211  = IS5 *IS31
 SEC212  = IS6 *IS31
 SEC213  = IS7 *IS31
 SEC214  = IS3 *IS32
 SEC215  = IS4 *IS32
 SEC216  = IS5 *IS32
 SEC217  = IS6 *IS32
 SEC218  = IS7 *IS32
 SEC219  = IS3 *IS33
 SEC220  = IS4 *IS33
 SEC221  = IS5 *IS33
 SEC222  = IS6 *IS33
 SEC223  = IS7 *IS33
 SEC224  = IS3 *IS34
 SEC225  = IS4 *IS34
 SEC226  = IS5 *IS34
 SEC227  = IS6 *IS34
 SEC228  = IS7 *IS34
 SEC229  = IS3 *IS35
 SEC230  = IS4 *IS35
 SEC231  = IS5 *IS35
 SEC232  = IS6 *IS35
 SEC233  = IS7 *IS35
 SEC234  = IS3 *IS36
 SEC235  = IS4 *IS36
 SEC236  = IS5 *IS36
 SEC237  = IS6 *IS36
 SEC238  = IS7 *IS36
 SEC239  = IS3 *IS37
 SEC240  = IS4 *IS37
 SEC241  = IS5 *IS37
 SEC242  = IS6 *IS37
 SEC243  = IS7 *IS37
 SEC244  = IS3 *IS38
 SEC245  = IS4 *IS38
 SEC246  = IS5 *IS38
 SEC247  = IS6 *IS38
 SEC248  = IS7 *IS38
 SEC249  = IS3 *IS39
 SEC250  = IS4 *IS39
 SEC251  = IS5 *IS39
 SEC252  = IS6 *IS39
 SEC253  = IS7 *IS39
 SEC254  = IS3 *IS40
 SEC255  = IS4 *IS40
 SEC256  = IS5 *IS40
 SEC257  = IS6 *IS40
 SEC258  = IS7 *IS40
 SEC259  = IS1 *IS41
 SEC260  = IS2 *IS41
 SEC261  = IS1 *IS42
 SEC262  = IS2 *IS42
 SEC263  = IS1 *IS43
 SEC264  = IS2 *IS43
 SEC265  = IS1 *IS44
 SEC266  = IS2 *IS44

 dSEC1   = @SVector zeros(10)
 dSEC2  = dIS1
 dSEC3  = dIS2
 dSEC4  = dIS3
 dSEC5  = dIS4
 dSEC6  = dIS5
 dSEC7  = dIS6
 dSEC8  = dIS7
 dSEC9  = dIS8
 dSEC10  = dIS9
 dSEC11  = dIS10
 dSEC12  = dIS11
 dSEC13  = dIS12
 dSEC14  = dIS13
 dSEC15  = dIS14
 dSEC16  = dIS15
 dSEC17   =  dIS1 *IS1 + IS1 *dIS1
 dSEC18   =  dIS1 *IS2 + IS1 *dIS2
 dSEC19   =  dIS2 *IS2 + IS2 *dIS2
 dSEC20  = dIS16
 dSEC21  = dIS17
 dSEC22  = dIS18
 dSEC23  = dIS19
 dSEC24  = dIS20
 dSEC25  = dIS21
 dSEC26  = dIS22
 dSEC27  = dIS23
 dSEC28  = dIS24
 dSEC29  = dIS25
 dSEC30  = dIS26
 dSEC31  = dIS27
 dSEC32   =  dIS1 *IS3 + IS1 *dIS3
 dSEC33   =  dIS2 *IS3 + IS2 *dIS3
 dSEC34   =  dIS1 *IS4 + IS1 *dIS4
 dSEC35   =  dIS2 *IS4 + IS2 *dIS4
 dSEC36   =  dIS1 *IS5 + IS1 *dIS5
 dSEC37   =  dIS2 *IS5 + IS2 *dIS5
 dSEC38   =  dIS1 *IS6 + IS1 *dIS6
 dSEC39   =  dIS2 *IS6 + IS2 *dIS6
 dSEC40   =  dIS1 *IS7 + IS1 *dIS7
 dSEC41   =  dIS2 *IS7 + IS2 *dIS7
 dSEC42  = dIS28
 dSEC43  = dIS29
 dSEC44  = dIS30
 dSEC45  = dIS31
 dSEC46  = dIS32
 dSEC47  = dIS33
 dSEC48  = dIS34
 dSEC49  = dIS35
 dSEC50  = dIS36
 dSEC51  = dIS37
 dSEC52  = dIS38
 dSEC53  = dIS39
 dSEC54  = dIS40
 dSEC55   =  dIS4 *IS4 + IS4 *dIS4
 dSEC56   =  dIS3 *IS5 + IS3 *dIS5
 dSEC57   =  dIS4 *IS5 + IS4 *dIS5
 dSEC58   =  dIS5 *IS5 + IS5 *dIS5
 dSEC59   =  dIS3 *IS6 + IS3 *dIS6
 dSEC60   =  dIS4 *IS6 + IS4 *dIS6
 dSEC61   =  dIS5 *IS6 + IS5 *dIS6
 dSEC62   =  dIS6 *IS6 + IS6 *dIS6
 dSEC63   =  dIS3 *IS7 + IS3 *dIS7
 dSEC64   =  dIS4 *IS7 + IS4 *dIS7
 dSEC65   =  dIS5 *IS7 + IS5 *dIS7
 dSEC66   =  dIS6 *IS7 + IS6 *dIS7
 dSEC67   =  dIS7 *IS7 + IS7 *dIS7
 dSEC68   =  dIS1 *IS8 + IS1 *dIS8
 dSEC69   =  dIS2 *IS8 + IS2 *dIS8
 dSEC70   =  dIS1 *IS9 + IS1 *dIS9
 dSEC71   =  dIS2 *IS9 + IS2 *dIS9
 dSEC72   =  dIS1 *IS10 + IS1 *dIS10
 dSEC73   =  dIS2 *IS10 + IS2 *dIS10
 dSEC74   =  dIS1 *IS11 + IS1 *dIS11
 dSEC75   =  dIS2 *IS11 + IS2 *dIS11
 dSEC76   =  dIS1 *IS12 + IS1 *dIS12
 dSEC77   =  dIS2 *IS12 + IS2 *dIS12
 dSEC78   =  dIS1 *IS13 + IS1 *dIS13
 dSEC79   =  dIS2 *IS13 + IS2 *dIS13
 dSEC80   =  dIS1 *IS14 + IS1 *dIS14
 dSEC81   =  dIS2 *IS14 + IS2 *dIS14
 dSEC82   =  dIS1 *IS15 + IS1 *dIS15
 dSEC83   =  dIS2 *IS15 + IS2 *dIS15
 dSEC84  = dIS41
 dSEC85  = dIS42
 dSEC86  = dIS43
 dSEC87  = dIS44
 dSEC88   =  dIS3 *IS12 + IS3 *dIS12
 dSEC89   =  dIS4 *IS12 + IS4 *dIS12
 dSEC90   =  dIS5 *IS12 + IS5 *dIS12
 dSEC91   =  dIS6 *IS12 + IS6 *dIS12
 dSEC92   =  dIS7 *IS12 + IS7 *dIS12
 dSEC93   =  dIS3 *IS13 + IS3 *dIS13
 dSEC94   =  dIS4 *IS13 + IS4 *dIS13
 dSEC95   =  dIS5 *IS13 + IS5 *dIS13
 dSEC96   =  dIS6 *IS13 + IS6 *dIS13
 dSEC97   =  dIS7 *IS13 + IS7 *dIS13
 dSEC98   =  dIS3 *IS14 + IS3 *dIS14
 dSEC99   =  dIS4 *IS14 + IS4 *dIS14
 dSEC100   =  dIS5 *IS14 + IS5 *dIS14
 dSEC101   =  dIS6 *IS14 + IS6 *dIS14
 dSEC102   =  dIS7 *IS14 + IS7 *dIS14
 dSEC103   =  dIS3 *IS15 + IS3 *dIS15
 dSEC104   =  dIS4 *IS15 + IS4 *dIS15
 dSEC105   =  dIS5 *IS15 + IS5 *dIS15
 dSEC106   =  dIS6 *IS15 + IS6 *dIS15
 dSEC107   =  dIS7 *IS15 + IS7 *dIS15
 dSEC108   =  dIS1 *IS16 + IS1 *dIS16
 dSEC109   =  dIS2 *IS16 + IS2 *dIS16
 dSEC110   =  dIS1 *IS17 + IS1 *dIS17
 dSEC111   =  dIS2 *IS17 + IS2 *dIS17
 dSEC112   =  dIS1 *IS18 + IS1 *dIS18
 dSEC113   =  dIS2 *IS18 + IS2 *dIS18
 dSEC114   =  dIS1 *IS19 + IS1 *dIS19
 dSEC115   =  dIS2 *IS19 + IS2 *dIS19
 dSEC116   =  dIS1 *IS20 + IS1 *dIS20
 dSEC117   =  dIS2 *IS20 + IS2 *dIS20
 dSEC118   =  dIS1 *IS21 + IS1 *dIS21
 dSEC119   =  dIS2 *IS21 + IS2 *dIS21
 dSEC120   =  dIS1 *IS22 + IS1 *dIS22
 dSEC121   =  dIS2 *IS22 + IS2 *dIS22
 dSEC122   =  dIS1 *IS23 + IS1 *dIS23
 dSEC123   =  dIS2 *IS23 + IS2 *dIS23
 dSEC124   =  dIS1 *IS24 + IS1 *dIS24
 dSEC125   =  dIS2 *IS24 + IS2 *dIS24
 dSEC126   =  dIS1 *IS25 + IS1 *dIS25
 dSEC127   =  dIS2 *IS25 + IS2 *dIS25
 dSEC128   =  dIS1 *IS26 + IS1 *dIS26
 dSEC129   =  dIS2 *IS26 + IS2 *dIS26
 dSEC130   =  dIS1 *IS27 + IS1 *dIS27
 dSEC131   =  dIS2 *IS27 + IS2 *dIS27
 dSEC132  = dIS45
 dSEC133  = dIS46
 dSEC134   =  dIS3 *IS21 + IS3 *dIS21
 dSEC135   =  dIS4 *IS21 + IS4 *dIS21
 dSEC136   =  dIS5 *IS21 + IS5 *dIS21
 dSEC137   =  dIS6 *IS21 + IS6 *dIS21
 dSEC138   =  dIS7 *IS21 + IS7 *dIS21
 dSEC139   =  dIS3 *IS22 + IS3 *dIS22
 dSEC140   =  dIS4 *IS22 + IS4 *dIS22
 dSEC141   =  dIS5 *IS22 + IS5 *dIS22
 dSEC142   =  dIS6 *IS22 + IS6 *dIS22
 dSEC143   =  dIS7 *IS22 + IS7 *dIS22
 dSEC144   =  dIS3 *IS23 + IS3 *dIS23
 dSEC145   =  dIS4 *IS23 + IS4 *dIS23
 dSEC146   =  dIS5 *IS23 + IS5 *dIS23
 dSEC147   =  dIS6 *IS23 + IS6 *dIS23
 dSEC148   =  dIS7 *IS23 + IS7 *dIS23
 dSEC149   =  dIS3 *IS24 + IS3 *dIS24
 dSEC150   =  dIS4 *IS24 + IS4 *dIS24
 dSEC151   =  dIS5 *IS24 + IS5 *dIS24
 dSEC152   =  dIS6 *IS24 + IS6 *dIS24
 dSEC153   =  dIS7 *IS24 + IS7 *dIS24
 dSEC154   =  dIS3 *IS25 + IS3 *dIS25
 dSEC155   =  dIS4 *IS25 + IS4 *dIS25
 dSEC156   =  dIS5 *IS25 + IS5 *dIS25
 dSEC157   =  dIS6 *IS25 + IS6 *dIS25
 dSEC158   =  dIS7 *IS25 + IS7 *dIS25
 dSEC159   =  dIS3 *IS26 + IS3 *dIS26
 dSEC160   =  dIS4 *IS26 + IS4 *dIS26
 dSEC161   =  dIS5 *IS26 + IS5 *dIS26
 dSEC162   =  dIS6 *IS26 + IS6 *dIS26
 dSEC163   =  dIS7 *IS26 + IS7 *dIS26
 dSEC164   =  dIS3 *IS27 + IS3 *dIS27
 dSEC165   =  dIS4 *IS27 + IS4 *dIS27
 dSEC166   =  dIS5 *IS27 + IS5 *dIS27
 dSEC167   =  dIS6 *IS27 + IS6 *dIS27
 dSEC168   =  dIS7 *IS27 + IS7 *dIS27
 dSEC169   =  dIS1 *IS28 + IS1 *dIS28
 dSEC170   =  dIS2 *IS28 + IS2 *dIS28
 dSEC171   =  dIS1 *IS29 + IS1 *dIS29
 dSEC172   =  dIS2 *IS29 + IS2 *dIS29
 dSEC173   =  dIS1 *IS30 + IS1 *dIS30
 dSEC174   =  dIS2 *IS30 + IS2 *dIS30
 dSEC175   =  dIS1 *IS31 + IS1 *dIS31
 dSEC176   =  dIS2 *IS31 + IS2 *dIS31
 dSEC177   =  dIS1 *IS32 + IS1 *dIS32
 dSEC178   =  dIS2 *IS32 + IS2 *dIS32
 dSEC179   =  dIS1 *IS33 + IS1 *dIS33
 dSEC180   =  dIS2 *IS33 + IS2 *dIS33
 dSEC181   =  dIS1 *IS34 + IS1 *dIS34
 dSEC182   =  dIS2 *IS34 + IS2 *dIS34
 dSEC183   =  dIS1 *IS35 + IS1 *dIS35
 dSEC184   =  dIS2 *IS35 + IS2 *dIS35
 dSEC185   =  dIS1 *IS36 + IS1 *dIS36
 dSEC186   =  dIS2 *IS36 + IS2 *dIS36
 dSEC187   =  dIS1 *IS37 + IS1 *dIS37
 dSEC188   =  dIS2 *IS37 + IS2 *dIS37
 dSEC189   =  dIS1 *IS38 + IS1 *dIS38
 dSEC190   =  dIS2 *IS38 + IS2 *dIS38
 dSEC191   =  dIS1 *IS39 + IS1 *dIS39
 dSEC192   =  dIS2 *IS39 + IS2 *dIS39
 dSEC193   =  dIS1 *IS40 + IS1 *dIS40
 dSEC194   =  dIS2 *IS40 + IS2 *dIS40
 dSEC195   =  dIS4 *IS28 + IS4 *dIS28
 dSEC196   =  dIS5 *IS28 + IS5 *dIS28
 dSEC197   =  dIS6 *IS28 + IS6 *dIS28
 dSEC198   =  dIS7 *IS28 + IS7 *dIS28
 dSEC199   =  dIS3 *IS29 + IS3 *dIS29
 dSEC200   =  dIS4 *IS29 + IS4 *dIS29
 dSEC201   =  dIS5 *IS29 + IS5 *dIS29
 dSEC202   =  dIS6 *IS29 + IS6 *dIS29
 dSEC203   =  dIS7 *IS29 + IS7 *dIS29
 dSEC204   =  dIS3 *IS30 + IS3 *dIS30
 dSEC205   =  dIS4 *IS30 + IS4 *dIS30
 dSEC206   =  dIS5 *IS30 + IS5 *dIS30
 dSEC207   =  dIS6 *IS30 + IS6 *dIS30
 dSEC208   =  dIS7 *IS30 + IS7 *dIS30
 dSEC209   =  dIS3 *IS31 + IS3 *dIS31
 dSEC210   =  dIS4 *IS31 + IS4 *dIS31
 dSEC211   =  dIS5 *IS31 + IS5 *dIS31
 dSEC212   =  dIS6 *IS31 + IS6 *dIS31
 dSEC213   =  dIS7 *IS31 + IS7 *dIS31
 dSEC214   =  dIS3 *IS32 + IS3 *dIS32
 dSEC215   =  dIS4 *IS32 + IS4 *dIS32
 dSEC216   =  dIS5 *IS32 + IS5 *dIS32
 dSEC217   =  dIS6 *IS32 + IS6 *dIS32
 dSEC218   =  dIS7 *IS32 + IS7 *dIS32
 dSEC219   =  dIS3 *IS33 + IS3 *dIS33
 dSEC220   =  dIS4 *IS33 + IS4 *dIS33
 dSEC221   =  dIS5 *IS33 + IS5 *dIS33
 dSEC222   =  dIS6 *IS33 + IS6 *dIS33
 dSEC223   =  dIS7 *IS33 + IS7 *dIS33
 dSEC224   =  dIS3 *IS34 + IS3 *dIS34
 dSEC225   =  dIS4 *IS34 + IS4 *dIS34
 dSEC226   =  dIS5 *IS34 + IS5 *dIS34
 dSEC227   =  dIS6 *IS34 + IS6 *dIS34
 dSEC228   =  dIS7 *IS34 + IS7 *dIS34
 dSEC229   =  dIS3 *IS35 + IS3 *dIS35
 dSEC230   =  dIS4 *IS35 + IS4 *dIS35
 dSEC231   =  dIS5 *IS35 + IS5 *dIS35
 dSEC232   =  dIS6 *IS35 + IS6 *dIS35
 dSEC233   =  dIS7 *IS35 + IS7 *dIS35
 dSEC234   =  dIS3 *IS36 + IS3 *dIS36
 dSEC235   =  dIS4 *IS36 + IS4 *dIS36
 dSEC236   =  dIS5 *IS36 + IS5 *dIS36
 dSEC237   =  dIS6 *IS36 + IS6 *dIS36
 dSEC238   =  dIS7 *IS36 + IS7 *dIS36
 dSEC239   =  dIS3 *IS37 + IS3 *dIS37
 dSEC240   =  dIS4 *IS37 + IS4 *dIS37
 dSEC241   =  dIS5 *IS37 + IS5 *dIS37
 dSEC242   =  dIS6 *IS37 + IS6 *dIS37
 dSEC243   =  dIS7 *IS37 + IS7 *dIS37
 dSEC244   =  dIS3 *IS38 + IS3 *dIS38
 dSEC245   =  dIS4 *IS38 + IS4 *dIS38
 dSEC246   =  dIS5 *IS38 + IS5 *dIS38
 dSEC247   =  dIS6 *IS38 + IS6 *dIS38
 dSEC248   =  dIS7 *IS38 + IS7 *dIS38
 dSEC249   =  dIS3 *IS39 + IS3 *dIS39
 dSEC250   =  dIS4 *IS39 + IS4 *dIS39
 dSEC251   =  dIS5 *IS39 + IS5 *dIS39
 dSEC252   =  dIS6 *IS39 + IS6 *dIS39
 dSEC253   =  dIS7 *IS39 + IS7 *dIS39
 dSEC254   =  dIS3 *IS40 + IS3 *dIS40
 dSEC255   =  dIS4 *IS40 + IS4 *dIS40
 dSEC256   =  dIS5 *IS40 + IS5 *dIS40
 dSEC257   =  dIS6 *IS40 + IS6 *dIS40
 dSEC258   =  dIS7 *IS40 + IS7 *dIS40
 dSEC259   =  dIS1 *IS41 + IS1 *dIS41
 dSEC260   =  dIS2 *IS41 + IS2 *dIS41
 dSEC261   =  dIS1 *IS42 + IS1 *dIS42
 dSEC262   =  dIS2 *IS42 + IS2 *dIS42
 dSEC263   =  dIS1 *IS43 + IS1 *dIS43
 dSEC264   =  dIS2 *IS43 + IS2 *dIS43
 dSEC265   =  dIS1 *IS44 + IS1 *dIS44
 dSEC266   =  dIS2 *IS44 + IS2 *dIS44

return (@SVector [P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,]), (@SVector [SEC1,SEC2,SEC3,SEC4,SEC5,SEC6,SEC7,SEC8,SEC9,SEC10,SEC11,SEC12,SEC13,SEC14,SEC15,SEC16,SEC17,SEC18,SEC19,SEC20,SEC21,SEC22,SEC23,SEC24,SEC25,SEC26,SEC27,SEC28,SEC29,SEC30,SEC31,SEC32,SEC33,SEC34,SEC35,SEC36,SEC37,SEC38,SEC39,SEC40,SEC41,SEC42,SEC43,SEC44,SEC45,SEC46,SEC47,SEC48,SEC49,SEC50,SEC51,SEC52,SEC53,SEC54,SEC55,SEC56,SEC57,SEC58,SEC59,SEC60,SEC61,SEC62,SEC63,SEC64,SEC65,SEC66,SEC67,SEC68,SEC69,SEC70,SEC71,SEC72,SEC73,SEC74,SEC75,SEC76,SEC77,SEC78,SEC79,SEC80,SEC81,SEC82,SEC83,SEC84,SEC85,SEC86,SEC87,SEC88,SEC89,SEC90,SEC91,SEC92,SEC93,SEC94,SEC95,SEC96,SEC97,SEC98,SEC99,SEC100,SEC101,SEC102,SEC103,SEC104,SEC105,SEC106,SEC107,SEC108,SEC109,SEC110,SEC111,SEC112,SEC113,SEC114,SEC115,SEC116,SEC117,SEC118,SEC119,SEC120,SEC121,SEC122,SEC123,SEC124,SEC125,SEC126,SEC127,SEC128,SEC129,SEC130,SEC131,SEC132,SEC133,SEC134,SEC135,SEC136,SEC137,SEC138,SEC139,SEC140,SEC141,SEC142,SEC143,SEC144,SEC145,SEC146,SEC147,SEC148,SEC149,SEC150,SEC151,SEC152,SEC153,SEC154,SEC155,SEC156,SEC157,SEC158,SEC159,SEC160,SEC161,SEC162,SEC163,SEC164,SEC165,SEC166,SEC167,SEC168,SEC169,SEC170,SEC171,SEC172,SEC173,SEC174,SEC175,SEC176,SEC177,SEC178,SEC179,SEC180,SEC181,SEC182,SEC183,SEC184,SEC185,SEC186,SEC187,SEC188,SEC189,SEC190,SEC191,SEC192,SEC193,SEC194,SEC195,SEC196,SEC197,SEC198,SEC199,SEC200,SEC201,SEC202,SEC203,SEC204,SEC205,SEC206,SEC207,SEC208,SEC209,SEC210,SEC211,SEC212,SEC213,SEC214,SEC215,SEC216,SEC217,SEC218,SEC219,SEC220,SEC221,SEC222,SEC223,SEC224,SEC225,SEC226,SEC227,SEC228,SEC229,SEC230,SEC231,SEC232,SEC233,SEC234,SEC235,SEC236,SEC237,SEC238,SEC239,SEC240,SEC241,SEC242,SEC243,SEC244,SEC245,SEC246,SEC247,SEC248,SEC249,SEC250,SEC251,SEC252,SEC253,SEC254,SEC255,SEC256,SEC257,SEC258,SEC259,SEC260,SEC261,SEC262,SEC263,SEC264,SEC265,SEC266,]), (@SVector [dP1,dP2,dP3,dP4,dP5,dP6,dP7,dP8,dP9,dP10,]), (@SVector [dSEC1,dSEC2,dSEC3,dSEC4,dSEC5,dSEC6,dSEC7,dSEC8,dSEC9,dSEC10,dSEC11,dSEC12,dSEC13,dSEC14,dSEC15,dSEC16,dSEC17,dSEC18,dSEC19,dSEC20,dSEC21,dSEC22,dSEC23,dSEC24,dSEC25,dSEC26,dSEC27,dSEC28,dSEC29,dSEC30,dSEC31,dSEC32,dSEC33,dSEC34,dSEC35,dSEC36,dSEC37,dSEC38,dSEC39,dSEC40,dSEC41,dSEC42,dSEC43,dSEC44,dSEC45,dSEC46,dSEC47,dSEC48,dSEC49,dSEC50,dSEC51,dSEC52,dSEC53,dSEC54,dSEC55,dSEC56,dSEC57,dSEC58,dSEC59,dSEC60,dSEC61,dSEC62,dSEC63,dSEC64,dSEC65,dSEC66,dSEC67,dSEC68,dSEC69,dSEC70,dSEC71,dSEC72,dSEC73,dSEC74,dSEC75,dSEC76,dSEC77,dSEC78,dSEC79,dSEC80,dSEC81,dSEC82,dSEC83,dSEC84,dSEC85,dSEC86,dSEC87,dSEC88,dSEC89,dSEC90,dSEC91,dSEC92,dSEC93,dSEC94,dSEC95,dSEC96,dSEC97,dSEC98,dSEC99,dSEC100,dSEC101,dSEC102,dSEC103,dSEC104,dSEC105,dSEC106,dSEC107,dSEC108,dSEC109,dSEC110,dSEC111,dSEC112,dSEC113,dSEC114,dSEC115,dSEC116,dSEC117,dSEC118,dSEC119,dSEC120,dSEC121,dSEC122,dSEC123,dSEC124,dSEC125,dSEC126,dSEC127,dSEC128,dSEC129,dSEC130,dSEC131,dSEC132,dSEC133,dSEC134,dSEC135,dSEC136,dSEC137,dSEC138,dSEC139,dSEC140,dSEC141,dSEC142,dSEC143,dSEC144,dSEC145,dSEC146,dSEC147,dSEC148,dSEC149,dSEC150,dSEC151,dSEC152,dSEC153,dSEC154,dSEC155,dSEC156,dSEC157,dSEC158,dSEC159,dSEC160,dSEC161,dSEC162,dSEC163,dSEC164,dSEC165,dSEC166,dSEC167,dSEC168,dSEC169,dSEC170,dSEC171,dSEC172,dSEC173,dSEC174,dSEC175,dSEC176,dSEC177,dSEC178,dSEC179,dSEC180,dSEC181,dSEC182,dSEC183,dSEC184,dSEC185,dSEC186,dSEC187,dSEC188,dSEC189,dSEC190,dSEC191,dSEC192,dSEC193,dSEC194,dSEC195,dSEC196,dSEC197,dSEC198,dSEC199,dSEC200,dSEC201,dSEC202,dSEC203,dSEC204,dSEC205,dSEC206,dSEC207,dSEC208,dSEC209,dSEC210,dSEC211,dSEC212,dSEC213,dSEC214,dSEC215,dSEC216,dSEC217,dSEC218,dSEC219,dSEC220,dSEC221,dSEC222,dSEC223,dSEC224,dSEC225,dSEC226,dSEC227,dSEC228,dSEC229,dSEC230,dSEC231,dSEC232,dSEC233,dSEC234,dSEC235,dSEC236,dSEC237,dSEC238,dSEC239,dSEC240,dSEC241,dSEC242,dSEC243,dSEC244,dSEC245,dSEC246,dSEC247,dSEC248,dSEC249,dSEC250,dSEC251,dSEC252,dSEC253,dSEC254,dSEC255,dSEC256,dSEC257,dSEC258,dSEC259,dSEC260,dSEC261,dSEC262,dSEC263,dSEC264,dSEC265,dSEC266,])
 end

end

max_stars_repo_name: cortner/ManyBodyIPs

max_issues_repo_name: cortner/ManyBodyIPs

max_forks_repo_name: cortner/ManyBodyIPs


text:
# Utils for modifying plot style variables

function PushStyleColor(idx, col::UInt32)
    return LibCImPlot.PushStyleColorU32(idx, col)
end

function PushStyleColor(idx, col::ImVec4)
    return LibCImPlot.PushStyleColorVec4(idx, col)
end

function PushStyleVar(idx, val::AbstractFloat)
    return LibCImPlot.PushStyleVarFloat(idx, Float32(val))
end

function PushStyleVar(idx, val::Integer)
    return LibCImPlot.PushStyleVarInt(idx, Cint(val))
end

function PopStyleColor(count::Integer=1)
    return LibCImPlot.PopStyleColor(count)
end

function PopStyleVar(count::Integer=1)
    return LibCImPlot.PopStyleVar(count)
end

ext: jl


text:
dependency_id_string(id::NamedTuple) = sorted_json(id)
dependency_id_string(id::String) = sorted_json(id)

function dependency_string(dep::Dependency{Trait, String}) where {Trait}
    return "$(dep.id).$(dep.property)"
end

function dependency_string(dep::Dependency{Trait, <:NamedTuple}) where {Trait}
    id_str = replace(
        sorted_json(dep.id),
        "."=>"\\."
    )
    return "$(id_str).$(dep.property)"
end

function output_string(deps::CallbackDeps)
    if deps.multi_out
        return ".." *
        join(dependency_string.(deps.output), "...") *
        ".."
    end
    return dependency_string(deps.output[1])
end

"""
    function callback!(func::Union{Function, ClientsideFunction, String},
        app::DashApp,
        output::Union{Vector{Output}, Output},
        input::Union{Vector{Input}, Input},
        state::Union{Vector{State}, State} = []
        )

Create a callback that updates the output by calling function `func`.

# Examples

```julia
app = dash() do
    html_div() do
        dcc_input(id="graphTitle", value="Let's Dance!", type = "text"),
        dcc_input(id="graphTitle2", value="Let's Dance!", type = "text"),
        html_div(id="outputID"),
        html_div(id="outputID2")

    end
end
callback!(app, [Output("outputID2", "children"), Output("outputID", "children")],
    Input("graphTitle", "value"),
    State("graphTitle", "type")
    ) do inputValue, stateType
    return (stateType * "..." * inputValue, inputValue)
end
```
"""
function callback!(func::Union{Function, ClientsideFunction, String},
     app::DashApp,
     output::Union{Vector{<:Output}, Output},
     input::Union{Vector{<:Input}, Input},
     state::Union{Vector{<:State}, State} = State[];
     prevent_initial_call = nothing
     )
     return _callback!(func, app, CallbackDeps(output, input, state), prevent_initial_call = prevent_initial_call)
end

"""
    function callback!(func::Union{Function, ClientsideFunction, String},
        app::DashApp,
        deps...
        )

Create a callback that updates the output by calling function `func`.
"Flat" version of `callback!` function, `deps` must be ``Output..., Input...[,State...]``

# Examples

```julia
app = dash() do
    html_div() do
        dcc_input(id="graphTitle", value="Let's Dance!", type = "text"),
        dcc_input(id="graphTitle2", value="Let's Dance!", type = "text"),
        html_div(id="outputID"),
        html_div(id="outputID2")

    end
end
callback!(app,
    Output("outputID2", "children"),
    Output("outputID", "children"),
    Input("graphTitle", "value"),
    State("graphTitle", "type")
    ) do  inputValue, stateType
    return (stateType * "..." * inputValue, inputValue)
end
```
"""
function callback!(func::Union{Function, ClientsideFunction, String},
     app::DashApp,
     deps::Dependency...;
     prevent_initial_call = nothing
     )
     output = Output[]
     input = Input[]
     state = State[]
     _process_callback_args(deps, (output, input, state))
     return _callback!(func, app, CallbackDeps(output, input, state, length(output) > 1), prevent_initial_call = prevent_initial_call)
end

function _process_callback_args(args::Tuple{T, Vararg}, dest::Tuple{Vector{T}, Vararg}) where {T}
    push!(dest[1], args[1])
    _process_callback_args(Base.tail(args), dest)
end
function _process_callback_args(args::Tuple{}, dest::Tuple{Vector{T}, Vararg}) where {T}
end
function _process_callback_args(args::Tuple, dest::Tuple{Vector{T}, Vararg}) where {T}
    _process_callback_args(args, Base.tail(dest))
end
function _process_callback_args(args::Tuple, dest::Tuple{})
    error("The callback method must received first all Outputs, then all Inputs, then all States")
end
function _process_callback_args(args::Tuple{}, dest::Tuple{})
end

function _callback!(func::Union{Function, ClientsideFunction, String}, app::DashApp, deps::CallbackDeps; prevent_initial_call)

    check_callback(func, app, deps)

    out_symbol = Symbol(output_string(deps))
    callback_func = make_callback_func!(app, func, deps)
    push!(
        app.callbacks,
        out_symbol => Callback(
                callback_func,
                deps,
                isnothing(prevent_initial_call) ?
                    get_setting(app, :prevent_initial_callbacks) :
                    prevent_initial_call
            )
        )
end

make_callback_func!(app::DashApp, func::Union{Function, ClientsideFunction}, deps::CallbackDeps) = func

function make_callback_func!(app::DashApp, func::String, deps::CallbackDeps)
    first_output = first(deps.output)
    namespace = replace("_dashprivate_$(first_output.id)", "\""=>"\\\"")
    function_name = replace("$(first_output.property)", "\""=>"\\\"")

    function_string = """
            var clientside = window.dash_clientside = window.dash_clientside || {};
            var ns = clientside["$namespace"] = clientside["$namespace"] || {};
            ns["$function_name"] = $func;
    """
    push!(app.inline_scripts, function_string)
    return ClientsideFunction(namespace, function_name)
end

function check_callback(func, app::DashApp, deps::CallbackDeps)

    isempty(deps.output) && error("The callback method requires that one or more properly formatted outputs are passed.")
    isempty(deps.input) && error("The callback method requires that one or more properly formatted inputs are passed.")

    args_count = length(deps.state) + length(deps.input)

    check_callback_func(func, args_count)

end

function check_callback_func(func::Function, args_count)
    !hasmethod(func, NTuple{args_count, Any}) && error("The arguments of the specified callback function do not align with the currently defined callback; please ensure that the arguments to `func` are properly defined.")
end
function check_callback_func(func, args_count)
end


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

module PolicyClient

using Random
using Dates
using HTTP
using Swagger
import Swagger: field_name, property_type, hasproperty, validate_property, SwaggerApi, SwaggerModel
import Base: convert, propertynames

include("modelincludes.jl")

include("api_PolicyAssignmentsApi.jl")
include("api_PolicyDefinitionsApi.jl")

# export models
export convert, PolicyAssignment
export convert, PolicyAssignmentListResult
export convert, PolicyAssignmentProperties
export convert, PolicyDefinition
export convert, PolicyDefinitionListResult
export convert, PolicyDefinitionProperties

# export operations
export convert, PolicyAssignmentsApi, PolicyDefinitionsApi

export check_required, field_name, property_type, hasproperty, propertynames, validate_property, convert

end


text:
function test_identity_layer(backend::Backend, T)
  println("-- Testing IdentityLayer on $(typeof(backend)){$T}...")

  eps = 1e-10
  input = rand(T, 3, 4, 5)
  input_blob = make_blob(backend, input)

  println("    > Setup")
  layer = IdentityLayer(tops=[:foo], bottoms=[:bar])
  state = setup(backend, layer, Blob[input_blob], Blob[NullBlob()])
  @test all(map(x -> isa(x, NullBlob), state.blobs_diff))

  println("    > Forward")
  forward(backend, state, Blob[input_blob])
  got_output = to_array(state.blobs[1])
  @test all(abs(got_output-input) .< eps)

  shutdown(backend, state)
end

function test_identity_layer(backend::Backend)
  test_identity_layer(backend, Float32)
  test_identity_layer(backend, Float64)
end

if test_cpu
  test_identity_layer(backend_cpu)
end
if test_gpu
  test_identity_layer(backend_gpu)
end


text:
julia> a = "hello world"
"hello world"

julia> run(`espeak $a`)

max_stars_repo_name: ethansaxenian/RosettaDecode

max_issues_repo_name: ethansaxenian/RosettaDecode

max_forks_repo_name: ethansaxenian/RosettaDecode


text:
# plots data from dp2_examples.jl

using Winston, Color

using VI2, CIRProc

include("utils.jl")

# settings
datafile = "dp2_examples.jld"
figpath = "figs"
# n colors as columns of returned matrix
pcols(n) = [RGB(xi, xi, xi) for xi in linspace(0.0, 0.7, n)]
pwidth = 5

## Bounds for different costs
@readdata(datafile, "var_c", mu_tau, sig_tau, theta_tau, cs, bound, taus)
cirp = CIRProcess(mu_tau, sig_tau, theta_tau)
ptau = pdf(ssdist(cirp), taus)
p = FramedPlot(title="Optimal bound for different costs",
    xlabel = "\\tau", ylabel = "g_\\theta(\\tau)",
    xrange = [taus[1], taus[div(length(taus),2)]], yrange = [0.5, 1.0],
    aspect_ratio = 3/4)
nc = length(cs)
ccols = pcols(nc)
add(p,Curve(taus, 0.5.+0.2*ptau/maximum(ptau), kind="dashed"))
pcurve = cell(nc);
for i = 1:nc
    pcurve[i] = Curve(taus, bound[i,:], color=ccols[i], width=pwidth)
    setattr(pcurve[i], label=@sprintf("%4.2f", cs[i]))
    add(p, pcurve[i])
end
add(p, Legend(0.1, 0.9, pcurve))
display(p)
println("-- Figure saved as $figpath/dp2_examples_c.eps")
savefig(p, joinpath(figpath, "dp2_examples_c.eps"))

## Bound for different mu_tau
@readdata(datafile, "var_mu_tau", mu_taus, sig_tau, theta_tau, bound, taus)
p = FramedPlot(title = "Optimal bound for different \\tau  means",
    xlabel = "\\tau", ylabel = "g_\\theta(\\tau)",
    xrange = [taus[1], taus[div(length(taus),2)]], yrange = [0.5, 1.0],
    aspect_ratio = 3/4)
nmu_tau = length(mu_taus)
ccols = pcols(nmu_tau)
for i = 1:nmu_tau
    cirp = CIRProcess(mu_taus[i], sig_tau, theta_tau)
    ptau = pdf(ssdist(cirp), taus)
    add(p, Curve(taus, 0.5.+0.1*ptau, color=ccols[i], kind="dashed"))
end
pcurve = cell(nmu_tau);
for i = 1:nmu_tau
    pcurve[i] = Curve(taus, bound[i,:], color=ccols[i], width=pwidth)
    setattr(pcurve[i], label=@sprintf("%4.2f", mu_taus[i]))
    add(p, pcurve[i])
end
add(p, Legend(0.1, 0.9, pcurve))
display(p)
println("-- Figure saved as $figpath/dp2_examples_mu_tau.eps")
savefig(p, joinpath(figpath, "dp2_examples_mu_tau.eps"))

## Bound for different sig_tau
@readdata(datafile, "var_sig_tau", mu_tau, sig_taus, theta_tau, bound, taus)
p = FramedPlot(title = "Optimal bound for different \\tau  SDs",
    xlabel = "\\tau", ylabel = "g_\\theta(\\tau)",
    xrange = [taus[1], taus[div(length(taus),2)]], yrange = [0.5, 1.0],
    aspect_ratio = 3/4)
nsig_tau = length(sig_taus)
ccols = pcols(nsig_tau)
for i = 1:nsig_tau
    cirp = CIRProcess(mu_tau, sig_taus[i], theta_tau)
    ptau = pdf(ssdist(cirp), taus)
    add(p, Curve(taus, 0.5.+0.1*ptau, color=ccols[i], kind="dashed"))
end
pcurve = cell(nsig_tau)
for i = 1:nsig_tau
    pcurve[i] = Curve(taus, bound[i,:], color=ccols[i], width=pwidth)
    setattr(pcurve[i], label=@sprintf("%2.4f", sig_taus[i]))
    add(p, pcurve[i])
end
add(p, Legend(0.1, 0.9, pcurve))
display(p)
println("-- Figure saved as $figpath/dp2_examples_sig_tau.eps")
savefig(p, joinpath(figpath, "dp2_examples_sig_tau.eps"))

## Bound for different theta_tau
@readdata(datafile, "var_theta_tau", mu_tau, sig_tau, theta_taus, bound, taus)
p = FramedPlot(title = "Optimal bound for different \\tau  speeds",
    xlabel = "\\tau", ylabel = "g_\\theta(\\tau)",
    xrange = [taus[1], taus[div(length(taus),2)]], yrange = [0.5, 1.0],
    aspect_ratio = 3/4)
ntheta_tau = length(theta_taus)
ccols = pcols(ntheta_tau)
for i = 1:ntheta_tau
    cirp = CIRProcess(mu_tau, sig_tau, theta_taus[i])
    ptau = pdf(ssdist(cirp), taus)
    add(p, Curve(taus, 0.5.+0.1*ptau, color=ccols[i], kind="dashed"))
end
pcurve = cell(ntheta_tau)
for i = 1:ntheta_tau
    pcurve[i] = Curve(taus, bound[i,:], color=ccols[i], width=pwidth)
    setattr(pcurve[i], label=@sprintf("%4.2f", theta_taus[i]))
    add(p, pcurve[i])
end
add(p, Legend(0.1, 0.9, pcurve))
display(p)
println("-- Figure saved as $figpath/dp2_examples_theta_tau.eps")
savefig(p, joinpath(figpath, "dp2_examples_theta_tau.eps"))

## Bound for different ti's
@readdata(datafile, "var_ti", mu_tau, sig_tau, theta_tau, bound, taus, tis)
cirp = CIRProcess(mu_tau, sig_tau, theta_tau)
ptau = pdf(ssdist(cirp), taus)
p = FramedPlot(title = "Optimal bound for different t_i's",
    xlabel = "\\tau", ylabel = "g_\\theta(\\tau)",
    xrange = [taus[1], taus[div(length(taus),2)]], yrange = [0.5, 1.0],
    aspect_ratio = 3/4)
add(p,Curve(taus, 0.5.+0.2*ptau/maximum(ptau), kind="dashed"))
nti = length(tis)
ccols = pcols(nti)
pcurve = cell(nti);
for i = 1:nti
    pcurve[i] = Curve(taus, bound[i,:], color=ccols[i], width=pwidth)
    setattr(pcurve[i], label=@sprintf("%6.2f", tis[i]))
    add(p, pcurve[i])
end
add(p, Legend(0.1, 0.9, pcurve))
display(p)
println("-- Figure saved as $figpath/dp2_examples_ti.eps")
savefig(p, joinpath(figpath, "dp2_examples_ti.eps"))

## Bound for different tp's
@readdata(datafile, "var_tp", mu_tau, sig_tau, theta_tau, bound, taus, tps)
cirp = CIRProcess(mu_tau, sig_tau, theta_tau)
ptau = pdf(ssdist(cirp), taus)
p = FramedPlot(title = "Optimal bound for different t_p's",
    xlabel = "\\tau", ylabel = "g_\\theta(\\tau)",
    xrange = [taus[1], taus[div(length(taus),2)]], yrange = [0.5, 1.0],
    aspect_ratio = 3/4)
add(p,Curve(taus, 0.5.+0.2*ptau/maximum(ptau), kind="dashed"))
ntp = length(tps)
ccols = pcols(ntp)
pcurve = cell(ntp);
for i = 1:ntp
    pcurve[i] = Curve(taus, bound[i,:], color=ccols[i], width=pwidth)
    setattr(pcurve[i], label=@sprintf("%6.2f", tps[i]))
    add(p, pcurve[i])
end
add(p, Legend(0.1, 0.9, pcurve))
display(p)
println("-- Figure saved as $figpath/dp2_examples_tp.eps")
savefig(p, joinpath(figpath, "dp2_examples_tp.eps"))


text:
"""
Big class of general phase-retrieval-related problems.
"""
abstract type AbstractPRproblem <: Problem end

"""
  PRproblem(a, A)

Classical phase-retrieval problem of finding complex arrays x, X such that
  |x| = a, |X| = A, and X =F(x),
where F denotes the Fourier transform.
"""
struct PRproblem{T <: Real, N} <: AbstractPRproblem
  a::Array{T,N}
  A::Array{T,N}
end

# this problem can be converted to a feasibility problem
TwoSetsFP(pr::PRproblem) = TwoSetsFP(ConstrainedByAmplitude(pr.a), FourierTransformedSet(ConstrainedByAmplitude(pr.A)))

# methods to solve
"""
Gerchberg-Saxton, classical method to solve PR problem
"""
abstract type GS <: IterativeAlgorithm end

"""
    GSparam(; ϕ⁰, maxit, maxϵ, keephistory, snapshots)

Parameters for a concrete realisation of GS method.
"""
Base.@kwdef struct GSparam <: GS
    ϕ⁰ = missing
    maxϵ::Union{Float64, Missing} = missing
    maxit::Union{Missing,Int64} = missing
    keephistory::Bool = false
    snapshots::Array{Int64} = Int64[]
end

initial(alg::GSparam) = alg.ϕ⁰
tolerance(alg::GSparam) = alg.maxϵ
maxit(alg::GSparam) = alg.maxit
keephistory(alg::GSparam) = alg.keephistory
snapshots(alg::GSparam) = alg.snapshots

# GS is just alternating projection method
"""
    solve(pr::PRproblem, alg::GS, args...)

Solve PR problem using GS method. Any change of the GS parameters can be given
"""
solve(pr::PRproblem, ::GSparam, ϕ⁰, maxϵ, maxit, keephistory, snapshots) =
        solve(
            TwoSetsFP(pr),
            AlternatingProjections.APparam(),
            ismissing(ϕ⁰) ?  missing : pr.a .* exp.(2π .* im .* ϕ⁰),
            maxϵ,
            maxit,
            keephistory,
            snapshots)

# PRproblem(x, X) = TwoSetsFP(ConstrainedByAmplitude(x), FourierTransformedSet(ConstrainedByAmplitude(X)))


text:
module Benchmarker

# Configure the pool allocator in CuArrays
#ENV["CUARRAYS_MEMORY_POOL"] = "simple"

using AutoTM
using nGraph
using PGFPlotsX
using CuArrays

using AutoTM.Utils

using Serialization

# Make data directories if needed.
function __init__()
    for dir in (DATADIR, CPUDATA, GPUDATA, FIGDIR)
        isdir(dir) || mkpath(dir)
    end

    # Configure the PGFPlotsX backend
    PGFPlotsX.latexengine!(PGFPlotsX.PDFLATEX)
end

const SRCDIR = @__DIR__
const PKGDIR = dirname(SRCDIR)
const DATADIR = joinpath(PKGDIR, "data")
const FIGDIR = joinpath(PKGDIR, "figures")

const CPUDATA = joinpath(DATADIR, "cpu")
const GPUDATA = joinpath(DATADIR, "gpu")

include("benchmarks.jl")
include("plots.jl")
include("kernel.jl")
include("presentation_plots.jl")

#####
##### Trials
#####

# Forward the `name` function to `AutoTM.Experiments.name`
name(x...) = AutoTM.Experiments.name(x...)

wrap(x::Union{Tuple, <:Array, <:Iterators.Flatten}) = x
wrap(x) = (x,)

savedir(::Type{nGraph.CPU}) = CPUDATA
savedir(::Type{nGraph.GPU}) = GPUDATA
savedir(::nGraph.Backend{T}) where {T} = savedir(T)

getcache(::nGraph.Backend{nGraph.CPU}, path::String) = AutoTM.Profiler.CPUKernelCache(path)
getcache(::nGraph.Backend{nGraph.GPU}, path::String) = AutoTM.Profiler.GPUKernelCache(path)

# Unwrap the string name from `cache`
function canonical_path(
        f,
        opt::AutoTM.Optimizer.AbstractOptimizer,
        cache::String,
        backend::nGraph.Backend,
        suffix = nothing
    )
    return canonical_path(f, AutoTM.Optimizer.name(opt), cache, backend, suffix)
end

function canonical_path(f, opt::String, cache::String, backend, suffix = nothing)
    # Find the prefix for the cache
    cachename = first(splitext(basename(cache)))
    n = join((name(f), opt, cachename), "_")
    if !isnothing(suffix)
        n = n * "_$suffix"
    end
    n = n * ".jls"
    return joinpath(savedir(backend), n)
end

function execute(fns, opts, caches, backend, suffix = nothing; kw...)
    # Wrap functions, optimizers, and caches so we can safely iterate over everything
    for f in wrap(fns), cache in wrap(caches), opt in wrap(opts)
        savefile = canonical_path(f, opt, cache, backend, suffix)
        AutoTM.Profiler.compare(
            f,
            opt,
            backend;
            statspath = savefile,
            cache = getcache(backend, cache),
            kw...
        )
    end
end

end

max_stars_repo_name: darchr/AutoTM

max_issues_repo_name: darchr/AutoTM

max_forks_repo_name: darchr/AutoTM


text:
#############################################################################
# rank_of_graph_matroid.jl
# given a graph G = (V, E)
# f(S) = n - # of connected components of the subgraph of G induced by S
#############################################################################

export rank_of_graph_matroid
export sign, monotonicity, modularity, evaluate

mutable struct RankOfGraphicMatroidAtom <: SubmodFunc
  head::Symbol
  id_hash::UInt64
  children::Tuple{WeightedGraph, CombiSet}
  size::Tuple{Int, Int}
  graph::WeightedGraph
  setvariables::Array{CombiSet}

  function RankOfGraphicMatroidAtom(g::WeightedGraph, S::CombiSet)
    if ne(g) != S.cardinality
      error("Cannot define a rank function of a graphic matroid when the number of edges in the graph is different from the size of the set variable.")
    else
      children = (g, S)
      setvariables = get_sv(S)
      return new(:rankofgraphicmatroid, hash(children), children, (1, 1), g, setvariables)
    end
  end
end

rank_of_graph_matroid(g::WeightedGraph, S::CombiSet) = RankOfGraphicMatroidAtom(g, S)

function sign(F::RankOfGraphicMatroidAtom)
  return Positive()
end

function monotonicity(F::RankOfGraphicMatroidAtom)
  return (Nonincreasing(), )
end

function modularity(F::RankOfGraphicMatroidAtom)
  return SubModularity()    # up to verification
end

function evaluate(F::RankOfGraphicMatroidAtom)
  elist = AbstractEdge[]
  i = 1
  set = get_elements(F.children[2])
  for e in edges(F.children[1])
    if in(i, set) == true
      u, v = src(e), dst(e)
      push!(elist, Edge(u, v))
    end
    i += 1
  end
  sub_graph, vmap = induced_subgraph(F.children[1], elist)
  val = nv(sub_graph) - length(connected_components(sub_graph))
  return val
end