Time computation problems with “Maximize” expression

I just started to use Mathematica a few weeks ago. I am afraid there is something that does not work on my laptop because, for the following simple command, it takes too much time. Do you know if there is a mistake in this command syntax? Thank you in advance for your help.

Maximize[{(g/e)*Sqrt[((g – e)^2 + (f – h)^2)], 0 <= e <= 1, 0 <= f <= 1, e^2 + f^2 == 1, 0 <= g <= e, 0 <= h <= f}, {e, f, g, h}]

What’s the most effective way to maximize skills as a character of any class?

I feel like Pathfinder skills are very compact when compared to 3.5 skills, as a result that makes each individual skill point worth more than each individual point in 3.5, due to combining some skills to form others that perform multiple functions.

Since skill points are more valuable, what are the best ways to gain as many skill points as possible as a character of any class? What’s the best way to optimize a skills modifiers for each set of classes below without affecting combat stats?

I’d prefer if the answers were formatted in the following way, explaining how each group can more easily gain skill modifiers:

  • High skill point classes: Rogue, Bard
  • Medium skill point classes: Monk, Barbarian, Alchemist
  • Low skill point classes: Fighter, Magic-users, Paladins

Does the Tempest domain’s Destructive Wrath maximize ongoing damage from a twinned Witch Bolt?

I have a multiclass tempest cleric/sorcerer.

If I twin Witch Bolt and then use Channel Divinity: Destructive Wrath, which allows me to deal max thunder or lightning damage, are both bolts impacted? I assume I can concentrate on both because it is one spell casting but is the lingering effect of witch bolt also maximized?

What are some feats that are required to maximize eldritch blast damage output?

I am working on a warlock build for my next campaign and I am having trouble finding feats that would apply and boost Warlock’s eldritch blast damage output. This is because Warlock is not a traditional spell caster from PHB and I am unsure which feats would apply to EB as its a ranged touch attack. What are some of my options for EB feats and at what level they would come into play?

How can I maximize the value of Appearance for a sidhe?

I am preparing a character for my first Changeling:The Dreaming second edition game. I’ve opted for a sidhe, which come with this ability:

Sidhe get two extra dots of Appearance during character creation, even if this increases scores above 5.

Starting with an attribute of 7 sounds pretty incredible, so I’d like to maximize the value of my Appearance. I’m having some trouble:

  • I don’t see any attributes which obviously synergize with my high Appearance.
  • None of the Arts in the core rules are based on Appearance.
  • The only task I’ve seen which calls for Appearance is seduction.

How can I maximize the value of my abnormally high Appearance score? Assume nothing about the rest of the party (our characters will meet for the first time at the table). Anything published for Changeling: The Dreaming second edition is allowed, but I myself was only able to search the core rules.

If I cast Thunderous Smite and Booming Blade, hit, and use Destructive Wrath to maximize damage, how many uses of Channel Divinity are expended?

How many uses of channel divinity should be expended in the following example?


  • A character is using that a weapon that deals 2d6 thunder damage on a hit.
  • They cast Thunderous Smite, using a bonus action.
  • Then cast Booming Blade (at 5th level), making a melee attack as an action.
  • On a hit, the weapon does an additional 1d8 + 2d6 + 2d6 thunder damage.

Thunderous Smite:

The first time you hit with a melee weapon attack during this spell’s duration, your weapon rings with thunder that is audible within 300 feet of you, and the attack deals an extra 2d6 thunder damage to the target.

Booming Blade:

At 5th level, the melee attack deals an extra 1d8 thunder damage to the target, and the damage the target takes for moving increases to 2d8.

Destructive Wrath:

When you roll lightning or thunder damage, you can use your Channel Divinity to deal maximum damage, instead of rolling.

I’m interpreting this as three separate rolls for thunder damage, each requiring a use of Channel Divinity to maximize. Instead of one use of Channel Divinity to maximize all of them at once.

One of the main reasons I’m thinking this, is because another use of Channel Divinity needs to be expended to maximize the secondary damage from Booming Blade, as it’s a completely separate roll.

Maximize does not work

I try to maximise a following function:

 x[t_] :=   1/4 (-1 + a) + a/4 + 1/2 Sqrt[a - a^2] Cos[d] -    1/4 (1 - a) Cos[d + 2*t] + 1/4 a Cos[d - 2*t] +    1/2 Sqrt[a - a^2] Cos[2*t] 

with respect to a and d, and $ t \in (0,\frac{\pi}{4})$ . From NMaximize I know what the range of a and d should be (see figures, where, however, $ t \in (0,\frac{\pi}{2})$ ),

Numerical maximisation with respect to a

Numerical maximisation with respect to d

but I am looking for the analytical formula.

I have written something like this

Maximize[{x[t], 0 < t < Pi/4, 4/5 < a < 1, 0 < d < Pi/2}, {a, d}] 

(I have hoped that limiting the possible values of a and d will help Mathematica), but the output is the same as the input.

Does it mean that the Mathematica is not able to give the analytical form of the maximisation?

Need help optimizing an algorithm that’s supposed to maximize the greatest common divisor of n elements by removing at most one element

Alright, first here’s the text of the problem:

You’re given n bags of candies where the i-th bag contains a[i] candies and all numbers a[i] are in the segment [1,m]. You can choose a natural number x and each second remove x candies from one of the bags if it contains at least x candies. The goal is to empty all the bags except at most one of them. Find the greatest possible value of x that allows you to achieve this goal.

The desired time complexity is O(n* log m);

What I managed(I think) to do is write an O(n^2 * log m) algorithm (the two nested for loops are O(n^2) and Euclid’s algorithm is O(log m)).

The code written in c++ is below. The second for loop calculates the gcd of the numbers excluding the i-th number and I calculate the maximum by considering all values of i, but apparently it can be done linearly. Any ideas on how to optimize it to O(n* log m)?

int gcd(int a, int b){     if(b == 0)         return a;     return gcd(b, a%b); }   int greatestPossibleGcd(int *arr, int n){     int maxgcd = 0;     int current = 0;      for(int i=0;i<n;i++){         maxgcd = gcd(maxgcd, arr[i]);     }      for(int i=0;i<n;i++){         for(int j=0;j<n;j++){             if(j == i)                 continue;             current = gcd(current, arr[j]);         }         if(current > maxgcd)             maxgcd = current;          current = 0;     }      return maxgcd;  } 

Selling Stocks to Maximize Profit Algorithm – Greedy

I am trying to find an efficient algorithm that takes the prices p1 . . . pn and the function values f (1) . . . f (x) and determines the best way to sell x shares by day n.

Problem set-up.

I’m given the market prices for this stock over the next n days, let these be p1, p2 …pn. I also know the function f(y) which predicts the effect of selling y shares on a single day: if you sell y shares, it permanently decreases the price of the stock by f(y) from that day onwards.

So, if I sell y1 shares on day 1, the price per share for the transaction is p1 −f(y1) and the corresponding profit for that day is y1 · (p1 − f(y1)). If I then sell y2 shares on day 2, the price per share for that transaction is p2 − f(y1) − f(y2). Note that the decreases in price accumulates.

Assume that p1 …pn decreases monotonically and f(1) …f(x) increases monotonically. (Prices are generally going down and it goes down even more if I sell more shares). I can also assume that no matter how I sell your stocks, it is impossible for me to reduce the price of the stock to 0 (or negative numbers). (meaning, pi is larger than the cumulative decrease in price from any possible sequences of sales in the first i days) In other words, the algorithm finds integers y1 . . . yn, where yi corresponds to the number of shares sold on day i, such that:

  • All x shares are sold: 􏰀ni = 1 yi = x.
  • The total profit is maximized.

I know some about the stereotypical “buy-sell stocks” algorithm, but this seems like a bit of a different beast. I think this might be a greedy algorithm that takes a graph. Anything will help 🙂