
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - 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) + ((1.0d0 - x) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(1 - 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) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - 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) + ((1.0d0 - x) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(1 - x\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (- z y) (- 0.0 x) z))
double code(double x, double y, double z) {
return fma((z - y), (0.0 - x), z);
}
function code(x, y, z) return fma(Float64(z - y), Float64(0.0 - x), z) end
code[x_, y_, z_] := N[(N[(z - y), $MachinePrecision] * N[(0.0 - x), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - y, 0 - x, z\right)
\end{array}
Initial program 99.2%
+-commutativeN/A
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
associate-+l-N/A
--lowering--.f64N/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
--lowering--.f64100.0%
Simplified100.0%
sub-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
fma-defineN/A
fma-lowering-fma.f64N/A
--lowering--.f64N/A
neg-sub0N/A
--lowering--.f64100.0%
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (- 0.0 x)))) (if (<= x -9e-7) t_0 (if (<= x 1.0) z (if (<= x 1.1e+227) t_0 (* y x))))))
double code(double x, double y, double z) {
double t_0 = z * (0.0 - x);
double tmp;
if (x <= -9e-7) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = z;
} else if (x <= 1.1e+227) {
tmp = t_0;
} else {
tmp = y * 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) :: t_0
real(8) :: tmp
t_0 = z * (0.0d0 - x)
if (x <= (-9d-7)) then
tmp = t_0
else if (x <= 1.0d0) then
tmp = z
else if (x <= 1.1d+227) then
tmp = t_0
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * (0.0 - x);
double tmp;
if (x <= -9e-7) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = z;
} else if (x <= 1.1e+227) {
tmp = t_0;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): t_0 = z * (0.0 - x) tmp = 0 if x <= -9e-7: tmp = t_0 elif x <= 1.0: tmp = z elif x <= 1.1e+227: tmp = t_0 else: tmp = y * x return tmp
function code(x, y, z) t_0 = Float64(z * Float64(0.0 - x)) tmp = 0.0 if (x <= -9e-7) tmp = t_0; elseif (x <= 1.0) tmp = z; elseif (x <= 1.1e+227) tmp = t_0; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (0.0 - x); tmp = 0.0; if (x <= -9e-7) tmp = t_0; elseif (x <= 1.0) tmp = z; elseif (x <= 1.1e+227) tmp = t_0; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(0.0 - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -9e-7], t$95$0, If[LessEqual[x, 1.0], z, If[LessEqual[x, 1.1e+227], t$95$0, N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(0 - x\right)\\
\mathbf{if}\;x \leq -9 \cdot 10^{-7}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 1.1 \cdot 10^{+227}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -8.99999999999999959e-7 or 1 < x < 1.1000000000000001e227Initial program 97.9%
Taylor expanded in x around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
--lowering--.f6499.3%
Simplified99.3%
sub-negN/A
+-commutativeN/A
remove-double-negN/A
distribute-neg-inN/A
sub-negN/A
distribute-rgt-neg-inN/A
/-rgt-identityN/A
associate-/r/N/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
/-lowering-/.f64N/A
--lowering--.f6499.2%
Applied egg-rr99.2%
Taylor expanded in z around inf
/-lowering-/.f6463.1%
Simplified63.1%
frac-2negN/A
distribute-frac-negN/A
neg-lowering-neg.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
associate-/r/N/A
/-rgt-identityN/A
*-lowering-*.f6463.3%
Applied egg-rr63.3%
if -8.99999999999999959e-7 < x < 1Initial program 100.0%
Taylor expanded in x around 0
Simplified71.6%
if 1.1000000000000001e227 < x Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6485.2%
Simplified85.2%
Final simplification69.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- y z)))) (if (<= x -1.0) t_0 (if (<= x 1.0) (+ z (* y x)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = z + (y * x);
} 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 * (y - z)
if (x <= (-1.0d0)) then
tmp = t_0
else if (x <= 1.0d0) then
tmp = z + (y * x)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = z + (y * x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) tmp = 0 if x <= -1.0: tmp = t_0 elif x <= 1.0: tmp = z + (y * x) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 1.0) tmp = Float64(z + Float64(y * x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y - z); tmp = 0.0; if (x <= -1.0) tmp = t_0; elseif (x <= 1.0) tmp = z + (y * x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 1.0], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;z + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 98.1%
Taylor expanded in x around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
--lowering--.f6499.4%
Simplified99.4%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0
Simplified99.2%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- y z)))) (if (<= x -3.3e-12) t_0 (if (<= x 3.2e-50) (* z (- 1.0 x)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -3.3e-12) {
tmp = t_0;
} else if (x <= 3.2e-50) {
tmp = z * (1.0 - x);
} 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 * (y - z)
if (x <= (-3.3d-12)) then
tmp = t_0
else if (x <= 3.2d-50) then
tmp = z * (1.0d0 - x)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -3.3e-12) {
tmp = t_0;
} else if (x <= 3.2e-50) {
tmp = z * (1.0 - x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) tmp = 0 if x <= -3.3e-12: tmp = t_0 elif x <= 3.2e-50: tmp = z * (1.0 - x) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) tmp = 0.0 if (x <= -3.3e-12) tmp = t_0; elseif (x <= 3.2e-50) tmp = Float64(z * Float64(1.0 - x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y - z); tmp = 0.0; if (x <= -3.3e-12) tmp = t_0; elseif (x <= 3.2e-50) tmp = z * (1.0 - x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -3.3e-12], t$95$0, If[LessEqual[x, 3.2e-50], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;x \leq -3.3 \cdot 10^{-12}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-50}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.3000000000000001e-12 or 3.2e-50 < x Initial program 98.3%
Taylor expanded in x around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
--lowering--.f6494.6%
Simplified94.6%
if -3.3000000000000001e-12 < x < 3.2e-50Initial program 100.0%
Taylor expanded in y around 0
*-lowering-*.f64N/A
--lowering--.f6475.3%
Simplified75.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- y z)))) (if (<= x -1.32e-11) t_0 (if (<= x 4e-53) z t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -1.32e-11) {
tmp = t_0;
} else if (x <= 4e-53) {
tmp = 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 * (y - z)
if (x <= (-1.32d-11)) then
tmp = t_0
else if (x <= 4d-53) then
tmp = 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 * (y - z);
double tmp;
if (x <= -1.32e-11) {
tmp = t_0;
} else if (x <= 4e-53) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) tmp = 0 if x <= -1.32e-11: tmp = t_0 elif x <= 4e-53: tmp = z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) tmp = 0.0 if (x <= -1.32e-11) tmp = t_0; elseif (x <= 4e-53) tmp = z; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y - z); tmp = 0.0; if (x <= -1.32e-11) tmp = t_0; elseif (x <= 4e-53) tmp = z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.32e-11], t$95$0, If[LessEqual[x, 4e-53], z, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;x \leq -1.32 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 4 \cdot 10^{-53}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.32e-11 or 4.00000000000000012e-53 < x Initial program 98.3%
Taylor expanded in x around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
--lowering--.f6494.6%
Simplified94.6%
if -1.32e-11 < x < 4.00000000000000012e-53Initial program 100.0%
Taylor expanded in x around 0
Simplified75.2%
(FPCore (x y z) :precision binary64 (if (<= x -3.55e-12) (* y x) (if (<= x 8.5e-51) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.55e-12) {
tmp = y * x;
} else if (x <= 8.5e-51) {
tmp = z;
} else {
tmp = y * 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 (x <= (-3.55d-12)) then
tmp = y * x
else if (x <= 8.5d-51) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.55e-12) {
tmp = y * x;
} else if (x <= 8.5e-51) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.55e-12: tmp = y * x elif x <= 8.5e-51: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.55e-12) tmp = Float64(y * x); elseif (x <= 8.5e-51) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.55e-12) tmp = y * x; elseif (x <= 8.5e-51) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.55e-12], N[(y * x), $MachinePrecision], If[LessEqual[x, 8.5e-51], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.55 \cdot 10^{-12}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 8.5 \cdot 10^{-51}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -3.55e-12 or 8.50000000000000036e-51 < x Initial program 98.3%
Taylor expanded in y around inf
*-lowering-*.f6447.2%
Simplified47.2%
if -3.55e-12 < x < 8.50000000000000036e-51Initial program 100.0%
Taylor expanded in x around 0
Simplified75.2%
Final simplification61.6%
(FPCore (x y z) :precision binary64 (- z (* (- z y) x)))
double code(double x, double y, double z) {
return z - ((z - y) * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z - ((z - y) * x)
end function
public static double code(double x, double y, double z) {
return z - ((z - y) * x);
}
def code(x, y, z): return z - ((z - y) * x)
function code(x, y, z) return Float64(z - Float64(Float64(z - y) * x)) end
function tmp = code(x, y, z) tmp = z - ((z - y) * x); end
code[x_, y_, z_] := N[(z - N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - \left(z - y\right) \cdot x
\end{array}
Initial program 99.2%
+-commutativeN/A
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
associate-+l-N/A
--lowering--.f64N/A
distribute-lft-out--N/A
*-lowering-*.f64N/A
--lowering--.f64100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.2%
Taylor expanded in x around 0
Simplified42.2%
herbie shell --seed 2024163
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))