
(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 (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 (* z (- x))))
(if (<= z -1e+134)
t_0
(if (<= z -8.5e+32)
(* y z)
(if (<= z -52000000000000.0)
t_0
(if (<= z -2.3e-96)
(* y z)
(if (<= z 1.02e-26)
x
(if (<= z 2.55e+206)
(* y z)
(if (<= z 6.4e+226) t_0 (* y z))))))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -1e+134) {
tmp = t_0;
} else if (z <= -8.5e+32) {
tmp = y * z;
} else if (z <= -52000000000000.0) {
tmp = t_0;
} else if (z <= -2.3e-96) {
tmp = y * z;
} else if (z <= 1.02e-26) {
tmp = x;
} else if (z <= 2.55e+206) {
tmp = y * z;
} else if (z <= 6.4e+226) {
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 = z * -x
if (z <= (-1d+134)) then
tmp = t_0
else if (z <= (-8.5d+32)) then
tmp = y * z
else if (z <= (-52000000000000.0d0)) then
tmp = t_0
else if (z <= (-2.3d-96)) then
tmp = y * z
else if (z <= 1.02d-26) then
tmp = x
else if (z <= 2.55d+206) then
tmp = y * z
else if (z <= 6.4d+226) 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 = z * -x;
double tmp;
if (z <= -1e+134) {
tmp = t_0;
} else if (z <= -8.5e+32) {
tmp = y * z;
} else if (z <= -52000000000000.0) {
tmp = t_0;
} else if (z <= -2.3e-96) {
tmp = y * z;
} else if (z <= 1.02e-26) {
tmp = x;
} else if (z <= 2.55e+206) {
tmp = y * z;
} else if (z <= 6.4e+226) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if z <= -1e+134: tmp = t_0 elif z <= -8.5e+32: tmp = y * z elif z <= -52000000000000.0: tmp = t_0 elif z <= -2.3e-96: tmp = y * z elif z <= 1.02e-26: tmp = x elif z <= 2.55e+206: tmp = y * z elif z <= 6.4e+226: tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (z <= -1e+134) tmp = t_0; elseif (z <= -8.5e+32) tmp = Float64(y * z); elseif (z <= -52000000000000.0) tmp = t_0; elseif (z <= -2.3e-96) tmp = Float64(y * z); elseif (z <= 1.02e-26) tmp = x; elseif (z <= 2.55e+206) tmp = Float64(y * z); elseif (z <= 6.4e+226) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (z <= -1e+134) tmp = t_0; elseif (z <= -8.5e+32) tmp = y * z; elseif (z <= -52000000000000.0) tmp = t_0; elseif (z <= -2.3e-96) tmp = y * z; elseif (z <= 1.02e-26) tmp = x; elseif (z <= 2.55e+206) tmp = y * z; elseif (z <= 6.4e+226) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[z, -1e+134], t$95$0, If[LessEqual[z, -8.5e+32], N[(y * z), $MachinePrecision], If[LessEqual[z, -52000000000000.0], t$95$0, If[LessEqual[z, -2.3e-96], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.02e-26], x, If[LessEqual[z, 2.55e+206], N[(y * z), $MachinePrecision], If[LessEqual[z, 6.4e+226], t$95$0, N[(y * z), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;z \leq -1 \cdot 10^{+134}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -8.5 \cdot 10^{+32}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -52000000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -2.3 \cdot 10^{-96}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.02 \cdot 10^{-26}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.55 \cdot 10^{+206}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 6.4 \cdot 10^{+226}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -9.99999999999999921e133 or -8.4999999999999998e32 < z < -5.2e13 or 2.5500000000000002e206 < z < 6.39999999999999954e226Initial program 100.0%
Taylor expanded in x around inf 74.7%
distribute-rgt1-in74.7%
mul-1-neg74.7%
cancel-sign-sub-inv74.7%
Simplified74.7%
Taylor expanded in z around inf 74.4%
mul-1-neg74.4%
distribute-rgt-neg-in74.4%
Simplified74.4%
if -9.99999999999999921e133 < z < -8.4999999999999998e32 or -5.2e13 < z < -2.3e-96 or 1.02e-26 < z < 2.5500000000000002e206 or 6.39999999999999954e226 < z Initial program 100.0%
Taylor expanded in x around 0 62.1%
if -2.3e-96 < z < 1.02e-26Initial program 100.0%
Taylor expanded in z around 0 77.0%
Final simplification70.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.9e-93) (not (<= z 1.05e-26))) (* (- y x) z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.9e-93) || !(z <= 1.05e-26)) {
tmp = (y - x) * 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 <= (-5.9d-93)) .or. (.not. (z <= 1.05d-26))) then
tmp = (y - x) * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -5.9e-93) || !(z <= 1.05e-26)) {
tmp = (y - x) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.9e-93) or not (z <= 1.05e-26): tmp = (y - x) * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.9e-93) || !(z <= 1.05e-26)) tmp = Float64(Float64(y - x) * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.9e-93) || ~((z <= 1.05e-26))) tmp = (y - x) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.9e-93], N[Not[LessEqual[z, 1.05e-26]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.9 \cdot 10^{-93} \lor \neg \left(z \leq 1.05 \cdot 10^{-26}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.9e-93 or 1.05000000000000004e-26 < z Initial program 100.0%
Taylor expanded in z around inf 93.1%
if -5.9e-93 < z < 1.05000000000000004e-26Initial program 100.0%
Taylor expanded in z around 0 77.0%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (<= z -3.7e-93) (* y z) (if (<= z 1.05e-26) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.7e-93) {
tmp = y * z;
} else if (z <= 1.05e-26) {
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.7d-93)) then
tmp = y * z
else if (z <= 1.05d-26) 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.7e-93) {
tmp = y * z;
} else if (z <= 1.05e-26) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.7e-93: tmp = y * z elif z <= 1.05e-26: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.7e-93) tmp = Float64(y * z); elseif (z <= 1.05e-26) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.7e-93) tmp = y * z; elseif (z <= 1.05e-26) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.7e-93], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.05e-26], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.7 \cdot 10^{-93}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{-26}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -3.70000000000000002e-93 or 1.05000000000000004e-26 < z Initial program 100.0%
Taylor expanded in x around 0 51.3%
if -3.70000000000000002e-93 < z < 1.05000000000000004e-26Initial program 100.0%
Taylor expanded in z around 0 77.0%
Final simplification61.4%
(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.6%
Final simplification35.6%
herbie shell --seed 2023252
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))