On Tue, Nov 18, 2014 at 2:50 PM, Bill Page <bill.p...@newsynthesis.org> wrote:
> On 18 November 2014 15:19, Ondřej Čertík <ondrej.cer...@gmail.com> wrote:
>> On Tue, Nov 18, 2014 at 12:14 PM, Bill Page <bill.p...@newsynthesis.org> 
>> wrote:
>>>
>>>   abs(x).diff(x)
>>>
>>> would return the symbolic expression
>>>
>>>   conjugate(x)/(2*abs(x)) + conjugate(x)/(2*abs(x))* e^{-2*i*theta}
>>
>> I think you made a mistake, the correct expression is:
>>
>> conjugate(x)/(2*abs(x)) + x/(2*abs(x)) * e^{-2*i*theta}
>>
>
> Yes, sorry.
>
>>> ...
>>> I thought rather that what you were proposing was to set theta=0
>>> from the start.  If you did that, then I think you still have problems
>>> with the chain rule.
>>
>> For a CAS, I was leaning towards using theta=0. But given your
>> objections, I first needed to figure out the most general case that
>> covers everything. I think that's now sufficiently clarified.
>>
>
> OK.
>
>>> Let me add that the kind of solution to this problem that I did
>>> imagine was to implement two derivatives, for example both
>>>
>>>   f.diff(z) = df/dz + df/d conjugate(z)
>>>
>>> and
>>>
>>>   f.diff2(z) = df/dz - df/d conjugate(z)
>>>
>>> diff(z) would equal diff2(z) for all analytic functions and diff would
>>> reduce to the derivative of real non-analytic functions as you desire.
>>
>> Right, diff() is for theta = 0. diff2() is for theta=pi/2, i.e. taking
>> the derivative along the imaginary axis.
>>
>>> Note that for abs we have
>>>
>>>   abs(z).diff2(z) = 0
>>
>> Actually, for abs you have:
>>
>> abs(z).diff2(z) = (conjugate(z)-z)/(2*abs(z))
>>
>
> Yes again, sorry.  Of course 0 only if conjugate(z)=z.
>
>>> but not in general.  There would be no need to discuss this 2nd
>>> derivative with less experienced users until they were ready to
>>> consider more "advanced" mathematics.
>>>
>>> Clearly we could implement the chain rule given these two derivatives.
>> ...
>
> On 18 November 2014 15:46, Ondřej Čertík <ondrej.cer...@gmail.com> wrote:
>> On Tue, Nov 18, 2014 at 1:19 PM, Ondřej Čertík <ondrej.cer...@gmail.com> 
>> wrote:
>> ..
>>>
>>> So I think that functions can return their own correct derivative, for
>>> example analytic functions just return the unique complex derivative,
>>> for example:
>>>
>>> log(z).diff(z) = 1/z
>>>
>>> This holds for all cases. Non-analytic functions like abs(f) can return:
>>>
>>> abs(f).diff(z) = (conjugate(f)*f.diff(z) +
>>> f*conjugate(f).diff(z)*e^{-2*i*theta}) / (2*abs(f))
>>
>> Actually, I think I made a mistake. Let's do abs(f).diff(x) again for
>> the most general case. We use:
>>
>> D f(g) / D z =
>>
>> = df/dg * (dg/dz + dg/d conjugate(z) * e^{-2*i*theta}) + df/d
>> conjugate(g) * (d conjugate(g)/dz + d conjugate(g)/d conjugate(z) *
>> e^{-2*i*theta}) =
>>
>> = df/dg Dg/Dz + df/d conjugate(g) D conjugate(g) / Dz
>>
>> Which we derived above. We have f(g) -> |g| and g(z) -> f(z). So we get:
>>
>> D |f| / Dz = d|f|/df * Df/Dz + d|f|/d conjugate(f) * D conjugate(f) / Dz =
>>
>> = (conjugate(f) * Df/Dz + f * D conjugate(f) / Dz) / (2*abs(f))
>>
>> And then:
>>
>> Df/Dz = f.diff(z)
>> D conjugate(f) / Dz = conjugate(f).diff(z)
>>
>> So I think the formula:
>>
>> abs(f).diff(z) = (conjugate(f)*f.diff(z) + f*conjugate(f).diff(z)) / 
>> (2*abs(f))
>>
>> is the most general formula for any theta. The theta dependence is hidden
>> in conjugate(f).diff(z), since if "f" is analytic, like f=log(z), the
>> conjugate(f) is not analytic, and so the derivative is theta dependent.
>>
>> The below holds though:
>>
>>>
>>> I think that's the correct application of the chain rule. We can set
>>> theta=0, so we would just return:
>>>
>>> abs(f).diff(z) = (conjugate(f)*f.diff(z) + f*conjugate(f).diff(z)) / 
>>> (2*abs(f))
>>>
>>> Which for real "f" (i.e. conjugate(f)=f) simplifies to (as a special case):
>>>
>>> abs(f).diff(z) = (f*f.diff(z) + f*f.diff(z)) / (2*abs(f)) = f/abs(f) *
>>> f.diff(z) = sign(f) * f.diff(z)
>>>
>>> So it all works.
>>>
>>> Unless there is some issue that I don't see, it seems to me we just
>>> need to have one diff(z) function, no need for diff2().
>>>
>
> Hmmm... So given only f(z).diff(z) as you have defined it above, how
> do I get Df(z)/D conjugate(z), i.e. the other Wirtinger derivative?
> Or are you claiming that this is not necessary in general in spite of
> the Wirtinger  formula for the chain rule?

In my notation, the Wirtinger derivative is d f(z) / d z and d f(z) /
d conjugate(z). The Df(z) / Dz is the complex derivative taking in
direction theta (where it could be theta=0). Given the chain rule, as
I derived above using chain rules for the Wirtinger derivative:

D f(g) / D z = df/dg Dg/Dz + df/d conjugate(g) D conjugate(g) / Dz

I don't see why you would need the isolated Wirtinger derivatives. The
method that implements the derivative of the given function, like
log(z) or abs(z) would simply return the correct formula, as I said
above, e.g.

log(z).diff(z) = 1/z

abs(f).diff(z) = (conjugate(f)*f.diff(z) + f*conjugate(f).diff(z)) / (2*abs(f))

Both formulas hold for any theta. I guess it depends on how the CAS is
implemented, maybe some CASes have a general machinery for
derivatives. But I am pretty sure you can simply implemented it as I
outlined.

Let me know if you found any issue with this.

Ondrej

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to