
(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 7 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 (+ 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
(if (<= y -7e+229)
(* y z)
(if (<= y -3.6e+47)
(* x y)
(if (<= y -1.75e-13) (* y z) (if (<= y 1.75e-48) x (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7e+229) {
tmp = y * z;
} else if (y <= -3.6e+47) {
tmp = x * y;
} else if (y <= -1.75e-13) {
tmp = y * z;
} else if (y <= 1.75e-48) {
tmp = x;
} else {
tmp = 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 <= (-7d+229)) then
tmp = y * z
else if (y <= (-3.6d+47)) then
tmp = x * y
else if (y <= (-1.75d-13)) then
tmp = y * z
else if (y <= 1.75d-48) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -7e+229) {
tmp = y * z;
} else if (y <= -3.6e+47) {
tmp = x * y;
} else if (y <= -1.75e-13) {
tmp = y * z;
} else if (y <= 1.75e-48) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7e+229: tmp = y * z elif y <= -3.6e+47: tmp = x * y elif y <= -1.75e-13: tmp = y * z elif y <= 1.75e-48: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7e+229) tmp = Float64(y * z); elseif (y <= -3.6e+47) tmp = Float64(x * y); elseif (y <= -1.75e-13) tmp = Float64(y * z); elseif (y <= 1.75e-48) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -7e+229) tmp = y * z; elseif (y <= -3.6e+47) tmp = x * y; elseif (y <= -1.75e-13) tmp = y * z; elseif (y <= 1.75e-48) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7e+229], N[(y * z), $MachinePrecision], If[LessEqual[y, -3.6e+47], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.75e-13], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.75e-48], x, N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{+229}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -3.6 \cdot 10^{+47}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.75 \cdot 10^{-13}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.75 \cdot 10^{-48}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -7.0000000000000005e229 or -3.60000000000000008e47 < y < -1.7500000000000001e-13 or 1.74999999999999996e-48 < y Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6462.9%
Simplified62.9%
if -7.0000000000000005e229 < y < -3.60000000000000008e47Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6471.5%
Simplified71.5%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6471.5%
Simplified71.5%
if -1.7500000000000001e-13 < y < 1.74999999999999996e-48Initial program 100.0%
Taylor expanded in y around 0
Simplified79.6%
Final simplification71.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -1000000.0) t_0 (if (<= y 1.3e-8) (+ x (* y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -1000000.0) {
tmp = t_0;
} else if (y <= 1.3e-8) {
tmp = x + (y * z);
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = y * (x + z)
if (y <= (-1000000.0d0)) then
tmp = t_0
else if (y <= 1.3d-8) then
tmp = x + (y * z)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -1000000.0) {
tmp = t_0;
} else if (y <= 1.3e-8) {
tmp = x + (y * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -1000000.0: tmp = t_0 elif y <= 1.3e-8: tmp = x + (y * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -1000000.0) tmp = t_0; elseif (y <= 1.3e-8) tmp = Float64(x + Float64(y * z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x + z); tmp = 0.0; if (y <= -1000000.0) tmp = t_0; elseif (y <= 1.3e-8) tmp = x + (y * z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1000000.0], t$95$0, If[LessEqual[y, 1.3e-8], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -1000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-8}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1e6 or 1.3000000000000001e-8 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6499.3%
Simplified99.3%
if -1e6 < y < 1.3000000000000001e-8Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6499.9%
Simplified99.9%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -1.3e-13) t_0 (if (<= y 1.42e-47) (* x (+ y 1.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -1.3e-13) {
tmp = t_0;
} else if (y <= 1.42e-47) {
tmp = x * (y + 1.0);
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = y * (x + z)
if (y <= (-1.3d-13)) then
tmp = t_0
else if (y <= 1.42d-47) then
tmp = x * (y + 1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -1.3e-13) {
tmp = t_0;
} else if (y <= 1.42e-47) {
tmp = x * (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -1.3e-13: tmp = t_0 elif y <= 1.42e-47: tmp = x * (y + 1.0) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -1.3e-13) tmp = t_0; elseif (y <= 1.42e-47) tmp = Float64(x * Float64(y + 1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x + z); tmp = 0.0; if (y <= -1.3e-13) tmp = t_0; elseif (y <= 1.42e-47) tmp = x * (y + 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.3e-13], t$95$0, If[LessEqual[y, 1.42e-47], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -1.3 \cdot 10^{-13}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.42 \cdot 10^{-47}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.3e-13 or 1.41999999999999989e-47 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6497.3%
Simplified97.3%
if -1.3e-13 < y < 1.41999999999999989e-47Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6479.7%
Simplified79.7%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (<= z -2.7e+43) (* y z) (if (<= z 7.2e+68) (* x (+ y 1.0)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.7e+43) {
tmp = y * z;
} else if (z <= 7.2e+68) {
tmp = x * (y + 1.0);
} else {
tmp = 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 (z <= (-2.7d+43)) then
tmp = y * z
else if (z <= 7.2d+68) then
tmp = x * (y + 1.0d0)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.7e+43) {
tmp = y * z;
} else if (z <= 7.2e+68) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.7e+43: tmp = y * z elif z <= 7.2e+68: tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.7e+43) tmp = Float64(y * z); elseif (z <= 7.2e+68) tmp = Float64(x * Float64(y + 1.0)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.7e+43) tmp = y * z; elseif (z <= 7.2e+68) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.7e+43], N[(y * z), $MachinePrecision], If[LessEqual[z, 7.2e+68], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{+43}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 7.2 \cdot 10^{+68}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.7000000000000002e43 or 7.1999999999999998e68 < z Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6476.1%
Simplified76.1%
if -2.7000000000000002e43 < z < 7.1999999999999998e68Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6484.1%
Simplified84.1%
(FPCore (x y z) :precision binary64 (if (<= y -3.8e-11) (* x y) (if (<= y 18.5) x (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e-11) {
tmp = x * y;
} else if (y <= 18.5) {
tmp = x;
} else {
tmp = x * 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 <= (-3.8d-11)) then
tmp = x * y
else if (y <= 18.5d0) then
tmp = x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e-11) {
tmp = x * y;
} else if (y <= 18.5) {
tmp = x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.8e-11: tmp = x * y elif y <= 18.5: tmp = x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.8e-11) tmp = Float64(x * y); elseif (y <= 18.5) tmp = x; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.8e-11) tmp = x * y; elseif (y <= 18.5) tmp = x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.8e-11], N[(x * y), $MachinePrecision], If[LessEqual[y, 18.5], x, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{-11}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 18.5:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -3.7999999999999998e-11 or 18.5 < y Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6450.1%
Simplified50.1%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6449.4%
Simplified49.4%
if -3.7999999999999998e-11 < y < 18.5Initial program 100.0%
Taylor expanded in y around 0
Simplified76.6%
Final simplification63.8%
(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
Simplified41.8%
herbie shell --seed 2024138
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))