
(FPCore (x y z) :precision binary64 (+ (+ (+ (+ (+ x y) y) x) z) x))
double code(double x, double y, double z) {
return ((((x + y) + y) + x) + 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) + y) + x) + z) + x
end function
public static double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
def code(x, y, z): return ((((x + y) + y) + x) + z) + x
function code(x, y, z) return Float64(Float64(Float64(Float64(Float64(x + y) + y) + x) + z) + x) end
function tmp = code(x, y, z) tmp = ((((x + y) + y) + x) + z) + x; end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ (+ (+ (+ x y) y) x) z) x))
double code(double x, double y, double z) {
return ((((x + y) + y) + x) + 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) + y) + x) + z) + x
end function
public static double code(double x, double y, double z) {
return ((((x + y) + y) + x) + z) + x;
}
def code(x, y, z): return ((((x + y) + y) + x) + z) + x
function code(x, y, z) return Float64(Float64(Float64(Float64(Float64(x + y) + y) + x) + z) + x) end
function tmp = code(x, y, z) tmp = ((((x + y) + y) + x) + z) + x; end
code[x_, y_, z_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\end{array}
(FPCore (x y z) :precision binary64 (+ z (+ (* 2.0 y) (* 3.0 x))))
double code(double x, double y, double z) {
return z + ((2.0 * y) + (3.0 * 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 + ((2.0d0 * y) + (3.0d0 * x))
end function
public static double code(double x, double y, double z) {
return z + ((2.0 * y) + (3.0 * x));
}
def code(x, y, z): return z + ((2.0 * y) + (3.0 * x))
function code(x, y, z) return Float64(z + Float64(Float64(2.0 * y) + Float64(3.0 * x))) end
function tmp = code(x, y, z) tmp = z + ((2.0 * y) + (3.0 * x)); end
code[x_, y_, z_] := N[(z + N[(N[(2.0 * y), $MachinePrecision] + N[(3.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(2 \cdot y + 3 \cdot x\right)
\end{array}
Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in x around 0 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (<= y -3.6e+70)
(* 2.0 y)
(if (<= y -2.95e-170)
z
(if (<= y 10200000.0) (* 3.0 x) (if (<= y 3.1e+86) z (* 2.0 y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.6e+70) {
tmp = 2.0 * y;
} else if (y <= -2.95e-170) {
tmp = z;
} else if (y <= 10200000.0) {
tmp = 3.0 * x;
} else if (y <= 3.1e+86) {
tmp = z;
} else {
tmp = 2.0 * 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.6d+70)) then
tmp = 2.0d0 * y
else if (y <= (-2.95d-170)) then
tmp = z
else if (y <= 10200000.0d0) then
tmp = 3.0d0 * x
else if (y <= 3.1d+86) then
tmp = z
else
tmp = 2.0d0 * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.6e+70) {
tmp = 2.0 * y;
} else if (y <= -2.95e-170) {
tmp = z;
} else if (y <= 10200000.0) {
tmp = 3.0 * x;
} else if (y <= 3.1e+86) {
tmp = z;
} else {
tmp = 2.0 * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.6e+70: tmp = 2.0 * y elif y <= -2.95e-170: tmp = z elif y <= 10200000.0: tmp = 3.0 * x elif y <= 3.1e+86: tmp = z else: tmp = 2.0 * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.6e+70) tmp = Float64(2.0 * y); elseif (y <= -2.95e-170) tmp = z; elseif (y <= 10200000.0) tmp = Float64(3.0 * x); elseif (y <= 3.1e+86) tmp = z; else tmp = Float64(2.0 * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.6e+70) tmp = 2.0 * y; elseif (y <= -2.95e-170) tmp = z; elseif (y <= 10200000.0) tmp = 3.0 * x; elseif (y <= 3.1e+86) tmp = z; else tmp = 2.0 * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.6e+70], N[(2.0 * y), $MachinePrecision], If[LessEqual[y, -2.95e-170], z, If[LessEqual[y, 10200000.0], N[(3.0 * x), $MachinePrecision], If[LessEqual[y, 3.1e+86], z, N[(2.0 * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{+70}:\\
\;\;\;\;2 \cdot y\\
\mathbf{elif}\;y \leq -2.95 \cdot 10^{-170}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 10200000:\\
\;\;\;\;3 \cdot x\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{+86}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;2 \cdot y\\
\end{array}
\end{array}
if y < -3.6e70 or 3.1000000000000002e86 < y Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 69.4%
if -3.6e70 < y < -2.9499999999999999e-170 or 1.02e7 < y < 3.1000000000000002e86Initial program 100.0%
associate-+l+100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 58.1%
if -2.9499999999999999e-170 < y < 1.02e7Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in x around inf 54.7%
Final simplification61.8%
(FPCore (x y z) :precision binary64 (if (<= y -3.1e+32) (+ z (* 2.0 y)) (if (<= y 2.75e+88) (+ z (* 3.0 x)) (+ x (* 2.0 (+ y x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.1e+32) {
tmp = z + (2.0 * y);
} else if (y <= 2.75e+88) {
tmp = z + (3.0 * x);
} else {
tmp = x + (2.0 * (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 <= (-3.1d+32)) then
tmp = z + (2.0d0 * y)
else if (y <= 2.75d+88) then
tmp = z + (3.0d0 * x)
else
tmp = x + (2.0d0 * (y + x))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.1e+32) {
tmp = z + (2.0 * y);
} else if (y <= 2.75e+88) {
tmp = z + (3.0 * x);
} else {
tmp = x + (2.0 * (y + x));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.1e+32: tmp = z + (2.0 * y) elif y <= 2.75e+88: tmp = z + (3.0 * x) else: tmp = x + (2.0 * (y + x)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.1e+32) tmp = Float64(z + Float64(2.0 * y)); elseif (y <= 2.75e+88) tmp = Float64(z + Float64(3.0 * x)); else tmp = Float64(x + Float64(2.0 * Float64(y + x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.1e+32) tmp = z + (2.0 * y); elseif (y <= 2.75e+88) tmp = z + (3.0 * x); else tmp = x + (2.0 * (y + x)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.1e+32], N[(z + N[(2.0 * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.75e+88], N[(z + N[(3.0 * x), $MachinePrecision]), $MachinePrecision], N[(x + N[(2.0 * N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \cdot 10^{+32}:\\
\;\;\;\;z + 2 \cdot y\\
\mathbf{elif}\;y \leq 2.75 \cdot 10^{+88}:\\
\;\;\;\;z + 3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;x + 2 \cdot \left(y + x\right)\\
\end{array}
\end{array}
if y < -3.09999999999999993e32Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in x around 0 87.8%
if -3.09999999999999993e32 < y < 2.75e88Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in y around 0 93.0%
+-commutative93.0%
associate-+l+93.0%
distribute-lft1-in93.0%
metadata-eval93.0%
Simplified93.0%
if 2.75e88 < y Initial program 100.0%
associate-+l+100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around 0 87.0%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.3e+134) (not (<= x 2.6e+104))) (* 3.0 x) (+ z (* 2.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.3e+134) || !(x <= 2.6e+104)) {
tmp = 3.0 * x;
} else {
tmp = z + (2.0 * 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 <= (-6.3d+134)) .or. (.not. (x <= 2.6d+104))) then
tmp = 3.0d0 * x
else
tmp = z + (2.0d0 * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.3e+134) || !(x <= 2.6e+104)) {
tmp = 3.0 * x;
} else {
tmp = z + (2.0 * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.3e+134) or not (x <= 2.6e+104): tmp = 3.0 * x else: tmp = z + (2.0 * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.3e+134) || !(x <= 2.6e+104)) tmp = Float64(3.0 * x); else tmp = Float64(z + Float64(2.0 * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.3e+134) || ~((x <= 2.6e+104))) tmp = 3.0 * x; else tmp = z + (2.0 * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.3e+134], N[Not[LessEqual[x, 2.6e+104]], $MachinePrecision]], N[(3.0 * x), $MachinePrecision], N[(z + N[(2.0 * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.3 \cdot 10^{+134} \lor \neg \left(x \leq 2.6 \cdot 10^{+104}\right):\\
\;\;\;\;3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z + 2 \cdot y\\
\end{array}
\end{array}
if x < -6.3000000000000003e134 or 2.6e104 < x Initial program 99.8%
associate-+l+99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
count-299.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in x around inf 68.4%
if -6.3000000000000003e134 < x < 2.6e104Initial program 100.0%
associate-+l+100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 84.1%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.45e+30) (not (<= y 6.5e+77))) (+ z (* 2.0 y)) (+ z (* 3.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.45e+30) || !(y <= 6.5e+77)) {
tmp = z + (2.0 * y);
} else {
tmp = z + (3.0 * 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 <= (-3.45d+30)) .or. (.not. (y <= 6.5d+77))) then
tmp = z + (2.0d0 * y)
else
tmp = z + (3.0d0 * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.45e+30) || !(y <= 6.5e+77)) {
tmp = z + (2.0 * y);
} else {
tmp = z + (3.0 * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.45e+30) or not (y <= 6.5e+77): tmp = z + (2.0 * y) else: tmp = z + (3.0 * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.45e+30) || !(y <= 6.5e+77)) tmp = Float64(z + Float64(2.0 * y)); else tmp = Float64(z + Float64(3.0 * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.45e+30) || ~((y <= 6.5e+77))) tmp = z + (2.0 * y); else tmp = z + (3.0 * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.45e+30], N[Not[LessEqual[y, 6.5e+77]], $MachinePrecision]], N[(z + N[(2.0 * y), $MachinePrecision]), $MachinePrecision], N[(z + N[(3.0 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.45 \cdot 10^{+30} \lor \neg \left(y \leq 6.5 \cdot 10^{+77}\right):\\
\;\;\;\;z + 2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;z + 3 \cdot x\\
\end{array}
\end{array}
if y < -3.4499999999999999e30 or 6.5e77 < y Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 83.9%
if -3.4499999999999999e30 < y < 6.5e77Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in y around 0 92.9%
+-commutative92.9%
associate-+l+92.9%
distribute-lft1-in92.9%
metadata-eval92.9%
Simplified92.9%
Final simplification88.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1e+69) (not (<= y 8.5e+88))) (* 2.0 y) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1e+69) || !(y <= 8.5e+88)) {
tmp = 2.0 * y;
} else {
tmp = 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 <= (-1d+69)) .or. (.not. (y <= 8.5d+88))) then
tmp = 2.0d0 * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1e+69) || !(y <= 8.5e+88)) {
tmp = 2.0 * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1e+69) or not (y <= 8.5e+88): tmp = 2.0 * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1e+69) || !(y <= 8.5e+88)) tmp = Float64(2.0 * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1e+69) || ~((y <= 8.5e+88))) tmp = 2.0 * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1e+69], N[Not[LessEqual[y, 8.5e+88]], $MachinePrecision]], N[(2.0 * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+69} \lor \neg \left(y \leq 8.5 \cdot 10^{+88}\right):\\
\;\;\;\;2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.0000000000000001e69 or 8.5000000000000005e88 < y Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 69.4%
if -1.0000000000000001e69 < y < 8.5000000000000005e88Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in z around inf 48.7%
Final simplification57.5%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
count-299.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in z around inf 34.9%
Final simplification34.9%
herbie shell --seed 2024046
(FPCore (x y z)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendInside from plot-0.2.3.4"
:precision binary64
(+ (+ (+ (+ (+ x y) y) x) z) x))