
(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 -2.1e+46)
t_0
(if (<= z -5e-73)
(* y z)
(if (<= z 1e-28)
x
(if (or (<= z 1.1e+32) (not (<= z 3.95e+58))) (* y z) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -2.1e+46) {
tmp = t_0;
} else if (z <= -5e-73) {
tmp = y * z;
} else if (z <= 1e-28) {
tmp = x;
} else if ((z <= 1.1e+32) || !(z <= 3.95e+58)) {
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 <= (-2.1d+46)) then
tmp = t_0
else if (z <= (-5d-73)) then
tmp = y * z
else if (z <= 1d-28) then
tmp = x
else if ((z <= 1.1d+32) .or. (.not. (z <= 3.95d+58))) 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 <= -2.1e+46) {
tmp = t_0;
} else if (z <= -5e-73) {
tmp = y * z;
} else if (z <= 1e-28) {
tmp = x;
} else if ((z <= 1.1e+32) || !(z <= 3.95e+58)) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -2.1e+46: tmp = t_0 elif z <= -5e-73: tmp = y * z elif z <= 1e-28: tmp = x elif (z <= 1.1e+32) or not (z <= 3.95e+58): 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 <= -2.1e+46) tmp = t_0; elseif (z <= -5e-73) tmp = Float64(y * z); elseif (z <= 1e-28) tmp = x; elseif ((z <= 1.1e+32) || !(z <= 3.95e+58)) 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 <= -2.1e+46) tmp = t_0; elseif (z <= -5e-73) tmp = y * z; elseif (z <= 1e-28) tmp = x; elseif ((z <= 1.1e+32) || ~((z <= 3.95e+58))) 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, -2.1e+46], t$95$0, If[LessEqual[z, -5e-73], N[(y * z), $MachinePrecision], If[LessEqual[z, 1e-28], x, If[Or[LessEqual[z, 1.1e+32], N[Not[LessEqual[z, 3.95e+58]], $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 -2.1 \cdot 10^{+46}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -5 \cdot 10^{-73}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 10^{-28}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.1 \cdot 10^{+32} \lor \neg \left(z \leq 3.95 \cdot 10^{+58}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -2.1e46 or 1.1e32 < z < 3.94999999999999994e58Initial program 99.9%
Taylor expanded in y around 0 66.3%
mul-1-neg66.3%
distribute-lft-neg-out66.3%
*-commutative66.3%
Simplified66.3%
Taylor expanded in z around inf 66.3%
associate-*r*66.3%
mul-1-neg66.3%
Simplified66.3%
if -2.1e46 < z < -4.9999999999999998e-73 or 9.99999999999999971e-29 < z < 1.1e32 or 3.94999999999999994e58 < z Initial program 100.0%
Taylor expanded in y around inf 73.9%
*-commutative73.9%
Simplified73.9%
Taylor expanded in x around 0 64.9%
if -4.9999999999999998e-73 < z < 9.99999999999999971e-29Initial program 100.0%
Taylor expanded in y around inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 77.9%
Final simplification70.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.55e+20) (not (<= x 1.45e+69))) (- x (* x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.55e+20) || !(x <= 1.45e+69)) {
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.55d+20)) .or. (.not. (x <= 1.45d+69))) 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.55e+20) || !(x <= 1.45e+69)) {
tmp = x - (x * z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.55e+20) or not (x <= 1.45e+69): tmp = x - (x * z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.55e+20) || !(x <= 1.45e+69)) 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.55e+20) || ~((x <= 1.45e+69))) tmp = x - (x * z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.55e+20], N[Not[LessEqual[x, 1.45e+69]], $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.55 \cdot 10^{+20} \lor \neg \left(x \leq 1.45 \cdot 10^{+69}\right):\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -2.55e20 or 1.4499999999999999e69 < 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.55e20 < x < 1.4499999999999999e69Initial program 100.0%
Taylor expanded in y around inf 92.0%
*-commutative92.0%
Simplified92.0%
Final simplification91.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.75e-74) (not (<= z 3.6e-30))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.75e-74) || !(z <= 3.6e-30)) {
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.75d-74)) .or. (.not. (z <= 3.6d-30))) 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.75e-74) || !(z <= 3.6e-30)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.75e-74) or not (z <= 3.6e-30): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.75e-74) || !(z <= 3.6e-30)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.75e-74) || ~((z <= 3.6e-30))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.75e-74], N[Not[LessEqual[z, 3.6e-30]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{-74} \lor \neg \left(z \leq 3.6 \cdot 10^{-30}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.75000000000000007e-74 or 3.6000000000000003e-30 < z Initial program 100.0%
Taylor expanded in y around inf 60.0%
*-commutative60.0%
Simplified60.0%
Taylor expanded in x around 0 53.9%
if -1.75000000000000007e-74 < z < 3.6000000000000003e-30Initial program 100.0%
Taylor expanded in y around inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 77.9%
Final simplification64.2%
(FPCore (x y z) :precision binary64 (if (<= x -4.2e+223) (* x (- z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.2e+223) {
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 (x <= (-4.2d+223)) 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 (x <= -4.2e+223) {
tmp = x * -z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.2e+223: tmp = x * -z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.2e+223) 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 (x <= -4.2e+223) tmp = x * -z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.2e+223], N[(x * (-z)), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{+223}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -4.19999999999999981e223Initial program 100.0%
Taylor expanded in y around 0 100.0%
mul-1-neg100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 76.9%
associate-*r*76.9%
mul-1-neg76.9%
Simplified76.9%
if -4.19999999999999981e223 < x Initial program 100.0%
Taylor expanded in y around inf 81.3%
*-commutative81.3%
Simplified81.3%
Final simplification81.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 77.2%
*-commutative77.2%
Simplified77.2%
Taylor expanded in x around inf 38.4%
Final simplification38.4%
herbie shell --seed 2023298
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))