
(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 5 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
(if (or (<= z -5.6e+20)
(and (not (<= z 3.9e+60))
(or (<= z 5.5e+137) (not (<= z 1.85e+213)))))
(* x (- z))
(+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.6e+20) || (!(z <= 3.9e+60) && ((z <= 5.5e+137) || !(z <= 1.85e+213)))) {
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 <= (-5.6d+20)) .or. (.not. (z <= 3.9d+60)) .and. (z <= 5.5d+137) .or. (.not. (z <= 1.85d+213))) 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 <= -5.6e+20) || (!(z <= 3.9e+60) && ((z <= 5.5e+137) || !(z <= 1.85e+213)))) {
tmp = x * -z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.6e+20) or (not (z <= 3.9e+60) and ((z <= 5.5e+137) or not (z <= 1.85e+213))): tmp = x * -z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.6e+20) || (!(z <= 3.9e+60) && ((z <= 5.5e+137) || !(z <= 1.85e+213)))) 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 <= -5.6e+20) || (~((z <= 3.9e+60)) && ((z <= 5.5e+137) || ~((z <= 1.85e+213))))) tmp = x * -z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.6e+20], And[N[Not[LessEqual[z, 3.9e+60]], $MachinePrecision], Or[LessEqual[z, 5.5e+137], N[Not[LessEqual[z, 1.85e+213]], $MachinePrecision]]]], N[(x * (-z)), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.6 \cdot 10^{+20} \lor \neg \left(z \leq 3.9 \cdot 10^{+60}\right) \land \left(z \leq 5.5 \cdot 10^{+137} \lor \neg \left(z \leq 1.85 \cdot 10^{+213}\right)\right):\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -5.6e20 or 3.9000000000000003e60 < z < 5.5000000000000002e137 or 1.84999999999999996e213 < z Initial program 100.0%
Taylor expanded in y around 0 67.8%
mul-1-neg67.8%
distribute-rgt-neg-out67.8%
Simplified67.8%
Taylor expanded in z around inf 67.8%
associate-*r*67.8%
mul-1-neg67.8%
Simplified67.8%
if -5.6e20 < z < 3.9000000000000003e60 or 5.5000000000000002e137 < z < 1.84999999999999996e213Initial program 100.0%
Taylor expanded in y around inf 93.6%
*-commutative93.6%
Simplified93.6%
Final simplification84.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.2e-30) (not (<= y 2.45e-8))) (+ x (* y z)) (- x (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.2e-30) || !(y <= 2.45e-8)) {
tmp = x + (y * z);
} else {
tmp = x - (x * 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 <= (-9.2d-30)) .or. (.not. (y <= 2.45d-8))) then
tmp = x + (y * z)
else
tmp = x - (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -9.2e-30) || !(y <= 2.45e-8)) {
tmp = x + (y * z);
} else {
tmp = x - (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.2e-30) or not (y <= 2.45e-8): tmp = x + (y * z) else: tmp = x - (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.2e-30) || !(y <= 2.45e-8)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9.2e-30) || ~((y <= 2.45e-8))) tmp = x + (y * z); else tmp = x - (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.2e-30], N[Not[LessEqual[y, 2.45e-8]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.2 \cdot 10^{-30} \lor \neg \left(y \leq 2.45 \cdot 10^{-8}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot z\\
\end{array}
\end{array}
if y < -9.19999999999999937e-30 or 2.4500000000000001e-8 < y Initial program 100.0%
Taylor expanded in y around inf 89.2%
*-commutative89.2%
Simplified89.2%
if -9.19999999999999937e-30 < y < 2.4500000000000001e-8Initial program 100.0%
Taylor expanded in y around 0 92.0%
mul-1-neg92.0%
distribute-rgt-neg-out92.0%
Simplified92.0%
distribute-rgt-neg-out92.0%
unsub-neg92.0%
*-commutative92.0%
Applied egg-rr92.0%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 300000.0))) (* x (- z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 300000.0)) {
tmp = 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 <= (-1.0d0)) .or. (.not. (z <= 300000.0d0))) then
tmp = 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 <= -1.0) || !(z <= 300000.0)) {
tmp = x * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 300000.0): tmp = x * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 300000.0)) tmp = Float64(x * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.0) || ~((z <= 300000.0))) tmp = x * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 300000.0]], $MachinePrecision]], N[(x * (-z)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 300000\right):\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1 or 3e5 < z Initial program 100.0%
Taylor expanded in y around 0 55.1%
mul-1-neg55.1%
distribute-rgt-neg-out55.1%
Simplified55.1%
Taylor expanded in z around inf 54.3%
associate-*r*54.3%
mul-1-neg54.3%
Simplified54.3%
if -1 < z < 3e5Initial program 100.0%
Taylor expanded in y around 0 70.0%
mul-1-neg70.0%
distribute-rgt-neg-out70.0%
Simplified70.0%
Taylor expanded in z around 0 69.6%
Final simplification62.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 0 62.6%
mul-1-neg62.6%
distribute-rgt-neg-out62.6%
Simplified62.6%
Taylor expanded in z around 0 36.5%
Final simplification36.5%
herbie shell --seed 2023195
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))