# Linnea: automatic generation of efficient linear algebra programs

**URL:** <https://discourse.julialang.org/t/linnea-automatic-generation-of-efficient-linear-algebra-programs/66288>\
**Category:** Numerics\
**Tags:** linearalgebra, symbolic, symbolics\
**Created:** [August 12, 2021, 7:20pm UTC](https://discourse.julialang.org/t/linnea-automatic-generation-of-efficient-linear-algebra-programs/66288 "2021-08-12T19:20:00Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![artkuo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/artkuo/32/28577_2.png) [@artkuo](https://discourse.julialang.org/u/artkuo)\
**Post date:** [September 24, 2021, 10:35pm UTC](https://discourse.julialang.org/t/linnea-automatic-generation-of-efficient-linear-algebra-programs/66288/13 "2021-09-24T22:35:05Z")

</div>

Another potential approach is to use laziness to gain some similar advantages to Linnea. I had a [proof-of-concept](https://discourse.julialang.org/t/how-lazy-is-too-lazy-an-exercise-in-pseudoinverses/67020) (posted previously; apologies for self-promotion) that lazily recognizes `inv(A'A)*A'b` as a pseudo-inverse, similar to Fig 3 of the [Linnea article](https://arxiv.org/pdf/1912.12924.pdf). Except instead of a graph, it stores info such as positive definiteness and matrix solve in types, and then tries to do the right thing when the operations resolve into an expected pattern. Re-posting from before,

```julia
julia> using LazyPseudoinverse
julia> A = [1 2 3; 4 5 6; 7. 8 10; 11 13 19];
julia> b = [5, 8, 10, 11.];
julia> inv(A'A)A'b # looks like normal matrix operation
3-element Vector{Float64}:
 -4.679738562091531
  8.222222222222245
 -2.3333333333333317

julia> inv(A'A)A'b == A\b # it's really a QR solve!
true

```

If the pattern ended up as `inv(A'A)C`, it would still recognize positive definiteness and use Cholesky factorization. In principle, any use of `inv` could be done lazily and automatically do `\` when right-multiplied by something. The lazy approach is probably very limited in what it can do compared to [Metatheory.jl](https://github.com/JuliaSymbolics/Metatheory.jl) or Linnea, but for simple things it is quite straightforward and doesn’t need to know the sizes in advance.

---

_[View the full topic](https://discourse.julialang.org/t/linnea-automatic-generation-of-efficient-linear-algebra-programs/66288)._
