Re: HoldForm
- To: mathgroup at smc.vnet.net
- Subject: [mg68107] Re: [mg68094] HoldForm
- From: "Bharat Bhole" <bbhole at gmail.com>
- Date: Mon, 24 Jul 2006 00:55:50 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hi Bruce,
A simple modification of your program gives the desired result. Basically,
perform A+(-B) rather than performing A-B. So your code will look like,
A = {{1, 2}, {3, 4}};
B = {{5, 6}, {7, -8}};
Map[MapThread[HoldForm[#1 + #2] &, {A[[#]], -B[[#]]}] &, Range@2]
As desired, the output is {{1 - 5, 2 - 6}, {3 - 7, 4+8}}.
I am not sure why HoldForm treats + and - differently. It performs addition
but not subtraction in the sense that,
In: HoldForm[2+ (-3)]
Out: 2-3
In:HoldForm[2 - (-3) ]
Out: 2 - - 3
Bharat.
On 7/23/06, Bruce Colletti <vze269bv at verizon.net> wrote:
>
> Re Mathematica 5.2.0.0.
>
> This code displays the component differences of matrix subtraction (A-B):
>
> A = {{1, 2}, {3, 4}};
>
> B = {{5, 6}, {7, -8}};
>
> Map[MapThread[HoldForm[#1 - #2] &, {A[[#]], B[[#]]}] &, Range@2]
>
> As desired, the output is {{1 - 5, 2 - 6}, {3 - 7, 4--8}}.
>
> Two questions:
>
> - What's a better way to do this?
>
> - How can I replace the -- by +?
>
> Thankx.
>
> Bruce
>
>
>
--
----------------------------------------------------------
"No problem can withstand the assault
of sustained thinking."
Voltaire
----------------------------------------------------------