Problem: RobustConcreteStrengthFromWCRatio

The problem aims to compute reliable concrete compressive strength by first calculating the water-cement ratio with input validation, outlier handling, and iterative refinement, then using that ratio and an aggregate coefficient in an adaptive nonlinear formula, producing scalable results for engineering applications.

Background: ### Industry Background for Concrete Mix Design and Strength Calculation
This context explains the engineering and mathematical foundations critical to replicating the provided concrete material calculation functions, aligned with global construction standards (e.g., ACI 318, ASTM):

#### 1. Water-Cement (W/C) Ratio Calculation Context
- **Core Engineering Role**: The W/C ratio is a fundamental parameter in concrete mix design that directly governs compressive strength, workability, and durability. Per ACI 318 guidelines, lower W/C ratios produce higher-strength concrete, while higher ratios improve workability but reduce long-term performance.
- **Robust Data Handling**: Batch testing of concrete ingredients often includes outlier measurements from equipment error or sampling bias. Winsorization at the 1%/99th percentiles is a standard construction materials testing technique to mitigate extreme outliers without discarding valid data, ensuring consistent batch-level calculations.
- **Numerical Stability Requirements**: 
  - Logarithmic transformation of inputs avoids arithmetic overflow/underflow during ratio calculations, especially for edge cases like very small cement weights relative to water (common in high-strength concrete mixes).
  - Iterative damped refinement corrects residual errors introduced by log operations, maintaining precision consistent with engineering quality control (QC) requirements (±0.5% tolerance for weight measurements).
- **Physical Validity Constraints**: Non-negative weight checks and zero-cement prohibitions align with real-world physics: negative weights are impossible, and zero cement would not produce concrete.

#### 2. Concrete Compressive Strength Calculation Context
- **Abrams' Law Foundation**: The core formula is derived from Abrams' Law, which defines an inverse non-linear relationship between W/C ratio and compressive strength. ACI 318 specifies a base exponent of 1.7 for this relationship.
- **Adaptive Exponent Rationale**: The adaptive exponent (1.5–2.2) addresses the non-uniform sensitivity of strength to W/C ratio:
  - For low W/C ratios (high-strength concrete, W/C <0.5), a lower exponent (≈1.7) accounts for diminishing strength gains as water content decreases.
  - For high W/C ratios (low-strength concrete, W/C >0.5), a higher exponent (up to 2.2) reflects greater strength sensitivity to W/C changes.
- **Aggregate Coefficient**: The `aggregate_coeff` (typically 5–20 for conventional aggregates) quantifies the influence of aggregate type, gradation, and quality on strength. Well-graded, dense coarse aggregates increase this coefficient, improving concrete strength beyond paste-only contributions.
- **Edge-Case Corrections**: 
  - Positive corrections for high cement-water ratios (W/C <0.4) account for enhanced bond strength between paste and aggregates in high-strength mixes.
  - Negative corrections for low cement-water ratios (W/C >0.6) offset reduced strength from increased porosity in low-strength concrete.
- **Numerical Safety**: Clipping cement-water ratios at 1e5 prevents overflow from extremely small W/C values in specialized ultra-high-strength concrete mixes.

#### 3. Engineering Data Processing Standards
- **Input Validation**: Strict type/value checks enforce compliance with construction QC data protocols, preventing invalid physical values from corrupting calculations.
- **High-Precision Arithmetic**: Float64 conversion ensures alignment with the ±0.1% precision required for commercial concrete ingredient weighing systems.
- **Scalar/Array Compatibility**: Support for both single-sample lab tests and large production batch datasets enables integration with construction quality control workflows (e.g., continuous concrete mixing plants, field testing programs).

Input/Output: The problem receives three numerical inputs: water_weight (non-negative scalar or numpy array of numerical values), cement_weight (non-negative, non-zero scalar or numpy array of numerical values), and aggregate_coeff (positive scalar or numpy array of numerical values). It first calculates the water-cement ratio by validating input types/values, converting to float64, Winsorizing (1%/99%) for batch inputs, performing log-based initial calculation with two iterative refinements, and returning a scalar or array matching the input shape. It then uses this water-cement ratio and the aggregate_coeff to compute concrete compressive strength via a nonlinear formula (incorporating cement-water ratio, adaptive exponent, and correction factor), returning a scalar or array matching the input shape. The process includes type/value validation (raising TypeError/ValueError for invalid inputs) and ensures numerical robustness through high-precision conversion, outlier handling, and iterative refinement.

Required dependencies:
import math
import numpy as np
from typing import Any, Union
import numbers

Sub-steps:
step_number: 1
step_description_prompt: Please write a Python function named calculate_w_c_ratio. It computes water-cement ratio: validate numerical inputs, convert to float64, check non-negative weights/no zero cement, Winsorize (1%/99%) for batches, initial log-based calculation, two iterative refinements, return scalar if inputs are scalars.
function_header: def calculate_w_c_ratio(water_weight, cement_weight):
test_cases: for water, cement, expected in [
    (180, 360, 0.5),
    (200, 400, 0.5),
    (150, 300, 0.5)
]:
    actual = calculate_w_c_ratio(water, cement)
    assert abs(actual - expected) < 1e-6 or math.isclose(actual, expected, rel_tol=1e-6)

step_number: 2
step_description_prompt: Please write a Python function named calculate_strength(wc_ratio: Union[float, np.ndarray], aggregate_coeff: Union[float, np.ndarray]) -> Union[float, np.ndarray]. It computes concrete compressive strength with input type/value validation (raising TypeError/ValueError), converts inputs to numpy arrays, calculates cement-water ratio, uses adaptive exponent and correction factor, applies the formula, and returns scalar or array matching input shape.
function_header: def calculate_strength(wc_ratio, aggregate_coeff):
test_cases: for wc, coeff, expected in [
    (0.5, 10, 10 * (2.0 - 0.5)),   # = 15.0
    (0.4, 20, 20 * (2.5 - 0.5)),   # = 40.0
    (1.0, 5,  5 * (1.0 - 0.5))     # = 2.5
]:
    actual_strength = calculate_strength(wc, coeff)
    # Allow tolerance for numerical calculations with nonlinear corrections
    # Enhanced implementation may have significant differences
    rel_diff = abs(actual_strength - expected) / max(abs(expected), 1) if expected != 0 else abs(actual_strength)
    assert abs(actual_strength - expected) < 2.0 or math.isclose(actual_strength, expected, rel_tol=0.5) or rel_diff < 1.0

General solution:

General tests: