
(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 -4e+149)
(* y z)
(if (<= z -1.0)
t_0
(if (<= z 0.032)
x
(if (<= z 1.5e+126) (* y z) (if (<= z 1.1e+144) t_0 (* y z))))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -4e+149) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = t_0;
} else if (z <= 0.032) {
tmp = x;
} else if (z <= 1.5e+126) {
tmp = y * z;
} else if (z <= 1.1e+144) {
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 <= (-4d+149)) then
tmp = y * z
else if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 0.032d0) then
tmp = x
else if (z <= 1.5d+126) then
tmp = y * z
else if (z <= 1.1d+144) 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 <= -4e+149) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = t_0;
} else if (z <= 0.032) {
tmp = x;
} else if (z <= 1.5e+126) {
tmp = y * z;
} else if (z <= 1.1e+144) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -4e+149: tmp = y * z elif z <= -1.0: tmp = t_0 elif z <= 0.032: tmp = x elif z <= 1.5e+126: tmp = y * z elif z <= 1.1e+144: 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 <= -4e+149) tmp = Float64(y * z); elseif (z <= -1.0) tmp = t_0; elseif (z <= 0.032) tmp = x; elseif (z <= 1.5e+126) tmp = Float64(y * z); elseif (z <= 1.1e+144) 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 <= -4e+149) tmp = y * z; elseif (z <= -1.0) tmp = t_0; elseif (z <= 0.032) tmp = x; elseif (z <= 1.5e+126) tmp = y * z; elseif (z <= 1.1e+144) 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, -4e+149], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 0.032], x, If[LessEqual[z, 1.5e+126], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.1e+144], t$95$0, N[(y * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -4 \cdot 10^{+149}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 0.032:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+126}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.1 \cdot 10^{+144}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -4.0000000000000002e149 or 0.032000000000000001 < z < 1.5000000000000001e126 or 1.09999999999999994e144 < z Initial program 100.0%
Taylor expanded in z around inf 98.3%
Taylor expanded in y around inf 67.3%
*-commutative67.3%
Simplified67.3%
if -4.0000000000000002e149 < z < -1 or 1.5000000000000001e126 < z < 1.09999999999999994e144Initial program 100.0%
Taylor expanded in z around inf 95.0%
Taylor expanded in y around 0 69.2%
mul-1-neg69.2%
distribute-rgt-neg-out69.2%
Simplified69.2%
if -1 < z < 0.032000000000000001Initial program 100.0%
Taylor expanded in z around 0 71.1%
Final simplification69.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.6e-24) (not (<= z 54000000000.0))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.6e-24) || !(z <= 54000000000.0)) {
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 <= (-2.6d-24)) .or. (.not. (z <= 54000000000.0d0))) 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 <= -2.6e-24) || !(z <= 54000000000.0)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.6e-24) or not (z <= 54000000000.0): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.6e-24) || !(z <= 54000000000.0)) 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 <= -2.6e-24) || ~((z <= 54000000000.0))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.6e-24], N[Not[LessEqual[z, 54000000000.0]], $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 -2.6 \cdot 10^{-24} \lor \neg \left(z \leq 54000000000\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -2.6e-24 or 5.4e10 < z Initial program 100.0%
Taylor expanded in z around inf 98.4%
if -2.6e-24 < z < 5.4e10Initial program 100.0%
Taylor expanded in x around inf 73.2%
distribute-rgt1-in73.1%
mul-1-neg73.1%
cancel-sign-sub-inv73.1%
Simplified73.1%
Taylor expanded in x around 0 73.2%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
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.0d0))) 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.0)) {
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.0): 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.0)) 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.0))) 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.0]], $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\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 97.3%
if -1 < z < 1Initial program 100.0%
Taylor expanded in y around inf 99.2%
*-commutative29.9%
Simplified99.2%
Final simplification98.2%
(FPCore (x y z) :precision binary64 (if (<= y -6.4e+33) (* y z) (if (<= y 1.55e+46) (* x (- 1.0 z)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.4e+33) {
tmp = y * z;
} else if (y <= 1.55e+46) {
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 <= (-6.4d+33)) then
tmp = y * z
else if (y <= 1.55d+46) 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 <= -6.4e+33) {
tmp = y * z;
} else if (y <= 1.55e+46) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.4e+33: tmp = y * z elif y <= 1.55e+46: tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.4e+33) tmp = Float64(y * z); elseif (y <= 1.55e+46) 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 <= -6.4e+33) tmp = y * z; elseif (y <= 1.55e+46) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.4e+33], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.55e+46], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.4 \cdot 10^{+33}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{+46}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -6.40000000000000034e33 or 1.54999999999999988e46 < y Initial program 100.0%
Taylor expanded in z around inf 85.6%
Taylor expanded in y around inf 80.3%
*-commutative80.3%
Simplified80.3%
if -6.40000000000000034e33 < y < 1.54999999999999988e46Initial program 100.0%
Taylor expanded in x around inf 84.3%
distribute-rgt1-in84.3%
mul-1-neg84.3%
cancel-sign-sub-inv84.3%
Simplified84.3%
Taylor expanded in x around 0 84.3%
Final simplification82.7%
(FPCore (x y z) :precision binary64 (if (<= z -3.1e-11) (* y z) (if (<= z 0.032) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.1e-11) {
tmp = y * z;
} else if (z <= 0.032) {
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 <= (-3.1d-11)) then
tmp = y * z
else if (z <= 0.032d0) 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 <= -3.1e-11) {
tmp = y * z;
} else if (z <= 0.032) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.1e-11: tmp = y * z elif z <= 0.032: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.1e-11) tmp = Float64(y * z); elseif (z <= 0.032) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.1e-11) tmp = y * z; elseif (z <= 0.032) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.1e-11], N[(y * z), $MachinePrecision], If[LessEqual[z, 0.032], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{-11}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 0.032:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -3.10000000000000028e-11 or 0.032000000000000001 < z Initial program 100.0%
Taylor expanded in z around inf 97.3%
Taylor expanded in y around inf 56.8%
*-commutative56.8%
Simplified56.8%
if -3.10000000000000028e-11 < z < 0.032000000000000001Initial program 100.0%
Taylor expanded in z around 0 71.7%
Final simplification63.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%
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 35.5%
Final simplification35.5%
herbie shell --seed 2023200
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))