
(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 (- 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%
+-commutative98.4%
+-lft-identity98.4%
cancel-sign-sub98.4%
cancel-sign-sub98.4%
+-lft-identity98.4%
distribute-lft-out--98.4%
*-rgt-identity98.4%
associate-+l-98.4%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.25e-23) (* y x) (if (<= y 5.2e-14) z (if (<= y 4.7e+49) (* y x) (* z (- y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.25e-23) {
tmp = y * x;
} else if (y <= 5.2e-14) {
tmp = z;
} else if (y <= 4.7e+49) {
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.25d-23)) then
tmp = y * x
else if (y <= 5.2d-14) then
tmp = z
else if (y <= 4.7d+49) 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.25e-23) {
tmp = y * x;
} else if (y <= 5.2e-14) {
tmp = z;
} else if (y <= 4.7e+49) {
tmp = y * x;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.25e-23: tmp = y * x elif y <= 5.2e-14: tmp = z elif y <= 4.7e+49: tmp = y * x else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.25e-23) tmp = Float64(y * x); elseif (y <= 5.2e-14) tmp = z; elseif (y <= 4.7e+49) 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.25e-23) tmp = y * x; elseif (y <= 5.2e-14) tmp = z; elseif (y <= 4.7e+49) tmp = y * x; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.25e-23], N[(y * x), $MachinePrecision], If[LessEqual[y, 5.2e-14], z, If[LessEqual[y, 4.7e+49], N[(y * x), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.25 \cdot 10^{-23}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-14}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 4.7 \cdot 10^{+49}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < -1.2500000000000001e-23 or 5.19999999999999993e-14 < y < 4.6999999999999997e49Initial program 96.3%
Taylor expanded in x around inf 63.0%
*-commutative63.0%
Simplified63.0%
if -1.2500000000000001e-23 < y < 5.19999999999999993e-14Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 77.7%
if 4.6999999999999997e49 < y Initial program 98.2%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 60.3%
neg-mul-160.3%
*-commutative60.3%
distribute-rgt-neg-in60.3%
Simplified60.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -15600000000000.0) (not (<= y 0.86))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -15600000000000.0) || !(y <= 0.86)) {
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 <= (-15600000000000.0d0)) .or. (.not. (y <= 0.86d0))) 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 <= -15600000000000.0) || !(y <= 0.86)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -15600000000000.0) or not (y <= 0.86): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -15600000000000.0) || !(y <= 0.86)) 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 <= -15600000000000.0) || ~((y <= 0.86))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -15600000000000.0], N[Not[LessEqual[y, 0.86]], $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 -15600000000000 \lor \neg \left(y \leq 0.86\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -1.56e13 or 0.859999999999999987 < y Initial program 96.9%
Taylor expanded in y around inf 99.5%
mul-1-neg99.5%
sub-neg99.5%
Simplified99.5%
if -1.56e13 < y < 0.859999999999999987Initial program 100.0%
Taylor expanded in y around 0 99.5%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -8e-25) (not (<= y 4.7e-5))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8e-25) || !(y <= 4.7e-5)) {
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 <= (-8d-25)) .or. (.not. (y <= 4.7d-5))) 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 <= -8e-25) || !(y <= 4.7e-5)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8e-25) or not (y <= 4.7e-5): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8e-25) || !(y <= 4.7e-5)) 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 <= -8e-25) || ~((y <= 4.7e-5))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8e-25], N[Not[LessEqual[y, 4.7e-5]], $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 -8 \cdot 10^{-25} \lor \neg \left(y \leq 4.7 \cdot 10^{-5}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -8.00000000000000031e-25 or 4.69999999999999972e-5 < y Initial program 97.0%
Taylor expanded in y around inf 99.5%
mul-1-neg99.5%
sub-neg99.5%
Simplified99.5%
if -8.00000000000000031e-25 < y < 4.69999999999999972e-5Initial 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 inf 77.3%
*-commutative77.3%
Simplified77.3%
Taylor expanded in z around 0 77.3%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.8e-20) (not (<= y 2.6e-14))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.8e-20) || !(y <= 2.6e-14)) {
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.8d-20)) .or. (.not. (y <= 2.6d-14))) 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.8e-20) || !(y <= 2.6e-14)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.8e-20) or not (y <= 2.6e-14): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.8e-20) || !(y <= 2.6e-14)) 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.8e-20) || ~((y <= 2.6e-14))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.8e-20], N[Not[LessEqual[y, 2.6e-14]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{-20} \lor \neg \left(y \leq 2.6 \cdot 10^{-14}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -2.8000000000000003e-20 or 2.59999999999999997e-14 < y Initial program 97.0%
Taylor expanded in y around inf 98.8%
mul-1-neg98.8%
sub-neg98.8%
Simplified98.8%
if -2.8000000000000003e-20 < y < 2.59999999999999997e-14Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 77.7%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.5e-24) (not (<= y 1.15e-15))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.5e-24) || !(y <= 1.15e-15)) {
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 <= (-4.5d-24)) .or. (.not. (y <= 1.15d-15))) 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 <= -4.5e-24) || !(y <= 1.15e-15)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.5e-24) or not (y <= 1.15e-15): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.5e-24) || !(y <= 1.15e-15)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.5e-24) || ~((y <= 1.15e-15))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.5e-24], N[Not[LessEqual[y, 1.15e-15]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{-24} \lor \neg \left(y \leq 1.15 \cdot 10^{-15}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -4.4999999999999997e-24 or 1.14999999999999995e-15 < y Initial program 97.0%
Taylor expanded in x around inf 53.9%
*-commutative53.9%
Simplified53.9%
if -4.4999999999999997e-24 < y < 1.14999999999999995e-15Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 77.7%
Final simplification65.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 75.8%
Taylor expanded in x around 0 38.1%
(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 2024136
(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))))