aimx/info_library/
statistical_cards.rs

1//! Statistical function documentation cards for AIMX expressions.
2//!
3//! Provides comprehensive documentation for all 25 statistical analysis functions,
4//! including descriptive statistics, distribution functions, correlation analysis,
5//! and statistical tests essential for data-driven workflow automation.
6
7use crate::info_library::{FunctionCard, ArgumentInfo};
8
9/// Statistical function documentation cards.
10pub const STATISTICAL_CARDS: &[FunctionCard] = &[
11    // Descriptive Statistics (8)
12    FunctionCard {
13        identifier: "median",
14        signature: "median(array)",
15        brief: "Calculate the median (middle value) of a numeric array.",
16        description: "Returns the median value, which is the middle value when the data is sorted in ascending order. For even-length arrays, returns the average of the two middle values. The median is a robust measure of central tendency that is less affected by outliers than the mean.",
17        arguments: &[
18            &ArgumentInfo {
19                label: "array",
20                description: "Array of numeric values to calculate median from",
21                type_hint: "Vec<f64>",
22                optional: false,
23            },
24        ],
25        returns: "f64 - The median value of the array",
26        errors: "Returns error if array is empty",
27        categories: &["statistical", "descriptive"],
28        examples: &[
29            "median((1, 2, 3, 4, 5)) → 3",
30            "median((1, 2, 3, 4)) → 2.5",
31            "median((10, 5, 8, 3, 7, 2)) → 6",
32        ],
33    },
34    FunctionCard {
35        identifier: "mode",
36        signature: "mode(array)",
37        brief: "Calculate the mode (most frequent value) of a numeric array.",
38        description: "Returns the value that appears most frequently in the dataset. If multiple values have the same highest frequency, returns the first one encountered. The mode is useful for identifying the most common value or values in a dataset.",
39        arguments: &[
40            &ArgumentInfo {
41                label: "array",
42                description: "Array of numeric values to calculate mode from",
43                type_hint: "Vec<f64>",
44                optional: false,
45            },
46        ],
47        returns: "f64 - The most frequently occurring value",
48        errors: "Returns error if array is empty",
49        categories: &["statistical", "descriptive"],
50        examples: &[
51            "mode((1, 2, 3, 3, 4, 5)) → 3",
52            "mode((1, 1, 2, 2, 3)) → 1",
53            "mode((5, 5, 5, 4, 4, 3)) → 5",
54        ],
55    },
56    FunctionCard {
57        identifier: "range",
58        signature: "range(array)",
59        brief: "Calculate the range (difference between max and min) of a numeric array.",
60        description: "Returns the difference between the maximum and minimum values in the dataset. The range provides a simple measure of statistical dispersion, indicating how spread out the data values are.",
61        arguments: &[
62            &ArgumentInfo {
63                label: "array",
64                description: "Array of numeric values to calculate range from",
65                type_hint: "Vec<f64>",
66                optional: false,
67            },
68        ],
69        returns: "f64 - The range (max - min) of the array",
70        errors: "Returns 0.0 for empty arrays",
71        categories: &["statistical", "descriptive"],
72        examples: &[
73            "range((1, 2, 3, 4, 5)) → 4",
74            "range((10, 5, 8, 3, 7, 2)) → 8",
75            "range((100, 50, 75, 25)) → 75",
76        ],
77    },
78    FunctionCard {
79        identifier: "stdev",
80        signature: "stdev(array)",
81        brief: "Calculate the sample standard deviation of a numeric array.",
82        description: "Returns the sample standard deviation, which measures the amount of variation or dispersion in a set of values. Uses the sample formula (n-1 denominator) which provides an unbiased estimate of the population standard deviation. A low standard deviation indicates values are close to the mean, while a high standard deviation indicates values are spread out.",
83        arguments: &[
84            &ArgumentInfo {
85                label: "array",
86                description: "Array of numeric values to calculate standard deviation from",
87                type_hint: "Vec<f64>",
88                optional: false,
89            },
90        ],
91        returns: "f64 - The sample standard deviation of the array",
92        errors: "Returns 0.0 for arrays with fewer than 2 elements",
93        categories: &["statistical", "descriptive"],
94        examples: &[
95            "stdev((1, 2, 3, 4, 5)) → 1.58",
96            "stdev((10, 10, 10, 10)) → 0",
97            "stdev((1, 5, 10, 15, 20)) → 7.91",
98        ],
99    },
100    FunctionCard {
101        identifier: "confidence",
102        signature: "confidence(alpha, stdev, size)",
103        brief: "Calculate the confidence interval for a population mean.",
104        description: "Returns the margin of error for a confidence interval around a population mean. The confidence interval provides a range of values that likely contains the true population mean with a certain level of confidence. Uses Z-scores for common confidence levels (90%, 95%, 99%) or defaults to 95% for other values.",
105        arguments: &[
106            &ArgumentInfo {
107                label: "alpha",
108                description: "Significance level (1 - confidence level)",
109                type_hint: "f64",
110                optional: false,
111            },
112            &ArgumentInfo {
113                label: "stdev",
114                description: "Sample standard deviation",
115                type_hint: "f64",
116                optional: false,
117            },
118            &ArgumentInfo {
119                label: "size",
120                description: "Sample size",
121                type_hint: "f64",
122                optional: false,
123            },
124        ],
125        returns: "f64 - The confidence interval margin of error",
126        errors: "Returns 0.0 if size <= 1 or standard deviation < 0",
127        categories: &["statistical", "descriptive"],
128        examples: &[
129            "confidence(0.05, 2.5, 100) → 0.49",
130            "confidence(0.01, 1.8, 50) → 0.66",
131            "confidence(0.1, 3.2, 200) → 0.45",
132        ],
133    },
134    FunctionCard {
135        identifier: "margin_of_error",
136        signature: "margin_of_error(array, alpha)",
137        brief: "Calculate the margin of error for a sample mean.",
138        description: "Returns the margin of error for a confidence interval around a sample mean. This represents the radius of the interval that likely contains the true population mean. Uses the sample standard deviation and Z-scores for common confidence levels.",
139        arguments: &[
140            &ArgumentInfo {
141                label: "array",
142                description: "Sample data array",
143                type_hint: "Vec<f64>",
144                optional: false,
145            },
146            &ArgumentInfo {
147                label: "alpha",
148                description: "Significance level (1 - confidence level)",
149                type_hint: "f64",
150                optional: false,
151            },
152        ],
153        returns: "f64 - The margin of error for the sample mean",
154        errors: "Returns 0.0 for empty arrays",
155        categories: &["statistical", "descriptive"],
156        examples: &[
157            "margin_of_error((1, 2, 3, 4, 5), 0.05) → 1.75",
158            "margin_of_error((10, 12, 8, 11, 9), 0.01) → 3.67",
159            "margin_of_error((5, 5, 5, 5), 0.05) → 0",
160        ],
161    },
162    FunctionCard {
163        identifier: "growth_rate",
164        signature: "growth_rate(from, to)",
165        brief: "Calculate the period-over-period growth rate.",
166        description: "Returns the percentage change from an initial value to a final value. Growth rate is commonly used in business and finance to measure performance over time. Handles division by zero cases by returning positive or negative infinity when appropriate.",
167        arguments: &[
168            &ArgumentInfo {
169                label: "from",
170                description: "Initial value (base period)",
171                type_hint: "f64",
172                optional: false,
173            },
174            &ArgumentInfo {
175                label: "to",
176                description: "Final value (comparison period)",
177                type_hint: "f64",
178                optional: false,
179            },
180        ],
181        returns: "f64 - The growth rate as a decimal (multiply by 100 for percentage)",
182        errors: "Returns 0.0 when both values are 0",
183        categories: &["statistical", "descriptive"],
184        examples: &[
185            "growth_rate(100, 120) → 0.2",
186            "growth_rate(50, 40) → -0.2",
187            "growth_rate(0, 100) → Infinity",
188        ],
189    },
190    FunctionCard {
191        identifier: "variance",
192        signature: "variance(array)",
193        brief: "Calculate the sample variance of a numeric array.",
194        description: "Returns the sample variance, which measures how far a set of numbers are spread out from their average value. Variance is the square of the standard deviation and provides another measure of data dispersion. Uses the sample formula (n-1 denominator) for an unbiased estimate.",
195        arguments: &[
196            &ArgumentInfo {
197                label: "array",
198                description: "Array of numeric values to calculate variance from",
199                type_hint: "Vec<f64>",
200                optional: false,
201            },
202        ],
203        returns: "f64 - The sample variance of the array",
204        errors: "Returns 0.0 for arrays with fewer than 2 elements",
205        categories: &["statistical", "descriptive"],
206        examples: &[
207            "variance((1, 2, 3, 4, 5)) → 2.5",
208            "variance((10, 10, 10, 10)) → 0",
209            "variance((1, 5, 10, 15, 20)) → 62.5",
210        ],
211    },
212    // Distribution Functions (3)
213    FunctionCard {
214        identifier: "percentile",
215        signature: "percentile(array, percentage)",
216        brief: "Calculate the value at a specific percentile in a numeric array.",
217        description: "Returns the value below which a given percentage of observations in a group of observations falls. Uses linear interpolation between adjacent values when the exact percentile falls between data points. Percentiles are useful for understanding the distribution of data and identifying thresholds.",
218        arguments: &[
219            &ArgumentInfo {
220                label: "array",
221                description: "Array of numeric values",
222                type_hint: "Vec<f64>",
223                optional: false,
224            },
225            &ArgumentInfo {
226                label: "percentage",
227                description: "Percentile to calculate (0-100)",
228                type_hint: "f64",
229                optional: false,
230            },
231        ],
232        returns: "f64 - The value at the specified percentile",
233        errors: "Returns error if array is empty or percentage is not between 0 and 100",
234        categories: &["statistical", "distribution"],
235        examples: &[
236            "percentile((1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 50) → 5",
237            "percentile((1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 75) → 8.25",
238            "percentile((10, 20, 30, 40, 50), 90) → 46",
239        ],
240    },
241    FunctionCard {
242        identifier: "quartile",
243        signature: "quartile(array, quartile)",
244        brief: "Calculate the value at a specific quartile in a numeric array.",
245        description: "Returns the value at the first (Q1), second (Q2/median), or third (Q3) quartile. Quartiles divide the dataset into four equal parts and are commonly used in box plots and to identify the interquartile range (IQR). Q1 represents the 25th percentile, Q2 the 50th percentile (median), and Q3 the 75th percentile.",
246        arguments: &[
247            &ArgumentInfo {
248                label: "array",
249                description: "Array of numeric values",
250                type_hint: "Vec<f64>",
251                optional: false,
252            },
253            &ArgumentInfo {
254                label: "quartile",
255                description: "Quartile number (1, 2, or 3)",
256                type_hint: "f64",
257                optional: false,
258            },
259        ],
260        returns: "f64 - The value at the specified quartile",
261        errors: "Returns error if array is empty or quartile is not 1, 2, or 3",
262        categories: &["statistical", "distribution"],
263        examples: &[
264            "quartile((1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 1) → 3",
265            "quartile((1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 2) → 5.5",
266            "quartile((1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 3) → 8",
267        ],
268    },
269    FunctionCard {
270        identifier: "frequency",
271        signature: "frequency(array, bins)",
272        brief: "Calculate the frequency distribution of values across bins.",
273        description: "Returns an array showing how many values fall into each of a specified number of equal-width bins. Frequency distributions are useful for understanding the shape of data distribution and identifying patterns such as normal distribution, skewness, or outliers.",
274        arguments: &[
275            &ArgumentInfo {
276                label: "array",
277                description: "Array of numeric values to analyze",
278                type_hint: "Vec<f64>",
279                optional: false,
280            },
281            &ArgumentInfo {
282                label: "bins",
283                description: "Number of bins to divide the data range into",
284                type_hint: "f64",
285                optional: false,
286            },
287        ],
288        returns: "Vec<f64> - Array of frequencies for each bin",
289        errors: "Returns error if bins <= 0 or array is empty",
290        categories: &["statistical", "distribution"],
291        examples: &[
292            "frequency((1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 5) → (2, 2, 2, 2, 2)",
293            "frequency((1, 1, 2, 2, 2, 3, 3, 4), 4) → (2, 3, 2, 1)",
294            "frequency((10, 20, 30, 40, 50), 3) → (2, 1, 2)",
295        ],
296    },
297    // Counting Functions (8)
298    FunctionCard {
299        identifier: "unique_count",
300        signature: "unique_count(array)",
301        brief: "Count the number of unique values in an array.",
302        description: "Returns the count of distinct values in the dataset. This is useful for understanding data diversity, identifying duplicate records, or measuring the variety of values in a dataset.",
303        arguments: &[
304            &ArgumentInfo {
305                label: "array",
306                description: "Array of values to count unique values from",
307                type_hint: "Vec<f64>",
308                optional: false,
309            },
310        ],
311        returns: "f64 - The number of unique values in the array",
312        errors: "Returns 0.0 for empty arrays",
313        categories: &["statistical", "counting"],
314        examples: &[
315            "unique_count((1, 2, 3, 4, 5)) → 5",
316            "unique_count((1, 1, 2, 2, 3)) → 3",
317            "unique_count((5, 5, 5, 5)) → 1",
318        ],
319    },
320    FunctionCard {
321        identifier: "count_if_gt",
322        signature: "count_if_gt(array, threshold)",
323        brief: "Count values greater than a threshold.",
324        description: "Returns the number of values in the array that are strictly greater than the specified threshold. Useful for filtering data and counting occurrences above certain limits.",
325        arguments: &[
326            &ArgumentInfo {
327                label: "array",
328                description: "Array of numeric values to count from",
329                type_hint: "Vec<f64>",
330                optional: false,
331            },
332            &ArgumentInfo {
333                label: "threshold",
334                description: "Threshold value to compare against",
335                type_hint: "f64",
336                optional: false,
337            },
338        ],
339        returns: "f64 - Count of values greater than threshold",
340        errors: "Returns 0.0 for empty arrays",
341        categories: &["statistical", "counting"],
342        examples: &[
343            "count_if_gt((1, 2, 3, 4, 5), 3) → 2",
344            "count_if_gt((10, 20, 30, 40, 50), 25) → 3",
345            "count_if_gt((1, 1, 1, 1), 2) → 0",
346        ],
347    },
348    FunctionCard {
349        identifier: "count_if_ge",
350        signature: "count_if_ge(array, threshold)",
351        brief: "Count values greater than or equal to a threshold.",
352        description: "Returns the number of values in the array that are greater than or equal to the specified threshold. Similar to count_if_gt but includes values that exactly match the threshold.",
353        arguments: &[
354            &ArgumentInfo {
355                label: "array",
356                description: "Array of numeric values to count from",
357                type_hint: "Vec<f64>",
358                optional: false,
359            },
360            &ArgumentInfo {
361                label: "threshold",
362                description: "Threshold value to compare against",
363                type_hint: "f64",
364                optional: false,
365            },
366        ],
367        returns: "f64 - Count of values greater than or equal to threshold",
368        errors: "Returns 0.0 for empty arrays",
369        categories: &["statistical", "counting"],
370        examples: &[
371            "count_if_ge((1, 2, 3, 4, 5), 3) → 3",
372            "count_if_ge((10, 20, 30, 40, 50), 30) → 3",
373            "count_if_ge((1, 1, 1, 1), 1) → 4",
374        ],
375    },
376    FunctionCard {
377        identifier: "count_if_lt",
378        signature: "count_if_lt(array, threshold)",
379        brief: "Count values less than a threshold.",
380        description: "Returns the number of values in the array that are strictly less than the specified threshold. Useful for counting occurrences below certain limits or identifying values in the lower range of a dataset.",
381        arguments: &[
382            &ArgumentInfo {
383                label: "array",
384                description: "Array of numeric values to count from",
385                type_hint: "Vec<f64>",
386                optional: false,
387            },
388            &ArgumentInfo {
389                label: "threshold",
390                description: "Threshold value to compare against",
391                type_hint: "f64",
392                optional: false,
393            },
394        ],
395        returns: "f64 - Count of values less than threshold",
396        errors: "Returns 0.0 for empty arrays",
397        categories: &["statistical", "counting"],
398        examples: &[
399            "count_if_lt((1, 2, 3, 4, 5), 3) → 2",
400            "count_if_lt((10, 20, 30, 40, 50), 25) → 2",
401            "count_if_lt((5, 5, 5, 5), 4) → 0",
402        ],
403    },
404    FunctionCard {
405        identifier: "count_if_le",
406        signature: "count_if_le(array, threshold)",
407        brief: "Count values less than or equal to a threshold.",
408        description: "Returns the number of values in the array that are less than or equal to the specified threshold. Similar to count_if_lt but includes values that exactly match the threshold.",
409        arguments: &[
410            &ArgumentInfo {
411                label: "array",
412                description: "Array of numeric values to count from",
413                type_hint: "Vec<f64>",
414                optional: false,
415            },
416            &ArgumentInfo {
417                label: "threshold",
418                description: "Threshold value to compare against",
419                type_hint: "f64",
420                optional: false,
421            },
422        ],
423        returns: "f64 - Count of values less than or equal to threshold",
424        errors: "Returns 0.0 for empty arrays",
425        categories: &["statistical", "counting"],
426        examples: &[
427            "count_if_le((1, 2, 3, 4, 5), 3) → 3",
428            "count_if_le((10, 20, 30, 40, 50), 30) → 3",
429            "count_if_le((5, 5, 5, 5), 5) → 4",
430        ],
431    },
432    FunctionCard {
433        identifier: "count_if",
434        signature: "count_if(array, value)",
435        brief: "Count values equal to a specific value.",
436        description: "Returns the number of values in the array that exactly match the specified value. Uses floating-point comparison with epsilon tolerance to handle precision issues.",
437        arguments: &[
438            &ArgumentInfo {
439                label: "array",
440                description: "Array of numeric values to count from",
441                type_hint: "Vec<f64>",
442                optional: false,
443            },
444            &ArgumentInfo {
445                label: "value",
446                description: "Value to count occurrences of",
447                type_hint: "f64",
448                optional: false,
449            },
450        ],
451        returns: "f64 - Count of values equal to the specified value",
452        errors: "Returns 0.0 for empty arrays",
453        categories: &["statistical", "counting"],
454        examples: &[
455            "count_if((1, 2, 3, 2, 4, 2), 2) → 3",
456            "count_if((1.0, 1.0001, 1.0002, 1.0), 1.0) → 2",
457            "count_if((5, 5, 5, 5), 3) → 0",
458        ],
459    },
460    FunctionCard {
461        identifier: "count_if_ne",
462        signature: "count_if_ne(array, value)",
463        brief: "Count values not equal to a specific value.",
464        description: "Returns the number of values in the array that do not match the specified value. This is the complement of count_if and is useful for identifying values that differ from a baseline or expected value.",
465        arguments: &[
466            &ArgumentInfo {
467                label: "array",
468                description: "Array of numeric values to count from",
469                type_hint: "Vec<f64>",
470                optional: false,
471            },
472            &ArgumentInfo {
473                label: "value",
474                description: "Value to exclude from count",
475                type_hint: "f64",
476                optional: false,
477            },
478        ],
479        returns: "f64 - Count of values not equal to the specified value",
480        errors: "Returns 0.0 for empty arrays",
481        categories: &["statistical", "counting"],
482        examples: &[
483            "count_if_ne((1, 2, 3, 2, 4, 2), 2) → 3",
484            "count_if_ne((5, 5, 5, 5), 5) → 0",
485            "count_if_ne((1, 2, 3, 4, 5), 10) → 5",
486        ],
487    },
488    // Correlation & Regression (2)
489    FunctionCard {
490        identifier: "slope",
491        signature: "slope(x_values, y_values)",
492        brief: "Calculate the slope of the linear regression line.",
493        description: "Returns the slope of the best-fit line through a set of x,y data points using the least squares method. The slope represents the rate of change in the dependent variable (y) for each unit change in the independent variable (x). A positive slope indicates a positive relationship, while a negative slope indicates a negative relationship.",
494        arguments: &[
495            &ArgumentInfo {
496                label: "x_values",
497                description: "Array of independent variable values",
498                type_hint: "Vec<f64>",
499                optional: false,
500            },
501            &ArgumentInfo {
502                label: "y_values",
503                description: "Array of dependent variable values",
504                type_hint: "Vec<f64>",
505                optional: false,
506            },
507        ],
508        returns: "f64 - The slope of the regression line",
509        errors: "Returns error if arrays have different lengths or fewer than 2 points",
510        categories: &["statistical", "correlation"],
511        examples: &[
512            "slope((1, 2, 3, 4, 5), (2, 4, 6, 8, 10)) → 2",
513            "slope((1, 2, 3), (1, 1, 1)) → 0",
514            "slope((1, 2, 3, 4), (4, 3, 2, 1)) → -1",
515        ],
516    },
517    FunctionCard {
518        identifier: "correlation",
519        signature: "correlation(x_values, y_values)",
520        brief: "Calculate the Pearson correlation coefficient.",
521        description: "Returns the Pearson correlation coefficient (r), which measures the linear relationship between two variables. The value ranges from -1 to 1, where 1 indicates a perfect positive linear relationship, -1 indicates a perfect negative linear relationship, and 0 indicates no linear relationship. Correlation does not imply causation.",
522        arguments: &[
523            &ArgumentInfo {
524                label: "x_values",
525                description: "Array of first variable values",
526                type_hint: "Vec<f64>",
527                optional: false,
528            },
529            &ArgumentInfo {
530                label: "y_values",
531                description: "Array of second variable values",
532                type_hint: "Vec<f64>",
533                optional: false,
534            },
535        ],
536        returns: "f64 - Pearson correlation coefficient (-1 to 1)",
537        errors: "Returns error if arrays have different lengths or fewer than 2 points",
538        categories: &["statistical", "correlation"],
539        examples: &[
540            "correlation((1, 2, 3, 4, 5), (2, 4, 6, 8, 10)) → 1",
541            "correlation((1, 2, 3, 4, 5), (5, 4, 3, 2, 1)) → -1",
542            "correlation((1, 2, 3, 4, 5), (1, 5, 2, 4, 3)) → 0",
543        ],
544    },
545    // Data Analysis (5)
546    FunctionCard {
547        identifier: "moving_average",
548        signature: "moving_average(array, period)",
549        brief: "Calculate the moving average over a specified period.",
550        description: "Returns an array of moving averages, which smooths data by creating a series of averages of different subsets of the full dataset. Moving averages are commonly used in time series analysis to identify trends and reduce noise. Each value in the result represents the average of the current and previous (period-1) values.",
551        arguments: &[
552            &ArgumentInfo {
553                label: "array",
554                description: "Array of numeric values",
555                type_hint: "Vec<f64>",
556                optional: false,
557            },
558            &ArgumentInfo {
559                label: "period",
560                description: "Number of periods to include in each average",
561                type_hint: "f64",
562                optional: false,
563            },
564        ],
565        returns: "Vec<f64> - Array of moving average values",
566        errors: "Returns error if period <= 0 or period > array length",
567        categories: &["statistical", "analysis"],
568        examples: &[
569            "moving_average((1, 2, 3, 4, 5), 3) → (2, 3, 4)",
570            "moving_average((10, 15, 13, 17, 20, 18), 2) → (12.5, 14, 15, 18.5, 19)",
571            "moving_average((5, 5, 5, 5), 4) → (5)",
572        ],
573    },
574    FunctionCard {
575        identifier: "cumulative_sum",
576        signature: "cumulative_sum(array)",
577        brief: "Calculate the cumulative sum of an array.",
578        description: "Returns an array where each element is the sum of all previous elements in the original array including itself. Cumulative sums are useful for tracking running totals, analyzing growth patterns, and creating cumulative distribution functions.",
579        arguments: &[
580            &ArgumentInfo {
581                label: "array",
582                description: "Array of numeric values",
583                type_hint: "Vec<f64>",
584                optional: false,
585            },
586        ],
587        returns: "Vec<f64> - Array of cumulative sums",
588        errors: "Returns empty array for empty input",
589        categories: &["statistical", "analysis"],
590        examples: &[
591            "cumulative_sum((1, 2, 3, 4, 5)) → (1, 3, 6, 10, 15)",
592            "cumulative_sum((10, -5, 3, -2)) → (10, 5, 8, 6)",
593            "cumulative_sum((1, 1, 1, 1)) → (1, 2, 3, 4)",
594        ],
595    },
596    FunctionCard {
597        identifier: "rank",
598        signature: "rank(array, value)",
599        brief: "Calculate the rank of a value within an array.",
600        description: "Returns the rank of a specified value when the array is sorted in descending order (highest value gets rank 1). Ranks are useful for identifying the relative position of values within a dataset, such as finding the top performers or percentile rankings.",
601        arguments: &[
602            &ArgumentInfo {
603                label: "array",
604                description: "Array of numeric values to rank within",
605                type_hint: "Vec<f64>",
606                optional: false,
607            },
608            &ArgumentInfo {
609                label: "value",
610                description: "Value to find the rank of",
611                type_hint: "f64",
612                optional: false,
613            },
614        ],
615        returns: "f64 - The rank of the value (1-based)",
616        errors: "Returns error if array is empty or value not found",
617        categories: &["statistical", "analysis"],
618        examples: &[
619            "rank((1, 2, 3, 4, 5), 3) → 3",
620            "rank((10, 5, 8, 3, 7), 8) → 2",
621            "rank((100, 50, 75, 25), 50) → 3",
622        ],
623    },
624    FunctionCard {
625        identifier: "percentile_rank",
626        signature: "percentile_rank(array, value)",
627        brief: "Calculate the percentile rank of a value within an array.",
628        description: "Returns the percentile rank of a specified value, which represents the percentage of values in the array that are less than or equal to the given value. Percentile ranks are commonly used in standardized testing and performance evaluation to show relative standing within a group.",
629        arguments: &[
630            &ArgumentInfo {
631                label: "array",
632                description: "Array of numeric values to rank within",
633                type_hint: "Vec<f64>",
634                optional: false,
635            },
636            &ArgumentInfo {
637                label: "value",
638                description: "Value to find the percentile rank of",
639                type_hint: "f64",
640                optional: false,
641            },
642        ],
643        returns: "f64 - The percentile rank as a percentage (0-100)",
644        errors: "Returns error if array is empty",
645        categories: &["statistical", "analysis"],
646        examples: &[
647            "percentile_rank((1, 2, 3, 4, 5), 3) → 40",
648            "percentile_rank((10, 20, 30, 40, 50), 30) → 40",
649            "percentile_rank((1, 1, 2, 2, 3), 2) → 60",
650        ],
651    },
652    FunctionCard {
653        identifier: "outliers",
654        signature: "outliers(array)",
655        brief: "Detect statistical outliers using the IQR method.",
656        description: "Returns values that are identified as outliers using the Interquartile Range (IQR) method. Outliers are defined as values that fall below Q1 - 1.5×IQR or above Q3 + 1.5×IQR, where Q1 and Q3 are the first and third quartiles. This method is robust and commonly used in box plot analysis.",
657        arguments: &[
658            &ArgumentInfo {
659                label: "array",
660                description: "Array of numeric values to analyze for outliers",
661                type_hint: "Vec<f64>",
662                optional: false,
663            },
664        ],
665        returns: "Vec<f64> - Array of outlier values",
666        errors: "Returns empty array for empty input",
667        categories: &["statistical", "analysis"],
668        examples: &[
669            "outliers((1, 2, 3, 4, 5, 100)) → (100)",
670            "outliers((10, 12, 11, 13, 14, 15, 50)) → (50)",
671            "outliers((1, 2, 3, 4, 5)) → ()",
672        ],
673    },
674];