Optimising the Selection of MaxValue in AssociationOptimising 2D binning codeMathematica List Selectionselection based on values of other listConstructing lists in an efficient wayImproving a selection routineSelect Consecutive Association rows based on patternSelection based on truth tableHow to negate a boolean selection criteriaSorting an Association by FindMaximumOptimising Table wrapping over a Select
Did Voldemort kill his father before finding out about Horcruxes?
How can the electric potential be zero at a point where the electric field isn't, if that field can give a test charge kinetic energy?
Increasing muscle power without increasing volume
Why is the total probability theorem expressed in this way?
How possible is a successful landing just with 1 wing?
ArcPy Delete Function not working inside for loop?
Was Apollo 13 radio blackout on reentry longer than expected?
Is this Android phone Android 9.0 or Android 6.0?
Use chown -R while excluding one or two files
What is the point of a constraint expression on a non-templated function?
Cover a cube with four-legged walky-squares!
Kepler space telescope undetected planets
A verb to describe specific positioning of three layers
Why does "git status" show I'm on the master branch and "git branch" does not in a newly created repository?
Which GPUs to get for Mathematical Optimization (if any...)?
How to have a continuous player experience in a setting that's likely to favor TPKs?
Credit card details stolen every 1-2 years. What am I doing wrong?
How to color a tag in a math equation?
Where are the rest of the Dwarves of Nidavellir?
How could an animal "smell" carbon monoxide?
What are the basics of commands in Minecraft Java Edition?
Will this tire fail its MOT?
Does inertia keep a rotating object rotating forever, or something else?
What would be the safest way to drop thousands of small, hard objects from a typical, high wing, GA airplane?
Optimising the Selection of MaxValue in Association
Optimising 2D binning codeMathematica List Selectionselection based on values of other listConstructing lists in an efficient wayImproving a selection routineSelect Consecutive Association rows based on patternSelection based on truth tableHow to negate a boolean selection criteriaSorting an Association by FindMaximumOptimising Table wrapping over a Select
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
Suppose I have the following Association:
f=<|"vanilla:veal" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 480.615 x^17 + 261.089 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"leek:white_wine" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3772.08 x^4 + 5369.78 x^5 + 6306.37 x^6 + 6699.93 x^7 +
6523.46 x^8 + 5443.65 x^9 + 4606.18 x^10 + 3463.31 x^11 +
2651.02 x^12 + 2101.95 x^13 + 1520.17 x^14 + 1073.14 x^15 +
755.953 x^16 + 476.793 x^17 + 264.901 x^18 + 202.406 x^19 +
111.822 x^20 + 53.8665 x^21 + 29.2147 x^22 + 27.2539 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"orange:shiitake" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2655.86 x^12 + 2099.05 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.995 x^18 + 203.356 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"pepper:smoked_sausage" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3773.07 x^4 + 5370.77 x^5 + 6303.41 x^6 + 6708.77 x^7 +
6522.48 x^8 + 5432.91 x^9 + 4612.02 x^10 + 3461.37 x^11 +
2650.05 x^12 + 2100.02 x^13 + 1520.17 x^14 + 1075.06 x^15 +
754.037 x^16 + 481.571 x^17 + 262.042 x^18 + 203.356 x^19 +
109.927 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"carrot:celery" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3787.92 x^4 + 5375.7 x^5 + 6322.12 x^6 + 6740.18 x^7 +
6545.98 x^8 + 5464.16 x^9 + 4600.34 x^10 + 3451.66 x^11 +
2659.74 x^12 + 2084.56 x^13 + 1512.46 x^14 + 1049.12 x^15 +
733.916 x^16 + 467.238 x^17 + 254.419 x^18 + 199.555 x^19 +
107.084 x^20 + 47.2513 x^21 + 31.0995 x^22 + 23.4948 x^23 +
18.7435 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
0.926702 x^28 + 2.77225 x^29 + 1.84293 x^30 +
0.918848 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"cane_molasses:cumin" -> (353.073 x + 1137.02 x^2 + 2303.76 x^3 +
3769.12 x^4 + 5371.76 x^5 + 6304.4 x^6 + 6706.81 x^7 +
6518.57 x^8 + 5447.56 x^9 + 4618.84 x^10 + 3458.46 x^11 +
2655.86 x^12 + 2105.81 x^13 + 1514.39 x^14 + 1076.98 x^15 +
749.246 x^16 + 479.66 x^17 + 255.372 x^18 + 208.107 x^19 +
108.031 x^20 + 51.9764 x^21 + 24.5026 x^22 + 28.1937 x^23 +
18.7435 x^24 + 5.60733 x^25 + 2.79581 x^26 + 0.929319 x^27 +
2.7801 x^28 + 2.77225 x^29 + 1.8377 x^31)/(354 x + 1143 x^2 +
2320 x^3 + 3811 x^4 + 5441 x^5 + 6403 x^6 + 6829 x^7 +
6658 x^8 + 5571 x^9 + 4737 x^10 + 3560 x^11 + 2741 x^12 +
2174 x^13 + 1579 x^14 + 1120 x^15 + 789 x^16 + 502 x^17 +
275 x^18 + 215 x^19 + 117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 +
21 x^24 + 6 x^25 + 4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 +
2 x^31),
"lettuce:turnip" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6519.54 x^8 + 5438.77 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"corn_grit:pork_sausage" -> (353.073 x + 1137.02 x^2 + 2302.77 x^3 +
3771.09 x^4 + 5371.76 x^5 + 6301.45 x^6 + 6701.9 x^7 +
6519.54 x^8 + 5439.75 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.98 x^13 + 1519.2 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
2.7801 x^28 + 1.84817 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"avocado:pumpkin" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6303.41 x^6 + 6702.88 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"chive:mandarin_peel" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6704.84 x^7 +
6517.59 x^8 + 5439.75 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"anise_seed:coconut" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5439.75 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.98 x^13 + 1521.13 x^14 + 1075.06 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31)|>
which contains rational functions. I want to select the ones that have y value above 1 for a specific range of x, so I do:
Select[f, MaxValue[#, 2/382 <= x <= 1, x] > 1 &] // AbsoluteTiming
in this case none of them are, so I get:
The point is that my original list contains 30000 of these polynomials and the command I have for selection is taking a lot of time. For 10 of them as above it took 1.8 seconds. I wonder how can I break this time down without losing the dictionary, namely what key is related to what polynomial?
I know if I only look at values the time would be reduced, but then I will not know the output would belong to which key from the association.
list-manipulation filtering maximum
$endgroup$
add a comment |
$begingroup$
Suppose I have the following Association:
f=<|"vanilla:veal" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 480.615 x^17 + 261.089 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"leek:white_wine" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3772.08 x^4 + 5369.78 x^5 + 6306.37 x^6 + 6699.93 x^7 +
6523.46 x^8 + 5443.65 x^9 + 4606.18 x^10 + 3463.31 x^11 +
2651.02 x^12 + 2101.95 x^13 + 1520.17 x^14 + 1073.14 x^15 +
755.953 x^16 + 476.793 x^17 + 264.901 x^18 + 202.406 x^19 +
111.822 x^20 + 53.8665 x^21 + 29.2147 x^22 + 27.2539 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"orange:shiitake" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2655.86 x^12 + 2099.05 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.995 x^18 + 203.356 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"pepper:smoked_sausage" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3773.07 x^4 + 5370.77 x^5 + 6303.41 x^6 + 6708.77 x^7 +
6522.48 x^8 + 5432.91 x^9 + 4612.02 x^10 + 3461.37 x^11 +
2650.05 x^12 + 2100.02 x^13 + 1520.17 x^14 + 1075.06 x^15 +
754.037 x^16 + 481.571 x^17 + 262.042 x^18 + 203.356 x^19 +
109.927 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"carrot:celery" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3787.92 x^4 + 5375.7 x^5 + 6322.12 x^6 + 6740.18 x^7 +
6545.98 x^8 + 5464.16 x^9 + 4600.34 x^10 + 3451.66 x^11 +
2659.74 x^12 + 2084.56 x^13 + 1512.46 x^14 + 1049.12 x^15 +
733.916 x^16 + 467.238 x^17 + 254.419 x^18 + 199.555 x^19 +
107.084 x^20 + 47.2513 x^21 + 31.0995 x^22 + 23.4948 x^23 +
18.7435 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
0.926702 x^28 + 2.77225 x^29 + 1.84293 x^30 +
0.918848 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"cane_molasses:cumin" -> (353.073 x + 1137.02 x^2 + 2303.76 x^3 +
3769.12 x^4 + 5371.76 x^5 + 6304.4 x^6 + 6706.81 x^7 +
6518.57 x^8 + 5447.56 x^9 + 4618.84 x^10 + 3458.46 x^11 +
2655.86 x^12 + 2105.81 x^13 + 1514.39 x^14 + 1076.98 x^15 +
749.246 x^16 + 479.66 x^17 + 255.372 x^18 + 208.107 x^19 +
108.031 x^20 + 51.9764 x^21 + 24.5026 x^22 + 28.1937 x^23 +
18.7435 x^24 + 5.60733 x^25 + 2.79581 x^26 + 0.929319 x^27 +
2.7801 x^28 + 2.77225 x^29 + 1.8377 x^31)/(354 x + 1143 x^2 +
2320 x^3 + 3811 x^4 + 5441 x^5 + 6403 x^6 + 6829 x^7 +
6658 x^8 + 5571 x^9 + 4737 x^10 + 3560 x^11 + 2741 x^12 +
2174 x^13 + 1579 x^14 + 1120 x^15 + 789 x^16 + 502 x^17 +
275 x^18 + 215 x^19 + 117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 +
21 x^24 + 6 x^25 + 4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 +
2 x^31),
"lettuce:turnip" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6519.54 x^8 + 5438.77 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"corn_grit:pork_sausage" -> (353.073 x + 1137.02 x^2 + 2302.77 x^3 +
3771.09 x^4 + 5371.76 x^5 + 6301.45 x^6 + 6701.9 x^7 +
6519.54 x^8 + 5439.75 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.98 x^13 + 1519.2 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
2.7801 x^28 + 1.84817 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"avocado:pumpkin" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6303.41 x^6 + 6702.88 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"chive:mandarin_peel" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6704.84 x^7 +
6517.59 x^8 + 5439.75 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"anise_seed:coconut" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5439.75 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.98 x^13 + 1521.13 x^14 + 1075.06 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31)|>
which contains rational functions. I want to select the ones that have y value above 1 for a specific range of x, so I do:
Select[f, MaxValue[#, 2/382 <= x <= 1, x] > 1 &] // AbsoluteTiming
in this case none of them are, so I get:
The point is that my original list contains 30000 of these polynomials and the command I have for selection is taking a lot of time. For 10 of them as above it took 1.8 seconds. I wonder how can I break this time down without losing the dictionary, namely what key is related to what polynomial?
I know if I only look at values the time would be reduced, but then I will not know the output would belong to which key from the association.
list-manipulation filtering maximum
$endgroup$
1
$begingroup$
If you have 8 cores, and useParallelTable
, that would take less than 12 minutes. Is that too long?
$endgroup$
– rhermans
9 hours ago
$begingroup$
I have 4 so presume it will take 24', is there any way to chunk the code down into easier-to-handle part?
$endgroup$
– William
9 hours ago
$begingroup$
For all of the polynomials you give, the maximum lies at the lower edge of your search interval. Maybe there's something generalizable here: maybe it's possible to exclude a large number of polynomials by just looking at the values (and derivatives) at the end points.
$endgroup$
– Roman
7 hours ago
add a comment |
$begingroup$
Suppose I have the following Association:
f=<|"vanilla:veal" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 480.615 x^17 + 261.089 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"leek:white_wine" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3772.08 x^4 + 5369.78 x^5 + 6306.37 x^6 + 6699.93 x^7 +
6523.46 x^8 + 5443.65 x^9 + 4606.18 x^10 + 3463.31 x^11 +
2651.02 x^12 + 2101.95 x^13 + 1520.17 x^14 + 1073.14 x^15 +
755.953 x^16 + 476.793 x^17 + 264.901 x^18 + 202.406 x^19 +
111.822 x^20 + 53.8665 x^21 + 29.2147 x^22 + 27.2539 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"orange:shiitake" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2655.86 x^12 + 2099.05 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.995 x^18 + 203.356 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"pepper:smoked_sausage" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3773.07 x^4 + 5370.77 x^5 + 6303.41 x^6 + 6708.77 x^7 +
6522.48 x^8 + 5432.91 x^9 + 4612.02 x^10 + 3461.37 x^11 +
2650.05 x^12 + 2100.02 x^13 + 1520.17 x^14 + 1075.06 x^15 +
754.037 x^16 + 481.571 x^17 + 262.042 x^18 + 203.356 x^19 +
109.927 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"carrot:celery" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3787.92 x^4 + 5375.7 x^5 + 6322.12 x^6 + 6740.18 x^7 +
6545.98 x^8 + 5464.16 x^9 + 4600.34 x^10 + 3451.66 x^11 +
2659.74 x^12 + 2084.56 x^13 + 1512.46 x^14 + 1049.12 x^15 +
733.916 x^16 + 467.238 x^17 + 254.419 x^18 + 199.555 x^19 +
107.084 x^20 + 47.2513 x^21 + 31.0995 x^22 + 23.4948 x^23 +
18.7435 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
0.926702 x^28 + 2.77225 x^29 + 1.84293 x^30 +
0.918848 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"cane_molasses:cumin" -> (353.073 x + 1137.02 x^2 + 2303.76 x^3 +
3769.12 x^4 + 5371.76 x^5 + 6304.4 x^6 + 6706.81 x^7 +
6518.57 x^8 + 5447.56 x^9 + 4618.84 x^10 + 3458.46 x^11 +
2655.86 x^12 + 2105.81 x^13 + 1514.39 x^14 + 1076.98 x^15 +
749.246 x^16 + 479.66 x^17 + 255.372 x^18 + 208.107 x^19 +
108.031 x^20 + 51.9764 x^21 + 24.5026 x^22 + 28.1937 x^23 +
18.7435 x^24 + 5.60733 x^25 + 2.79581 x^26 + 0.929319 x^27 +
2.7801 x^28 + 2.77225 x^29 + 1.8377 x^31)/(354 x + 1143 x^2 +
2320 x^3 + 3811 x^4 + 5441 x^5 + 6403 x^6 + 6829 x^7 +
6658 x^8 + 5571 x^9 + 4737 x^10 + 3560 x^11 + 2741 x^12 +
2174 x^13 + 1579 x^14 + 1120 x^15 + 789 x^16 + 502 x^17 +
275 x^18 + 215 x^19 + 117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 +
21 x^24 + 6 x^25 + 4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 +
2 x^31),
"lettuce:turnip" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6519.54 x^8 + 5438.77 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"corn_grit:pork_sausage" -> (353.073 x + 1137.02 x^2 + 2302.77 x^3 +
3771.09 x^4 + 5371.76 x^5 + 6301.45 x^6 + 6701.9 x^7 +
6519.54 x^8 + 5439.75 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.98 x^13 + 1519.2 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
2.7801 x^28 + 1.84817 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"avocado:pumpkin" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6303.41 x^6 + 6702.88 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"chive:mandarin_peel" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6704.84 x^7 +
6517.59 x^8 + 5439.75 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"anise_seed:coconut" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5439.75 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.98 x^13 + 1521.13 x^14 + 1075.06 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31)|>
which contains rational functions. I want to select the ones that have y value above 1 for a specific range of x, so I do:
Select[f, MaxValue[#, 2/382 <= x <= 1, x] > 1 &] // AbsoluteTiming
in this case none of them are, so I get:
The point is that my original list contains 30000 of these polynomials and the command I have for selection is taking a lot of time. For 10 of them as above it took 1.8 seconds. I wonder how can I break this time down without losing the dictionary, namely what key is related to what polynomial?
I know if I only look at values the time would be reduced, but then I will not know the output would belong to which key from the association.
list-manipulation filtering maximum
$endgroup$
Suppose I have the following Association:
f=<|"vanilla:veal" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 480.615 x^17 + 261.089 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"leek:white_wine" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3772.08 x^4 + 5369.78 x^5 + 6306.37 x^6 + 6699.93 x^7 +
6523.46 x^8 + 5443.65 x^9 + 4606.18 x^10 + 3463.31 x^11 +
2651.02 x^12 + 2101.95 x^13 + 1520.17 x^14 + 1073.14 x^15 +
755.953 x^16 + 476.793 x^17 + 264.901 x^18 + 202.406 x^19 +
111.822 x^20 + 53.8665 x^21 + 29.2147 x^22 + 27.2539 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"orange:shiitake" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2655.86 x^12 + 2099.05 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.995 x^18 + 203.356 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"pepper:smoked_sausage" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3773.07 x^4 + 5370.77 x^5 + 6303.41 x^6 + 6708.77 x^7 +
6522.48 x^8 + 5432.91 x^9 + 4612.02 x^10 + 3461.37 x^11 +
2650.05 x^12 + 2100.02 x^13 + 1520.17 x^14 + 1075.06 x^15 +
754.037 x^16 + 481.571 x^17 + 262.042 x^18 + 203.356 x^19 +
109.927 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"carrot:celery" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3787.92 x^4 + 5375.7 x^5 + 6322.12 x^6 + 6740.18 x^7 +
6545.98 x^8 + 5464.16 x^9 + 4600.34 x^10 + 3451.66 x^11 +
2659.74 x^12 + 2084.56 x^13 + 1512.46 x^14 + 1049.12 x^15 +
733.916 x^16 + 467.238 x^17 + 254.419 x^18 + 199.555 x^19 +
107.084 x^20 + 47.2513 x^21 + 31.0995 x^22 + 23.4948 x^23 +
18.7435 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
0.926702 x^28 + 2.77225 x^29 + 1.84293 x^30 +
0.918848 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"cane_molasses:cumin" -> (353.073 x + 1137.02 x^2 + 2303.76 x^3 +
3769.12 x^4 + 5371.76 x^5 + 6304.4 x^6 + 6706.81 x^7 +
6518.57 x^8 + 5447.56 x^9 + 4618.84 x^10 + 3458.46 x^11 +
2655.86 x^12 + 2105.81 x^13 + 1514.39 x^14 + 1076.98 x^15 +
749.246 x^16 + 479.66 x^17 + 255.372 x^18 + 208.107 x^19 +
108.031 x^20 + 51.9764 x^21 + 24.5026 x^22 + 28.1937 x^23 +
18.7435 x^24 + 5.60733 x^25 + 2.79581 x^26 + 0.929319 x^27 +
2.7801 x^28 + 2.77225 x^29 + 1.8377 x^31)/(354 x + 1143 x^2 +
2320 x^3 + 3811 x^4 + 5441 x^5 + 6403 x^6 + 6829 x^7 +
6658 x^8 + 5571 x^9 + 4737 x^10 + 3560 x^11 + 2741 x^12 +
2174 x^13 + 1579 x^14 + 1120 x^15 + 789 x^16 + 502 x^17 +
275 x^18 + 215 x^19 + 117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 +
21 x^24 + 6 x^25 + 4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 +
2 x^31),
"lettuce:turnip" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6519.54 x^8 + 5438.77 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"corn_grit:pork_sausage" -> (353.073 x + 1137.02 x^2 + 2302.77 x^3 +
3771.09 x^4 + 5371.76 x^5 + 6301.45 x^6 + 6701.9 x^7 +
6519.54 x^8 + 5439.75 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.98 x^13 + 1519.2 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
2.7801 x^28 + 1.84817 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"avocado:pumpkin" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6303.41 x^6 + 6702.88 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"chive:mandarin_peel" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6704.84 x^7 +
6517.59 x^8 + 5439.75 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31),
"anise_seed:coconut" -> (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5439.75 x^9 + 4612.99 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.98 x^13 + 1521.13 x^14 + 1075.06 x^15 +
755.953 x^16 + 479.66 x^17 + 262.042 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31)|>
which contains rational functions. I want to select the ones that have y value above 1 for a specific range of x, so I do:
Select[f, MaxValue[#, 2/382 <= x <= 1, x] > 1 &] // AbsoluteTiming
in this case none of them are, so I get:
The point is that my original list contains 30000 of these polynomials and the command I have for selection is taking a lot of time. For 10 of them as above it took 1.8 seconds. I wonder how can I break this time down without losing the dictionary, namely what key is related to what polynomial?
I know if I only look at values the time would be reduced, but then I will not know the output would belong to which key from the association.
list-manipulation filtering maximum
list-manipulation filtering maximum
edited 8 hours ago
Carl Woll
87.2k3 gold badges114 silver badges222 bronze badges
87.2k3 gold badges114 silver badges222 bronze badges
asked 10 hours ago
WilliamWilliam
1,0066 silver badges8 bronze badges
1,0066 silver badges8 bronze badges
1
$begingroup$
If you have 8 cores, and useParallelTable
, that would take less than 12 minutes. Is that too long?
$endgroup$
– rhermans
9 hours ago
$begingroup$
I have 4 so presume it will take 24', is there any way to chunk the code down into easier-to-handle part?
$endgroup$
– William
9 hours ago
$begingroup$
For all of the polynomials you give, the maximum lies at the lower edge of your search interval. Maybe there's something generalizable here: maybe it's possible to exclude a large number of polynomials by just looking at the values (and derivatives) at the end points.
$endgroup$
– Roman
7 hours ago
add a comment |
1
$begingroup$
If you have 8 cores, and useParallelTable
, that would take less than 12 minutes. Is that too long?
$endgroup$
– rhermans
9 hours ago
$begingroup$
I have 4 so presume it will take 24', is there any way to chunk the code down into easier-to-handle part?
$endgroup$
– William
9 hours ago
$begingroup$
For all of the polynomials you give, the maximum lies at the lower edge of your search interval. Maybe there's something generalizable here: maybe it's possible to exclude a large number of polynomials by just looking at the values (and derivatives) at the end points.
$endgroup$
– Roman
7 hours ago
1
1
$begingroup$
If you have 8 cores, and use
ParallelTable
, that would take less than 12 minutes. Is that too long?$endgroup$
– rhermans
9 hours ago
$begingroup$
If you have 8 cores, and use
ParallelTable
, that would take less than 12 minutes. Is that too long?$endgroup$
– rhermans
9 hours ago
$begingroup$
I have 4 so presume it will take 24', is there any way to chunk the code down into easier-to-handle part?
$endgroup$
– William
9 hours ago
$begingroup$
I have 4 so presume it will take 24', is there any way to chunk the code down into easier-to-handle part?
$endgroup$
– William
9 hours ago
$begingroup$
For all of the polynomials you give, the maximum lies at the lower edge of your search interval. Maybe there's something generalizable here: maybe it's possible to exclude a large number of polynomials by just looking at the values (and derivatives) at the end points.
$endgroup$
– Roman
7 hours ago
$begingroup$
For all of the polynomials you give, the maximum lies at the lower edge of your search interval. Maybe there's something generalizable here: maybe it's possible to exclude a large number of polynomials by just looking at the values (and derivatives) at the end points.
$endgroup$
– Roman
7 hours ago
add a comment |
3 Answers
3
active
oldest
votes
$begingroup$
Maybe you can use Reduce
instead of MaxValue
. For instance, the "vanilla:veal" rational function is:
p = (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 480.615 x^17 + 261.089 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31)
Compare:
MaxValue[p, 2/382 <= x <= 1, x] //AbsoluteTiming
Quiet[Reduce[p > 1 && 2/382 <= x <= 1, x], Reduce::ratnz] //AbsoluteTiming
0.133098, 0.976077
0.041712, False
Another example where the result isn't false:
MaxValue[p+.5, 2/382 <= x <= 1, x] //AbsoluteTiming
Quiet[Reduce[p+.5 > 1 && 2/382 <= x <= 1, x], Reduce::ratnz] //AbsoluteTiming
0.128614, 1.47608
0.041923, 0.0390256 < x <= 1.
So, using Reduce
is about 3 times faster. Combine it with a ParallelTable
approach as in @rherman's answer.
$endgroup$
add a comment |
$begingroup$
This would take less than 25 minutes with 4 cores.
LaunchKernels[];
maxlist = ParallelTable[
MaxValue[eq, 2/382 <= x <= 1, x]
, eq, List @@ f
];
Pick[
Keys[f],
Thread[Greater[maxlist, 1]]
]
My take on the answer by Carl Woll, which should bring you below 6 minutes.
trueFalseList = ParallelTable[
UnsameQ[
False,
Quiet[
Reduce[eq > 1 && 2/382 <= x <= 1, x]
, Reduce::ratnz]
], eq, List @@ f]
Pick[
Keys[f],
trueFalseList
]
$endgroup$
add a comment |
$begingroup$
The following is not the exact filter that you want, but a simple prefilter that apparently is quite good at filtering the given example ;) The point is that this check is much cheaper than computing the maxima, so it can be used to filter out (hopefully) many rational functions from your list f
, so that filtering the resulting list becomes less expensive.
Here is the code:
a = 2./382;
b = 1.;
picker =
ParallelMap[
With[x = a + (b - a) z/(1 + z),
With[p = Together[#],
Min[CoefficientList[Denominator[r] - Numerator[r], z]] < 0.
]
] &,
Values[f]
]; // AbsoluteTiming // First
fpresieved = Pick[f, picker]
0.04817
<||>
Here is the idea behind the method.
Let $r(x)$ be a rational function from your list f
.
First, we apply the substitution x = a + (b - a) z/(1 + z)
; The mapping $z mapsto x$ maps the $[0,infty]$ to the interval $[a,b]$.
Thus, $r = fracpq$ is a rational function on the positive real axis for which we want to check whether
$$r(x) = fracp(z)q(z) leq 1 quad textfor all $z geq 0$.$$
This is equivalent to
$$q(z) - p(z) geq 0 quad textfor all $z geq 0$.$$
A sufficient condition for this is that all coefficients of the polynomial $q(z) - p(z)$ are nonnegative. So a necessary condition for r(x)
to be selected is that at least one coefficient of $q(z) - p(z)$ is negative. And precisely that is checked for in the code above.
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f202252%2foptimising-the-selection-of-maxvalue-in-association%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Maybe you can use Reduce
instead of MaxValue
. For instance, the "vanilla:veal" rational function is:
p = (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 480.615 x^17 + 261.089 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31)
Compare:
MaxValue[p, 2/382 <= x <= 1, x] //AbsoluteTiming
Quiet[Reduce[p > 1 && 2/382 <= x <= 1, x], Reduce::ratnz] //AbsoluteTiming
0.133098, 0.976077
0.041712, False
Another example where the result isn't false:
MaxValue[p+.5, 2/382 <= x <= 1, x] //AbsoluteTiming
Quiet[Reduce[p+.5 > 1 && 2/382 <= x <= 1, x], Reduce::ratnz] //AbsoluteTiming
0.128614, 1.47608
0.041923, 0.0390256 < x <= 1.
So, using Reduce
is about 3 times faster. Combine it with a ParallelTable
approach as in @rherman's answer.
$endgroup$
add a comment |
$begingroup$
Maybe you can use Reduce
instead of MaxValue
. For instance, the "vanilla:veal" rational function is:
p = (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 480.615 x^17 + 261.089 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31)
Compare:
MaxValue[p, 2/382 <= x <= 1, x] //AbsoluteTiming
Quiet[Reduce[p > 1 && 2/382 <= x <= 1, x], Reduce::ratnz] //AbsoluteTiming
0.133098, 0.976077
0.041712, False
Another example where the result isn't false:
MaxValue[p+.5, 2/382 <= x <= 1, x] //AbsoluteTiming
Quiet[Reduce[p+.5 > 1 && 2/382 <= x <= 1, x], Reduce::ratnz] //AbsoluteTiming
0.128614, 1.47608
0.041923, 0.0390256 < x <= 1.
So, using Reduce
is about 3 times faster. Combine it with a ParallelTable
approach as in @rherman's answer.
$endgroup$
add a comment |
$begingroup$
Maybe you can use Reduce
instead of MaxValue
. For instance, the "vanilla:veal" rational function is:
p = (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 480.615 x^17 + 261.089 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31)
Compare:
MaxValue[p, 2/382 <= x <= 1, x] //AbsoluteTiming
Quiet[Reduce[p > 1 && 2/382 <= x <= 1, x], Reduce::ratnz] //AbsoluteTiming
0.133098, 0.976077
0.041712, False
Another example where the result isn't false:
MaxValue[p+.5, 2/382 <= x <= 1, x] //AbsoluteTiming
Quiet[Reduce[p+.5 > 1 && 2/382 <= x <= 1, x], Reduce::ratnz] //AbsoluteTiming
0.128614, 1.47608
0.041923, 0.0390256 < x <= 1.
So, using Reduce
is about 3 times faster. Combine it with a ParallelTable
approach as in @rherman's answer.
$endgroup$
Maybe you can use Reduce
instead of MaxValue
. For instance, the "vanilla:veal" rational function is:
p = (353.073 x + 1137.02 x^2 + 2301.78 x^3 +
3771.09 x^4 + 5369.78 x^5 + 6302.43 x^6 + 6703.86 x^7 +
6518.57 x^8 + 5440.72 x^9 + 4612.02 x^10 + 3457.49 x^11 +
2654.9 x^12 + 2100.02 x^13 + 1521.13 x^14 + 1076.02 x^15 +
755.953 x^16 + 480.615 x^17 + 261.089 x^18 + 204.306 x^19 +
110.874 x^20 + 55.7565 x^21 + 28.2723 x^22 + 28.1937 x^23 +
19.6806 x^24 + 5.60733 x^25 + 3.72775 x^26 + 0.929319 x^27 +
1.8534 x^28 + 2.77225 x^29 + 0.921466 x^30 +
1.8377 x^31)/(354 x + 1143 x^2 + 2320 x^3 + 3811 x^4 +
5441 x^5 + 6403 x^6 + 6829 x^7 + 6658 x^8 + 5571 x^9 +
4737 x^10 + 3560 x^11 + 2741 x^12 + 2174 x^13 + 1579 x^14 +
1120 x^15 + 789 x^16 + 502 x^17 + 275 x^18 + 215 x^19 +
117 x^20 + 59 x^21 + 30 x^22 + 30 x^23 + 21 x^24 + 6 x^25 +
4 x^26 + x^27 + 2 x^28 + 3 x^29 + x^30 + 2 x^31)
Compare:
MaxValue[p, 2/382 <= x <= 1, x] //AbsoluteTiming
Quiet[Reduce[p > 1 && 2/382 <= x <= 1, x], Reduce::ratnz] //AbsoluteTiming
0.133098, 0.976077
0.041712, False
Another example where the result isn't false:
MaxValue[p+.5, 2/382 <= x <= 1, x] //AbsoluteTiming
Quiet[Reduce[p+.5 > 1 && 2/382 <= x <= 1, x], Reduce::ratnz] //AbsoluteTiming
0.128614, 1.47608
0.041923, 0.0390256 < x <= 1.
So, using Reduce
is about 3 times faster. Combine it with a ParallelTable
approach as in @rherman's answer.
answered 8 hours ago
Carl WollCarl Woll
87.2k3 gold badges114 silver badges222 bronze badges
87.2k3 gold badges114 silver badges222 bronze badges
add a comment |
add a comment |
$begingroup$
This would take less than 25 minutes with 4 cores.
LaunchKernels[];
maxlist = ParallelTable[
MaxValue[eq, 2/382 <= x <= 1, x]
, eq, List @@ f
];
Pick[
Keys[f],
Thread[Greater[maxlist, 1]]
]
My take on the answer by Carl Woll, which should bring you below 6 minutes.
trueFalseList = ParallelTable[
UnsameQ[
False,
Quiet[
Reduce[eq > 1 && 2/382 <= x <= 1, x]
, Reduce::ratnz]
], eq, List @@ f]
Pick[
Keys[f],
trueFalseList
]
$endgroup$
add a comment |
$begingroup$
This would take less than 25 minutes with 4 cores.
LaunchKernels[];
maxlist = ParallelTable[
MaxValue[eq, 2/382 <= x <= 1, x]
, eq, List @@ f
];
Pick[
Keys[f],
Thread[Greater[maxlist, 1]]
]
My take on the answer by Carl Woll, which should bring you below 6 minutes.
trueFalseList = ParallelTable[
UnsameQ[
False,
Quiet[
Reduce[eq > 1 && 2/382 <= x <= 1, x]
, Reduce::ratnz]
], eq, List @@ f]
Pick[
Keys[f],
trueFalseList
]
$endgroup$
add a comment |
$begingroup$
This would take less than 25 minutes with 4 cores.
LaunchKernels[];
maxlist = ParallelTable[
MaxValue[eq, 2/382 <= x <= 1, x]
, eq, List @@ f
];
Pick[
Keys[f],
Thread[Greater[maxlist, 1]]
]
My take on the answer by Carl Woll, which should bring you below 6 minutes.
trueFalseList = ParallelTable[
UnsameQ[
False,
Quiet[
Reduce[eq > 1 && 2/382 <= x <= 1, x]
, Reduce::ratnz]
], eq, List @@ f]
Pick[
Keys[f],
trueFalseList
]
$endgroup$
This would take less than 25 minutes with 4 cores.
LaunchKernels[];
maxlist = ParallelTable[
MaxValue[eq, 2/382 <= x <= 1, x]
, eq, List @@ f
];
Pick[
Keys[f],
Thread[Greater[maxlist, 1]]
]
My take on the answer by Carl Woll, which should bring you below 6 minutes.
trueFalseList = ParallelTable[
UnsameQ[
False,
Quiet[
Reduce[eq > 1 && 2/382 <= x <= 1, x]
, Reduce::ratnz]
], eq, List @@ f]
Pick[
Keys[f],
trueFalseList
]
edited 7 hours ago
answered 8 hours ago
rhermansrhermans
23k4 gold badges42 silver badges107 bronze badges
23k4 gold badges42 silver badges107 bronze badges
add a comment |
add a comment |
$begingroup$
The following is not the exact filter that you want, but a simple prefilter that apparently is quite good at filtering the given example ;) The point is that this check is much cheaper than computing the maxima, so it can be used to filter out (hopefully) many rational functions from your list f
, so that filtering the resulting list becomes less expensive.
Here is the code:
a = 2./382;
b = 1.;
picker =
ParallelMap[
With[x = a + (b - a) z/(1 + z),
With[p = Together[#],
Min[CoefficientList[Denominator[r] - Numerator[r], z]] < 0.
]
] &,
Values[f]
]; // AbsoluteTiming // First
fpresieved = Pick[f, picker]
0.04817
<||>
Here is the idea behind the method.
Let $r(x)$ be a rational function from your list f
.
First, we apply the substitution x = a + (b - a) z/(1 + z)
; The mapping $z mapsto x$ maps the $[0,infty]$ to the interval $[a,b]$.
Thus, $r = fracpq$ is a rational function on the positive real axis for which we want to check whether
$$r(x) = fracp(z)q(z) leq 1 quad textfor all $z geq 0$.$$
This is equivalent to
$$q(z) - p(z) geq 0 quad textfor all $z geq 0$.$$
A sufficient condition for this is that all coefficients of the polynomial $q(z) - p(z)$ are nonnegative. So a necessary condition for r(x)
to be selected is that at least one coefficient of $q(z) - p(z)$ is negative. And precisely that is checked for in the code above.
$endgroup$
add a comment |
$begingroup$
The following is not the exact filter that you want, but a simple prefilter that apparently is quite good at filtering the given example ;) The point is that this check is much cheaper than computing the maxima, so it can be used to filter out (hopefully) many rational functions from your list f
, so that filtering the resulting list becomes less expensive.
Here is the code:
a = 2./382;
b = 1.;
picker =
ParallelMap[
With[x = a + (b - a) z/(1 + z),
With[p = Together[#],
Min[CoefficientList[Denominator[r] - Numerator[r], z]] < 0.
]
] &,
Values[f]
]; // AbsoluteTiming // First
fpresieved = Pick[f, picker]
0.04817
<||>
Here is the idea behind the method.
Let $r(x)$ be a rational function from your list f
.
First, we apply the substitution x = a + (b - a) z/(1 + z)
; The mapping $z mapsto x$ maps the $[0,infty]$ to the interval $[a,b]$.
Thus, $r = fracpq$ is a rational function on the positive real axis for which we want to check whether
$$r(x) = fracp(z)q(z) leq 1 quad textfor all $z geq 0$.$$
This is equivalent to
$$q(z) - p(z) geq 0 quad textfor all $z geq 0$.$$
A sufficient condition for this is that all coefficients of the polynomial $q(z) - p(z)$ are nonnegative. So a necessary condition for r(x)
to be selected is that at least one coefficient of $q(z) - p(z)$ is negative. And precisely that is checked for in the code above.
$endgroup$
add a comment |
$begingroup$
The following is not the exact filter that you want, but a simple prefilter that apparently is quite good at filtering the given example ;) The point is that this check is much cheaper than computing the maxima, so it can be used to filter out (hopefully) many rational functions from your list f
, so that filtering the resulting list becomes less expensive.
Here is the code:
a = 2./382;
b = 1.;
picker =
ParallelMap[
With[x = a + (b - a) z/(1 + z),
With[p = Together[#],
Min[CoefficientList[Denominator[r] - Numerator[r], z]] < 0.
]
] &,
Values[f]
]; // AbsoluteTiming // First
fpresieved = Pick[f, picker]
0.04817
<||>
Here is the idea behind the method.
Let $r(x)$ be a rational function from your list f
.
First, we apply the substitution x = a + (b - a) z/(1 + z)
; The mapping $z mapsto x$ maps the $[0,infty]$ to the interval $[a,b]$.
Thus, $r = fracpq$ is a rational function on the positive real axis for which we want to check whether
$$r(x) = fracp(z)q(z) leq 1 quad textfor all $z geq 0$.$$
This is equivalent to
$$q(z) - p(z) geq 0 quad textfor all $z geq 0$.$$
A sufficient condition for this is that all coefficients of the polynomial $q(z) - p(z)$ are nonnegative. So a necessary condition for r(x)
to be selected is that at least one coefficient of $q(z) - p(z)$ is negative. And precisely that is checked for in the code above.
$endgroup$
The following is not the exact filter that you want, but a simple prefilter that apparently is quite good at filtering the given example ;) The point is that this check is much cheaper than computing the maxima, so it can be used to filter out (hopefully) many rational functions from your list f
, so that filtering the resulting list becomes less expensive.
Here is the code:
a = 2./382;
b = 1.;
picker =
ParallelMap[
With[x = a + (b - a) z/(1 + z),
With[p = Together[#],
Min[CoefficientList[Denominator[r] - Numerator[r], z]] < 0.
]
] &,
Values[f]
]; // AbsoluteTiming // First
fpresieved = Pick[f, picker]
0.04817
<||>
Here is the idea behind the method.
Let $r(x)$ be a rational function from your list f
.
First, we apply the substitution x = a + (b - a) z/(1 + z)
; The mapping $z mapsto x$ maps the $[0,infty]$ to the interval $[a,b]$.
Thus, $r = fracpq$ is a rational function on the positive real axis for which we want to check whether
$$r(x) = fracp(z)q(z) leq 1 quad textfor all $z geq 0$.$$
This is equivalent to
$$q(z) - p(z) geq 0 quad textfor all $z geq 0$.$$
A sufficient condition for this is that all coefficients of the polynomial $q(z) - p(z)$ are nonnegative. So a necessary condition for r(x)
to be selected is that at least one coefficient of $q(z) - p(z)$ is negative. And precisely that is checked for in the code above.
answered 6 hours ago
Henrik SchumacherHenrik Schumacher
65.3k5 gold badges94 silver badges180 bronze badges
65.3k5 gold badges94 silver badges180 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f202252%2foptimising-the-selection-of-maxvalue-in-association%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
$begingroup$
If you have 8 cores, and use
ParallelTable
, that would take less than 12 minutes. Is that too long?$endgroup$
– rhermans
9 hours ago
$begingroup$
I have 4 so presume it will take 24', is there any way to chunk the code down into easier-to-handle part?
$endgroup$
– William
9 hours ago
$begingroup$
For all of the polynomials you give, the maximum lies at the lower edge of your search interval. Maybe there's something generalizable here: maybe it's possible to exclude a large number of polynomials by just looking at the values (and derivatives) at the end points.
$endgroup$
– Roman
7 hours ago