
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (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 = x + (y * (z + x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z + x));
}
def code(x, y, z): return x + (y * (z + x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z + x))) end
function tmp = code(x, y, z) tmp = x + (y * (z + x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z + x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (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 = x + (y * (z + x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z + x));
}
def code(x, y, z): return x + (y * (z + x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z + x))) end
function tmp = code(x, y, z) tmp = x + (y * (z + x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z + x\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma y (+ x z) x))
double code(double x, double y, double z) {
return fma(y, (x + z), x);
}
function code(x, y, z) return fma(y, Float64(x + z), x) end
code[x_, y_, z_] := N[(y * N[(x + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x + z, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1.42e+20)
(* y x)
(if (<= y 5.7e-18)
x
(if (or (<= y 1.4e+91) (not (<= y 1.7e+204))) (* y z) (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.42e+20) {
tmp = y * x;
} else if (y <= 5.7e-18) {
tmp = x;
} else if ((y <= 1.4e+91) || !(y <= 1.7e+204)) {
tmp = y * 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.42d+20)) then
tmp = y * x
else if (y <= 5.7d-18) then
tmp = x
else if ((y <= 1.4d+91) .or. (.not. (y <= 1.7d+204))) then
tmp = y * 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.42e+20) {
tmp = y * x;
} else if (y <= 5.7e-18) {
tmp = x;
} else if ((y <= 1.4e+91) || !(y <= 1.7e+204)) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.42e+20: tmp = y * x elif y <= 5.7e-18: tmp = x elif (y <= 1.4e+91) or not (y <= 1.7e+204): tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.42e+20) tmp = Float64(y * x); elseif (y <= 5.7e-18) tmp = x; elseif ((y <= 1.4e+91) || !(y <= 1.7e+204)) tmp = Float64(y * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.42e+20) tmp = y * x; elseif (y <= 5.7e-18) tmp = x; elseif ((y <= 1.4e+91) || ~((y <= 1.7e+204))) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.42e+20], N[(y * x), $MachinePrecision], If[LessEqual[y, 5.7e-18], x, If[Or[LessEqual[y, 1.4e+91], N[Not[LessEqual[y, 1.7e+204]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.42 \cdot 10^{+20}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 5.7 \cdot 10^{-18}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{+91} \lor \neg \left(y \leq 1.7 \cdot 10^{+204}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.42e20 or 1.3999999999999999e91 < y < 1.70000000000000005e204Initial program 100.0%
Taylor expanded in z around 0 63.2%
*-commutative63.2%
Simplified63.2%
Taylor expanded in y around inf 63.2%
if -1.42e20 < y < 5.69999999999999971e-18Initial program 100.0%
Taylor expanded in y around 0 67.3%
if 5.69999999999999971e-18 < y < 1.3999999999999999e91 or 1.70000000000000005e204 < y Initial program 100.0%
Taylor expanded in z around inf 80.4%
Taylor expanded in x around 0 79.1%
Final simplification68.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.2e-15) (not (<= y 6.4e-18))) (* y (+ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.2e-15) || !(y <= 6.4e-18)) {
tmp = y * (x + z);
} else {
tmp = 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 <= (-9.2d-15)) .or. (.not. (y <= 6.4d-18))) then
tmp = y * (x + z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -9.2e-15) || !(y <= 6.4e-18)) {
tmp = y * (x + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.2e-15) or not (y <= 6.4e-18): tmp = y * (x + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.2e-15) || !(y <= 6.4e-18)) tmp = Float64(y * Float64(x + z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9.2e-15) || ~((y <= 6.4e-18))) tmp = y * (x + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.2e-15], N[Not[LessEqual[y, 6.4e-18]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.2 \cdot 10^{-15} \lor \neg \left(y \leq 6.4 \cdot 10^{-18}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -9.19999999999999961e-15 or 6.3999999999999998e-18 < y Initial program 100.0%
Taylor expanded in x around -inf 97.5%
+-commutative97.5%
mul-1-neg97.5%
unsub-neg97.5%
sub-neg97.5%
metadata-eval97.5%
+-commutative97.5%
mul-1-neg97.5%
unsub-neg97.5%
Simplified97.5%
Taylor expanded in y around inf 99.2%
cancel-sign-sub-inv99.2%
metadata-eval99.2%
*-lft-identity99.2%
+-commutative99.2%
Simplified99.2%
if -9.19999999999999961e-15 < y < 6.3999999999999998e-18Initial program 100.0%
Taylor expanded in y around 0 68.9%
Final simplification83.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.4e-23) (not (<= x 50000000000.0))) (+ x (* y x)) (* y (+ x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.4e-23) || !(x <= 50000000000.0)) {
tmp = x + (y * x);
} else {
tmp = y * (x + 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 ((x <= (-1.4d-23)) .or. (.not. (x <= 50000000000.0d0))) then
tmp = x + (y * x)
else
tmp = y * (x + z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.4e-23) || !(x <= 50000000000.0)) {
tmp = x + (y * x);
} else {
tmp = y * (x + z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.4e-23) or not (x <= 50000000000.0): tmp = x + (y * x) else: tmp = y * (x + z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.4e-23) || !(x <= 50000000000.0)) tmp = Float64(x + Float64(y * x)); else tmp = Float64(y * Float64(x + z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.4e-23) || ~((x <= 50000000000.0))) tmp = x + (y * x); else tmp = y * (x + z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.4e-23], N[Not[LessEqual[x, 50000000000.0]], $MachinePrecision]], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-23} \lor \neg \left(x \leq 50000000000\right):\\
\;\;\;\;x + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + z\right)\\
\end{array}
\end{array}
if x < -1.3999999999999999e-23 or 5e10 < x Initial program 100.0%
Taylor expanded in z around 0 89.6%
*-commutative89.6%
Simplified89.6%
if -1.3999999999999999e-23 < x < 5e10Initial program 100.0%
Taylor expanded in x around -inf 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
sub-neg100.0%
metadata-eval100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in y around inf 79.7%
cancel-sign-sub-inv79.7%
metadata-eval79.7%
*-lft-identity79.7%
+-commutative79.7%
Simplified79.7%
Final simplification84.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.05e+22) (not (<= y 6.5e-18))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.05e+22) || !(y <= 6.5e-18)) {
tmp = y * (x + z);
} else {
tmp = x + (y * 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.05d+22)) .or. (.not. (y <= 6.5d-18))) then
tmp = y * (x + z)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.05e+22) || !(y <= 6.5e-18)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.05e+22) or not (y <= 6.5e-18): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.05e+22) || !(y <= 6.5e-18)) tmp = Float64(y * Float64(x + z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.05e+22) || ~((y <= 6.5e-18))) tmp = y * (x + z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.05e+22], N[Not[LessEqual[y, 6.5e-18]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.05 \cdot 10^{+22} \lor \neg \left(y \leq 6.5 \cdot 10^{-18}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -3.0499999999999999e22 or 6.50000000000000008e-18 < y Initial program 100.0%
Taylor expanded in x around -inf 97.4%
+-commutative97.4%
mul-1-neg97.4%
unsub-neg97.4%
sub-neg97.4%
metadata-eval97.4%
+-commutative97.4%
mul-1-neg97.4%
unsub-neg97.4%
Simplified97.4%
Taylor expanded in y around inf 100.0%
cancel-sign-sub-inv100.0%
metadata-eval100.0%
*-lft-identity100.0%
+-commutative100.0%
Simplified100.0%
if -3.0499999999999999e22 < y < 6.50000000000000008e-18Initial program 100.0%
Taylor expanded in z around inf 99.5%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.42e+20) (not (<= y 42000000000000.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.42e+20) || !(y <= 42000000000000.0)) {
tmp = y * x;
} else {
tmp = 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.42d+20)) .or. (.not. (y <= 42000000000000.0d0))) then
tmp = y * x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.42e+20) || !(y <= 42000000000000.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.42e+20) or not (y <= 42000000000000.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.42e+20) || !(y <= 42000000000000.0)) tmp = Float64(y * x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.42e+20) || ~((y <= 42000000000000.0))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.42e+20], N[Not[LessEqual[y, 42000000000000.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.42 \cdot 10^{+20} \lor \neg \left(y \leq 42000000000000\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.42e20 or 4.2e13 < y Initial program 100.0%
Taylor expanded in z around 0 54.8%
*-commutative54.8%
Simplified54.8%
Taylor expanded in y around inf 54.8%
if -1.42e20 < y < 4.2e13Initial program 100.0%
Taylor expanded in y around 0 64.3%
Final simplification60.3%
(FPCore (x y z) :precision binary64 (+ x (* y (+ x z))))
double code(double x, double y, double z) {
return x + (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 = x + (y * (x + z))
end function
public static double code(double x, double y, double z) {
return x + (y * (x + z));
}
def code(x, y, z): return x + (y * (x + z))
function code(x, y, z) return Float64(x + Float64(y * Float64(x + z))) end
function tmp = code(x, y, z) tmp = x + (y * (x + z)); end
code[x_, y_, z_] := N[(x + N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(x + z\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 38.4%
Final simplification38.4%
herbie shell --seed 2024027
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))