Problem: Chemical Species State Estimation and Uncertainty Propagation

The problem focuses on building a suite of Python utilities for dynamic chemical reaction-transport system modeling, covering species state propagation, uncertainty evolution, observation correction coefficient calculation, and observation-consistent state equilibration, to deliver numerically stable, validated tools for accurate simulation and adjustment of chemical species dynamics with standard input validity checks.


Input/Output: The problem receives the following valid inputs: 1) 1D or 2D chemical species state (Union[numpy.ndarray, List[float], List[List[float]]], structured as interleaved concentration and reaction rate entries), 2) positive reaction time interval (float), 3) three 2×2 symmetric List[List[float]] matrices: initial reaction uncertainty tensor, linear chemical interaction map, symmetric fluctuation source tensor, 4) square prior uncertainty matrix, 2D observation operator, scalar/1D/2D measurement fluctuation, 5) prior species profile array, modulation coefficient array, observed signal array, observation operator matrix. All inputs first go through validity checks including dimension matching, symmetry verification, and positive value validation before computation. The problem outputs four corresponding results sequentially: 1) propagated next species profile preserving the original input type, 2) evolved 2×2 symmetric uncertainty tensor as List[List[float]], 3) reaction modulation coefficient List[float], 4) tuple of equilibrated updated species profile list and updated symmetric uncertainty tensor list.

Required dependencies:

Sub-steps:
step_number: 1
step_description_prompt: Please write a Python function named propagate_species_profile. It predicts the next chemical species profile (interleaved concentration and reaction rate entries) using a linear reaction-transport model with nonlinear dissipation, supports 1D/2D inputs, preserves input type, includes optional 3-species low-amplitude coupling, and runs input validity checks first.
function_header: def propagate_species_profile(
    species_state: Union[np.ndarray, list[float], list[list[float]]],
    reaction_interval: float
) -> Union[np.ndarray, list[float], list[list[float]]]:
test_cases: for state, dt, expected_len in [
    ([1.0, 0.1, 0.5, -0.05], 0.1, 4),
    ([[1.0, 0.1, 0.5, -0.05], [2.0, 0.2, 1.0, -0.1]], 0.05, 4)
]:
    result = propagate_species_profile(state, dt)
    if isinstance(state, list) and isinstance(state[0], list):
        assert len(result) == len(state)
        assert all(len(r) == expected_len for r in result)
    else:
        assert len(result) == expected_len

step_number: 2
step_description_prompt: Please write Python code to implement a function named evolve_uncertainty_tensor. This function propagates 2x2 symmetric reaction uncertainty under linearized chemical interaction dynamics. It accepts three 2x2 List[List[float]] inputs, returns the evolved 2x2 List[List[float]] uncertainty tensor, with necessary input validation and degeneracy check.
function_header: def evolve_uncertainty_tensor(
    uncertainty: List[List[float]],
    interaction_map: List[List[float]],
    fluctuation_source: List[List[float]]
) -> List[List[float]]:
test_cases: U = [[1.0, 0.2], [0.2, 0.5]]
A = [[0.9, 0.1], [0.0, 0.8]]
Q = [[0.1, 0.0], [0.0, 0.1]]
result = evolve_uncertainty_tensor(U, A, Q)
assert len(result) == 2
assert all(len(row) == 2 for row in result)
assert abs(result[0][1] - result[1][0]) < 1e-9  # symmetry check

step_number: 3
step_description_prompt: Please use Python code to generate a function named compute_reaction_modulation. This function computes reaction modulation coefficients for chemical observation correction, accepts prior_uncertainty, observation_operator, measurement_fluctuation as inputs, applies matrix operations and numerical stabilization steps, returns a list of float values.
function_header: def compute_reaction_modulation(
    prior_uncertainty,
    observation_operator,
    measurement_fluctuation
) -> List[float]:
test_cases: U = [[1.0, 0.3], [0.3, 0.8]]
O = [[1.0, 0.5]]
R = 0.1
mod = compute_reaction_modulation(U, O, R)
assert len(mod) == 2

step_number: 4
step_description_prompt: Please write a Python function named equilibrate_species_state. This function updates chemical species profiles and corresponding uncertainty via observation-consistent equilibration. It takes prior profile, prior uncertainty, modulation coefficients, observed signal, observation operator as inputs, runs dimension adjustment, matrix validity check, linear update, returns updated state and uncertainty as lists.
function_header: def equilibrate_species_state(
    prior_profile: Union[List[float], np.ndarray],
    prior_uncertainty: Union[List[List[float]], np.ndarray],
    modulation_coeff: Union[List[float], np.ndarray],
    observed_signal: Union[float, List[float], np.ndarray],
    observation_operator: Union[List[List[float]], np.ndarray]
) -> Tuple[List[float], List[List[float]]]:
test_cases: x = [1.0, 0.5]
U = [[0.8, 0.2], [0.2, 0.6]]
M = [0.7, 0.3]
z = 1.2
O = [[1.0, 0.0]]
x_new, U_new = equilibrate_species_state(x, U, M, z, O)
assert len(x_new) == 2
assert len(U_new) == 2
assert all(len(row) == 2 for row in U_new)

General solution:

General tests: