
(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 (+ 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 98.4%
distribute-lft-out--98.4%
*-rgt-identity98.4%
cancel-sign-sub-inv98.4%
+-commutative98.4%
associate-+r+98.4%
+-commutative98.4%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
fma-udef100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -3.4e-10)
(* y x)
(if (<= y 2.8e-95)
z
(if (<= y 3.8e+34) (* y x) (if (<= y 2.8e+111) (* z (- y)) (* y x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.4e-10) {
tmp = y * x;
} else if (y <= 2.8e-95) {
tmp = z;
} else if (y <= 3.8e+34) {
tmp = y * x;
} else if (y <= 2.8e+111) {
tmp = z * -y;
} 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 <= (-3.4d-10)) then
tmp = y * x
else if (y <= 2.8d-95) then
tmp = z
else if (y <= 3.8d+34) then
tmp = y * x
else if (y <= 2.8d+111) then
tmp = z * -y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.4e-10) {
tmp = y * x;
} else if (y <= 2.8e-95) {
tmp = z;
} else if (y <= 3.8e+34) {
tmp = y * x;
} else if (y <= 2.8e+111) {
tmp = z * -y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.4e-10: tmp = y * x elif y <= 2.8e-95: tmp = z elif y <= 3.8e+34: tmp = y * x elif y <= 2.8e+111: tmp = z * -y else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.4e-10) tmp = Float64(y * x); elseif (y <= 2.8e-95) tmp = z; elseif (y <= 3.8e+34) tmp = Float64(y * x); elseif (y <= 2.8e+111) tmp = Float64(z * Float64(-y)); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.4e-10) tmp = y * x; elseif (y <= 2.8e-95) tmp = z; elseif (y <= 3.8e+34) tmp = y * x; elseif (y <= 2.8e+111) tmp = z * -y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.4e-10], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.8e-95], z, If[LessEqual[y, 3.8e+34], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.8e+111], N[(z * (-y)), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{-10}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{-95}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{+34}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{+111}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -3.40000000000000015e-10 or 2.7999999999999999e-95 < y < 3.8000000000000001e34 or 2.7999999999999999e111 < y Initial program 97.6%
Taylor expanded in x around inf 59.3%
*-commutative59.3%
Simplified59.3%
if -3.40000000000000015e-10 < y < 2.7999999999999999e-95Initial program 100.0%
Taylor expanded in y around 0 72.7%
if 3.8000000000000001e34 < y < 2.7999999999999999e111Initial program 93.3%
Taylor expanded in x around 0 68.2%
distribute-lft-out--68.2%
*-rgt-identity68.2%
Simplified68.2%
Taylor expanded in y around inf 68.2%
mul-1-neg68.2%
*-commutative68.2%
distribute-rgt-neg-in68.2%
Simplified68.2%
Final simplification65.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.5e-10) (not (<= y 1.4e-94))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.5e-10) || !(y <= 1.4e-94)) {
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 <= (-3.5d-10)) .or. (.not. (y <= 1.4d-94))) 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 <= -3.5e-10) || !(y <= 1.4e-94)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.5e-10) or not (y <= 1.4e-94): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.5e-10) || !(y <= 1.4e-94)) 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 <= -3.5e-10) || ~((y <= 1.4e-94))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.5e-10], N[Not[LessEqual[y, 1.4e-94]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{-10} \lor \neg \left(y \leq 1.4 \cdot 10^{-94}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -3.4999999999999998e-10 or 1.3999999999999999e-94 < y Initial program 97.1%
Taylor expanded in y around inf 91.3%
mul-1-neg91.3%
sub-neg91.3%
Simplified91.3%
if -3.4999999999999998e-10 < y < 1.3999999999999999e-94Initial program 100.0%
Taylor expanded in y around 0 72.7%
Final simplification82.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -14500000000000.0) (not (<= y 3.4e-94))) (* y (- x z)) (- z (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -14500000000000.0) || !(y <= 3.4e-94)) {
tmp = y * (x - z);
} else {
tmp = z - (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 <= (-14500000000000.0d0)) .or. (.not. (y <= 3.4d-94))) then
tmp = y * (x - z)
else
tmp = z - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -14500000000000.0) || !(y <= 3.4e-94)) {
tmp = y * (x - z);
} else {
tmp = z - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -14500000000000.0) or not (y <= 3.4e-94): tmp = y * (x - z) else: tmp = z - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -14500000000000.0) || !(y <= 3.4e-94)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -14500000000000.0) || ~((y <= 3.4e-94))) tmp = y * (x - z); else tmp = z - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -14500000000000.0], N[Not[LessEqual[y, 3.4e-94]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -14500000000000 \lor \neg \left(y \leq 3.4 \cdot 10^{-94}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z - y \cdot z\\
\end{array}
\end{array}
if y < -1.45e13 or 3.3999999999999998e-94 < y Initial program 97.0%
Taylor expanded in y around inf 92.4%
mul-1-neg92.4%
sub-neg92.4%
Simplified92.4%
if -1.45e13 < y < 3.3999999999999998e-94Initial program 100.0%
Taylor expanded in x around 0 73.0%
distribute-lft-out--73.0%
*-rgt-identity73.0%
Simplified73.0%
Final simplification83.3%
(FPCore (x y z) :precision binary64 (if (<= y -4e-10) (* y x) (if (<= y 2.05e-94) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e-10) {
tmp = y * x;
} else if (y <= 2.05e-94) {
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 <= (-4d-10)) then
tmp = y * x
else if (y <= 2.05d-94) 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 <= -4e-10) {
tmp = y * x;
} else if (y <= 2.05e-94) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4e-10: tmp = y * x elif y <= 2.05e-94: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4e-10) tmp = Float64(y * x); elseif (y <= 2.05e-94) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4e-10) tmp = y * x; elseif (y <= 2.05e-94) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4e-10], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.05e-94], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-10}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2.05 \cdot 10^{-94}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -4.00000000000000015e-10 or 2.05e-94 < y Initial program 97.1%
Taylor expanded in x around inf 56.8%
*-commutative56.8%
Simplified56.8%
if -4.00000000000000015e-10 < y < 2.05e-94Initial program 100.0%
Taylor expanded in y around 0 72.7%
Final simplification64.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 98.4%
Taylor expanded in y around 0 38.2%
Final simplification38.2%
(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 2023293
(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))))