Conditioning math
Blend two prompts in embedding space, not in prose
- V
- F
- Expression
- Expression_pi
- stack
- CONDITIONING
- STACK
When you want a picture that's "half a cat, half a dog", the blunt way is to write both into one prompt and hope. Conditioning math from More Math does it properly: you encode both prompts, then blend the conditioning tensors numerically. The result is a smooth interpolation in embedding space instead of a comma-separated guess.
How it works
A conditioning is two parts: the big tensor from the text encoder (the per-token embeddings) and the pooled output. This node runs expressions on both, independently - that's why there are two expression fields. Expression operates on the tensor part and defaults to the pack's signature I0*(1-F0)+I1*F0, a lerp between conditioning V0 and V1 by float F0. Expression_pi does the same job on the pooled part, with the same default. In practice you usually leave both as lerps and just drive F0 from a float - an animation script that ramps F0 from 0 to 1 over frames gives you a genuine prompt morph, far smoother than cutting between prompt texts.
The image-style variables (X, Y, W, H, C, B, T) are available, and the whole shared function library is in scope, so you can get exotic - weighted per-token edits, attention-style masking of parts of the embedding. For 99% of users, the lerp is the win.
Inputs and outputs
V is the autogrow list of conditionings (V0, V1, ...), F the floats, and the two expressions as described. length_mismatch handles differing batch sizes (error default, tile, pad), and batching controls how many samples evaluate per pass.
Outputs are CONDITIONING (a list) and STACK. The conditioning plugs straight into a KSampler's positive/negative inputs.
Installing it
Standard for the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/mcDandy/more_math
cd more_math
pip install -r requirements.txt
Restart ComfyUI, or grab "More math" from ComfyUI Manager. Dependency: antlr4-python3-runtime plus torch. No models.
Gotchas
Blending conditioning tensors of different token counts will hit the length_mismatch error fast - two prompts encoded separately almost always have different lengths, so expect to set tile or pad and decide which behavior you actually want. Also remember Expression_pi: if you only edit the tensor field, the pooled signal still comes from one side, which can leave your morph looking like it's carrying the wrong style DNA. Keep both fields consistent. The pack is new and solo-maintained, so treat embedding-math results as experiments worth eyeballing - but this node is genuinely the clean way to do prompt interpolation.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| V | COMFY_AUTOGROW_V3 | — | |
| F | COMFY_AUTOGROW_V3 | — | |
| Expression | STRING,SYNTAX_TREE | V0 | Expression to apply on tensor part of conditioning |
| Expression_pi | STRING,SYNTAX_TREE | V0 | Expression to apply on pooled_input part of conditioning |
| length_mismatch | COMBO | error | How to handle mismatched image batch sizes. tile: repeat shorter inputs; error: raise error on mismatch; pad: treat missing frames as zero. |
| batching | INT | 0 | — |
| remember_stack | BOOLEAN | false | If enabled, stack is copied at output leading to changes being remembered during batch operations (node runs multiple times in sucession). If disabled each batch gets it's own copy of the stack. |
| use_compute_device | BOOLEAN | true | Temporarily copies conditioning tensors to the compute device for math and moves the result back afterwards. |
| stackopt | STACK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| CONDITIONING | CONDITIONING | — |
| STACK | STACK | — |