
(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 (fma (+ x z) y x))
double code(double x, double y, double z) {
return fma((x + z), y, x);
}
function code(x, y, z) return fma(Float64(x + z), y, x) end
code[x_, y_, z_] := N[(N[(x + z), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + z, y, x\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ x z) y))) (if (<= y -9.2e+16) t_0 (if (<= y 0.0105) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (x + z) * y;
double tmp;
if (y <= -9.2e+16) {
tmp = t_0;
} else if (y <= 0.0105) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x + z) * y) tmp = 0.0 if (y <= -9.2e+16) tmp = t_0; elseif (y <= 0.0105) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + z), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -9.2e+16], t$95$0, If[LessEqual[y, 0.0105], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + z\right) \cdot y\\
\mathbf{if}\;y \leq -9.2 \cdot 10^{+16}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0105:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -9.2e16 or 0.0105000000000000007 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
if -9.2e16 < y < 0.0105000000000000007Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6498.7
Applied rewrites98.7%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6498.7
Applied rewrites98.7%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (<= x -3.8e+123) (fma y x x) (if (<= x 2.6e+165) (fma z y x) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.8e+123) {
tmp = fma(y, x, x);
} else if (x <= 2.6e+165) {
tmp = fma(z, y, x);
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -3.8e+123) tmp = fma(y, x, x); elseif (x <= 2.6e+165) tmp = fma(z, y, x); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -3.8e+123], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 2.6e+165], N[(z * y + x), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{+123}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 2.6 \cdot 10^{+165}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -3.79999999999999994e123 or 2.6000000000000001e165 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6496.2
Applied rewrites96.2%
if -3.79999999999999994e123 < x < 2.6000000000000001e165Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6485.7
Applied rewrites85.7%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6485.7
Applied rewrites85.7%
(FPCore (x y z) :precision binary64 (if (<= x -4.6e-160) (fma y x x) (if (<= x 2.9e-51) (* z y) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.6e-160) {
tmp = fma(y, x, x);
} else if (x <= 2.9e-51) {
tmp = z * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -4.6e-160) tmp = fma(y, x, x); elseif (x <= 2.9e-51) tmp = Float64(z * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -4.6e-160], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 2.9e-51], N[(z * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{-160}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 2.9 \cdot 10^{-51}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -4.5999999999999997e-160 or 2.89999999999999973e-51 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6478.6
Applied rewrites78.6%
if -4.5999999999999997e-160 < x < 2.89999999999999973e-51Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6481.0
Applied rewrites81.0%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (<= x -9.6e+79) (* x y) (if (<= x 2.6e+165) (* z y) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -9.6e+79) {
tmp = x * y;
} else if (x <= 2.6e+165) {
tmp = z * y;
} 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 (x <= (-9.6d+79)) then
tmp = x * y
else if (x <= 2.6d+165) then
tmp = z * y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -9.6e+79) {
tmp = x * y;
} else if (x <= 2.6e+165) {
tmp = z * y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -9.6e+79: tmp = x * y elif x <= 2.6e+165: tmp = z * y else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -9.6e+79) tmp = Float64(x * y); elseif (x <= 2.6e+165) tmp = Float64(z * y); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -9.6e+79) tmp = x * y; elseif (x <= 2.6e+165) tmp = z * y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -9.6e+79], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.6e+165], N[(z * y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.6 \cdot 10^{+79}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.6 \cdot 10^{+165}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -9.59999999999999942e79 or 2.6000000000000001e165 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6493.4
Applied rewrites93.4%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6453.6
Applied rewrites53.6%
if -9.59999999999999942e79 < x < 2.6000000000000001e165Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6457.7
Applied rewrites57.7%
Final simplification56.4%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return 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 = x * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6461.3
Applied rewrites61.3%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6429.7
Applied rewrites29.7%
Final simplification29.7%
herbie shell --seed 2024216
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))