
(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 98.8%
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 (<= y -2.05e+207) (* (- z) y) (if (or (<= y -1.62e-100) (not (<= y 2.5e-12))) (* y x) (* 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.05e+207) {
tmp = -z * y;
} else if ((y <= -1.62e-100) || !(y <= 2.5e-12)) {
tmp = y * x;
} 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 <= (-2.05d+207)) then
tmp = -z * y
else if ((y <= (-1.62d-100)) .or. (.not. (y <= 2.5d-12))) then
tmp = y * x
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 <= -2.05e+207) {
tmp = -z * y;
} else if ((y <= -1.62e-100) || !(y <= 2.5e-12)) {
tmp = y * x;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.05e+207: tmp = -z * y elif (y <= -1.62e-100) or not (y <= 2.5e-12): tmp = y * x else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.05e+207) tmp = Float64(Float64(-z) * y); elseif ((y <= -1.62e-100) || !(y <= 2.5e-12)) tmp = Float64(y * x); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.05e+207) tmp = -z * y; elseif ((y <= -1.62e-100) || ~((y <= 2.5e-12))) tmp = y * x; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.05e+207], N[((-z) * y), $MachinePrecision], If[Or[LessEqual[y, -1.62e-100], N[Not[LessEqual[y, 2.5e-12]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.05 \cdot 10^{+207}:\\
\;\;\;\;\left(-z\right) \cdot y\\
\mathbf{elif}\;y \leq -1.62 \cdot 10^{-100} \lor \neg \left(y \leq 2.5 \cdot 10^{-12}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if y < -2.05e207Initial program 100.0%
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--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites82.8%
if -2.05e207 < y < -1.6200000000000001e-100 or 2.49999999999999985e-12 < y Initial program 97.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6445.8
Applied rewrites45.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6458.4
Applied rewrites58.4%
if -1.6200000000000001e-100 < y < 2.49999999999999985e-12Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6480.7
Applied rewrites80.7%
Taylor expanded in y around 0
Applied rewrites80.5%
Final simplification68.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.8e-103) (not (<= y 2.5e-12))) (* (- x z) y) (* (- 1.0 y) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.8e-103) || !(y <= 2.5e-12)) {
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 <= (-8.8d-103)) .or. (.not. (y <= 2.5d-12))) 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 <= -8.8e-103) || !(y <= 2.5e-12)) {
tmp = (x - z) * y;
} else {
tmp = (1.0 - y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.8e-103) or not (y <= 2.5e-12): tmp = (x - z) * y else: tmp = (1.0 - y) * z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.8e-103) || !(y <= 2.5e-12)) 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 <= -8.8e-103) || ~((y <= 2.5e-12))) tmp = (x - z) * y; else tmp = (1.0 - y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.8e-103], N[Not[LessEqual[y, 2.5e-12]], $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 -8.8 \cdot 10^{-103} \lor \neg \left(y \leq 2.5 \cdot 10^{-12}\right):\\
\;\;\;\;\left(x - z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - y\right) \cdot z\\
\end{array}
\end{array}
if y < -8.7999999999999997e-103 or 2.49999999999999985e-12 < y Initial program 98.0%
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--.f6494.0
Applied rewrites94.0%
if -8.7999999999999997e-103 < y < 2.49999999999999985e-12Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6480.7
Applied rewrites80.7%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.5e-197) (not (<= z 5.5e-96))) (* (- 1.0 y) z) (* y x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.5e-197) || !(z <= 5.5e-96)) {
tmp = (1.0 - y) * 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 ((z <= (-4.5d-197)) .or. (.not. (z <= 5.5d-96))) then
tmp = (1.0d0 - y) * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.5e-197) || !(z <= 5.5e-96)) {
tmp = (1.0 - y) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.5e-197) or not (z <= 5.5e-96): tmp = (1.0 - y) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.5e-197) || !(z <= 5.5e-96)) tmp = Float64(Float64(1.0 - y) * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.5e-197) || ~((z <= 5.5e-96))) tmp = (1.0 - y) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.5e-197], N[Not[LessEqual[z, 5.5e-96]], $MachinePrecision]], N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-197} \lor \neg \left(z \leq 5.5 \cdot 10^{-96}\right):\\
\;\;\;\;\left(1 - y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if z < -4.5000000000000001e-197 or 5.4999999999999997e-96 < z Initial program 98.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6479.1
Applied rewrites79.1%
if -4.5000000000000001e-197 < z < 5.4999999999999997e-96Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6418.6
Applied rewrites18.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6483.6
Applied rewrites83.6%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.62e-100) (not (<= y 2.5e-12))) (* y x) (* 1.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.62e-100) || !(y <= 2.5e-12)) {
tmp = y * x;
} 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.62d-100)) .or. (.not. (y <= 2.5d-12))) then
tmp = y * x
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.62e-100) || !(y <= 2.5e-12)) {
tmp = y * x;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.62e-100) or not (y <= 2.5e-12): tmp = y * x else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.62e-100) || !(y <= 2.5e-12)) tmp = Float64(y * x); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.62e-100) || ~((y <= 2.5e-12))) tmp = y * x; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.62e-100], N[Not[LessEqual[y, 2.5e-12]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.62 \cdot 10^{-100} \lor \neg \left(y \leq 2.5 \cdot 10^{-12}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if y < -1.6200000000000001e-100 or 2.49999999999999985e-12 < y Initial program 98.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6449.9
Applied rewrites49.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6456.2
Applied rewrites56.2%
if -1.6200000000000001e-100 < y < 2.49999999999999985e-12Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6480.7
Applied rewrites80.7%
Taylor expanded in y around 0
Applied rewrites80.5%
Final simplification66.0%
(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 98.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6462.3
Applied rewrites62.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6442.5
Applied rewrites42.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 2024323
(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))))