Skip to main content
added 34 characters in body; edited title
Source Link
rm -rf
  • 89.3k
  • 21
  • 297
  • 479

Help What's wrong with Squarefreemy implementation of SquareFreeQ?

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 using Select construct your own variant of SquareFreeQ. 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^{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.

Help with Squarefree?

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 this was a question I had last month but when I got it back it says incorrect with no explanation. And this is what I had for part A.

squareFreeQ := Select[Last /@ FactorInteger[#], # > 1 &] &

My answer for part B:

Timing[SquareFreeQ[#] & /@ RandomInteger[{10^13, 10^14}, 10^15]] squareFreeQ := Select[Last /@ FactorInteger[#], # > 1 &] &

What would be the correct input? Please explain

What's wrong with my implementation of SquareFreeQ?

This was a question I had last month:

Part A: Looking at the exponent of each of the elements in the list, FactorInteger and using Select construct your own variant of SquareFreeQ. 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^{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 &] &

and for part B:

Timing[SquareFreeQ[#] & /@ RandomInteger[{10^13, 10^14}, 10^15]]
squareFreeQ := Select[Last /@ FactorInteger[#], # > 1 &] &

When I got my assignment back, it says incorrect with no explanation. What would be the correct answer? Please explain.

Source Link
asik
  • 109
  • 6

Help with Squarefree?

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 this was a question I had last month but when I got it back it says incorrect with no explanation. And this is what I had for part A.

squareFreeQ := Select[Last /@ FactorInteger[#], # > 1 &] &

My answer for part B:

Timing[SquareFreeQ[#] & /@ RandomInteger[{10^13, 10^14}, 10^15]] squareFreeQ := Select[Last /@ FactorInteger[#], # > 1 &] &

What would be the correct input? Please explain