
(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-define100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -1.0)
t_0
(if (<= z 1.25e-90) x (if (<= z 1.95e+118) (* y z) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 1.25e-90) {
tmp = x;
} else if (z <= 1.95e+118) {
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 <= (-1.0d0)) then
tmp = t_0
else if (z <= 1.25d-90) then
tmp = x
else if (z <= 1.95d+118) 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 <= -1.0) {
tmp = t_0;
} else if (z <= 1.25e-90) {
tmp = x;
} else if (z <= 1.95e+118) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -1.0: tmp = t_0 elif z <= 1.25e-90: tmp = x elif z <= 1.95e+118: 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 <= -1.0) tmp = t_0; elseif (z <= 1.25e-90) tmp = x; elseif (z <= 1.95e+118) 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 <= -1.0) tmp = t_0; elseif (z <= 1.25e-90) tmp = x; elseif (z <= 1.95e+118) 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, -1.0], t$95$0, If[LessEqual[z, 1.25e-90], x, If[LessEqual[z, 1.95e+118], N[(y * z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.25 \cdot 10^{-90}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.95 \cdot 10^{+118}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1 or 1.95e118 < z Initial program 100.0%
Taylor expanded in x around inf 59.5%
mul-1-neg59.5%
unsub-neg59.5%
Simplified59.5%
Taylor expanded in z around inf 58.7%
neg-mul-158.7%
*-commutative58.7%
Simplified58.7%
if -1 < z < 1.25000000000000005e-90Initial program 100.0%
Taylor expanded in z around 0 79.5%
if 1.25000000000000005e-90 < z < 1.95e118Initial program 100.0%
Taylor expanded in x around 0 100.0%
fma-define100.0%
+-commutative100.0%
mul-1-neg100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 61.2%
Final simplification68.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.96e-17))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.96e-17)) {
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 <= 1.96d-17))) 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 <= 1.96e-17)) {
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 <= 1.96e-17): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.96e-17)) 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 <= 1.96e-17))) 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, 1.96e-17]], $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 1.96 \cdot 10^{-17}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1 or 1.96e-17 < z Initial program 100.0%
Taylor expanded in x around 0 95.5%
fma-define97.8%
+-commutative97.8%
mul-1-neg97.8%
*-commutative97.8%
Simplified97.8%
Taylor expanded in z around inf 99.0%
mul-1-neg99.0%
unsub-neg99.0%
Simplified99.0%
if -1 < z < 1.96e-17Initial program 100.0%
Taylor expanded in y around inf 98.8%
*-commutative98.8%
Simplified98.8%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.3e+15) (not (<= z 5.5e-20))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.3e+15) || !(z <= 5.5e-20)) {
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.3d+15)) .or. (.not. (z <= 5.5d-20))) 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.3e+15) || !(z <= 5.5e-20)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.3e+15) or not (z <= 5.5e-20): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.3e+15) || !(z <= 5.5e-20)) 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.3e+15) || ~((z <= 5.5e-20))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.3e+15], N[Not[LessEqual[z, 5.5e-20]], $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.3 \cdot 10^{+15} \lor \neg \left(z \leq 5.5 \cdot 10^{-20}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -4.3e15 or 5.4999999999999996e-20 < z Initial program 100.0%
Taylor expanded in x around 0 95.4%
fma-define97.7%
+-commutative97.7%
mul-1-neg97.7%
*-commutative97.7%
Simplified97.7%
Taylor expanded in z around inf 99.7%
mul-1-neg99.7%
unsub-neg99.7%
Simplified99.7%
if -4.3e15 < z < 5.4999999999999996e-20Initial program 100.0%
Taylor expanded in x around inf 78.3%
mul-1-neg78.3%
unsub-neg78.3%
Simplified78.3%
Final simplification89.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.9e+117) (not (<= y 1.9e+70))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.9e+117) || !(y <= 1.9e+70)) {
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.9d+117)) .or. (.not. (y <= 1.9d+70))) 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.9e+117) || !(y <= 1.9e+70)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.9e+117) or not (y <= 1.9e+70): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.9e+117) || !(y <= 1.9e+70)) 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.9e+117) || ~((y <= 1.9e+70))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.9e+117], N[Not[LessEqual[y, 1.9e+70]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.9 \cdot 10^{+117} \lor \neg \left(y \leq 1.9 \cdot 10^{+70}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -3.8999999999999999e117 or 1.8999999999999999e70 < y Initial program 99.9%
Taylor expanded in x around 0 93.5%
fma-define97.4%
+-commutative97.4%
mul-1-neg97.4%
*-commutative97.4%
Simplified97.4%
Taylor expanded in x around 0 73.6%
if -3.8999999999999999e117 < y < 1.8999999999999999e70Initial program 100.0%
Taylor expanded in x around inf 81.0%
mul-1-neg81.0%
unsub-neg81.0%
Simplified81.0%
Final simplification78.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -8e-11) (not (<= z 9e-91))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8e-11) || !(z <= 9e-91)) {
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 <= (-8d-11)) .or. (.not. (z <= 9d-91))) 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 <= -8e-11) || !(z <= 9e-91)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8e-11) or not (z <= 9e-91): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8e-11) || !(z <= 9e-91)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8e-11) || ~((z <= 9e-91))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8e-11], N[Not[LessEqual[z, 9e-91]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{-11} \lor \neg \left(z \leq 9 \cdot 10^{-91}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.99999999999999952e-11 or 8.99999999999999952e-91 < z Initial program 100.0%
Taylor expanded in x around 0 95.9%
fma-define98.0%
+-commutative98.0%
mul-1-neg98.0%
*-commutative98.0%
Simplified98.0%
Taylor expanded in x around 0 49.7%
if -7.99999999999999952e-11 < z < 8.99999999999999952e-91Initial program 100.0%
Taylor expanded in z around 0 80.5%
Final simplification62.8%
(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 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.2%
herbie shell --seed 2024133
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))