
(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 (- 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 97.3%
Taylor expanded in x around 0
distribute-rgt-out--N/A
unsub-negN/A
mul-1-negN/A
*-lft-identityN/A
+-commutativeN/A
associate-+l+N/A
+-commutativeN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.1e-27) (not (<= y 9e-101))) (* (- x z) y) (* (- 1.0 y) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.1e-27) || !(y <= 9e-101)) {
tmp = (x - z) * y;
} else {
tmp = (1.0 - y) * z;
}
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 <= (-6.1d-27)) .or. (.not. (y <= 9d-101))) then
tmp = (x - z) * y
else
tmp = (1.0d0 - y) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.1e-27) || !(y <= 9e-101)) {
tmp = (x - z) * y;
} else {
tmp = (1.0 - y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.1e-27) or not (y <= 9e-101): tmp = (x - z) * y else: tmp = (1.0 - y) * z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.1e-27) || !(y <= 9e-101)) tmp = Float64(Float64(x - z) * y); else tmp = Float64(Float64(1.0 - y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.1e-27) || ~((y <= 9e-101))) tmp = (x - z) * y; else tmp = (1.0 - y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.1e-27], N[Not[LessEqual[y, 9e-101]], $MachinePrecision]], N[(N[(x - z), $MachinePrecision] * y), $MachinePrecision], N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.1 \cdot 10^{-27} \lor \neg \left(y \leq 9 \cdot 10^{-101}\right):\\
\;\;\;\;\left(x - z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - y\right) \cdot z\\
\end{array}
\end{array}
if y < -6.0999999999999999e-27 or 8.9999999999999997e-101 < y Initial program 95.4%
Taylor expanded in y around inf
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6492.2
Applied rewrites92.2%
if -6.0999999999999999e-27 < y < 8.9999999999999997e-101Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6480.9
Applied rewrites80.9%
Final simplification87.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* (- z) y) (* 1.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = -z * y;
} else {
tmp = 1.0 * z;
}
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.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = -z * y
else
tmp = 1.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = -z * y;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = -z * y else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(Float64(-z) * y); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = -z * y; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[((-z) * y), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;\left(-z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 94.5%
Taylor expanded in y around inf
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6498.2
Applied rewrites98.2%
Taylor expanded in x around 0
Applied rewrites54.7%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6473.2
Applied rewrites73.2%
Taylor expanded in y around 0
Applied rewrites72.8%
Final simplification63.7%
(FPCore (x y z) :precision binary64 (* (- 1.0 y) z))
double code(double x, double y, double z) {
return (1.0 - y) * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (1.0d0 - y) * z
end function
public static double code(double x, double y, double z) {
return (1.0 - y) * z;
}
def code(x, y, z): return (1.0 - y) * z
function code(x, y, z) return Float64(Float64(1.0 - y) * z) end
function tmp = code(x, y, z) tmp = (1.0 - y) * z; end
code[x_, y_, z_] := N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - y\right) \cdot z
\end{array}
Initial program 97.3%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6464.8
Applied rewrites64.8%
(FPCore (x y z) :precision binary64 (* 1.0 z))
double code(double x, double y, double z) {
return 1.0 * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 * z
end function
public static double code(double x, double y, double z) {
return 1.0 * z;
}
def code(x, y, z): return 1.0 * z
function code(x, y, z) return Float64(1.0 * z) end
function tmp = code(x, y, z) tmp = 1.0 * z; end
code[x_, y_, z_] := N[(1.0 * z), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot z
\end{array}
Initial program 97.3%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6464.8
Applied rewrites64.8%
Taylor expanded in y around 0
Applied rewrites37.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 2024324
(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))))