
(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%
(FPCore (x y z) :precision binary64 (if (<= z -7.5e-33) (* y z) (if (<= z 1.0) x (if (<= z 1.15e+114) (* x (- z)) (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.5e-33) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else if (z <= 1.15e+114) {
tmp = x * -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 (z <= (-7.5d-33)) then
tmp = y * z
else if (z <= 1.0d0) then
tmp = x
else if (z <= 1.15d+114) then
tmp = x * -z
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -7.5e-33) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else if (z <= 1.15e+114) {
tmp = x * -z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.5e-33: tmp = y * z elif z <= 1.0: tmp = x elif z <= 1.15e+114: tmp = x * -z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.5e-33) tmp = Float64(y * z); elseif (z <= 1.0) tmp = x; elseif (z <= 1.15e+114) tmp = Float64(x * Float64(-z)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7.5e-33) tmp = y * z; elseif (z <= 1.0) tmp = x; elseif (z <= 1.15e+114) tmp = x * -z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.5e-33], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.0], x, If[LessEqual[z, 1.15e+114], N[(x * (-z)), $MachinePrecision], N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.5 \cdot 10^{-33}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+114}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -7.5000000000000001e-33 or 1.15e114 < z Initial program 100.0%
Taylor expanded in y around inf 65.5%
*-commutative65.5%
Simplified65.5%
Taylor expanded in x around 0 63.3%
*-commutative63.3%
Simplified63.3%
if -7.5000000000000001e-33 < z < 1Initial program 100.0%
Taylor expanded in z around 0 77.5%
if 1 < z < 1.15e114Initial program 100.0%
Taylor expanded in x around inf 72.1%
mul-1-neg72.1%
unsub-neg72.1%
Simplified72.1%
Taylor expanded in z around inf 64.5%
mul-1-neg64.5%
*-commutative64.5%
distribute-rgt-neg-in64.5%
Simplified64.5%
Final simplification70.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.5e-78) (not (<= y 8.2e-66))) (+ x (* y z)) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.5e-78) || !(y <= 8.2e-66)) {
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 ((y <= (-6.5d-78)) .or. (.not. (y <= 8.2d-66))) 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 ((y <= -6.5e-78) || !(y <= 8.2e-66)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.5e-78) or not (y <= 8.2e-66): tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.5e-78) || !(y <= 8.2e-66)) 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 ((y <= -6.5e-78) || ~((y <= 8.2e-66))) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.5e-78], N[Not[LessEqual[y, 8.2e-66]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-78} \lor \neg \left(y \leq 8.2 \cdot 10^{-66}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -6.5000000000000003e-78 or 8.19999999999999996e-66 < y Initial program 100.0%
Taylor expanded in y around inf 92.4%
*-commutative92.4%
Simplified92.4%
if -6.5000000000000003e-78 < y < 8.19999999999999996e-66Initial program 100.0%
Taylor expanded in x around inf 87.1%
mul-1-neg87.1%
unsub-neg87.1%
Simplified87.1%
Final simplification90.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.08e+161) (not (<= y 1.5e-46))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.08e+161) || !(y <= 1.5e-46)) {
tmp = 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 ((y <= (-1.08d+161)) .or. (.not. (y <= 1.5d-46))) then
tmp = 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 ((y <= -1.08e+161) || !(y <= 1.5e-46)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.08e+161) or not (y <= 1.5e-46): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.08e+161) || !(y <= 1.5e-46)) tmp = 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 ((y <= -1.08e+161) || ~((y <= 1.5e-46))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.08e+161], N[Not[LessEqual[y, 1.5e-46]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.08 \cdot 10^{+161} \lor \neg \left(y \leq 1.5 \cdot 10^{-46}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -1.08e161 or 1.49999999999999994e-46 < y Initial program 100.0%
Taylor expanded in y around inf 95.9%
*-commutative95.9%
Simplified95.9%
Taylor expanded in x around 0 77.6%
*-commutative77.6%
Simplified77.6%
if -1.08e161 < y < 1.49999999999999994e-46Initial program 100.0%
Taylor expanded in x around inf 80.4%
mul-1-neg80.4%
unsub-neg80.4%
Simplified80.4%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.2e-37) (not (<= z 6.8e-18))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.2e-37) || !(z <= 6.8e-18)) {
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 <= (-5.2d-37)) .or. (.not. (z <= 6.8d-18))) 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 <= -5.2e-37) || !(z <= 6.8e-18)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.2e-37) or not (z <= 6.8e-18): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.2e-37) || !(z <= 6.8e-18)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.2e-37) || ~((z <= 6.8e-18))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.2e-37], N[Not[LessEqual[z, 6.8e-18]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{-37} \lor \neg \left(z \leq 6.8 \cdot 10^{-18}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.19999999999999959e-37 or 6.80000000000000002e-18 < z Initial program 100.0%
Taylor expanded in y around inf 60.2%
*-commutative60.2%
Simplified60.2%
Taylor expanded in x around 0 58.5%
*-commutative58.5%
Simplified58.5%
if -5.19999999999999959e-37 < z < 6.80000000000000002e-18Initial program 100.0%
Taylor expanded in z around 0 78.1%
Final simplification67.6%
(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 38.4%
herbie shell --seed 2024101
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))