
(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 (- x z) y z))
double code(double x, double y, double z) {
return fma((x - z), y, z);
}
function code(x, y, z) return fma(Float64(x - z), y, z) end
code[x_, y_, z_] := N[(N[(x - z), $MachinePrecision] * y + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x - z, y, z\right)
\end{array}
Initial program 96.5%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
distribute-lft1-inN/A
associate-*r*N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
*-commutativeN/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- z) y)))
(if (<= y -1.0)
t_0
(if (<= y 2.7e-15)
(* 1.0 z)
(if (<= y 6e+170) (* y x) (if (<= y 1.75e+276) t_0 (* y x)))))))
double code(double x, double y, double z) {
double t_0 = -z * y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 2.7e-15) {
tmp = 1.0 * z;
} else if (y <= 6e+170) {
tmp = y * x;
} else if (y <= 1.75e+276) {
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 * y
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 2.7d-15) then
tmp = 1.0d0 * z
else if (y <= 6d+170) then
tmp = y * x
else if (y <= 1.75d+276) 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 * y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 2.7e-15) {
tmp = 1.0 * z;
} else if (y <= 6e+170) {
tmp = y * x;
} else if (y <= 1.75e+276) {
tmp = t_0;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): t_0 = -z * y tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 2.7e-15: tmp = 1.0 * z elif y <= 6e+170: tmp = y * x elif y <= 1.75e+276: tmp = t_0 else: tmp = y * x return tmp
function code(x, y, z) t_0 = Float64(Float64(-z) * y) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 2.7e-15) tmp = Float64(1.0 * z); elseif (y <= 6e+170) tmp = Float64(y * x); elseif (y <= 1.75e+276) tmp = t_0; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) t_0 = -z * y; tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 2.7e-15) tmp = 1.0 * z; elseif (y <= 6e+170) tmp = y * x; elseif (y <= 1.75e+276) tmp = t_0; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * y), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 2.7e-15], N[(1.0 * z), $MachinePrecision], If[LessEqual[y, 6e+170], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.75e+276], t$95$0, N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot y\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-15}:\\
\;\;\;\;1 \cdot z\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+170}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.75 \cdot 10^{+276}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1 or 5.99999999999999994e170 < y < 1.74999999999999991e276Initial program 91.7%
Taylor expanded in y around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6499.1
Applied rewrites99.1%
Taylor expanded in z around inf
Applied rewrites65.9%
if -1 < y < 2.70000000000000009e-15Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6472.9
Applied rewrites72.9%
Taylor expanded in y around 0
Applied rewrites72.8%
if 2.70000000000000009e-15 < y < 5.99999999999999994e170 or 1.74999999999999991e276 < y Initial program 95.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6471.3
Applied rewrites71.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 y) z))) (if (<= z -4e+116) t_0 (if (<= z 6.5e-9) (* (- x z) y) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - y) * z;
double tmp;
if (z <= -4e+116) {
tmp = t_0;
} else if (z <= 6.5e-9) {
tmp = (x - z) * y;
} 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 = (1.0d0 - y) * z
if (z <= (-4d+116)) then
tmp = t_0
else if (z <= 6.5d-9) then
tmp = (x - z) * y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (1.0 - y) * z;
double tmp;
if (z <= -4e+116) {
tmp = t_0;
} else if (z <= 6.5e-9) {
tmp = (x - z) * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - y) * z tmp = 0 if z <= -4e+116: tmp = t_0 elif z <= 6.5e-9: tmp = (x - z) * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - y) * z) tmp = 0.0 if (z <= -4e+116) tmp = t_0; elseif (z <= 6.5e-9) tmp = Float64(Float64(x - z) * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - y) * z; tmp = 0.0; if (z <= -4e+116) tmp = t_0; elseif (z <= 6.5e-9) tmp = (x - z) * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -4e+116], t$95$0, If[LessEqual[z, 6.5e-9], N[(N[(x - z), $MachinePrecision] * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - y\right) \cdot z\\
\mathbf{if}\;z \leq -4 \cdot 10^{+116}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{-9}:\\
\;\;\;\;\left(x - z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -4.00000000000000006e116 or 6.5000000000000003e-9 < z Initial program 94.4%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6492.3
Applied rewrites92.3%
if -4.00000000000000006e116 < z < 6.5000000000000003e-9Initial program 98.4%
Taylor expanded in y around inf
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6482.0
Applied rewrites82.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 y) z))) (if (<= z -6e-62) t_0 (if (<= z 1.7e-51) (* y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - y) * z;
double tmp;
if (z <= -6e-62) {
tmp = t_0;
} else if (z <= 1.7e-51) {
tmp = 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 = (1.0d0 - y) * z
if (z <= (-6d-62)) then
tmp = t_0
else if (z <= 1.7d-51) then
tmp = 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 = (1.0 - y) * z;
double tmp;
if (z <= -6e-62) {
tmp = t_0;
} else if (z <= 1.7e-51) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - y) * z tmp = 0 if z <= -6e-62: tmp = t_0 elif z <= 1.7e-51: tmp = y * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - y) * z) tmp = 0.0 if (z <= -6e-62) tmp = t_0; elseif (z <= 1.7e-51) tmp = Float64(y * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - y) * z; tmp = 0.0; if (z <= -6e-62) tmp = t_0; elseif (z <= 1.7e-51) tmp = y * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -6e-62], t$95$0, If[LessEqual[z, 1.7e-51], N[(y * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - y\right) \cdot z\\
\mathbf{if}\;z \leq -6 \cdot 10^{-62}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.7 \cdot 10^{-51}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -6.0000000000000002e-62 or 1.70000000000000001e-51 < z Initial program 94.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6484.4
Applied rewrites84.4%
if -6.0000000000000002e-62 < z < 1.70000000000000001e-51Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6477.7
Applied rewrites77.7%
(FPCore (x y z) :precision binary64 (if (<= y -4.2e-15) (* y x) (if (<= y 2.7e-15) (* 1.0 z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.2e-15) {
tmp = y * x;
} else if (y <= 2.7e-15) {
tmp = 1.0 * 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 <= (-4.2d-15)) then
tmp = y * x
else if (y <= 2.7d-15) then
tmp = 1.0d0 * 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 <= -4.2e-15) {
tmp = y * x;
} else if (y <= 2.7e-15) {
tmp = 1.0 * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.2e-15: tmp = y * x elif y <= 2.7e-15: tmp = 1.0 * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.2e-15) tmp = Float64(y * x); elseif (y <= 2.7e-15) tmp = Float64(1.0 * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.2e-15) tmp = y * x; elseif (y <= 2.7e-15) tmp = 1.0 * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.2e-15], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.7e-15], N[(1.0 * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{-15}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-15}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -4.19999999999999962e-15 or 2.70000000000000009e-15 < y Initial program 93.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6453.2
Applied rewrites53.2%
if -4.19999999999999962e-15 < y < 2.70000000000000009e-15Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6473.4
Applied rewrites73.4%
Taylor expanded in y around 0
Applied rewrites73.4%
(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 96.5%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6441.6
Applied rewrites41.6%
(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 2024276
(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))))