Analysis and generation of substitutions