
(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 8 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%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -3.4e+186)
(* y z)
(if (<= z -7.4e+80)
t_0
(if (<= z -3.1e-90) (* y z) (if (<= z 1.0) x t_0))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -3.4e+186) {
tmp = y * z;
} else if (z <= -7.4e+80) {
tmp = t_0;
} else if (z <= -3.1e-90) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = 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 = x * -z
if (z <= (-3.4d+186)) then
tmp = y * z
else if (z <= (-7.4d+80)) then
tmp = t_0
else if (z <= (-3.1d-90)) then
tmp = y * z
else if (z <= 1.0d0) then
tmp = x
else
tmp = t_0
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 <= -3.4e+186) {
tmp = y * z;
} else if (z <= -7.4e+80) {
tmp = t_0;
} else if (z <= -3.1e-90) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -3.4e+186: tmp = y * z elif z <= -7.4e+80: tmp = t_0 elif z <= -3.1e-90: tmp = y * z elif z <= 1.0: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -3.4e+186) tmp = Float64(y * z); elseif (z <= -7.4e+80) tmp = t_0; elseif (z <= -3.1e-90) tmp = Float64(y * z); elseif (z <= 1.0) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -3.4e+186) tmp = y * z; elseif (z <= -7.4e+80) tmp = t_0; elseif (z <= -3.1e-90) tmp = y * z; elseif (z <= 1.0) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -3.4e+186], N[(y * z), $MachinePrecision], If[LessEqual[z, -7.4e+80], t$95$0, If[LessEqual[z, -3.1e-90], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.0], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -3.4 \cdot 10^{+186}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -7.4 \cdot 10^{+80}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -3.1 \cdot 10^{-90}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -3.40000000000000005e186 or -7.39999999999999992e80 < z < -3.1000000000000001e-90Initial program 99.9%
*-commutative99.9%
flip--70.4%
associate-*r/67.5%
associate-/l*70.3%
*-un-lft-identity70.3%
associate-/l*70.3%
flip--99.8%
Applied egg-rr99.8%
associate-/r/99.9%
/-rgt-identity99.9%
sub-neg99.9%
distribute-lft-out100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-rgt-neg-out100.0%
distribute-lft-neg-in100.0%
add-sqr-sqrt44.4%
sqrt-unprod77.9%
sqr-neg77.9%
sqrt-unprod39.1%
add-sqr-sqrt66.7%
cancel-sign-sub-inv66.7%
associate-+l-66.7%
add-sqr-sqrt39.1%
sqrt-unprod77.9%
sqr-neg77.9%
sqrt-unprod44.4%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 89.3%
Taylor expanded in y around inf 59.8%
*-commutative59.8%
Simplified59.8%
if -3.40000000000000005e186 < z < -7.39999999999999992e80 or 1 < z Initial program 100.0%
*-commutative100.0%
flip--77.7%
associate-*r/67.3%
associate-/l*77.5%
*-un-lft-identity77.5%
associate-/l*77.5%
flip--99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 60.8%
*-commutative60.8%
mul-1-neg60.8%
sub-neg60.8%
Simplified60.8%
Taylor expanded in z around inf 59.0%
*-commutative59.0%
mul-1-neg59.0%
distribute-rgt-neg-out59.0%
Simplified59.0%
if -3.1000000000000001e-90 < z < 1Initial program 100.0%
Taylor expanded in z around 0 76.6%
Final simplification66.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.15e-129) (not (<= x 3.8e-133))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.15e-129) || !(x <= 3.8e-133)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
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 <= (-1.15d-129)) .or. (.not. (x <= 3.8d-133))) then
tmp = x * (1.0d0 - z)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.15e-129) || !(x <= 3.8e-133)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.15e-129) or not (x <= 3.8e-133): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.15e-129) || !(x <= 3.8e-133)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.15e-129) || ~((x <= 3.8e-133))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.15e-129], N[Not[LessEqual[x, 3.8e-133]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{-129} \lor \neg \left(x \leq 3.8 \cdot 10^{-133}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.15e-129 or 3.8000000000000003e-133 < x Initial program 100.0%
Taylor expanded in x around inf 81.1%
mul-1-neg81.1%
unsub-neg81.1%
Simplified81.1%
if -1.15e-129 < x < 3.8000000000000003e-133Initial program 100.0%
*-commutative100.0%
flip--73.7%
associate-*r/67.6%
associate-/l*73.6%
*-un-lft-identity73.6%
associate-/l*73.7%
flip--99.7%
Applied egg-rr99.7%
associate-/r/100.0%
/-rgt-identity100.0%
sub-neg100.0%
distribute-lft-out100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-rgt-neg-out100.0%
distribute-lft-neg-in100.0%
add-sqr-sqrt52.6%
sqrt-unprod96.7%
sqr-neg96.7%
sqrt-unprod46.0%
add-sqr-sqrt93.9%
cancel-sign-sub-inv93.9%
associate-+l-93.9%
add-sqr-sqrt46.0%
sqrt-unprod96.7%
sqr-neg96.7%
sqrt-unprod52.6%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 83.0%
Taylor expanded in y around inf 77.8%
*-commutative77.8%
Simplified77.8%
Final simplification80.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.15e-88) (not (<= z 11000000000.0))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.15e-88) || !(z <= 11000000000.0)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
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 <= (-2.15d-88)) .or. (.not. (z <= 11000000000.0d0))) then
tmp = (y - x) * z
else
tmp = x * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.15e-88) || !(z <= 11000000000.0)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.15e-88) or not (z <= 11000000000.0): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.15e-88) || !(z <= 11000000000.0)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.15e-88) || ~((z <= 11000000000.0))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.15e-88], N[Not[LessEqual[z, 11000000000.0]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.15 \cdot 10^{-88} \lor \neg \left(z \leq 11000000000\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -2.1499999999999999e-88 or 1.1e10 < z Initial program 100.0%
*-commutative100.0%
flip--75.3%
associate-*r/68.0%
associate-/l*75.1%
*-un-lft-identity75.1%
associate-/l*75.2%
flip--99.8%
Applied egg-rr99.8%
associate-/r/100.0%
/-rgt-identity100.0%
sub-neg100.0%
distribute-lft-out96.4%
+-commutative96.4%
associate-+r+96.4%
distribute-rgt-neg-out96.4%
distribute-lft-neg-in96.4%
add-sqr-sqrt48.1%
sqrt-unprod70.5%
sqr-neg70.5%
sqrt-unprod27.4%
add-sqr-sqrt52.6%
cancel-sign-sub-inv52.6%
associate-+l-52.6%
add-sqr-sqrt27.4%
sqrt-unprod70.5%
sqr-neg70.5%
sqrt-unprod48.1%
add-sqr-sqrt96.4%
Applied egg-rr96.4%
Taylor expanded in z around inf 95.2%
if -2.1499999999999999e-88 < z < 1.1e10Initial program 100.0%
Taylor expanded in x around inf 78.5%
mul-1-neg78.5%
unsub-neg78.5%
Simplified78.5%
Final simplification87.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -10000.0) (not (<= z 0.019))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -10000.0) || !(z <= 0.019)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
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 <= (-10000.0d0)) .or. (.not. (z <= 0.019d0))) then
tmp = (y - x) * z
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -10000.0) || !(z <= 0.019)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -10000.0) or not (z <= 0.019): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -10000.0) || !(z <= 0.019)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -10000.0) || ~((z <= 0.019))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -10000.0], N[Not[LessEqual[z, 0.019]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -10000 \lor \neg \left(z \leq 0.019\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1e4 or 0.0189999999999999995 < z Initial program 100.0%
*-commutative100.0%
flip--79.5%
associate-*r/71.4%
associate-/l*79.4%
*-un-lft-identity79.4%
associate-/l*79.4%
flip--99.8%
Applied egg-rr99.8%
associate-/r/100.0%
/-rgt-identity100.0%
sub-neg100.0%
distribute-lft-out96.0%
+-commutative96.0%
associate-+r+96.0%
distribute-rgt-neg-out96.0%
distribute-lft-neg-in96.0%
add-sqr-sqrt48.3%
sqrt-unprod68.1%
sqr-neg68.1%
sqrt-unprod22.6%
add-sqr-sqrt45.6%
cancel-sign-sub-inv45.6%
associate-+l-45.6%
add-sqr-sqrt22.6%
sqrt-unprod68.1%
sqr-neg68.1%
sqrt-unprod48.3%
add-sqr-sqrt96.0%
Applied egg-rr96.0%
Taylor expanded in z around inf 98.8%
if -1e4 < z < 0.0189999999999999995Initial program 100.0%
Taylor expanded in y around inf 97.8%
*-commutative97.8%
Simplified97.8%
Final simplification98.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -9.6e-91) (not (<= z 8.2e-14))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9.6e-91) || !(z <= 8.2e-14)) {
tmp = y * z;
} else {
tmp = 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 <= (-9.6d-91)) .or. (.not. (z <= 8.2d-14))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -9.6e-91) || !(z <= 8.2e-14)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9.6e-91) or not (z <= 8.2e-14): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9.6e-91) || !(z <= 8.2e-14)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -9.6e-91) || ~((z <= 8.2e-14))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9.6e-91], N[Not[LessEqual[z, 8.2e-14]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.6 \cdot 10^{-91} \lor \neg \left(z \leq 8.2 \cdot 10^{-14}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.60000000000000043e-91 or 8.2000000000000004e-14 < z Initial program 100.0%
*-commutative100.0%
flip--73.1%
associate-*r/66.3%
associate-/l*72.9%
*-un-lft-identity72.9%
associate-/l*73.0%
flip--99.8%
Applied egg-rr99.8%
associate-/r/100.0%
/-rgt-identity100.0%
sub-neg100.0%
distribute-lft-out96.7%
+-commutative96.7%
associate-+r+96.7%
distribute-rgt-neg-out96.7%
distribute-lft-neg-in96.7%
add-sqr-sqrt48.3%
sqrt-unprod68.7%
sqr-neg68.7%
sqrt-unprod26.5%
add-sqr-sqrt52.8%
cancel-sign-sub-inv52.8%
associate-+l-52.8%
add-sqr-sqrt26.5%
sqrt-unprod68.7%
sqr-neg68.7%
sqrt-unprod48.3%
add-sqr-sqrt96.7%
Applied egg-rr96.7%
Taylor expanded in z around inf 92.6%
Taylor expanded in y around inf 51.7%
*-commutative51.7%
Simplified51.7%
if -9.60000000000000043e-91 < z < 8.2000000000000004e-14Initial program 100.0%
Taylor expanded in z around 0 80.1%
Final simplification63.3%
(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}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in z around 0 37.3%
Final simplification37.3%
herbie shell --seed 2023336
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))