# Lazy representation of x^T A x

**URL:** <https://discourse.julialang.org/t/lazy-representation-of-x-t-a-x/47087>\
**Category:** Numerics\
**Created:** [September 22, 2020, 6:35pm UTC](https://discourse.julialang.org/t/lazy-representation-of-x-t-a-x/47087 "2020-09-22T18:35:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [September 22, 2020, 6:35pm UTC](https://discourse.julialang.org/t/lazy-representation-of-x-t-a-x/47087/1 "2020-09-22T18:35:34Z")

</div>

Hello,

I have a complicated code (nested calls to subroutines) that computes an expression of the form x^T A x, where A is not necessarily PSD. Is it possible to construct a lazy representation of A, in the same spirit as LinearMaps?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 22, 2020, 6:41pm UTC](https://discourse.julialang.org/t/lazy-representation-of-x-t-a-x/47087/2 "2020-09-22T18:41:44Z")

</div>

Wait, I misunderstood your question.

You’re saying you have `f(x) = …compute xᵀAx …`, and you want to construct `A`?

If `A` is not symmetric, then this is impossible, since `f(x)` can’t distinguish between A and Aᵀ.

---

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [September 22, 2020, 6:46pm UTC](https://discourse.julialang.org/t/lazy-representation-of-x-t-a-x/47087/3 "2020-09-22T18:46:39Z")

</div>

Yes, I would like some way to represent A, without an explicit expression for A.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 22, 2020, 6:56pm UTC](https://discourse.julialang.org/t/lazy-representation-of-x-t-a-x/47087/4 "2020-09-22T18:56:49Z")

</div>

Can’t you modify your code to compute Ax for an arbitrary x? Or at least y^T A x for arbitrary (x,y)?

---

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [September 22, 2020, 8:08pm UTC](https://discourse.julialang.org/t/lazy-representation-of-x-t-a-x/47087/5 "2020-09-22T20:08:41Z")

</div>

That’s true, I haven’t thought about this. Basically, I have a set of routines to compute analytically the pressure on an infinitely thin plate due to vortex elements in the surrounding fluid. We know that this function can be written as x^T A x + b^T x + c where x denotes the strength of each vortex element, A, b, c depends on the location of the vortex elements and the location on the plate

The dimension of x is of order 20

The code involves multiples linear and affine transformations of the original variables or intermediate variables. Creating the factorization into the original variables is painful, and also requires to store all the intermediate linear operators and offset terms.

My goal is to use this factorization to create a sparse representation of x with little sacrifice on the pressure field (quadratic compressed sensing). Here is the algorithm I want to use for the compressed sensing [https://arxiv.org/pdf/1301.7002.pdf](https://arxiv.org/pdf/1301.7002.pdf)

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [September 22, 2020, 8:11pm UTC](https://discourse.julialang.org/t/lazy-representation-of-x-t-a-x/47087/6 "2020-09-22T20:11:39Z")

</div>

Would a truncated singular value decomposition be of help here?

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [September 22, 2020, 8:36pm UTC](https://discourse.julialang.org/t/lazy-representation-of-x-t-a-x/47087/7 "2020-09-22T20:36:21Z")

</div>

> [@stevengj](#):
>
> If `A` is not symmetric, then this is impossible, since `f(x)` can’t distinguish between A and Aᵀ.

For completeness, I was confused for a second why symmetry helps but then realised one can use `(x-y)’A*(x-y) - x’A*x - y’A*y = -2x’A*y`.
