# Help with getting rid of ugly code

**URL:** <https://oscar.discourse.group/t/help-with-getting-rid-of-ugly-code/26>\
**Category:** Helpdesk\
**Created:** [October 28, 2026, 11:33pm UTC](https://oscar.discourse.group/t/help-with-getting-rid-of-ugly-code/26 "2026-10-28T23:33:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![akaushik](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@akaushik](https://oscar.discourse.group/u/akaushik)\
**Post date:** [October 28, 2026, 11:33pm UTC](https://oscar.discourse.group/t/help-with-getting-rid-of-ugly-code/26/1 "2026-10-28T23:33:51Z")

</div>

Originally asked by @lkastner on Slack :

* * *

I have some ugly constructions that I would like to get rid of.

```julia-repl
julia> filter(t->leading_exponent_vector(t)==[0,4,4], collect(terms(QC4)))
1-element Vector{MPolyDecRingElem{QQFieldElem, QQMPolyRingElem}}:
 1972628140481//316238254381921*y^4*z^4

```

I do this to get the term corresponding to a certain exponent vector. Is there something nicer? It does not work without `collect`. I also find the `leading_exponent_vector` a bit ugly, since basically it gets a “term”, so this vector should be unique, so I often tried `exponent_vector` instead, but that did not work.

---

<div class="post-metadata">

**Author:** ![akaushik](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@akaushik](https://oscar.discourse.group/u/akaushik)\
**Post date:** [October 28, 2026, 11:35pm UTC](https://oscar.discourse.group/t/help-with-getting-rid-of-ugly-code/26/2 "2026-10-28T23:35:07Z")

</div>

Originally answered by @YueRen on Slack

* * *

There are various `coeff` commands:

```julia-repl
julia> f = x1+2*x2-3*x3
x1 + 2*x2 - 3*x3

julia> f = x1^2+2*x2^2-3*x3^2
x1^2 + 2*x2^2 - 3*x3^2

julia> coeff(f,x1^2)
1

julia> coeff(f,x2^2)
2

```

You can also give it an exponent vector:

```julia-repl
julia> coeff(f,[2,0,0,0])
1

```

But the exponent vector is not checked for correctness. If you give it a vector that is too short or too long, it’ll return… something.
