Skip to content

minikin/antifragile

Antifragile

Crates.io Documentation License: MIT CI

A Rust library attempting to implement Nassim Nicholas Taleb's antifragility theory.

Overview

This library provides a trait-based system for analyzing how systems respond to stress and volatility, classifying them into three categories:

Installation

[dependencies]
antifragile = "0.0.1"

Quick Start

use antifragile::{Antifragile, Triad, TriadAnalysis};

// Define a system with convex response (benefits from volatility)
struct ConvexSystem;

impl Antifragile for ConvexSystem {
    type Stressor = f64;
    type Payoff = f64;

    fn payoff(&self, x: Self::Stressor) -> Self::Payoff {
        x * x  // Quadratic: convex response
    }
}

let system = ConvexSystem;
assert_eq!(system.classify(10.0, 1.0), Triad::Antifragile);

Core Concepts

The Antifragile Trait

Implement the Antifragile trait to define how your system responds to stress:

use antifragile::Antifragile;

struct MySystem;

impl Antifragile for MySystem {
    type Stressor = f64;  // The type of stress applied
    type Payoff = f64;    // The outcome produced

    fn payoff(&self, stressor: Self::Stressor) -> Self::Payoff {
        // Define your system's response to stress
        stressor * stressor
    }
}

The Triad Classification

The Triad enum represents the three categories:

use antifragile::Triad;

let classification = Triad::Antifragile;

// Check classification
assert!(classification.is_antifragile());

// Ordering: Fragile < Robust < Antifragile
assert!(Triad::Fragile < Triad::Robust);
assert!(Triad::Robust < Triad::Antifragile);

// Convert to/from strings
let s: &str = classification.into();  // "antifragile"
let parsed: Triad = "robust".parse().unwrap();

// Convert to/from u8 (Fragile=0, Robust=1, Antifragile=2)
let n: u8 = classification.into();  // 2
let from_n = Triad::try_from(1u8).unwrap();  // Triad::Robust

The Verified Wrapper

Use Verified to wrap a system with its verified classification:

use antifragile::{Antifragile, Verified, TriadAnalysis};

struct MySystem;
impl Antifragile for MySystem {
    type Stressor = f64;
    type Payoff = f64;
    fn payoff(&self, x: Self::Stressor) -> Self::Payoff { x * x }
}

let verified = Verified::check(MySystem, 10.0, 1.0);
println!("Classification: {}", verified.classification());

Mathematical Foundation

The classification is based on second-order effects (convexity):

For a payoff function f(x) at operating point x with perturbation δ:

  • Convex (Antifragile): f(x+δ) + f(x-δ) > 2·f(x)
  • Concave (Fragile): f(x+δ) + f(x-δ) < 2·f(x)
  • Linear (Robust): f(x+δ) + f(x-δ) = 2·f(x)

This is Jensen's inequality applied to volatility.

When to Use This Library

Good fit:

  • Analyzing financial instruments (options, insurance)
  • Evaluating system resilience in chaos engineering
  • Comparing algorithms under varying load
  • Educational purposes (demonstrating Taleb's theory)

Not a good fit:

  • Real-time trading decisions (too abstract)
  • Systems where "stress" is not mathematically quantifiable
  • Cases requiring probabilistic analysis (use Monte Carlo instead)

Feature Flags

Feature Default Description
std Yes Enable standard library support. Disable for no_std environments.
serde No Enable serialization/deserialization for Triad and Verified.

Using in no_std environments

[dependencies]
antifragile = { version = "0.0.1", default-features = false }

Enabling serde support

[dependencies]
antifragile = { version = "0.0.1", features = ["serde"] }

Minimum Supported Rust Version

This crate requires Rust 1.85 or later (edition 2024).

License

Licensed under the MIT License. See LICENSE for details.

About

A Rust library, attempting to implement Nassim Nicholas Taleb's antifragility theory.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Contributors

Languages