(*source*)
sourceStruct =
{{a, {{c1, d}, {e, f}}}, {b, {{c2, h}, {i, k}}}, {m, {{c3, n}, {v,x}}}}
(*target*)
targetStruct = {{a, {{d}, {e, f}}}, {b, {{h}, {i,k}}}, {m, {{n}, {v, x}}}}
(*try 1*)
Apply[Function[x, Delete[x, 1]], Level[sourceStruct, {2}], {1}]
(*result 1*)
{a, {d}, b, {h}, m, {n}}
(*try 2*)
Map[Function[x, Delete[x, 1]], sourceStruct, {3}]
(*result 2*)
{{a, {{d}, {f}}}, {b, {{h}, {k}}}, {m, {{n}, {x}}}}
Given a function f[x] , I would like to have a function leadingSeries that returns just the leading term in the series around x=0 . For example: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x)] x and leadingSeries[(1/x + 2 + (1 - 1/x^3)/4)/(4 + x)] -(1/(16 x^3)) Is there such a function in Mathematica? Or maybe one can implement it efficiently? EDIT I finally went with the following implementation, based on Carl Woll 's answer: lds[ex_,x_]:=( (ex/.x->(x+O[x]^2))/.SeriesData[U_,Z_,L_List,Mi_,Ma_,De_]:>SeriesData[U,Z,{L[[1]]},Mi,Mi+1,De]//Quiet//Normal) The advantage is, that this one also properly works with functions whose leading term is a constant: lds[Exp[x],x] 1 Answer Update 1 Updated to eliminate SeriesData and to not return additional terms Perhaps you could use: leadingSeries[expr_, x_] := Normal[expr /. x->(x+O[x]^2) /. a_List :> Take[a, 1]] Then for your examples: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x), x] leadingSeries[Exp[x], x] leadingSeries[(1/x + 2 + (1 - 1/x...
Comments
Post a Comment