# Computer Algebra "factor" function

**URL:** <https://discourse.julialang.org/t/computer-algebra-factor-function/102837>\
**Category:** General Usage\
**Tags:** question, symbolics, factorization\
**Created:** [August 15, 2023, 5:50pm UTC](https://discourse.julialang.org/t/computer-algebra-factor-function/102837 "2023-08-15T17:50:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxasauruswall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxasauruswall/32/52263_2.png) [@maxasauruswall](https://discourse.julialang.org/u/maxasauruswall)\
**Post date:** [August 15, 2023, 5:50pm UTC](https://discourse.julialang.org/t/computer-algebra-factor-function/102837/1 "2023-08-15T17:50:02Z")

</div>

Hi All,

I’m reading “Computer Algebra Concepts and Techniques” by Lamagna (I’m new to CAS systems, and fairly new to Julia as well). I was curious to see if I could follow along with some of the examples in Julia, rather than Maple/Mathematica.

My specific question: is there a way to do something like the following?

```julia
using Symbolics

@variables x y
p = 55*x^2*y - 15*x*y^2 + 44*x*y - 12*y^2
factor(p)

```

What I’d like to see is something similar to pg 36, where Lamagna uses Maple to do the following:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/3/a39572fcb4d9d3b8ee79953d195a58ea0237a48c.png)

I see that you can use Primes.jl `factor` functions for integers and polynomials:

```julia
using Primes
 
factor(2^(2^5)+1)
# 641 * 6700417

```

But I haven’t yet found a method that would work with Symbolic’s variables/expressions.

Thanks for the help,  
Cheers,  
Max

---

<div class="post-metadata">

**Author:** ![shikil](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@shikil](https://discourse.julialang.org/u/shikil)\
**Post date:** [August 16, 2023, 1:25am UTC](https://discourse.julialang.org/t/computer-algebra-factor-function/102837/2 "2023-08-16T01:25:12Z")

</div>

> [@maxasauruswall](#):
>
> `p = 55*x^2*y - 15*x*y^2 + 44*x*y - 12*y^2`

Package `Hecke` has factor function for polynomial.

```julia
using Hecke

R,(x,y)=polynomial_ring(QQ, [:x, :y])
# (Multivariate polynomial ring in 2 variables over QQ, QQMPolyRingElem[x, y])

p = 55*x^2*y - 15*x*y^2 + 44*x*y - 12*y^2
# 55*x^2*y - 15*x*y^2 + 44*x*y - 12*y^2

factor(p)
# 1 * y * (11*x - 3*y) * (5*x + 4)

q=77x^2*y-21x*y^2-22x^2+6x*y
# 77*x^2*y - 22*x^2 - 21*x*y^2 + 6*x*y

gcd(p, q)
# x - 3//11*y

```

---

<div class="post-metadata">

**Author:** ![maxasauruswall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxasauruswall/32/52263_2.png) [@maxasauruswall](https://discourse.julialang.org/u/maxasauruswall)\
**Post date:** [August 16, 2023, 2:45am UTC](https://discourse.julialang.org/t/computer-algebra-factor-function/102837/3 "2023-08-16T02:45:07Z")

</div>

Thanks @shikil ! Works beautifully. Excited to look deeper into this package.

Best,  
Max
