
(FPCore (x y z t) :precision binary64 (- 1 (/ x (* (- y z) (- y t)))))
double code(double x, double y, double z, double t) {
return 1.0 - (x / ((y - z) * (y - t)));
}
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, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = 1.0d0 - (x / ((y - z) * (y - t)))
end function
public static double code(double x, double y, double z, double t) {
return 1.0 - (x / ((y - z) * (y - t)));
}
def code(x, y, z, t): return 1.0 - (x / ((y - z) * (y - t)))
function code(x, y, z, t) return Float64(1.0 - Float64(x / Float64(Float64(y - z) * Float64(y - t)))) end
function tmp = code(x, y, z, t) tmp = 1.0 - (x / ((y - z) * (y - t))); end
code[x_, y_, z_, t_] := N[(1 - N[(x / N[(N[(y - z), $MachinePrecision] * N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
1 - \frac{x}{\left(y - z\right) \cdot \left(y - t\right)}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (- 1 (/ x (* (- y z) (- y t)))))
double code(double x, double y, double z, double t) {
return 1.0 - (x / ((y - z) * (y - t)));
}
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, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = 1.0d0 - (x / ((y - z) * (y - t)))
end function
public static double code(double x, double y, double z, double t) {
return 1.0 - (x / ((y - z) * (y - t)));
}
def code(x, y, z, t): return 1.0 - (x / ((y - z) * (y - t)))
function code(x, y, z, t) return Float64(1.0 - Float64(x / Float64(Float64(y - z) * Float64(y - t)))) end
function tmp = code(x, y, z, t) tmp = 1.0 - (x / ((y - z) * (y - t))); end
code[x_, y_, z_, t_] := N[(1 - N[(x / N[(N[(y - z), $MachinePrecision] * N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
1 - \frac{x}{\left(y - z\right) \cdot \left(y - t\right)}
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ x (* (- t y) (- y z))))
(t_2 (- 1 (/ x (* (- y z) (- y t))))))
(if (<= t_2 -1000000) t_1 (if (<= t_2 2) 1 t_1))))double code(double x, double y, double z, double t) {
double t_1 = x / ((t - y) * (y - z));
double t_2 = 1.0 - (x / ((y - z) * (y - t)));
double tmp;
if (t_2 <= -1000000.0) {
tmp = t_1;
} else if (t_2 <= 2.0) {
tmp = 1.0;
} else {
tmp = t_1;
}
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, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = x / ((t - y) * (y - z))
t_2 = 1.0d0 - (x / ((y - z) * (y - t)))
if (t_2 <= (-1000000.0d0)) then
tmp = t_1
else if (t_2 <= 2.0d0) then
tmp = 1.0d0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = x / ((t - y) * (y - z));
double t_2 = 1.0 - (x / ((y - z) * (y - t)));
double tmp;
if (t_2 <= -1000000.0) {
tmp = t_1;
} else if (t_2 <= 2.0) {
tmp = 1.0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x / ((t - y) * (y - z)) t_2 = 1.0 - (x / ((y - z) * (y - t))) tmp = 0 if t_2 <= -1000000.0: tmp = t_1 elif t_2 <= 2.0: tmp = 1.0 else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x / Float64(Float64(t - y) * Float64(y - z))) t_2 = Float64(1.0 - Float64(x / Float64(Float64(y - z) * Float64(y - t)))) tmp = 0.0 if (t_2 <= -1000000.0) tmp = t_1; elseif (t_2 <= 2.0) tmp = 1.0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x / ((t - y) * (y - z)); t_2 = 1.0 - (x / ((y - z) * (y - t))); tmp = 0.0; if (t_2 <= -1000000.0) tmp = t_1; elseif (t_2 <= 2.0) tmp = 1.0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x / N[(N[(t - y), $MachinePrecision] * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1 - N[(x / N[(N[(y - z), $MachinePrecision] * N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1000000], t$95$1, If[LessEqual[t$95$2, 2], 1, t$95$1]]]]
\begin{array}{l}
t_1 := \frac{x}{\left(t - y\right) \cdot \left(y - z\right)}\\
t_2 := 1 - \frac{x}{\left(y - z\right) \cdot \left(y - t\right)}\\
\mathbf{if}\;t\_2 \leq -1000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
if (-.f64 #s(literal 1 binary64) (/.f64 x (*.f64 (-.f64 y z) (-.f64 y t)))) < -1e6 or 2 < (-.f64 #s(literal 1 binary64) (/.f64 x (*.f64 (-.f64 y z) (-.f64 y t)))) Initial program 99.0%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lower-*.f64N/A
frac-2negN/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lift--.f64N/A
sub-negate-revN/A
lower-*.f64N/A
lower--.f6498.9%
Applied rewrites98.9%
Taylor expanded in x around inf
lower-/.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower--.f6426.6%
Applied rewrites26.6%
if -1e6 < (-.f64 #s(literal 1 binary64) (/.f64 x (*.f64 (-.f64 y z) (-.f64 y t)))) < 2Initial program 99.0%
Taylor expanded in x around 0
Applied rewrites74.5%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- y (fmin z t)))
(t_2 (/ x (* (fmax z t) t_1)))
(t_3 (- 1 (/ x (* t_1 (- y (fmax z t)))))))
(if (<= t_3 -1000000) t_2 (if (<= t_3 2) 1 t_2))))double code(double x, double y, double z, double t) {
double t_1 = y - fmin(z, t);
double t_2 = x / (fmax(z, t) * t_1);
double t_3 = 1.0 - (x / (t_1 * (y - fmax(z, t))));
double tmp;
if (t_3 <= -1000000.0) {
tmp = t_2;
} else if (t_3 <= 2.0) {
tmp = 1.0;
} else {
tmp = t_2;
}
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, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_1 = y - fmin(z, t)
t_2 = x / (fmax(z, t) * t_1)
t_3 = 1.0d0 - (x / (t_1 * (y - fmax(z, t))))
if (t_3 <= (-1000000.0d0)) then
tmp = t_2
else if (t_3 <= 2.0d0) then
tmp = 1.0d0
else
tmp = t_2
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = y - fmin(z, t);
double t_2 = x / (fmax(z, t) * t_1);
double t_3 = 1.0 - (x / (t_1 * (y - fmax(z, t))));
double tmp;
if (t_3 <= -1000000.0) {
tmp = t_2;
} else if (t_3 <= 2.0) {
tmp = 1.0;
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z, t): t_1 = y - fmin(z, t) t_2 = x / (fmax(z, t) * t_1) t_3 = 1.0 - (x / (t_1 * (y - fmax(z, t)))) tmp = 0 if t_3 <= -1000000.0: tmp = t_2 elif t_3 <= 2.0: tmp = 1.0 else: tmp = t_2 return tmp
function code(x, y, z, t) t_1 = Float64(y - fmin(z, t)) t_2 = Float64(x / Float64(fmax(z, t) * t_1)) t_3 = Float64(1.0 - Float64(x / Float64(t_1 * Float64(y - fmax(z, t))))) tmp = 0.0 if (t_3 <= -1000000.0) tmp = t_2; elseif (t_3 <= 2.0) tmp = 1.0; else tmp = t_2; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y - min(z, t); t_2 = x / (max(z, t) * t_1); t_3 = 1.0 - (x / (t_1 * (y - max(z, t)))); tmp = 0.0; if (t_3 <= -1000000.0) tmp = t_2; elseif (t_3 <= 2.0) tmp = 1.0; else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y - N[Min[z, t], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x / N[(N[Max[z, t], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(1 - N[(x / N[(t$95$1 * N[(y - N[Max[z, t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -1000000], t$95$2, If[LessEqual[t$95$3, 2], 1, t$95$2]]]]]
\begin{array}{l}
t_1 := y - \mathsf{min}\left(z, t\right)\\
t_2 := \frac{x}{\mathsf{max}\left(z, t\right) \cdot t\_1}\\
t_3 := 1 - \frac{x}{t\_1 \cdot \left(y - \mathsf{max}\left(z, t\right)\right)}\\
\mathbf{if}\;t\_3 \leq -1000000:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_3 \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
if (-.f64 #s(literal 1 binary64) (/.f64 x (*.f64 (-.f64 y z) (-.f64 y t)))) < -1e6 or 2 < (-.f64 #s(literal 1 binary64) (/.f64 x (*.f64 (-.f64 y z) (-.f64 y t)))) Initial program 99.0%
Taylor expanded in t around inf
lower-+.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower--.f6479.2%
Applied rewrites79.2%
Taylor expanded in y around inf
lower-*.f6458.3%
Applied rewrites58.3%
lift-+.f64N/A
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
distribute-neg-frac2N/A
lower--.f64N/A
lower-*.f64N/A
metadata-evalN/A
frac-2neg-revN/A
lower-/.f6458.2%
Applied rewrites58.2%
Taylor expanded in x around inf
lower-/.f64N/A
lower-*.f64N/A
lower--.f6418.1%
Applied rewrites18.1%
if -1e6 < (-.f64 #s(literal 1 binary64) (/.f64 x (*.f64 (-.f64 y z) (-.f64 y t)))) < 2Initial program 99.0%
Taylor expanded in x around 0
Applied rewrites74.5%
(FPCore (x y z t) :precision binary64 1)
double code(double x, double y, double z, double t) {
return 1.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, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = 1.0d0
end function
public static double code(double x, double y, double z, double t) {
return 1.0;
}
def code(x, y, z, t): return 1.0
function code(x, y, z, t) return 1.0 end
function tmp = code(x, y, z, t) tmp = 1.0; end
code[x_, y_, z_, t_] := 1
1
Initial program 99.0%
Taylor expanded in x around 0
Applied rewrites74.5%
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (x y z t)
:name "Data.Random.Distribution.Triangular:triangularCDF from random-fu-0.2.6.2, A"
:precision binary64
(- 1 (/ x (* (- y z) (- y t)))))