
(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 6 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 97.2%
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
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
accelerator-lowering-fma.f64N/A
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- z))))
(if (<= y -2.3e+104)
t_0
(if (<= y 3.5e+27) (fma y x z) (if (<= y 4.8e+198) t_0 (* y x))))))
double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (y <= -2.3e+104) {
tmp = t_0;
} else if (y <= 3.5e+27) {
tmp = fma(y, x, z);
} else if (y <= 4.8e+198) {
tmp = t_0;
} else {
tmp = y * x;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(-z)) tmp = 0.0 if (y <= -2.3e+104) tmp = t_0; elseif (y <= 3.5e+27) tmp = fma(y, x, z); elseif (y <= 4.8e+198) tmp = t_0; else tmp = Float64(y * x); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[y, -2.3e+104], t$95$0, If[LessEqual[y, 3.5e+27], N[(y * x + z), $MachinePrecision], If[LessEqual[y, 4.8e+198], t$95$0, N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-z\right)\\
\mathbf{if}\;y \leq -2.3 \cdot 10^{+104}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{+27}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{+198}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -2.29999999999999985e104 or 3.5000000000000002e27 < y < 4.8000000000000003e198Initial program 96.2%
Taylor expanded in y around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
*-lowering-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
--lowering--.f64100.0
Simplified100.0%
Taylor expanded in x around 0
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6464.3
Simplified64.3%
if -2.29999999999999985e104 < y < 3.5000000000000002e27Initial program 100.0%
Taylor expanded in y around 0
Simplified90.7%
*-commutativeN/A
accelerator-lowering-fma.f6490.7
Applied egg-rr90.7%
if 4.8000000000000003e198 < y Initial program 85.7%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6462.3
Simplified62.3%
Final simplification79.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- x z)))) (if (<= y -1.0) t_0 (if (<= y 1.0) (fma y x z) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = fma(y, x, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(x - z)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 1.0) tmp = fma(y, x, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 1.0], N[(y * x + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 94.9%
Taylor expanded in y around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
*-lowering-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
--lowering--.f6497.9
Simplified97.9%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0
Simplified99.3%
*-commutativeN/A
accelerator-lowering-fma.f6499.3
Applied egg-rr99.3%
(FPCore (x y z) :precision binary64 (if (<= y -1.7e-20) (* y x) (if (<= y 4e-47) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.7e-20) {
tmp = y * x;
} else if (y <= 4e-47) {
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 <= (-1.7d-20)) then
tmp = y * x
else if (y <= 4d-47) 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 <= -1.7e-20) {
tmp = y * x;
} else if (y <= 4e-47) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.7e-20: tmp = y * x elif y <= 4e-47: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.7e-20) tmp = Float64(y * x); elseif (y <= 4e-47) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.7e-20) tmp = y * x; elseif (y <= 4e-47) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.7e-20], N[(y * x), $MachinePrecision], If[LessEqual[y, 4e-47], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{-20}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-47}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.6999999999999999e-20 or 3.9999999999999999e-47 < y Initial program 95.4%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6447.0
Simplified47.0%
if -1.6999999999999999e-20 < y < 3.9999999999999999e-47Initial program 100.0%
Taylor expanded in y around 0
Simplified79.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 97.2%
Taylor expanded in y around 0
Simplified70.5%
*-commutativeN/A
accelerator-lowering-fma.f6470.5
Applied egg-rr70.5%
(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 97.2%
Taylor expanded in y around 0
Simplified35.5%
(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 2024201
(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))))