
(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 10 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 (+ (* z (+ x y)) (+ x y)))
double code(double x, double y, double z) {
return (z * (x + y)) + (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 = (z * (x + y)) + (x + y)
end function
public static double code(double x, double y, double z) {
return (z * (x + y)) + (x + y);
}
def code(x, y, z): return (z * (x + y)) + (x + y)
function code(x, y, z) return Float64(Float64(z * Float64(x + y)) + Float64(x + y)) end
function tmp = code(x, y, z) tmp = (z * (x + y)) + (x + y); end
code[x_, y_, z_] := N[(N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision] + N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \left(x + y\right) + \left(x + y\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= (+ z 1.0) -5e+66)
(* y z)
(if (or (<= (+ z 1.0) -10000000.0) (not (<= (+ z 1.0) 1.0)))
(* x (+ z 1.0))
(+ x y))))
double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= -5e+66) {
tmp = y * z;
} else if (((z + 1.0) <= -10000000.0) || !((z + 1.0) <= 1.0)) {
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 + 1.0d0) <= (-5d+66)) then
tmp = y * z
else if (((z + 1.0d0) <= (-10000000.0d0)) .or. (.not. ((z + 1.0d0) <= 1.0d0))) 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 + 1.0) <= -5e+66) {
tmp = y * z;
} else if (((z + 1.0) <= -10000000.0) || !((z + 1.0) <= 1.0)) {
tmp = x * (z + 1.0);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z + 1.0) <= -5e+66: tmp = y * z elif ((z + 1.0) <= -10000000.0) or not ((z + 1.0) <= 1.0): tmp = x * (z + 1.0) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z + 1.0) <= -5e+66) tmp = Float64(y * z); elseif ((Float64(z + 1.0) <= -10000000.0) || !(Float64(z + 1.0) <= 1.0)) 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 + 1.0) <= -5e+66) tmp = y * z; elseif (((z + 1.0) <= -10000000.0) || ~(((z + 1.0) <= 1.0))) tmp = x * (z + 1.0); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z + 1.0), $MachinePrecision], -5e+66], N[(y * z), $MachinePrecision], If[Or[LessEqual[N[(z + 1.0), $MachinePrecision], -10000000.0], N[Not[LessEqual[N[(z + 1.0), $MachinePrecision], 1.0]], $MachinePrecision]], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z + 1 \leq -5 \cdot 10^{+66}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z + 1 \leq -10000000 \lor \neg \left(z + 1 \leq 1\right):\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < -4.99999999999999991e66Initial program 99.9%
Taylor expanded in z around inf 99.9%
Taylor expanded in x around 0 56.5%
if -4.99999999999999991e66 < (+.f64 z #s(literal 1 binary64)) < -1e7 or 1 < (+.f64 z #s(literal 1 binary64)) Initial program 99.9%
Taylor expanded in x around inf 60.4%
if -1e7 < (+.f64 z #s(literal 1 binary64)) < 1Initial program 100.0%
Taylor expanded in z around 0 100.0%
+-commutative100.0%
Simplified100.0%
Final simplification76.3%
(FPCore (x y z) :precision binary64 (if (<= z -2.2e+66) (* y z) (if (<= z -1.0) (* x z) (if (<= z 6e-157) y (if (<= z 205.0) x (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e+66) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = x * z;
} else if (z <= 6e-157) {
tmp = y;
} else if (z <= 205.0) {
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 <= (-2.2d+66)) then
tmp = y * z
else if (z <= (-1.0d0)) then
tmp = x * z
else if (z <= 6d-157) then
tmp = y
else if (z <= 205.0d0) 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 <= -2.2e+66) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = x * z;
} else if (z <= 6e-157) {
tmp = y;
} else if (z <= 205.0) {
tmp = x;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.2e+66: tmp = y * z elif z <= -1.0: tmp = x * z elif z <= 6e-157: tmp = y elif z <= 205.0: tmp = x else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.2e+66) tmp = Float64(y * z); elseif (z <= -1.0) tmp = Float64(x * z); elseif (z <= 6e-157) tmp = y; elseif (z <= 205.0) tmp = x; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.2e+66) tmp = y * z; elseif (z <= -1.0) tmp = x * z; elseif (z <= 6e-157) tmp = y; elseif (z <= 205.0) tmp = x; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.2e+66], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, 6e-157], y, If[LessEqual[z, 205.0], x, N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+66}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 6 \cdot 10^{-157}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 205:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -2.1999999999999998e66Initial program 99.9%
Taylor expanded in z around inf 99.9%
Taylor expanded in x around 0 56.5%
if -2.1999999999999998e66 < z < -1 or 205 < z Initial program 100.0%
Taylor expanded in z around inf 97.0%
Taylor expanded in x around inf 59.8%
*-commutative59.8%
Simplified59.8%
if -1 < z < 6e-157Initial program 100.0%
Taylor expanded in z around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 52.7%
if 6e-157 < z < 205Initial program 99.8%
Taylor expanded in z around 0 89.3%
+-commutative89.3%
Simplified89.3%
Taylor expanded in y around 0 52.5%
Final simplification55.9%
(FPCore (x y z) :precision binary64 (if (<= z -2.5e+66) (* y z) (if (or (<= z -1.0) (not (<= z 3700.0))) (* x z) (+ x y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.5e+66) {
tmp = y * z;
} else if ((z <= -1.0) || !(z <= 3700.0)) {
tmp = x * z;
} 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.5d+66)) then
tmp = y * z
else if ((z <= (-1.0d0)) .or. (.not. (z <= 3700.0d0))) then
tmp = x * z
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.5e+66) {
tmp = y * z;
} else if ((z <= -1.0) || !(z <= 3700.0)) {
tmp = x * z;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.5e+66: tmp = y * z elif (z <= -1.0) or not (z <= 3700.0): tmp = x * z else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.5e+66) tmp = Float64(y * z); elseif ((z <= -1.0) || !(z <= 3700.0)) tmp = Float64(x * z); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.5e+66) tmp = y * z; elseif ((z <= -1.0) || ~((z <= 3700.0))) tmp = x * z; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.5e+66], N[(y * z), $MachinePrecision], If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 3700.0]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \cdot 10^{+66}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1 \lor \neg \left(z \leq 3700\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -2.49999999999999996e66Initial program 99.9%
Taylor expanded in z around inf 99.9%
Taylor expanded in x around 0 56.5%
if -2.49999999999999996e66 < z < -1 or 3700 < z Initial program 100.0%
Taylor expanded in z around inf 97.7%
Taylor expanded in x around inf 60.4%
*-commutative60.4%
Simplified60.4%
if -1 < z < 3700Initial program 99.9%
Taylor expanded in z around 0 95.9%
+-commutative95.9%
Simplified95.9%
Final simplification75.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* y z) (if (<= z 4.8e-157) y (if (<= z 0.108) x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = y * z;
} else if (z <= 4.8e-157) {
tmp = y;
} else if (z <= 0.108) {
tmp = x;
} else {
tmp = y * 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 = y * z
else if (z <= 4.8d-157) then
tmp = y
else if (z <= 0.108d0) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = y * z;
} else if (z <= 4.8e-157) {
tmp = y;
} else if (z <= 0.108) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = y * z elif z <= 4.8e-157: tmp = y elif z <= 0.108: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(y * z); elseif (z <= 4.8e-157) tmp = y; elseif (z <= 0.108) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = y * z; elseif (z <= 4.8e-157) tmp = y; elseif (z <= 0.108) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 4.8e-157], y, If[LessEqual[z, 0.108], x, N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 4.8 \cdot 10^{-157}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 0.108:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1 or 0.107999999999999999 < z Initial program 100.0%
Taylor expanded in z around inf 96.5%
Taylor expanded in x around 0 46.1%
if -1 < z < 4.8e-157Initial program 100.0%
Taylor expanded in z around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 52.7%
if 4.8e-157 < z < 0.107999999999999999Initial program 99.8%
Taylor expanded in z around 0 95.7%
+-commutative95.7%
Simplified95.7%
Taylor expanded in y around 0 56.9%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-256) (+ x (* x z)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-256) {
tmp = x + (x * z);
} 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 + y) <= (-2d-256)) then
tmp = x + (x * z)
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 + y) <= -2e-256) {
tmp = x + (x * z);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -2e-256: tmp = x + (x * z) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-256) tmp = Float64(x + Float64(x * z)); else tmp = Float64(y * Float64(z + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x + y) <= -2e-256) tmp = x + (x * z); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-256], N[(x + N[(x * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-256}:\\
\;\;\;\;x + x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -1.99999999999999995e-256Initial program 99.9%
Taylor expanded in x around inf 56.3%
distribute-lft-in56.4%
*-rgt-identity56.4%
Applied egg-rr56.4%
if -1.99999999999999995e-256 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 51.9%
Final simplification54.2%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-256) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-256) {
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 + y) <= (-2d-256)) 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 + y) <= -2e-256) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -2e-256: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-256) 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 + y) <= -2e-256) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-256], 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 + y \leq -2 \cdot 10^{-256}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -1.99999999999999995e-256Initial program 99.9%
Taylor expanded in x around inf 56.3%
if -1.99999999999999995e-256 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 51.9%
(FPCore (x y z) :precision binary64 (* (+ z 1.0) (+ x y)))
double code(double x, double y, double z) {
return (z + 1.0) * (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 = (z + 1.0d0) * (x + y)
end function
public static double code(double x, double y, double z) {
return (z + 1.0) * (x + y);
}
def code(x, y, z): return (z + 1.0) * (x + y)
function code(x, y, z) return Float64(Float64(z + 1.0) * Float64(x + y)) end
function tmp = code(x, y, z) tmp = (z + 1.0) * (x + y); end
code[x_, y_, z_] := N[(N[(z + 1.0), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(z + 1\right) \cdot \left(x + y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y 7e-106) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 7e-106) {
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 <= 7d-106) 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 <= 7e-106) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 7e-106: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 7e-106) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 7e-106) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 7e-106], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7 \cdot 10^{-106}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 7e-106Initial program 99.9%
Taylor expanded in z around 0 45.8%
+-commutative45.8%
Simplified45.8%
Taylor expanded in y around 0 28.4%
if 7e-106 < y Initial program 100.0%
Taylor expanded in z around 0 45.0%
+-commutative45.0%
Simplified45.0%
Taylor expanded in y around inf 30.1%
(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 z around 0 45.5%
+-commutative45.5%
Simplified45.5%
Taylor expanded in y around 0 24.6%
herbie shell --seed 2024163
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))