Question: Part A: Looking at the exponent of each of the elements in the list FactorInteger and using Select construct your own variant of SquareFree. Call it squareFreeQ. (You want the list of powers in FactorInteger to be all be 1, equivalently no power should be greater than 1 . The right Select evaluated on FactorInteger should give {}.Notice we only have to find one power >1 so you will speed things up by using Select with an option.
Part B: Test that your construction squareFreeQ and Mathematica's SquareFreeQ are identical. You can do this by Selecting the integer for which SquareFreeQ[n]!=squarefreeQ[n]. Do this on a list of 10^5 random integers between 10^13and 10^14. Tell me how long it takes to perform this test. Be prepared to wait a little while.
Okay, so thisThis was a question I had last month but when I got it back it says incorrect with no explanation. And this:
Part A: Looking at the exponent of each of the elements in the list,
FactorInteger
and usingSelect
construct your own variant ofSquareFreeQ
. Call itsquareFreeQ
. (You want the list of powers inFactorInteger
to be all be 1, equivalently no power should be greater than 1 . The rightSelect
evaluated onFactorInteger
should give{}
. Notice we only have to find one power > 1 so you will speed things up by usingSelect
with an option.
Part B: Test that your construction
squareFreeQ
and Mathematica'sSquareFreeQ
are identical. You can do this by selecting the integer for whichSquareFreeQ[n] != squarefreeQ[n]
. Do this on a list of $10^5$ random integers between $10^{13}$ and $10^{14}$. Tell me how long it takes to perform this test. Be prepared to wait a little while.
This is what I had for part A.
squareFreeQ := Select[Last /@ FactorInteger[#], # > 1 &] &
squareFreeQ := Select[Last /@ FactorInteger[#], # > 1 &] &
My answerand for part B:
Timing[SquareFreeQ[#] & /@ RandomInteger[{10^13, 10^14}, 10^15]]
squareFreeQ := Select[Last /@ FactorInteger[#], # > 1 &] &
Timing[SquareFreeQ[#] & /@ RandomInteger[{10^13, 10^14}When I got my assignment back, 10^15]]it says incorrect with no explanation. squareFreeQ := Select[Last /@ FactorInteger[#], # > 1 &] &
WhatWhat would be the correct inputanswer? Please explain.