
(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.8%
+-commutative98.8%
+-lft-identity98.8%
cancel-sign-sub98.8%
cancel-sign-sub98.8%
+-lft-identity98.8%
distribute-lft-out--98.8%
*-rgt-identity98.8%
associate-+l-98.8%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- y))))
(if (<= y -2.8e+20)
t_0
(if (<= y -1.25e-39)
(* y x)
(if (<= y 1.45e-29)
z
(if (or (<= y 1600000000.0) (not (<= y 8e+192))) (* y x) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * -y;
double tmp;
if (y <= -2.8e+20) {
tmp = t_0;
} else if (y <= -1.25e-39) {
tmp = y * x;
} else if (y <= 1.45e-29) {
tmp = z;
} else if ((y <= 1600000000.0) || !(y <= 8e+192)) {
tmp = y * x;
} 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 = z * -y
if (y <= (-2.8d+20)) then
tmp = t_0
else if (y <= (-1.25d-39)) then
tmp = y * x
else if (y <= 1.45d-29) then
tmp = z
else if ((y <= 1600000000.0d0) .or. (.not. (y <= 8d+192))) then
tmp = y * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -y;
double tmp;
if (y <= -2.8e+20) {
tmp = t_0;
} else if (y <= -1.25e-39) {
tmp = y * x;
} else if (y <= 1.45e-29) {
tmp = z;
} else if ((y <= 1600000000.0) || !(y <= 8e+192)) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -y tmp = 0 if y <= -2.8e+20: tmp = t_0 elif y <= -1.25e-39: tmp = y * x elif y <= 1.45e-29: tmp = z elif (y <= 1600000000.0) or not (y <= 8e+192): tmp = y * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-y)) tmp = 0.0 if (y <= -2.8e+20) tmp = t_0; elseif (y <= -1.25e-39) tmp = Float64(y * x); elseif (y <= 1.45e-29) tmp = z; elseif ((y <= 1600000000.0) || !(y <= 8e+192)) tmp = Float64(y * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -y; tmp = 0.0; if (y <= -2.8e+20) tmp = t_0; elseif (y <= -1.25e-39) tmp = y * x; elseif (y <= 1.45e-29) tmp = z; elseif ((y <= 1600000000.0) || ~((y <= 8e+192))) tmp = y * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-y)), $MachinePrecision]}, If[LessEqual[y, -2.8e+20], t$95$0, If[LessEqual[y, -1.25e-39], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.45e-29], z, If[Or[LessEqual[y, 1600000000.0], N[Not[LessEqual[y, 8e+192]], $MachinePrecision]], N[(y * x), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -2.8 \cdot 10^{+20}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.25 \cdot 10^{-39}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-29}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 1600000000 \lor \neg \left(y \leq 8 \cdot 10^{+192}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.8e20 or 1.6e9 < y < 8.00000000000000033e192Initial program 100.0%
Taylor expanded in y around inf 99.2%
mul-1-neg99.2%
sub-neg99.2%
Simplified99.2%
Taylor expanded in x around 0 62.6%
neg-mul-162.6%
*-commutative62.6%
distribute-rgt-neg-in62.6%
Simplified62.6%
if -2.8e20 < y < -1.25e-39 or 1.45000000000000012e-29 < y < 1.6e9 or 8.00000000000000033e192 < y Initial program 94.6%
Taylor expanded in x around inf 64.7%
*-commutative64.7%
Simplified64.7%
if -1.25e-39 < y < 1.45000000000000012e-29Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 79.0%
Final simplification69.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -122000000000.0) (not (<= y 1.0))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -122000000000.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 <= (-122000000000.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 <= -122000000000.0) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -122000000000.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 <= -122000000000.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 <= -122000000000.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, -122000000000.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 -122000000000 \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 < -1.22e11 or 1 < y Initial program 97.7%
Taylor expanded in y around inf 98.7%
mul-1-neg98.7%
sub-neg98.7%
Simplified98.7%
if -1.22e11 < y < 1Initial program 100.0%
Taylor expanded in y around 0 97.9%
Final simplification98.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.1e-38) (not (<= y 7.5e-30))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.1e-38) || !(y <= 7.5e-30)) {
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 <= (-1.1d-38)) .or. (.not. (y <= 7.5d-30))) 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 <= -1.1e-38) || !(y <= 7.5e-30)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.1e-38) or not (y <= 7.5e-30): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.1e-38) || !(y <= 7.5e-30)) 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 <= -1.1e-38) || ~((y <= 7.5e-30))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.1e-38], N[Not[LessEqual[y, 7.5e-30]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{-38} \lor \neg \left(y \leq 7.5 \cdot 10^{-30}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.10000000000000004e-38 or 7.5000000000000006e-30 < y Initial program 98.0%
Taylor expanded in y around inf 93.6%
mul-1-neg93.6%
sub-neg93.6%
Simplified93.6%
if -1.10000000000000004e-38 < y < 7.5000000000000006e-30Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 79.0%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -8e-41) (not (<= y 3e-29))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8e-41) || !(y <= 3e-29)) {
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 <= (-8d-41)) .or. (.not. (y <= 3d-29))) 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 <= -8e-41) || !(y <= 3e-29)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8e-41) or not (y <= 3e-29): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8e-41) || !(y <= 3e-29)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -8e-41) || ~((y <= 3e-29))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8e-41], N[Not[LessEqual[y, 3e-29]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{-41} \lor \neg \left(y \leq 3 \cdot 10^{-29}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -8.00000000000000005e-41 or 3.0000000000000003e-29 < y Initial program 98.0%
Taylor expanded in x around inf 49.7%
*-commutative49.7%
Simplified49.7%
if -8.00000000000000005e-41 < y < 3.0000000000000003e-29Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 79.0%
Final simplification61.4%
(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.8%
Taylor expanded in y around 0 72.1%
Taylor expanded in x around 0 35.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 2024149
(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))))