
(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.9e+248)
t_0
(if (<= z -2.6e+57)
(* y z)
(if (<= z -1.0)
t_0
(if (<= z 1.15e-56)
x
(if (or (<= z 255000000.0) (not (<= z 2.9e+136))) (* y z) t_0)))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -3.9e+248) {
tmp = t_0;
} else if (z <= -2.6e+57) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = t_0;
} else if (z <= 1.15e-56) {
tmp = x;
} else if ((z <= 255000000.0) || !(z <= 2.9e+136)) {
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 = x * -z
if (z <= (-3.9d+248)) then
tmp = t_0
else if (z <= (-2.6d+57)) then
tmp = y * z
else if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 1.15d-56) then
tmp = x
else if ((z <= 255000000.0d0) .or. (.not. (z <= 2.9d+136))) 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 = x * -z;
double tmp;
if (z <= -3.9e+248) {
tmp = t_0;
} else if (z <= -2.6e+57) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = t_0;
} else if (z <= 1.15e-56) {
tmp = x;
} else if ((z <= 255000000.0) || !(z <= 2.9e+136)) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -3.9e+248: tmp = t_0 elif z <= -2.6e+57: tmp = y * z elif z <= -1.0: tmp = t_0 elif z <= 1.15e-56: tmp = x elif (z <= 255000000.0) or not (z <= 2.9e+136): tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -3.9e+248) tmp = t_0; elseif (z <= -2.6e+57) tmp = Float64(y * z); elseif (z <= -1.0) tmp = t_0; elseif (z <= 1.15e-56) tmp = x; elseif ((z <= 255000000.0) || !(z <= 2.9e+136)) tmp = Float64(y * z); 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.9e+248) tmp = t_0; elseif (z <= -2.6e+57) tmp = y * z; elseif (z <= -1.0) tmp = t_0; elseif (z <= 1.15e-56) tmp = x; elseif ((z <= 255000000.0) || ~((z <= 2.9e+136))) tmp = y * z; 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.9e+248], t$95$0, If[LessEqual[z, -2.6e+57], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 1.15e-56], x, If[Or[LessEqual[z, 255000000.0], N[Not[LessEqual[z, 2.9e+136]], $MachinePrecision]], N[(y * z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -3.9 \cdot 10^{+248}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -2.6 \cdot 10^{+57}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-56}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 255000000 \lor \neg \left(z \leq 2.9 \cdot 10^{+136}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -3.8999999999999999e248 or -2.6e57 < z < -1 or 2.55e8 < z < 2.89999999999999974e136Initial program 100.0%
Taylor expanded in x around inf 67.2%
mul-1-neg67.2%
unsub-neg67.2%
Simplified67.2%
Taylor expanded in z around inf 66.1%
associate-*r*66.1%
mul-1-neg66.1%
Simplified66.1%
if -3.8999999999999999e248 < z < -2.6e57 or 1.15000000000000001e-56 < z < 2.55e8 or 2.89999999999999974e136 < z Initial program 100.0%
Taylor expanded in y around inf 67.3%
*-commutative67.3%
Simplified67.3%
Taylor expanded in x around 0 63.7%
*-commutative63.7%
Simplified63.7%
if -1 < z < 1.15000000000000001e-56Initial program 100.0%
Taylor expanded in z around 0 78.6%
Final simplification70.4%
(FPCore (x y z)
:precision binary64
(if (or (<= x -6.4e-13)
(not
(or (<= x -4.7e-140) (and (not (<= x -2.2e-214)) (<= x 1.85e-28)))))
(* x (- 1.0 z))
(* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.4e-13) || !((x <= -4.7e-140) || (!(x <= -2.2e-214) && (x <= 1.85e-28)))) {
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 <= (-6.4d-13)) .or. (.not. (x <= (-4.7d-140)) .or. (.not. (x <= (-2.2d-214))) .and. (x <= 1.85d-28))) 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 <= -6.4e-13) || !((x <= -4.7e-140) || (!(x <= -2.2e-214) && (x <= 1.85e-28)))) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.4e-13) or not ((x <= -4.7e-140) or (not (x <= -2.2e-214) and (x <= 1.85e-28))): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.4e-13) || !((x <= -4.7e-140) || (!(x <= -2.2e-214) && (x <= 1.85e-28)))) 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 <= -6.4e-13) || ~(((x <= -4.7e-140) || (~((x <= -2.2e-214)) && (x <= 1.85e-28))))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.4e-13], N[Not[Or[LessEqual[x, -4.7e-140], And[N[Not[LessEqual[x, -2.2e-214]], $MachinePrecision], LessEqual[x, 1.85e-28]]]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.4 \cdot 10^{-13} \lor \neg \left(x \leq -4.7 \cdot 10^{-140} \lor \neg \left(x \leq -2.2 \cdot 10^{-214}\right) \land x \leq 1.85 \cdot 10^{-28}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -6.39999999999999999e-13 or -4.70000000000000046e-140 < x < -2.20000000000000001e-214 or 1.8500000000000001e-28 < x Initial program 100.0%
Taylor expanded in x around inf 84.4%
mul-1-neg84.4%
unsub-neg84.4%
Simplified84.4%
if -6.39999999999999999e-13 < x < -4.70000000000000046e-140 or -2.20000000000000001e-214 < x < 1.8500000000000001e-28Initial program 100.0%
Taylor expanded in y around inf 90.2%
*-commutative90.2%
Simplified90.2%
Taylor expanded in x around 0 72.7%
*-commutative72.7%
Simplified72.7%
Final simplification79.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.06e+67) (not (<= x 7.2e+25))) (* x (- 1.0 z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.06e+67) || !(x <= 7.2e+25)) {
tmp = x * (1.0 - 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 ((x <= (-1.06d+67)) .or. (.not. (x <= 7.2d+25))) then
tmp = x * (1.0d0 - 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 ((x <= -1.06e+67) || !(x <= 7.2e+25)) {
tmp = x * (1.0 - z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.06e+67) or not (x <= 7.2e+25): tmp = x * (1.0 - z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.06e+67) || !(x <= 7.2e+25)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.06e+67) || ~((x <= 7.2e+25))) tmp = x * (1.0 - z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.06e+67], N[Not[LessEqual[x, 7.2e+25]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.06 \cdot 10^{+67} \lor \neg \left(x \leq 7.2 \cdot 10^{+25}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.0599999999999999e67 or 7.20000000000000031e25 < x Initial program 100.0%
Taylor expanded in x around inf 93.6%
mul-1-neg93.6%
unsub-neg93.6%
Simplified93.6%
if -1.0599999999999999e67 < x < 7.20000000000000031e25Initial program 100.0%
Taylor expanded in y around inf 83.7%
*-commutative83.7%
Simplified83.7%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (<= x -7e+66) (- x (* x z)) (if (<= x 7.2e+25) (+ x (* y z)) (* x (- 1.0 z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7e+66) {
tmp = x - (x * z);
} else if (x <= 7.2e+25) {
tmp = x + (y * 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 (x <= (-7d+66)) then
tmp = x - (x * z)
else if (x <= 7.2d+25) then
tmp = x + (y * 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 (x <= -7e+66) {
tmp = x - (x * z);
} else if (x <= 7.2e+25) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7e+66: tmp = x - (x * z) elif x <= 7.2e+25: tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7e+66) tmp = Float64(x - Float64(x * z)); elseif (x <= 7.2e+25) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7e+66) tmp = x - (x * z); elseif (x <= 7.2e+25) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7e+66], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 7.2e+25], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{+66}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{elif}\;x \leq 7.2 \cdot 10^{+25}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if x < -6.9999999999999994e66Initial program 100.0%
Taylor expanded in x around inf 93.1%
mul-1-neg93.1%
unsub-neg93.1%
Simplified93.1%
Taylor expanded in z around 0 93.1%
mul-1-neg93.1%
sub-neg93.1%
Simplified93.1%
if -6.9999999999999994e66 < x < 7.20000000000000031e25Initial program 100.0%
Taylor expanded in y around inf 83.7%
*-commutative83.7%
Simplified83.7%
if 7.20000000000000031e25 < x Initial program 100.0%
Taylor expanded in x around inf 94.2%
mul-1-neg94.2%
unsub-neg94.2%
Simplified94.2%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.2e-30) (not (<= z 1.5e-55))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.2e-30) || !(z <= 1.5e-55)) {
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 <= (-1.2d-30)) .or. (.not. (z <= 1.5d-55))) 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 <= -1.2e-30) || !(z <= 1.5e-55)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.2e-30) or not (z <= 1.5e-55): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.2e-30) || !(z <= 1.5e-55)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.2e-30) || ~((z <= 1.5e-55))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.2e-30], N[Not[LessEqual[z, 1.5e-55]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.2 \cdot 10^{-30} \lor \neg \left(z \leq 1.5 \cdot 10^{-55}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.19999999999999992e-30 or 1.50000000000000008e-55 < z Initial program 100.0%
Taylor expanded in y around inf 54.2%
*-commutative54.2%
Simplified54.2%
Taylor expanded in x around 0 50.9%
*-commutative50.9%
Simplified50.9%
if -1.19999999999999992e-30 < z < 1.50000000000000008e-55Initial program 100.0%
Taylor expanded in z around 0 80.4%
Final simplification62.4%
(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 34.9%
Final simplification34.9%
herbie shell --seed 2023332
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))