# Inner product grammar is neater than sum(index) in JuMP modeling, But triggers Warning?

**URL:** <https://discourse.julialang.org/t/inner-product-grammar-is-neater-than-sum-index-in-jump-modeling-but-triggers-warning/124528>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [January 8, 2025, 9:35am UTC](https://discourse.julialang.org/t/inner-product-grammar-is-neater-than-sum-index-in-jump-modeling-but-triggers-warning/124528 "2025-01-08T09:35:37Z")\
**Posts on this page:** 1\
**Showing post:** 28

<div class="post-metadata">

**Author:** ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Post date:** [March 17, 2025, 4:43am UTC](https://discourse.julialang.org/t/inner-product-grammar-is-neater-than-sum-index-in-jump-modeling-but-triggers-warning/124528/28 "2025-03-17T04:43:07Z")

</div>

I reviewed some math books and concluded that `ip` (inner product) is a false name which conveyed a misconception. A correction could be

```julia
function sm(p, x) return sum(p .* x) end

```

where `s` stands for `vector sum` and `m` stands for `scalar multiplication`.

The `sm` should be a more fundamental operation, which makes sense in, e.g.,  
integration theory (`p` represents a _probability measure_ while `x` represents a _measurable function_).

And some related useful formulas are:

1. `@assert sm(A, B) == tr(transpose(A) * B)`
2. `@assert transpose(z) * A * w == tr(A * w * transpose(z))`
3. `@assert tr(A * B) == tr(B * A)` as long as `size(A) == size(transpose(B))`
4. `@assert sm(c .* x, y) == sm(c, diag(x * y'))`

where, `tr` and `diag` are from module `LinearAlgebra`.  
From the 4th point we see that `sm` is indeed more versatile that `tr`. Therefore I think it’s obfuscating to define an inner product using `tr` (as it was done in some textbooks).

---

_[View the full topic](https://discourse.julialang.org/t/inner-product-grammar-is-neater-than-sum-index-in-jump-modeling-but-triggers-warning/124528)._
