Reputation: 23
I need a function that takes two parameters as input: 0<=a<=1
and 0<=b<=1
.
The output is another number c
which falls in the interval [0,1]
too. c
must be greater than or equal to both a
and b
. The function must be monotonic as well, so if a2>a1
and b2>=b1
, c2
must be greater than c1
, unless c2=c1=1
.
Thanks you guys, I've figured out a simple solution myself. simply make c=a+b-ab
, all requirements are met.
Upvotes: 2
Views: 128
Reputation: 25992
Another proposal:
1-(1-a)(1-b)=a+b-ab=a+b(1-a)=b+a(1-b)
is, by the first form, inside [0,1], by the third greater than a for b<1, and by the fourth greater than b for a<1.
Upvotes: 0
Reputation: 29724
The requirement that c is always greater than a and b cannot be met since a and b are allowed to be 1.0
and c cannot be greater than this.
Also the requirement that
The function must be monotonic as well, so if a2>a1 and b2>=b1, c2 must be greater than c1.
is bad formed. This is not a definition of monotonicity of a multivariate function. Nevertheless, I give an example how to fulfill
The function must be monotonic as well, so if a2>a1 and b2>=b1, c2 must be greater than c1 (or c = 1.0).
condition too, in function (3).
Here I assume that c is greater or equal to both parameters:
(1)
double f( double a, double b) {
if ( (a == 1.0) || (b == 1.0)) return 1.0;
return max(a,b) + (1.0 - max(a,b)) / 2;
}
You can eventually specify epsilon to make accuracy explicit.
(2)
double f( double a, double b, double epsilon) {
if ( (a == 1.0) || (b == 1.0)) return 1.0;
return min( 1.0, max(a,b) + epsilon);
}
Function that satisfies also (bad worded monotonicity)
The function must be monotonic as well, so if a2>a1 and b2>=b1, c2 must be greater than c1.
(3)
double f( double a, double b, double epsilon) {
if ( (a == 1.0) || (b == 1.0)) return 1.0;
double distance = 1.0 - max(a,b);
return 1.0 - distance + max( epsilon, a * distance);
}
Upvotes: 1
Reputation: 41474
There is no such function possible. For a=0, b=1
, the only valid output would be c=1
. However, if a2=0.5, b2=1
, then again the only valid output is c2=1
, violating your second requirement.
Upvotes: 1
Reputation: 20027
One function to consider is bit interleaving or Morton numbers.
Example:
a = 0.1 0 0 1 = 9/16 = 0.5625
b = 0. 0 1 1 0 = 6/16 = 0.3750
c = 0.10010110 = 150/256 = 0.5859375 c >= a, c >= b
a = 1-epsilon = 0.1111111
b = 1-epsilon = 0.1111111 --> c = 0.11111111 = 1-epsilon
The numbers a, b must be sorted however, i.e. a > b
Upvotes: 0