
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
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 + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
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 + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
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 + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -1.0)
(* x z)
(if (<= z -6.8e-105)
y
(if (<= z -5.5e-225)
x
(if (<= z 4.2e-231)
y
(if (<= z 2.55e-85)
x
(if (<= z 3.4e-43) y (if (<= z 6.3e+24) x (* x z)))))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= -6.8e-105) {
tmp = y;
} else if (z <= -5.5e-225) {
tmp = x;
} else if (z <= 4.2e-231) {
tmp = y;
} else if (z <= 2.55e-85) {
tmp = x;
} else if (z <= 3.4e-43) {
tmp = y;
} else if (z <= 6.3e+24) {
tmp = x;
} else {
tmp = x * 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 <= (-1.0d0)) then
tmp = x * z
else if (z <= (-6.8d-105)) then
tmp = y
else if (z <= (-5.5d-225)) then
tmp = x
else if (z <= 4.2d-231) then
tmp = y
else if (z <= 2.55d-85) then
tmp = x
else if (z <= 3.4d-43) then
tmp = y
else if (z <= 6.3d+24) then
tmp = x
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= -6.8e-105) {
tmp = y;
} else if (z <= -5.5e-225) {
tmp = x;
} else if (z <= 4.2e-231) {
tmp = y;
} else if (z <= 2.55e-85) {
tmp = x;
} else if (z <= 3.4e-43) {
tmp = y;
} else if (z <= 6.3e+24) {
tmp = x;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x * z elif z <= -6.8e-105: tmp = y elif z <= -5.5e-225: tmp = x elif z <= 4.2e-231: tmp = y elif z <= 2.55e-85: tmp = x elif z <= 3.4e-43: tmp = y elif z <= 6.3e+24: tmp = x else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(x * z); elseif (z <= -6.8e-105) tmp = y; elseif (z <= -5.5e-225) tmp = x; elseif (z <= 4.2e-231) tmp = y; elseif (z <= 2.55e-85) tmp = x; elseif (z <= 3.4e-43) tmp = y; elseif (z <= 6.3e+24) tmp = x; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = x * z; elseif (z <= -6.8e-105) tmp = y; elseif (z <= -5.5e-225) tmp = x; elseif (z <= 4.2e-231) tmp = y; elseif (z <= 2.55e-85) tmp = x; elseif (z <= 3.4e-43) tmp = y; elseif (z <= 6.3e+24) tmp = x; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, -6.8e-105], y, If[LessEqual[z, -5.5e-225], x, If[LessEqual[z, 4.2e-231], y, If[LessEqual[z, 2.55e-85], x, If[LessEqual[z, 3.4e-43], y, If[LessEqual[z, 6.3e+24], x, N[(x * z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -6.8 \cdot 10^{-105}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq -5.5 \cdot 10^{-225}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.2 \cdot 10^{-231}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 2.55 \cdot 10^{-85}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.4 \cdot 10^{-43}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 6.3 \cdot 10^{+24}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -1 or 6.30000000000000038e24 < z Initial program 100.0%
Taylor expanded in x around inf 62.3%
+-commutative62.3%
distribute-lft-in62.3%
*-rgt-identity62.3%
Applied egg-rr62.3%
Taylor expanded in z around inf 60.3%
if -1 < z < -6.79999999999999984e-105 or -5.5000000000000002e-225 < z < 4.19999999999999978e-231 or 2.5500000000000001e-85 < z < 3.4000000000000001e-43Initial program 100.0%
Taylor expanded in x around 0 49.6%
Taylor expanded in z around 0 48.6%
if -6.79999999999999984e-105 < z < -5.5000000000000002e-225 or 4.19999999999999978e-231 < z < 2.5500000000000001e-85 or 3.4000000000000001e-43 < z < 6.30000000000000038e24Initial program 100.0%
Taylor expanded in x around inf 49.4%
Taylor expanded in z around 0 48.0%
Final simplification54.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.4e-8) (not (<= z 6.9e-16))) (* x (+ z 1.0)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e-8) || !(z <= 6.9e-16)) {
tmp = x * (z + 1.0);
} 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 ((z <= (-2.4d-8)) .or. (.not. (z <= 6.9d-16))) then
tmp = x * (z + 1.0d0)
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e-8) || !(z <= 6.9e-16)) {
tmp = x * (z + 1.0);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.4e-8) or not (z <= 6.9e-16): tmp = x * (z + 1.0) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.4e-8) || !(z <= 6.9e-16)) tmp = Float64(x * Float64(z + 1.0)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.4e-8) || ~((z <= 6.9e-16))) tmp = x * (z + 1.0); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.4e-8], N[Not[LessEqual[z, 6.9e-16]], $MachinePrecision]], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{-8} \lor \neg \left(z \leq 6.9 \cdot 10^{-16}\right):\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -2.39999999999999998e-8 or 6.8999999999999997e-16 < z Initial program 100.0%
Taylor expanded in x around inf 61.4%
if -2.39999999999999998e-8 < z < 6.8999999999999997e-16Initial program 100.0%
Taylor expanded in z around 0 99.8%
+-commutative99.8%
Simplified99.8%
Final simplification80.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (* z (+ x y)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = z * (x + 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 ((z <= (-1.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = z * (x + y)
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = z * (x + y);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.0): tmp = z * (x + y) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) tmp = Float64(z * Float64(x + y)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.0) || ~((z <= 1.0))) tmp = z * (x + y); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;z \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 97.1%
+-commutative97.1%
Simplified97.1%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.2%
+-commutative98.2%
Simplified98.2%
Final simplification97.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* x z) (if (<= z 6.3e+24) (+ x y) (* x z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= 6.3e+24) {
tmp = x + y;
} else {
tmp = x * 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 <= (-1.0d0)) then
tmp = x * z
else if (z <= 6.3d+24) then
tmp = x + y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= 6.3e+24) {
tmp = x + y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x * z elif z <= 6.3e+24: tmp = x + y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(x * z); elseif (z <= 6.3e+24) tmp = Float64(x + y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = x * z; elseif (z <= 6.3e+24) tmp = x + y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, 6.3e+24], N[(x + y), $MachinePrecision], N[(x * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 6.3 \cdot 10^{+24}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -1 or 6.30000000000000038e24 < z Initial program 100.0%
Taylor expanded in x around inf 62.3%
+-commutative62.3%
distribute-lft-in62.3%
*-rgt-identity62.3%
Applied egg-rr62.3%
Taylor expanded in z around inf 60.3%
if -1 < z < 6.30000000000000038e24Initial program 100.0%
Taylor expanded in z around 0 96.9%
+-commutative96.9%
Simplified96.9%
Final simplification79.2%
(FPCore (x y z) :precision binary64 (if (<= x -8.6e-48) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -8.6e-48) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.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) :: tmp
if (x <= (-8.6d-48)) then
tmp = x * (z + 1.0d0)
else
tmp = y * (z + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -8.6e-48) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -8.6e-48: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -8.6e-48) tmp = Float64(x * Float64(z + 1.0)); else tmp = Float64(y * Float64(z + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -8.6e-48) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -8.6e-48], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.6 \cdot 10^{-48}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if x < -8.6e-48Initial program 100.0%
Taylor expanded in x around inf 75.1%
if -8.6e-48 < x Initial program 100.0%
Taylor expanded in x around 0 55.5%
Final simplification62.1%
(FPCore (x y z) :precision binary64 (if (<= y 2.75e-158) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.75e-158) {
tmp = x;
} else {
tmp = 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 <= 2.75d-158) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 2.75e-158) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.75e-158: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.75e-158) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2.75e-158) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.75e-158], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.75 \cdot 10^{-158}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 2.75000000000000013e-158Initial program 100.0%
Taylor expanded in x around inf 65.5%
Taylor expanded in z around 0 30.6%
if 2.75000000000000013e-158 < y Initial program 100.0%
Taylor expanded in x around 0 59.2%
Taylor expanded in z around 0 37.1%
Final simplification33.2%
(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 x around inf 56.3%
Taylor expanded in z around 0 27.0%
Final simplification27.0%
herbie shell --seed 2023293
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))