
(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 6 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 (+ (* (+ z x) y) x))
double code(double x, double y, double z) {
return ((z + x) * y) + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((z + x) * y) + x
end function
public static double code(double x, double y, double z) {
return ((z + x) * y) + x;
}
def code(x, y, z): return ((z + x) * y) + x
function code(x, y, z) return Float64(Float64(Float64(z + x) * y) + x) end
function tmp = code(x, y, z) tmp = ((z + x) * y) + x; end
code[x_, y_, z_] := N[(N[(N[(z + x), $MachinePrecision] * y), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(z + x\right) \cdot y + x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ z x) y))) (if (<= y -1.0) t_0 (if (<= y 4e-15) (+ (* z y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = (z + x) * y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 4e-15) {
tmp = (z * y) + x;
} 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 = (z + x) * y
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 4d-15) then
tmp = (z * y) + x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z + x) * y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 4e-15) {
tmp = (z * y) + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z + x) * y tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 4e-15: tmp = (z * y) + x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(z + x) * y) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 4e-15) tmp = Float64(Float64(z * y) + x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z + x) * y; tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 4e-15) tmp = (z * y) + x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z + x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 4e-15], N[(N[(z * y), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z + x\right) \cdot y\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-15}:\\
\;\;\;\;z \cdot y + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 4.0000000000000003e-15 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.9
Applied rewrites98.9%
if -1 < y < 4.0000000000000003e-15Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ z x) y))) (if (<= y -3.6e-100) t_0 (if (<= y 4.1e-57) (fma y x x) t_0))))
double code(double x, double y, double z) {
double t_0 = (z + x) * y;
double tmp;
if (y <= -3.6e-100) {
tmp = t_0;
} else if (y <= 4.1e-57) {
tmp = fma(y, x, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(z + x) * y) tmp = 0.0 if (y <= -3.6e-100) tmp = t_0; elseif (y <= 4.1e-57) tmp = fma(y, x, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z + x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -3.6e-100], t$95$0, If[LessEqual[y, 4.1e-57], N[(y * x + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z + x\right) \cdot y\\
\mathbf{if}\;y \leq -3.6 \cdot 10^{-100}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.1 \cdot 10^{-57}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.5999999999999999e-100 or 4.1000000000000001e-57 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6495.6
Applied rewrites95.6%
if -3.5999999999999999e-100 < y < 4.1000000000000001e-57Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6475.6
Applied rewrites75.6%
(FPCore (x y z) :precision binary64 (if (<= x -2.6e-85) (fma y x x) (if (<= x 0.0052) (* z y) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.6e-85) {
tmp = fma(y, x, x);
} else if (x <= 0.0052) {
tmp = z * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -2.6e-85) tmp = fma(y, x, x); elseif (x <= 0.0052) tmp = Float64(z * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2.6e-85], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 0.0052], N[(z * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{-85}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 0.0052:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -2.60000000000000011e-85 or 0.0051999999999999998 < x Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6484.8
Applied rewrites84.8%
if -2.60000000000000011e-85 < x < 0.0051999999999999998Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6471.2
Applied rewrites71.2%
(FPCore (x y z) :precision binary64 (if (<= z -59000000000000.0) (* z y) (if (<= z 6.5e-33) (* y x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -59000000000000.0) {
tmp = z * y;
} else if (z <= 6.5e-33) {
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 (z <= (-59000000000000.0d0)) then
tmp = z * y
else if (z <= 6.5d-33) 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 (z <= -59000000000000.0) {
tmp = z * y;
} else if (z <= 6.5e-33) {
tmp = y * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -59000000000000.0: tmp = z * y elif z <= 6.5e-33: tmp = y * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -59000000000000.0) tmp = Float64(z * y); elseif (z <= 6.5e-33) tmp = Float64(y * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -59000000000000.0) tmp = z * y; elseif (z <= 6.5e-33) tmp = y * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -59000000000000.0], N[(z * y), $MachinePrecision], If[LessEqual[z, 6.5e-33], N[(y * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -59000000000000:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{-33}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -5.9e13 or 6.4999999999999993e-33 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6467.8
Applied rewrites67.8%
if -5.9e13 < z < 6.4999999999999993e-33Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6485.4
Applied rewrites85.4%
Taylor expanded in y around inf
Applied rewrites52.6%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6459.1
Applied rewrites59.1%
Taylor expanded in y around inf
Applied rewrites31.8%
herbie shell --seed 2024268
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))