text:
module Qulacs

using PyCall

import ..@pyfunc
import ..@pyclass

export qulacs

const qulacs = PyNULL()

const qulacs_class = [
    :DensityMatrix, :QuantumGate_SingleParameter,
    :GeneralQuantumOperator, :QuantumState,
    :Observable, :QuantumStateBase,
    :ParametricQuantumCircuit, :StateVector,
    :PauliOperator,
    :QuantumCircuit,
    :QuantumCircuitSimulator,
    :QuantumGateBase,
    :QuantumGateMatrix,
]

#=
for class in qulacs_class
    @eval begin
        struct $class
            pyobj::PyObject
            $(class)(args...) = new(qulacs.$(class)(args...))
        end

        PyObject(t::$(class)) = t.pyobj

        function Base.propertynames(t::$(class))
            propertynames(getfield(t, :pyobj))
        end

        function Base.getproperty(t::$(class), s::Symbol)
            if s ∈ fieldnames($(class))
                return getfield(t, s)
            else
                return getproperty(getfield(t, :pyobj), s)
            end
        end

        export $(class)
    end
end
=#

for class in qulacs_class
    @eval begin
        @pyclass qulacs $(class)
        export $(class)
    end
end

function __init__()
    copy!(qulacs, pyimport("qulacs"))
end

end


text:
"""
    B_Spline{T, edge, order} <: AbstractInterpolation{T, edge, order}

Abstract supertype for all bspline interpolation type
"""
abstract type B_Spline{T,edge,order} <: AbstractInterpolation{T,edge,order} end
isbspline(_::B_Spline) = true
issolidentity(_::B_Spline) = false
function get_kl_ku(order)
    ku = div(order, 2)
    kl = order - 1 - ku
    return kl, ku # kl <= ku
end

ext: jl


text:
export europe8, eurasia38, scand3, scand4, eurasia21, china6, europe13, europe21, europe22, europe54, syntheticdemandregions,
        testreg, caspian, NUTS_Europe, eurasia92

const scand3 = [
    "SWE"   GADM("Sweden")
    "NOR"   GADM("Norway")
    "FIN"   GADM("Finland","Åland")
]

const scand4 = [
    scand3;
    "DEN"   GADM("Denmark")
]

# const spainsubregions = subregions(GADM, "Spain")[[1:13; 15:18]]  # all subregions except Canary Islands
# const portugalsubregions = subregions(GADM, "Portugal")[[1; 3:11; 13:20]]  # all subregions except Azores and Madeira
# const europe8 = [
#     # Europe: "NOR","FRA","GER","UK","MED","BAL","SPA","CEN"
#     "NOR"   GADM("Sweden","Norway","Denmark","Finland","Åland","Faroe Islands")
#     "FRA"   GADM("France","Monaco")
#     "GER"   GADM("Germany","Netherlands","Belgium","Luxembourg")
#     "UK"    GADM("United Kingdom","Ireland","Guernsey","Isle of Man","Jersey")
#     "MED"   GADM("Greece","Bulgaria","Italy","San Marino","Vatican City","Slovenia","Croatia","Bosnia and Herzegovina","Serbia","Montenegro","Kosovo","Albania","Macedonia","Malta")
#     "BAL"   GADM("Poland","Estonia","Latvia","Lithuania")
#     "SPA"   (GADM(["Spain"], spainsubregions...), GADM(["Portugal"], portugalsubregions...), GADM("Andorra","Gibraltar"))
#     "CEN"   GADM("Austria","Switzerland","Czech Republic","Hungary","Slovakia","Romania","Liechtenstein")
# ]

const eurasia38 = [
    # Europe: "NOR","FRA","GER","UK","MED","BAL","SPA","CEN"
    "NOR"   GADM("Sweden","Norway","Denmark","Finland","Åland","Faroe Islands")
    "FRA"   GADM("France","Monaco")
    "GER"   GADM("Germany","Netherlands","Belgium","Luxembourg")
    "UK"    GADM("United Kingdom","Ireland","Guernsey","Isle of Man","Jersey")
    "MED"   GADM("Greece","Bulgaria","Italy","San Marino","Vatican City","Slovenia","Croatia","Bosnia and Herzegovina","Serbia","Montenegro","Kosovo","Albania","Macedonia","Malta")
    "BAL"   GADM("Poland","Estonia","Latvia","Lithuania")
    "SPA"   GADM("Spain","Portugal","Andorra","Gibraltar")
    "CEN"   GADM("Austria","Switzerland","Czech Republic","Hungary","Slovakia","Romania","Liechtenstein")

    # Eastern Europe & Middle East: "Belarus/Ukraine/Moldova","Turkey/Caucasus","Middle East","Iran","Arabian peninsula"
    "BUK"   GADM("Belarus","Ukraine","Moldova")
    "TCC"   GADM("Turkey","Georgia","Armenia","Azerbaijan")
    "MEA"   GADM("Israel","Palestina","Lebanon","Jordan","Syria","Iraq","Kuwait")
    "IRN"   GADM("Iran")
    "ARB"   GADM("Saudi Arabia","Yemen","Oman","United Arab Emirates","Bahrain","Qatar")

    # Central & South-Central Asia: "Central Asia","South-Central Asia"
    "KZK"   GADM("Kazakhstan")
    "CAS"   GADM("Uzbekistan","Turkmenistan","Tajikistan","Kyrgyzstan")
    "SCA"   GADM("Afghanistan","Pakistan")

    # India: "North","West","Central","South","East","Northeast"
    # https://en.wikipedia.org/wiki/Administrative_divisions_of_India
    # Excluding island groups: "Andaman and Nicobar Islands","Lakshadweep"
    # South also includes Sri Lanka
    # Northeast also includes Nepal,Bhutan and Bangladesh
    "IN_N"  GADM(["India"], "Jammu and Kashmir","Himachal Pradesh","Punjab","Rajasthan","Chandigarh","Haryana","NCT of Delhi","Uttarakhand","Uttar Pradesh")
    "IN_W"  GADM(["India"], "Gujarat","Goa","Maharashtra","Dadra and Nagar Haveli","Daman and Diu")
    "IN_C"  GADM(["India"], "Madhya Pradesh","Chhattisgarh")
    "IN_S"  (GADM(["India"], "Karnataka","Kerala","Tamil Nadu","Andhra Pradesh","Telangana","Puducherry"), GADM("Sri Lanka"))
    "IN_E"  GADM(["India"], "Odisha","Jharkhand","West Bengal","Bihar")
    "IN_NE" (GADM(["India"], "Sikkim","Assam","Meghalaya","Tripura","Mizoram","Manipur","Nagaland","Arunachal Pradesh"),
                GADM("Nepal","Bhutan","Bangladesh"))

    # Southeast Asia: "Central Asia","South-Central Asia"
    # also includes Peninsular Malaysia,https://en.wikipedia.org/wiki/Peninsular_Malaysia
    "SEA"   (GADM("Myanmar","Thailand","Laos","Vietnam","Cambodia","Singapore"),
                GADM(["Malaysia"], "Perlis","Kedah","Pulau Pinang","Perak","Kelantan","Trengganu","Pahang","Selangor","Kuala Lumpur","Putrajaya","Negeri Sembilan","Melaka","Johor"))

    # Russia: "Northwest","Central","Southwest","Volga","Ural","Siberia","East"
    # https://en.wikipedia.org/wiki/Federal_districts_of_Russia
    # questionable: Novgorod,Altay,Yevrey,Maga Buryatdan/Magadan
    "RU_NW"  GADM(["Russia"], "Arkhangel'sk","Vologda","Kaliningrad","Karelia","Komi","Leningrad","Murmansk","Nenets","Novgorod","Pskov","City of St. Petersburg")
    "RU_C"   GADM(["Russia"], "Belgorod","Bryansk","Vladimir","Voronezh","Ivanovo","Kaluga","Kostroma","Kursk","Lipetsk","Moscow City","Moskva","Orel","Ryazan'","Smolensk","Tambov","Tver'","Tula","Yaroslavl'")
    "RU_SW"  GADM(["Russia"], "Adygey","Astrakhan'","Volgograd","Kalmyk","Krasnodar","Rostov","Dagestan","Ingush","Kabardin-Balkar","Karachay-Cherkess","North Ossetia","Stavropol'","Chechnya")
    "RU_VL"  GADM(["Russia"], "Bashkortostan","Kirov","Mariy-El","Mordovia","Nizhegorod","Orenburg","Penza","Perm'","Samara","Saratov","Tatarstan","Udmurt","Ul'yanovsk","Chuvash")
    "RU_UR"  GADM(["Russia"], "Kurgan","Sverdlovsk","Tyumen'","Khanty-Mansiy","Chelyabinsk","Yamal-Nenets")
    "RU_SB"  GADM(["Russia"], "Altay","Gorno-Altay","Irkutsk","Kemerovo","Krasnoyarsk","Novosibirsk","Omsk","Tomsk","Tuva","Khakass")
    "RU_E"   GADM(["Russia"], "Amur","Buryat","Yevrey","Zabaykal'ye","Kamchatka","Maga Buryatdan","Primor'ye","Sakha","Sakhalin","Khabarovsk","Chukot")

    # China: "North" (Huáběi),"Northeast" (Dōngběi),"East" (Huádōng),"South Central" (Zhōngnán),"Southwest" (Xīnán),"Northwest" (Xīběi)
    # https://en.wikipedia.org/wiki/List_of_regions_of_China
    # East also includes Taiwan
    # South Central also includes Hong Kong and Macao
    "CH_N"   GADM(["China"], "Beijing","Tianjin","Hebei","Shanxi","Nei Mongol")
    "CH_NE"  GADM(["China"], "Liaoning","Jilin","Heilongjiang")
    "CH_E"   (GADM(["China"], "Shanghai","Jiangsu","Zhejiang","Anhui","Fujian","Jiangxi","Shandong"), GADM("Taiwan"))
    "CH_SC"  (GADM(["China"], "Henan","Hubei","Hunan","Guangdong","Guangxi","Hainan"), GADM("Hong Kong","Macao"))
    "CH_SW"  GADM(["China"], "Chongqing","Sichuan","Guizhou","Yunnan","Xizang")
    "CH_NW"  GADM(["China"], "Shaanxi","Gansu","Qinghai","Ningxia Hui","Xinjiang Uygur")

    # Other
    "MON"    GADM("Mongolia")
    "JKR"    GADM("Japan","South Korea","North Korea")
]

const eurasia21 = eurasia38[[1:10; 14:15; 25:27; 31:36], :]
const china6 = eurasia38[31:36, :]

const europe13 = [
    # BNL = Benelux, BTC = Baltic, BKN = Balkan, CEN = Central
    "SWE"   GADM("Sweden")
    "NOR"   GADM("Norway")
    "DEN"   GADM("Denmark","Faroe Islands")
    "FIN"   GADM("Finland","Åland")
    "BNL"   GADM("Netherlands","Belgium","Luxembourg")
    "GER"   GADM("Germany")
    "FRA"   GADM("France","Monaco")
    "UK"    GADM("United Kingdom","Ireland","Guernsey","Isle of Man","Jersey")
    "ITA"   GADM("Italy","San Marino","Vatican City")
    "BKN"   GADM("Greece","Bulgaria","Romania","Slovenia","Croatia","Bosnia and Herzegovina","Serbia","Montenegro","Kosovo","Albania","Macedonia","Malta","Moldova")
    "BTC"   GADM("Poland","Estonia","Latvia","Lithuania")
    "SPA"   GADM("Spain","Portugal","Andorra","Gibraltar")
    "CEN"   GADM("Austria","Switzerland","Czech Republic","Hungary","Slovakia","Liechtenstein")
]

# Wikipedia's definition of Europe
const europe21 = [
    europe13;
    "BLR"   GADM("Belarus")
    "UKR"   GADM("Ukraine")
    "TUR"   GADM("Turkey")
    "CCS"   GADM("Georgia","Armenia","Azerbaijan")
    eurasia38[24:27, :]
]

# Regions for the ELIN/EPOD models
const europe54 = [
    "AT"    NUTS("AT")
    "BE"    NUTS("BE")
    "BG"    NUTS("BG")
    "CY"    NUTS("CY")
    "CZ"    NUTS("CZ")
    "DE1"   NUTS("DE11","DE12","DE13","DE14","DE21","DE22","DE23","DE24","DE25","DE26","DE27")
    "DE2"   NUTS("DEB1","DEB2","DEB3","DEC0")
    "DE3"   NUTS("DE71","DE72","DE73","DE91","DE92","DEA1","DEA2","DEA3","DEA4","DEA5","DEG0")
    "DE4"   NUTS("DE30","DE40","DE60","DE80","DED4","DED2","DED5","DEF0","DEE0")
    "DE5"   NUTS("DE50","DE93","DE94")
    "DK1"   NUTS("DK01","DK02")
    "DK2"   NUTS("DK03","DK04","DK05")
    "EE"    NUTS("EE")
    "FI"    NUTS("FI")                # Åland is included in NUTS("FI")
    "GR"    NUTS("EL")                # ΕΛΛΑΔΑ (Greece in Greek)
    "HU"    NUTS("HU")
    "IE"    NUTS("IE")
    "LV"    NUTS("LV")
    "LT"    NUTS("LT")
    "LU"    NUTS("LU")
    "MT"    NUTS("MT")
    "NL"    NUTS("NL")
    "PT"    NUTS("PT11","PT15","PT16","PT17","PT18")    # excludes small islands
    "RO"    NUTS("RO")
    "SI"    NUTS("SI")
    "SK"    NUTS("SK")
    "CH"    NUTS("CH","LI")                   # includes Liechtenstein
    "IS"    NUTS("IS")
 #   "BO"    GADM("Bosnia and Herzegovina")    # Bosnia and Herzegovina completely missing in NUTS
    "CR"    NUTS("HR")                        # Hrvatska (Croatia in Croatian)
 #   "MC"    NUTS("MK")                        # Macedonia
    "ES1"   NUTS("ES11","ES12","ES13")
    "ES2"   NUTS("ES21","ES22","ES23","ES24","ES51","ES52","ES53","ES62")
    "ES3"   NUTS("ES30","ES41","ES42")
    "ES4"   NUTS("ES61","ES43")
    "FR1"   NUTS("FRJ1","FRL0","FRM0")
    "FR2"   NUTS("FRI1","FRJ2","FRI2")
    "FR3"   NUTS("FRG0","FRH0","FRI3")
    "FR4"   NUTS("FRF3","FRF1","FRC2")
    "FR5"   NUTS("FR10","FRF2","FRE2","FRD2","FRB0","FRD1","FRC1","FRE1","FRK2","FRK1")
    "IT1"   NUTS("ITC","ITH")
    "IT2"   NUTS("ITI","ITG2")
    "IT3"   NUTS("ITF","ITG1")
    "NO1"   NUTS("NO01","NO02","NO03","NO04","NO05")
    "NO2"   NUTS("NO06")
    "NO3"   NUTS("NO07")
    "PO1"   NUTS("PL21","PL22","PL51","PL52")
    "PO2"   NUTS("PL71","PL72","PL81","PL82","PL84","PL91","PL92")
    "PO3"   NUTS("PL41","PL42","PL43","PL61","PL62","PL63")
    "SE1"   NUTS("SE22")
    "SE2"   NUTS("SE11","SE12","SE21","SE23","SE31")
    "SE3"   NUTS("SE32")
    "SE4"   NUTS("SE33")
    "UK1"   NUTS("UKC1","UKC2","UKD1","UKD3","UKD4","UKD5","UKD6","UKD7","UKL1","UKL2","UKG1","UKG2","UKG3",
                 "UKE1","UKE2","UKE3","UKE4","UKF1","UKF2","UKF3","UKH1","UKH2","UKH3","UKI3","UKI4","UKI5","UKI6","UKI7",
                 "UKK1","UKK2","UKK3","UKK4","UKJ1","UKJ2","UKJ3","UKJ4")
    "UK2"   NUTS("UKM5","UKM6","UKM7","UKM8","UKM9")
    "UK3"   NUTS("UKN0", "UKN1")
]

# https://ec.europa.eu/eurostat/statistics-explained/index.php/Glossary:EU_enlargements
# https://ec.europa.eu/eurostat/statistics-explained/index.php?title=Glossary:Candidate_countries
const NUTS_Europe = [
    "EU12"  NUTS("BE","DK","FR","DE","EL","IE","IT","LU","NL","PT","ES","UK")
    "EU15"  NUTS("AT","FI","SE")
    "EFTA"  NUTS("IS","LI","NO","CH")
    "EU25"  NUTS("CY","CZ","EE","HU","LV","LT","MT","PL","SK","SI")
    "EU28"  NUTS("BG","RO","HR")
    "CAND"  NUTS("ME","MK","AL","RS","TR","BA","XK")
]

# Non NUTS regions and neighboring countries to European regions (onshore or offshore)
# https://ec.europa.eu/eurostat/statistical-atlas/gis/viewer/?config=typologies.json
const non_NUTS_Europe = [
    "mainland"  GADM("Monaco", "Andorra", "San Marino", "Vatican City")
    "islands"   GADM("Faroe Islands", "Isle of Man", "Guernsey", "Jersey", "Svalbard and Jan Mayen")
    "east"      GADM("Moldova", "Ukraine", "Belarus", "Russia")
    "south"     GADM("Morocco", "Algeria", "Tunisia", "Libya", "Egypt", "Israel", "Jordan", "Lebanon", "Syria")
    "west"      GADM("Greenland")
]

const europe22 = [
    "SE1"   NUTS("SE332")
    "SE2"   NUTS("SE313", "SE321", "SE322", "SE331")
    "SE3"   NUTS("SE110", "SE121", "SE122", "SE123", "SE124", "SE125", "SE211", "SE213", "SE214", "SE232", "SE311", "SE312")
    "SE4"   NUTS("SE212", "SE221", "SE224", "SE231")
    "NO1"   NUTS("NO011", "NO012", "NO021", "NO022", "NO031")
    "NO2"   NUTS("NO033", "NO034", "NO041", "NO042", "NO043")
    "NO3"   NUTS("NO053", "NO060")
    "NO4"   NUTS("NO071", "NO072", "NO073")
    "NO5"   NUTS("NO032", "NO051", "NO052")
    "DEN"   NUTS("DK")
    "FI1"   NUTS("FI193", "FI194", "FI195", "FI196", "FI197", "FI1B1", "FI1C1", "FI1C2", "FI1C3", "FI1C4", "FI1C5",
                    "FI1D1", "FI1D2", "FI1D3", "FI1D5", "FI200")
    "FI2"   NUTS("FI1D7", "FI1D8", "FI1D9")
    "BNL"   NUTS("NL","BE","LU")
    "GER"   NUTS("DE")
    "POL"   NUTS("PL")
    "BAL"   NUTS("EE", "LV", "LT")
    "IRL"   NUTS("IE")
    "UK"    NUTS("UK")
    "FRA"   (NUTS("FR"), GADM("Monaco"))
    "CEN"   NUTS("AT", "CH", "LI", "CZ", "HU", "SK", "RO")  # Austria, Switzerland, Liechtenstein, Czech Rep, Hungary, Slovakia, Romania
    "SPA"   (NUTS("ES", "PT"), GADM("Andorra"))             # Spain includes Gibraltar
    "MED"   (NUTS("IT", "SI", "HR", "RS", "BG", "ME",       # Italy, Slovenia, Croatia, Serbia, Bularia, Montenegro
                  "AL", "MK", "EL"),                        # Albania, North Macedonia, Greece
            GADM("San Marino", "Vatican City", "Bosnia and Herzegovina", "Kosovo"))       # these are not included in NUTS-2016
    # Not included in any region:  Iceland, Faroe Islands, Cyprus, Malta, Isle of Man, Guernsey, Jersey, Jan Mayen, Svalbard, Bear Island,
    #                               Moldova, Ukraine, Belarus, Kaliningrad (or any part of Russia)
    # Islands that ARE included:  Canarias, Mallorca and other Balearic islands (ES); Madeira, Azores (PT); Åland (FI);
    #                               Corsica, Reunion, Mayotte, Guadeloupe, Martinique, Guyana (FR); Sicily, Sardinia (IT);
    #                               Orkney Islands, Shetney Islands, Western Isles, Isle of Wight (UK); Crete (EL)
    # But note that non-European territories are eliminated when the region bounding box is set to [34 -11; 72 32].
]

const france13 = [
    "Auvergne-Rhône-Alpes"         GADM(["France"], "Auvergne-Rhône-Alpes")
    "Bourgogne-Franche-Comté"      GADM(["France"], "Bourgogne-Franche-Comté")
    "Bretagne"                     GADM(["France"], "Bretagne")
    "Centre-Val de Loire"          GADM(["France"], "Centre-Val de Loire")
    "Corse"                        GADM(["France"], "Corse")
    "Grand Est"                    GADM(["France"], "Grand Est")
    "Hauts-de-France"              GADM(["France"], "Hauts-de-France")
    "Île-de-France"                GADM(["France"], "Île-de-France")
    "Normandie"                    GADM(["France"], "Normandie")
    "Nouvelle-Aquitaine"           GADM(["France"], "Nouvelle-Aquitaine")
    "Occitanie"                    GADM(["France"], "Occitanie")
    "Pays de la Loire"             GADM(["France"], "Pays de la Loire")
    "Provence-Alpes-Côte d'Azur"   GADM(["France"], "Provence-Alpes-Côte d'Azur")
]

const usa9 = [
    "New England"       GADM(["United States"], "Connecticut", "Maine", "Massachusetts", "New Hampshire", "Rhode Island", "Vermont")
    "Mid-Atlantic"      GADM(["United States"], "New Jersey", "New York", "Pennsylvania")
    "Central NE"        GADM(["United States"], "Illinois", "Indiana", "Michigan", "Ohio", "Wisconsin")
    "Central NW"        GADM(["United States"], "Iowa", "Kansas", "Minnesota", "Missouri", "Nebraska", "North Dakota", "South Dakota")
    "South Atlantic"    GADM(["United States"], "Delaware", "Florida", "Georgia", "Maryland", "North Carolina", "South Carolina", "Virginia", "District of Columbia", "West Virginia")
    "Central SE"        GADM(["United States"], "Alabama", "Kentucky", "Mississippi", "Tennessee")
    "Central SW"        GADM(["United States"], "Arkansas", "Louisiana", "Oklahoma", "Texas")
    "Mountain"          GADM(["United States"], "Arizona", "Colorado", "Idaho", "Montana", "Nevada", "New Mexico", "Utah", "Wyoming")
    "Pacific"           GADM(["United States"], "California", "Oregon", "Washington") # "Alaska", "Hawaii",
]

const denmark5 = [
    "Hovedstaden"       GADM(["Denmark"], "Hovedstaden")
    "Midtjylland"       GADM(["Denmark"], "Midtjylland")
    "Nordjylland"       GADM(["Denmark"], "Nordjylland")
    "Sjælland"          GADM(["Denmark"], "Sjælland")
    "Syddanmark"        GADM(["Denmark"], "Syddanmark")
]

# Test region to see if mixed GADM/NUTS notation works
const testreg = [
    "NO"     GADM("Norway")
    "DK"     NUTS("DK")
    "ISL"    (NUTS("SE214"), GADM("Åland"), GADM(["Sweden","Kalmar"], "Borgholm","Mörbylånga"))  # Gotland, Åland, Öland
]

const caspian = [
    "RU_SW"  GADM(["Russia"], "Astrakhan'","Kalmyk", "Dagestan")
    "KZK"    GADM(["Kazakhstan"], "Atyrau", "Mangghystau")
    "AZR"    GADM("Azerbaijan")
    "IRN"    GADM(["Iran"], "Gilan", "Golestan", "Mazandaran")
    "TRK"    GADM(["Turkmenistan"], "Balkan")
]

const mapregions = [
    "FRA"   GADM("France","Monaco")
    "KZK"   GADM("Kazakhstan")
    "CH_E"   (GADM(["China"], "Shanghai","Jiangsu","Zhejiang","Anhui","Fujian","Jiangxi","Shandong"), GADM("Taiwan"))
]

const syntheticdemandregions = [
    "Argentina", "Australia", "Austria", "Belgium", "Bosnia and Herzegovina", "Brazil", "Bulgaria", "Canada", "Chile",
    "Croatia", "Cyprus", "Czech Republic", "Denmark", "Estonia", "Finland", "France", "Germany", "Greece", "Hungary",
    "Iceland", "Ireland", "Italy", "Kenya", "Latvia", "Lithuania", "Macedonia", "Mexico", "Netherlands", "New Zealand",
    "Norway", "Poland", "Portugal", "Romania", "Saudi Arabia", "Serbia", "Slovakia", "Slovenia", "South Korea", "Spain",
    "Sri Lanka", "Sweden", "Switzerland", "Turkey", "United Kingdom"
]

const hovedstaden15 = [
    "København C"     GADM(["Denmark", "Hovedstaden"], "København","Frederiksberg","Tårnby","Dragør")
    "København W"     GADM(["Denmark", "Hovedstaden"], "Albertslund","Glostrup","Rødovre","Vallensbæk","Brøndby","Hvidovre")
    "København N"     GADM(["Denmark", "Hovedstaden"], "Lyngby-Taarbæk","Gladsaxe","Gentofte")
    "København NW"    GADM(["Denmark", "Hovedstaden"], "Furesø","Ballerup","Herlev")
    "Hovedstaden SW"  GADM(["Denmark", "Hovedstaden"], "Høje Taastrup", "Ishøj")
    "Allerød"         GADM(["Denmark", "Hovedstaden"], "Allerød")
    "Bornholm"        GADM(["Denmark", "Hovedstaden"], "Bornholm")  # Christiansø
    "Egedal"          GADM(["Denmark", "Hovedstaden"], "Egedal")
    "Helsingør"       GADM(["Denmark", "Hovedstaden"], "Fredensborg","Helsingør")
    "Frederikssund"   GADM(["Denmark", "Hovedstaden"], "Frederikssund")
    "Gribskov"        GADM(["Denmark", "Hovedstaden"], "Gribskov")
    "Halsnæs"         GADM(["Denmark", "Hovedstaden"], "Halsnæs")
    "Hillerød"        GADM(["Denmark", "Hovedstaden"], "Hillerød")
    "Hørsholm"        GADM(["Denmark", "Hovedstaden"], "Hørsholm")
    "Rudersdal"       GADM(["Denmark", "Hovedstaden"], "Rudersdal")
]

# no small islands included
const eurasia92 = [
    # Europe: "NOR","FRA","GER","UK","MED","BAL","SPA","CEN"
    "NOR_SEN"   GADM(["Sweden"], "Norrbotten","Västerbotten","Västernorrland","Jämtland","Gävleborg","Dalarna","Värmland")
    "NOR_SES"   GADM(["Sweden"], "Uppsala","Västmanland","Orebro","Stockholm","Södermanland","Västra Götaland","Östergötland","Jönköping","Kalmar","Gotland","Halland","Kronoberg","Skåne","Blekinge")
    "NOR_NO"    GADM("Norway")
    "NOR_DK"    GADM("Denmark")
    "NOR_FI"    GADM("Finland","Åland")
    "FRA_N"   GADM(["France"], "Hauts-de-France","Normandie")
    "FRA_W"   GADM(["France"], "Bretagne","Pays de la Loire","Nouvelle-Aquitaine")
    "FRA_C"   GADM(["France"], "Île-de-France","Grand Est","Centre-Val de Loire","Bourgogne-Franche-Comté")
    "FRA_S"   (GADM(["France"], "Auvergne-Rhône-Alpes","Occitanie","Provence-Alpes-Côte d'Azur"), GADM("Monaco"))
    "GER_BNL" GADM("Netherlands","Belgium","Luxembourg")
    "GER_N"   GADM(["Germany"], "Schleswig-Holstein","Hamburg","Mecklenburg-Vorpommern","Bremen","Niedersachsen")
    "GER_W"   GADM(["Germany"], "Nordrhein-Westfalen","Hessen","Rheinland-Pfalz","Saarland")
    "GER_E"   GADM(["Germany"], "Brandenburg","Berlin","Sachsen-Anhalt","Thüringen","Sachsen")
    "GER_S"   GADM(["Germany"], "Baden-Württemberg","Bayern")
    "UK_ESW"  GADM(["United Kingdom"], "England","Scotland","Wales")
    "UK_I"    (GADM("Ireland"), GADM(["United Kingdom"], "Northern Ireland"))
    "MED_IT"   GADM("Italy","San Marino","Vatican City")
    "MED_BK"   GADM("Slovenia","Croatia","Bosnia and Herzegovina","Serbia","Montenegro","Kosovo")
    "MED_GR"   GADM("Greece","Albania","Macedonia")
    "BAL_PL"   GADM("Poland")
    "BAL_ELL"  (GADM("Estonia","Latvia","Lithuania"), GADM(["Russia"], "Kaliningrad"))
    "SPA_NW"   GADM(["Spain"], "Galicia","Principado de Asturias","Cantabria","País Vasco","Comunidad Foral de Navarra","La Rioja","Castilla y León")
    "SPA_C"    GADM(["Spain"], "Aragón","Castilla-La Mancha","Comunidad de Madrid","Extremadura")
    "SPA_SE"   (GADM(["Spain"], "Cataluña", "Comunidad Valenciana", "Región de Murcia", "Andalucía"), GADM("Andorra","Gibraltar"))
    "SPA_PT"   GADM("Portugal")
    "CEN_AT"   GADM("Austria")
    "CEN_CH"   GADM("Switzerland","Liechtenstein")
    "CEN_CZ"   GADM("Czech Republic")
    "CEN_HU"   GADM("Hungary")
    "CEN_SK"   GADM("Slovakia")
    "CEN_RO"   GADM("Romania","Moldova")
    "CEN_BG"   GADM("Bulgaria")

    # Eastern Europe & Middle East: "Belarus/Ukraine/Moldova","Turkey/Caucasus","Middle East","Iran","Arabian peninsula"
    "BUK_BY"   GADM("Belarus")
    "BUK_UA"   GADM("Ukraine")
    "TCC_TR"   GADM("Turkey")
    "TCC_CC"   GADM("Georgia","Armenia","Azerbaijan")
    "MEA_SY"   GADM("Syria")
    "MEA_IPL"  GADM("Israel","Palestina","Lebanon")
    "MEA_JO"   GADM("Jordan")
    "MEA_IQ"   GADM("Iraq","Kuwait")
    "ARB_SAN"  GADM(["Saudi Arabia"], "Tabuk","Al Jawf","Al Madinah","Ha'il","Al Quassim","Al Hudud ash Shamaliyah")
    "ARB_SAS"  GADM(["Saudi Arabia"], "Makkah","Ar Riyad","Al Bahah","`Asir","Jizan","Najran","Ash Sharqiyah")
    "ARB_S"   GADM("Yemen","Oman")
    "ARB_E"   GADM("United Arab Emirates","Bahrain","Qatar")
    "IRN_NW"  GADM(["Iran"], "Ardebil","East Azarbaijan","Gilan","Kordestan","West Azarbaijan","Zanjan")
    "IRN_W"   GADM(["Iran"], "Hamadan","Ilam","Kermanshah","Khuzestan","Lorestan","Markazi")
    "IRN_N"   GADM(["Iran"], "Alborz","Golestan","Mazandaran","Qazvin","Qom","Semnan","Tehran")
    "IRN_S"   GADM(["Iran"], "Bushehr","Chahar Mahall and Bakhtiari","Fars","Hormozgan","Esfahan","Kohgiluyeh and Buyer Ahmad")
    "IRN_E"   GADM(["Iran"], "Kerman","North Khorasan","Razavi Khorasan","Sistan and Baluchestan","South Khorasan","Yazd")

    # Central & South-Central Asia: "Central Asia","South-Central Asia"
    "KZK_E"   GADM(["Kazakhstan"], "Almaty","East Kazakhstan")
    "KZK_N"   GADM(["Kazakhstan"], "Qostanay","North Kazakhstan","Aqmola","Pavlodar")
    "KZK_W"   GADM(["Kazakhstan"], "West Kazakhstan","Atyrau","Aqtöbe","Mangghystau")
    "KZK_SC"  GADM(["Kazakhstan"], "Qaraghandy","Qyzylorda","South Kazakhstan","Zhambyl")
    "CAS_UZ"   GADM("Uzbekistan")
    "CAS_TM"   GADM("Turkmenistan")
    "CAS_KT"   GADM("Tajikistan","Kyrgyzstan")
    "SCA_AF"   GADM("Afghanistan")
    "SCA_PK"   GADM("Pakistan")

    # India: "North","West","Central","South","East","Northeast"
    # https://en.wikipedia.org/wiki/Administrative_divisions_of_India
    # Excluding island groups: "Andaman and Nicobar Islands","Lakshadweep"
    # South also includes Sri Lanka
    # Northeast also includes Nepal,Bhutan and Bangladesh
    "IN_N"  GADM(["India"], "Jammu and Kashmir","Himachal Pradesh","Punjab","Rajasthan","Chandigarh","Haryana","NCT of Delhi","Uttarakhand","Uttar Pradesh")
    "IN_W"  GADM(["India"], "Gujarat","Goa","Maharashtra","Dadra and Nagar Haveli","Daman and Diu")
    "IN_C"  GADM(["India"], "Madhya Pradesh","Chhattisgarh")
    "IN_S"  (GADM(["India"], "Karnataka","Kerala","Tamil Nadu","Andhra Pradesh","Telangana","Puducherry"), GADM("Sri Lanka"))
    "IN_E"  GADM(["India"], "Odisha","Jharkhand","West Bengal","Bihar","Sikkim")
    "IN_NE" GADM(["India"], "Assam","Meghalaya","Tripura","Mizoram","Manipur","Nagaland","Arunachal Pradesh")

    # Southeast Asia: "Central Asia","South-Central Asia"
    # also includes Peninsular Malaysia,https://en.wikipedia.org/wiki/Peninsular_Malaysia
    "SEA_NB"   GADM("Nepal","Bhutan")
    "SEA_BD"   GADM("Bangladesh")
    "SEA_VLC"  GADM("Laos","Vietnam","Cambodia")
    "SEA_MM"   GADM("Myanmar")
    "SEA_TH"   GADM("Thailand")
    "SEA_MY"   (GADM("Singapore"), GADM(["Malaysia"], "Perlis","Kedah","Pulau Pinang","Perak","Kelantan","Trengganu","Pahang","Selangor","Kuala Lumpur","Putrajaya","Negeri Sembilan","Melaka","Johor"))

    # Russia: "Northwest","Central","Southwest","Volga","Ural","Siberia","East"
    # https://en.wikipedia.org/wiki/Federal_districts_of_Russia
    # questionable: Novgorod,Altay,Yevrey,Maga Buryatdan/Magadan
    "RU_NW"  GADM(["Russia"], "Arkhangel'sk","Vologda","Karelia","Komi","Leningrad","Murmansk","Nenets","Novgorod","Pskov","City of St. Petersburg")
    "RU_C"   GADM(["Russia"], "Belgorod","Bryansk","Vladimir","Voronezh","Ivanovo","Kaluga","Kostroma","Kursk","Lipetsk","Moscow City","Moskva","Orel","Ryazan'","Smolensk","Tambov","Tver'","Tula","Yaroslavl'")
    "RU_SW"  GADM(["Russia"], "Adygey","Astrakhan'","Volgograd","Kalmyk","Krasnodar","Rostov","Dagestan","Ingush","Kabardin-Balkar","Karachay-Cherkess","North Ossetia","Stavropol'","Chechnya")
    "RU_VL"  GADM(["Russia"], "Bashkortostan","Kirov","Mariy-El","Mordovia","Nizhegorod","Orenburg","Penza","Perm'","Samara","Saratov","Tatarstan","Udmurt","Ul'yanovsk","Chuvash")
    "RU_UR"  GADM(["Russia"], "Kurgan","Sverdlovsk","Tyumen'","Khanty-Mansiy","Chelyabinsk","Yamal-Nenets")
    "RU_SB"  GADM(["Russia"], "Irkutsk","Krasnoyarsk","Tuva")
    "RU_S"  GADM(["Russia"], "Altay","Gorno-Altay","Kemerovo","Novosibirsk","Omsk","Tomsk","Khakass")
    "RU_E"   GADM(["Russia"], "Amur","Buryat","Yevrey","Zabaykal'ye","Kamchatka","Maga Buryatdan","Primor'ye","Sakha","Sakhalin","Khabarovsk","Chukot")

    # China: "North" (Huáběi),"Northeast" (Dōngběi),"East" (Huádōng),"South Central" (Zhōngnán),"Southwest" (Xīnán),"Northwest" (Xīběi)
    # https://en.wikipedia.org/wiki/List_of_regions_of_China
    # East also includes Taiwan
    # South Central also includes Hong Kong and Macao
    "CH_N"    GADM(["China"], "Nei Mongol")
    "CH_NE"   GADM(["China"], "Liaoning","Jilin","Heilongjiang")
    "CH_CNE"  GADM(["China"], "Beijing","Tianjin","Hebei","Shanxi","Shandong")
    "CH_CSE"  (GADM(["China"], "Shanghai","Jiangsu","Zhejiang","Anhui","Fujian","Jiangxi"), GADM("Taiwan"))
    "CH_CS"   GADM(["China"], "Henan","Hubei","Hunan")
    "CH_CSW"  GADM(["China"], "Chongqing","Sichuan","Guizhou","Yunnan")
    "CH_CNW"  GADM(["China"], "Shaanxi","Gansu","Qinghai","Ningxia Hui")
    "CH_S"    (GADM(["China"], "Guangdong","Guangxi","Hainan"), GADM("Hong Kong","Macao"))
    "CH_TB"   GADM(["China"], "Xizang")
    "CH_NW"   GADM(["China"], "Xinjiang Uygur")

    # Other
    "MON"      GADM("Mongolia")
    "JKR_JP"    GADM("Japan")
    "JKR_NK"    GADM("North Korea")
    "JKR_SK"    GADM("South Korea")
]

max_stars_repo_name: henrikhodel/GlobalEnergyGIS

max_issues_repo_name: henrikhodel/GlobalEnergyGIS

max_forks_repo_name: henrikhodel/GlobalEnergyGIS


text:
"""
    HyperGradDescent

Descent method which minimizes the objective function in the direction
of antigradient at each step.
"""
mutable struct HyperGradDescent{T<:AbstractFloat,V<:AbstractVector{T}} <: OptBuffer
    x::V
    xpre::V
    g::V
    gpre::V
    y::T
    ypre::T
    α::T
    μ::T
end

function HyperGradDescent(x::AbstractVector{T}, α::Real, μ::Real) where {T}
    F = float(T)
    return HyperGradDescent(
        similar(x, F),
        similar(x, F),
        similar(x, F),
        similar(x, F),
        F(NaN),
        F(NaN),
        convert(F, α),
        convert(F, μ),
    )
end

HyperGradDescent(x::AbstractVector{T}) where {T} = HyperGradDescent(x, 0, 1e-4)

function init!(optfn!, M::HyperGradDescent{T}, x0; reset, kw...) where {T}
    reset != false && reset!(M, x0)
    optfn!(x0, zero(T), x0)
    fill!(M.gpre, false)
    return M
end

@inline function reset!(M::HyperGradDescent)
    M.α = false
    return M
end

function reset!(M::HyperGradDescent{T}, x0, α = zero(T), μ = M.μ) where {T}
    if length(M.x) != length(x0)
        foreach((M.x, M.g, M.gpre)) do v
            resize!(v, length(x0))
        end
    end
    M.α = α
    M.μ = μ
    return M
end

@inline function callfn!(fdf, M::HyperGradDescent, x, α, d)
    __update_arg!(M, x, α, d)
    y, g = fdf(M.x, M.g)
    __update_grad!(M, g)
    return y, g
end

function step!(optfn!, M::HyperGradDescent; constrain_step = infstep)
    M.gpre, M.g = M.g, M.gpre
    M.α += abs(M.μ * dot(M.g, M.gpre))
    d = rmul!(M.gpre, -1)
    maxstep = constrain_step(M.x, d)
    s = maxstep > M.α ? M.α : maxstep / 2
    optfn!(M.x, s, d)
    return M.α
end

@inline function __update_arg!(M::HyperGradDescent, x, α, d)
    map!(M.x, d, x) do a, b
        muladd(α, a, b)
    end
    return
end

@inline function __update_arg!(M::HyperGradDescent, x)
    if x !== M.x
        copy!(M.x, x)
    end
    return
end

@inline function __update_grad!(M::HyperGradDescent, g)
    if M.g !== g
        copy!(M.g, g)
    end
    return
end


text:
module LeastSquaresSVM

using LinearAlgebra
using KernelFunctions
using Krylov
import MLJModelInterface

const MMI = MLJModelInterface

export SVM, LSSVC, LSSVR, KernelRBF, svmtrain, svmtrain_mc, svmpredict, LSSVClassifier,
LSSVRegressor

include("types.jl")
include("utils.jl")
include("training.jl")
include("mlj_interface.jl")

end

max_stars_repo_name: gmagannaDevelop/Elysivm

max_issues_repo_name: gmagannaDevelop/Elysivm

max_forks_repo_name: gmagannaDevelop/Elysivm


text:
function get_material_matrix(matrix_input)
  input_path = ""
  if typeof(matrix_input) == String
    input_path = matrix_input
    material_matrix = file_to_matrix(matrix_input)
  else
    material_matrix = matrix_input
  end
  if size(material_matrix)[1] < 1 || size(material_matrix)[2] < 1
    println("ERROR: wrong input matrix")
    return
  end
  return input_path, material_matrix
end

function change_extension_to(path, new_ext)
  last_dot_position = findall(x -> x == '.', path)[end]
  if last_dot_position < 2
    println("ERROR: input_path: last_dot_position = $(last_dot_position) < 2")
  end
  return path[1:last_dot_position-1]*"."*new_ext
end

function image_to_EIS(
            matrix_input::Union{Array, String} = [1 1 0 1; 0 1 0 1; 0 1 0 1; 0 1 0 1],
            prms_pairs = [];
            #
            f_list="TPE",
            TPE_f_list = [2.0^n for n in -5 : 0.5 : 15],
            TPE_warning = true,
            #f_list=[2.0^i for i in -3:10],
            #
            complex_type=ComplexF64,
            iterative_solver = false,
            verbose = false,
            pyplot=true,
            return_R_RC=false,
            export_z_file="",
            #export_z_file="!use_file_name",
            save_also_image="",
            #save_also_image="!input",

            return_specific_impedance = true,
            store_R_RC=""
            )

  input_path, material_matrix = get_material_matrix(matrix_input)

  two_point_extrapolation = false
  if typeof(f_list)==String && (f_list == "two_point_extrapolation" || f_list == "TPE")
    two_point_extrapolation = true
    f_list = [0.1, 10000]
  end

  extract_R_RC = false
  if return_R_RC || two_point_extrapolation || store_R_RC != ""
    extract_R_RC = true
  end

  f_list, Z_list =  material_matrix_to_impedance(
    material_matrix,
    prms_pairs,
    #
    f_list = f_list,
    #
    complex_type=complex_type,
    iterative_solver = iterative_solver,
    verbose = verbose
  )

  if return_specific_impedance
    #normalize output
    dims = size(material_matrix)
    if length(dims) == 2
      Z_list .*= dims[1] / dims[2]
    else
      Z_list .*= dims[1]*dims[3] / dims[2]
    end
  end

  if extract_R_RC
    R_ohm, R, C = (1.0, 1.0, 1.0)
    if length(f_list) < 2
      println("ERROR: extract R_ohm, R, C: length(f_list) < 2, $(length(f_list)) < 2")
      return
    else
      omegas = 2*pi .* [f_list[1], f_list[end]]
      Zs = [Z_list[1], Z_list[end]]
      try
        R_ohm, R, C = get_R_RC_prms_from_2Z(omegas, Zs)
      catch
        println("ERROR: R_RC circuit evaluation failed for (Z1, Z2) = $(Zs)  ... returning (f_list, Z_list)\n")
        extract_R_RC = false
      end
    end
  end

  if two_point_extrapolation && extract_R_RC
    f_list = TPE_f_list
    Z_list = get_Z_from_R_RC(f_list, R_ohm, R, C)
    TPE_warning && println("WARNING: TPE (two_point_extrapolation) has been used!")
  end

  pyplot && nyquistPlot(Z_list)

  if store_R_RC != "" && extract_R_RC
    open(store_R_RC, "a") do f
      write(f, @sprintf("%s\t%s\t%E\t%E\t%E\n",
        Dates.now(),
        (input_path == "" ? "<matrix_input>" : input_path ),
        R_ohm, R, C)
      )
    end
  end

  if export_z_file == "!use_file_name"
    if input_path != ""
      export_EIS_to_Z_file(change_extension_to(input_path, "z"), f_list, Z_list)
    else
      println("ERROR: cannot export_z_file: input_path == \"\"!")
    end
  elseif export_z_file != ""

    export_EIS_to_Z_file(export_z_file, f_list, Z_list)

    if save_also_image == "!input" && input_path != ""
      cp(
        input_path,
        change_extension_to(export_z_file, input_path[end-2 : end]),
        force=true
      )
    elseif save_also_image != "" && length(size(material_matrix)) == 2
      matrix_to_file(save_also_image, material_matrix)
    end
  end

  if extract_R_RC && return_R_RC
    return R_ohm, R, C
  else
    return f_list, Z_list
  end
end

max_stars_repo_name: Masicko/ImageToEIS

max_issues_repo_name: Masicko/ImageToEIS

max_forks_repo_name: Masicko/ImageToEIS


text:
#=
This file defines a benchmark suite with the tools provided by
`PkgBenchmark` and `BenchmarkTools`.

To run the benchmarks, execute:

```julia
julia> using PkgBenchmark
julia> results = benchmarkpkg("LazySets")
```

To compare current version to another tagged version, commit or branch:

```julia
julia> results = judge("LazySets", <tagged-version-or-branch>)
```

To export the benchmark results to a Markdown file:

```julia
julia> export_markdown("results.md", results)
```

To export the benchmark results to a JSON file:

```julia
julia> writeresults("results.json", results)
```
=#
using BenchmarkTools, LazySets

@static if VERSION > v"0.7.0"
    using LinearAlgebra, SparseArrays
end

SUITE = BenchmarkGroup()  # parent BenchmarkGroup to contain our suite

include("support_vector.jl")
include("linear_map.jl")


text:
const tol = 10*eps()
const days_per_year = 365.2422
const global_base_date = Date(2000,1,1)
const global_base_date_as_day = convert(Dates.Day, global_base_date)

function years_between(a::Union{DateTime,Date}, b::Union{DateTime,Date})
    return (Dates.days(a) -Dates.days(b))/ days_per_year
end

function years_between(a::Dates.Day, b::Dates.Day)
    return (convert(Int, a)-convert(Int, b))/ days_per_year
end

function years_from_global_base(a::Union{DateTime,Date})
    return years_between(a, global_base_date)
end

function years_from_global_base(a::Dates.Day)
    return years_between(a, global_base_date_as_day)
end

"""
    Period length is designed to convert TimePeriod objects to a float in a consistent way to years_from_global_base
"""
function period_length(a::Dates.DatePeriod, base::Date = global_base_date)
    return years_between(base+a, base)
end


text:
@testset "5.3.5 u (a+b arctan(c+d x))^p" begin
    (a, b, c, d, e, f, m, x, ) = @variables a b c d e f m x

    #= ::Package:: =#

    #= ::Title:: =#
    #=Integrands*of*the*form*u*(a+b*atan(c+d*x))^p=#

    #= ::Section::Closed:: =#
    #=Integrands*of*the*form*(e+f*x)^m*(a+b*atan(c+d*x))^p=#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(e+f*x)^m*(a+b*atan(c+d*x))^p*when*d*e-c*f=0=#

    @test_int [(c*e + d*e*x)^3*(a + b*atan(c + d*x)), x, 6, (b*e^3*x)/4 - (b*e^3*(c + d*x)^3)/(12*d) - (b*e^3*atan(c + d*x))/(4*d) + (e^3*(c + d*x)^4*(a + b*atan(c + d*x)))/(4*d)]
    @test_int [(c*e + d*e*x)^2*(a + b*atan(c + d*x)), x, 6, -(b*e^2*(c + d*x)^2)/(6*d) + (e^2*(c + d*x)^3*(a + b*atan(c + d*x)))/(3*d) + (b*e^2*log(1 + (c + d*x)^2))/(6*d)]
    @test_int [(c*e + d*e*x)^1*(a + b*atan(c + d*x)), x, 5, -(b*e*x)/2 + (b*e*atan(c + d*x))/(2*d) + (e*(c + d*x)^2*(a + b*atan(c + d*x)))/(2*d)]
    @test_int [(a + b*atan(c + d*x))/(c*e + d*e*x)^1, x, 5, (a*log(c + d*x))/(d*e) + ((im/2)*b*PolyLog(2, (-im)*(c + d*x)))/(d*e) - ((im/2)*b*PolyLog(2, im*(c + d*x)))/(d*e)]
    @test_int [(a + b*atan(c + d*x))/(c*e + d*e*x)^2, x, 7, -((a + b*atan(c + d*x))/(d*e^2*(c + d*x))) + (b*log(c + d*x))/(d*e^2) - (b*log(1 + (c + d*x)^2))/(2*d*e^2)]
    @test_int [(a + b*atan(c + d*x))/(c*e + d*e*x)^3, x, 5, -b/(2*d*e^3*(c + d*x)) - (b*atan(c + d*x))/(2*d*e^3) - (a + b*atan(c + d*x))/(2*d*e^3*(c + d*x)^2)]

    @test_int [(c*e + d*e*x)^3*(a + b*atan(c + d*x))^2, x, 13, (a*b*e^3*x)/2 + (b^2*e^3*(c + d*x)^2)/(12*d) + (b^2*e^3*(c + d*x)*atan(c + d*x))/(2*d) - (b*e^3*(c + d*x)^3*(a + b*atan(c + d*x)))/(6*d) - (e^3*(a + b*atan(c + d*x))^2)/(4*d) + (e^3*(c + d*x)^4*(a + b*atan(c + d*x))^2)/(4*d) - (b^2*e^3*log(1 + (c + d*x)^2))/(3*d)]
    @test_int [(c*e + d*e*x)^2*(a + b*atan(c + d*x))^2, x, 11, (b^2*e^2*x)/3 - (b^2*e^2*atan(c + d*x))/(3*d) - (b*e^2*(c + d*x)^2*(a + b*atan(c + d*x)))/(3*d) - ((im/3)*e^2*(a + b*atan(c + d*x))^2)/d + (e^2*(c + d*x)^3*(a + b*atan(c + d*x))^2)/(3*d) - (2*b*e^2*(a + b*atan(c + d*x))*log(2/(1 + im*(c + d*x))))/(3*d) - ((im/3)*b^2*e^2*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/d]
    @test_int [(c*e + d*e*x)^1*(a + b*atan(c + d*x))^2, x, 8, -(a*b*e*x) - (b^2*e*(c + d*x)*atan(c + d*x))/d + (e*(a + b*atan(c + d*x))^2)/(2*d) + (e*(c + d*x)^2*(a + b*atan(c + d*x))^2)/(2*d) + (b^2*e*log(1 + (c + d*x)^2))/(2*d)]
    @test_int [(a + b*atan(c + d*x))^2/(c*e + d*e*x)^1, x, 8, (2*(a + b*atan(c + d*x))^2*atanh(1 - 2/(1 + im*(c + d*x))))/(d*e) - (im*b*(a + b*atan(c + d*x))*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/(d*e) + (im*b*(a + b*atan(c + d*x))*PolyLog(2, -1 + 2/(1 + im*(c + d*x))))/(d*e) - (b^2*PolyLog(3, 1 - 2/(1 + im*(c + d*x))))/(2*d*e) + (b^2*PolyLog(3, -1 + 2/(1 + im*(c + d*x))))/(2*d*e)]
    @test_int [(a + b*atan(c + d*x))^2/(c*e + d*e*x)^2, x, 6, ((-im)*(a + b*atan(c + d*x))^2)/(d*e^2) - (a + b*atan(c + d*x))^2/(d*e^2*(c + d*x)) + (2*b*(a + b*atan(c + d*x))*log(2 - 2/(1 - im*(c + d*x))))/(d*e^2) - (im*b^2*PolyLog(2, -1 + 2/(1 - im*(c + d*x))))/(d*e^2)]
    @test_int [(a + b*atan(c + d*x))^2/(c*e + d*e*x)^3, x, 10, -((b*(a + b*atan(c + d*x)))/(d*e^3*(c + d*x))) - (a + b*atan(c + d*x))^2/(2*d*e^3) - (a + b*atan(c + d*x))^2/(2*d*e^3*(c + d*x)^2) + (b^2*log(c + d*x))/(d*e^3) - (b^2*log(1 + (c + d*x)^2))/(2*d*e^3)]
    @test_int [(a + b*atan(c + d*x))^2/(c*e + d*e*x)^4, x, 10, -b^2/(3*d*e^4*(c + d*x)) - (b^2*atan(c + d*x))/(3*d*e^4) - (b*(a + b*atan(c + d*x)))/(3*d*e^4*(c + d*x)^2) + ((im/3)*(a + b*atan(c + d*x))^2)/(d*e^4) - (a + b*atan(c + d*x))^2/(3*d*e^4*(c + d*x)^3) - (2*b*(a + b*atan(c + d*x))*log(2 - 2/(1 - im*(c + d*x))))/(3*d*e^4) + ((im/3)*b^2*PolyLog(2, -1 + 2/(1 - im*(c + d*x))))/(d*e^4)]
    @test_int [(a + b*atan(c + d*x))^2/(c*e + d*e*x)^5, x, 15, -b^2/(12*d*e^5*(c + d*x)^2) - (b*(a + b*atan(c + d*x)))/(6*d*e^5*(c + d*x)^3) + (b*(a + b*atan(c + d*x)))/(2*d*e^5*(c + d*x)) + (a + b*atan(c + d*x))^2/(4*d*e^5) - (a + b*atan(c + d*x))^2/(4*d*e^5*(c + d*x)^4) - (2*b^2*log(c + d*x))/(3*d*e^5) + (b^2*log(1 + (c + d*x)^2))/(3*d*e^5)]

    @test_int [(c*e + d*e*x)^2*(a + b*atan(c + d*x))^3, x, 14, a*b^2*e^2*x + (b^3*e^2*(c + d*x)*atan(c + d*x))/d - (b*e^2*(a + b*atan(c + d*x))^2)/(2*d) - (b*e^2*(c + d*x)^2*(a + b*atan(c + d*x))^2)/(2*d) - ((im/3)*e^2*(a + b*atan(c + d*x))^3)/d + (e^2*(c + d*x)^3*(a + b*atan(c + d*x))^3)/(3*d) - (b*e^2*(a + b*atan(c + d*x))^2*log(2/(1 + im*(c + d*x))))/d - (b^3*e^2*log(1 + (c + d*x)^2))/(2*d) - (im*b^2*e^2*(a + b*atan(c + d*x))*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/d - (b^3*e^2*PolyLog(3, 1 - 2/(1 + im*(c + d*x))))/(2*d)]
    @test_int [(c*e + d*e*x)^1*(a + b*atan(c + d*x))^3, x, 10, (((-3*im)/2)*b*e*(a + b*atan(c + d*x))^2)/d - (3*b*e*(c + d*x)*(a + b*atan(c + d*x))^2)/(2*d) + (e*(a + b*atan(c + d*x))^3)/(2*d) + (e*(c + d*x)^2*(a + b*atan(c + d*x))^3)/(2*d) - (3*b^2*e*(a + b*atan(c + d*x))*log(2/(1 + im*(c + d*x))))/d - (((3*im)/2)*b^3*e*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/d]
    @test_int [(a + b*atan(c + d*x))^3/(c*e + d*e*x)^1, x, 10, (2*(a + b*atan(c + d*x))^3*atanh(1 - 2/(1 + im*(c + d*x))))/(d*e) - (((3*im)/2)*b*(a + b*atan(c + d*x))^2*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/(d*e) + (((3*im)/2)*b*(a + b*atan(c + d*x))^2*PolyLog(2, -1 + 2/(1 + im*(c + d*x))))/(d*e) - (3*b^2*(a + b*atan(c + d*x))*PolyLog(3, 1 - 2/(1 + im*(c + d*x))))/(2*d*e) + (3*b^2*(a + b*atan(c + d*x))*PolyLog(3, -1 + 2/(1 + im*(c + d*x))))/(2*d*e) + (((3*im)/4)*b^3*PolyLog(4, 1 - 2/(1 + im*(c + d*x))))/(d*e) - (((3*im)/4)*b^3*PolyLog(4, -1 + 2/(1 + im*(c + d*x))))/(d*e)]
    @test_int [(a + b*atan(c + d*x))^3/(c*e + d*e*x)^2, x, 7, ((-im)*(a + b*atan(c + d*x))^3)/(d*e^2) - (a + b*atan(c + d*x))^3/(d*e^2*(c + d*x)) + (3*b*(a + b*atan(c + d*x))^2*log(2 - 2/(1 - im*(c + d*x))))/(d*e^2) - ((3*im)*b^2*(a + b*atan(c + d*x))*PolyLog(2, -1 + 2/(1 - im*(c + d*x))))/(d*e^2) + (3*b^3*PolyLog(3, -1 + 2/(1 - im*(c + d*x))))/(2*d*e^2)]
    @test_int [(a + b*atan(c + d*x))^3/(c*e + d*e*x)^3, x, 9, (((-3*im)/2)*b*(a + b*atan(c + d*x))^2)/(d*e^3) - (3*b*(a + b*atan(c + d*x))^2)/(2*d*e^3*(c + d*x)) - (a + b*atan(c + d*x))^3/(2*d*e^3) - (a + b*atan(c + d*x))^3/(2*d*e^3*(c + d*x)^2) + (3*b^2*(a + b*atan(c + d*x))*log(2 - 2/(1 - im*(c + d*x))))/(d*e^3) - (((3*im)/2)*b^3*PolyLog(2, -1 + 2/(1 - im*(c + d*x))))/(d*e^3)]
    @test_int [(a + b*atan(c + d*x))^3/(c*e + d*e*x)^4, x, 16, -((b^2*(a + b*atan(c + d*x)))/(d*e^4*(c + d*x))) - (b*(a + b*atan(c + d*x))^2)/(2*d*e^4) - (b*(a + b*atan(c + d*x))^2)/(2*d*e^4*(c + d*x)^2) + ((im/3)*(a + b*atan(c + d*x))^3)/(d*e^4) - (a + b*atan(c + d*x))^3/(3*d*e^4*(c + d*x)^3) + (b^3*log(c + d*x))/(d*e^4) - (b^3*log(1 + (c + d*x)^2))/(2*d*e^4) - (b*(a + b*atan(c + d*x))^2*log(2 - 2/(1 - im*(c + d*x))))/(d*e^4) + (im*b^2*(a + b*atan(c + d*x))*PolyLog(2, -1 + 2/(1 - im*(c + d*x))))/(d*e^4) - (b^3*PolyLog(3, -1 + 2/(1 - im*(c + d*x))))/(2*d*e^4)]

    @test_int [atan(1 + x)/(2 + 2*x), x, 5, (1/4)*im*PolyLog(2, (-im)*(1 + x)) - (1/4)*im*PolyLog(2, im*(1 + x))]

    @test_int [atan(a + b*x)/((a*d)/b + d*x), x, 5, (im*PolyLog(2, (-im)*(a + b*x)))/(2*d) - (im*PolyLog(2, im*(a + b*x)))/(2*d)]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(e+f*x)^m*(a+b*atan(c+d*x))^(p/2)*when*d*e-c*f=0=#

    @test_int [(a + b*x)^2*atan(a + b*x)^(1/2), x, 0, Unintegrable((a + b*x)^2*sqrt(atan(a + b*x)), x)]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(e+f*x)^m*(a+b*atan(c+d*x))^p=#

    @test_int [(e + f*x)^3*(a + b*atan(c + d*x)), x, 7, -((b*f*(6*d^2*e^2 - 12*c*d*e*f - (1 - 6*c^2)*f^2)*x)/(4*d^3)) - (b*f^2*(d*e - c*f)*(c + d*x)^2)/(2*d^4) - (b*f^3*(c + d*x)^3)/(12*d^4) - (b*(d^4*e^4 - 4*c*d^3*e^3*f - 6*(1 - c^2)*d^2*e^2*f^2 + 4*c*(3 - c^2)*d*e*f^3 + (1 - 6*c^2 + c^4)*f^4)*atan(c + d*x))/(4*d^4*f) + ((e + f*x)^4*(a + b*atan(c + d*x)))/(4*f) - (b*(d*e - c*f)*(d*e + f - c*f)*(d*e - (1 + c)*f)*log(1 + (c + d*x)^2))/(2*d^4)]
    @test_int [(e + f*x)^2*(a + b*atan(c + d*x)), x, 7, -((b*f*(d*e - c*f)*x)/d^2) - (b*f^2*(c + d*x)^2)/(6*d^3) - (b*(d*e - c*f)*(d^2*e^2 - 2*c*d*e*f - (3 - c^2)*f^2)*atan(c + d*x))/(3*d^3*f) + ((e + f*x)^3*(a + b*atan(c + d*x)))/(3*f) - (b*(3*d^2*e^2 - 6*c*d*e*f - (1 - 3*c^2)*f^2)*log(1 + (c + d*x)^2))/(6*d^3)]
    @test_int [(e + f*x)^1*(a + b*atan(c + d*x)), x, 7, -((b*f*x)/(2*d)) - (b*(d*e + f - c*f)*(d*e - (1 + c)*f)*atan(c + d*x))/(2*d^2*f) + ((e + f*x)^2*(a + b*atan(c + d*x)))/(2*f) - (b*(d*e - c*f)*log(1 + (c + d*x)^2))/(2*d^2)]
    @test_int [(e + f*x)^0*(a + b*atan(c + d*x)), x, 4, a*x + (b*(c + d*x)*atan(c + d*x))/d - (b*log(1 + (c + d*x)^2))/(2*d)]
    @test_int [(a + b*atan(c + d*x))/(e + f*x)^1, x, 5, -(((a + b*atan(c + d*x))*log(2/(1 - im*(c + d*x))))/f) + ((a + b*atan(c + d*x))*log((2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/f + (im*b*PolyLog(2, 1 - 2/(1 - im*(c + d*x))))/(2*f) - (im*b*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/(2*f)]
    @test_int [(a + b*atan(c + d*x))/(e + f*x)^2, x, 8, (b*d*(d*e - c*f)*atan(c + d*x))/(f*(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)) - (a + b*atan(c + d*x))/(f*(e + f*x)) + (b*d*log(e + f*x))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) - (b*d*log(1 + c^2 + 2*c*d*x + d^2*x^2))/(2*(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2))]
    @test_int [(a + b*atan(c + d*x))/(e + f*x)^3, x, 9, -((b*d)/(2*(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)*(e + f*x))) + (b*d^2*(d*e + f - c*f)*(d*e - (1 + c)*f)*atan(c + d*x))/(2*f*(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)^2) - (a + b*atan(c + d*x))/(2*f*(e + f*x)^2) + (b*d^2*(d*e - c*f)*log(e + f*x))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)^2 - (b*d^2*(d*e - c*f)*log(1 + c^2 + 2*c*d*x + d^2*x^2))/(2*(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)^2)]

    @test_int [(e + f*x)^2*(a + b*atan(c + d*x))^2, x, 16, (b^2*f^2*x)/(3*d^2) - (2*a*b*f*(d*e - c*f)*x)/d^2 - (b^2*f^2*atan(c + d*x))/(3*d^3) - (2*b^2*f*(d*e - c*f)*(c + d*x)*atan(c + d*x))/d^3 - (b*f^2*(c + d*x)^2*(a + b*atan(c + d*x)))/(3*d^3) + (im*(3*d^2*e^2 - 6*c*d*e*f - (1 - 3*c^2)*f^2)*(a + b*atan(c + d*x))^2)/(3*d^3) - ((d*e - c*f)*(d^2*e^2 - 2*c*d*e*f - (3 - c^2)*f^2)*(a + b*atan(c + d*x))^2)/(3*d^3*f) + ((e + f*x)^3*(a + b*atan(c + d*x))^2)/(3*f) + (2*b*(3*d^2*e^2 - 6*c*d*e*f - (1 - 3*c^2)*f^2)*(a + b*atan(c + d*x))*log(2/(1 + im*(c + d*x))))/(3*d^3) + (b^2*f*(d*e - c*f)*log(1 + (c + d*x)^2))/d^3 + (im*b^2*(3*d^2*e^2 - 6*c*d*e*f - (1 - 3*c^2)*f^2)*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/(3*d^3)]
    @test_int [(e + f*x)^1*(a + b*atan(c + d*x))^2, x, 13, -((a*b*f*x)/d) - (b^2*f*(c + d*x)*atan(c + d*x))/d^2 + (im*(d*e - c*f)*(a + b*atan(c + d*x))^2)/d^2 - ((d*e + f - c*f)*(d*e - (1 + c)*f)*(a + b*atan(c + d*x))^2)/(2*d^2*f) + ((e + f*x)^2*(a + b*atan(c + d*x))^2)/(2*f) + (2*b*(d*e - c*f)*(a + b*atan(c + d*x))*log(2/(1 + im*(c + d*x))))/d^2 + (b^2*f*log(1 + (c + d*x)^2))/(2*d^2) + (im*b^2*(d*e - c*f)*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/d^2]
    @test_int [(e + f*x)^0*(a + b*atan(c + d*x))^2, x, 6, (im*(a + b*atan(c + d*x))^2)/d + ((c + d*x)*(a + b*atan(c + d*x))^2)/d + (2*b*(a + b*atan(c + d*x))*log(2/(1 + im*(c + d*x))))/d + (im*b^2*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/d]
    @test_int [(a + b*atan(c + d*x))^2/(e + f*x)^1, x, 2, -(((a + b*atan(c + d*x))^2*log(2/(1 - im*(c + d*x))))/f) + ((a + b*atan(c + d*x))^2*log((2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/f + (im*b*(a + b*atan(c + d*x))*PolyLog(2, 1 - 2/(1 - im*(c + d*x))))/f - (im*b*(a + b*atan(c + d*x))*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/f - (b^2*PolyLog(3, 1 - 2/(1 - im*(c + d*x))))/(2*f) + (b^2*PolyLog(3, 1 - (2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/(2*f)]
    @test_int [(a + b*atan(c + d*x))^2/(e + f*x)^2, x, 25, (2*a*b*d*(d*e - c*f)*atan(c + d*x))/(f*(f^2 + (d*e - c*f)^2)) + (im*b^2*d*atan(c + d*x)^2)/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) + (b^2*d*(d*e - c*f)*atan(c + d*x)^2)/(f*(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)) - (a + b*atan(c + d*x))^2/(f*(e + f*x)) + (2*a*b*d*log(e + f*x))/(f^2 + (d*e - c*f)^2) - (2*b^2*d*atan(c + d*x)*log(2/(1 - im*(c + d*x))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) + (2*b^2*d*atan(c + d*x)*log((2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) + (2*b^2*d*atan(c + d*x)*log(2/(1 + im*(c + d*x))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) - (a*b*d*log(1 + (c + d*x)^2))/(f^2 + (d*e - c*f)^2) + (im*b^2*d*PolyLog(2, 1 - 2/(1 - im*(c + d*x))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) - (im*b^2*d*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) + (im*b^2*d*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)]

    @test_int [(e + f*x)^2*(a + b*atan(c + d*x))^3, x, 21, (a*b^2*f^2*x)/d^2 + (b^3*f^2*(c + d*x)*atan(c + d*x))/d^3 - (b*f^2*(a + b*atan(c + d*x))^2)/(2*d^3) - (3*im*b*f*(d*e - c*f)*(a + b*atan(c + d*x))^2)/d^3 - (3*b*f*(d*e - c*f)*(c + d*x)*(a + b*atan(c + d*x))^2)/d^3 - (b*f^2*(c + d*x)^2*(a + b*atan(c + d*x))^2)/(2*d^3) + (im*(3*d^2*e^2 - 6*c*d*e*f - (1 - 3*c^2)*f^2)*(a + b*atan(c + d*x))^3)/(3*d^3) - ((d*e - c*f)*(d^2*e^2 - 2*c*d*e*f - (3 - c^2)*f^2)*(a + b*atan(c + d*x))^3)/(3*d^3*f) + ((e + f*x)^3*(a + b*atan(c + d*x))^3)/(3*f) - (6*b^2*f*(d*e - c*f)*(a + b*atan(c + d*x))*log(2/(1 + im*(c + d*x))))/d^3 + (b*(3*d^2*e^2 - 6*c*d*e*f - (1 - 3*c^2)*f^2)*(a + b*atan(c + d*x))^2*log(2/(1 + im*(c + d*x))))/d^3 - (b^3*f^2*log(1 + (c + d*x)^2))/(2*d^3) - (3*im*b^3*f*(d*e - c*f)*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/d^3 + (im*b^2*(3*d^2*e^2 - 6*c*d*e*f - (1 - 3*c^2)*f^2)*(a + b*atan(c + d*x))*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/d^3 + (b^3*(3*d^2*e^2 - 6*c*d*e*f - (1 - 3*c^2)*f^2)*PolyLog(3, 1 - 2/(1 + im*(c + d*x))))/(2*d^3)]
    @test_int [(e + f*x)^1*(a + b*atan(c + d*x))^3, x, 15, -((3*im*b*f*(a + b*atan(c + d*x))^2)/(2*d^2)) - (3*b*f*(c + d*x)*(a + b*atan(c + d*x))^2)/(2*d^2) + (im*(d*e - c*f)*(a + b*atan(c + d*x))^3)/d^2 - ((d*e + f - c*f)*(d*e - (1 + c)*f)*(a + b*atan(c + d*x))^3)/(2*d^2*f) + ((e + f*x)^2*(a + b*atan(c + d*x))^3)/(2*f) - (3*b^2*f*(a + b*atan(c + d*x))*log(2/(1 + im*(c + d*x))))/d^2 + (3*b*(d*e - c*f)*(a + b*atan(c + d*x))^2*log(2/(1 + im*(c + d*x))))/d^2 - (3*im*b^3*f*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/(2*d^2) + (3*im*b^2*(d*e - c*f)*(a + b*atan(c + d*x))*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/d^2 + (3*b^3*(d*e - c*f)*PolyLog(3, 1 - 2/(1 + im*(c + d*x))))/(2*d^2)]
    @test_int [(e + f*x)^0*(a + b*atan(c + d*x))^3, x, 6, (im*(a + b*atan(c + d*x))^3)/d + ((c + d*x)*(a + b*atan(c + d*x))^3)/d + (3*b*(a + b*atan(c + d*x))^2*log(2/(1 + im*(c + d*x))))/d + (3*im*b^2*(a + b*atan(c + d*x))*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/d + (3*b^3*PolyLog(3, 1 - 2/(1 + im*(c + d*x))))/(2*d)]
    @test_int [(a + b*atan(c + d*x))^3/(e + f*x)^1, x, 2, -(((a + b*atan(c + d*x))^3*log(2/(1 - im*(c + d*x))))/f) + ((a + b*atan(c + d*x))^3*log((2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/f + (3*im*b*(a + b*atan(c + d*x))^2*PolyLog(2, 1 - 2/(1 - im*(c + d*x))))/(2*f) - (3*im*b*(a + b*atan(c + d*x))^2*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/(2*f) - (3*b^2*(a + b*atan(c + d*x))*PolyLog(3, 1 - 2/(1 - im*(c + d*x))))/(2*f) + (3*b^2*(a + b*atan(c + d*x))*PolyLog(3, 1 - (2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/(2*f) - (3*im*b^3*PolyLog(4, 1 - 2/(1 - im*(c + d*x))))/(4*f) + (3*im*b^3*PolyLog(4, 1 - (2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/(4*f)]
    @test_int [(a + b*atan(c + d*x))^3/(e + f*x)^2, x, 35, (3*a^2*b*d*(d*e - c*f)*atan(c + d*x))/(f*(f^2 + (d*e - c*f)^2)) + (3*im*a*b^2*d*atan(c + d*x)^2)/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) + (3*a*b^2*d*(d*e - c*f)*atan(c + d*x)^2)/(f*(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)) + (im*b^3*d*atan(c + d*x)^3)/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) + (b^3*d*(d*e - c*f)*atan(c + d*x)^3)/(f*(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)) - (a + b*atan(c + d*x))^3/(f*(e + f*x)) + (3*a^2*b*d*log(e + f*x))/(f^2 + (d*e - c*f)^2) - (6*a*b^2*d*atan(c + d*x)*log(2/(1 - im*(c + d*x))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) - (3*b^3*d*atan(c + d*x)^2*log(2/(1 - im*(c + d*x))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) + (6*a*b^2*d*atan(c + d*x)*log((2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) + (3*b^3*d*atan(c + d*x)^2*log((2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) + (6*a*b^2*d*atan(c + d*x)*log(2/(1 + im*(c + d*x))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) + (3*b^3*d*atan(c + d*x)^2*log(2/(1 + im*(c + d*x))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) - (3*a^2*b*d*log(1 + (c + d*x)^2))/(2*(f^2 + (d*e - c*f)^2)) + (3*im*a*b^2*d*PolyLog(2, 1 - 2/(1 - im*(c + d*x))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) + (3*im*b^3*d*atan(c + d*x)*PolyLog(2, 1 - 2/(1 - im*(c + d*x))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) - (3*im*a*b^2*d*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) - (3*im*b^3*d*atan(c + d*x)*PolyLog(2, 1 - (2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) + (3*im*a*b^2*d*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) + (3*im*b^3*d*atan(c + d*x)*PolyLog(2, 1 - 2/(1 + im*(c + d*x))))/(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2) - (3*b^3*d*PolyLog(3, 1 - 2/(1 - im*(c + d*x))))/(2*(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)) + (3*b^3*d*PolyLog(3, 1 - (2*d*(e + f*x))/((d*e + im*f - c*f)*(1 - im*(c + d*x)))))/(2*(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2)) + (3*b^3*d*PolyLog(3, 1 - 2/(1 + im*(c + d*x))))/(2*(d^2*e^2 - 2*c*d*e*f + (1 + c^2)*f^2))]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(e+f*x)^m*(a+b*atan(c+d*x))^p*with*m*symbolic=#

    @test_int [(e + f*x)^m*(a + b*atan(c + d*x))^1, x, 6, ((e + f*x)^(1 + m)*(a + b*atan(c + d*x)))/(f*(1 + m)) - (im*b*d*(e + f*x)^(2 + m)*HypergeometricFunctions._₂F₁(1, 2 + m, 3 + m, (d*(e + f*x))/(d*e + im*f - c*f)))/(2*f*(d*e + (im - c)*f)*(1 + m)*(2 + m)) + (im*b*d*(e + f*x)^(2 + m)*HypergeometricFunctions._₂F₁(1, 2 + m, 3 + m, (d*(e + f*x))/(d*e - (im + c)*f)))/(2*f*(d*e - (im + c)*f)*(1 + m)*(2 + m))]
    @test_int [(e + f*x)^m*(a + b*atan(c + d*x))^2, x, 1, Unintegrable((e + f*x)^m*(a + b*atan(c + d*x))^2, x)]
    @test_int [(e + f*x)^m*(a + b*atan(c + d*x))^3, x, 1, Unintegrable((e + f*x)^m*(a + b*atan(c + d*x))^3, x)]

    #= ::Section::Closed:: =#
    #=Integrands*of*the*form*AF(x)*(a+b*atan(c+d*x))^p=#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*x^m*atan(a+b*x)^p=#

    #= ::Subsubsection::Closed:: =#
    #=n>0=#

    @test_int [x^3*atan(a + b*x), x, 7, ((1 - 6*a^2)*x)/(4*b^3) + (a*(a + b*x)^2)/(2*b^4) - (a + b*x)^3/(12*b^4) - ((1 - 6*a^2 + a^4)*atan(a + b*x))/(4*b^4) + (1/4)*x^4*atan(a + b*x) - (a*(1 - a^2)*log(1 + (a + b*x)^2))/(2*b^4)]
    @test_int [x^2*atan(a + b*x), x, 7, (a*x)/b^2 - (a + b*x)^2/(6*b^3) - (a*(3 - a^2)*atan(a + b*x))/(3*b^3) + (1/3)*x^3*atan(a + b*x) + ((1 - 3*a^2)*log(1 + (a + b*x)^2))/(6*b^3)]
    @test_int [x^1*atan(a + b*x), x, 7, -(x/(2*b)) + ((1 - a^2)*atan(a + b*x))/(2*b^2) + (1/2)*x^2*atan(a + b*x) + (a*log(1 + (a + b*x)^2))/(2*b^2)]
    @test_int [x^0*atan(a + b*x), x, 3, ((a + b*x)*atan(a + b*x))/b - log(1 + (a + b*x)^2)/(2*b)]
    @test_int [atan(a + b*x)/x^1, x, 5, (-atan(a + b*x))*log(2/(1 - im*(a + b*x))) + atan(a + b*x)*log((2*b*x)/((im - a)*(1 - im*(a + b*x)))) + (1/2)*im*PolyLog(2, 1 - 2/(1 - im*(a + b*x))) - (1/2)*im*PolyLog(2, 1 - (2*b*x)/((im - a)*(1 - im*(a + b*x))))]
    @test_int [atan(a + b*x)/x^2, x, 7, -((a*b*atan(a + b*x))/(1 + a^2)) - atan(a + b*x)/x + (b*log(x))/(1 + a^2) - (b*log(1 + (a + b*x)^2))/(2*(1 + a^2))]
    @test_int [atan(a + b*x)/x^3, x, 8, -(b/(2*(1 + a^2)*x)) - ((1 - a^2)*b^2*atan(a + b*x))/(2*(1 + a^2)^2) - atan(a + b*x)/(2*x^2) - (a*b^2*log(x))/(1 + a^2)^2 + (a*b^2*log(1 + (a + b*x)^2))/(2*(1 + a^2)^2)]
    @test_int [atan(a + b*x)/x^4, x, 8, -(b/(6*(1 + a^2)*x^2)) + (2*a*b^2)/(3*(1 + a^2)^2*x) + (a*(3 - a^2)*b^3*atan(a + b*x))/(3*(1 + a^2)^3) - atan(a + b*x)/(3*x^3) - ((1 - 3*a^2)*b^3*log(x))/(3*(1 + a^2)^3) + ((1 - 3*a^2)*b^3*log(1 + (a + b*x)^2))/(6*(1 + a^2)^3)]

    #= ::Subsubsection:: =#
    #=n<0=#

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(c+d*x^n)*atan(a+b*x)=#

    @test_int [atan(a + b*x)/(c + d*x^3), x, 23, -((im*log(1 + im*a + im*b*x)*log((b*(c^(1/3) + d^(1/3)*x))/(b*c^(1/3) + (im - a)*d^(1/3))))/(6*c^(2/3)*d^(1/3))) + (im*log(1 - im*a - im*b*x)*log((b*(c^(1/3) + d^(1/3)*x))/(b*c^(1/3) - (im + a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) + ((-1)^(1/6)*log(1 + im*a + im*b*x)*log((b*(c^(1/3) - (-1)^(1/3)*d^(1/3)*x))/(b*c^(1/3) - (-1)^(1/3)*(im - a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) - ((-1)^(1/6)*log(1 - im*a - im*b*x)*log((b*(c^(1/3) - (-1)^(1/3)*d^(1/3)*x))/(b*c^(1/3) + (-1)^(1/3)*(im + a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) + ((-1)^(5/6)*log(1 + im*a + im*b*x)*log((b*(c^(1/3) + (-1)^(2/3)*d^(1/3)*x))/(b*c^(1/3) + (-1)^(2/3)*(im - a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) - ((-1)^(5/6)*log(1 - im*a - im*b*x)*log((b*(c^(1/3) + (-1)^(2/3)*d^(1/3)*x))/(b*c^(1/3) + (-1)^(1/6)*(1 - im*a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) - (im*PolyLog(2, (d^(1/3)*(im - a - b*x))/(b*c^(1/3) + (im - a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) + ((-1)^(5/6)*PolyLog(2, -(((-1)^(1/6)*d^(1/3)*(im - a - b*x))/(im*b*c^(1/3) - (-1)^(1/6)*(im - a)*d^(1/3)))))/(6*c^(2/3)*d^(1/3)) + ((-1)^(1/6)*PolyLog(2, -(((-1)^(1/3)*d^(1/3)*(im - a - b*x))/(b*c^(1/3) - (-1)^(1/3)*(im - a)*d^(1/3)))))/(6*c^(2/3)*d^(1/3)) + (im*PolyLog(2, -((d^(1/3)*(im + a + b*x))/(b*c^(1/3) - (im + a)*d^(1/3)))))/(6*c^(2/3)*d^(1/3)) - ((-1)^(1/6)*PolyLog(2, ((-1)^(1/3)*d^(1/3)*(im + a + b*x))/(b*c^(1/3) + (-1)^(1/3)*(im + a)*d^(1/3))))/(6*c^(2/3)*d^(1/3)) - ((-1)^(5/6)*PolyLog(2, -(((-1)^(2/3)*d^(1/3)*(im + a + b*x))/(b*c^(1/3) - (-1)^(2/3)*(im + a)*d^(1/3)))))/(6*c^(2/3)*d^(1/3))]
    @test_int [atan(a + b*x)/(c + d*x^2), x, 17, -((im*log(1 + im*a + im*b*x)*log((b*(sqrt(-c) - sqrt(d)*x))/(b*sqrt(-c) - (im - a)*sqrt(d))))/(4*sqrt(-c)*sqrt(d))) + (im*log(1 - im*a - im*b*x)*log((b*(sqrt(-c) - sqrt(d)*x))/(b*sqrt(-c) + (im + a)*sqrt(d))))/(4*sqrt(-c)*sqrt(d)) + (im*log(1 + im*a + im*b*x)*log((b*(sqrt(-c) + sqrt(d)*x))/(b*sqrt(-c) + (im - a)*sqrt(d))))/(4*sqrt(-c)*sqrt(d)) - (im*log(1 - im*a - im*b*x)*log((b*(sqrt(-c) + sqrt(d)*x))/(b*sqrt(-c) - (im + a)*sqrt(d))))/(4*sqrt(-c)*sqrt(d)) - (im*PolyLog(2, -((sqrt(d)*(im - a - b*x))/(b*sqrt(-c) - (im - a)*sqrt(d)))))/(4*sqrt(-c)*sqrt(d)) + (im*PolyLog(2, (sqrt(d)*(im - a - b*x))/(b*sqrt(-c) + (im - a)*sqrt(d))))/(4*sqrt(-c)*sqrt(d)) - (im*PolyLog(2, -((sqrt(d)*(im + a + b*x))/(b*sqrt(-c) - (im + a)*sqrt(d)))))/(4*sqrt(-c)*sqrt(d)) + (im*PolyLog(2, (sqrt(d)*(im + a + b*x))/(b*sqrt(-c) + (im + a)*sqrt(d))))/(4*sqrt(-c)*sqrt(d))]
    @test_int [atan(a + b*x)/(c + d*x), x, 5, -((atan(a + b*x)*log(2/(1 - im*(a + b*x))))/d) + (atan(a + b*x)*log((2*b*(c + d*x))/((b*c + im*d - a*d)*(1 - im*(a + b*x)))))/d + (im*PolyLog(2, 1 - 2/(1 - im*(a + b*x))))/(2*d) - (im*PolyLog(2, 1 - (2*b*(c + d*x))/((b*c + im*d - a*d)*(1 - im*(a + b*x)))))/(2*d)]
    @test_int [atan(a + b*x)/(c + d/x), x, 15, -(((1 + im*a + im*b*x)*log(1 + im*a + im*b*x))/(2*b*c)) - ((1 - im*a - im*b*x)*log((-im)*(im + a + b*x)))/(2*b*c) - (im*d*log(1 - im*a - im*b*x)*log(-((b*(d + c*x))/((im + a)*c - b*d))))/(2*c^2) + (im*d*log(1 + im*a + im*b*x)*log((b*(d + c*x))/((im - a)*c + b*d)))/(2*c^2) + (im*d*PolyLog(2, (c*(im - a - b*x))/(im*c - a*c + b*d)))/(2*c^2) - (im*d*PolyLog(2, (c*(im + a + b*x))/((im + a)*c - b*d)))/(2*c^2)]
    @test_int [atan(a + b*x)/(c + d/x^2), x, 25, -(((1 + im*a + im*b*x)*log(1 + im*a + im*b*x))/(2*b*c)) - ((1 - im*a - im*b*x)*log((-im)*(im + a + b*x)))/(2*b*c) + (im*sqrt(d)*log(1 + im*a + im*b*x)*log(-((b*(sqrt(d) - sqrt(-c)*x))/(im*sqrt(-c) - a*sqrt(-c) - b*sqrt(d)))))/(4*(-c)^(3/2)) - (im*sqrt(d)*log(1 - im*a - im*b*x)*log((b*(sqrt(d) - sqrt(-c)*x))/(im*sqrt(-c) + a*sqrt(-c) + b*sqrt(d))))/(4*(-c)^(3/2)) + (im*sqrt(d)*log(1 - im*a - im*b*x)*log(-((b*(sqrt(d) + sqrt(-c)*x))/((im + a)*sqrt(-c) - b*sqrt(d)))))/(4*(-c)^(3/2)) - (im*sqrt(d)*log(1 + im*a + im*b*x)*log((b*(sqrt(d) + sqrt(-c)*x))/(im*sqrt(-c) - a*sqrt(-c) + b*sqrt(d))))/(4*(-c)^(3/2)) + (im*sqrt(d)*PolyLog(2, (sqrt(-c)*(im - a - b*x))/(im*sqrt(-c) - a*sqrt(-c) - b*sqrt(d))))/(4*(-c)^(3/2)) - (im*sqrt(d)*PolyLog(2, (sqrt(-c)*(1 + im*a + im*b*x))/((1 + im*a)*sqrt(-c) - im*b*sqrt(d))))/(4*(-c)^(3/2)) + (im*sqrt(d)*PolyLog(2, (sqrt(-c)*(im + a + b*x))/(im*sqrt(-c) + a*sqrt(-c) - b*sqrt(d))))/(4*(-c)^(3/2)) - (im*sqrt(d)*PolyLog(2, (sqrt(-c)*(im + a + b*x))/(im*sqrt(-c) + a*sqrt(-c) + b*sqrt(d))))/(4*(-c)^(3/2))]
    @test_int [atan(a + b*x)/(c + d/x^3), x, 31, -(((1 + im*a + im*b*x)*log(1 + im*a + im*b*x))/(2*b*c)) - ((1 - im*a - im*b*x)*log((-im)*(im + a + b*x)))/(2*b*c) - (im*d^(1/3)*log(1 - im*a - im*b*x)*log(-((b*(d^(1/3) + c^(1/3)*x))/((im + a)*c^(1/3) - b*d^(1/3)))))/(6*c^(4/3)) + (im*d^(1/3)*log(1 + im*a + im*b*x)*log((b*(d^(1/3) + c^(1/3)*x))/((im - a)*c^(1/3) + b*d^(1/3))))/(6*c^(4/3)) - ((-1)^(1/6)*d^(1/3)*log(1 + im*a + im*b*x)*log(-((b*(d^(1/3) - (-1)^(1/3)*c^(1/3)*x))/((-1)^(1/3)*(im - a)*c^(1/3) - b*d^(1/3)))))/(6*c^(4/3)) + ((-1)^(1/6)*d^(1/3)*log(1 - im*a - im*b*x)*log((b*(d^(1/3) - (-1)^(1/3)*c^(1/3)*x))/((-1)^(1/3)*(im + a)*c^(1/3) + b*d^(1/3))))/(6*c^(4/3)) - ((-1)^(5/6)*d^(1/3)*log(1 + im*a + im*b*x)*log((b*(d^(1/3) + (-1)^(2/3)*c^(1/3)*x))/((-1)^(2/3)*(im - a)*c^(1/3) + b*d^(1/3))))/(6*c^(4/3)) + ((-1)^(5/6)*d^(1/3)*log(1 - im*a - im*b*x)*log((b*(d^(1/3) + (-1)^(2/3)*c^(1/3)*x))/((-1)^(1/6)*(1 - im*a)*c^(1/3) + b*d^(1/3))))/(6*c^(4/3)) - ((-1)^(1/6)*d^(1/3)*PolyLog(2, ((-1)^(1/3)*c^(1/3)*(im - a - b*x))/((-1)^(1/3)*(im - a)*c^(1/3) - b*d^(1/3))))/(6*c^(4/3)) - ((-1)^(5/6)*d^(1/3)*PolyLog(2, ((-1)^(1/6)*c^(1/3)*(im - a - b*x))/((-1)^(1/6)*(im - a)*c^(1/3) - im*b*d^(1/3))))/(6*c^(4/3)) + (im*d^(1/3)*PolyLog(2, (c^(1/3)*(im - a - b*x))/((im - a)*c^(1/3) + b*d^(1/3))))/(6*c^(4/3)) - (im*d^(1/3)*PolyLog(2, (c^(1/3)*(im + a + b*x))/((im + a)*c^(1/3) - b*d^(1/3))))/(6*c^(4/3)) + ((-1)^(5/6)*d^(1/3)*PolyLog(2, ((-1)^(2/3)*c^(1/3)*(im + a + b*x))/((-1)^(2/3)*(im + a)*c^(1/3) - b*d^(1/3))))/(6*c^(4/3)) + ((-1)^(1/6)*d^(1/3)*PolyLog(2, ((-1)^(1/3)*c^(1/3)*(im + a + b*x))/((-1)^(1/3)*(im + a)*c^(1/3) + b*d^(1/3))))/(6*c^(4/3))]

    #= [atan(a + b*x)/(a + b*x^(3/2)), x, 41, ((im/3)*log(-a^(1/3) - b^(1/3)*sqrt(x))*log((sqrt(-im - a) - sqrt(b)*sqrt(x))/(sqrt(-im - a) + a^(1/3)*b^(1/6))))/(a^(1/3)*b^(2/3)) - ((-1)^(1/6)*log((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x))*log((sqrt(-im - a) - sqrt(b)*sqrt(x))/(sqrt(-im - a) - (-1)^(1/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) - ((-1)^(5/6)*log(-((-1)^(2/3)*a^(1/3)) - b^(1/3)*sqrt(x))*log((sqrt(-im - a) - sqrt(b)*sqrt(x))/(sqrt(-im - a) + (-1)^(2/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) + ((-1)^(1/6)*log((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x))*log(-(((-1)^(3/4)*((-1)^(1/4)*sqrt(1 + im*a) - sqrt(b)*sqrt(x)))/(sqrt(1 + im*a) - (-1)^(1/12)*a^(1/3)*b^(1/6)))))/(3*a^(1/3)*b^(2/3)) + ((-1)^(5/6)*log(-((-1)^(2/3)*a^(1/3)) - b^(1/3)*sqrt(x))*log(-(((-1)^(3/4)*((-1)^(1/4)*sqrt(1 + im*a) - sqrt(b)*sqrt(x)))/(sqrt(1 + im*a) + (-1)^(5/12)*a^(1/3)*b^(1/6)))))/(3*a^(1/3)*b^(2/3)) + ((im/3)*log(-a^(1/3) - b^(1/3)*sqrt(x))*log((sqrt(-im - a) + sqrt(b)*sqrt(x))/(sqrt(-im - a) - a^(1/3)*b^(1/6))))/(a^(1/3)*b^(2/3)) - ((-1)^(1/6)*log((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x))*log((sqrt(-im - a) + sqrt(b)*sqrt(x))/(sqrt(-im - a) + (-1)^(1/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) - ((-1)^(5/6)*log(-((-1)^(2/3)*a^(1/3)) - b^(1/3)*sqrt(x))*log((sqrt(-im - a) + sqrt(b)*sqrt(x))/(sqrt(-im - a) - (-1)^(2/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) - ((im/3)*log(-a^(1/3) - b^(1/3)*sqrt(x))*log(((-1)^(1/4)*sqrt(1 + im*a) + sqrt(b)*sqrt(x))/((-1)^(1/4)*sqrt(1 + im*a) - a^(1/3)*b^(1/6))))/(a^(1/3)*b^(2/3)) + ((-1)^(1/6)*log((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x))*log((sqrt(1 + im*a) - (-1)^(3/4)*sqrt(b)*sqrt(x))/(sqrt(1 + im*a) + (-1)^(1/12)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) + ((-1)^(5/6)*log(-((-1)^(2/3)*a^(1/3)) - b^(1/3)*sqrt(x))*log((sqrt(1 + im*a) - (-1)^(3/4)*sqrt(b)*sqrt(x))/(sqrt(1 + im*a) - (-1)^(5/12)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) - ((im/3)*log(-a^(1/3) - b^(1/3)*sqrt(x))*log(((-1)^(1/4)*(sqrt(1 + im*a) + (-1)^(3/4)*sqrt(b)*sqrt(x)))/((-1)^(1/4)*sqrt(1 + im*a) + a^(1/3)*b^(1/6))))/(a^(1/3)*b^(2/3)) + ((im/3)*log(-a^(1/3) - b^(1/3)*sqrt(x))*log(1 + im*a + im*b*x))/(a^(1/3)*b^(2/3)) - ((-1)^(1/6)*log((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x))*log(1 + im*a + im*b*x))/(3*a^(1/3)*b^(2/3)) - ((-1)^(5/6)*log(-((-1)^(2/3)*a^(1/3)) - b^(1/3)*sqrt(x))*log(1 + im*a + im*b*x))/(3*a^(1/3)*b^(2/3)) - ((im/3)*log(-a^(1/3) - b^(1/3)*sqrt(x))*log((-im)*(im + a + b*x)))/(a^(1/3)*b^(2/3)) + ((-1)^(1/6)*log((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x))*log((-im)*(im + a + b*x)))/(3*a^(1/3)*b^(2/3)) + ((-1)^(5/6)*log(-((-1)^(2/3)*a^(1/3)) - b^(1/3)*sqrt(x))*log((-im)*(im + a + b*x)))/(3*a^(1/3)*b^(2/3)) - ((-1)^(1/6)*PolyLog(2, -((b^(1/6)*((-1)^(1/3)*a^(1/3) - b^(1/3)*sqrt(x)))/(sqrt(-im - a) - (-1)^(1/3)*a^(1/3)*b^(1/6)))))/(3*a^(1/3)*b^(2/3)) + ((im/3)*PolyLog(2, -((b^(1/6)*(a^(1/3) + b^(1/3)*sqrt(x)))/(sqrt(-im - a) - a^(1/3)*b^(1/6)))))/(a^(1/3)*b^(2/3)) - ((im/3)*PolyLog(2, -((b^(1/6)*(a^(1/3) + b^(1/3)*sqrt(x)))/((-1)^(1/4)*sqrt(1 + im*a) - a^(1/3)*b^(1/6)))))/(a^(1/3)*b^(2/3)) + ((im/3)*PolyLog(2, (b^(1/6)*(a^(1/3) + b^(1/3)*sqrt(x)))/(sqrt(-im - a) + a^(1/3)*b^(1/6))))/(a^(1/3)*b^(2/3)) - ((im/3)*PolyLog(2, (b^(1/6)*(a^(1/3) + b^(1/3)*sqrt(x)))/((-1)^(1/4)*sqrt(1 + im*a) + a^(1/3)*b^(1/6))))/(a^(1/3)*b^(2/3)) + ((-1)^(5/6)*PolyLog(2, ((-1)^(3/4)*b^(1/6)*((-1)^(2/3)*a^(1/3) + b^(1/3)*sqrt(x)))/(sqrt(1 + im*a) - (-1)^(5/12)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) - ((-1)^(5/6)*PolyLog(2, -((b^(1/6)*((-1)^(2/3)*a^(1/3) + b^(1/3)*sqrt(x)))/(sqrt(-im - a) - (-1)^(2/3)*a^(1/3)*b^(1/6)))))/(3*a^(1/3)*b^(2/3)) - ((-1)^(5/6)*PolyLog(2, (b^(1/6)*((-1)^(2/3)*a^(1/3) + b^(1/3)*sqrt(x)))/(sqrt(-im - a) + (-1)^(2/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) + ((-1)^(5/6)*PolyLog(2, ((-1)^(5/12)*b^(1/6)*(a^(1/3) - (-1)^(1/3)*b^(1/3)*sqrt(x)))/(sqrt(1 + im*a) + (-1)^(5/12)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) + ((-1)^(1/6)*PolyLog(2, ((-1)^(1/12)*b^(1/6)*(a^(1/3) + (-1)^(2/3)*b^(1/3)*sqrt(x)))/(sqrt(1 + im*a) + (-1)^(1/12)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) - ((-1)^(1/6)*PolyLog(2, ((-1)^(1/3)*b^(1/6)*(a^(1/3) + (-1)^(2/3)*b^(1/3)*sqrt(x)))/(sqrt(-im - a) + (-1)^(1/3)*a^(1/3)*b^(1/6))))/(3*a^(1/3)*b^(2/3)) + ((-1)^(1/6)*PolyLog(2, -((b^(1/6)*((-1)^(1/12)*a^(1/3) + (-1)^(3/4)*b^(1/3)*sqrt(x)))/(sqrt(1 + im*a) - (-1)^(1/12)*a^(1/3)*b^(1/6)))))/(3*a^(1/3)*b^(2/3))] =#
    @test_int [atan(a + b*x)/(c + d*sqrt(x)), x, 31, (2*im*sqrt(im + a)*atan((sqrt(b)*sqrt(x))/sqrt(im + a)))/(sqrt(b)*d) - (2*im*sqrt(im - a)*atanh((sqrt(b)*sqrt(x))/sqrt(im - a)))/(sqrt(b)*d) + (im*c*log((d*(sqrt(-im - a) - sqrt(b)*sqrt(x)))/(sqrt(b)*c + sqrt(-im - a)*d))*log(c + d*sqrt(x)))/d^2 - (im*c*log((d*(sqrt(im - a) - sqrt(b)*sqrt(x)))/(sqrt(b)*c + sqrt(im - a)*d))*log(c + d*sqrt(x)))/d^2 + (im*c*log(-((d*(sqrt(-im - a) + sqrt(b)*sqrt(x)))/(sqrt(b)*c - sqrt(-im - a)*d)))*log(c + d*sqrt(x)))/d^2 - (im*c*log(-((d*(sqrt(im - a) + sqrt(b)*sqrt(x)))/(sqrt(b)*c - sqrt(im - a)*d)))*log(c + d*sqrt(x)))/d^2 + (im*sqrt(x)*log(1 - im*a - im*b*x))/d - (im*c*log(c + d*sqrt(x))*log(1 - im*a - im*b*x))/d^2 - (im*sqrt(x)*log(1 + im*a + im*b*x))/d + (im*c*log(c + d*sqrt(x))*log(1 + im*a + im*b*x))/d^2 + (im*c*PolyLog(2, (sqrt(b)*(c + d*sqrt(x)))/(sqrt(b)*c - sqrt(-im - a)*d)))/d^2 + (im*c*PolyLog(2, (sqrt(b)*(c + d*sqrt(x)))/(sqrt(b)*c + sqrt(-im - a)*d)))/d^2 - (im*c*PolyLog(2, (sqrt(b)*(c + d*sqrt(x)))/(sqrt(b)*c - sqrt(im - a)*d)))/d^2 - (im*c*PolyLog(2, (sqrt(b)*(c + d*sqrt(x)))/(sqrt(b)*c + sqrt(im - a)*d)))/d^2]
    @test_int [atan(a + b*x)/(c + d/sqrt(x)), x, 37, -((2*im*sqrt(im + a)*d*atan((sqrt(b)*sqrt(x))/sqrt(im + a)))/(sqrt(b)*c^2)) + (2*im*sqrt(im - a)*d*atanh((sqrt(b)*sqrt(x))/sqrt(im - a)))/(sqrt(b)*c^2) - (im*d^2*log((c*(sqrt(-im - a) - sqrt(b)*sqrt(x)))/(sqrt(-im - a)*c + sqrt(b)*d))*log(d + c*sqrt(x)))/c^3 + (im*d^2*log((c*(sqrt(im - a) - sqrt(b)*sqrt(x)))/(sqrt(im - a)*c + sqrt(b)*d))*log(d + c*sqrt(x)))/c^3 - (im*d^2*log((c*(sqrt(-im - a) + sqrt(b)*sqrt(x)))/(sqrt(-im - a)*c - sqrt(b)*d))*log(d + c*sqrt(x)))/c^3 + (im*d^2*log((c*(sqrt(im - a) + sqrt(b)*sqrt(x)))/(sqrt(im - a)*c - sqrt(b)*d))*log(d + c*sqrt(x)))/c^3 - (im*d*sqrt(x)*log(1 - im*a - im*b*x))/c^2 + (im*d^2*log(d + c*sqrt(x))*log(1 - im*a - im*b*x))/c^3 + (im*d*sqrt(x)*log(1 + im*a + im*b*x))/c^2 - ((1 + im*a + im*b*x)*log(1 + im*a + im*b*x))/(2*b*c) - (im*d^2*log(d + c*sqrt(x))*log(1 + im*a + im*b*x))/c^3 - ((1 - im*a - im*b*x)*log((-im)*(im + a + b*x)))/(2*b*c) - (im*d^2*PolyLog(2, -((sqrt(b)*(d + c*sqrt(x)))/(sqrt(-im - a)*c - sqrt(b)*d))))/c^3 + (im*d^2*PolyLog(2, -((sqrt(b)*(d + c*sqrt(x)))/(sqrt(im - a)*c - sqrt(b)*d))))/c^3 - (im*d^2*PolyLog(2, (sqrt(b)*(d + c*sqrt(x)))/(sqrt(-im - a)*c + sqrt(b)*d)))/c^3 + (im*d^2*PolyLog(2, (sqrt(b)*(d + c*sqrt(x)))/(sqrt(im - a)*c + sqrt(b)*d)))/c^3]
    #= [atan(a + b*x)/(a + b/x^(3/2)), x, 49, -((-1)^(5/6)*b^(2/3)*log(-((-1)^(2/3)*b^(1/3)) - a^(1/3)*sqrt(x))*log(-(((-1)^(3/4)*a^(1/3)*((-1)^(1/4)*sqrt(1 + im*a) - sqrt(b)*sqrt(x)))/(sqrt(1 + im*a)*a^(1/3) + (-1)^(5/12)*b^(5/6)))))/(3*a^(5/3)) - ((im/3)*b^(2/3)*log(-b^(1/3) - a^(1/3)*sqrt(x))*log((a^(1/3)*((-1)^(3/4)*sqrt(1 - im*a) + sqrt(b)*sqrt(x)))/((-1)^(3/4)*sqrt(1 - im*a)*a^(1/3) - b^(5/6))))/a^(5/3) + ((im/3)*b^(2/3)*log(-b^(1/3) - a^(1/3)*sqrt(x))*log((a^(1/3)*((-1)^(1/4)*sqrt(1 + im*a) + sqrt(b)*sqrt(x)))/((-1)^(1/4)*sqrt(1 + im*a)*a^(1/3) - b^(5/6))))/a^(5/3) + ((-1)^(5/6)*b^(2/3)*log(-((-1)^(2/3)*b^(1/3)) - a^(1/3)*sqrt(x))*log(((-1)^(1/12)*a^(1/3)*(sqrt(1 - im*a) - (-1)^(1/4)*sqrt(b)*sqrt(x)))/((-1)^(1/12)*sqrt(1 - im*a)*a^(1/3) - b^(5/6))))/(3*a^(5/3)) + ((-1)^(1/6)*b^(2/3)*log((-1)^(1/3)*b^(1/3) - a^(1/3)*sqrt(x))*log(((-1)^(5/12)*a^(1/3)*(sqrt(1 - im*a) - (-1)^(1/4)*sqrt(b)*sqrt(x)))/((-1)^(5/12)*sqrt(1 - im*a)*a^(1/3) + b^(5/6))))/(3*a^(5/3)) + ((-1)^(1/6)*b^(2/3)*log((-1)^(1/3)*b^(1/3) - a^(1/3)*sqrt(x))*log(((-1)^(5/12)*a^(1/3)*(sqrt(1 - im*a) + (-1)^(1/4)*sqrt(b)*sqrt(x)))/((-1)^(5/12)*sqrt(1 - im*a)*a^(1/3) - b^(5/6))))/(3*a^(5/3)) + ((-1)^(5/6)*b^(2/3)*log(-((-1)^(2/3)*b^(1/3)) - a^(1/3)*sqrt(x))*log(((-1)^(1/12)*a^(1/3)*(sqrt(1 - im*a) + (-1)^(1/4)*sqrt(b)*sqrt(x)))/((-1)^(1/12)*sqrt(1 - im*a)*a^(1/3) + b^(5/6))))/(3*a^(5/3)) - ((im/3)*b^(2/3)*log(-b^(1/3) - a^(1/3)*sqrt(x))*log(((-1)^(3/4)*a^(1/3)*(sqrt(1 - im*a) + (-1)^(1/4)*sqrt(b)*sqrt(x)))/((-1)^(3/4)*sqrt(1 - im*a)*a^(1/3) + b^(5/6))))/a^(5/3) - ((-1)^(1/6)*b^(2/3)*log((-1)^(1/3)*b^(1/3) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(1 + im*a) - (-1)^(3/4)*sqrt(b)*sqrt(x)))/(sqrt(1 + im*a)*a^(1/3) + (-1)^(1/12)*b^(5/6))))/(3*a^(5/3)) - ((-1)^(5/6)*b^(2/3)*log(-((-1)^(2/3)*b^(1/3)) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(1 + im*a) - (-1)^(3/4)*sqrt(b)*sqrt(x)))/(sqrt(1 + im*a)*a^(1/3) - (-1)^(5/12)*b^(5/6))))/(3*a^(5/3)) + ((im/3)*b^(2/3)*log(-b^(1/3) - a^(1/3)*sqrt(x))*log(((-1)^(1/4)*a^(1/3)*(sqrt(1 + im*a) + (-1)^(3/4)*sqrt(b)*sqrt(x)))/((-1)^(1/4)*sqrt(1 + im*a)*a^(1/3) + b^(5/6))))/a^(5/3) - ((-1)^(1/6)*b^(2/3)*log((-1)^(1/3)*b^(1/3) - a^(1/3)*sqrt(x))*log((a^(1/3)*(sqrt(1 + im*a) + (-1)^(3/4)*sqrt(b)*sqrt(x)))/(sqrt(1 + im*a)*a^(1/3) - (-1)^(1/12)*b^(5/6))))/(3*a^(5/3)) - ((1 - im*a - im*b*x)*log(1 - im*a - im*b*x))/(2*a*b) + ((im/3)*b^(2/3)*log(-b^(1/3) - a^(1/3)*sqrt(x))*log(1 - im*a - im*b*x))/a^(5/3) - ((-1)^(1/6)*b^(2/3)*log((-1)^(1/3)*b^(1/3) - a^(1/3)*sqrt(x))*log(1 - im*a - im*b*x))/(3*a^(5/3)) - ((-1)^(5/6)*b^(2/3)*log(-((-1)^(2/3)*b^(1/3)) - a^(1/3)*sqrt(x))*log(1 - im*a - im*b*x))/(3*a^(5/3)) - ((1 + im*a + im*b*x)*log(1 + im*a + im*b*x))/(2*a*b) - ((im/3)*b^(2/3)*log(-b^(1/3) - a^(1/3)*sqrt(x))*log(1 + im*a + im*b*x))/a^(5/3) + ((-1)^(1/6)*b^(2/3)*log((-1)^(1/3)*b^(1/3) - a^(1/3)*sqrt(x))*log(1 + im*a + im*b*x))/(3*a^(5/3)) + ((-1)^(5/6)*b^(2/3)*log(-((-1)^(2/3)*b^(1/3)) - a^(1/3)*sqrt(x))*log(1 + im*a + im*b*x))/(3*a^(5/3)) - ((im/3)*b^(2/3)*PolyLog(2, -((sqrt(b)*(b^(1/3) + a^(1/3)*sqrt(x)))/((-1)^(3/4)*sqrt(1 - im*a)*a^(1/3) - b^(5/6)))))/a^(5/3) + ((im/3)*b^(2/3)*PolyLog(2, -((sqrt(b)*(b^(1/3) + a^(1/3)*sqrt(x)))/((-1)^(1/4)*sqrt(1 + im*a)*a^(1/3) - b^(5/6)))))/a^(5/3) - ((im/3)*b^(2/3)*PolyLog(2, (sqrt(b)*(b^(1/3) + a^(1/3)*sqrt(x)))/((-1)^(3/4)*sqrt(1 - im*a)*a^(1/3) + b^(5/6))))/a^(5/3) + ((im/3)*b^(2/3)*PolyLog(2, (sqrt(b)*(b^(1/3) + a^(1/3)*sqrt(x)))/((-1)^(1/4)*sqrt(1 + im*a)*a^(1/3) + b^(5/6))))/a^(5/3) + ((-1)^(5/6)*b^(2/3)*PolyLog(2, ((-1)^(1/3)*sqrt(b)*((-1)^(2/3)*b^(1/3) + a^(1/3)*sqrt(x)))/((-1)^(1/12)*sqrt(1 - im*a)*a^(1/3) - b^(5/6))))/(3*a^(5/3)) - ((-1)^(5/6)*b^(2/3)*PolyLog(2, ((-1)^(3/4)*sqrt(b)*((-1)^(2/3)*b^(1/3) + a^(1/3)*sqrt(x)))/(sqrt(1 + im*a)*a^(1/3) - (-1)^(5/12)*b^(5/6))))/(3*a^(5/3)) + ((-1)^(5/6)*b^(2/3)*PolyLog(2, (sqrt(b)*(b^(1/3) - (-1)^(1/3)*a^(1/3)*sqrt(x)))/((-1)^(1/12)*sqrt(1 - im*a)*a^(1/3) + b^(5/6))))/(3*a^(5/3)) - ((-1)^(5/6)*b^(2/3)*PolyLog(2, ((-1)^(5/12)*sqrt(b)*(b^(1/3) - (-1)^(1/3)*a^(1/3)*sqrt(x)))/(sqrt(1 + im*a)*a^(1/3) + (-1)^(5/12)*b^(5/6))))/(3*a^(5/3)) + ((-1)^(1/6)*b^(2/3)*PolyLog(2, -((sqrt(b)*(b^(1/3) + (-1)^(2/3)*a^(1/3)*sqrt(x)))/((-1)^(5/12)*sqrt(1 - im*a)*a^(1/3) - b^(5/6)))))/(3*a^(5/3)) + ((-1)^(1/6)*b^(2/3)*PolyLog(2, (sqrt(b)*(b^(1/3) + (-1)^(2/3)*a^(1/3)*sqrt(x)))/((-1)^(5/12)*sqrt(1 - im*a)*a^(1/3) + b^(5/6))))/(3*a^(5/3)) - ((-1)^(1/6)*b^(2/3)*PolyLog(2, ((-1)^(1/12)*sqrt(b)*(b^(1/3) + (-1)^(2/3)*a^(1/3)*sqrt(x)))/(sqrt(1 + im*a)*a^(1/3) + (-1)^(1/12)*b^(5/6))))/(3*a^(5/3)) - ((-1)^(1/6)*b^(2/3)*PolyLog(2, -((sqrt(b)*((-1)^(1/12)*b^(1/3) + (-1)^(3/4)*a^(1/3)*sqrt(x)))/(sqrt(1 + im*a)*a^(1/3) - (-1)^(1/12)*b^(5/6)))))/(3*a^(5/3))] =#

    @test_int [atan(a + b*x)/(1 + x^2), x, 17, (1/4)*log((b*(im - x))/(a + im*(1 + b)))*log(1 - im*a - im*b*x) - (1/4)*log(-((b*(im + x))/(a + im*(1 - b))))*log(1 - im*a - im*b*x) - (1/4)*log((b*(im - x))/(a - im*(1 - b)))*log(1 + im*a + im*b*x) + (1/4)*log(-((b*(im + x))/(a - im*(1 + b))))*log(1 + im*a + im*b*x) - (1/4)*PolyLog(2, -((im - a - b*x)/(a - im*(1 - b)))) + (1/4)*PolyLog(2, -((im - a - b*x)/(a - im*(1 + b)))) - (1/4)*PolyLog(2, (im + a + b*x)/(im + a - im*b)) + (1/4)*PolyLog(2, (im + a + b*x)/(a + im*(1 + b)))]

    @test_int [atan(d + e*x)/(a + b*x^2), x, 17, (im*log((e*(sqrt(-a) - sqrt(b)*x))/(sqrt(b)*(im + d) + sqrt(-a)*e))*log(1 - im*d - im*e*x))/(4*sqrt(-a)*sqrt(b)) - (im*log(-((e*(sqrt(-a) + sqrt(b)*x))/(sqrt(b)*(im + d) - sqrt(-a)*e)))*log(1 - im*d - im*e*x))/(4*sqrt(-a)*sqrt(b)) - (im*log(-((e*(sqrt(-a) - sqrt(b)*x))/(sqrt(b)*(im - d) - sqrt(-a)*e)))*log(1 + im*d + im*e*x))/(4*sqrt(-a)*sqrt(b)) + (im*log((e*(sqrt(-a) + sqrt(b)*x))/(sqrt(b)*(im - d) + sqrt(-a)*e))*log(1 + im*d + im*e*x))/(4*sqrt(-a)*sqrt(b)) - (im*PolyLog(2, (sqrt(b)*(im - d - e*x))/(sqrt(b)*(im - d) - sqrt(-a)*e)))/(4*sqrt(-a)*sqrt(b)) + (im*PolyLog(2, (sqrt(b)*(im - d - e*x))/(sqrt(b)*(im - d) + sqrt(-a)*e)))/(4*sqrt(-a)*sqrt(b)) - (im*PolyLog(2, (sqrt(b)*(im + d + e*x))/(sqrt(b)*(im + d) - sqrt(-a)*e)))/(4*sqrt(-a)*sqrt(b)) + (im*PolyLog(2, (sqrt(b)*(im + d + e*x))/(sqrt(b)*(im + d) + sqrt(-a)*e)))/(4*sqrt(-a)*sqrt(b))]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(A+B*x+C*x^2)^q*atan(a+b*x)=#

    @test_int [atan(d + e*x)/(a + b*x + c*x^2), x, 12, (atan(d + e*x)*log((2*e*(b - sqrt(b^2 - 4*a*c) + 2*c*x))/((2*c*(im - d) + (b - sqrt(b^2 - 4*a*c))*e)*(1 - im*(d + e*x)))))/sqrt(b^2 - 4*a*c) - (atan(d + e*x)*log((2*e*(b + sqrt(b^2 - 4*a*c) + 2*c*x))/((2*c*(im - d) + (b + sqrt(b^2 - 4*a*c))*e)*(1 - im*(d + e*x)))))/sqrt(b^2 - 4*a*c) - (im*PolyLog(2, 1 + (2*(2*c*d - (b - sqrt(b^2 - 4*a*c))*e - 2*c*(d + e*x)))/((2*im*c - 2*c*d + b*e - sqrt(b^2 - 4*a*c)*e)*(1 - im*(d + e*x)))))/(2*sqrt(b^2 - 4*a*c)) + (im*PolyLog(2, 1 + (2*(2*c*d - (b + sqrt(b^2 - 4*a*c))*e - 2*c*(d + e*x)))/((2*c*(im - d) + (b + sqrt(b^2 - 4*a*c))*e)*(1 - im*(d + e*x)))))/(2*sqrt(b^2 - 4*a*c))]

    @test_int [atan(a + b*x)/sqrt(1 + a^2 + 2*a*b*x + b^2*x^2), x, 2, -((2*im*atan(a + b*x)*atan(sqrt(1 + im*(a + b*x))/sqrt(1 - im*(a + b*x))))/b) + (im*PolyLog(2, -((im*sqrt(1 + im*(a + b*x)))/sqrt(1 - im*(a + b*x)))))/b - (im*PolyLog(2, (im*sqrt(1 + im*(a + b*x)))/sqrt(1 - im*(a + b*x))))/b]
    @test_int [atan(a + b*x)/sqrt((1 + a^2)*c + 2*a*b*c*x + b^2*c*x^2), x, 3, -((2*im*sqrt(1 + (a + b*x)^2)*atan(a + b*x)*atan(sqrt(1 + im*(a + b*x))/sqrt(1 - im*(a + b*x))))/(b*sqrt(c + c*(a + b*x)^2))) + (im*sqrt(1 + (a + b*x)^2)*PolyLog(2, -((im*sqrt(1 + im*(a + b*x)))/sqrt(1 - im*(a + b*x)))))/(b*sqrt(c + c*(a + b*x)^2)) - (im*sqrt(1 + (a + b*x)^2)*PolyLog(2, (im*sqrt(1 + im*(a + b*x)))/sqrt(1 - im*(a + b*x))))/(b*sqrt(c + c*(a + b*x)^2))]

    @test_int [atan(a + b*x)/(1 + a^2 + 2*a*b*x + b^2*x^2)^(1/3), x, 1, Unintegrable(atan(a + b*x)/(1 + (a + b*x)^2)^(1/3), x)]
    @test_int [atan(a + b*x)/((1 + a^2)*c + 2*a*b*c*x + b^2*c*x^2)^(1/3), x, 1, Unintegrable(atan(a + b*x)/(c + c*(a + b*x)^2)^(1/3), x)]

    #= ::Subsection::Closed:: =#
    #=Integrands*of*the*form*(e+f*x)^m*(A+B*x+C*x^2)^q*atan(a+b*x)^p=#

    @test_int [(a + b*x)^2*atan(a + b*x)/sqrt(1 + a^2 + 2*a*b*x + b^2*x^2), x, 4, -(sqrt(1 + (a + b*x)^2)/(2*b)) + ((a + b*x)*sqrt(1 + (a + b*x)^2)*atan(a + b*x))/(2*b) + (im*atan(a + b*x)*atan(sqrt(1 + im*(a + b*x))/sqrt(1 - im*(a + b*x))))/b - (im*PolyLog(2, -((im*sqrt(1 + im*(a + b*x)))/sqrt(1 - im*(a + b*x)))))/(2*b) + (im*PolyLog(2, (im*sqrt(1 + im*(a + b*x)))/sqrt(1 - im*(a + b*x))))/(2*b)]
    @test_int [(a + b*x)^2*atan(a + b*x)/sqrt((1 + a^2)*c + 2*a*b*c*x + b^2*c*x^2), x, 5, -(sqrt(c + c*(a + b*x)^2)/(2*b*c)) + ((a + b*x)*sqrt(c + c*(a + b*x)^2)*atan(a + b*x))/(2*b*c) + (im*sqrt(1 + (a + b*x)^2)*atan(a + b*x)*atan(sqrt(1 + im*(a + b*x))/sqrt(1 - im*(a + b*x))))/(b*sqrt(c + c*(a + b*x)^2)) - (im*sqrt(1 + (a + b*x)^2)*PolyLog(2, -((im*sqrt(1 + im*(a + b*x)))/sqrt(1 - im*(a + b*x)))))/(2*b*sqrt(c + c*(a + b*x)^2)) + (im*sqrt(1 + (a + b*x)^2)*PolyLog(2, (im*sqrt(1 + im*(a + b*x)))/sqrt(1 - im*(a + b*x))))/(2*b*sqrt(c + c*(a + b*x)^2))]

    @test_int [(a + b*x)^2*atan(a + b*x)/(1 + a^2 + 2*a*b*x + b^2*x^2)^(1/3), x, 1, Unintegrable(((a + b*x)^2*atan(a + b*x))/(1 + (a + b*x)^2)^(1/3), x)]
    @test_int [(a + b*x)^2*atan(a + b*x)/((1 + a^2)*c + 2*a*b*c*x + b^2*c*x^2)^(1/3), x, 1, Unintegrable(((a + b*x)^2*atan(a + b*x))/(c + c*(a + b*x)^2)^(1/3), x)]
    end

max_stars_repo_path: test/5 Inverse trig functions/5.3 Inverse tangent/5.3.5 u (a+b arctan(c+d x))^p.jl


text:
module ThreadsAPIBenchmarks

using Glob
using JSON

export run_benchmarks, create_default_symlink

include("core.jl")
include("runners.jl")
include("loaders.jl")

end


text:
#
# This file is a part of MolecularGraph.jl
# Licensed under the MIT License http://opensource.org/licenses/MIT
#

export
    findmcis, mcissize,
    findmces, mcessize

"""
    findmcis(G::UndirectedGraph, H::UndirectedGraph; kwargs...
        ) -> Tuple{Dict{Int,Int},Symbol}

Compute maximum common induced subgraph between `G` and `H`.

## Keyword arguments:

- connected(Bool): if true, apply connected MCS constraint.
- topological(Bool): if true, apply topological constraint.
- diameter(Int): distance cutoff for topological constraint.
- tolerance(Int): distance mismatch tolerance for topological constraint.
- timeout(Int): abort calculation and return suboptimal results so far if the
execution time has reached the given value (default=60, in seconds).
- targetsize(Int): abort calculation and return suboptimal result so far if the
given mcs size achieved.
- nodematcher(Function): node matcher function that takes two node indices as
arguments.
- edgematcher(Function): edge matcher function that takes two edge indices as
arguments.
"""
function findmcis(G::UndirectedGraph, H::UndirectedGraph;
        nodematcher=(g,h)->true, edgematcher=(g,h)->true, kwargs...)
    mapping = Dict{Int,Int}()
    status = :invalidinput
    (nodecount(G) == 0 || nodecount(H) == 0) && return (mapping, status)
    # Generate modular product
    if haskey(kwargs, :topological) && kwargs[:topological]
        eflt = tpconstraintfilter(G, H, edgematcher; kwargs...)
    else
        eflt = modprodedgefilter(G, H, edgematcher)
    end
    prod = modularproduct(
        G, H, nodematcher=nodematcher, edgefilter=eflt; kwargs...)
    # Clique detection
    if haskey(kwargs, :connected) && kwargs[:connected]
        (cliques, status) = maximalconncliques(prod; kwargs...)
    else
        (cliques, status) = maximalcliques(prod; kwargs...)
    end
    maxclique = sortstablemax(collect(cliques), by=length, init=[])
    mapping = Dict(
        nodeattr(prod, n).g => nodeattr(prod, n).h for n in maxclique)
    return (mapping, status)
end

"""
    findmces(G::UndirectedGraph, H::UndirectedGraph; kwargs...
        ) -> Tuple{Dict{Int,Int},Symbol}

Compute maximum common edge induced subgraph between `G` and `H`.
"""
function findmces(G::UndirectedGraph, H::UndirectedGraph;
        nodematcher=(g,h)->true, edgematcher=(g,h)->true, kwargs...)
    mapping = Dict{Int,Int}()
    status = :invalidinput
    (edgecount(G) == 0 || edgecount(H) == 0) && return (mapping, status)
    lg = linegraph(G)
    lh = linegraph(H)
    ematch = lgedgematcher(lg, lh, nodematcher)
    nmatch = lgnodematcher(lg, lh, nodematcher, edgematcher)
    # Generate modular product
    if haskey(kwargs, :topological) && kwargs[:topological]
        eflt = tpconstraintfilter(lg, lh, ematch; kwargs...)
    else
        eflt = modprodedgefilter(lg, lh, ematch)
    end
    prod = modularproduct(lg, lh, nodematcher=nmatch, edgefilter=eflt)
    # Clique detection
    if haskey(kwargs, :connected) && kwargs[:connected]
        (cliques, status) = maximalconncliques(prod; kwargs...)
    else
        (cliques, status) = maximalcliques(prod; kwargs...)
    end
    for edges in cliques
        length(edges) > length(mapping) || continue
        mp = Dict(nodeattr(prod, e).g => nodeattr(prod, e).h for e in edges)
        delta_y_correction!(mp, G, H)
        if length(mp) > length(mapping)
            mapping = mp
        end
    end
    return (mapping, status)
end

function modprodedgefilter(G, H, edgematcher)
    return function (g1, g2, h1, h2)
        hasedge(G, g1, g2) == hasedge(H, h1, h2) || return false
        !hasedge(G, g1, g2) && !hasedge(H, h1, h2) && return true
        return edgematcher(findedgekey(G, g1, g2), findedgekey(H, h1, h2))
    end
end

function tpconstraintfilter(
        G, H, edgematcher; diameter=typemax(Int), tolerance=0, kwargs...)
    gdist = Dict(n => bfsdepth(adjacencies, G, n) for n in nodeset(G))
    hdist = Dict(n => bfsdepth(adjacencies, H, n) for n in nodeset(H))
    return function (g1, g2, h1, h2)
        gdist[g1][g2] > diameter && return false
        hdist[h1][h2] > diameter && return false
        abs(gdist[g1][g2] - hdist[h1][h2]) > tolerance && return false
        !hasedge(G, g1, g2) && !hasedge(H, h1, h2) && return true
        return edgematcher(findedgekey(G, g1, g2), findedgekey(H, h1, h2))
    end
end

"""
    mcissize(G::AbstractGraph, H::AbstractGraph; kwargs...) -> Int

Return the maximum common induced subgraph size (number of nodes).
"""
mcissize(G, H; kwargs...) = length(findmcis(G, H; kwargs...)[1])

"""
    mcessize(G::AbstractGraph, H::AbstractGraph; kwargs...) -> Int

Return the maximum common edge induced subgraph size (number of edges).
"""
mcessize(G, H; kwargs...) = length(findmces(G, H; kwargs...)[1])