
(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 7 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 (* (- x) z)))
(if (<= z -1.4e+47)
t_0
(if (<= z -9.2e-95)
(* z y)
(if (<= z 1.3e-32)
(* 1.0 x)
(if (<= z 4.5e+19) (* z y) (if (<= z 2.95e+180) t_0 (* z y))))))))
double code(double x, double y, double z) {
double t_0 = -x * z;
double tmp;
if (z <= -1.4e+47) {
tmp = t_0;
} else if (z <= -9.2e-95) {
tmp = z * y;
} else if (z <= 1.3e-32) {
tmp = 1.0 * x;
} else if (z <= 4.5e+19) {
tmp = z * y;
} else if (z <= 2.95e+180) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = -x * z
if (z <= (-1.4d+47)) then
tmp = t_0
else if (z <= (-9.2d-95)) then
tmp = z * y
else if (z <= 1.3d-32) then
tmp = 1.0d0 * x
else if (z <= 4.5d+19) then
tmp = z * y
else if (z <= 2.95d+180) then
tmp = t_0
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -x * z;
double tmp;
if (z <= -1.4e+47) {
tmp = t_0;
} else if (z <= -9.2e-95) {
tmp = z * y;
} else if (z <= 1.3e-32) {
tmp = 1.0 * x;
} else if (z <= 4.5e+19) {
tmp = z * y;
} else if (z <= 2.95e+180) {
tmp = t_0;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): t_0 = -x * z tmp = 0 if z <= -1.4e+47: tmp = t_0 elif z <= -9.2e-95: tmp = z * y elif z <= 1.3e-32: tmp = 1.0 * x elif z <= 4.5e+19: tmp = z * y elif z <= 2.95e+180: tmp = t_0 else: tmp = z * y return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) * z) tmp = 0.0 if (z <= -1.4e+47) tmp = t_0; elseif (z <= -9.2e-95) tmp = Float64(z * y); elseif (z <= 1.3e-32) tmp = Float64(1.0 * x); elseif (z <= 4.5e+19) tmp = Float64(z * y); elseif (z <= 2.95e+180) tmp = t_0; else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x * z; tmp = 0.0; if (z <= -1.4e+47) tmp = t_0; elseif (z <= -9.2e-95) tmp = z * y; elseif (z <= 1.3e-32) tmp = 1.0 * x; elseif (z <= 4.5e+19) tmp = z * y; elseif (z <= 2.95e+180) tmp = t_0; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) * z), $MachinePrecision]}, If[LessEqual[z, -1.4e+47], t$95$0, If[LessEqual[z, -9.2e-95], N[(z * y), $MachinePrecision], If[LessEqual[z, 1.3e-32], N[(1.0 * x), $MachinePrecision], If[LessEqual[z, 4.5e+19], N[(z * y), $MachinePrecision], If[LessEqual[z, 2.95e+180], t$95$0, N[(z * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-x\right) \cdot z\\
\mathbf{if}\;z \leq -1.4 \cdot 10^{+47}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -9.2 \cdot 10^{-95}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{-32}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{+19}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 2.95 \cdot 10^{+180}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -1.39999999999999994e47 or 4.5e19 < z < 2.9500000000000001e180Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites60.6%
if -1.39999999999999994e47 < z < -9.19999999999999997e-95 or 1.2999999999999999e-32 < z < 4.5e19 or 2.9500000000000001e180 < z Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6468.0
Applied rewrites68.0%
if -9.19999999999999997e-95 < z < 1.2999999999999999e-32Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6480.8
Applied rewrites80.8%
Taylor expanded in z around 0
Applied rewrites80.8%
Final simplification71.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (- y x)))) (if (<= z -1.0) t_0 (if (<= z 1.0) (+ (* z y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = z * (y - x);
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 1.0) {
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 = z * (y - x)
if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 1.0d0) 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 = z * (y - x);
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = (z * y) + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * (y - x) tmp = 0 if z <= -1.0: tmp = t_0 elif z <= 1.0: tmp = (z * y) + x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(y - x)) tmp = 0.0 if (z <= -1.0) tmp = t_0; elseif (z <= 1.0) tmp = Float64(Float64(z * y) + x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (y - x); tmp = 0.0; if (z <= -1.0) tmp = t_0; elseif (z <= 1.0) tmp = (z * y) + x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 1.0], N[(N[(z * y), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(y - x\right)\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;z \cdot y + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6498.9
Applied rewrites98.9%
if -1 < z < 1Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6499.1
Applied rewrites99.1%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (- y x)))) (if (<= z -9.2e-95) t_0 (if (<= z 0.088) (* (- 1.0 z) x) t_0))))
double code(double x, double y, double z) {
double t_0 = z * (y - x);
double tmp;
if (z <= -9.2e-95) {
tmp = t_0;
} else if (z <= 0.088) {
tmp = (1.0 - z) * 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 * (y - x)
if (z <= (-9.2d-95)) then
tmp = t_0
else if (z <= 0.088d0) then
tmp = (1.0d0 - z) * 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 * (y - x);
double tmp;
if (z <= -9.2e-95) {
tmp = t_0;
} else if (z <= 0.088) {
tmp = (1.0 - z) * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * (y - x) tmp = 0 if z <= -9.2e-95: tmp = t_0 elif z <= 0.088: tmp = (1.0 - z) * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(y - x)) tmp = 0.0 if (z <= -9.2e-95) tmp = t_0; elseif (z <= 0.088) tmp = Float64(Float64(1.0 - z) * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (y - x); tmp = 0.0; if (z <= -9.2e-95) tmp = t_0; elseif (z <= 0.088) tmp = (1.0 - z) * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -9.2e-95], t$95$0, If[LessEqual[z, 0.088], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(y - x\right)\\
\mathbf{if}\;z \leq -9.2 \cdot 10^{-95}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.088:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -9.19999999999999997e-95 or 0.087999999999999995 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6495.7
Applied rewrites95.7%
if -9.19999999999999997e-95 < z < 0.087999999999999995Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6479.4
Applied rewrites79.4%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (<= y -7.2e+19) (* z y) (if (<= y 4.2e+54) (* (- 1.0 z) x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.2e+19) {
tmp = z * y;
} else if (y <= 4.2e+54) {
tmp = (1.0 - z) * 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 (y <= (-7.2d+19)) then
tmp = z * y
else if (y <= 4.2d+54) then
tmp = (1.0d0 - z) * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -7.2e+19) {
tmp = z * y;
} else if (y <= 4.2e+54) {
tmp = (1.0 - z) * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.2e+19: tmp = z * y elif y <= 4.2e+54: tmp = (1.0 - z) * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.2e+19) tmp = Float64(z * y); elseif (y <= 4.2e+54) tmp = Float64(Float64(1.0 - z) * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -7.2e+19) tmp = z * y; elseif (y <= 4.2e+54) tmp = (1.0 - z) * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.2e+19], N[(z * y), $MachinePrecision], If[LessEqual[y, 4.2e+54], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{+19}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{+54}:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -7.2e19 or 4.19999999999999972e54 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6474.3
Applied rewrites74.3%
if -7.2e19 < y < 4.19999999999999972e54Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6485.5
Applied rewrites85.5%
Final simplification81.1%
(FPCore (x y z) :precision binary64 (if (<= z -9.2e-95) (* z y) (if (<= z 1.3e-32) (* 1.0 x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.2e-95) {
tmp = z * y;
} else if (z <= 1.3e-32) {
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 <= (-9.2d-95)) then
tmp = z * y
else if (z <= 1.3d-32) 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 <= -9.2e-95) {
tmp = z * y;
} else if (z <= 1.3e-32) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.2e-95: tmp = z * y elif z <= 1.3e-32: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.2e-95) tmp = Float64(z * y); elseif (z <= 1.3e-32) 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 <= -9.2e-95) tmp = z * y; elseif (z <= 1.3e-32) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.2e-95], N[(z * y), $MachinePrecision], If[LessEqual[z, 1.3e-32], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{-95}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{-32}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -9.19999999999999997e-95 or 1.2999999999999999e-32 < z Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6452.9
Applied rewrites52.9%
if -9.19999999999999997e-95 < z < 1.2999999999999999e-32Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6480.8
Applied rewrites80.8%
Taylor expanded in z around 0
Applied rewrites80.8%
Final simplification65.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 y around inf
lower-*.f6438.9
Applied rewrites38.9%
Final simplification38.9%
herbie shell --seed 2024240
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))