Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:1kbgz Tributary Automatic Differentiation

From Leeroopedia
Knowledge Sources
Domains Automatic_Differentiation, Mathematical_Operators
Last Updated 2026-10-14 00:00 GMT

Overview

A technique for computing exact derivatives of functions by augmenting each arithmetic operation with a derivative computation, using dual numbers to carry both the function value and its derivative through the computation graph.

Description

Forward-mode automatic differentiation (AD) computes derivatives by propagating tangent values alongside primal values through a computation. The dual number extension ℝ[ε] represents values as (v,v′) where v is the function value and v′ is the derivative with respect to a chosen input.

Each arithmetic operation is augmented with its derivative rule:

  • Addition: (a+b,a′+b′)
  • Multiplication: (a⋅b,a⋅b′+a′⋅b) (product rule)
  • Power: (ab,b⋅a′⋅ab−1)
  • Sine: (sin⁡(a),cos⁡(a)⋅a′)
  • Cosine: (cos⁡(a),−sin⁡(a)⋅a′)

This solves the problem of numerical differentiation, which is inaccurate (finite differences) or infeasible (symbolic differentiation explodes for complex expressions). Forward-mode AD gives exact derivatives in O(1)x the cost of the original computation.

Usage

Use this principle when you need exact derivatives of mathematical functions expressed as computation graphs:

  • Gradient-based optimization (sensitivity analysis)
  • Physics simulations requiring Jacobians
  • Financial risk calculations (Greeks)
  • Verifying analytical derivatives against numerical tests

In Tributary, enable by setting use_dual=True on input nodes; all downstream operators automatically select their dual-number lambda variants.

Theoretical Basis

Dual numbers extend real numbers with an infinitesimal element ε where ε2=0:

a+bεwhereε2=0

A function f evaluated at x+ε gives:

f(x+ε)=f(x)+f′(x)ε

This is Taylor expansion truncated at first order, justified because ε2=0.

The chain rule is automatically satisfied through composition:

f(g(x+ε))=f(g(x)+g′(x)ε)=f(g(x))+f′(g(x))⋅g′(x)⋅ε

# Abstract dual-number arithmetic (NOT real implementation)
class Dual:
    def __init__(self, value, derivative):
        self.v = value       # primal (function value)
        self.d = derivative  # tangent (derivative)

    def __mul__(self, other):
        return Dual(
            self.v * other.v,
            self.v * other.d + self.d * other.v  # product rule
        )

    def __add__(self, other):
        return Dual(
            self.v + other.v,
            self.d + other.d
        )

To compute f′(x): set the input seed ε=1 (i.e., x=(x0,1)) and read the derivative from result[1].

Related Pages

Implemented By

Uses Heuristics

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment