
(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 -2.8e+256)
(* y z)
(if (<= z -2.3e+213)
t_0
(if (<= z -7.5e+46)
(* y z)
(if (or (<= z -920.0) (not (<= z 0.0068))) t_0 x))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -2.8e+256) {
tmp = y * z;
} else if (z <= -2.3e+213) {
tmp = t_0;
} else if (z <= -7.5e+46) {
tmp = y * z;
} else if ((z <= -920.0) || !(z <= 0.0068)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * -z
if (z <= (-2.8d+256)) then
tmp = y * z
else if (z <= (-2.3d+213)) then
tmp = t_0
else if (z <= (-7.5d+46)) then
tmp = y * z
else if ((z <= (-920.0d0)) .or. (.not. (z <= 0.0068d0))) then
tmp = t_0
else
tmp = x
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.8e+256) {
tmp = y * z;
} else if (z <= -2.3e+213) {
tmp = t_0;
} else if (z <= -7.5e+46) {
tmp = y * z;
} else if ((z <= -920.0) || !(z <= 0.0068)) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -2.8e+256: tmp = y * z elif z <= -2.3e+213: tmp = t_0 elif z <= -7.5e+46: tmp = y * z elif (z <= -920.0) or not (z <= 0.0068): tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -2.8e+256) tmp = Float64(y * z); elseif (z <= -2.3e+213) tmp = t_0; elseif (z <= -7.5e+46) tmp = Float64(y * z); elseif ((z <= -920.0) || !(z <= 0.0068)) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -2.8e+256) tmp = y * z; elseif (z <= -2.3e+213) tmp = t_0; elseif (z <= -7.5e+46) tmp = y * z; elseif ((z <= -920.0) || ~((z <= 0.0068))) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -2.8e+256], N[(y * z), $MachinePrecision], If[LessEqual[z, -2.3e+213], t$95$0, If[LessEqual[z, -7.5e+46], N[(y * z), $MachinePrecision], If[Or[LessEqual[z, -920.0], N[Not[LessEqual[z, 0.0068]], $MachinePrecision]], t$95$0, x]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -2.8 \cdot 10^{+256}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -2.3 \cdot 10^{+213}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -7.5 \cdot 10^{+46}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -920 \lor \neg \left(z \leq 0.0068\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.79999999999999988e256 or -2.29999999999999998e213 < z < -7.5000000000000003e46Initial program 100.0%
Taylor expanded in x around 0 73.4%
if -2.79999999999999988e256 < z < -2.29999999999999998e213 or -7.5000000000000003e46 < z < -920 or 0.00679999999999999962 < z Initial program 99.9%
*-commutative99.9%
sub-neg99.9%
distribute-lft-in98.7%
Applied egg-rr98.7%
Taylor expanded in y around 0 61.0%
associate-*r*61.0%
mul-1-neg61.0%
Simplified61.0%
Taylor expanded in z around inf 59.8%
mul-1-neg59.8%
*-commutative59.8%
distribute-rgt-neg-in59.8%
Simplified59.8%
if -920 < z < 0.00679999999999999962Initial program 100.0%
Taylor expanded in z around 0 70.8%
Final simplification67.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.6e+50) (not (<= y 3.4e+167))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.6e+50) || !(y <= 3.4e+167)) {
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 <= (-3.6d+50)) .or. (.not. (y <= 3.4d+167))) 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 <= -3.6e+50) || !(y <= 3.4e+167)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.6e+50) or not (y <= 3.4e+167): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.6e+50) || !(y <= 3.4e+167)) 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 <= -3.6e+50) || ~((y <= 3.4e+167))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.6e+50], N[Not[LessEqual[y, 3.4e+167]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{+50} \lor \neg \left(y \leq 3.4 \cdot 10^{+167}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -3.59999999999999986e50 or 3.4e167 < y Initial program 100.0%
Taylor expanded in x around 0 75.9%
if -3.59999999999999986e50 < y < 3.4e167Initial program 100.0%
Taylor expanded in x around inf 80.0%
mul-1-neg80.0%
unsub-neg80.0%
Simplified80.0%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.08) (not (<= z 0.00034))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.08) || !(z <= 0.00034)) {
tmp = (y - x) * 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 ((z <= (-0.08d0)) .or. (.not. (z <= 0.00034d0))) then
tmp = (y - x) * 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 ((z <= -0.08) || !(z <= 0.00034)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.08) or not (z <= 0.00034): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.08) || !(z <= 0.00034)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -0.08) || ~((z <= 0.00034))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.08], N[Not[LessEqual[z, 0.00034]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.08 \lor \neg \left(z \leq 0.00034\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -0.0800000000000000017 or 3.4e-4 < z Initial program 100.0%
Taylor expanded in z around inf 99.0%
if -0.0800000000000000017 < z < 3.4e-4Initial program 100.0%
Taylor expanded in x around inf 72.6%
mul-1-neg72.6%
unsub-neg72.6%
Simplified72.6%
Final simplification84.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -2700000.0) (not (<= z 0.0068))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2700000.0) || !(z <= 0.0068)) {
tmp = (y - 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 <= (-2700000.0d0)) .or. (.not. (z <= 0.0068d0))) then
tmp = (y - 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 <= -2700000.0) || !(z <= 0.0068)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2700000.0) or not (z <= 0.0068): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2700000.0) || !(z <= 0.0068)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2700000.0) || ~((z <= 0.0068))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2700000.0], N[Not[LessEqual[z, 0.0068]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2700000 \lor \neg \left(z \leq 0.0068\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -2.7e6 or 0.00679999999999999962 < z Initial program 100.0%
Taylor expanded in z around inf 99.0%
if -2.7e6 < z < 0.00679999999999999962Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 99.2%
*-commutative99.2%
Simplified99.2%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.08) (not (<= z 2.4e-9))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.08) || !(z <= 2.4e-9)) {
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 <= (-0.08d0)) .or. (.not. (z <= 2.4d-9))) 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 <= -0.08) || !(z <= 2.4e-9)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.08) or not (z <= 2.4e-9): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.08) || !(z <= 2.4e-9)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -0.08) || ~((z <= 2.4e-9))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.08], N[Not[LessEqual[z, 2.4e-9]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.08 \lor \neg \left(z \leq 2.4 \cdot 10^{-9}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -0.0800000000000000017 or 2.4e-9 < z Initial program 100.0%
Taylor expanded in x around 0 50.6%
if -0.0800000000000000017 < z < 2.4e-9Initial program 100.0%
Taylor expanded in z around 0 71.8%
Final simplification62.1%
(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 40.4%
Final simplification40.4%
herbie shell --seed 2024026
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))