Nodes/ComfyUI_Hangover-Utils/Sympy Interpreter
ComfyUI Node

Sympy Interpreter

Actual math in ComfyUI, not a glorified calculator

By Hangover3832·Created about a year ago·Updated 2 days ago· 1
Sympy Interpreter
  • values
  • int_A
  • float_A
  • str_A
expressiona

ComfyUI's built-in math nodes can add, subtract, and multiply - and then you hit the wall the moment you want a derivative. Sympy Interpreter doesn't hit that wall: it's a full SymPy session in a node, which means real symbolic math in your graph. Type diff(a*x**2+b*x+c,x) and differentiate, integrate(exp(-x**2),(x,a,b)) and integrate, or just do the boring round(a/b) that a normal math node handles anyway. You reach for it when the number you need downstream isn't a static value but a formula of other values - aspect-ratio-correct dimensions, interpolation between two points, a CFG that varies with something else in the graph.

It ships in Hangover3832's ComfyUI_Hangover-Utils pack (the successor to the old ComfyUI-Hangover-Nodes suite). Like the rest of the pack it's a hobbyist project - "learning work in progress," Windows-10-tested - so expect rough edges, but the SymPy core is solid.

How it works

The node parses your expression with SymPy's parse_expr and evaluates it. What makes it interesting is the input side: values is an autogrow input, so the node grows new sockets on demand, named a, b, c, d… (lowercase letters) for every number you plug in. Those names are your variables, usable directly in the expression. That's the whole ergonomics story: wire in numbers, write a formula using their letters, get answers.

Under the hood it converts the parsed result to a float and hands you three views of it:

  • int_A - the float's floor, so 1.9 comes out as 1. Watch this if you're feeding an INT that must not round down.
  • float_A - the exact numeric result.
  • str_A - the symbolic string form of the result (SymPy likes to simplify, so this can surprise you in a good way).

The README's example list gives the flavor: round(a/b), min(max(a,b),c), diff(...), integrate(...), plus things like exp, sin, cos, powers, and factorial-style expressions. It's genuinely "more than the author is self-aware of."

The one real trap: symbolic results crash the float step

Here's where the README oversells. The node does float(expr) on whatever your expression produces - and you cannot convert an expression that still contains a free symbol like x to a float. So diff(a*x**3+b*x**2+c,x) on its own evaluates to 3*a*x**2 + 2*b*x, which still has x, and the node errors. The pattern that actually works is derive-then-substitute, which is exactly the README's other example:

diff(a*x**2+b*x+c,x).subs({x:d})

That differentiates, substitutes d for x, and lands on a number. Think of the node as evaluate-to-a-number, not "show me the symbolic answer" - symbolic-only results are the failure mode, not a feature.

Install

ComfyUI Manager: search ComfyUI_Hangover-Utils, install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/Hangover3832/ComfyUI_Hangover-Utils

then restart. The sympy dependency in requirements.txt installs automatically via Manager.

One thing to know: this node is written against ComfyUI's newer node-authoring API (from comfy_api.latest import io, autogrow schemas, the whole modern machinery that the ecosystem essay in the KB describes replacing NODE_CLASS_MAPPINGS). That means it needs a reasonably recent ComfyUI. If the node is missing from your node list on an older install, that's why - update ComfyUI before blaming the pack.

CategoryHangover

Inputs (2)

NameTypeDefaultDescription
expressionSTRINGa
valuesCOMFY_AUTOGROW_V3

Outputs (3)

NameTypeDescription
int_AINT
float_AFLOAT
str_ASTRING