
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
double code(double x, double y, double z) {
return (x * (y - z)) / 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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y - z)) / y
end function
public static double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
def code(x, y, z): return (x * (y - z)) / y
function code(x, y, z) return Float64(Float64(x * Float64(y - z)) / y) end
function tmp = code(x, y, z) tmp = (x * (y - z)) / y; end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
\frac{x \cdot \left(y - z\right)}{y}
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
double code(double x, double y, double z) {
return (x * (y - z)) / 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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y - z)) / y
end function
public static double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
def code(x, y, z): return (x * (y - z)) / y
function code(x, y, z) return Float64(Float64(x * Float64(y - z)) / y) end
function tmp = code(x, y, z) tmp = (x * (y - z)) / y; end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
\frac{x \cdot \left(y - z\right)}{y}
(FPCore (x y z) :precision binary64 (134-z0z1z2z3z4 (/ 1 y) y x z x))
\mathsf{134\_z0z1z2z3z4}\left(\left(\frac{1}{y}\right), y, x, z, x\right)
Initial program 84.5%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lift-*.f64N/A
lift--.f64N/A
distribute-rgt-out--N/A
lower-134-z0z1z2z3z4N/A
lower-/.f6499.7%
Applied rewrites99.7%
(FPCore (x y z) :precision binary64 (- x (* (/ z y) x)))
double code(double x, double y, double z) {
return x - ((z / 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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x - ((z / y) * x)
end function
public static double code(double x, double y, double z) {
return x - ((z / y) * x);
}
def code(x, y, z): return x - ((z / y) * x)
function code(x, y, z) return Float64(x - Float64(Float64(z / y) * x)) end
function tmp = code(x, y, z) tmp = x - ((z / y) * x); end
code[x_, y_, z_] := N[(x - N[(N[(z / y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
x - \frac{z}{y} \cdot x
Initial program 84.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lift--.f64N/A
sub-flipN/A
div-addN/A
distribute-rgt-inN/A
fp-cancel-sign-sub-invN/A
*-inversesN/A
*-lft-identityN/A
distribute-neg-fracN/A
remove-double-negN/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f6496.3%
Applied rewrites96.3%
(FPCore (x y z) :precision binary64 (* (/ (- y z) y) x))
double code(double x, double y, double z) {
return ((y - z) / 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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((y - z) / y) * x
end function
public static double code(double x, double y, double z) {
return ((y - z) / y) * x;
}
def code(x, y, z): return ((y - z) / y) * x
function code(x, y, z) return Float64(Float64(Float64(y - z) / y) * x) end
function tmp = code(x, y, z) tmp = ((y - z) / y) * x; end
code[x_, y_, z_] := N[(N[(N[(y - z), $MachinePrecision] / y), $MachinePrecision] * x), $MachinePrecision]
\frac{y - z}{y} \cdot x
Initial program 84.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6496.3%
Applied rewrites96.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (/ (fabs x) y) (- y z)))
(t_1 (/ (* (fabs x) (- y z)) y)))
(*
(copysign 1 x)
(if (<= t_1 0)
t_0
(if (<=
t_1
4230758200257591/42307582002575910332922579714097346549017899709713998034217522897561970639123926132812109468141778230245837569601494931472384)
(* 1 (fabs x))
t_0)))))double code(double x, double y, double z) {
double t_0 = (fabs(x) / y) * (y - z);
double t_1 = (fabs(x) * (y - z)) / y;
double tmp;
if (t_1 <= 0.0) {
tmp = t_0;
} else if (t_1 <= 1e-109) {
tmp = 1.0 * fabs(x);
} else {
tmp = t_0;
}
return copysign(1.0, x) * tmp;
}
public static double code(double x, double y, double z) {
double t_0 = (Math.abs(x) / y) * (y - z);
double t_1 = (Math.abs(x) * (y - z)) / y;
double tmp;
if (t_1 <= 0.0) {
tmp = t_0;
} else if (t_1 <= 1e-109) {
tmp = 1.0 * Math.abs(x);
} else {
tmp = t_0;
}
return Math.copySign(1.0, x) * tmp;
}
def code(x, y, z): t_0 = (math.fabs(x) / y) * (y - z) t_1 = (math.fabs(x) * (y - z)) / y tmp = 0 if t_1 <= 0.0: tmp = t_0 elif t_1 <= 1e-109: tmp = 1.0 * math.fabs(x) else: tmp = t_0 return math.copysign(1.0, x) * tmp
function code(x, y, z) t_0 = Float64(Float64(abs(x) / y) * Float64(y - z)) t_1 = Float64(Float64(abs(x) * Float64(y - z)) / y) tmp = 0.0 if (t_1 <= 0.0) tmp = t_0; elseif (t_1 <= 1e-109) tmp = Float64(1.0 * abs(x)); else tmp = t_0; end return Float64(copysign(1.0, x) * tmp) end
function tmp_2 = code(x, y, z) t_0 = (abs(x) / y) * (y - z); t_1 = (abs(x) * (y - z)) / y; tmp = 0.0; if (t_1 <= 0.0) tmp = t_0; elseif (t_1 <= 1e-109) tmp = 1.0 * abs(x); else tmp = t_0; end tmp_2 = (sign(x) * abs(1.0)) * tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[Abs[x], $MachinePrecision] / y), $MachinePrecision] * N[(y - z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Abs[x], $MachinePrecision] * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$1, 0], t$95$0, If[LessEqual[t$95$1, 4230758200257591/42307582002575910332922579714097346549017899709713998034217522897561970639123926132812109468141778230245837569601494931472384], N[(1 * N[Abs[x], $MachinePrecision]), $MachinePrecision], t$95$0]]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \frac{\left|x\right|}{y} \cdot \left(y - z\right)\\
t_1 := \frac{\left|x\right| \cdot \left(y - z\right)}{y}\\
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq 0:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq \frac{4230758200257591}{42307582002575910332922579714097346549017899709713998034217522897561970639123926132812109468141778230245837569601494931472384}:\\
\;\;\;\;1 \cdot \left|x\right|\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (-.f64 y z)) y) < -0.0 or 9.9999999999999999e-110 < (/.f64 (*.f64 x (-.f64 y z)) y) Initial program 84.5%
lift-/.f64N/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
mult-flip-revN/A
lower-/.f6484.2%
Applied rewrites84.2%
if -0.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < 9.9999999999999999e-110Initial program 84.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6496.3%
Applied rewrites96.3%
Taylor expanded in y around inf
Applied rewrites51.6%
(FPCore (x y z) :precision binary64 (* 1 x))
double code(double x, double y, double z) {
return 1.0 * 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, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 * x
end function
public static double code(double x, double y, double z) {
return 1.0 * x;
}
def code(x, y, z): return 1.0 * x
function code(x, y, z) return Float64(1.0 * x) end
function tmp = code(x, y, z) tmp = 1.0 * x; end
code[x_, y_, z_] := N[(1 * x), $MachinePrecision]
1 \cdot x
Initial program 84.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6496.3%
Applied rewrites96.3%
Taylor expanded in y around inf
Applied rewrites51.6%
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (x y z)
:name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"
:precision binary64
(/ (* x (- y z)) y))