
(FPCore (x) :precision binary64 (/ (+ x 16.0) 116.0))
double code(double x) {
return (x + 16.0) / 116.0;
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (x + 16.0d0) / 116.0d0
end function
public static double code(double x) {
return (x + 16.0) / 116.0;
}
def code(x): return (x + 16.0) / 116.0
function code(x) return Float64(Float64(x + 16.0) / 116.0) end
function tmp = code(x) tmp = (x + 16.0) / 116.0; end
code[x_] := N[(N[(x + 16.0), $MachinePrecision] / 116.0), $MachinePrecision]
\frac{x + 16}{116}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (+ x 16.0) 116.0))
double code(double x) {
return (x + 16.0) / 116.0;
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (x + 16.0d0) / 116.0d0
end function
public static double code(double x) {
return (x + 16.0) / 116.0;
}
def code(x): return (x + 16.0) / 116.0
function code(x) return Float64(Float64(x + 16.0) / 116.0) end
function tmp = code(x) tmp = (x + 16.0) / 116.0; end
code[x_] := N[(N[(x + 16.0), $MachinePrecision] / 116.0), $MachinePrecision]
\frac{x + 16}{116}
(FPCore (x) :precision binary64 (* (- x -16.0) 0.008620689655172414))
double code(double x) {
return (x - -16.0) * 0.008620689655172414;
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (x - (-16.0d0)) * 0.008620689655172414d0
end function
public static double code(double x) {
return (x - -16.0) * 0.008620689655172414;
}
def code(x): return (x - -16.0) * 0.008620689655172414
function code(x) return Float64(Float64(x - -16.0) * 0.008620689655172414) end
function tmp = code(x) tmp = (x - -16.0) * 0.008620689655172414; end
code[x_] := N[(N[(x - -16.0), $MachinePrecision] * 0.008620689655172414), $MachinePrecision]
\left(x - -16\right) \cdot 0.008620689655172414
Initial program 100.0%
lift-/.f64N/A
mult-flipN/A
lower-*.f64N/A
lift-+.f64N/A
add-flipN/A
lower--.f64N/A
metadata-evalN/A
metadata-eval99.9%
Applied rewrites99.9%
(FPCore (x)
:precision binary64
(if (<= x -540000.0)
(* 0.008620689655172414 x)
(if (<= x 4500000000.0)
0.13793103448275862
(* 0.008620689655172414 x))))double code(double x) {
double tmp;
if (x <= -540000.0) {
tmp = 0.008620689655172414 * x;
} else if (x <= 4500000000.0) {
tmp = 0.13793103448275862;
} else {
tmp = 0.008620689655172414 * 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-540000.0d0)) then
tmp = 0.008620689655172414d0 * x
else if (x <= 4500000000.0d0) then
tmp = 0.13793103448275862d0
else
tmp = 0.008620689655172414d0 * x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -540000.0) {
tmp = 0.008620689655172414 * x;
} else if (x <= 4500000000.0) {
tmp = 0.13793103448275862;
} else {
tmp = 0.008620689655172414 * x;
}
return tmp;
}
def code(x): tmp = 0 if x <= -540000.0: tmp = 0.008620689655172414 * x elif x <= 4500000000.0: tmp = 0.13793103448275862 else: tmp = 0.008620689655172414 * x return tmp
function code(x) tmp = 0.0 if (x <= -540000.0) tmp = Float64(0.008620689655172414 * x); elseif (x <= 4500000000.0) tmp = 0.13793103448275862; else tmp = Float64(0.008620689655172414 * x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -540000.0) tmp = 0.008620689655172414 * x; elseif (x <= 4500000000.0) tmp = 0.13793103448275862; else tmp = 0.008620689655172414 * x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -540000.0], N[(0.008620689655172414 * x), $MachinePrecision], If[LessEqual[x, 4500000000.0], 0.13793103448275862, N[(0.008620689655172414 * x), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;x \leq -540000:\\
\;\;\;\;0.008620689655172414 \cdot x\\
\mathbf{elif}\;x \leq 4500000000:\\
\;\;\;\;0.13793103448275862\\
\mathbf{else}:\\
\;\;\;\;0.008620689655172414 \cdot x\\
\end{array}
if x < -5.4e5 or 4.5e9 < x Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6450.9%
Applied rewrites50.9%
if -5.4e5 < x < 4.5e9Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites50.5%
(FPCore (x) :precision binary64 0.13793103448275862)
double code(double x) {
return 0.13793103448275862;
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 0.13793103448275862d0
end function
public static double code(double x) {
return 0.13793103448275862;
}
def code(x): return 0.13793103448275862
function code(x) return 0.13793103448275862 end
function tmp = code(x) tmp = 0.13793103448275862; end
code[x_] := 0.13793103448275862
0.13793103448275862
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites50.5%
herbie shell --seed 2025258
(FPCore (x)
:name "Data.Colour.CIE:cieLAB from colour-2.3.3, B"
:precision binary64
(/ (+ x 16.0) 116.0))