Condition in Mathematica to accept list of pairs with numeric input -



Condition in Mathematica to accept list of pairs with numeric input -

i trying create function in mathematica takes in list of pairs numeric , outputs list of first element of pair raised inverse powerfulness of sec element e.g. {{1,3},{2,2}....} -> {1^(1/3),2^(1/2),...}.

this have got far:

pairstoroots3[list : {{_, _} ..}] := list /. {p_real, q_real} :> p^(1/q)

it doesn't seem work p_real if set p_integer works fine. not sure why. ideally, status expressed like

pairstoroots3[list : {{_real, _real} ..}]

or somehting tried seemed not work.

this works if numbers have head real:

pairstoroots[list : {{_real, _real} ..}] := #^(1/#2) & @@@ list pairstoroots[{{1`, 3`}, {2`, 2`}}] {1., 1.41421}

but these numbers not have head real:

head /@ {1, 2, pi 7/8} {integer, integer, integer, symbol, rational}

therefore want numericq george used:

pairstoroots[list : {{_?numericq, _?numericq} ..}] := #^(1/#2) & @@@ list pairstoroots[{{1, 3}, {2, 2}}] {1, sqrt[2]}

list wolfram-mathematica condition

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -