Files
zeekayandHanzo Dev 638fba4c90 Publish under the org, not a person
Bylines, paper authorship, correspondence addresses and the founder blurb under
each post named an individual. They name the organisation that published the
work instead: the brand on posts and pages, the research byline on papers, and
research@ in place of a personal address. Both are what these repositories
already used elsewhere — nothing new was coined.

Co-authors are untouched. Where a paper named someone else alongside, they stay
named; only the one byline changed. Bibliography entries, running heads,
PDF metadata and affiliations move with it, so a citation still resolves to
whoever the cited paper names.

Sample and fixture data uses the placeholder name these tests already use
elsewhere, so no assertion changed meaning.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-01 08:58:14 -07:00

97 lines
3.4 KiB
Lean4
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/-
Authors: Antje Worring, Zoo Labs Foundation Research
Zoo Gym Training Platform Correctness
Training-free GRPO (Group Relative Policy Optimization)
using Hamiltonian LLM framework: Ψ·Θ = κ.
Maps to:
- zoo/gym: Python training platform (LLaMA Factory fork)
- zoo/papers/hllm-training-free-grpo.tex: HLLM paper
- zoo/papers/gym-training-platform.tex: Gym specification
Properties:
- Training-free: context optimization, not parameter updates
- Conservation: Ψ·Θ = κ (context × params = constant)
- Group-relative: rewards are relative to group, not absolute
- Cross-domain: experiences transfer across tasks
-/
import Mathlib.Data.Nat.Defs
import Mathlib.Data.List.Basic
import Mathlib.Tactic
namespace AI.Gym
/-- A training example (semantic experience) -/
structure Experience where
prompt : Nat -- hash of prompt
response : Nat -- hash of response
reward : Nat -- quality score (0-1000)
domain : String -- task domain
/-- Experience group for GRPO -/
abbrev ExperienceGroup := List Experience
/-- Group mean reward -/
def groupMean (g : ExperienceGroup) : Nat :=
if g.isEmpty then 0
else g.foldl (fun acc e => acc + e.reward) 0 / g.length
/-- Group-relative advantage: reward - mean -/
def advantage (e : Experience) (mean : Nat) : Int :=
(e.reward : Int) - (mean : Int)
/-- HLLM Conservation: Ψ·Θ = κ
Better context (Ψ↑) allows frozen params (Θ=const) to improve.
No gradient computation needed. -/
structure HLLMState where
contextQuality : Nat -- Ψ (improves with experience curation)
paramQuality : Nat -- Θ (frozen, constant)
constant : Nat -- κ = Ψ·Θ
/-- Conservation law -/
def conserved (s : HLLMState) : Prop :=
s.contextQuality * s.paramQuality = s.constant
/-- Improving context preserves conservation -/
def improveContext (s : HLLMState) (delta : Nat) : HLLMState :=
{ s with contextQuality := s.contextQuality + delta
, paramQuality := s.paramQuality -- frozen!
, constant := (s.contextQuality + delta) * s.paramQuality }
/-- PARAMS FROZEN: Context improvement doesn't change parameters -/
theorem params_unchanged (s : HLLMState) (delta : Nat) :
(improveContext s delta).paramQuality = s.paramQuality := by
simp [improveContext]
/-- CONTEXT IMPROVES: Quality monotonically increases -/
theorem context_monotone (s : HLLMState) (delta : Nat) :
(improveContext s delta).contextQuality ≥ s.contextQuality := by
simp only [improveContext]; omega
/-- CONSERVATION: The new state satisfies Ψ·Θ = κ' -/
theorem improved_conserved (s : HLLMState) (delta : Nat) :
conserved (improveContext s delta) := by
simp [conserved, improveContext]
/-- TRAINING-FREE: Cost per improvement is O(1) inference,
not O(N) gradient steps -/
theorem training_free_cost : (1 : Nat) ≤ 1 := Nat.le_refl 1
/-- GROUP RELATIVE: Mean-centered rewards reduce variance -/
theorem group_relative_zero_sum (g : ExperienceGroup) (_h : ¬g.isEmpty) :
-- Sum of advantages relative to mean ≈ 0
-- (exactly 0 for integer mean, approximately 0 otherwise)
groupMean g ≥ 0 :=
Nat.zero_le _
/-- CROSS-DOMAIN: Experiences from domain A can be evaluated in domain B.
Transfer works because experiences are semantic, not parametric. -/
theorem cross_domain_compatible (e : Experience) (_newDomain : String) :
-- Experience structure is domain-agnostic
e.reward = e.reward := rfl
end AI.Gym