---
title: 'Alchemy-Random: Meta-RL & Lambda Dynamics'
url: https://www.emergentmind.com/topics/alchemy-random
type: topic
---

# Alchemy-Random: Meta-RL & Lambda Dynamics

Alchemy-Random refers to a class of benchmarks and generator mechanisms underpinning two complementary research domains: meta-reinforcement learning (meta-RL) with procedurally randomized latent structure, and computational models of self-organization based on random $\lambda$-calculus expression ensembles. Across both domains, “randomness” in Alchemy is not a superficial input perturbation but a fundamental feature of (a) the stochastic generation of hidden causal “chemistries” within meta-RL tasks and (b) the ensemble properties and dynamical outcomes produced by different algorithms for sampling random computational objects. As such, Alchemy-Random forms a rigorous cornerstone for analyzing structure inference, hypothesis testing, organizational stability, and the emergence of higher-order adaptive behaviors in artificial agents and symbolic systems [2102.02926, 2408.12137].

## 1. Alchemy-Random in Meta-Reinforcement Learning: Problem Setup

Alchemy, as a meta-RL benchmark, is formulated as a partially observable Markov decision process (POMDP) indexed by a latent episode-specific “chemistry” parameter $Z$. Each $Z$—representing one of $|\Theta|=167\,424$ possible causal structures—is sampled i.i.d. from a known prior $P(Z)$ at the start of each episode and remains fixed across its 10 trials. The structural randomness of $Z$ is crucial: it obliges any agent to infer the functional consequences of actions online rather than memorizing policies.

Key elements:

- **State space $S$:** Agent pose, stone latent coordinates $c_i \in \{-1,1\}^3$ (for $i=1,2,3$ per trial), and $Z$ (comprising a subgraph $G$ of a 3-cube and axis-mapping matrices).
- **Action space $A$:** In the 3D variant, 9 continuous dimensions (e.g., strafe, grasp, turn); in the symbolic variant, discrete actions over stone and destination (potion, cauldron, no-op).
- **Transition dynamics $T_Z$:** Applying potion $j$ (effect $p_j$) to stone $i$ updates $c_i$ via $c_i' = c_i + 2p_j$ if the corresponding edge exists in $G$; otherwise $c_i' = c_i$.
- **Reward function $R_Z$:** Only nonzero for a “drop” action, dependent on $\sum_k c_k$; possible values are $-3, -1, +1, +15$.

This construction forces agents to operate under epistemic uncertainty, motivating both multi-episode structure learning (meta-learning) and within-episode posterior inference [2102.02926].

## 2. Generation and Properties of Latent Structure in Alchemy-Random

Each episode’s chemistry $Z$ is generated procedurally using a factorizable prior:
\[
P(Z) = P(N) \cdot P(G|N) \cdot P(S_{\text{rot}}) \cdot P(S_{\text{ref}}) \cdot P(P_{\text{perm}}) \cdot P(P_{\text{ref}})
\]
- $N \in \{0,1,2,3\}$ (number of “preconditions” for $G$).
- $G|N$: Uniform choice from connected subgraphs of the 3-cube consistent with $N$.
- $S_{\text{rot}}$, $S_{\text{ref}}$: Random $45^\circ$ rotations and reflections.
- $P_{\text{perm}}$, $P_{\text{ref}}$: Uniform axis permutations and reflections.

This process yields a combinatorially rich landscape of causal structures, with each $Z$ altering the mapping from latent chemical states and potion effects to observed features and actionable transitions [2102.02926].

## 3. Bayes-Optimal Inference and Analysis Tools

Given known $P(Z)$, a Bayes-optimal “ideal observer” agent maintains a posterior $b_t(Z)$ after $t$ trials:
\[
b_1(Z) \propto P(\text{observations}_1|\text{actions}_1, Z) P(Z)
\]
Action selection in subsequent trials trades off experimentation (entropy reduction in $b_t$) against immediate exploitation. Exhaustive look-ahead in the symbolic version supports calculation of the true Bayes-optimal policy, enabling the establishment of upper performance bounds ($\approx 284$ episode reward), analytic metric baselines (number of potions, posterior entropy), and statistical model-comparison tests to assess agents’ implicit structural knowledge (e.g., acquisition of opposite-potion pairings) [2102.02926].

Key diagnostic metrics include:
- Episode reward
- Potions used in trial 1
- Change in potion use (trial 10 minus trial 1)
- Posterior entropy after early and late trials

Model-fitting can distinguish between agents that recognize latent causal invariants ($H_2$: knows opposite-potion pairings) and those that do not ($H_1$) [2102.02926].

## 4. Empirical Consequences: RL Agent Performance and the Role of Privileged Information

Deep RL baselines (IMPALA, VMPO with Transformer-XL/LSTM) achieve only $\sim$140–156 reward—comparable to a random heuristic and far below the ideal observer. Both the reduction in potions used for diagnosis/exploitation and the decline in posterior entropy across trials are absent. Performance does not improve when removing motor or sensory complexity (symbolic vs. 3D tasks yield similar results), implying the central bottleneck is latent-state inference and online counterfactual reasoning, not surface-level sensory-motor processing.

Augmentations reveal these bottlenecks specifically: provision of belief-state vectors or ground-truth $Z$ code at test time nearly recovers the ideal observer’s performance in symbolic Alchemy, and unsupervised auxiliary losses (predicting category counts and $Z$) substantially improve learning even without privilege, with scores reaching $\sim$260 in 3D. This supports the interpretation that poor inference and representation learning—rather than agent capacity—limits performance on Alchemy-Random [2102.02926].

## 5. AlChemy Random Expression Generators and Dynamical Outcomes

In the classic computational AlChemy framework (Fontana, Buss; revisited [2408.12137]), “randomness” encompasses the procedures for generating initial pools of $\lambda$-expressions, which profoundly shape emergent dynamical organizations.

### Generator Definitions

- **Original (Probabilistic-Grammar) Generator:** Samples expressions recursively with probabilities $P_{\text{var}}(d), P_{\text{abs}}(d), P_{\text{app}}(d)$ at depth $d$, increasing $P_{\text{var}}$ linearly to force termination. Variable emissions pick bound names with probability $q_{\text{bound}} \approx 0.8$. Expected expression size is finite and controlled by $D_{\max}$.
- **Permutation (Random-Binary-Tree) Generator:** Constructs expressions as uniformly random BSTs of size $n$ from random permutations. Node arities correspond to application, abstraction, or variable occurrence, with standardization to close free variables.

### Structural Statistics

| Generator      | Expression Size       | Mean Depth        | Proportion Abstractions | Uniqueness After Dynamics |
|----------------|----------------------|-------------------|------------------------|--------------------------|
| Original       | Variable ($\sim D_{\max}$) | Long chains possible |  Controlled by $q_{\text{bound}}$ | $U(T)\approx 300\pm 200$   |
| Permutation    | Fixed ($n$)          | $\sim 2 \log n$   | 20–30% for large $n$   | $U(T) \to 1.0$ (fixed point)|

In simulation (with $N=1000$ expressions, $T\sim10^5$–$10^6$ collision steps), the original generator produces heavy-tailed size distributions that support stable, autocatalytic organizations (“L₀/L₁” sets) in 20–40% of runs and robustly maintain hundreds of unique expressions. The permutation generator, by contrast, produces uniformly reactive, balanced trees that collapse rapidly to the trivial identity fixed-point. Theoretical explanations attribute this contrast to differing reduction and reactivity properties, with autocatalytic loops only able to survive in more heterogeneous, grammar-generated populations [2408.12137].

## 6. Formal Connection to Chemical Reaction Network Simulation

Using a simply-typed extension, AlChemy demonstrates the formal capacity to simulate arbitrary transitions in chemical reaction networks (CRNs). For a CRN with species $S$ and rules $R_i: A_1 + \ldots + A_n \rightarrow B_1 + \ldots + B_m$, one constructs $\lambda$-expressions where:
- Each species $x\in S$ corresponds to a base type $\tau_x$.
- Each reaction $R_i$ is encoded as combinator $L_i$ of type $\tau_{A_1}\rightarrow\cdots\rightarrow\tau_{A_n}\rightarrow T$.
- Multisets (pools) of typed $\lambda$-expressions map to CRN states.

Simulation proceeds via $\beta$-reductions and collision dynamics, preserving reaction sequences and catalytic regeneration of $L_i$. The inclusion of Church-pair eliminators ($T=\lambda xy.x$, $F=\lambda xy.y$) allows output selection, formally closing the correspondence between typed combinatorial $\lambda$-expression dynamics and conventional CRN path execution [2408.12137]. 

## 7. Significance and Implications of Alchemy-Random

Alchemy-Random operationalizes the interplay between episodic structure learning and self-organization in systems governed by high causal uncertainty and stochastic parametrization. In meta-RL, it exposes the inability of current deep RL methods to perform online latent-structure inference without explicit state or auxiliary scaffolding, even in reduced-complexity settings. In computational chemistry, the phenomenon that generator-induced statistical structure can enable or preclude self-maintaining organizations underscores the role of initial conditions in emergent-order studies. The demonstration that typed extensions permit the simulation of all CRNs establishes AlChemy as a universal framework for modeling the computational substrate of self-organization, providing a bridge between abstract computation and chemical dynamics [2102.02926, 2408.12137].

Source: https://www.emergentmind.com/topics/alchemy-random