Nemo definitely wonâ€™t be of any help here. There is no symbolic ring type in Nemo (though there may be a rudimentary one day).

What you require here is a symbolics package. Note that Sage isnâ€™t quite Python and preprocesses some input so that it can behave more like a CAS, and behind the scenes it has some symbolics package which handles symbolics; itâ€™s not baked into Python.

General purpose programming languages (like Julia and Python) are actually very poor for symbolics. You really need a specialised language to handle this properly, though you can get some of the way there with a specialised symbolics package. The really hard part is making it very fast.

Maple, for example, stores all its data in a DAG (Directed Acyclic Graph) format, which is completely different to the way general purpose languages handle variables and bindings.

The interesting question is whether it might be possible to introduce a special REPL mode in Julia one day that allows symbolics. I havenâ€™t looked to see if anyone has already worked on such a thing.

If you are really asking how to implement a symbolic ring in Julia, you first need to decide how symbolic expressions will be stored (what data format), and how complex you want the supported expressions to be. Your simple example just requires polynomials, which means you just need terms and factors, essentially. But sophisticated systems like Maple support extremely complex expressions, along with very complex algorithms for expanding and simplifying expressions.

By the way, SymEngine is supposed to be a C++ library. So you could interface to that from Julia if you wanted to (using Cxx.jl). This would be the most logical way to support symbolic computation in Julia, unless you have a team of dozens of coders who are willing to write a Julia-only symbolic engine for you!