
(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 97.6%
+-commutative97.6%
+-lft-identity97.6%
cancel-sign-sub97.6%
cancel-sign-sub97.6%
+-lft-identity97.6%
distribute-lft-out--97.6%
*-rgt-identity97.6%
associate-+l-97.6%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1.06e-126)
(* y x)
(if (<= y 9.5e-23)
z
(if (or (<= y 7.1e+19) (not (<= y 4.8e+111))) (* y x) (* z (- y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.06e-126) {
tmp = y * x;
} else if (y <= 9.5e-23) {
tmp = z;
} else if ((y <= 7.1e+19) || !(y <= 4.8e+111)) {
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.06d-126)) then
tmp = y * x
else if (y <= 9.5d-23) then
tmp = z
else if ((y <= 7.1d+19) .or. (.not. (y <= 4.8d+111))) 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.06e-126) {
tmp = y * x;
} else if (y <= 9.5e-23) {
tmp = z;
} else if ((y <= 7.1e+19) || !(y <= 4.8e+111)) {
tmp = y * x;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.06e-126: tmp = y * x elif y <= 9.5e-23: tmp = z elif (y <= 7.1e+19) or not (y <= 4.8e+111): tmp = y * x else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.06e-126) tmp = Float64(y * x); elseif (y <= 9.5e-23) tmp = z; elseif ((y <= 7.1e+19) || !(y <= 4.8e+111)) 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.06e-126) tmp = y * x; elseif (y <= 9.5e-23) tmp = z; elseif ((y <= 7.1e+19) || ~((y <= 4.8e+111))) tmp = y * x; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.06e-126], N[(y * x), $MachinePrecision], If[LessEqual[y, 9.5e-23], z, If[Or[LessEqual[y, 7.1e+19], N[Not[LessEqual[y, 4.8e+111]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.06 \cdot 10^{-126}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{-23}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 7.1 \cdot 10^{+19} \lor \neg \left(y \leq 4.8 \cdot 10^{+111}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < -1.0600000000000001e-126 or 9.50000000000000058e-23 < y < 7.1e19 or 4.80000000000000011e111 < y Initial program 95.5%
Taylor expanded in x around inf 62.7%
*-commutative62.7%
Simplified62.7%
if -1.0600000000000001e-126 < y < 9.50000000000000058e-23Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 78.5%
if 7.1e19 < y < 4.80000000000000011e111Initial program 100.0%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 75.9%
associate-*r*75.9%
neg-mul-175.9%
*-commutative75.9%
Simplified75.9%
Final simplification70.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.7) (not (<= y 0.00041))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.7) || !(y <= 0.00041)) {
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 <= (-3.7d0)) .or. (.not. (y <= 0.00041d0))) 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 <= -3.7) || !(y <= 0.00041)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.7) or not (y <= 0.00041): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.7) || !(y <= 0.00041)) 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 <= -3.7) || ~((y <= 0.00041))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.7], N[Not[LessEqual[y, 0.00041]], $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 -3.7 \lor \neg \left(y \leq 0.00041\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -3.7000000000000002 or 4.0999999999999999e-4 < y Initial program 95.2%
Taylor expanded in y around inf 99.6%
mul-1-neg99.6%
sub-neg99.6%
Simplified99.6%
if -3.7000000000000002 < y < 4.0999999999999999e-4Initial program 100.0%
Taylor expanded in y around 0 99.3%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.1e-127) (not (<= y 7e-24))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.1e-127) || !(y <= 7e-24)) {
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 <= (-5.1d-127)) .or. (.not. (y <= 7d-24))) 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 <= -5.1e-127) || !(y <= 7e-24)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.1e-127) or not (y <= 7e-24): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.1e-127) || !(y <= 7e-24)) 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 <= -5.1e-127) || ~((y <= 7e-24))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.1e-127], N[Not[LessEqual[y, 7e-24]], $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 -5.1 \cdot 10^{-127} \lor \neg \left(y \leq 7 \cdot 10^{-24}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -5.10000000000000019e-127 or 6.9999999999999993e-24 < y Initial program 96.1%
Taylor expanded in y around inf 93.1%
mul-1-neg93.1%
sub-neg93.1%
Simplified93.1%
if -5.10000000000000019e-127 < y < 6.9999999999999993e-24Initial 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 78.5%
*-commutative78.5%
Simplified78.5%
Taylor expanded in z around 0 78.5%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.06e-126) (not (<= y 9.2e-23))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.06e-126) || !(y <= 9.2e-23)) {
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.06d-126)) .or. (.not. (y <= 9.2d-23))) 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.06e-126) || !(y <= 9.2e-23)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.06e-126) or not (y <= 9.2e-23): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.06e-126) || !(y <= 9.2e-23)) 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.06e-126) || ~((y <= 9.2e-23))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.06e-126], N[Not[LessEqual[y, 9.2e-23]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.06 \cdot 10^{-126} \lor \neg \left(y \leq 9.2 \cdot 10^{-23}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.0600000000000001e-126 or 9.2000000000000004e-23 < y Initial program 96.1%
Taylor expanded in y around inf 93.1%
mul-1-neg93.1%
sub-neg93.1%
Simplified93.1%
if -1.0600000000000001e-126 < y < 9.2000000000000004e-23Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 78.5%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.06e-126) (not (<= y 7.6e-23))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.06e-126) || !(y <= 7.6e-23)) {
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.06d-126)) .or. (.not. (y <= 7.6d-23))) 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.06e-126) || !(y <= 7.6e-23)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.06e-126) or not (y <= 7.6e-23): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.06e-126) || !(y <= 7.6e-23)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.06e-126) || ~((y <= 7.6e-23))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.06e-126], N[Not[LessEqual[y, 7.6e-23]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.06 \cdot 10^{-126} \lor \neg \left(y \leq 7.6 \cdot 10^{-23}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.0600000000000001e-126 or 7.60000000000000023e-23 < y Initial program 96.1%
Taylor expanded in x around inf 58.2%
*-commutative58.2%
Simplified58.2%
if -1.0600000000000001e-126 < y < 7.60000000000000023e-23Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 78.5%
Final simplification66.2%
(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.6%
Taylor expanded in y around 0 78.6%
Taylor expanded in x around 0 36.3%
(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 2024148
(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))))