
(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 7 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 -6.3e+168)
t_0
(if (<= z -5.4e-8)
(* y z)
(if (<= z 3.5e-84) x (if (<= z 1.3e+64) (* y z) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -6.3e+168) {
tmp = t_0;
} else if (z <= -5.4e-8) {
tmp = y * z;
} else if (z <= 3.5e-84) {
tmp = x;
} else if (z <= 1.3e+64) {
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 <= (-6.3d+168)) then
tmp = t_0
else if (z <= (-5.4d-8)) then
tmp = y * z
else if (z <= 3.5d-84) then
tmp = x
else if (z <= 1.3d+64) 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 <= -6.3e+168) {
tmp = t_0;
} else if (z <= -5.4e-8) {
tmp = y * z;
} else if (z <= 3.5e-84) {
tmp = x;
} else if (z <= 1.3e+64) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -6.3e+168: tmp = t_0 elif z <= -5.4e-8: tmp = y * z elif z <= 3.5e-84: tmp = x elif z <= 1.3e+64: 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 <= -6.3e+168) tmp = t_0; elseif (z <= -5.4e-8) tmp = Float64(y * z); elseif (z <= 3.5e-84) tmp = x; elseif (z <= 1.3e+64) 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 <= -6.3e+168) tmp = t_0; elseif (z <= -5.4e-8) tmp = y * z; elseif (z <= 3.5e-84) tmp = x; elseif (z <= 1.3e+64) 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, -6.3e+168], t$95$0, If[LessEqual[z, -5.4e-8], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.5e-84], x, If[LessEqual[z, 1.3e+64], N[(y * z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -6.3 \cdot 10^{+168}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -5.4 \cdot 10^{-8}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{-84}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{+64}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -6.2999999999999997e168 or 1.29999999999999998e64 < z Initial program 100.0%
Taylor expanded in x around inf 66.1%
mul-1-neg66.1%
unsub-neg66.1%
Simplified66.1%
Taylor expanded in z around inf 66.1%
mul-1-neg66.1%
*-commutative66.1%
distribute-rgt-neg-out66.1%
Simplified66.1%
if -6.2999999999999997e168 < z < -5.40000000000000005e-8 or 3.5000000000000001e-84 < z < 1.29999999999999998e64Initial program 100.0%
Taylor expanded in x around 0 59.9%
if -5.40000000000000005e-8 < z < 3.5000000000000001e-84Initial program 100.0%
Taylor expanded in z around 0 74.9%
Final simplification69.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.6e+167) (not (<= y 2.1e+24))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.6e+167) || !(y <= 2.1e+24)) {
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+167)) .or. (.not. (y <= 2.1d+24))) 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+167) || !(y <= 2.1e+24)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.6e+167) or not (y <= 2.1e+24): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.6e+167) || !(y <= 2.1e+24)) 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+167) || ~((y <= 2.1e+24))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.6e+167], N[Not[LessEqual[y, 2.1e+24]], $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^{+167} \lor \neg \left(y \leq 2.1 \cdot 10^{+24}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -3.60000000000000024e167 or 2.1000000000000001e24 < y Initial program 100.0%
Taylor expanded in x around 0 75.0%
if -3.60000000000000024e167 < y < 2.1000000000000001e24Initial program 100.0%
Taylor expanded in x around inf 81.4%
mul-1-neg81.4%
unsub-neg81.4%
Simplified81.4%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -9.4e-7) (not (<= z 2.6e-84))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9.4e-7) || !(z <= 2.6e-84)) {
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 <= (-9.4d-7)) .or. (.not. (z <= 2.6d-84))) 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 <= -9.4e-7) || !(z <= 2.6e-84)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9.4e-7) or not (z <= 2.6e-84): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9.4e-7) || !(z <= 2.6e-84)) 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 <= -9.4e-7) || ~((z <= 2.6e-84))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9.4e-7], N[Not[LessEqual[z, 2.6e-84]], $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 -9.4 \cdot 10^{-7} \lor \neg \left(z \leq 2.6 \cdot 10^{-84}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -9.4e-7 or 2.6e-84 < z Initial program 100.0%
Taylor expanded in z around inf 93.4%
if -9.4e-7 < z < 2.6e-84Initial program 100.0%
Taylor expanded in x around inf 74.9%
mul-1-neg74.9%
unsub-neg74.9%
Simplified74.9%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -7.4e-7) (not (<= z 3.5e-84))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.4e-7) || !(z <= 3.5e-84)) {
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 <= (-7.4d-7)) .or. (.not. (z <= 3.5d-84))) 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 <= -7.4e-7) || !(z <= 3.5e-84)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.4e-7) or not (z <= 3.5e-84): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.4e-7) || !(z <= 3.5e-84)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -7.4e-7) || ~((z <= 3.5e-84))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.4e-7], N[Not[LessEqual[z, 3.5e-84]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.4 \cdot 10^{-7} \lor \neg \left(z \leq 3.5 \cdot 10^{-84}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.40000000000000009e-7 or 3.5000000000000001e-84 < z Initial program 100.0%
Taylor expanded in x around 0 48.0%
if -7.40000000000000009e-7 < z < 3.5000000000000001e-84Initial program 100.0%
Taylor expanded in z around 0 74.9%
Final simplification61.0%
(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.3%
Final simplification40.3%
herbie shell --seed 2024019
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))