AAdjustable Coins
Shlomo Moran ∗ Irad Yavneh ∗ August 11, 2020
Abstract
In this paper we consider a scenario where there are several algorithmsfor solving a given problem. Each algorithm is associated with a proba-bility of success and a cost, and there is also a penalty for failing to solvethe problem. The user may run one algorithm at a time for the specifiedcost, or give up and pay the penalty. The probability of success may beimplied by randomization in the algorithm, or by assuming a probabilitydistribution on the input space, which lead to different variants of theproblem. The goal is to minimize the expected cost of the process underthe assumption that the algorithms are independent. We study severalvariants of this problem, and present possible solution strategies and ahardness result.
Some optimization problems concern optimal ordering of certain tasks that aimat achieving some common goal (see, e.g., [1]). A possible scenario can bedescribed as follows: the king’s daughter is approaching marrying age. Themiser king, who cares about money more than anything else, estimates that if shedoesn’t marry then he will need to spend E gold pieces to continue supportingher for the rest of their lives. There are n princes he can invite to try to win herheart, and he must choose the order, knowing that the cost of travel room andboard for prince i is µ i , and the probability that he will win the princess’s heartis P i . What order minimizes the king’s expected cost? In a more challengingscenario, there are n kingdoms with several eligible princes in each kingdom,each with his own µ and P , and the king must also decide which prince heshould invite from each kingdom (he cannot invite more than one).Such problems can be described as one player games, which we call adjustablecoins games. An adjustable coin—A-coin in short—is a coin whose bias can becontrolled by the user: the probability of success (rolling on one) can be in-creased, for a price. Formally, an A-coin is defined by a monotone increasingfunction µ : D µ → R + where D µ ⊆ (0 ,
1] contains the possible success proba-bilities, and for P ∈ D µ , µ ( P ) is the nonnegative fee for tossing the coin with ∗ Compter Science Department, Technion. Israel a r X i v : . [ c s . D S ] A ug uccess probability P . If | D µ | = 1 then µ is a simple coin , or just coin, denotedby a pair c = ( P, µ ). Thus an A-coin µ can be viewed as a set of the simplecoins { ( P, µ ( P )) : P ∈ D µ } .In the games studied in this paper the player is given a set C of A-coinsand a penalty E >
0, and in each step she may select an A-coin µ ∈ C , and aprobability P ∈ D µ , and toss the coin for the fee µ ( P ) . If the coin rolls on onethe player terminates the game without paying a penalty, else she either takesanother step, or terminates the game and pays the penalty E . Thus, a strategyfor an A-coin game maps each pair ( C , E ) of the set of A-coins and a penaltyto a sequence SEQ of the coins tossed by the player when the outcomes of alltosses are zeros. The goal is to minimize the expected cost—the total amountpaid. Variants of this game are determined by the nature of the coins in C , therules by which coins can be selected at each step, possible restrictions on thetermination rule, etc. Specifically, we distinguish between reusable coins, whichcan be tossed many times, and one time coins, which can be tossed only once.The latter case corresponds to a scenario where one or more deterministic testsshould be taken on a single item selected at random from a known distribution—repeating a test on the selected item just reproduces the initial outcome.In Section 2 we study variants of the game for simple coins. In Section3 we study the case where the A-coins are discrete, i.e., defined for finitelymany values. In Section 4 we study the game for A-coins which are piecewisecontinuous functions. In this section we study optimal strategies for the game where all A-coins aresimple. A useful property of a simple coin c = ( P, µ ) is its rate , given by the ratio r = µ/P . The notation c ∼ ( P, r ) means that the simple coin c has probability P and is of rate r , i.e., c = ( P, rP ). In the simplest scenario we are given a simple coin c = ( P, µ ) and a penalty E , and we must decide whether tossing the coin c is beneficial , i.e., reduces theexpected cost of the game.The expected payment when c is tossed is given by COST ( c, E ) = µ + (1 − P ) E = E − ( P E − µ ) , (1)which means that the benefit of using c w.r.t. E is ( P E − µ ) (see Figure 1). COST ( c, E ) as a function of the rate r of c is given by COST ( c, E ) = P r + (1 − P ) E = E − P ( E − r ) , (2)implying that the benefit of c w.r.t. E is P ( E − r ). This means that an optimalstrategy for this case is to toss c if and only if its rate is smaller than E .2 P Benefit w.r.t. E Benefit of c w.r.t. E Benefit of c w.r.t. E > < c =(P , ) c =(P , ) =PE Figure 1:
Benefit for a given penalty.
A coin c = ( P, µ ) is beneficial forpenalty E iff ( P, µ ) lies below the line µ = P E , and the benefit of c w.r.t. E is P E − µ . Thus both c and c are beneficial for E . The benefit of c is largersince it is further away from the line µ = P E , i.e. µ − µ P − P < E .In a natural extension of the “single coin single toss” game we are given asequence of coins SEQ = ( c , . . . , c n ) and a penalty E . Our task is to decidefor each coin, in the given order, if it should be tossed or skipped, so that theexpected cost of the implied game is minimized. For n = 1 this is the singlecoin single toss game. For n > backwards induction : Suppose we havean optimal strategy for SEQ (cid:48) = ( c , . . . , c n ) and E , whose cost is E (cid:48) . Then, bya simple calculation, an optimal strategy for SEQ and E is: toss c iff r < E (cid:48) ,and then, if the coin rolls on tail, continue with the optimal strategy for SEQ (cid:48) and E . Suppose next that we are given a (finite) set C of simple coins and a penalty E ,and we wish to select an optimal coin c ∈ C which minimizes COST ( c, E ), thecost of the single toss game. Let c = ( P, µ ). By Equation (1),
COST ( c, E ) isminimized if and only if the point c = ( P, µ ) lies below the line µ = P E and ata maximal distance (see Fig. 1).
Suppose now that the coins in C are reusable , that is, we may toss each coinin C multiple times. An elementary calculation shows that if there is no boundon the number of tosses, then tossing a coin of minimal possible rate r min untilit rolls on one yields an expected cost r min . Thus an optimal strategy is: if r min < E then toss a coin c min of rate r min until it rolls on one, else pay thepenalty E and terminate.Assume now that we are allowed to make no more than k tosses for some3 ≥
0. Given a set of reusable simple coins C and a penalty E , if r min ≥ E thendo nothing and pay the penalty E . Else an optimal strategy is obtained againby a backwards induction:If k = 0 or E ≤ r min then do nothing and pay the penalty E . So assumethat E > r min , and let E k = E k ( C , E, k ) be the expected cost of an optimalstrategy for set of coins C , penalty E and k tosses (in particular E = E ).Then E k > r min and an optimal strategy for k + 1 tosses is obtained by firstselecting and tossing a coin c k +1 ∈ C which minimizes COST ( c k +1 , E k ) asin Section 2.2 (note that COST ( c k +1 , E k ) < E k since E k > r min ); if c k +1 rolls on one then stop, else execute the optimal strategy for C , E and k . Thus E k +1 = COST ( c k +1 , E k ) > r min . We now assume that each coin in C can be tossed at most once, and we areallowed to toss as many coins as we wish.Consider first a variant of this game in which termination is possible only ifeither some coin rolls on one, or after all coins rolled on zero. We note that thisvariant is, in fact, the problem of optimal ordering of independent tests thatwas studied in [1], where each coin corresponds to a test, and it is needed tocheck if at least one test fails.A strategy for this latter game is a permutation of all the available coins.Thus given a set of n one-time simple coins C = { c , . . . , c n } , where c i = ( P i , µ i ),and a nonnegative penalty E , we need to find an optimal ordering of the coinsin C , which minimizes the expected cost.The expected cost for ordering SEQ = ( c , c , ..., c n ) and penalty E is givenby: COST ( SEQ, E ) = P µ + (1 − P ) P ( µ + µ ) + . . . + (1 − P )(1 − P ) · · · (1 − P n )( µ + · · · + µ n + E ) . (3) By straightforward induction,
COST ( SEQ, E ) can also be expressed as thefollowing convex combination of the coin rates r , . . . , r n and E . COST ( SEQ, E ) = P r + (1 − P ) P r + . . . + (1 − P ) · · · (1 − P i − ) P i r i + . . . + (1 − P ) · · · (1 − P n ) E. (4) Equation (4) implies the following useful lemma:
Lemma 1.
Let
SEQ = ( c , . . . , c n ) , where c k ∼ ( P k , r k ) , k = 1 , . . . , n , and let SEQ (cid:48) be obtained from
SEQ by interchanging c i and c i +1 . If r i ≥ r i +1 then COST ( SEQ (cid:48) , E ) ≤ COST ( SEQ, E ) , with equality iff r i = r i +1 .Proof. By substituting in Equation (4) we get
COST ( SEQ (cid:48) , E ) − COST ( SEQ, E ) = (cid:18) i − (cid:89) k =1 (1 − P k ) (cid:19) P i P i +1 ( r i +1 − r i ) , which is negative for r i > r i +1 , and equals zero iff r i = r i +1 .4emma 1 implies: Lemma 2.
Let C = { c , . . . , c n } be a set of one-time simple coins, where the rateof c i is r i . Then for each penalty E and each permutation π , ( c π (1) , . . . , c π ( n ) ) isan optimal ordering of C w.r.t E if and only if r π ( i ) ≤ r π ( i +1) for i = 1 , . . . , n − . Observe that the optimal orderings of a set of coins are independent of the valueof the penalty E . We note that Lemma 2 is equivalent to Theorem 1 of [1] whichconsidered optimal ordering of independent tests.Assume now that the player can terminate the game at any time (i.e., evenif no coin rolled on one and some coins were not tossed yet). By Lemma 2 andthe comment at the end of Section 2.1, an optimal strategy is obtained by anoptimal ordering of the coins in C whose rates are smaller than E . Lemma 3.
The optimal strategies for a set C of one-time simple coins and apenalty E are obtained by the optimal orderings of the coins in C whose ratesare smaller than E . Assume now that the coins are not reusable, and we may use at most k coins forsome k ≥
0. This problem can be solved by the following dynamic programmingalgorithm. First sort the coins whose rates are smaller than E by increasingrates (ties are broken arbitrarily). Let the sorted list be ( c , . . . , c n ), where c i = ( P i , µ i ).For i = 1 , . . . , n and j = 0 , . . . , max( k, n − i +1), let OP T ( i, j ) be the value of theoptimal strategies for the sequence ( c i , c i +1 , . . . , c n ) and penalty E which use atmost j coins. Thus our task is to find OP T (1 , k ). This can be done in kn stepsby setting OP T ( i,
0) = E for i = 1 , . . . , n , OP T ( n, j ) = µ n +(1 − P n ) E for j ≥ i = n − , n − , . . . , , j =1 , . . . k : OP T ( i, j ) = min (cid:18) OP T ( i + 1 , j ) , µ i + (1 − P i ) OP T ( i + 1 , j − (cid:19) . This implies the following.
Lemma 4.
Given a set C of n one-time simple coins and bound k on the numberof tosses, an optimal strategy for the implied game can be found in O ( kn ) time. The results for simple coins are summarized in Table 1.
An A-coin µ is discrete if its domain D µ is finite and contains at least two simplecoins. Given a penalty E > COST ( µ, E ) is naturally defined as COST ( µ, E ) = min c ∈ µ COST ( c, E ) . rate < E rate < E → toss until success n No Unlimited, order given Backwards induction n Yes Unlimited Section 2.3 Toss c min until success n Yes Bounded Backwards induction n No Unlimited Lemma 3 Toss by increasing rates n No Bounded Lemma 4 Backwards dynamic programming P A = PE d c f d L d P B = PE c L c c d Figure 2: A: L d , the supporting line for d and E d , is a supporting line of theconvex hull of µ = { c, d, f } . B: The rate of c (i.e., the slope of the dashed linesegment connecting c to the origin) is smaller than the rate of d , (the slope ofthe line connecting d to the origin).An A-coin µ can be viewed as the set of the simple coins { ( P, µ ( P )) : P ∈ D µ } .We assume that this set does not contain redundant coins, in the sense of thefollowing definitions. Definition 1.
A coin c ∈ µ is essential for µ (or just essential when µ isclear) if there is a penalty E c s.t. for any other coin d ∈ µ , COST ( c, E c )
A discrete coin µ is efficient if each coin in µ is essential. Efficient discrete coins posses nice geometrical properties, depicted in Fig. 2:6 emma 5.
Let µ be an efficient discrete coin. Then1. µ is a strictly convex function on D µ , and2. The function r ( P ) = µ ( P ) /P is strictly increasing on D µ .Sketch of proof. Let c ∼ ( P c , r c ) be any coin in µ . Then L c , the supporting linefor c and E c , is a supporting line of the convex hull of µ which contains c butno other coin in µ (see Fig. 2A). This proves (1).To show (2), let d ∼ ( P d , r d ) be another coin in µ , where P c < P d . Then r c < E c (since c lies below the line µ = P E c ), and d lies strictly above L c , the supportingline for c and E c , whose slope is E c . Hence r c < r d (see Fig. 2B). Optimal strategies for reusable discrete coins are implied by such strategiesfor sets of simple coins: Given a set C of discrete coins and a penalty E , let C (cid:48) be the union of the discrete coins in C . Applying the optimal strategiesfor reusable simple coins presented in Section 2.3 on C (cid:48) and E yields optimalstrategies for C and E . For example, when the number of tosses is unbounded,Lemma 5 implies the following strategy for a reusable efficient discrete coin µ :Let c min ∼ ( P min , r min ) be the coin with the minimum success probability in µ .If E > r min then repeatedly toss c min until it rolls on one, else pay the penalty E and terminate. Suppose we are given a sequence of one-time discrete coins and we need todecide for each coin µ , in its turn, whether to toss a simple coin from µ , andif so which one. Then we can use a simple extension of the strategy for simplecoins in Section 2.1: Given an optimal strategy for a sequence ( µ , . . . , µ n )with optimal cost E (cid:48) , an optimal strategy for ( µ , µ , . . . , µ n ) is obtained byskipping µ if COST ( µ , E (cid:48) ) ≥ E (cid:48) , and tossing a coin c ∈ µ which minimizes COST ( µ , E (cid:48) ) and upon failure executing the optimal strategy for ( µ , . . . , µ n )otherwise.Finding an optimal strategy for one-time discrete coins when the sequenceis not given is complicated by the fact that we need to decide which simple coinshould be selected from each discrete coin (if any) before the order of tosses isknown. Once these coins are selected, all we need to do is to toss them in anincreasing order of their rates, until some coin rolls on one (or all coins roll onzero), as discussed in Section 2.4. Thus, the strategy is determined by the waythe simple coins are chosen from the given discrete ones. We next show thatsuch a selection is NP Hard even in a highly restricted variant of the problem. { , } discrete coins problem We now present a restricted version of the A-coins problem—the { , } A-coinsproblem, and prove that it is NP hard. An instance ( C , E ) for this problem7onsists of a set C = { A , . . . , A n } of one-time discrete coins, where each A i contains two coins c i , d i , s.t. the rate of all c i coins is 0 and the rate of all d i coins is 1, i.e., c i = (0 , P i, ) and d i = ( P i, , P i, ), where 0 ≤ P i, < P i, ≤ , i = 1 , . . . , n . Let h i = 1 − P i, and (cid:96) i = 1 − P i, ; then h = ( h , . . . , h n )and (cid:96) = ( (cid:96) , . . . , (cid:96) n ) are the failure probability vectors of c i ’s and d i ’s (note that h i > (cid:96) i for all i ). NP Hardness of the { , } discrete coin problem Consider an instance to the { , } problem with penalty E >
1, and let D = E −
1. By Lemma 3 an optimal strategy for this instance is obtained by selectinga set S ⊆ I n of indices i for which the coin c i is chosen, and tossing the coinsin S first. The cost of this strategy can be calculated as follows: charge eachevent (sequence of tosses) in which the first | S | tosses are zero by one, and inaddition charge the event in which all tosses are zero by D . The resulting costis COST h,(cid:96),D ( S ) = (cid:89) i ∈ S h i D · (cid:89) i ∈ I n \ S (cid:96) i . (5)For a vector a = ( a , . . . , a n ), let prod ( a ) be the product (cid:81) ni =1 a i . Then (cid:81) [ i ∈ I n \ S ] (cid:96) i = prod ( (cid:96) ) (cid:81) i ∈ S (cid:96) i . Hence, letting b i = (cid:96) i h i < b = ( b , . . . , b n ), wecan rewrite (5) as a function of h and b : COST h,b,D ( S ) = (cid:89) i ∈ S h i + D · prod ( (cid:96) ) (cid:81) i ∈ S b i (6)Let H S = (cid:81) i ∈ S h i and B S = (cid:81) i ∈ S b i . Then Equation (6) can be rewritten as COST (cid:96),b,C ( S ) = H S + CB S , (7)where C = D · prod ( (cid:96) ). Consider now the case h = b (i.e., ∀ i : (cid:96) i = h i ).Then weget COST h,C ( S ) = H S + CH S . (8)Since the function f ( x ) = x + Cx has a unique minimum at x = √ C , we getthat COST h,C ( S ) ≥ √ C + √ C , with equality iff H s = √ C . This implies thefollowing: Lemma 6.
Let C = { A i : i = 1 , . . . , n } be a set of A-coins with A i = { c i , d i } where c i ∼ (0 , − h i ) , d i ∼ (1 , − h i ) and let C = D · ( prod ( h )) . Let further OP T ( C , D + 1) be the value of theoptimal solution to the { , } A-coins problem for C and penalty D + 1 . Then OP T ( C , D + 1) ≥ √ C + 1 √ C , ith equality iff for some S ⊆ I n it holds that H S = √ C . Lemma 6 now implies:
Theorem 7.
The { , } A-coins problem is NP Hard.Outline of proof.
By a reduction from the NP hard subset product problem [2]:
Input: An n + 1 tuple of natural numbers ( m , . . . , m n , N ) Property:
There is a subset S ⊆ I n s.t. (cid:81) i ∈ S m i = N .Given an instance ( m , . . . , m n , N ) to the subset product problem, we reduceit to an instance ( C , D + 1) to the { , } problem in which C = { A , . . . , A n } ,where for each i , c i ∼ (0 , − m i ) and d i ∼ (1 , − m i ) - i.e., h i = m i and (cid:96) i = m i . In addition, we set D to (cid:16) prod ( m ) N (cid:17) .Let C = D · ( prod ( h )) = D ( prod ( m )) . Then from Lemma 6 it follows that OP T ( C , D + 1) ≥ √ C + √ C , and OP T ( C , D + 1) = √ C + √ C iff there is asubset S ⊆ I n s.t. (cid:81) i ∈ S m i = N . The theorem follows. Note:
The rates 0 and 1 in Theorem 7 could be replaced by any pair of distinctrates 0 ≤ a < b .A summary of the results for discrete coins appears in Table 2 below.Table 2: Solutions and hardenss results for Discrete Coins n Yes Unlimited Section 3.1 Extensions of solutions n Yes Bounded for simple coins n No Unlimited, order given Section 3.2 n No Unlimited Theorem 7 NP hard even for { } coins A continuous adjustable coin, or CA-coin, enables the user to smoothly andcontinuously adjust the desired success probability. As a possible example, as-sume an algorithm which gets a composite integer n as an input, and repeatedlyattempts to find a divisor of n . µ ( P ) is the cost (e.g. running time) of findinga divisor with probability P , and the penalty E is the loss implied by failingto find a divisor. The reusable version assumes that the algorithm is random-ized, and the one time version assumes that the composite number is selectedat random from a given distribution.In general, a CA-coin is defined by a non-decreasing cost function µ ( P ) :[ P min , P max ] → R where 0 < P min < P max ≤ E is naturally defined as COST ( µ, E ) = min P ∈ [ P min ,P max ] COST ( P, µ ( P )) = min P ∈ [ P min ,P max µ ( P )+(1 − P ) E.
9e assume, as in the case of discrete A-coins, that each CA-coin is efficient,that is, for each P ∈ [ P min , P max ] there is a penalty E P s.t. COST (( P, µ ( P )) , E P )has a unique minimum at P = P . By arguments similar to the ones used inLemma 5, this implies that a CA-coin µ is a nonnegative convex function on[ P min , P max ], and that r ( P ) = µ ( P ) /P is a strictly increasing function of P .We restrict our attention to regular CA-coins µ ( P ) which are defined and twicecontinuously differentiable on the segment [ P min , P max ]. This implies that dµdP > d µdP > , P ∈ ( P min , P max ) . Suppose we are given a single (efficient) CA-coin and are allowed to toss it onceat most. That is, given E we must decide whether we wish to use our CA-coinat all, and if we do, which value of P we should choose so as to minimize theexpected cost. Recall that the expected cost is given by COST ( µ ( P ) , P, E ) = µ ( P ) + (1 − P ) E = P · r ( P ) + (1 − P ) E , where r ( P ) = µ/P . Differentiating COST with respect to P we obtain dCOSTdP = dµdP − E .
Differentiating r ( P ) and noting that it is strictly increasing yield drdP = 1 P (cid:18) dµdP − r (cid:19) > . Observe that for P ∈ ( P min , P max ), for each coin c = ( P , µ ( P )) there is aunique supporting line, namely, the tangent to µ at c . This yields the followingconclusions. Let r min = r ( P min ), E low be the derivative of µ at P min , and E high be the derivative of µ at P max —see Fig. 3. Then1. If E ≤ r min then the coin is not beneficial for E , i.e., COST ( µ, E ) = E .Otherwise the coin is beneficial for E , and the maximum benefit for agiven penalty E is attained as follows:2. If r min < E ≤ E low then the benefit is maximized at P min .3. If E low < E < E high then the maximal benefit is attained at the uniqueinternal value P opt ∈ ( P min , P max ), where dµdP = E .4. If E high ≤ E then the benefit is maximized at P max .10 P Continuous A-coin
O p min
O P max
CA coin = P r min = P E low = P E high
Figure 3: c min = ( P min , µ ( P min )), c max = ( P max , µ ( P max )), and r min = µ ( P min ) P min . If E < r min then c min lies above the line µ = P E , meaning thatthe CA-coin is not beneficial for E . For E ∈ ( r min , E low ] any supporting line of µ = P E passes through c min . For E ∈ ( E low , E high ) there is a unique support-ing line that passes through an internal point of the coin, and for E ∈ [ E high , ∞ )any supporting line passes through c max . Suppose next that we are given a single regular CA-coin which we may toss mul-tiple times, selecting P for each toss. The optimal strategy for minimizing theexpected cost as a function of the number of tosses we are allowed, is obtainedrecursively from the observations of the previous subsection 4.1. If the numberof tosses is unlimited and r min < E , then we can reduce the expected cost to r min by repeatedly tossing the coin with P = P min until we succeed. If thenumber of tosses is bounded then we can use the recursive approach describedin Section 2.3.When we are given a few regular CA-coins { µ , . . . , µ k } which we may tossmultiple times, we adapt a variant of strategies used in Sections 2.3 and 3.2:whenever we need to toss a coin for a given penalty E , we select µ j for which COST ( µ j , E ) is minimized. This can be done by computing COST ( µ i , E ) forall i ∈ [1 , k ]. We present the concept of adjustable coins, which aims to model a scenario inwhich various algorithms for solving a given problem can be applied: Each suchalgorithm is modeled by an adjustable coin, which is characterized by a costand a probability of success. The related optimization problem is: Given a setof independent A-coins and a penalty for failing to solve the problem, find a11equence of coin-tosses which minimizes the expected cost, subject to possiblefurther restrictions.We note that all our solutions are by offline algorithms, which require thatthe full set (or sequence) of coins is given before the first coin is tossed. Aninteresting problem is what conditions enable useful algorithms which use onlypartial information on the available coins (e.g., that the coins are drawn froma known distribution, or that only a limited number of coins is known ahead oftime).
References [1] D. Berend, R. Brafman, S. Cohen, S.E. Shimony, and S. Zucker. Optimalordering of independent tests with precedence constraints.
Discrete AppliedMathematics , 162:115 – 127, 2014.[2] S. Moran. General approximation algorithms for some arithmetical combi-natorial problems.