
(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 (<= x -1.1e+59) (* x y) (if (<= x 1.4e+70) (* y z) (if (<= x 6.8e+194) x (* x y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.1e+59) {
tmp = x * y;
} else if (x <= 1.4e+70) {
tmp = y * z;
} else if (x <= 6.8e+194) {
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 (x <= (-1.1d+59)) then
tmp = x * y
else if (x <= 1.4d+70) then
tmp = y * z
else if (x <= 6.8d+194) 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 (x <= -1.1e+59) {
tmp = x * y;
} else if (x <= 1.4e+70) {
tmp = y * z;
} else if (x <= 6.8e+194) {
tmp = x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.1e+59: tmp = x * y elif x <= 1.4e+70: tmp = y * z elif x <= 6.8e+194: tmp = x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.1e+59) tmp = Float64(x * y); elseif (x <= 1.4e+70) tmp = Float64(y * z); elseif (x <= 6.8e+194) tmp = x; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.1e+59) tmp = x * y; elseif (x <= 1.4e+70) tmp = y * z; elseif (x <= 6.8e+194) tmp = x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.1e+59], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.4e+70], N[(y * z), $MachinePrecision], If[LessEqual[x, 6.8e+194], x, N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+59}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{+70}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;x \leq 6.8 \cdot 10^{+194}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.1e59 or 6.8000000000000002e194 < x Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6463.5%
Simplified63.5%
Taylor expanded in z around 0
*-commutativeN/A
*-lowering-*.f6459.3%
Simplified59.3%
if -1.1e59 < x < 1.39999999999999995e70Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6467.9%
Simplified67.9%
if 1.39999999999999995e70 < x < 6.8000000000000002e194Initial program 100.0%
Taylor expanded in y around 0
Simplified56.0%
Final simplification64.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -1.0) t_0 (if (<= y 1.0) (+ x (* y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.0) {
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 <= (-1.0d0)) then
tmp = t_0
else if (y <= 1.0d0) 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 <= -1.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = x + (y * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 1.0: 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 <= -1.0) tmp = t_0; elseif (y <= 1.0) 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 <= -1.0) tmp = t_0; elseif (y <= 1.0) 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, -1.0], t$95$0, If[LessEqual[y, 1.0], 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 -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64100.0%
Simplified100.0%
if -1 < y < 1Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6498.9%
Simplified98.9%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ x (* x y)))) (if (<= x -1.5e-36) t_0 (if (<= x 1.8e+104) (* y (+ x z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x + (x * y);
double tmp;
if (x <= -1.5e-36) {
tmp = t_0;
} else if (x <= 1.8e+104) {
tmp = y * (x + 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 = x + (x * y)
if (x <= (-1.5d-36)) then
tmp = t_0
else if (x <= 1.8d+104) then
tmp = y * (x + z)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (x * y);
double tmp;
if (x <= -1.5e-36) {
tmp = t_0;
} else if (x <= 1.8e+104) {
tmp = y * (x + z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (x * y) tmp = 0 if x <= -1.5e-36: tmp = t_0 elif x <= 1.8e+104: tmp = y * (x + z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(x * y)) tmp = 0.0 if (x <= -1.5e-36) tmp = t_0; elseif (x <= 1.8e+104) tmp = Float64(y * Float64(x + z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (x * y); tmp = 0.0; if (x <= -1.5e-36) tmp = t_0; elseif (x <= 1.8e+104) tmp = y * (x + z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.5e-36], t$95$0, If[LessEqual[x, 1.8e+104], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + x \cdot y\\
\mathbf{if}\;x \leq -1.5 \cdot 10^{-36}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{+104}:\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.5000000000000001e-36 or 1.8e104 < x Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
*-lowering-*.f6488.6%
Simplified88.6%
if -1.5000000000000001e-36 < x < 1.8e104Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6485.2%
Simplified85.2%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -4e-121) t_0 (if (<= y 8.2e-55) x t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -4e-121) {
tmp = t_0;
} else if (y <= 8.2e-55) {
tmp = 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 = y * (x + z)
if (y <= (-4d-121)) then
tmp = t_0
else if (y <= 8.2d-55) then
tmp = x
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 <= -4e-121) {
tmp = t_0;
} else if (y <= 8.2e-55) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -4e-121: tmp = t_0 elif y <= 8.2e-55: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -4e-121) tmp = t_0; elseif (y <= 8.2e-55) tmp = x; 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 <= -4e-121) tmp = t_0; elseif (y <= 8.2e-55) tmp = x; 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, -4e-121], t$95$0, If[LessEqual[y, 8.2e-55], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -4 \cdot 10^{-121}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{-55}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.9999999999999999e-121 or 8.1999999999999996e-55 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6488.9%
Simplified88.9%
if -3.9999999999999999e-121 < y < 8.1999999999999996e-55Initial program 100.0%
Taylor expanded in y around 0
Simplified66.7%
Final simplification81.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.0) (* x y) (if (<= y 1.0) x (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 1.0) {
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 <= (-1.0d0)) then
tmp = x * y
else if (y <= 1.0d0) 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 <= -1.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 1.0: tmp = x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * y); elseif (y <= 1.0) tmp = x; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.0) tmp = x * y; elseif (y <= 1.0) tmp = x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], x, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in z around 0
*-commutativeN/A
*-lowering-*.f6455.1%
Simplified55.1%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0
Simplified60.2%
Final simplification57.6%
(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
Simplified30.4%
herbie shell --seed 2024191
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))