MathGroup Archive 2006

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

Search the Archive

Re: HoldForm

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68097] Re: [mg68094] HoldForm
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Mon, 24 Jul 2006 00:55:39 -0400 (EDT)
  • References: <200607230742.DAA16992@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 23 Jul 2006, at 09:42, Bruce Colletti 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
>
>

An easier way to get identical looking output Traditional or  
StandardForm is:

Subtract @@ Map[HoldForm, {A, B}, {3}]

The difference is that HoldForm is in a different place than in your  
case. If you really prefer your position of HoldForm you can use:

Subtract @@ Map[HoldForm, {A, B}, {3}] /. HoldForm[x_] - HoldForm[
       y_] :> HoldForm[x - y]

but this no longer looks much simpler than your original approach.  
However, you can use analogous approach to get the same answer as  
yours but without the double minus signs:

Plus @@ Map[HoldForm, {A, -B}, {3}] /.
   HoldForm[x_] + HoldForm[y_] :> HoldForm[y + x]


Andrzej Kozlowski


  • References:
    • HoldForm
      • From: Bruce Colletti <vze269bv@verizon.net>
  • Prev by Date: Mathlink: Passing functions to C++
  • Next by Date: Re: HoldForm
  • Previous by thread: HoldForm
  • Next by thread: Re: HoldForm