
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((y - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((y - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (- y x) z x))
double code(double x, double y, double z) {
return fma((y - x), z, x);
}
function code(x, y, z) return fma(Float64(y - x), z, x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, z, x\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- z) x)))
(if (<= z -2.1e+147)
t_0
(if (<= z -3.65e+50)
(* z y)
(if (<= z -1.2e-7)
t_0
(if (<= z 3.4e-66) (* 1.0 x) (if (<= z 2.4e+221) (* z y) t_0)))))))
double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (z <= -2.1e+147) {
tmp = t_0;
} else if (z <= -3.65e+50) {
tmp = z * y;
} else if (z <= -1.2e-7) {
tmp = t_0;
} else if (z <= 3.4e-66) {
tmp = 1.0 * x;
} else if (z <= 2.4e+221) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = -z * x
if (z <= (-2.1d+147)) then
tmp = t_0
else if (z <= (-3.65d+50)) then
tmp = z * y
else if (z <= (-1.2d-7)) then
tmp = t_0
else if (z <= 3.4d-66) then
tmp = 1.0d0 * x
else if (z <= 2.4d+221) then
tmp = z * y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (z <= -2.1e+147) {
tmp = t_0;
} else if (z <= -3.65e+50) {
tmp = z * y;
} else if (z <= -1.2e-7) {
tmp = t_0;
} else if (z <= 3.4e-66) {
tmp = 1.0 * x;
} else if (z <= 2.4e+221) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -z * x tmp = 0 if z <= -2.1e+147: tmp = t_0 elif z <= -3.65e+50: tmp = z * y elif z <= -1.2e-7: tmp = t_0 elif z <= 3.4e-66: tmp = 1.0 * x elif z <= 2.4e+221: tmp = z * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-z) * x) tmp = 0.0 if (z <= -2.1e+147) tmp = t_0; elseif (z <= -3.65e+50) tmp = Float64(z * y); elseif (z <= -1.2e-7) tmp = t_0; elseif (z <= 3.4e-66) tmp = Float64(1.0 * x); elseif (z <= 2.4e+221) tmp = Float64(z * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -z * x; tmp = 0.0; if (z <= -2.1e+147) tmp = t_0; elseif (z <= -3.65e+50) tmp = z * y; elseif (z <= -1.2e-7) tmp = t_0; elseif (z <= 3.4e-66) tmp = 1.0 * x; elseif (z <= 2.4e+221) tmp = z * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * x), $MachinePrecision]}, If[LessEqual[z, -2.1e+147], t$95$0, If[LessEqual[z, -3.65e+50], N[(z * y), $MachinePrecision], If[LessEqual[z, -1.2e-7], t$95$0, If[LessEqual[z, 3.4e-66], N[(1.0 * x), $MachinePrecision], If[LessEqual[z, 2.4e+221], N[(z * y), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot x\\
\mathbf{if}\;z \leq -2.1 \cdot 10^{+147}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -3.65 \cdot 10^{+50}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq -1.2 \cdot 10^{-7}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3.4 \cdot 10^{-66}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;z \leq 2.4 \cdot 10^{+221}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.10000000000000006e147 or -3.6500000000000002e50 < z < -1.19999999999999989e-7 or 2.40000000000000019e221 < z Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6468.0
Applied rewrites68.0%
Taylor expanded in z around inf
Applied rewrites67.1%
if -2.10000000000000006e147 < z < -3.6500000000000002e50 or 3.39999999999999997e-66 < z < 2.40000000000000019e221Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6465.8
Applied rewrites65.8%
if -1.19999999999999989e-7 < z < 3.39999999999999997e-66Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6470.2
Applied rewrites70.2%
Taylor expanded in z around 0
Applied rewrites70.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 z) x))) (if (<= x -9.4e-51) t_0 (if (<= x 1e+40) (* z (- y x)) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - z) * x;
double tmp;
if (x <= -9.4e-51) {
tmp = t_0;
} else if (x <= 1e+40) {
tmp = z * (y - x);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (1.0d0 - z) * x
if (x <= (-9.4d-51)) then
tmp = t_0
else if (x <= 1d+40) then
tmp = z * (y - x)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (1.0 - z) * x;
double tmp;
if (x <= -9.4e-51) {
tmp = t_0;
} else if (x <= 1e+40) {
tmp = z * (y - x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - z) * x tmp = 0 if x <= -9.4e-51: tmp = t_0 elif x <= 1e+40: tmp = z * (y - x) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - z) * x) tmp = 0.0 if (x <= -9.4e-51) tmp = t_0; elseif (x <= 1e+40) tmp = Float64(z * Float64(y - x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - z) * x; tmp = 0.0; if (x <= -9.4e-51) tmp = t_0; elseif (x <= 1e+40) tmp = z * (y - x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -9.4e-51], t$95$0, If[LessEqual[x, 1e+40], N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - z\right) \cdot x\\
\mathbf{if}\;x \leq -9.4 \cdot 10^{-51}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 10^{+40}:\\
\;\;\;\;z \cdot \left(y - x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -9.3999999999999995e-51 or 1.00000000000000003e40 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6488.1
Applied rewrites88.1%
if -9.3999999999999995e-51 < x < 1.00000000000000003e40Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
sub-negN/A
distribute-lft-inN/A
associate-+l+N/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
mul-1-negN/A
sub-negN/A
lower-*.f64N/A
lower--.f6481.1
Applied rewrites81.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 z) x))) (if (<= x -4.2e-80) t_0 (if (<= x 1.1e-39) (* z y) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - z) * x;
double tmp;
if (x <= -4.2e-80) {
tmp = t_0;
} else if (x <= 1.1e-39) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (1.0d0 - z) * x
if (x <= (-4.2d-80)) then
tmp = t_0
else if (x <= 1.1d-39) then
tmp = z * y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (1.0 - z) * x;
double tmp;
if (x <= -4.2e-80) {
tmp = t_0;
} else if (x <= 1.1e-39) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - z) * x tmp = 0 if x <= -4.2e-80: tmp = t_0 elif x <= 1.1e-39: tmp = z * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - z) * x) tmp = 0.0 if (x <= -4.2e-80) tmp = t_0; elseif (x <= 1.1e-39) tmp = Float64(z * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - z) * x; tmp = 0.0; if (x <= -4.2e-80) tmp = t_0; elseif (x <= 1.1e-39) tmp = z * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -4.2e-80], t$95$0, If[LessEqual[x, 1.1e-39], N[(z * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - z\right) \cdot x\\
\mathbf{if}\;x \leq -4.2 \cdot 10^{-80}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.1 \cdot 10^{-39}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -4.20000000000000003e-80 or 1.1e-39 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6485.2
Applied rewrites85.2%
if -4.20000000000000003e-80 < x < 1.1e-39Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6475.1
Applied rewrites75.1%
(FPCore (x y z) :precision binary64 (if (<= z -4.5e-16) (* z y) (if (<= z 3.4e-66) (* 1.0 x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.5e-16) {
tmp = z * y;
} else if (z <= 3.4e-66) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-4.5d-16)) then
tmp = z * y
else if (z <= 3.4d-66) then
tmp = 1.0d0 * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.5e-16) {
tmp = z * y;
} else if (z <= 3.4e-66) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.5e-16: tmp = z * y elif z <= 3.4e-66: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.5e-16) tmp = Float64(z * y); elseif (z <= 3.4e-66) tmp = Float64(1.0 * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.5e-16) tmp = z * y; elseif (z <= 3.4e-66) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.5e-16], N[(z * y), $MachinePrecision], If[LessEqual[z, 3.4e-66], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-16}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 3.4 \cdot 10^{-66}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -4.5000000000000002e-16 or 3.39999999999999997e-66 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6453.1
Applied rewrites53.1%
if -4.5000000000000002e-16 < z < 3.39999999999999997e-66Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6470.2
Applied rewrites70.2%
Taylor expanded in z around 0
Applied rewrites70.2%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return z * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6441.2
Applied rewrites41.2%
herbie shell --seed 2024327
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))