
(FPCore (x y) :precision binary64 (+ (+ x y) x))
double code(double x, double y) {
return (x + y) + x;
}
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(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) + x
end function
public static double code(double x, double y) {
return (x + y) + x;
}
def code(x, y): return (x + y) + x
function code(x, y) return Float64(Float64(x + y) + x) end
function tmp = code(x, y) tmp = (x + y) + x; end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] + x), $MachinePrecision]
\left(x + y\right) + x
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (+ x y) x))
double code(double x, double y) {
return (x + y) + x;
}
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(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) + x
end function
public static double code(double x, double y) {
return (x + y) + x;
}
def code(x, y): return (x + y) + x
function code(x, y) return Float64(Float64(x + y) + x) end
function tmp = code(x, y) tmp = (x + y) + x; end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] + x), $MachinePrecision]
\left(x + y\right) + x
(FPCore (x y) :precision binary64 (+ (+ x x) y))
double code(double x, double y) {
return (x + x) + y;
}
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(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + x) + y
end function
public static double code(double x, double y) {
return (x + x) + y;
}
def code(x, y): return (x + x) + y
function code(x, y) return Float64(Float64(x + x) + y) end
function tmp = code(x, y) tmp = (x + x) + y; end
code[x_, y_] := N[(N[(x + x), $MachinePrecision] + y), $MachinePrecision]
\left(x + x\right) + y
Initial program 100.0%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
+-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
lower-+.f64100.0%
Applied rewrites100.0%
(FPCore (x y)
:precision binary64
(if (<= x -31500000000)
(+ x x)
(if (<=
x
329422299073093/803469022129495137770981046170581301261101496891396417650688)
(+ y x)
(+ x x))))double code(double x, double y) {
double tmp;
if (x <= -31500000000.0) {
tmp = x + x;
} else if (x <= 4.1e-46) {
tmp = y + x;
} else {
tmp = x + x;
}
return tmp;
}
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(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-31500000000.0d0)) then
tmp = x + x
else if (x <= 4.1d-46) then
tmp = y + x
else
tmp = x + x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -31500000000.0) {
tmp = x + x;
} else if (x <= 4.1e-46) {
tmp = y + x;
} else {
tmp = x + x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -31500000000.0: tmp = x + x elif x <= 4.1e-46: tmp = y + x else: tmp = x + x return tmp
function code(x, y) tmp = 0.0 if (x <= -31500000000.0) tmp = Float64(x + x); elseif (x <= 4.1e-46) tmp = Float64(y + x); else tmp = Float64(x + x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -31500000000.0) tmp = x + x; elseif (x <= 4.1e-46) tmp = y + x; else tmp = x + x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -31500000000], N[(x + x), $MachinePrecision], If[LessEqual[x, 329422299073093/803469022129495137770981046170581301261101496891396417650688], N[(y + x), $MachinePrecision], N[(x + x), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;x \leq -31500000000:\\
\;\;\;\;x + x\\
\mathbf{elif}\;x \leq \frac{329422299073093}{803469022129495137770981046170581301261101496891396417650688}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;x + x\\
\end{array}
if x < -3.15e10 or 4.0999999999999999e-46 < x Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6450.3%
Applied rewrites50.3%
lift-*.f64N/A
count-2-revN/A
lift-+.f6450.3%
Applied rewrites50.3%
if -3.15e10 < x < 4.0999999999999999e-46Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites58.8%
(FPCore (x y)
:precision binary64
(if (<= x -31500000000)
(+ x x)
(if (<=
x
329422299073093/803469022129495137770981046170581301261101496891396417650688)
y
(+ x x))))double code(double x, double y) {
double tmp;
if (x <= -31500000000.0) {
tmp = x + x;
} else if (x <= 4.1e-46) {
tmp = y;
} else {
tmp = x + x;
}
return tmp;
}
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(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-31500000000.0d0)) then
tmp = x + x
else if (x <= 4.1d-46) then
tmp = y
else
tmp = x + x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -31500000000.0) {
tmp = x + x;
} else if (x <= 4.1e-46) {
tmp = y;
} else {
tmp = x + x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -31500000000.0: tmp = x + x elif x <= 4.1e-46: tmp = y else: tmp = x + x return tmp
function code(x, y) tmp = 0.0 if (x <= -31500000000.0) tmp = Float64(x + x); elseif (x <= 4.1e-46) tmp = y; else tmp = Float64(x + x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -31500000000.0) tmp = x + x; elseif (x <= 4.1e-46) tmp = y; else tmp = x + x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -31500000000], N[(x + x), $MachinePrecision], If[LessEqual[x, 329422299073093/803469022129495137770981046170581301261101496891396417650688], y, N[(x + x), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;x \leq -31500000000:\\
\;\;\;\;x + x\\
\mathbf{elif}\;x \leq \frac{329422299073093}{803469022129495137770981046170581301261101496891396417650688}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x + x\\
\end{array}
if x < -3.15e10 or 4.0999999999999999e-46 < x Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6450.3%
Applied rewrites50.3%
lift-*.f64N/A
count-2-revN/A
lift-+.f6450.3%
Applied rewrites50.3%
if -3.15e10 < x < 4.0999999999999999e-46Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6450.3%
Applied rewrites50.3%
Taylor expanded in x around 0
Applied rewrites51.1%
(FPCore (x y) :precision binary64 y)
double code(double x, double y) {
return y;
}
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(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y
end function
public static double code(double x, double y) {
return y;
}
def code(x, y): return y
function code(x, y) return y end
function tmp = code(x, y) tmp = y; end
code[x_, y_] := y
y
Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6450.3%
Applied rewrites50.3%
Taylor expanded in x around 0
Applied rewrites51.1%
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (x y)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, A"
:precision binary64
(+ (+ x y) x))