# Defining a partial derivative operator with inactive variable

**URL:** <https://community.wolfram.com/t/defining-a-partial-derivative-operator-with-inactive-variable/25624>\
**Category:** Questions\
**Tags:** algebra, calculus\
**Created:** [July 3, 2025, 10:11pm UTC](https://community.wolfram.com/t/defining-a-partial-derivative-operator-with-inactive-variable/25624 "2025-07-03T22:11:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![saraivaq](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@saraivaq](https://community.wolfram.com/u/saraivaq)\
**Post date:** [July 3, 2025, 10:11pm UTC](https://community.wolfram.com/t/defining-a-partial-derivative-operator-with-inactive-variable/25624/1 "2025-07-03T22:11:56Z")

</div>

Hey folks,

I have a problem. I would like to be able to use a derivative operator inside an inactive sum to represent a mapping like this:

F(g(x\_1,x\_2,x\_3)) = \sum\_{i=1}^{3} \partial\_{i} g(x\_1,x\_2,x\_3)

where \partial\_{i} g = \frac{\partial g}{\partial x\_i}.  
The key thing here is that I would like to keep the sum inactive so I could manipulate the terms inside the sum and activate it later if needed.  
More specifically, I would like to be able to calculate a Gâteaux derivative of this functional like this:

\partial\_{g} F(g; \psi) = \left[\frac{\mathrm{d} }{\mathrm{d} t} F(g(x\_1,x\_2,x\_3) + \epsilon \,\psi(x\_1,x\_2,x\_3)) \right]\_{\epsilon=0}

Ideally, I would like to be able to write this:

```
x = {x1, x2, x3};
expr = Inactive[Sum][D[p[k][x1, x3, x3], x[[k]]], {k, 1, 3}]

```

but it does not work, as it accuses:

```
Part::pkspec1: The expression k cannot be used as a part specification.

```

I then tried this

```
func[p_] := 
  Inactive[Sum][
   Inactive[D][p[k],(*function*)
    Inactive[Part][x, k]],(*\[PartialD]/\[PartialD]x_k kept inert*){k,
     1, 3}];

```

This works, but it does not allow for the Gâteaux derivative to work:

```
D[func[Function[i, 
    p[i] @@ x + \[Epsilon] \[Psi] @@ x KroneckerDelta[k, 
       1]]], \[Epsilon]] // InputForm

```

which yields:

```
Inactive[Sum][KroneckerDelta[1, k]*\[Psi][x1, x2, x3]*Inactive[D][1, Inactive[Part][{x1, x2, x3}, k]], {k, 1, 3}]

```

which is wrong. Since the derivative is inactive, the derivative with relation to \epsilon doesn’t really work here, as it assumes that \phi is not related to {x1,x2,x3}[[k]], and then takes it out of the derivative.

The reason why I need this is for calculating the Gâteaux derivative of an Augmented Lagrangians for the Adjoint State Method for my research. Since I am dealing with PDEs with tensor notation, I would like to preserve the indices of the tensor notation all the way to the end of the calculations, and activate only then.

I think the way to go might be to define a function that acts as a derivative and somehow tell Mathematica how it interacts with other derivatives that might nest with it, and then make it turn into a normal derivative as soon as I activate it.

I wonder if any of you has any suggestions on how to proceed and lend me some help. I am attaching a notebook with some of my attempts but it is a little cluttered, I apologize in advance,

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/d29f4a65-0b75-4bc8-98c1-6d6a5ae4005f)

All the best,

Átila.

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [July 4, 2025, 10:20am UTC](https://community.wolfram.com/t/defining-a-partial-derivative-operator-with-inactive-variable/25624/2 "2025-07-04T10:20:22Z")

</div>

I only read until the Gâteaux derivative, that I would do this way:

```
func[p_] := 
  Inactive[Sum][
   Inactive[D][p[k],(*function*)
    Inactive[Part][x, k]],(*\[PartialD]/\[PartialD]x_k kept inert*){k,
     1, 3}];
MapAt[D[#, \[Epsilon]] &,
 func[Function[i, 
   p[i] @@ x + \[Epsilon] \[Psi] @@ x KroneckerDelta[k, 1]]],
 1]

```
