
(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 -8.2e+152)
t_0
(if (<= z -5.5e-15) (* z y) (if (<= z 0.85) (* 1.0 x) t_0)))))
double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (z <= -8.2e+152) {
tmp = t_0;
} else if (z <= -5.5e-15) {
tmp = z * y;
} else if (z <= 0.85) {
tmp = 1.0 * 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 = -z * x
if (z <= (-8.2d+152)) then
tmp = t_0
else if (z <= (-5.5d-15)) then
tmp = z * y
else if (z <= 0.85d0) then
tmp = 1.0d0 * x
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 <= -8.2e+152) {
tmp = t_0;
} else if (z <= -5.5e-15) {
tmp = z * y;
} else if (z <= 0.85) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -z * x tmp = 0 if z <= -8.2e+152: tmp = t_0 elif z <= -5.5e-15: tmp = z * y elif z <= 0.85: tmp = 1.0 * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-z) * x) tmp = 0.0 if (z <= -8.2e+152) tmp = t_0; elseif (z <= -5.5e-15) tmp = Float64(z * y); elseif (z <= 0.85) tmp = Float64(1.0 * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -z * x; tmp = 0.0; if (z <= -8.2e+152) tmp = t_0; elseif (z <= -5.5e-15) tmp = z * y; elseif (z <= 0.85) tmp = 1.0 * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * x), $MachinePrecision]}, If[LessEqual[z, -8.2e+152], t$95$0, If[LessEqual[z, -5.5e-15], N[(z * y), $MachinePrecision], If[LessEqual[z, 0.85], N[(1.0 * x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot x\\
\mathbf{if}\;z \leq -8.2 \cdot 10^{+152}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -5.5 \cdot 10^{-15}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 0.85:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -8.1999999999999996e152 or 0.849999999999999978 < z Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6467.7
Applied rewrites67.7%
Taylor expanded in z around inf
Applied rewrites66.5%
if -8.1999999999999996e152 < z < -5.5000000000000002e-15Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6458.4
Applied rewrites58.4%
if -5.5000000000000002e-15 < z < 0.849999999999999978Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6472.0
Applied rewrites72.0%
Taylor expanded in z around 0
Applied rewrites71.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.8e-75) (not (<= x 2.1e+26))) (* (- 1.0 z) x) (* z (- y x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.8e-75) || !(x <= 2.1e+26)) {
tmp = (1.0 - z) * x;
} else {
tmp = z * (y - x);
}
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 ((x <= (-6.8d-75)) .or. (.not. (x <= 2.1d+26))) then
tmp = (1.0d0 - z) * x
else
tmp = z * (y - x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.8e-75) || !(x <= 2.1e+26)) {
tmp = (1.0 - z) * x;
} else {
tmp = z * (y - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.8e-75) or not (x <= 2.1e+26): tmp = (1.0 - z) * x else: tmp = z * (y - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.8e-75) || !(x <= 2.1e+26)) tmp = Float64(Float64(1.0 - z) * x); else tmp = Float64(z * Float64(y - x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.8e-75) || ~((x <= 2.1e+26))) tmp = (1.0 - z) * x; else tmp = z * (y - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.8e-75], N[Not[LessEqual[x, 2.1e+26]], $MachinePrecision]], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision], N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{-75} \lor \neg \left(x \leq 2.1 \cdot 10^{+26}\right):\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y - x\right)\\
\end{array}
\end{array}
if x < -6.8000000000000003e-75 or 2.1000000000000001e26 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6490.0
Applied rewrites90.0%
if -6.8000000000000003e-75 < x < 2.1000000000000001e26Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6466.6
Applied rewrites66.6%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6481.0
Applied rewrites81.0%
Final simplification86.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.5e-15) (not (<= z 5.5e-48))) (* z (- y x)) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.5e-15) || !(z <= 5.5e-48)) {
tmp = z * (y - x);
} else {
tmp = 1.0 * x;
}
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 <= (-5.5d-15)) .or. (.not. (z <= 5.5d-48))) then
tmp = z * (y - x)
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -5.5e-15) || !(z <= 5.5e-48)) {
tmp = z * (y - x);
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.5e-15) or not (z <= 5.5e-48): tmp = z * (y - x) else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.5e-15) || !(z <= 5.5e-48)) tmp = Float64(z * Float64(y - x)); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.5e-15) || ~((z <= 5.5e-48))) tmp = z * (y - x); else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.5e-15], N[Not[LessEqual[z, 5.5e-48]], $MachinePrecision]], N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{-15} \lor \neg \left(z \leq 5.5 \cdot 10^{-48}\right):\\
\;\;\;\;z \cdot \left(y - x\right)\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -5.5000000000000002e-15 or 5.50000000000000047e-48 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6444.9
Applied rewrites44.9%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6495.0
Applied rewrites95.0%
if -5.5000000000000002e-15 < z < 5.50000000000000047e-48Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6474.0
Applied rewrites74.0%
Taylor expanded in z around 0
Applied rewrites74.0%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.5e-15) (not (<= z 7.5e-84))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.5e-15) || !(z <= 7.5e-84)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
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 <= (-5.5d-15)) .or. (.not. (z <= 7.5d-84))) then
tmp = z * y
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -5.5e-15) || !(z <= 7.5e-84)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.5e-15) or not (z <= 7.5e-84): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.5e-15) || !(z <= 7.5e-84)) tmp = Float64(z * y); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.5e-15) || ~((z <= 7.5e-84))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.5e-15], N[Not[LessEqual[z, 7.5e-84]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{-15} \lor \neg \left(z \leq 7.5 \cdot 10^{-84}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -5.5000000000000002e-15 or 7.50000000000000026e-84 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6445.6
Applied rewrites45.6%
if -5.5000000000000002e-15 < z < 7.50000000000000026e-84Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6477.2
Applied rewrites77.2%
Taylor expanded in z around 0
Applied rewrites77.2%
Final simplification57.8%
(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-*.f6437.8
Applied rewrites37.8%
herbie shell --seed 2024299
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))