
(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 8 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 99.6%
+-commutative99.6%
sub-neg99.6%
distribute-rgt-in99.6%
associate-+l+99.6%
*-lft-identity99.6%
+-commutative99.6%
distribute-lft-neg-out99.6%
distribute-rgt-neg-out99.6%
*-commutative99.6%
distribute-lft-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.3e-5) (not (<= y 7.2e-17))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.3e-5) || !(y <= 7.2e-17)) {
tmp = y * (x - z);
} else {
tmp = 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 <= (-5.3d-5)) .or. (.not. (y <= 7.2d-17))) then
tmp = y * (x - z)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5.3e-5) || !(y <= 7.2e-17)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.3e-5) or not (y <= 7.2e-17): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.3e-5) || !(y <= 7.2e-17)) tmp = Float64(y * Float64(x - z)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.3e-5) || ~((y <= 7.2e-17))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.3e-5], N[Not[LessEqual[y, 7.2e-17]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.3 \cdot 10^{-5} \lor \neg \left(y \leq 7.2 \cdot 10^{-17}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -5.3000000000000001e-5 or 7.1999999999999999e-17 < y Initial program 99.1%
Taylor expanded in y around inf 97.3%
mul-1-neg97.3%
unsub-neg97.3%
Simplified97.3%
if -5.3000000000000001e-5 < y < 7.1999999999999999e-17Initial program 100.0%
Taylor expanded in y around 0 74.4%
Final simplification85.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00024) (not (<= y 1.25))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00024) || !(y <= 1.25)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
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 <= (-0.00024d0)) .or. (.not. (y <= 1.25d0))) then
tmp = y * (x - z)
else
tmp = z * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00024) || !(y <= 1.25)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00024) or not (y <= 1.25): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00024) || !(y <= 1.25)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00024) || ~((y <= 1.25))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00024], N[Not[LessEqual[y, 1.25]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00024 \lor \neg \left(y \leq 1.25\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -2.40000000000000006e-4 or 1.25 < y Initial program 99.1%
Taylor expanded in y around inf 99.8%
mul-1-neg99.8%
unsub-neg99.8%
Simplified99.8%
if -2.40000000000000006e-4 < y < 1.25Initial program 100.0%
Taylor expanded in x around 0 74.3%
Final simplification85.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -66000000000.0) (not (<= y 1.0))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -66000000000.0) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (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 <= (-66000000000.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (x - z)
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -66000000000.0) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -66000000000.0) or not (y <= 1.0): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -66000000000.0) || !(y <= 1.0)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -66000000000.0) || ~((y <= 1.0))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -66000000000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -66000000000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -6.6e10 or 1 < y Initial program 99.1%
Taylor expanded in y around inf 99.8%
mul-1-neg99.8%
unsub-neg99.8%
Simplified99.8%
if -6.6e10 < y < 1Initial program 100.0%
Taylor expanded in y around 0 100.0%
mul-1-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around inf 98.4%
*-commutative98.4%
Simplified98.4%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.3e-5) (not (<= y 1.55e-15))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.3e-5) || !(y <= 1.55e-15)) {
tmp = y * x;
} else {
tmp = 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 <= (-5.3d-5)) .or. (.not. (y <= 1.55d-15))) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5.3e-5) || !(y <= 1.55e-15)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.3e-5) or not (y <= 1.55e-15): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.3e-5) || !(y <= 1.55e-15)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.3e-5) || ~((y <= 1.55e-15))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.3e-5], N[Not[LessEqual[y, 1.55e-15]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.3 \cdot 10^{-5} \lor \neg \left(y \leq 1.55 \cdot 10^{-15}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -5.3000000000000001e-5 or 1.5499999999999999e-15 < y Initial program 99.1%
Taylor expanded in x around inf 52.4%
*-commutative52.4%
Simplified52.4%
if -5.3000000000000001e-5 < y < 1.5499999999999999e-15Initial program 100.0%
Taylor expanded in y around 0 74.4%
Final simplification64.2%
(FPCore (x y z) :precision binary64 (if (<= y -1.0) (* y (- z)) (if (<= y 6.4e-14) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = y * -z;
} else if (y <= 6.4e-14) {
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.0d0)) then
tmp = y * -z
else if (y <= 6.4d-14) 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.0) {
tmp = y * -z;
} else if (y <= 6.4e-14) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.0: tmp = y * -z elif y <= 6.4e-14: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.0) tmp = Float64(y * Float64(-z)); elseif (y <= 6.4e-14) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.0) tmp = y * -z; elseif (y <= 6.4e-14) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.0], N[(y * (-z)), $MachinePrecision], If[LessEqual[y, 6.4e-14], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{elif}\;y \leq 6.4 \cdot 10^{-14}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1Initial program 98.2%
Taylor expanded in y around inf 99.6%
mul-1-neg99.6%
unsub-neg99.6%
Simplified99.6%
Taylor expanded in x around 0 62.6%
associate-*r*62.6%
mul-1-neg62.6%
Simplified62.6%
if -1 < y < 6.4000000000000005e-14Initial program 100.0%
Taylor expanded in y around 0 73.8%
if 6.4000000000000005e-14 < y Initial program 100.0%
Taylor expanded in x around inf 59.6%
*-commutative59.6%
Simplified59.6%
Final simplification67.9%
(FPCore (x y z) :precision binary64 (+ z (* y (- x z))))
double code(double x, double y, double z) {
return z + (y * (x - 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 + (y * (x - z))
end function
public static double code(double x, double y, double z) {
return z + (y * (x - z));
}
def code(x, y, z): return z + (y * (x - z))
function code(x, y, z) return Float64(z + Float64(y * Float64(x - z))) end
function tmp = code(x, y, z) tmp = z + (y * (x - z)); end
code[x_, y_, z_] := N[(z + N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot \left(x - z\right)
\end{array}
Initial program 99.6%
Taylor expanded in y around 0 100.0%
mul-1-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
Final simplification100.0%
(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 99.6%
Taylor expanded in y around 0 41.7%
Final simplification41.7%
(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 2023301
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:herbie-target
(- z (* (- z x) y))
(+ (* x y) (* z (- 1.0 y))))