Re: Easiest Mathematica algorhitm needed
- To: mathgroup at smc.vnet.net
- Subject: [mg92822] Re: Easiest Mathematica algorhitm needed
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Tue, 14 Oct 2008 04:57:31 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <gcq09i$c30$1@smc.vnet.net> <200810120835.EAA08892@smc.vnet.net> <gcv7ef$e31$1@smc.vnet.net>
Artur wrote: > Who know which Matrhematica function uses to separate square free part > of number. Pattern matching seems the more appropriate. > e.g. > In[1]: Table[Sqrt[n!], {n, 1, 10}] > Out[1]: {1, Sqrt[2], Sqrt[6], 2 Sqrt[6], 2 Sqrt[30], 12 Sqrt[5], 12 > Sqrt[35], > 24 Sqrt[70], 72 Sqrt[70], 720 Sqrt[7]} > What to do to take squre-free parts: > {1, 2, 6, 6, 30, 5, 35, 70, 70, 7} In[1]:= lst = Table[Sqrt[n!], {n, 1, 10}] Out[1]= {1, Sqrt[2], Sqrt[6], 2 Sqrt[6], 2 Sqrt[30], 12 Sqrt[5], 12 Sqrt[35], 24 Sqrt[70], 72 Sqrt[70], 720 Sqrt[7]} In[2]:= Cases[lst, ___*Sqrt[n_] | Sqrt[n_] -> n] Out[2]= {2, 6, 6, 30, 5, 35, 70, 70, 7} > or square parts > {1, 1, 1, 2, 2, 12, 12, 24, 72, 720} In[3]:= List @@ lst /. Sqrt[__] -> 1 Out[3]= {1, 1, 1, 2, 2, 12, 12, 24, 72, 720} HTH, -- Jean-Marc
- References:
- Re: Executing external notebook
- From: Peter Pein <petsie@dordos.net>
- Re: Executing external notebook