MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Derivatives of user-defined control-flow functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg51090] Re: Derivatives of user-defined control-flow functions
  • From: pein <petsie at arcor.de>
  • Date: Mon, 4 Oct 2004 06:18:01 -0400 (EDT)
  • References: <cjoiel$al2$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Maxim A. Dubinnyi schrieb:

> 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
> 
That is what TagSet has been made for:

MyIf /: D[MyIf[cond_, yes_, no_], x_] := MyIf[cond, D[yes, x], D[no, x]]

-- 
Peter Pein, Berlin


  • Prev by Date: Re: Problem with Maximize and conditions.
  • Next by Date: Re: Re: Thichness of Plot does not change Solved
  • Previous by thread: Derivatives of user-defined control-flow functions
  • Next by thread: Re: Re: Derivatives of user-defined control-flow functions