Lean 4 is an open-source programming language and interactive proof assistant where mathematics and code become the exact same thing.
Unlike traditional languages like Python or C++ that simply run instructions, Lean is built on dependent type theory. This allows you to write mathematical statements as types and construct their proofs as programs. A tiny, strict verification engine checks every single logical step—if you skip a step, miss an edge case, or make a false assumption, the code simply refuses to compile.
This makes Lean 4 especially valuable in modern AI research. While an AI can easily generate a plausible-sounding proof in plain English that hides a subtle flaw, Lean acts as an incorruptible referee, forcing the model to prove every deduction down to the foundational axioms. Beyond formal verification, Lean 4 also compiles to fast C code, making it a capable functional programming language for building real-world software, tools, and simulations.
In short: if your code compiles in Lean 4, your logic is 100% bulletproof. See the online tool.
-- Gordon Growth Model (Constant-Growth Dividend Discount Model) in Lean 4
-- Formula: P0 = D1 / (r - g), where D1 = D0 * (1 + g) and r > g
structure GordonParams where
d0 : Float -- Last annual dividend per share
g : Float -- Constant annual dividend growth rate (e.g., 0.04 for 4%)
r : Float -- Required annual return / discount rate (e.g., 0.09 for 9%)
deriving Repr
-- Next year's expected dividend: D1 = D0 * (1 + g)
def expectedDividend (p : GordonParams) : Float :=
p.d0 * (1.0 + p.g)
-- Intrinsic value P0 = D1 / (r - g) when r > g
def gordonFairValue (p : GordonParams) : Option Float :=
let spread := p.r - p.g
if spread > 0.0 then
some (expectedDividend p / spread)
else
none
-- Implied required return r = (D1 / P0) + g for a given market price p0 > 0
def impliedReturn (d1 p0 g : Float) : Option Float :=
if p0 > 0.0 then
some ((d1 / p0) + g)
else
none
-- Formal algebraic proof:
-- (a + b) - (a + c) = b - c (useful for comparing spread changes: r2 - r1)
theorem spread_difference (a b c : Int) : (a + b) - (a + c) = b - c := by
omega
def runGordonDemo : IO Unit := do
-- Example: D0 = $2.00, growth g = 5% (0.05), required return r = 9% (0.09)
-- D1 = 2.00 * 1.05 = 2.10; spread = 0.09 - 0.05 = 0.04 => Fair Value = 2.10 / 0.04 = $52.50
let p : GordonParams := { d0 := 2.0, g := 0.05, r := 0.09 }
let d1 := expectedDividend p
IO.println s!"Expected Dividend D1: {d1}"
match gordonFairValue p with
| some fairVal =>
IO.println s!"Gordon Fair Value P0: {fairVal}"
match impliedReturn d1 fairVal p.g with
| some impR => IO.println s!"Implied Return r check: {impR}"
| none => IO.println "Invalid price for implied return"
| none =>
IO.println "Invalid parameters: require r > g"
#eval runGordonDemo
