
(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 -1.75e+238)
(* y z)
(if (<= z -1.0)
t_0
(if (<= z 3.45e-15)
x
(if (<= z 1e+147) (* y z) (if (<= z 2.6e+177) t_0 (* y z))))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -1.75e+238) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = t_0;
} else if (z <= 3.45e-15) {
tmp = x;
} else if (z <= 1e+147) {
tmp = y * z;
} else if (z <= 2.6e+177) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * -z
if (z <= (-1.75d+238)) then
tmp = y * z
else if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 3.45d-15) then
tmp = x
else if (z <= 1d+147) then
tmp = y * z
else if (z <= 2.6d+177) then
tmp = t_0
else
tmp = y * z
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.75e+238) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = t_0;
} else if (z <= 3.45e-15) {
tmp = x;
} else if (z <= 1e+147) {
tmp = y * z;
} else if (z <= 2.6e+177) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -1.75e+238: tmp = y * z elif z <= -1.0: tmp = t_0 elif z <= 3.45e-15: tmp = x elif z <= 1e+147: tmp = y * z elif z <= 2.6e+177: tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -1.75e+238) tmp = Float64(y * z); elseif (z <= -1.0) tmp = t_0; elseif (z <= 3.45e-15) tmp = x; elseif (z <= 1e+147) tmp = Float64(y * z); elseif (z <= 2.6e+177) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -1.75e+238) tmp = y * z; elseif (z <= -1.0) tmp = t_0; elseif (z <= 3.45e-15) tmp = x; elseif (z <= 1e+147) tmp = y * z; elseif (z <= 2.6e+177) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -1.75e+238], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 3.45e-15], x, If[LessEqual[z, 1e+147], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.6e+177], t$95$0, N[(y * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -1.75 \cdot 10^{+238}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 3.45 \cdot 10^{-15}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 10^{+147}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.6 \cdot 10^{+177}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.75000000000000001e238 or 3.45000000000000005e-15 < z < 9.9999999999999998e146 or 2.59999999999999979e177 < z Initial program 100.0%
Taylor expanded in z around inf 98.6%
Taylor expanded in y around inf 64.2%
*-commutative64.2%
Simplified64.2%
if -1.75000000000000001e238 < z < -1 or 9.9999999999999998e146 < z < 2.59999999999999979e177Initial program 100.0%
Taylor expanded in x around inf 69.9%
distribute-rgt1-in69.9%
mul-1-neg69.9%
cancel-sign-sub-inv69.9%
Simplified69.9%
Taylor expanded in z around inf 68.4%
associate-*r*68.4%
mul-1-neg68.4%
Simplified68.4%
if -1 < z < 3.45000000000000005e-15Initial program 100.0%
Taylor expanded in z around 0 75.4%
Final simplification69.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.6e-81) (not (<= z 4e-8))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.6e-81) || !(z <= 4e-8)) {
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 <= (-4.6d-81)) .or. (.not. (z <= 4d-8))) 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 <= -4.6e-81) || !(z <= 4e-8)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.6e-81) or not (z <= 4e-8): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.6e-81) || !(z <= 4e-8)) 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 <= -4.6e-81) || ~((z <= 4e-8))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.6e-81], N[Not[LessEqual[z, 4e-8]], $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 -4.6 \cdot 10^{-81} \lor \neg \left(z \leq 4 \cdot 10^{-8}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -4.59999999999999982e-81 or 4.0000000000000001e-8 < z Initial program 100.0%
Taylor expanded in z around inf 94.0%
if -4.59999999999999982e-81 < z < 4.0000000000000001e-8Initial program 100.0%
Taylor expanded in x around inf 81.4%
distribute-rgt1-in81.4%
mul-1-neg81.4%
cancel-sign-sub-inv81.4%
Simplified81.4%
Taylor expanded in x around 0 81.4%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 4.8e-5))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 4.8e-5)) {
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 <= (-1.0d0)) .or. (.not. (z <= 4.8d-5))) 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 <= -1.0) || !(z <= 4.8e-5)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 4.8e-5): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 4.8e-5)) 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 <= -1.0) || ~((z <= 4.8e-5))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 4.8e-5]], $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 -1 \lor \neg \left(z \leq 4.8 \cdot 10^{-5}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1 or 4.8000000000000001e-5 < z Initial program 100.0%
Taylor expanded in z around inf 99.2%
if -1 < z < 4.8000000000000001e-5Initial program 100.0%
Taylor expanded in y around inf 99.4%
*-commutative27.9%
Simplified99.4%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (<= y -1.05e+123) (* y z) (if (<= y 5.2e+25) (* x (- 1.0 z)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.05e+123) {
tmp = y * z;
} else if (y <= 5.2e+25) {
tmp = x * (1.0 - 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 (y <= (-1.05d+123)) then
tmp = y * z
else if (y <= 5.2d+25) then
tmp = x * (1.0d0 - z)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.05e+123) {
tmp = y * z;
} else if (y <= 5.2e+25) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.05e+123: tmp = y * z elif y <= 5.2e+25: tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.05e+123) tmp = Float64(y * z); elseif (y <= 5.2e+25) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.05e+123) tmp = y * z; elseif (y <= 5.2e+25) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.05e+123], N[(y * z), $MachinePrecision], If[LessEqual[y, 5.2e+25], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{+123}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+25}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.04999999999999997e123 or 5.1999999999999997e25 < y Initial program 100.0%
Taylor expanded in z around inf 87.5%
Taylor expanded in y around inf 78.9%
*-commutative78.9%
Simplified78.9%
if -1.04999999999999997e123 < y < 5.1999999999999997e25Initial program 100.0%
Taylor expanded in x around inf 78.6%
distribute-rgt1-in78.6%
mul-1-neg78.6%
cancel-sign-sub-inv78.6%
Simplified78.6%
Taylor expanded in x around 0 78.6%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (<= z -7.6e-62) (* y z) (if (<= z 3.9e-12) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.6e-62) {
tmp = y * z;
} else if (z <= 3.9e-12) {
tmp = x;
} 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.6d-62)) then
tmp = y * z
else if (z <= 3.9d-12) then
tmp = x
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.6e-62) {
tmp = y * z;
} else if (z <= 3.9e-12) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.6e-62: tmp = y * z elif z <= 3.9e-12: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.6e-62) tmp = Float64(y * z); elseif (z <= 3.9e-12) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7.6e-62) tmp = y * z; elseif (z <= 3.9e-12) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.6e-62], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.9e-12], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.6 \cdot 10^{-62}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.9 \cdot 10^{-12}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -7.60000000000000013e-62 or 3.89999999999999994e-12 < z Initial program 100.0%
Taylor expanded in z around inf 95.0%
Taylor expanded in y around inf 53.0%
*-commutative53.0%
Simplified53.0%
if -7.60000000000000013e-62 < z < 3.89999999999999994e-12Initial program 100.0%
Taylor expanded in z around 0 80.0%
Final simplification63.2%
(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 34.8%
Final simplification34.8%
herbie shell --seed 2023221
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))