
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
double code(double a, double b) {
return log((exp(a) + exp(b)));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = log((exp(a) + exp(b)))
end function
public static double code(double a, double b) {
return Math.log((Math.exp(a) + Math.exp(b)));
}
def code(a, b): return math.log((math.exp(a) + math.exp(b)))
function code(a, b) return log(Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = log((exp(a) + exp(b))); end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(e^{a} + e^{b}\right)
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
double code(double a, double b) {
return log((exp(a) + exp(b)));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = log((exp(a) + exp(b)))
end function
public static double code(double a, double b) {
return Math.log((Math.exp(a) + Math.exp(b)));
}
def code(a, b): return math.log((math.exp(a) + math.exp(b)))
function code(a, b) return log(Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = log((exp(a) + exp(b))); end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(e^{a} + e^{b}\right)
\end{array}
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (+ (/ b (+ 1.0 (exp a))) (log1p (exp a))))
assert(a < b);
double code(double a, double b) {
return (b / (1.0 + exp(a))) + log1p(exp(a));
}
assert a < b;
public static double code(double a, double b) {
return (b / (1.0 + Math.exp(a))) + Math.log1p(Math.exp(a));
}
[a, b] = sort([a, b]) def code(a, b): return (b / (1.0 + math.exp(a))) + math.log1p(math.exp(a))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(b / Float64(1.0 + exp(a))) + log1p(exp(a))) end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(b / N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{b}{1 + e^{a}} + \mathsf{log1p}\left(e^{a}\right)
\end{array}
Initial program 54.3%
Taylor expanded in b around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lift-exp.f64N/A
lower-log.f64N/A
lower-+.f64N/A
lift-exp.f6498.2
Applied rewrites98.2%
lift-log.f64N/A
lift-+.f64N/A
lift-exp.f64N/A
lower-log1p.f64N/A
lift-exp.f6498.4
Applied rewrites98.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (let* ((t_0 (+ 1.0 (exp a)))) (+ (/ b t_0) (log t_0))))
assert(a < b);
double code(double a, double b) {
double t_0 = 1.0 + exp(a);
return (b / t_0) + log(t_0);
}
NOTE: a and b should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_0
t_0 = 1.0d0 + exp(a)
code = (b / t_0) + log(t_0)
end function
assert a < b;
public static double code(double a, double b) {
double t_0 = 1.0 + Math.exp(a);
return (b / t_0) + Math.log(t_0);
}
[a, b] = sort([a, b]) def code(a, b): t_0 = 1.0 + math.exp(a) return (b / t_0) + math.log(t_0)
a, b = sort([a, b]) function code(a, b) t_0 = Float64(1.0 + exp(a)) return Float64(Float64(b / t_0) + log(t_0)) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
t_0 = 1.0 + exp(a);
tmp = (b / t_0) + log(t_0);
end
NOTE: a and b should be sorted in increasing order before calling this function.
code[a_, b_] := Block[{t$95$0 = N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]}, N[(N[(b / t$95$0), $MachinePrecision] + N[Log[t$95$0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\begin{array}{l}
t_0 := 1 + e^{a}\\
\frac{b}{t\_0} + \log t\_0
\end{array}
\end{array}
Initial program 54.3%
Taylor expanded in b around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lift-exp.f64N/A
lower-log.f64N/A
lower-+.f64N/A
lift-exp.f6498.2
Applied rewrites98.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (+ (* 0.5 b) (log1p (exp a))))
assert(a < b);
double code(double a, double b) {
return (0.5 * b) + log1p(exp(a));
}
assert a < b;
public static double code(double a, double b) {
return (0.5 * b) + Math.log1p(Math.exp(a));
}
[a, b] = sort([a, b]) def code(a, b): return (0.5 * b) + math.log1p(math.exp(a))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(0.5 * b) + log1p(exp(a))) end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(0.5 * b), $MachinePrecision] + N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
0.5 \cdot b + \mathsf{log1p}\left(e^{a}\right)
\end{array}
Initial program 54.3%
Taylor expanded in b around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lift-exp.f64N/A
lower-log.f64N/A
lower-+.f64N/A
lift-exp.f6498.2
Applied rewrites98.2%
lift-log.f64N/A
lift-+.f64N/A
lift-exp.f64N/A
lower-log1p.f64N/A
lift-exp.f6498.4
Applied rewrites98.4%
Taylor expanded in a around 0
lower-*.f6458.6
Applied rewrites58.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (+ (* 0.5 b) (log (+ 1.0 (exp a)))))
assert(a < b);
double code(double a, double b) {
return (0.5 * b) + log((1.0 + exp(a)));
}
NOTE: a and b should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (0.5d0 * b) + log((1.0d0 + exp(a)))
end function
assert a < b;
public static double code(double a, double b) {
return (0.5 * b) + Math.log((1.0 + Math.exp(a)));
}
[a, b] = sort([a, b]) def code(a, b): return (0.5 * b) + math.log((1.0 + math.exp(a)))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(0.5 * b) + log(Float64(1.0 + exp(a)))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (0.5 * b) + log((1.0 + exp(a)));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(0.5 * b), $MachinePrecision] + N[Log[N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
0.5 \cdot b + \log \left(1 + e^{a}\right)
\end{array}
Initial program 54.3%
Taylor expanded in b around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lift-exp.f64N/A
lower-log.f64N/A
lower-+.f64N/A
lift-exp.f6498.2
Applied rewrites98.2%
Taylor expanded in a around 0
lower-*.f6458.4
Applied rewrites58.4%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (log (+ (exp a) (+ 1.0 b))))
assert(a < b);
double code(double a, double b) {
return log((exp(a) + (1.0 + b)));
}
NOTE: a and b should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = log((exp(a) + (1.0d0 + b)))
end function
assert a < b;
public static double code(double a, double b) {
return Math.log((Math.exp(a) + (1.0 + b)));
}
[a, b] = sort([a, b]) def code(a, b): return math.log((math.exp(a) + (1.0 + b)))
a, b = sort([a, b]) function code(a, b) return log(Float64(exp(a) + Float64(1.0 + b))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = log((exp(a) + (1.0 + b)));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[(1.0 + b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\log \left(e^{a} + \left(1 + b\right)\right)
\end{array}
Initial program 54.3%
Taylor expanded in b around 0
lower-+.f6452.6
Applied rewrites52.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (log (+ 1.0 (exp a))))
assert(a < b);
double code(double a, double b) {
return log((1.0 + exp(a)));
}
NOTE: a and b should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = log((1.0d0 + exp(a)))
end function
assert a < b;
public static double code(double a, double b) {
return Math.log((1.0 + Math.exp(a)));
}
[a, b] = sort([a, b]) def code(a, b): return math.log((1.0 + math.exp(a)))
a, b = sort([a, b]) function code(a, b) return log(Float64(1.0 + exp(a))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = log((1.0 + exp(a)));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[Log[N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\log \left(1 + e^{a}\right)
\end{array}
Initial program 54.3%
Taylor expanded in b around 0
lower-+.f64N/A
lift-exp.f6451.2
Applied rewrites51.2%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (+ (/ a (+ 2.0 b)) (log (+ 2.0 b))))
assert(a < b);
double code(double a, double b) {
return (a / (2.0 + b)) + log((2.0 + b));
}
NOTE: a and b should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (a / (2.0d0 + b)) + log((2.0d0 + b))
end function
assert a < b;
public static double code(double a, double b) {
return (a / (2.0 + b)) + Math.log((2.0 + b));
}
[a, b] = sort([a, b]) def code(a, b): return (a / (2.0 + b)) + math.log((2.0 + b))
a, b = sort([a, b]) function code(a, b) return Float64(Float64(a / Float64(2.0 + b)) + log(Float64(2.0 + b))) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = (a / (2.0 + b)) + log((2.0 + b));
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(N[(a / N[(2.0 + b), $MachinePrecision]), $MachinePrecision] + N[Log[N[(2.0 + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\frac{a}{2 + b} + \log \left(2 + b\right)
\end{array}
Initial program 54.3%
Taylor expanded in a around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lift-exp.f64N/A
lower-log.f64N/A
lower-+.f64N/A
lift-exp.f6450.5
Applied rewrites50.5%
Taylor expanded in b around 0
lower-+.f6450.4
Applied rewrites50.4%
Taylor expanded in b around 0
lower-+.f6449.6
Applied rewrites49.6%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (fma 0.5 b (log 2.0)))
assert(a < b);
double code(double a, double b) {
return fma(0.5, b, log(2.0));
}
a, b = sort([a, b]) function code(a, b) return fma(0.5, b, log(2.0)) end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[(0.5 * b + N[Log[2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\mathsf{fma}\left(0.5, b, \log 2\right)
\end{array}
Initial program 54.3%
Taylor expanded in b around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lift-exp.f64N/A
lower-log.f64N/A
lower-+.f64N/A
lift-exp.f6498.2
Applied rewrites98.2%
Taylor expanded in a around 0
+-commutativeN/A
lower-fma.f64N/A
lower-log.f6450.1
Applied rewrites50.1%
NOTE: a and b should be sorted in increasing order before calling this function. (FPCore (a b) :precision binary64 (log 2.0))
assert(a < b);
double code(double a, double b) {
return log(2.0);
}
NOTE: a and b should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
code = log(2.0d0)
end function
assert a < b;
public static double code(double a, double b) {
return Math.log(2.0);
}
[a, b] = sort([a, b]) def code(a, b): return math.log(2.0)
a, b = sort([a, b]) function code(a, b) return log(2.0) end
a, b = num2cell(sort([a, b])){:}
function tmp = code(a, b)
tmp = log(2.0);
end
NOTE: a and b should be sorted in increasing order before calling this function. code[a_, b_] := N[Log[2.0], $MachinePrecision]
\begin{array}{l}
[a, b] = \mathsf{sort}([a, b])\\
\\
\log 2
\end{array}
Initial program 54.3%
Taylor expanded in b around 0
lower-+.f64N/A
lift-exp.f6451.2
Applied rewrites51.2%
Taylor expanded in a around 0
Applied rewrites49.3%
herbie shell --seed 2025139
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))