#!/usr/bin/env python3
"""Build excel_functions.csv from the master list below.

Each tuple is (name, category, replaces_with). replaces_with is "" for
non-legacy functions and the modern preferred name for Compatibility
functions. Categories follow Microsoft's official function reference:
Math, Statistical, Logical, Lookup, Text, Date & Time, Financial,
Engineering, Information, Database, Cube, Web, Compatibility, Add-in.
"""
import csv

functions = [
    # --- Math & trigonometry ---
    ("ABS", "Math", ""),
    ("ACOS", "Math", ""),
    ("ACOSH", "Math", ""),
    ("ACOT", "Math", ""),
    ("ACOTH", "Math", ""),
    ("AGGREGATE", "Math", ""),
    ("ARABIC", "Math", ""),
    ("ASIN", "Math", ""),
    ("ASINH", "Math", ""),
    ("ATAN", "Math", ""),
    ("ATAN2", "Math", ""),
    ("ATANH", "Math", ""),
    ("BASE", "Math", ""),
    ("CEILING.MATH", "Math", ""),
    ("CEILING.PRECISE", "Math", ""),
    ("COMBIN", "Math", ""),
    ("COMBINA", "Math", ""),
    ("COS", "Math", ""),
    ("COSH", "Math", ""),
    ("COT", "Math", ""),
    ("COTH", "Math", ""),
    ("CSC", "Math", ""),
    ("CSCH", "Math", ""),
    ("DECIMAL", "Math", ""),
    ("DEGREES", "Math", ""),
    ("EVEN", "Math", ""),
    ("EXP", "Math", ""),
    ("FACT", "Math", ""),
    ("FACTDOUBLE", "Math", ""),
    ("FLOOR.MATH", "Math", ""),
    ("FLOOR.PRECISE", "Math", ""),
    ("GCD", "Math", ""),
    ("INT", "Math", ""),
    ("ISO.CEILING", "Math", ""),
    ("LCM", "Math", ""),
    ("LN", "Math", ""),
    ("LOG", "Math", ""),
    ("LOG10", "Math", ""),
    ("MDETERM", "Math", ""),
    ("MINVERSE", "Math", ""),
    ("MMULT", "Math", ""),
    ("MOD", "Math", ""),
    ("MROUND", "Math", ""),
    ("MULTINOMIAL", "Math", ""),
    ("MUNIT", "Math", ""),
    ("ODD", "Math", ""),
    ("PI", "Math", ""),
    ("POWER", "Math", ""),
    ("PRODUCT", "Math", ""),
    ("QUOTIENT", "Math", ""),
    ("RADIANS", "Math", ""),
    ("RAND", "Math", ""),
    ("RANDARRAY", "Math", ""),
    ("RANDBETWEEN", "Math", ""),
    ("ROMAN", "Math", ""),
    ("ROUND", "Math", ""),
    ("ROUNDDOWN", "Math", ""),
    ("ROUNDUP", "Math", ""),
    ("SEC", "Math", ""),
    ("SECH", "Math", ""),
    ("SEQUENCE", "Math", ""),
    ("SERIESSUM", "Math", ""),
    ("SIGN", "Math", ""),
    ("SIN", "Math", ""),
    ("SINH", "Math", ""),
    ("SQRT", "Math", ""),
    ("SQRTPI", "Math", ""),
    ("SUBTOTAL", "Math", ""),
    ("SUM", "Math", ""),
    ("SUMIF", "Math", ""),
    ("SUMIFS", "Math", ""),
    ("SUMPRODUCT", "Math", ""),
    ("SUMSQ", "Math", ""),
    ("SUMX2MY2", "Math", ""),
    ("SUMX2PY2", "Math", ""),
    ("SUMXMY2", "Math", ""),
    ("TAN", "Math", ""),
    ("TANH", "Math", ""),
    ("TRUNC", "Math", ""),

    # --- Statistical ---
    ("AVEDEV", "Statistical", ""),
    ("AVERAGE", "Statistical", ""),
    ("AVERAGEA", "Statistical", ""),
    ("AVERAGEIF", "Statistical", ""),
    ("AVERAGEIFS", "Statistical", ""),
    ("BETA.DIST", "Statistical", ""),
    ("BETA.INV", "Statistical", ""),
    ("BINOM.DIST", "Statistical", ""),
    ("BINOM.DIST.RANGE", "Statistical", ""),
    ("BINOM.INV", "Statistical", ""),
    ("CHISQ.DIST", "Statistical", ""),
    ("CHISQ.DIST.RT", "Statistical", ""),
    ("CHISQ.INV", "Statistical", ""),
    ("CHISQ.INV.RT", "Statistical", ""),
    ("CHISQ.TEST", "Statistical", ""),
    ("CONFIDENCE.NORM", "Statistical", ""),
    ("CONFIDENCE.T", "Statistical", ""),
    ("CORREL", "Statistical", ""),
    ("COUNT", "Statistical", ""),
    ("COUNTA", "Statistical", ""),
    ("COUNTBLANK", "Statistical", ""),
    ("COUNTIF", "Statistical", ""),
    ("COUNTIFS", "Statistical", ""),
    ("COVARIANCE.P", "Statistical", ""),
    ("COVARIANCE.S", "Statistical", ""),
    ("DEVSQ", "Statistical", ""),
    ("EXPON.DIST", "Statistical", ""),
    ("F.DIST", "Statistical", ""),
    ("F.DIST.RT", "Statistical", ""),
    ("F.INV", "Statistical", ""),
    ("F.INV.RT", "Statistical", ""),
    ("F.TEST", "Statistical", ""),
    ("FISHER", "Statistical", ""),
    ("FISHERINV", "Statistical", ""),
    ("FORECAST.ETS", "Statistical", ""),
    ("FORECAST.ETS.CONFINT", "Statistical", ""),
    ("FORECAST.ETS.SEASONALITY", "Statistical", ""),
    ("FORECAST.ETS.STAT", "Statistical", ""),
    ("FORECAST.LINEAR", "Statistical", ""),
    ("FREQUENCY", "Statistical", ""),
    ("GAMMA", "Statistical", ""),
    ("GAMMA.DIST", "Statistical", ""),
    ("GAMMA.INV", "Statistical", ""),
    ("GAMMALN", "Statistical", ""),
    ("GAMMALN.PRECISE", "Statistical", ""),
    ("GAUSS", "Statistical", ""),
    ("GEOMEAN", "Statistical", ""),
    ("GROWTH", "Statistical", ""),
    ("HARMEAN", "Statistical", ""),
    ("HYPGEOM.DIST", "Statistical", ""),
    ("INTERCEPT", "Statistical", ""),
    ("KURT", "Statistical", ""),
    ("LARGE", "Statistical", ""),
    ("LINEST", "Statistical", ""),
    ("LOGEST", "Statistical", ""),
    ("LOGNORM.DIST", "Statistical", ""),
    ("LOGNORM.INV", "Statistical", ""),
    ("MAX", "Statistical", ""),
    ("MAXA", "Statistical", ""),
    ("MAXIFS", "Statistical", ""),
    ("MEDIAN", "Statistical", ""),
    ("MIN", "Statistical", ""),
    ("MINA", "Statistical", ""),
    ("MINIFS", "Statistical", ""),
    ("MODE.MULT", "Statistical", ""),
    ("MODE.SNGL", "Statistical", ""),
    ("NEGBINOM.DIST", "Statistical", ""),
    ("NORM.DIST", "Statistical", ""),
    ("NORM.INV", "Statistical", ""),
    ("NORM.S.DIST", "Statistical", ""),
    ("NORM.S.INV", "Statistical", ""),
    ("PEARSON", "Statistical", ""),
    ("PERCENTILE.EXC", "Statistical", ""),
    ("PERCENTILE.INC", "Statistical", ""),
    ("PERCENTRANK.EXC", "Statistical", ""),
    ("PERCENTRANK.INC", "Statistical", ""),
    ("PERMUT", "Statistical", ""),
    ("PERMUTATIONA", "Statistical", ""),
    ("PHI", "Statistical", ""),
    ("POISSON.DIST", "Statistical", ""),
    ("PROB", "Statistical", ""),
    ("QUARTILE.EXC", "Statistical", ""),
    ("QUARTILE.INC", "Statistical", ""),
    ("RANK.AVG", "Statistical", ""),
    ("RANK.EQ", "Statistical", ""),
    ("RSQ", "Statistical", ""),
    ("SKEW", "Statistical", ""),
    ("SKEW.P", "Statistical", ""),
    ("SLOPE", "Statistical", ""),
    ("SMALL", "Statistical", ""),
    ("STANDARDIZE", "Statistical", ""),
    ("STDEV.P", "Statistical", ""),
    ("STDEV.S", "Statistical", ""),
    ("STDEVA", "Statistical", ""),
    ("STDEVPA", "Statistical", ""),
    ("STEYX", "Statistical", ""),
    ("T.DIST", "Statistical", ""),
    ("T.DIST.2T", "Statistical", ""),
    ("T.DIST.RT", "Statistical", ""),
    ("T.INV", "Statistical", ""),
    ("T.INV.2T", "Statistical", ""),
    ("T.TEST", "Statistical", ""),
    ("TREND", "Statistical", ""),
    ("TRIMMEAN", "Statistical", ""),
    ("VAR.P", "Statistical", ""),
    ("VAR.S", "Statistical", ""),
    ("VARA", "Statistical", ""),
    ("VARPA", "Statistical", ""),
    ("WEIBULL.DIST", "Statistical", ""),
    ("Z.TEST", "Statistical", ""),

    # --- Logical ---
    ("AND", "Logical", ""),
    ("BYCOL", "Logical", ""),
    ("BYROW", "Logical", ""),
    ("FALSE", "Logical", ""),
    ("IF", "Logical", ""),
    ("IFERROR", "Logical", ""),
    ("IFNA", "Logical", ""),
    ("IFS", "Logical", ""),
    ("LAMBDA", "Logical", ""),
    ("LET", "Logical", ""),
    ("MAKEARRAY", "Logical", ""),
    ("MAP", "Logical", ""),
    ("NOT", "Logical", ""),
    ("OR", "Logical", ""),
    ("REDUCE", "Logical", ""),
    ("SCAN", "Logical", ""),
    ("SWITCH", "Logical", ""),
    ("TRUE", "Logical", ""),
    ("XOR", "Logical", ""),

    # --- Lookup & reference ---
    ("ADDRESS", "Lookup", ""),
    ("AREAS", "Lookup", ""),
    ("CHOOSE", "Lookup", ""),
    ("CHOOSECOLS", "Lookup", ""),
    ("CHOOSEROWS", "Lookup", ""),
    ("COLUMN", "Lookup", ""),
    ("COLUMNS", "Lookup", ""),
    ("DROP", "Lookup", ""),
    ("EXPAND", "Lookup", ""),
    ("FILTER", "Lookup", ""),
    ("FORMULATEXT", "Lookup", ""),
    ("GETPIVOTDATA", "Lookup", ""),
    ("GROUPBY", "Lookup", ""),
    ("HLOOKUP", "Lookup", ""),
    ("HSTACK", "Lookup", ""),
    ("HYPERLINK", "Lookup", ""),
    ("IMAGE", "Lookup", ""),
    ("INDEX", "Lookup", ""),
    ("INDIRECT", "Lookup", ""),
    ("LOOKUP", "Lookup", ""),
    ("MATCH", "Lookup", ""),
    ("OFFSET", "Lookup", ""),
    ("PERCENTOF", "Lookup", ""),
    ("PIVOTBY", "Lookup", ""),
    ("ROW", "Lookup", ""),
    ("ROWS", "Lookup", ""),
    ("RTD", "Lookup", ""),
    ("SORT", "Lookup", ""),
    ("SORTBY", "Lookup", ""),
    ("TAKE", "Lookup", ""),
    ("TOCOL", "Lookup", ""),
    ("TOROW", "Lookup", ""),
    ("TRANSPOSE", "Lookup", ""),
    ("TRIMRANGE", "Lookup", ""),
    ("UNIQUE", "Lookup", ""),
    ("VLOOKUP", "Lookup", ""),
    ("VSTACK", "Lookup", ""),
    ("WRAPCOLS", "Lookup", ""),
    ("WRAPROWS", "Lookup", ""),
    ("XLOOKUP", "Lookup", ""),
    ("XMATCH", "Lookup", ""),

    # --- Text ---
    ("ARRAYTOTEXT", "Text", ""),
    ("ASC", "Text", ""),
    ("BAHTTEXT", "Text", ""),
    ("CHAR", "Text", ""),
    ("CLEAN", "Text", ""),
    ("CODE", "Text", ""),
    ("CONCAT", "Text", ""),
    ("DBCS", "Text", ""),
    ("DETECTLANGUAGE", "Text", ""),
    ("DOLLAR", "Text", ""),
    ("EXACT", "Text", ""),
    ("FIND", "Text", ""),
    ("FINDB", "Text", ""),
    ("FIXED", "Text", ""),
    ("LEFT", "Text", ""),
    ("LEFTB", "Text", ""),
    ("LEN", "Text", ""),
    ("LENB", "Text", ""),
    ("LOWER", "Text", ""),
    ("MID", "Text", ""),
    ("MIDB", "Text", ""),
    ("NUMBERVALUE", "Text", ""),
    ("PHONETIC", "Text", ""),
    ("PROPER", "Text", ""),
    ("REGEXEXTRACT", "Text", ""),
    ("REGEXREPLACE", "Text", ""),
    ("REGEXTEST", "Text", ""),
    ("REPLACE", "Text", ""),
    ("REPLACEB", "Text", ""),
    ("REPT", "Text", ""),
    ("RIGHT", "Text", ""),
    ("RIGHTB", "Text", ""),
    ("SEARCH", "Text", ""),
    ("SEARCHB", "Text", ""),
    ("SUBSTITUTE", "Text", ""),
    ("T", "Text", ""),
    ("TEXT", "Text", ""),
    ("TEXTAFTER", "Text", ""),
    ("TEXTBEFORE", "Text", ""),
    ("TEXTJOIN", "Text", ""),
    ("TEXTSPLIT", "Text", ""),
    ("TRANSLATE", "Text", ""),
    ("TRIM", "Text", ""),
    ("UNICHAR", "Text", ""),
    ("UNICODE", "Text", ""),
    ("UPPER", "Text", ""),
    ("VALUE", "Text", ""),
    ("VALUETOTEXT", "Text", ""),

    # --- Date & Time ---
    ("DATE", "Date & Time", ""),
    ("DATEDIF", "Date & Time", ""),
    ("DATEVALUE", "Date & Time", ""),
    ("DAY", "Date & Time", ""),
    ("DAYS", "Date & Time", ""),
    ("DAYS360", "Date & Time", ""),
    ("EDATE", "Date & Time", ""),
    ("EOMONTH", "Date & Time", ""),
    ("HOUR", "Date & Time", ""),
    ("ISOWEEKNUM", "Date & Time", ""),
    ("MINUTE", "Date & Time", ""),
    ("MONTH", "Date & Time", ""),
    ("NETWORKDAYS", "Date & Time", ""),
    ("NETWORKDAYS.INTL", "Date & Time", ""),
    ("NOW", "Date & Time", ""),
    ("SECOND", "Date & Time", ""),
    ("TIME", "Date & Time", ""),
    ("TIMEVALUE", "Date & Time", ""),
    ("TODAY", "Date & Time", ""),
    ("WEEKDAY", "Date & Time", ""),
    ("WEEKNUM", "Date & Time", ""),
    ("WORKDAY", "Date & Time", ""),
    ("WORKDAY.INTL", "Date & Time", ""),
    ("YEAR", "Date & Time", ""),
    ("YEARFRAC", "Date & Time", ""),

    # --- Financial ---
    ("ACCRINT", "Financial", ""),
    ("ACCRINTM", "Financial", ""),
    ("AMORDEGRC", "Financial", ""),
    ("AMORLINC", "Financial", ""),
    ("COUPDAYBS", "Financial", ""),
    ("COUPDAYS", "Financial", ""),
    ("COUPDAYSNC", "Financial", ""),
    ("COUPNCD", "Financial", ""),
    ("COUPNUM", "Financial", ""),
    ("COUPPCD", "Financial", ""),
    ("CUMIPMT", "Financial", ""),
    ("CUMPRINC", "Financial", ""),
    ("DB", "Financial", ""),
    ("DDB", "Financial", ""),
    ("DISC", "Financial", ""),
    ("DOLLARDE", "Financial", ""),
    ("DOLLARFR", "Financial", ""),
    ("DURATION", "Financial", ""),
    ("EFFECT", "Financial", ""),
    ("FV", "Financial", ""),
    ("FVSCHEDULE", "Financial", ""),
    ("INTRATE", "Financial", ""),
    ("IPMT", "Financial", ""),
    ("IRR", "Financial", ""),
    ("ISPMT", "Financial", ""),
    ("MDURATION", "Financial", ""),
    ("MIRR", "Financial", ""),
    ("NOMINAL", "Financial", ""),
    ("NPER", "Financial", ""),
    ("NPV", "Financial", ""),
    ("ODDFPRICE", "Financial", ""),
    ("ODDFYIELD", "Financial", ""),
    ("ODDLPRICE", "Financial", ""),
    ("ODDLYIELD", "Financial", ""),
    ("PDURATION", "Financial", ""),
    ("PMT", "Financial", ""),
    ("PPMT", "Financial", ""),
    ("PRICE", "Financial", ""),
    ("PRICEDISC", "Financial", ""),
    ("PRICEMAT", "Financial", ""),
    ("PV", "Financial", ""),
    ("RATE", "Financial", ""),
    ("RECEIVED", "Financial", ""),
    ("RRI", "Financial", ""),
    ("SLN", "Financial", ""),
    ("STOCKHISTORY", "Financial", ""),
    ("SYD", "Financial", ""),
    ("TBILLEQ", "Financial", ""),
    ("TBILLPRICE", "Financial", ""),
    ("TBILLYIELD", "Financial", ""),
    ("VDB", "Financial", ""),
    ("XIRR", "Financial", ""),
    ("XNPV", "Financial", ""),
    ("YIELD", "Financial", ""),
    ("YIELDDISC", "Financial", ""),
    ("YIELDMAT", "Financial", ""),

    # --- Engineering ---
    ("BESSELI", "Engineering", ""),
    ("BESSELJ", "Engineering", ""),
    ("BESSELK", "Engineering", ""),
    ("BESSELY", "Engineering", ""),
    ("BIN2DEC", "Engineering", ""),
    ("BIN2HEX", "Engineering", ""),
    ("BIN2OCT", "Engineering", ""),
    ("BITAND", "Engineering", ""),
    ("BITLSHIFT", "Engineering", ""),
    ("BITOR", "Engineering", ""),
    ("BITRSHIFT", "Engineering", ""),
    ("BITXOR", "Engineering", ""),
    ("COMPLEX", "Engineering", ""),
    ("CONVERT", "Engineering", ""),
    ("DEC2BIN", "Engineering", ""),
    ("DEC2HEX", "Engineering", ""),
    ("DEC2OCT", "Engineering", ""),
    ("DELTA", "Engineering", ""),
    ("ERF", "Engineering", ""),
    ("ERF.PRECISE", "Engineering", ""),
    ("ERFC", "Engineering", ""),
    ("ERFC.PRECISE", "Engineering", ""),
    ("GESTEP", "Engineering", ""),
    ("HEX2BIN", "Engineering", ""),
    ("HEX2DEC", "Engineering", ""),
    ("HEX2OCT", "Engineering", ""),
    ("IMABS", "Engineering", ""),
    ("IMAGINARY", "Engineering", ""),
    ("IMARGUMENT", "Engineering", ""),
    ("IMCONJUGATE", "Engineering", ""),
    ("IMCOS", "Engineering", ""),
    ("IMCOSH", "Engineering", ""),
    ("IMCOT", "Engineering", ""),
    ("IMCSC", "Engineering", ""),
    ("IMCSCH", "Engineering", ""),
    ("IMDIV", "Engineering", ""),
    ("IMEXP", "Engineering", ""),
    ("IMLN", "Engineering", ""),
    ("IMLOG10", "Engineering", ""),
    ("IMLOG2", "Engineering", ""),
    ("IMPOWER", "Engineering", ""),
    ("IMPRODUCT", "Engineering", ""),
    ("IMREAL", "Engineering", ""),
    ("IMSEC", "Engineering", ""),
    ("IMSECH", "Engineering", ""),
    ("IMSIN", "Engineering", ""),
    ("IMSINH", "Engineering", ""),
    ("IMSQRT", "Engineering", ""),
    ("IMSUB", "Engineering", ""),
    ("IMSUM", "Engineering", ""),
    ("IMTAN", "Engineering", ""),
    ("OCT2BIN", "Engineering", ""),
    ("OCT2DEC", "Engineering", ""),
    ("OCT2HEX", "Engineering", ""),

    # --- Information ---
    ("CELL", "Information", ""),
    ("ERROR.TYPE", "Information", ""),
    ("INFO", "Information", ""),
    ("ISBLANK", "Information", ""),
    ("ISERR", "Information", ""),
    ("ISERROR", "Information", ""),
    ("ISEVEN", "Information", ""),
    ("ISFORMULA", "Information", ""),
    ("ISLOGICAL", "Information", ""),
    ("ISNA", "Information", ""),
    ("ISNONTEXT", "Information", ""),
    ("ISNUMBER", "Information", ""),
    ("ISODD", "Information", ""),
    ("ISOMITTED", "Information", ""),
    ("ISREF", "Information", ""),
    ("ISTEXT", "Information", ""),
    ("N", "Information", ""),
    ("NA", "Information", ""),
    ("SHEET", "Information", ""),
    ("SHEETS", "Information", ""),
    ("TYPE", "Information", ""),

    # --- Database ---
    ("DAVERAGE", "Database", ""),
    ("DCOUNT", "Database", ""),
    ("DCOUNTA", "Database", ""),
    ("DGET", "Database", ""),
    ("DMAX", "Database", ""),
    ("DMIN", "Database", ""),
    ("DPRODUCT", "Database", ""),
    ("DSTDEV", "Database", ""),
    ("DSTDEVP", "Database", ""),
    ("DSUM", "Database", ""),
    ("DVAR", "Database", ""),
    ("DVARP", "Database", ""),

    # --- Cube ---
    ("CUBEKPIMEMBER", "Cube", ""),
    ("CUBEMEMBER", "Cube", ""),
    ("CUBEMEMBERPROPERTY", "Cube", ""),
    ("CUBERANKEDMEMBER", "Cube", ""),
    ("CUBESET", "Cube", ""),
    ("CUBESETCOUNT", "Cube", ""),
    ("CUBEVALUE", "Cube", ""),

    # --- Web ---
    ("ENCODEURL", "Web", ""),
    ("FILTERXML", "Web", ""),
    ("WEBSERVICE", "Web", ""),

    # --- Add-in ---
    ("CALL", "Add-in", ""),
    ("EUROCONVERT", "Add-in", ""),
    ("PY", "Add-in", ""),
    ("REGISTER.ID", "Add-in", ""),
    ("SQL.REQUEST", "Add-in", ""),

    # --- Compatibility (legacy → modern) ---
    ("BETADIST", "Compatibility", "BETA.DIST"),
    ("BETAINV", "Compatibility", "BETA.INV"),
    ("BINOMDIST", "Compatibility", "BINOM.DIST"),
    ("CEILING", "Compatibility", "CEILING.MATH"),
    ("CHIDIST", "Compatibility", "CHISQ.DIST.RT"),
    ("CHIINV", "Compatibility", "CHISQ.INV.RT"),
    ("CHITEST", "Compatibility", "CHISQ.TEST"),
    ("CONCATENATE", "Compatibility", "CONCAT"),
    ("CONFIDENCE", "Compatibility", "CONFIDENCE.NORM"),
    ("COVAR", "Compatibility", "COVARIANCE.P"),
    ("CRITBINOM", "Compatibility", "BINOM.INV"),
    ("EXPONDIST", "Compatibility", "EXPON.DIST"),
    ("FDIST", "Compatibility", "F.DIST.RT"),
    ("FINV", "Compatibility", "F.INV.RT"),
    ("FLOOR", "Compatibility", "FLOOR.MATH"),
    ("FORECAST", "Compatibility", "FORECAST.LINEAR"),
    ("FTEST", "Compatibility", "F.TEST"),
    ("GAMMADIST", "Compatibility", "GAMMA.DIST"),
    ("GAMMAINV", "Compatibility", "GAMMA.INV"),
    ("HYPGEOMDIST", "Compatibility", "HYPGEOM.DIST"),
    ("LOGINV", "Compatibility", "LOGNORM.INV"),
    ("LOGNORMDIST", "Compatibility", "LOGNORM.DIST"),
    ("MODE", "Compatibility", "MODE.SNGL"),
    ("NEGBINOMDIST", "Compatibility", "NEGBINOM.DIST"),
    ("NORMDIST", "Compatibility", "NORM.DIST"),
    ("NORMINV", "Compatibility", "NORM.INV"),
    ("NORMSDIST", "Compatibility", "NORM.S.DIST"),
    ("NORMSINV", "Compatibility", "NORM.S.INV"),
    ("PERCENTILE", "Compatibility", "PERCENTILE.INC"),
    ("PERCENTRANK", "Compatibility", "PERCENTRANK.INC"),
    ("POISSON", "Compatibility", "POISSON.DIST"),
    ("QUARTILE", "Compatibility", "QUARTILE.INC"),
    ("RANK", "Compatibility", "RANK.EQ"),
    ("STDEV", "Compatibility", "STDEV.S"),
    ("STDEVP", "Compatibility", "STDEV.P"),
    ("TDIST", "Compatibility", "T.DIST.2T"),
    ("TINV", "Compatibility", "T.INV.2T"),
    ("TTEST", "Compatibility", "T.TEST"),
    ("VAR", "Compatibility", "VAR.S"),
    ("VARP", "Compatibility", "VAR.P"),
    ("WEIBULL", "Compatibility", "WEIBULL.DIST"),
    ("ZTEST", "Compatibility", "Z.TEST"),
]

# sanity: no duplicates
names = [f[0] for f in functions]
dupes = {n for n in names if names.count(n) > 1}
assert not dupes, f"duplicate function names: {dupes}"

functions.sort(key=lambda f: f[0])

with open("excel_functions.csv", "w", newline="") as f:
    w = csv.writer(f)
    w.writerow(["name", "category", "replaces_with"])
    w.writerows(functions)

print(f"wrote {len(functions)} functions")
