Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #8026 > unrolled thread
| Started by | "mathgroup " <fizzymath@knology.net> |
|---|---|
| First post | 2012-01-20 06:50 +0000 |
| Last post | 2012-01-24 10:11 +0000 |
| Articles | 6 — 4 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Derivatives Output as TraditionalForm "mathgroup " <fizzymath@knology.net> - 2012-01-20 06:50 +0000
Re: Derivatives Output as TraditionalForm "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2012-01-21 10:26 +0000
Re: Derivatives Output as TraditionalForm JUN <noeckel@gmail.com> - 2012-01-22 12:22 +0000
Re: Derivatives Output as TraditionalForm A Retey <awnl@gmx-topmail.de> - 2012-01-22 12:21 +0000
Re: Derivatives Output as TraditionalForm "mathgroup " <fizzymath@knology.net> - 2012-01-23 07:57 +0000
Re: Derivatives Output as TraditionalForm JUN <noeckel@gmail.com> - 2012-01-24 10:11 +0000
| From | "mathgroup " <fizzymath@knology.net> |
|---|---|
| Date | 2012-01-20 06:50 +0000 |
| Subject | Derivatives Output as TraditionalForm |
| Message-ID | <jfb2rl$hls$1@smc.vnet.net> |
The following code was offered in a Wolfram Blog to make Derivatives print
out as they would be written with pencil and paper rather then f^(0,1)[x,y] for example....which is standard Mathematica output....here is the code(written by Simon, I think was his name).....the original Blog had a Wolfram program pdConv ...however, you had to apply it to each expression whereas this code , once run, does it throughout the Notebook....
Derivative/:MakeBoxes[Derivative[inds__][g_][vars__],TraditionalForm]:=ToB oxes[Apply[Defer[D[g[vars],##]]&,Transpose[{{vars},{inds}}]/.{{var_,0}:>Sequence[],{var_,1}:>{var}}],TraditionalForm]
I have 2 Questions....
(1) Why isnt this code standard within Mathematica rather then having to be Coded by the user?....I used to do all this with Format which was a Royal Nightmare by comparison.........I have never seen what purpose this output f^(0,1)[x,y] served.......or does it???
(2) Second....if I want to modify this code to get output as df/dx rather then df[x,y]/dx, , for example , how do I change it?
I also wanted to present this Code in case there are others who don't know about it and might find it useful for their work....
thanks.....Jerry Blimbaum
[toc] | [next] | [standalone]
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Date | 2012-01-21 10:26 +0000 |
| Message-ID | <jfe3s2$a34$1@smc.vnet.net> |
| In reply to | #8026 |
On Fri, 20 Jan 2012 06:50:29 -0000, mathgroup <fizzymath@knology.net>
wrote:
> The following code was offered in a Wolfram Blog to make Derivatives
> print
> out as they would be written with pencil and paper rather then
> f^(0,1)[x,y] for example....which is standard Mathematica output....here
> is the code(written by Simon, I think was his name).....the original
> Blog had a Wolfram program pdConv ...however, you had to apply it to
> each expression whereas this code , once run, does it throughout the
> Notebook....
>
>
> Derivative/:MakeBoxes[Derivative[inds__][g_][vars__],TraditionalForm]:=ToBoxes[Apply[Defer[D[g[vars],##]]&,Transpose[{{vars},{inds}}]/.{{var_,0}:>Sequence[],{var_,1}:>{var}}],TraditionalForm]
>
>
> I have 2 Questions....
>
> (1) Why isnt this code standard within Mathematica rather then having
> to be Coded by the user?....I used to do all this with Format which
> was a Royal Nightmare by comparison.........I have never seen what
> purpose this output f^(0,1)[x,y] served.......or does it???
The notation Mathematica uses is less commonly seen but there is nothing
especially non-standard about it. If you don't like it, you can change it,
as the code example demonstrates. As for why Mathematica doesn't use the
more typical notation in TraditionalForm output, I don't know for sure,
but I would hazard a guess that it is so that TraditionalForm can be
re-interpreted into StandardForm without having to be littered with
InterpretationBoxes to clarify the ambiguous notation. Implementing such
features is not free, of course, so maybe WRI took the view that their
time was better spent doing other things.
>
> (2) Second....if I want to modify this code to get output as
> df/dx rather then df[x,y]/dx, , for example , how do I change it?
Derivative/:MakeBoxes[Derivative[inds__][g_][vars__],TraditionalForm]:=ToBoxes[Apply[Defer[D[g,##]]&,Transpose[{{vars},{inds}}]/.{{var_,0}:>Sequence[],{var_,1}:>{var}}],TraditionalForm]
[toc] | [prev] | [next] | [standalone]
| From | JUN <noeckel@gmail.com> |
|---|---|
| Date | 2012-01-22 12:22 +0000 |
| Message-ID | <jfgv2e$pdc$1@smc.vnet.net> |
| In reply to | #8073 |
On Jan 21, 2:26 am, "Oleksandr Rasputinov"
<oleksandr_rasputi...@hmamail.com> wrote:
> On Fri, 20 Jan 2012 06:50:29 -0000, mathgroup <fizzym...@knology.net>
> wrote:
>
>
>
>
>
>
>
>
>
> > The following code was offered in a Wolfram Blog to make Derivatives
> > print
> > out as they would be written with pencil and paper rather then
> > f^(0,1)[x,y] for example....which is standard Mathematica output....here
> > is the code(written by Simon, I think was his name).....the original
> > Blog had a Wolfram program pdConv ...however, you had to apply it to
> > each expression whereas this code , once run, does it throughout the
> > Notebook....
>
> > Derivative/:MakeBoxes[Derivative[inds__][g_][vars__],TraditionalForm]:=ToBo xes[Apply[Defer[D[g[vars],##]]&,Transpose[{{vars},{inds}}]/.{{var_,0}:>Sequ ence[],{var_,1}:>{var}}],TraditionalForm]
>
> > I have 2 Questions....
>
> > (1) Why isnt this code standard within Mathematica rather then having
> > to be Coded by the user?....I used to do all this with Format which
> > was a Royal Nightmare by comparison.........I have never seen what
> > purpose this output f^(0,1)[x,y] served.......or does it???
>
> The notation Mathematica uses is less commonly seen but there is nothing
> especially non-standard about it. If you don't like it, you can change it,
> as the code example demonstrates. As for why Mathematica doesn't use the
> more typical notation in TraditionalForm output, I don't know for sure,
> but I would hazard a guess that it is so that TraditionalForm can be
> re-interpreted into StandardForm without having to be littered with
> InterpretationBoxes to clarify the ambiguous notation. Implementing such
> features is not free, of course, so maybe WRI took the view that their
> time was better spent doing other things.
>
>
>
> > (2) Second....if I want to modify this code to get output as
> > df/dx rather then df[x,y]/dx, , for example , how do I change it?
>
> Derivative/:MakeBoxes[Derivative[inds__][g_][vars__],TraditionalForm]:=
ToBo xes[Apply[Defer[D[g,##]]&,Transpose[{{vars},{inds}}]/.{{var_,0}:>Sequence[] ,{var_,1}:>{var}}],TraditionalForm]
If you look at the comments on that blog,
http://blog.wolfram.com/2011/12/15/mathematica-qa-series-converting-to-conventional-mathematical-typesetting/
you'll see that there were some problems with that approach. E.g., try
the above definition with this derivative:
D[f[g[x]] + h[x, y], {x, 2}] // TraditionalForm
I wouldn't consider the result acceptable. That's why I suggested a
different approach on that page:
Derivative /:
MakeBoxes[Derivative[\[Alpha]__][f1_][vars__Symbol],
TraditionalForm] := Module[{bb, dd, sp},
MakeBoxes[dd, _] ^=
If[Length[{\[Alpha]}] == 1, "\[DifferentialD]", "\[PartialD]"];
MakeBoxes[sp, _] ^= "\[ThinSpace]";
bb /: MakeBoxes[bb[x__], _] := RowBox[Map[ToBoxes[#] &, {x}]];
FractionBox[ToBoxes[bb[dd^Plus[\[Alpha]], f1]],
ToBoxes[Apply[bb,
Riffle[Map[bb[dd, #] &,
Select[({vars}^{\[Alpha]}), (# =!= 1 &)]], sp]]]]
]
Jens
[toc] | [prev] | [next] | [standalone]
| From | A Retey <awnl@gmx-topmail.de> |
|---|---|
| Date | 2012-01-22 12:21 +0000 |
| Message-ID | <jfguvi$pc0$1@smc.vnet.net> |
| In reply to | #8026 |
Hi, > I have 2 Questions.... > > (1) Why isnt this code standard within Mathematica rather then > having to be Coded by the user?....I used to do all this with Format > which was a Royal Nightmare by comparison.........I have never seen > what purpose this output f^(0,1)[x,y] served.......or does > it??? I don't want to start a discussion about whether it was a good decision to use that notation as the standard, but I think it probably is interesting to mention what the rational behind it might be: A derivative can be seen as something that acts on a function rather than an expression, and that includes functions in a programming language sense. It then is natural to think about argument slots rather than named variables, and the StandardForm of Derivative reflects that. When writing programs I find it very convenient to work with "function" objects compared to expressions since it avoids all kinds of complications with localizations and name spaces of those "artifical" symbols which actually implicitly are just used as named arguments for functions. If you wonder what I'm talking about, look at how this will work without ever defining names for the arguments: f = #1^2*#2^3 & Derivative[0,1][f] It probably needs a programmers viewpoint more than a mathematicians to appreciate the "beauty" and usefulness of such a notation, but I think with some good will you might see it... hth, albert
[toc] | [prev] | [next] | [standalone]
| From | "mathgroup " <fizzymath@knology.net> |
|---|---|
| Date | 2012-01-23 07:57 +0000 |
| Message-ID | <jfj3sl$7b9$1@smc.vnet.net> |
| In reply to | #8026 |
Thank You for Responding.... what you wrote was very Interesting....I'm quite mundane when it comes to Programming but I have enough background to appreciate what you said.....Your example certainly gives food for thought.... In fact, I went back to some old work I had done....lo and behold, I had a reason to use the form f^(0,1)[x,y] for something and when I tried it with the new found Derivatives code, it didn’t work....I was able to fix it, etc. but then I realized that perhaps the 'Raw Form' for the end user gives him many more Options....it proved to be a much easier approach for what I was trying to do....and actually made more sense.. So, again Wolfram has shown itself to be much Smarter then me...but that's why I use Mathematica and like it so much... Interesting how an answer can change your attitude.....I will never again feel upset by this as output form..... f^(0,1)[x,y] jerry B -----Original Message----- From: A Retey Sent: Sunday, January 22, 2012 6:19 AM Subject: Re: Derivatives Output as TraditionalForm Hi, > I have 2 Questions.... > > (1) Why isnt this code standard within Mathematica rather then > having to be Coded by the user?....I used to do all this with Format > which was a Royal Nightmare by comparison.........I have never seen > what purpose this output f^(0,1)[x,y] served.......or does > it??? I don't want to start a discussion about whether it was a good decision to use that notation as the standard, but I think it probably is interesting to mention what the rational behind it might be: A derivative can be seen as something that acts on a function rather than an expression, and that includes functions in a programming language sense. It then is natural to think about argument slots rather than named variables, and the StandardForm of Derivative reflects that. When writing programs I find it very convenient to work with "function" objects compared to expressions since it avoids all kinds of complications with localizations and name spaces of those "artifical" symbols which actually implicitly are just used as named arguments for functions. If you wonder what I'm talking about, look at how this will work without ever defining names for the arguments: f = #1^2*#2^3 & Derivative[0,1][f] It probably needs a programmers viewpoint more than a mathematicians to appreciate the "beauty" and usefulness of such a notation, but I think with some good will you might see it... hth, albert
[toc] | [prev] | [next] | [standalone]
| From | JUN <noeckel@gmail.com> |
|---|---|
| Date | 2012-01-24 10:11 +0000 |
| Message-ID | <jfm04m$jst$1@smc.vnet.net> |
| In reply to | #8112 |
On Jan 22, 11:57 pm, "mathgroup " <fizzym...@knology.net> wrote:
> Thank You for Responding....
>
> what you wrote was very Interesting....I'm quite mundane when it comes to
> Programming but I have enough background to appreciate what you
> said.....Your example certainly gives food for thought....
>
> In fact, I went back to some old work I had done....lo and behold, I had a
> reason to use the form f^(0,1)[x,y] for something and when I tried it with
> the new found Derivatives code, it didn't work....I was able to fix it, etc.
> but then I realized that perhaps the 'Raw Form' for the end user gives him
> many more Options....it proved to be a much easier approach for what I was
> trying to do....and actually made more sense..
>
> So, again Wolfram has shown itself to be much Smarter then me...but that's
> why I use Mathematica and like it so much...
>
> Interesting how an answer can change your attitude.....I will never again
> feel upset by this as output form..... f^(0,1)[x,y]
>
> jerry B
>
>
>
>
>
>
>
> -----Original Message-----
> From: A Retey
> Sent: Sunday, January 22, 2012 6:19 AM
> Subject: Re: Derivatives Output as TraditionalForm
>
> Hi,
>
> > I have 2 Questions....
>
> > (1) Why isnt this code standard within Mathematica rather then
> > having to be Coded by the user?....I used to do all this with Format
> > which was a Royal Nightmare by comparison.........I have never seen
> > what purpose this output f^(0,1)[x,y] served.......or does
> > it???
>
> I don't want to start a discussion about whether it was a good decision
> to use that notation as the standard, but I think it probably is
> interesting to mention what the rational behind it might be:
>
> A derivative can be seen as something that acts on a function rather
> than an expression, and that includes functions in a programming
> language sense. It then is natural to think about argument slots rather
> than named variables, and the StandardForm of Derivative reflects that.
>
> When writing programs I find it very convenient to work with "function"
> objects compared to expressions since it avoids all kinds of
> complications with localizations and name spaces of those "artifical"
> symbols which actually implicitly are just used as named arguments for
> functions. If you wonder what I'm talking about, look at how this will
> work without ever defining names for the arguments:
>
> f = #1^2*#2^3 &
>
> Derivative[0,1][f]
>
> It probably needs a programmers viewpoint more than a mathematicians to
> appreciate the "beauty" and usefulness of such a notation, but I think
> with some good will you might see it...
>
> hth,
>
> albert
As an example for why an abbreviated traditional form is important to
have, consider the following example from vector analysis.
Needs["VectorAnalysis`"];
SetCoordinates[Cartesian[x, y, z]];
a = Through[Array[
\!\(\*SubscriptBox[\("\<A\>"\), \({"\<x\>", "\<y\>", \
"\<z\>"}[\([\)\(#\)\(]\)]\)]\) &, 3][x, y, z]];
b = Through[Array[
\!\(\*SubscriptBox[\("\<B\>"\), \({"\<x\>", "\<y\>", \
"\<z\>"}[\([\)\(#\)\(]\)]\)]\) &, 3][x, y, z]];
MatrixForm[a]
MatrixForm[b]
Prove explicitly the following theorem which Mathematica tells us is
true:
Simplify[Curl[a\[Cross]b] ==
a Div[b] - b Div[a] + Map[b.Grad[#] &, a] - Map[a.Grad[#] &, b]]
It is nice that Mathematica says it's true, but we want to explain it
to our readers by going step by step. Unfortunately, writing out the
vectors is quite cumbersome. Even the left-hand side is already quite
long (not to mention the right side):
Curl[a\[Cross]b]
All this becomes much easier with the simplified traditional form, in
conjunction with some formatting specific to my problem:
Derivative /:
MakeBoxes[Derivative[\[Alpha]__][f1_][vars__Symbol],
TraditionalForm] :=
Module[{bb, dd, sp},
MakeBoxes[dd, _] ^=
If[Length[{\[Alpha]}] == 1, "\[DifferentialD]", "\[PartialD]"];
MakeBoxes[sp, _] ^= "\[ThinSpace]";
bb /: MakeBoxes[bb[x__], _] := RowBox[Map[ToBoxes[#] &, {x}]];
FractionBox[ToBoxes[bb[dd^Plus[\[Alpha]], f1]],
ToBoxes[Apply[bb,
Riffle[Map[bb[dd, #] &,
Select[({vars}^{\[Alpha]}), (# =!= 1 &)]], sp]]]]]
nice[expression_] :=
Module[{f, i, x},
HoldForm[expression // MatrixForm] /.
Subscript[f_, i_][x__] -> Subscript[f, i] // TraditionalForm]
The left-hand side of my desired equation is now:
Curl[a\[Cross]b] // nice
With this, you can now compare terms and recognize cancellations, etc.
So not everything is best done in StandardForm, and there is clearly a
place for a concise TraditionalForm.
Jens
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web