Search code examples
wolfram-mathematicamathematica-8

Reusing a function expansion by changing variable in Mathematica


I am using Spherical Hankel Functions, and making a tabulated form like this :

Table[SHF[n, z ] = FunctionExpand[SphericalHankelH1[n, z]], {n, 1, 5, 
   1}] // TableForm

Now, I need to use the z as different variables, keeping it as function expansion; meaning I need SHF[n , k] now. Instead of calculating again, I am trying :

Replace[SHF[1, k], SHF[1, z] :-> z]

or

Replace[SHF[1, z], SHF[1, z] -> SHF[1, k]]

Above both just gives me SHF [1, k] and not full expansion (replacing z by k after the expansion from table)

So, I try :

SHF[1, z] /. z -> k

which gives me this error :

Syntax::sntxi: Incomplete expression; more input is needed .

I need to calculate/expand it several times keeping it k, or some other variables, so am wondering if there is a better way to do this. Also, am new at this, so might be missing something obvious!

I am using Wolfram Mathematica 12.2 Please ask me if any necessary detail is missing


Solution

  • Various manipulations shown

    Clear[SHF]
    
    Table[SHF[n, z] = FunctionExpand[SphericalHankelH1[n, z]], {n, 1, 5, 1}];
    
    DownValues[SHF]
    

    shows down values

    Change definition, replacing z with k

    SHF[1, z] = ReplaceAll[SHF[1, z], z :> k]
    

    or equivalently

    SHF[1, z] = SHF[1, z] /. z :> k
    
    DownValues[SHF]
    

    shows change to down values

    Add new definition and remove old one

    SHF[1, k] = SHF[1, z]
    
    DownValues[SHF] = DeleteCases[DownValues[SHF, Sort -> False],
      HoldPattern[Verbatim[HoldPattern][SHF[1, z]] :> _]]
    
    DownValues[SHF]
    

    shows change to down values

    DownValues deletion thanks to Oleksandr R..