# Fast computation of bilinear forms

**URL:** <https://community.freefem.org/t/fast-computation-of-bilinear-forms/3355>\
**Category:** General Discussion\
**Created:** [June 26, 2024, 3:14pm UTC](https://community.freefem.org/t/fast-computation-of-bilinear-forms/3355 "2024-06-26T15:14:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcvillaquira](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/jcvillaquira/32/2016_2.png) [@jcvillaquira](https://community.freefem.org/u/jcvillaquira)\
**Post date:** [June 26, 2024, 3:14pm UTC](https://community.freefem.org/t/fast-computation-of-bilinear-forms/3355/1 "2024-06-26T15:14:16Z")

</div>

Hi,

I have the bilinear form `q` that can be represented as `q(f, g) = int2d(Th)( b * ( dx(uf) * dx(ug) + dy(uf) * dy(ug) ) )` where `b` is a fixed function, `uf` and `ug` solve a given BVP (details of the specific problem are not important) with Neumann boundary conditions `f` and `g`, respectively.

I also have a collection of functions `f1,...,fn` and I want to compute the matrix `B` given by `B_jk=q[fj,fk]` for all pairs `j,k`.

The question is, _what is the fastest way to do it?_

Using the expression for `q` each time is extremely slow, so what I am doing now is to compute the matrix `A = q(Vh, Vh)` and computing the inner products `<A * f[], g[]>` whenever I want to compute `q(f, g)`.

Thanks in advace!

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [June 26, 2024, 5:31pm UTC](https://community.freefem.org/t/fast-computation-of-bilinear-forms/3355/2 "2024-06-26T17:31:05Z")

</div>

How many `j`s and `k`s do you have? Most often, you do not want to store this explicitly, and want to deal with this in a matrix-free fashion, or with another representation, like Kronecker product.

---

<div class="post-metadata">

**Author:** ![jcvillaquira](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/jcvillaquira/32/2016_2.png) [@jcvillaquira](https://community.freefem.org/u/jcvillaquira)\
**Post date:** [June 27, 2024, 4:45am UTC](https://community.freefem.org/t/fast-computation-of-bilinear-forms/3355/3 "2024-06-27T04:45:31Z")

</div>

Give or take 40, I don’t think they are the problem. This algorithm fits into a larger process where this has be done a lot of times for different `b`s since this is an optimization algorithm for `q`.
