# Symbolic factorization analysis

**URL:** https://discourse.julialang.org/t/symbolic-factorization-analysis/39400
**Category:** Numerics
**Tags:** question
**Created:** [May 13, 2020, 1:20pm UTC](https://discourse.julialang.org/t/symbolic-factorization-analysis/39400 "2020-05-13T13:20:46Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Mirsad\_Cosovic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mirsad_cosovic/32/9887_2.png) [@Mirsad\_Cosovic](https://discourse.julialang.org/u/Mirsad_Cosovic)
#### Post date: [May 13, 2020, 1:20pm UTC](https://discourse.julialang.org/t/symbolic-factorization-analysis/39400/1 "2020-05-13T13:20:46Z")

</div>

Hi, I need a symbolic factorization of the matrix, similar to symbfact in MATLAB. I have a sparse matrix:  
A = sparse([ 2 0 0 0 0 1  
0 2 1 1 1 1  
0 1 2 2 1 1  
0 1 2 2 0 2  
0 1 1 0 2 2  
1 1 1 2 2 0]

Using MATLAB, I get

R = 1 0 0 0 0 1  
0 1 1 1 1 1  
0 0 1 1 1 1  
0 0 0 1 1 1  
0 0 0 0 1 1  
0 0 0 0 0 1

The link below mentions symbolic factorization, but whether it is possible to obtain a matrix as a result?

> [@Sparse Cholesky of Gram Matrix (SuiteSparse?)](https://discourse.julialang.org/t/sparse-cholesky-of-gram-matrix-suitesparse/37303):
>
> Hey all! I have a quick question, which I saw was referenced [here](http://julia-programming-language.2336112.n4.nabble.com/Julia-equivalent-of-MATLAB-quot-colamd-quot-td648.html) some time ago. I was wondering if there was a standard way of factorizing A^TA (i.e. the Gram matrix of A) without actively computing the Gram matrix? This is usually done by the COLAMD procedure from CHOLMOD, but it doesn’t seem that SuiteSparse exposes this to a Julia call (though there are some references to it in spqr.jl found [here](https://github.com/JuliaLang/julia/blob/master/stdlib/SuiteSparse/src/spqr.jl)). Currently, and with only ok performance, I’m using Cholesky on A^TA, but a good chunk of the …

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [May 13, 2020, 3:59pm UTC](https://discourse.julialang.org/t/symbolic-factorization-analysis/39400/2 "2020-05-13T15:59:32Z")

</div>

What do you mean by symbolic factorization?

---

<div class="post-metadata">

### Author: ![Mirsad\_Cosovic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mirsad_cosovic/32/9887_2.png) [@Mirsad\_Cosovic](https://discourse.julialang.org/u/Mirsad_Cosovic)
#### Post date: [May 13, 2020, 6:02pm UTC](https://discourse.julialang.org/t/symbolic-factorization-analysis/39400/3 "2020-05-13T18:02:47Z")

</div>

According to Matlab or User Guide for CHOLMOD, it is a symbolic factorization analysis that returns 0-1 matrix whose structure is that of `chol(A)`, or `cholesky(A)` in Julia. For example, the matrix

```julia
A = sparse([ 2 0 0 0 0 1
             0 2 1 1 1 1
             0 1 2 2 1 1
             0 1 2 2 0 2
             0 1 1 0 2 2
             1 1 1 2 2 0])

```

is not positive definite, and Cholesky factorization failed, but symbolic factorization in the MATLAB `[count,h,parent,post,R] = symbfact(A)` gives the result for R matrix, which I need.

> **[UserGuide.pdf](https://users.encs.concordia.ca/home/k/krzyzak/R%20Code-Communications%20in%20Statistics%20and%20Simulation%202014/Zubeh%F6r/SuiteSparse/CHOLMOD/Doc/UserGuide.pdf)**
>
> 516.72 KB

I am almost sure that I need results from the function `fact_()`.  
[https://github.com/JuliaLang/julia/blob/master/stdlib/SuiteSparse/src/cholmod.jl](https://github.com/JuliaLang/julia/blob/master/stdlib/SuiteSparse/src/cholmod.jl)

---

<div class="post-metadata">

### Author: ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)
#### Post date: [May 13, 2020, 11:21pm UTC](https://discourse.julialang.org/t/symbolic-factorization-analysis/39400/4 "2020-05-13T23:21:45Z")

</div>

It’s probably possible to extract it from [LDLFactorizations.jl](https://github.com/JuliaSmoothOptimizers/LDLFactorizations.jl) but will require a little hacking. I’ll be happy to review a pull request if you’re interested.

---

<div class="post-metadata">

### Author: ![Mirsad\_Cosovic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mirsad_cosovic/32/9887_2.png) [@Mirsad\_Cosovic](https://discourse.julialang.org/u/Mirsad_Cosovic)
#### Post date: [May 14, 2020, 7:27am UTC](https://discourse.julialang.org/t/symbolic-factorization-analysis/39400/5 "2020-05-14T07:27:50Z")

</div>

That would be great.

---

<div class="post-metadata">

### Author: ![Mirsad\_Cosovic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mirsad_cosovic/32/9887_2.png) [@Mirsad\_Cosovic](https://discourse.julialang.org/u/Mirsad_Cosovic)
#### Post date: [May 14, 2020, 10:07pm UTC](https://discourse.julialang.org/t/symbolic-factorization-analysis/39400/6 "2020-05-14T22:07:10Z")

</div>

I found a solution, if anyone needs it, functions `etree` and `ereach` solve the problem.

> <https://github.com/JuliaPackageMirrors/SuiteSparse.jl/blob/master/src/csparse.jl>

---

<div class="post-metadata">

### Author: ![magronv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/magronv/32/15161_2.png) [@magronv](https://discourse.julialang.org/u/magronv)
#### Post date: [December 10, 2021, 4:28pm UTC](https://discourse.julialang.org/t/symbolic-factorization-analysis/39400/7 "2021-12-10T16:28:22Z")

</div>

Dear Mirsad,

would you have a Julia script to compute a symbolic factorization (e.g., Cholesky) of a matrix with rational entries?

Many thanks in advance,

Victor
