
(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%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= y -1.4e-64)
(* y z)
(if (<= y 2.15e-86)
t_0
(if (<= y 7e-49)
(* y z)
(if (<= y 3.8e-33) t_0 (if (<= y 3e+87) x (* y z))))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (y <= -1.4e-64) {
tmp = y * z;
} else if (y <= 2.15e-86) {
tmp = t_0;
} else if (y <= 7e-49) {
tmp = y * z;
} else if (y <= 3.8e-33) {
tmp = t_0;
} else if (y <= 3e+87) {
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) :: t_0
real(8) :: tmp
t_0 = x * -z
if (y <= (-1.4d-64)) then
tmp = y * z
else if (y <= 2.15d-86) then
tmp = t_0
else if (y <= 7d-49) then
tmp = y * z
else if (y <= 3.8d-33) then
tmp = t_0
else if (y <= 3d+87) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (y <= -1.4e-64) {
tmp = y * z;
} else if (y <= 2.15e-86) {
tmp = t_0;
} else if (y <= 7e-49) {
tmp = y * z;
} else if (y <= 3.8e-33) {
tmp = t_0;
} else if (y <= 3e+87) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if y <= -1.4e-64: tmp = y * z elif y <= 2.15e-86: tmp = t_0 elif y <= 7e-49: tmp = y * z elif y <= 3.8e-33: tmp = t_0 elif y <= 3e+87: tmp = x else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (y <= -1.4e-64) tmp = Float64(y * z); elseif (y <= 2.15e-86) tmp = t_0; elseif (y <= 7e-49) tmp = Float64(y * z); elseif (y <= 3.8e-33) tmp = t_0; elseif (y <= 3e+87) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (y <= -1.4e-64) tmp = y * z; elseif (y <= 2.15e-86) tmp = t_0; elseif (y <= 7e-49) tmp = y * z; elseif (y <= 3.8e-33) tmp = t_0; elseif (y <= 3e+87) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[y, -1.4e-64], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.15e-86], t$95$0, If[LessEqual[y, 7e-49], N[(y * z), $MachinePrecision], If[LessEqual[y, 3.8e-33], t$95$0, If[LessEqual[y, 3e+87], x, N[(y * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;y \leq -1.4 \cdot 10^{-64}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.15 \cdot 10^{-86}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-49}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-33}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+87}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.40000000000000002e-64 or 2.15000000000000007e-86 < y < 7.00000000000000012e-49 or 2.9999999999999999e87 < y Initial program 100.0%
Taylor expanded in x around 0 78.7%
if -1.40000000000000002e-64 < y < 2.15000000000000007e-86 or 7.00000000000000012e-49 < y < 3.79999999999999994e-33Initial program 100.0%
Taylor expanded in x around inf 90.7%
Taylor expanded in z around inf 58.5%
associate-*r*58.5%
mul-1-neg58.5%
Simplified58.5%
if 3.79999999999999994e-33 < y < 2.9999999999999999e87Initial program 100.0%
Taylor expanded in z around 0 42.5%
Final simplification67.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.2e-80) (not (<= z 2.8e-28))) (* (- y x) z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.2e-80) || !(z <= 2.8e-28)) {
tmp = (y - x) * 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 <= (-4.2d-80)) .or. (.not. (z <= 2.8d-28))) then
tmp = (y - x) * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.2e-80) || !(z <= 2.8e-28)) {
tmp = (y - x) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.2e-80) or not (z <= 2.8e-28): tmp = (y - x) * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.2e-80) || !(z <= 2.8e-28)) tmp = Float64(Float64(y - x) * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.2e-80) || ~((z <= 2.8e-28))) tmp = (y - x) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.2e-80], N[Not[LessEqual[z, 2.8e-28]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{-80} \lor \neg \left(z \leq 2.8 \cdot 10^{-28}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.20000000000000003e-80 or 2.7999999999999998e-28 < z Initial program 100.0%
Taylor expanded in z around inf 97.6%
if -4.20000000000000003e-80 < z < 2.7999999999999998e-28Initial program 100.0%
Taylor expanded in z around 0 67.5%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (<= y -4.5e+55) (* y z) (if (<= y 3.15e+87) (* x (- 1.0 z)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.5e+55) {
tmp = y * z;
} else if (y <= 3.15e+87) {
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 <= (-4.5d+55)) then
tmp = y * z
else if (y <= 3.15d+87) 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 <= -4.5e+55) {
tmp = y * z;
} else if (y <= 3.15e+87) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.5e+55: tmp = y * z elif y <= 3.15e+87: tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.5e+55) tmp = Float64(y * z); elseif (y <= 3.15e+87) 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 <= -4.5e+55) tmp = y * z; elseif (y <= 3.15e+87) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.5e+55], N[(y * z), $MachinePrecision], If[LessEqual[y, 3.15e+87], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{+55}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 3.15 \cdot 10^{+87}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -4.49999999999999998e55 or 3.15e87 < y Initial program 100.0%
Taylor expanded in x around 0 86.1%
if -4.49999999999999998e55 < y < 3.15e87Initial program 100.0%
Taylor expanded in x around inf 79.7%
distribute-rgt1-in79.6%
mul-1-neg79.6%
cancel-sign-sub-inv79.6%
Simplified79.6%
Taylor expanded in x around 0 79.7%
Final simplification82.2%
(FPCore (x y z) :precision binary64 (if (<= z -2.2e-80) (* y z) (if (<= z 1.05e-26) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e-80) {
tmp = y * z;
} else if (z <= 1.05e-26) {
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 <= (-2.2d-80)) then
tmp = y * z
else if (z <= 1.05d-26) 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 <= -2.2e-80) {
tmp = y * z;
} else if (z <= 1.05e-26) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.2e-80: tmp = y * z elif z <= 1.05e-26: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.2e-80) tmp = Float64(y * z); elseif (z <= 1.05e-26) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.2e-80) tmp = y * z; elseif (z <= 1.05e-26) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.2e-80], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.05e-26], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{-80}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{-26}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.2000000000000001e-80 or 1.05000000000000004e-26 < z Initial program 100.0%
Taylor expanded in x around 0 54.3%
if -2.2000000000000001e-80 < z < 1.05000000000000004e-26Initial program 100.0%
Taylor expanded in z around 0 67.5%
Final simplification58.9%
(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 26.6%
Final simplification26.6%
herbie shell --seed 2023274
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))