
(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 (fma y (- x z) z))
double code(double x, double y, double z) {
return fma(y, (x - z), z);
}
function code(x, y, z) return fma(y, Float64(x - z), z) end
code[x_, y_, z_] := N[(y * N[(x - z), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x - z, z\right)
\end{array}
Initial program 98.8%
distribute-lft-out--98.8%
*-rgt-identity98.8%
cancel-sign-sub-inv98.8%
+-commutative98.8%
associate-+r+98.8%
distribute-rgt-out100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1.5e+213)
(* y x)
(if (<= y -2.1e+132)
(* y (- z))
(if (or (<= y -3.5e-7) (not (<= y 1.75e-74))) (* y x) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.5e+213) {
tmp = y * x;
} else if (y <= -2.1e+132) {
tmp = y * -z;
} else if ((y <= -3.5e-7) || !(y <= 1.75e-74)) {
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.5d+213)) then
tmp = y * x
else if (y <= (-2.1d+132)) then
tmp = y * -z
else if ((y <= (-3.5d-7)) .or. (.not. (y <= 1.75d-74))) 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.5e+213) {
tmp = y * x;
} else if (y <= -2.1e+132) {
tmp = y * -z;
} else if ((y <= -3.5e-7) || !(y <= 1.75e-74)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.5e+213: tmp = y * x elif y <= -2.1e+132: tmp = y * -z elif (y <= -3.5e-7) or not (y <= 1.75e-74): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.5e+213) tmp = Float64(y * x); elseif (y <= -2.1e+132) tmp = Float64(y * Float64(-z)); elseif ((y <= -3.5e-7) || !(y <= 1.75e-74)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.5e+213) tmp = y * x; elseif (y <= -2.1e+132) tmp = y * -z; elseif ((y <= -3.5e-7) || ~((y <= 1.75e-74))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.5e+213], N[(y * x), $MachinePrecision], If[LessEqual[y, -2.1e+132], N[(y * (-z)), $MachinePrecision], If[Or[LessEqual[y, -3.5e-7], N[Not[LessEqual[y, 1.75e-74]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+213}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -2.1 \cdot 10^{+132}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{elif}\;y \leq -3.5 \cdot 10^{-7} \lor \neg \left(y \leq 1.75 \cdot 10^{-74}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.5000000000000001e213 or -2.09999999999999993e132 < y < -3.49999999999999984e-7 or 1.75000000000000007e-74 < y Initial program 97.7%
Taylor expanded in x around inf 58.3%
*-commutative58.3%
Simplified58.3%
if -1.5000000000000001e213 < y < -2.09999999999999993e132Initial program 100.0%
Taylor expanded in x around 0 78.0%
Taylor expanded in y around inf 78.0%
mul-1-neg78.0%
distribute-lft-neg-out78.0%
*-commutative78.0%
Simplified78.0%
if -3.49999999999999984e-7 < y < 1.75000000000000007e-74Initial program 100.0%
Taylor expanded in y around 0 83.3%
Final simplification70.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.65e-5) (not (<= y 2.05e-74))) (* y (- x z)) (* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.65e-5) || !(y <= 2.05e-74)) {
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 <= (-2.65d-5)) .or. (.not. (y <= 2.05d-74))) 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 <= -2.65e-5) || !(y <= 2.05e-74)) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.65e-5) or not (y <= 2.05e-74): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.65e-5) || !(y <= 2.05e-74)) 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 <= -2.65e-5) || ~((y <= 2.05e-74))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.65e-5], N[Not[LessEqual[y, 2.05e-74]], $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 -2.65 \cdot 10^{-5} \lor \neg \left(y \leq 2.05 \cdot 10^{-74}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -2.65e-5 or 2.05000000000000016e-74 < y Initial program 98.0%
Taylor expanded in y around inf 93.7%
mul-1-neg93.7%
sub-neg93.7%
Simplified93.7%
if -2.65e-5 < y < 2.05000000000000016e-74Initial program 100.0%
Taylor expanded in x around 0 83.8%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.5e-7) (not (<= y 2.05e-74))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.5e-7) || !(y <= 2.05e-74)) {
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 <= (-3.5d-7)) .or. (.not. (y <= 2.05d-74))) 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 <= -3.5e-7) || !(y <= 2.05e-74)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.5e-7) or not (y <= 2.05e-74): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.5e-7) || !(y <= 2.05e-74)) 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 <= -3.5e-7) || ~((y <= 2.05e-74))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.5e-7], N[Not[LessEqual[y, 2.05e-74]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{-7} \lor \neg \left(y \leq 2.05 \cdot 10^{-74}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -3.49999999999999984e-7 or 2.05000000000000016e-74 < y Initial program 98.0%
Taylor expanded in y around inf 93.7%
mul-1-neg93.7%
sub-neg93.7%
Simplified93.7%
if -3.49999999999999984e-7 < y < 2.05000000000000016e-74Initial program 100.0%
Taylor expanded in y around 0 83.3%
Final simplification89.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.5e-7) (not (<= y 4.6e-76))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.5e-7) || !(y <= 4.6e-76)) {
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 <= (-3.5d-7)) .or. (.not. (y <= 4.6d-76))) 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 <= -3.5e-7) || !(y <= 4.6e-76)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.5e-7) or not (y <= 4.6e-76): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.5e-7) || !(y <= 4.6e-76)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.5e-7) || ~((y <= 4.6e-76))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.5e-7], N[Not[LessEqual[y, 4.6e-76]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{-7} \lor \neg \left(y \leq 4.6 \cdot 10^{-76}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -3.49999999999999984e-7 or 4.60000000000000012e-76 < y Initial program 98.0%
Taylor expanded in x around inf 54.9%
*-commutative54.9%
Simplified54.9%
if -3.49999999999999984e-7 < y < 4.60000000000000012e-76Initial program 100.0%
Taylor expanded in y around 0 83.3%
Final simplification66.9%
(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 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 39.2%
(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 2024103
(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))))