
(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 (- z x))))
double code(double x, double y, double z) {
return z - (y * (z - x));
}
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 * (z - x))
end function
public static double code(double x, double y, double z) {
return z - (y * (z - x));
}
def code(x, y, z): return z - (y * (z - x))
function code(x, y, z) return Float64(z - Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = z - (y * (z - x)); end
code[x_, y_, z_] := N[(z - N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - y \cdot \left(z - x\right)
\end{array}
Initial program 99.6%
+-commutative99.6%
distribute-lft-out--99.6%
*-rgt-identity99.6%
associate-+l-99.6%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -6.8e-121)
(* y x)
(if (<= y 3.4e-18)
z
(if (or (<= y 3.8e+25) (not (<= y 1.75e+260))) (* y x) (* y (- z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e-121) {
tmp = y * x;
} else if (y <= 3.4e-18) {
tmp = z;
} else if ((y <= 3.8e+25) || !(y <= 1.75e+260)) {
tmp = y * x;
} else {
tmp = 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.8d-121)) then
tmp = y * x
else if (y <= 3.4d-18) then
tmp = z
else if ((y <= 3.8d+25) .or. (.not. (y <= 1.75d+260))) then
tmp = y * x
else
tmp = y * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e-121) {
tmp = y * x;
} else if (y <= 3.4e-18) {
tmp = z;
} else if ((y <= 3.8e+25) || !(y <= 1.75e+260)) {
tmp = y * x;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.8e-121: tmp = y * x elif y <= 3.4e-18: tmp = z elif (y <= 3.8e+25) or not (y <= 1.75e+260): tmp = y * x else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.8e-121) tmp = Float64(y * x); elseif (y <= 3.4e-18) tmp = z; elseif ((y <= 3.8e+25) || !(y <= 1.75e+260)) tmp = Float64(y * x); else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.8e-121) tmp = y * x; elseif (y <= 3.4e-18) tmp = z; elseif ((y <= 3.8e+25) || ~((y <= 1.75e+260))) tmp = y * x; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.8e-121], N[(y * x), $MachinePrecision], If[LessEqual[y, 3.4e-18], z, If[Or[LessEqual[y, 3.8e+25], N[Not[LessEqual[y, 1.75e+260]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{-121}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{-18}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{+25} \lor \neg \left(y \leq 1.75 \cdot 10^{+260}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if y < -6.80000000000000003e-121 or 3.40000000000000001e-18 < y < 3.8e25 or 1.7499999999999999e260 < y Initial program 98.9%
Taylor expanded in x around inf 64.8%
*-commutative64.8%
Simplified64.8%
if -6.80000000000000003e-121 < y < 3.40000000000000001e-18Initial program 100.0%
Taylor expanded in y around 0 78.6%
if 3.8e25 < y < 1.7499999999999999e260Initial program 100.0%
Taylor expanded in y around inf 100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 61.9%
associate-*r*61.9%
mul-1-neg61.9%
Simplified61.9%
Final simplification70.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.05e-120) (not (<= y 3.35e-18))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.05e-120) || !(y <= 3.35e-18)) {
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 <= (-2.05d-120)) .or. (.not. (y <= 3.35d-18))) 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 <= -2.05e-120) || !(y <= 3.35e-18)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.05e-120) or not (y <= 3.35e-18): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.05e-120) || !(y <= 3.35e-18)) 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 <= -2.05e-120) || ~((y <= 3.35e-18))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.05e-120], N[Not[LessEqual[y, 3.35e-18]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.05 \cdot 10^{-120} \lor \neg \left(y \leq 3.35 \cdot 10^{-18}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -2.05000000000000017e-120 or 3.3499999999999999e-18 < y Initial program 99.3%
Taylor expanded in y around inf 95.4%
neg-mul-195.4%
unsub-neg95.4%
Simplified95.4%
if -2.05000000000000017e-120 < y < 3.3499999999999999e-18Initial program 100.0%
Taylor expanded in y around 0 78.6%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -30000000000.0) (not (<= y 3.6e-18))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -30000000000.0) || !(y <= 3.6e-18)) {
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 <= (-30000000000.0d0)) .or. (.not. (y <= 3.6d-18))) 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 <= -30000000000.0) || !(y <= 3.6e-18)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -30000000000.0) or not (y <= 3.6e-18): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -30000000000.0) || !(y <= 3.6e-18)) 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 <= -30000000000.0) || ~((y <= 3.6e-18))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -30000000000.0], N[Not[LessEqual[y, 3.6e-18]], $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 -30000000000 \lor \neg \left(y \leq 3.6 \cdot 10^{-18}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -3e10 or 3.6000000000000001e-18 < y Initial program 99.2%
Taylor expanded in y around inf 100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
if -3e10 < y < 3.6000000000000001e-18Initial program 100.0%
+-commutative100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
associate-+l-100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 99.5%
mul-1-neg99.5%
distribute-lft-neg-out99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.2e-122) (not (<= y 3.35e-18))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.2e-122) || !(y <= 3.35e-18)) {
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 <= (-1.2d-122)) .or. (.not. (y <= 3.35d-18))) 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 <= -1.2e-122) || !(y <= 3.35e-18)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.2e-122) or not (y <= 3.35e-18): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.2e-122) || !(y <= 3.35e-18)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.2e-122) || ~((y <= 3.35e-18))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.2e-122], N[Not[LessEqual[y, 3.35e-18]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{-122} \lor \neg \left(y \leq 3.35 \cdot 10^{-18}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.19999999999999994e-122 or 3.3499999999999999e-18 < y Initial program 99.3%
Taylor expanded in x around inf 58.8%
*-commutative58.8%
Simplified58.8%
if -1.19999999999999994e-122 < y < 3.3499999999999999e-18Initial program 100.0%
Taylor expanded in y around 0 78.6%
Final simplification67.8%
(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 39.4%
Final simplification39.4%
(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 2023336
(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))))