
(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
(if (<= y -4e+160)
(* y z)
(if (or (<= y -1.4e+100) (and (not (<= y -1.7e+14)) (<= y 1.4e+178)))
(* x (- 1.0 z))
(* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e+160) {
tmp = y * z;
} else if ((y <= -1.4e+100) || (!(y <= -1.7e+14) && (y <= 1.4e+178))) {
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 (y <= (-4d+160)) then
tmp = y * z
else if ((y <= (-1.4d+100)) .or. (.not. (y <= (-1.7d+14))) .and. (y <= 1.4d+178)) 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 (y <= -4e+160) {
tmp = y * z;
} else if ((y <= -1.4e+100) || (!(y <= -1.7e+14) && (y <= 1.4e+178))) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4e+160: tmp = y * z elif (y <= -1.4e+100) or (not (y <= -1.7e+14) and (y <= 1.4e+178)): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4e+160) tmp = Float64(y * z); elseif ((y <= -1.4e+100) || (!(y <= -1.7e+14) && (y <= 1.4e+178))) 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 (y <= -4e+160) tmp = y * z; elseif ((y <= -1.4e+100) || (~((y <= -1.7e+14)) && (y <= 1.4e+178))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4e+160], N[(y * z), $MachinePrecision], If[Or[LessEqual[y, -1.4e+100], And[N[Not[LessEqual[y, -1.7e+14]], $MachinePrecision], LessEqual[y, 1.4e+178]]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+160}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.4 \cdot 10^{+100} \lor \neg \left(y \leq -1.7 \cdot 10^{+14}\right) \land y \leq 1.4 \cdot 10^{+178}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -4.00000000000000003e160 or -1.3999999999999999e100 < y < -1.7e14 or 1.39999999999999997e178 < y Initial program 100.0%
Taylor expanded in z around inf 85.1%
Taylor expanded in y around inf 80.3%
*-commutative80.3%
Simplified80.3%
if -4.00000000000000003e160 < y < -1.3999999999999999e100 or -1.7e14 < y < 1.39999999999999997e178Initial program 100.0%
Taylor expanded in x around inf 80.2%
distribute-rgt1-in80.2%
mul-1-neg80.2%
cancel-sign-sub-inv80.2%
Simplified80.2%
Taylor expanded in x around 0 80.2%
Final simplification80.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= z -2e+52)
t_0
(if (<= z -1.2e-37)
(* y z)
(if (<= z 5.8e-13) x (if (<= z 3.6e+153) (* y z) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -2e+52) {
tmp = t_0;
} else if (z <= -1.2e-37) {
tmp = y * z;
} else if (z <= 5.8e-13) {
tmp = x;
} else if (z <= 3.6e+153) {
tmp = y * z;
} 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 <= (-2d+52)) then
tmp = t_0
else if (z <= (-1.2d-37)) then
tmp = y * z
else if (z <= 5.8d-13) then
tmp = x
else if (z <= 3.6d+153) then
tmp = y * z
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 <= -2e+52) {
tmp = t_0;
} else if (z <= -1.2e-37) {
tmp = y * z;
} else if (z <= 5.8e-13) {
tmp = x;
} else if (z <= 3.6e+153) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if z <= -2e+52: tmp = t_0 elif z <= -1.2e-37: tmp = y * z elif z <= 5.8e-13: tmp = x elif z <= 3.6e+153: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (z <= -2e+52) tmp = t_0; elseif (z <= -1.2e-37) tmp = Float64(y * z); elseif (z <= 5.8e-13) tmp = x; elseif (z <= 3.6e+153) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (z <= -2e+52) tmp = t_0; elseif (z <= -1.2e-37) tmp = y * z; elseif (z <= 5.8e-13) tmp = x; elseif (z <= 3.6e+153) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[z, -2e+52], t$95$0, If[LessEqual[z, -1.2e-37], N[(y * z), $MachinePrecision], If[LessEqual[z, 5.8e-13], x, If[LessEqual[z, 3.6e+153], N[(y * z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;z \leq -2 \cdot 10^{+52}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -1.2 \cdot 10^{-37}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 5.8 \cdot 10^{-13}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+153}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -2e52 or 3.6000000000000001e153 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around 0 64.2%
mul-1-neg64.2%
distribute-rgt-neg-out64.2%
Simplified64.2%
if -2e52 < z < -1.19999999999999995e-37 or 5.7999999999999995e-13 < z < 3.6000000000000001e153Initial program 99.9%
Taylor expanded in z around inf 88.0%
Taylor expanded in y around inf 66.4%
*-commutative66.4%
Simplified66.4%
if -1.19999999999999995e-37 < z < 5.7999999999999995e-13Initial program 100.0%
Taylor expanded in z around 0 76.4%
Final simplification70.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.12e-37) (not (<= z 4800.0))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.12e-37) || !(z <= 4800.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 <= (-1.12d-37)) .or. (.not. (z <= 4800.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 <= -1.12e-37) || !(z <= 4800.0)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.12e-37) or not (z <= 4800.0): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.12e-37) || !(z <= 4800.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 <= -1.12e-37) || ~((z <= 4800.0))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.12e-37], N[Not[LessEqual[z, 4800.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 -1.12 \cdot 10^{-37} \lor \neg \left(z \leq 4800\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -1.12e-37 or 4800 < z Initial program 100.0%
Taylor expanded in z around inf 96.2%
if -1.12e-37 < z < 4800Initial program 100.0%
Taylor expanded in x around inf 76.4%
distribute-rgt1-in76.4%
mul-1-neg76.4%
cancel-sign-sub-inv76.4%
Simplified76.4%
Taylor expanded in x around 0 76.4%
Final simplification86.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
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 <= (-1.0d0)) .or. (.not. (z <= 1.0d0))) 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 <= -1.0) || !(z <= 1.0)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.0): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) 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 <= -1.0) || ~((z <= 1.0))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $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 -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 98.3%
if -1 < z < 1Initial program 100.0%
Taylor expanded in y around inf 99.2%
*-commutative29.1%
Simplified99.2%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.2e-37) (* y z) (if (<= z 7.4e-12) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.2e-37) {
tmp = y * z;
} else if (z <= 7.4e-12) {
tmp = x;
} 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 (z <= (-1.2d-37)) then
tmp = y * z
else if (z <= 7.4d-12) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.2e-37) {
tmp = y * z;
} else if (z <= 7.4e-12) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.2e-37: tmp = y * z elif z <= 7.4e-12: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.2e-37) tmp = Float64(y * z); elseif (z <= 7.4e-12) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.2e-37) tmp = y * z; elseif (z <= 7.4e-12) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.2e-37], N[(y * z), $MachinePrecision], If[LessEqual[z, 7.4e-12], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.2 \cdot 10^{-37}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 7.4 \cdot 10^{-12}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.19999999999999995e-37 or 7.39999999999999997e-12 < z Initial program 100.0%
Taylor expanded in z around inf 95.0%
Taylor expanded in y around inf 54.2%
*-commutative54.2%
Simplified54.2%
if -1.19999999999999995e-37 < z < 7.39999999999999997e-12Initial program 100.0%
Taylor expanded in z around 0 76.4%
Final simplification65.2%
(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 40.7%
Final simplification40.7%
herbie shell --seed 2023240
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))