
(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 6 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 (+ 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
(let* ((t_0 (* x (- z))))
(if (<= z -1.5e+246)
t_0
(if (<= z -3e-22)
(* y z)
(if (<= z 5.5e-6) x (if (<= z 5e+146) (* y z) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -1.5e+246) {
tmp = t_0;
} else if (z <= -3e-22) {
tmp = y * z;
} else if (z <= 5.5e-6) {
tmp = x;
} else if (z <= 5e+146) {
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 <= (-1.5d+246)) then
tmp = t_0
else if (z <= (-3d-22)) then
tmp = y * z
else if (z <= 5.5d-6) then
tmp = x
else if (z <= 5d+146) 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 <= -1.5e+246) {
tmp = t_0;
} else if (z <= -3e-22) {
tmp = y * z;
} else if (z <= 5.5e-6) {
tmp = x;
} else if (z <= 5e+146) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -1.5e+246: tmp = t_0 elif z <= -3e-22: tmp = y * z elif z <= 5.5e-6: tmp = x elif z <= 5e+146: 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 <= -1.5e+246) tmp = t_0; elseif (z <= -3e-22) tmp = Float64(y * z); elseif (z <= 5.5e-6) tmp = x; elseif (z <= 5e+146) 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 <= -1.5e+246) tmp = t_0; elseif (z <= -3e-22) tmp = y * z; elseif (z <= 5.5e-6) tmp = x; elseif (z <= 5e+146) 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, -1.5e+246], t$95$0, If[LessEqual[z, -3e-22], N[(y * z), $MachinePrecision], If[LessEqual[z, 5.5e-6], x, If[LessEqual[z, 5e+146], N[(y * z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -1.5 \cdot 10^{+246}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -3 \cdot 10^{-22}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{-6}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5 \cdot 10^{+146}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.5e246 or 4.9999999999999999e146 < z Initial program 100.0%
Taylor expanded in y around 0 71.9%
mul-1-neg71.9%
distribute-lft-neg-out71.9%
*-commutative71.9%
Simplified71.9%
Taylor expanded in z around inf 71.9%
associate-*r*71.9%
mul-1-neg71.9%
Simplified71.9%
if -1.5e246 < z < -2.9999999999999999e-22 or 5.4999999999999999e-6 < z < 4.9999999999999999e146Initial program 100.0%
Taylor expanded in y around inf 59.9%
*-commutative59.9%
Simplified59.9%
Taylor expanded in x around 0 59.0%
if -2.9999999999999999e-22 < z < 5.4999999999999999e-6Initial program 100.0%
Taylor expanded in y around inf 99.3%
*-commutative99.3%
Simplified99.3%
Taylor expanded in x around inf 80.6%
Final simplification71.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.02e+247) (not (<= z 1.2e+146))) (* x (- z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.02e+247) || !(z <= 1.2e+146)) {
tmp = 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.02d+247)) .or. (.not. (z <= 1.2d+146))) then
tmp = 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.02e+247) || !(z <= 1.2e+146)) {
tmp = x * -z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.02e+247) or not (z <= 1.2e+146): tmp = x * -z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.02e+247) || !(z <= 1.2e+146)) tmp = Float64(x * Float64(-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.02e+247) || ~((z <= 1.2e+146))) tmp = x * -z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.02e+247], N[Not[LessEqual[z, 1.2e+146]], $MachinePrecision]], N[(x * (-z)), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.02 \cdot 10^{+247} \lor \neg \left(z \leq 1.2 \cdot 10^{+146}\right):\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1.02e247 or 1.2000000000000001e146 < z Initial program 100.0%
Taylor expanded in y around 0 71.9%
mul-1-neg71.9%
distribute-lft-neg-out71.9%
*-commutative71.9%
Simplified71.9%
Taylor expanded in z around inf 71.9%
associate-*r*71.9%
mul-1-neg71.9%
Simplified71.9%
if -1.02e247 < z < 1.2000000000000001e146Initial program 100.0%
Taylor expanded in y around inf 82.0%
*-commutative82.0%
Simplified82.0%
Final simplification80.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.7e-15) (not (<= x 2.1e+54))) (- x (* x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.7e-15) || !(x <= 2.1e+54)) {
tmp = x - (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 ((x <= (-2.7d-15)) .or. (.not. (x <= 2.1d+54))) then
tmp = x - (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 ((x <= -2.7e-15) || !(x <= 2.1e+54)) {
tmp = x - (x * z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.7e-15) or not (x <= 2.1e+54): tmp = x - (x * z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.7e-15) || !(x <= 2.1e+54)) tmp = Float64(x - Float64(x * z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.7e-15) || ~((x <= 2.1e+54))) tmp = x - (x * z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.7e-15], N[Not[LessEqual[x, 2.1e+54]], $MachinePrecision]], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-15} \lor \neg \left(x \leq 2.1 \cdot 10^{+54}\right):\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -2.70000000000000009e-15 or 2.09999999999999986e54 < x Initial program 100.0%
Taylor expanded in y around 0 91.0%
mul-1-neg91.0%
distribute-lft-neg-out91.0%
*-commutative91.0%
Simplified91.0%
distribute-rgt-neg-out91.0%
unsub-neg91.0%
*-commutative91.0%
Applied egg-rr91.0%
if -2.70000000000000009e-15 < x < 2.09999999999999986e54Initial program 100.0%
Taylor expanded in y around inf 85.6%
*-commutative85.6%
Simplified85.6%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -2e-20) (not (<= z 5.5e-6))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2e-20) || !(z <= 5.5e-6)) {
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 <= (-2d-20)) .or. (.not. (z <= 5.5d-6))) 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 <= -2e-20) || !(z <= 5.5e-6)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2e-20) or not (z <= 5.5e-6): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2e-20) || !(z <= 5.5e-6)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2e-20) || ~((z <= 5.5e-6))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2e-20], N[Not[LessEqual[z, 5.5e-6]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{-20} \lor \neg \left(z \leq 5.5 \cdot 10^{-6}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.99999999999999989e-20 or 5.4999999999999999e-6 < z Initial program 100.0%
Taylor expanded in y around inf 52.1%
*-commutative52.1%
Simplified52.1%
Taylor expanded in x around 0 51.6%
if -1.99999999999999989e-20 < z < 5.4999999999999999e-6Initial program 100.0%
Taylor expanded in y around inf 99.3%
*-commutative99.3%
Simplified99.3%
Taylor expanded in x around inf 80.6%
Final simplification65.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 y around inf 73.8%
*-commutative73.8%
Simplified73.8%
Taylor expanded in x around inf 38.8%
Final simplification38.8%
herbie shell --seed 2024076
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))