
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
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) + (z * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
def code(x, y, z): return (x * y) + (z * (1.0 - y))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (1.0 - y)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(1 - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
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) + (z * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
def code(x, y, z): return (x * y) + (z * (1.0 - y))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (1.0 - y)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(1 - y\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma y (- x z) z))
double code(double x, double y, double z) {
return fma(y, (x - z), z);
}
function code(x, y, z) return fma(y, Float64(x - z), z) end
code[x_, y_, z_] := N[(y * N[(x - z), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x - z, z\right)
\end{array}
Initial program 96.9%
Taylor expanded in x around 0
distribute-rgt-out--N/A
unsub-negN/A
*-lft-identityN/A
mul-1-negN/A
+-commutativeN/A
associate-+l+N/A
*-commutativeN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
distribute-lft-inN/A
+-commutativeN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
accelerator-lowering-fma.f64N/A
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -3.5e-72) (fma y x z) (if (<= x 7.3e-65) (fma (- 0.0 y) z z) (fma y x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.5e-72) {
tmp = fma(y, x, z);
} else if (x <= 7.3e-65) {
tmp = fma((0.0 - y), z, z);
} else {
tmp = fma(y, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -3.5e-72) tmp = fma(y, x, z); elseif (x <= 7.3e-65) tmp = fma(Float64(0.0 - y), z, z); else tmp = fma(y, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -3.5e-72], N[(y * x + z), $MachinePrecision], If[LessEqual[x, 7.3e-65], N[(N[(0.0 - y), $MachinePrecision] * z + z), $MachinePrecision], N[(y * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{-72}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\mathbf{elif}\;x \leq 7.3 \cdot 10^{-65}:\\
\;\;\;\;\mathsf{fma}\left(0 - y, z, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\end{array}
\end{array}
if x < -3.5e-72 or 7.2999999999999998e-65 < x Initial program 95.1%
Taylor expanded in y around 0
Simplified87.7%
*-commutativeN/A
accelerator-lowering-fma.f6487.7
Applied egg-rr87.7%
if -3.5e-72 < x < 7.2999999999999998e-65Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt-out--N/A
unsub-negN/A
*-lft-identityN/A
mul-1-negN/A
+-commutativeN/A
associate-+l+N/A
*-commutativeN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
distribute-lft-inN/A
+-commutativeN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
accelerator-lowering-fma.f64N/A
Simplified100.0%
sub-negN/A
distribute-lft-inN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64100.0
Applied egg-rr100.0%
associate-+r+N/A
+-commutativeN/A
associate-+r+N/A
sub0-negN/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-lowering-neg.f64N/A
accelerator-lowering-fma.f64100.0
Applied egg-rr100.0%
Taylor expanded in y around 0
Simplified85.9%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (<= y -6e-61) (* y x) (if (<= y 2e-110) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6e-61) {
tmp = y * x;
} else if (y <= 2e-110) {
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 (y <= (-6d-61)) then
tmp = y * x
else if (y <= 2d-110) 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 (y <= -6e-61) {
tmp = y * x;
} else if (y <= 2e-110) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6e-61: tmp = y * x elif y <= 2e-110: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6e-61) tmp = Float64(y * x); elseif (y <= 2e-110) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6e-61) tmp = y * x; elseif (y <= 2e-110) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6e-61], N[(y * x), $MachinePrecision], If[LessEqual[y, 2e-110], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{-61}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-110}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -6.00000000000000024e-61 or 2.0000000000000001e-110 < y Initial program 95.0%
Taylor expanded in x around inf
+-rgt-identityN/A
*-commutativeN/A
accelerator-lowering-fma.f6458.4
Simplified58.4%
+-rgt-identityN/A
*-lowering-*.f6458.4
Applied egg-rr58.4%
if -6.00000000000000024e-61 < y < 2.0000000000000001e-110Initial program 100.0%
Taylor expanded in y around 0
Simplified82.5%
(FPCore (x y z) :precision binary64 (fma y x z))
double code(double x, double y, double z) {
return fma(y, x, z);
}
function code(x, y, z) return fma(y, x, z) end
code[x_, y_, z_] := N[(y * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, z\right)
\end{array}
Initial program 96.9%
Taylor expanded in y around 0
Simplified77.8%
*-commutativeN/A
accelerator-lowering-fma.f6477.8
Applied egg-rr77.8%
(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 96.9%
Taylor expanded in y around 0
Simplified35.7%
(FPCore (x y z) :precision binary64 (- z (* (- z x) y)))
double code(double x, double y, double z) {
return z - ((z - x) * y);
}
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 - x) * y)
end function
public static double code(double x, double y, double z) {
return z - ((z - x) * y);
}
def code(x, y, z): return z - ((z - x) * y)
function code(x, y, z) return Float64(z - Float64(Float64(z - x) * y)) end
function tmp = code(x, y, z) tmp = z - ((z - x) * y); end
code[x_, y_, z_] := N[(z - N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - \left(z - x\right) \cdot y
\end{array}
herbie shell --seed 2024196
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:alt
(! :herbie-platform default (- z (* (- z x) y)))
(+ (* x y) (* z (- 1.0 y))))