# How to approximate only number but not the numeric indices in an equation? [duplicate]

I need to solve a system of equations. It would be too long to solve it exactly, so I need to approximate by numbers the coefficients.

The problem is the following :

In[51]:= N[1/3*gamma[1], 20]

Out[51]= 0.33333333333333333333 gamma[1.0000000000000000000]


As you can see, the indice 1 in gamma[1] is also approximated. But I don't want the indices to be approximated. (In fact I'm solving a linear system of equations and this behavior can be a little problematic).

How to tell mathematica to only approximate coefficients of the equations but not indices inside brackets ?

• Can the argument of gamma be Rational? if not, you can use this: N[expr] /. gamma[x_] :> gamma[Floor[x]]. – Anjan Kumar Jul 12 '17 at 12:31
• – jkuczm Jul 12 '17 at 13:37

Multiply by approximate unity, let it infect your exact coefficients.

120 1/3*gamma[1]
(* 0.33333333333333333333 gamma[1] *)


Depending on how complicated your expressions are, you might need to use Expand or other formula manipulation functions to push the approximate constant into the deep corners.

keep[head_] := Not[SameQ[{}, If[SystemPrivateHasImmediateValueQ[head], 0, {}],
Options[head], If[SystemPrivateHasAnyCodesQ[head], 0, {}], SubValues[head]]]

Probably there are some of the "values" in keep which aren't necessary in your cases. I think Attributes and Options`.