
(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 7 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.2%
+-commutative99.2%
+-lft-identity99.2%
cancel-sign-sub99.2%
cancel-sign-sub99.2%
+-lft-identity99.2%
distribute-lft-out--99.2%
*-rgt-identity99.2%
associate-+l-99.2%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.2e+167) (* y x) (if (<= y -1.3e-17) (* z (- y)) (if (<= y 1.55e-20) z (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.2e+167) {
tmp = y * x;
} else if (y <= -1.3e-17) {
tmp = z * -y;
} else if (y <= 1.55e-20) {
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.2d+167)) then
tmp = y * x
else if (y <= (-1.3d-17)) then
tmp = z * -y
else if (y <= 1.55d-20) 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.2e+167) {
tmp = y * x;
} else if (y <= -1.3e-17) {
tmp = z * -y;
} else if (y <= 1.55e-20) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.2e+167: tmp = y * x elif y <= -1.3e-17: tmp = z * -y elif y <= 1.55e-20: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.2e+167) tmp = Float64(y * x); elseif (y <= -1.3e-17) tmp = Float64(z * Float64(-y)); elseif (y <= 1.55e-20) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.2e+167) tmp = y * x; elseif (y <= -1.3e-17) tmp = z * -y; elseif (y <= 1.55e-20) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.2e+167], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.3e-17], N[(z * (-y)), $MachinePrecision], If[LessEqual[y, 1.55e-20], z, N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{+167}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.3 \cdot 10^{-17}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-20}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.19999999999999999e167 or 1.55e-20 < y Initial program 97.8%
Taylor expanded in x around inf 60.7%
*-commutative60.7%
Simplified60.7%
if -1.19999999999999999e167 < y < -1.30000000000000002e-17Initial program 100.0%
Taylor expanded in y around inf 95.5%
mul-1-neg95.5%
sub-neg95.5%
Simplified95.5%
Taylor expanded in x around 0 56.8%
associate-*r*56.8%
*-commutative56.8%
mul-1-neg56.8%
Simplified56.8%
if -1.30000000000000002e-17 < y < 1.55e-20Initial program 100.0%
Taylor expanded in y around 0 74.2%
Final simplification66.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.05e-22) (not (<= y 4.5e-20))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.05e-22) || !(y <= 4.5e-20)) {
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.05d-22)) .or. (.not. (y <= 4.5d-20))) 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.05e-22) || !(y <= 4.5e-20)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.05e-22) or not (y <= 4.5e-20): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.05e-22) || !(y <= 4.5e-20)) 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.05e-22) || ~((y <= 4.5e-20))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.05e-22], N[Not[LessEqual[y, 4.5e-20]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{-22} \lor \neg \left(y \leq 4.5 \cdot 10^{-20}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.05000000000000004e-22 or 4.5000000000000001e-20 < y Initial program 98.6%
Taylor expanded in y around inf 97.3%
mul-1-neg97.3%
sub-neg97.3%
Simplified97.3%
if -1.05000000000000004e-22 < y < 4.5000000000000001e-20Initial program 100.0%
Taylor expanded in y around 0 74.2%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.15e-26) (not (<= y 1750000.0))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.15e-26) || !(y <= 1750000.0)) {
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 <= (-1.15d-26)) .or. (.not. (y <= 1750000.0d0))) 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 <= -1.15e-26) || !(y <= 1750000.0)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.15e-26) or not (y <= 1750000.0): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.15e-26) || !(y <= 1750000.0)) 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 <= -1.15e-26) || ~((y <= 1750000.0))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.15e-26], N[Not[LessEqual[y, 1750000.0]], $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 -1.15 \cdot 10^{-26} \lor \neg \left(y \leq 1750000\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -1.15000000000000004e-26 or 1.75e6 < y Initial program 98.5%
Taylor expanded in y around inf 98.4%
mul-1-neg98.4%
sub-neg98.4%
Simplified98.4%
if -1.15000000000000004e-26 < y < 1.75e6Initial program 100.0%
Taylor expanded in x around 0 74.2%
Final simplification87.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.4) (not (<= y 1.0))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.4) || !(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 <= (-1.4d0)) .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 <= -1.4) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.4) 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 <= -1.4) || !(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 <= -1.4) || ~((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, -1.4], 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 -1.4 \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.3999999999999999 or 1 < y Initial program 98.5%
Taylor expanded in y around inf 97.2%
mul-1-neg97.2%
sub-neg97.2%
Simplified97.2%
if -1.3999999999999999 < y < 1Initial program 100.0%
+-commutative100.0%
+-lft-identity100.0%
cancel-sign-sub100.0%
cancel-sign-sub100.0%
+-lft-identity100.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 100.0%
mul-1-neg100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
Simplified100.0%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.8e-19) (not (<= y 3.3e-16))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8e-19) || !(y <= 3.3e-16)) {
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.8d-19)) .or. (.not. (y <= 3.3d-16))) 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.8e-19) || !(y <= 3.3e-16)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.8e-19) or not (y <= 3.3e-16): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.8e-19) || !(y <= 3.3e-16)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.8e-19) || ~((y <= 3.3e-16))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.8e-19], N[Not[LessEqual[y, 3.3e-16]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-19} \lor \neg \left(y \leq 3.3 \cdot 10^{-16}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.8000000000000001e-19 or 3.29999999999999988e-16 < y Initial program 98.6%
Taylor expanded in x around inf 53.7%
*-commutative53.7%
Simplified53.7%
if -1.8000000000000001e-19 < y < 3.29999999999999988e-16Initial program 100.0%
Taylor expanded in y around 0 74.2%
Final simplification63.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.2%
Taylor expanded in y around 0 35.4%
Final simplification35.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 2024047
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:alt
(- z (* (- z x) y))
(+ (* x y) (* z (- 1.0 y))))