
(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 97.7%
+-commutative97.7%
sub-neg97.7%
distribute-rgt-in97.6%
*-lft-identity97.6%
associate-+l+97.6%
+-commutative97.6%
*-commutative97.6%
neg-mul-197.6%
associate-*r*97.6%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1.9e-35)
(* y x)
(if (<= y -3.25e-57)
z
(if (<= y -1.8e-70)
(* y x)
(if (<= y 1.2e-60) z (if (<= y 850.0) (* y x) (* z (- y))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e-35) {
tmp = y * x;
} else if (y <= -3.25e-57) {
tmp = z;
} else if (y <= -1.8e-70) {
tmp = y * x;
} else if (y <= 1.2e-60) {
tmp = z;
} else if (y <= 850.0) {
tmp = y * x;
} else {
tmp = z * -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 <= (-1.9d-35)) then
tmp = y * x
else if (y <= (-3.25d-57)) then
tmp = z
else if (y <= (-1.8d-70)) then
tmp = y * x
else if (y <= 1.2d-60) then
tmp = z
else if (y <= 850.0d0) then
tmp = y * x
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e-35) {
tmp = y * x;
} else if (y <= -3.25e-57) {
tmp = z;
} else if (y <= -1.8e-70) {
tmp = y * x;
} else if (y <= 1.2e-60) {
tmp = z;
} else if (y <= 850.0) {
tmp = y * x;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.9e-35: tmp = y * x elif y <= -3.25e-57: tmp = z elif y <= -1.8e-70: tmp = y * x elif y <= 1.2e-60: tmp = z elif y <= 850.0: tmp = y * x else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.9e-35) tmp = Float64(y * x); elseif (y <= -3.25e-57) tmp = z; elseif (y <= -1.8e-70) tmp = Float64(y * x); elseif (y <= 1.2e-60) tmp = z; elseif (y <= 850.0) tmp = Float64(y * x); else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.9e-35) tmp = y * x; elseif (y <= -3.25e-57) tmp = z; elseif (y <= -1.8e-70) tmp = y * x; elseif (y <= 1.2e-60) tmp = z; elseif (y <= 850.0) tmp = y * x; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.9e-35], N[(y * x), $MachinePrecision], If[LessEqual[y, -3.25e-57], z, If[LessEqual[y, -1.8e-70], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.2e-60], z, If[LessEqual[y, 850.0], N[(y * x), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{-35}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -3.25 \cdot 10^{-57}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -1.8 \cdot 10^{-70}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{-60}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 850:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < -1.9000000000000001e-35 or -3.24999999999999996e-57 < y < -1.8000000000000001e-70 or 1.20000000000000005e-60 < y < 850Initial program 92.8%
Taylor expanded in x around inf 61.0%
if -1.9000000000000001e-35 < y < -3.24999999999999996e-57 or -1.8000000000000001e-70 < y < 1.20000000000000005e-60Initial program 100.0%
Taylor expanded in y around 0 75.3%
if 850 < y Initial program 98.5%
Taylor expanded in y around inf 97.1%
mul-1-neg97.1%
+-commutative97.1%
sub-neg97.1%
Simplified97.1%
Taylor expanded in x around 0 58.6%
associate-*r*58.6%
neg-mul-158.6%
Simplified58.6%
Final simplification67.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x z))))
(if (<= y -8.6e-34)
t_0
(if (<= y -3.25e-57)
z
(if (<= y -2.25e-70) (* y x) (if (<= y 5.2e-55) z t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -8.6e-34) {
tmp = t_0;
} else if (y <= -3.25e-57) {
tmp = z;
} else if (y <= -2.25e-70) {
tmp = y * x;
} else if (y <= 5.2e-55) {
tmp = z;
} 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 = y * (x - z)
if (y <= (-8.6d-34)) then
tmp = t_0
else if (y <= (-3.25d-57)) then
tmp = z
else if (y <= (-2.25d-70)) then
tmp = y * x
else if (y <= 5.2d-55) then
tmp = z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x - z);
double tmp;
if (y <= -8.6e-34) {
tmp = t_0;
} else if (y <= -3.25e-57) {
tmp = z;
} else if (y <= -2.25e-70) {
tmp = y * x;
} else if (y <= 5.2e-55) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x - z) tmp = 0 if y <= -8.6e-34: tmp = t_0 elif y <= -3.25e-57: tmp = z elif y <= -2.25e-70: tmp = y * x elif y <= 5.2e-55: tmp = z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x - z)) tmp = 0.0 if (y <= -8.6e-34) tmp = t_0; elseif (y <= -3.25e-57) tmp = z; elseif (y <= -2.25e-70) tmp = Float64(y * x); elseif (y <= 5.2e-55) tmp = z; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x - z); tmp = 0.0; if (y <= -8.6e-34) tmp = t_0; elseif (y <= -3.25e-57) tmp = z; elseif (y <= -2.25e-70) tmp = y * x; elseif (y <= 5.2e-55) tmp = z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8.6e-34], t$95$0, If[LessEqual[y, -3.25e-57], z, If[LessEqual[y, -2.25e-70], N[(y * x), $MachinePrecision], If[LessEqual[y, 5.2e-55], z, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -8.6 \cdot 10^{-34}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -3.25 \cdot 10^{-57}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -2.25 \cdot 10^{-70}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-55}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -8.5999999999999999e-34 or 5.1999999999999998e-55 < y Initial program 95.3%
Taylor expanded in y around inf 94.1%
mul-1-neg94.1%
+-commutative94.1%
sub-neg94.1%
Simplified94.1%
if -8.5999999999999999e-34 < y < -3.24999999999999996e-57 or -2.25000000000000011e-70 < y < 5.1999999999999998e-55Initial program 100.0%
Taylor expanded in y around 0 74.9%
if -3.24999999999999996e-57 < y < -2.25000000000000011e-70Initial program 100.0%
Taylor expanded in x around inf 92.5%
Final simplification84.8%
(FPCore (x y z)
:precision binary64
(if (<= y -8.2e-35)
(* y x)
(if (<= y -1.52e-56)
z
(if (<= y -4.6e-70) (* y x) (if (<= y 2.1e-59) z (* y x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.2e-35) {
tmp = y * x;
} else if (y <= -1.52e-56) {
tmp = z;
} else if (y <= -4.6e-70) {
tmp = y * x;
} else if (y <= 2.1e-59) {
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 <= (-8.2d-35)) then
tmp = y * x
else if (y <= (-1.52d-56)) then
tmp = z
else if (y <= (-4.6d-70)) then
tmp = y * x
else if (y <= 2.1d-59) 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 <= -8.2e-35) {
tmp = y * x;
} else if (y <= -1.52e-56) {
tmp = z;
} else if (y <= -4.6e-70) {
tmp = y * x;
} else if (y <= 2.1e-59) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.2e-35: tmp = y * x elif y <= -1.52e-56: tmp = z elif y <= -4.6e-70: tmp = y * x elif y <= 2.1e-59: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.2e-35) tmp = Float64(y * x); elseif (y <= -1.52e-56) tmp = z; elseif (y <= -4.6e-70) tmp = Float64(y * x); elseif (y <= 2.1e-59) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.2e-35) tmp = y * x; elseif (y <= -1.52e-56) tmp = z; elseif (y <= -4.6e-70) tmp = y * x; elseif (y <= 2.1e-59) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.2e-35], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.52e-56], z, If[LessEqual[y, -4.6e-70], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.1e-59], z, N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.2 \cdot 10^{-35}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.52 \cdot 10^{-56}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq -4.6 \cdot 10^{-70}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{-59}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -8.20000000000000052e-35 or -1.5199999999999999e-56 < y < -4.60000000000000001e-70 or 2.09999999999999997e-59 < y Initial program 95.5%
Taylor expanded in x around inf 52.3%
if -8.20000000000000052e-35 < y < -1.5199999999999999e-56 or -4.60000000000000001e-70 < y < 2.09999999999999997e-59Initial program 100.0%
Taylor expanded in y around 0 75.3%
Final simplification63.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.7e-10) (not (<= z 75.0))) (* z (- 1.0 y)) (* y (- x z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.7e-10) || !(z <= 75.0)) {
tmp = z * (1.0 - y);
} else {
tmp = y * (x - 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 ((z <= (-1.7d-10)) .or. (.not. (z <= 75.0d0))) then
tmp = z * (1.0d0 - y)
else
tmp = y * (x - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.7e-10) || !(z <= 75.0)) {
tmp = z * (1.0 - y);
} else {
tmp = y * (x - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.7e-10) or not (z <= 75.0): tmp = z * (1.0 - y) else: tmp = y * (x - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.7e-10) || !(z <= 75.0)) tmp = Float64(z * Float64(1.0 - y)); else tmp = Float64(y * Float64(x - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.7e-10) || ~((z <= 75.0))) tmp = z * (1.0 - y); else tmp = y * (x - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.7e-10], N[Not[LessEqual[z, 75.0]], $MachinePrecision]], N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{-10} \lor \neg \left(z \leq 75\right):\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x - z\right)\\
\end{array}
\end{array}
if z < -1.70000000000000007e-10 or 75 < z Initial program 95.3%
Taylor expanded in x around 0 90.4%
if -1.70000000000000007e-10 < z < 75Initial program 100.0%
Taylor expanded in y around inf 76.2%
mul-1-neg76.2%
+-commutative76.2%
sub-neg76.2%
Simplified76.2%
Final simplification83.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 7.5e-10))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 7.5e-10)) {
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 <= (-1.0d0)) .or. (.not. (y <= 7.5d-10))) 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 <= -1.0) || !(y <= 7.5e-10)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 7.5e-10): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 7.5e-10)) 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 <= -1.0) || ~((y <= 7.5e-10))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 7.5e-10]], $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 -1 \lor \neg \left(y \leq 7.5 \cdot 10^{-10}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -1 or 7.49999999999999995e-10 < y Initial program 94.7%
Taylor expanded in y around inf 97.8%
mul-1-neg97.8%
+-commutative97.8%
sub-neg97.8%
Simplified97.8%
if -1 < y < 7.49999999999999995e-10Initial program 100.0%
+-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-+l+100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around inf 99.8%
Final simplification98.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 97.7%
+-commutative97.7%
sub-neg97.7%
distribute-rgt-in97.6%
*-lft-identity97.6%
associate-+l+97.6%
+-commutative97.6%
*-commutative97.6%
neg-mul-197.6%
associate-*r*97.6%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-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 97.7%
Taylor expanded in y around 0 39.5%
Final simplification39.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 2023171
(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))))