MathGroup Archive 2006

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

Search the Archive

Re: Unevaluated values of a[[i]]+b[[j]]

Alexandre Costa wrote:

> Dear group,
> Suppose a have a = {3,4,4} and b = {4,3,8}.
> I want to see the Unevaluated numerics values of  a[[i]]*b[[j]],
> a[[i]]+b[[j]], a[[i]]/b[[j]], a[[i]] - b[[j]].
> The NonCommutativeMultiply operator (**)  solves the case of 
> a[[i]]*b[[j]]. But suppose I want to extend that NonCommutativeMultiply
> operator (**) to others operations: +, -, / , i.e., see the Unevaluated
> numeric values of a[[i]]+b[[j]], a[[i]]/b[[j]], a[[i]] - b[[j]]. Does
> anybody have a clue how to do this ?
> Suppose I have the expression for the roots of the quadratic equation: -
> b[[index]]^2 + Sqrt[delta]/2*a[[index]]
> How can I see at once all the numeric values unevaluated on that
> expression.
> In short words, I have lenghtly expressions(with
> sums,subtraction,divisions and multiplications and powers) and I want to
> check each numeric value of each term in the original unevaluated formula
> containing elements such as a[[index]] . I was thinking in a operator or
> function to solve all this issue. Any help is very welcome,
> Thanks,
> Alex

Here is what I can offer, it's neither optimized for speed nor elegance, but
it does what I think you want in a rather straightforward way by replacing
the parts you want to see evaluated. You might want to improve on this:

SetAttributes[ShowNumericSymbolsEvaluated, HoldFirst]

ShowNumericSymbolsEvaluated[expr_] := Module[{eee, numbers}, 
   eee = HoldForm[expr]; 
   positions = Position[eee,x_Symbol /; NumericQ[x]];
     (eee = ReplacePart[eee, eee[[Sequence @@ #1]], #1]) & , 


In[22]:= ShowNumericSymbolsEvaluated[
           b[[index]]^2 +(Sqrt[delta]/2)*a[[index]]

Out[22]= HoldForm[b[[3]]^2 + (1/2)*Sqrt[0.2]*a[[3]]]

(the HoldForm is not shown when working in the FrontEnd)

If you want to also see the list-entries evaluated use this:

SetAttributes[ShowNumericSymbolsEvaluatedEvenMore, HoldFirst]

ShowNumericSymbolsEvaluatedEvenMore[expr_] := Module[{eee, numbers},
   eee = ShowNumericSymbolsEvaluated[expr]; 
   positions = Position[eee, HoldPattern[
       (x_Symbol)[[i___Integer]] /; NumericQ[x[[i]]]]
     (eee = ReplacePart[eee, eee[[Sequence @@ #1]], #1]) & , 

In[23]:= ShowNumericSymbolsEvaluatedEvenMore[
           b[[index]]^2 +(Sqrt[delta]/2)*a[[index]]

Out[23] = HoldForm[0.3^2 + (Sqrt[0.2]*0.3)/2]



  • Prev by Date: Re: Combined Graphics3D with Separate PlotRange?
  • Next by Date: Re: Re: A Reap Sow question
  • Previous by thread: Re: Unevaluated values of a[[i]]+b[[j]]
  • Next by thread: Re: Unevaluated values of a[[i]]+b[[j]]