Re: Derivatives of user-defined control-flow functions

• To: mathgroup at smc.vnet.net
• Subject: [mg51080] Re: Derivatives of user-defined control-flow functions
• From: "Steve Luttrell" <steve_usenet at _removemefirst_luttrell.org.uk>
• Date: Mon, 4 Oct 2004 06:17:39 -0400 (EDT)
• References: <cjoiel\$al2\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Make the following definition

Unprotect[D];
D[If[u_, v_, w_], x_] := If[u, D[v, x], D[w, x]];
Protect[D];

then the input

D[If[f[x], g[x], h[x]], x]

gives the output

If[f[x], D[g[x], x], D[h[x], x]]

Steve Luttrell

"Maxim A. Dubinnyi" <maxim at nmr.ru> wrote in message
news:cjoiel\$al2\$1 at smc.vnet.net...
> Can anyone correctly define derivatives of
> user-defined control-flow functions?
>
> The derivative of build-in control function 'If' is evaluated as:
>
> In[]=  D[If[f[x], g[x], h[x]], x]
> Out[]= If[f[x],g'[x],h'[x]]
>
> Which is perfectly correct answer. I wish to introduce my own
> control flow function MyIf and define it's derivatives with
> properties identical to ones in build-in If function.
> Usually derivatives are defined via properties of
> symbol 'Derivative' by setting
>
> Derivative[order...][function_name]:= (derivative definition)
>
> but this method fails in case of control-flow expressions.
> The problem origin is in the rule for derivatives of
> composite functions:
>
> In[]=  D[f[g[x]], x]
> Out[]= f'[g[x]]g'[x]
>
> This rule should not be applied if 'f' is control-flow function such
> as 'If', 'Which', etc, and it is really so for build-in control-flow
> expressions. But how can I suppress this deepely build-in rule for
> some user-defined symbols?
>
> I am experienced user of Mathematica, and I use widely symbolic
> and functional programming in my applications,
> but can't find any solution of this problem.
>
> Is it the task which can't be solved by means of Mathematica
> symbolic programming language?
>
>
> Maxim A. Dubinnyi
>

```

• Prev by Date: Re: Re: Thichness of Plot does not change Solved
• Next by Date: Re: Re: Thichness of Plot does not change Solved
• Previous by thread: Re: Re: Derivatives of user-defined control-flow functions
• Next by thread: Re: Derivatives of user-defined control-flow functions