
(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.3%
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
lower-fma.f64N/A
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- z))))
(if (<= y -2.15e+61)
t_0
(if (<= y -5e-14)
(* y x)
(if (<= y 2.95e-21) (fma z y z) (if (<= y 5.8e+14) (* y x) t_0))))))
double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (y <= -2.15e+61) {
tmp = t_0;
} else if (y <= -5e-14) {
tmp = y * x;
} else if (y <= 2.95e-21) {
tmp = fma(z, y, z);
} else if (y <= 5.8e+14) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(-z)) tmp = 0.0 if (y <= -2.15e+61) tmp = t_0; elseif (y <= -5e-14) tmp = Float64(y * x); elseif (y <= 2.95e-21) tmp = fma(z, y, z); elseif (y <= 5.8e+14) tmp = Float64(y * x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[y, -2.15e+61], t$95$0, If[LessEqual[y, -5e-14], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.95e-21], N[(z * y + z), $MachinePrecision], If[LessEqual[y, 5.8e+14], N[(y * x), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-z\right)\\
\mathbf{if}\;y \leq -2.15 \cdot 10^{+61}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -5 \cdot 10^{-14}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2.95 \cdot 10^{-21}:\\
\;\;\;\;\mathsf{fma}\left(z, y, z\right)\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{+14}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.1500000000000001e61 or 5.8e14 < y Initial program 93.1%
Taylor expanded in y around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f64100.0
Simplified100.0%
Taylor expanded in x around 0
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6463.3
Simplified63.3%
if -2.1500000000000001e61 < y < -5.0000000000000002e-14 or 2.9500000000000001e-21 < y < 5.8e14Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6456.8
Simplified56.8%
if -5.0000000000000002e-14 < y < 2.9500000000000001e-21Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6476.6
Simplified76.6%
*-commutativeN/A
cancel-sign-sub-invN/A
lift-neg.f64N/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
*-commutativeN/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6476.6
Applied egg-rr76.6%
lift-neg.f64N/A
lift-fma.f6476.6
Applied egg-rr76.5%
Final simplification69.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- x z)))) (if (<= y -75000000.0) t_0 (if (<= y 0.2) (- z (* y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -75000000.0) {
tmp = t_0;
} else if (y <= 0.2) {
tmp = z - (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 = y * (x - z)
if (y <= (-75000000.0d0)) then
tmp = t_0
else if (y <= 0.2d0) then
tmp = z - (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 = y * (x - z);
double tmp;
if (y <= -75000000.0) {
tmp = t_0;
} else if (y <= 0.2) {
tmp = z - (y * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -75000000.0: tmp = t_0 elif y <= 0.2: tmp = z - (y * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x - z)) tmp = 0.0 if (y <= -75000000.0) tmp = t_0; elseif (y <= 0.2) tmp = Float64(z - Float64(y * z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x - z); tmp = 0.0; if (y <= -75000000.0) tmp = t_0; elseif (y <= 0.2) tmp = z - (y * z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -75000000.0], t$95$0, If[LessEqual[y, 0.2], N[(z - N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -75000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.2:\\
\;\;\;\;z - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.5e7 or 0.20000000000000001 < y Initial program 94.1%
Taylor expanded in y around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6498.9
Simplified98.9%
if -7.5e7 < y < 0.20000000000000001Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6475.2
Simplified75.2%
Final simplification86.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- x z)))) (if (<= y -7.4e-13) t_0 (if (<= y 3.6e-19) (fma z y z) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -7.4e-13) {
tmp = t_0;
} else if (y <= 3.6e-19) {
tmp = fma(z, y, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(x - z)) tmp = 0.0 if (y <= -7.4e-13) tmp = t_0; elseif (y <= 3.6e-19) tmp = fma(z, y, 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, -7.4e-13], t$95$0, If[LessEqual[y, 3.6e-19], N[(z * y + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -7.4 \cdot 10^{-13}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-19}:\\
\;\;\;\;\mathsf{fma}\left(z, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.39999999999999977e-13 or 3.6000000000000001e-19 < y Initial program 94.6%
Taylor expanded in y around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6495.0
Simplified95.0%
if -7.39999999999999977e-13 < y < 3.6000000000000001e-19Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6476.1
Simplified76.1%
*-commutativeN/A
cancel-sign-sub-invN/A
lift-neg.f64N/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
*-commutativeN/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6476.1
Applied egg-rr76.1%
lift-neg.f64N/A
lift-fma.f6476.1
Applied egg-rr76.1%
(FPCore (x y z) :precision binary64 (if (<= y -1.85e-13) (* y x) (if (<= y 3.3e-22) (fma z y z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.85e-13) {
tmp = y * x;
} else if (y <= 3.3e-22) {
tmp = fma(z, y, z);
} else {
tmp = y * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.85e-13) tmp = Float64(y * x); elseif (y <= 3.3e-22) tmp = fma(z, y, z); else tmp = Float64(y * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.85e-13], N[(y * x), $MachinePrecision], If[LessEqual[y, 3.3e-22], N[(z * y + z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.85 \cdot 10^{-13}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{-22}:\\
\;\;\;\;\mathsf{fma}\left(z, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.84999999999999994e-13 or 3.3000000000000001e-22 < y Initial program 94.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6444.2
Simplified44.2%
if -1.84999999999999994e-13 < y < 3.3000000000000001e-22Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6476.6
Simplified76.6%
*-commutativeN/A
cancel-sign-sub-invN/A
lift-neg.f64N/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
*-commutativeN/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6476.6
Applied egg-rr76.6%
lift-neg.f64N/A
lift-fma.f6476.6
Applied egg-rr76.5%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return 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 = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 97.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6435.0
Simplified35.0%
(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 2024207
(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))))