
(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 (+ x y)))))
double code(double x, double y, double z) {
return x + (y + (z * (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 + (z * (x + y)))
end function
public static double code(double x, double y, double z) {
return x + (y + (z * (x + y)));
}
def code(x, y, z): return x + (y + (z * (x + y)))
function code(x, y, z) return Float64(x + Float64(y + Float64(z * Float64(x + y)))) end
function tmp = code(x, y, z) tmp = x + (y + (z * (x + y))); end
code[x_, y_, z_] := N[(x + N[(y + N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y + z \cdot \left(x + y\right)\right)
\end{array}
Initial program 100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
+-commutative100.0%
associate-+r+100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -2e-7) (not (<= z 9.5e-11))) (* x (+ z 1.0)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2e-7) || !(z <= 9.5e-11)) {
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 <= (-2d-7)) .or. (.not. (z <= 9.5d-11))) 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 <= -2e-7) || !(z <= 9.5e-11)) {
tmp = x * (z + 1.0);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2e-7) or not (z <= 9.5e-11): tmp = x * (z + 1.0) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2e-7) || !(z <= 9.5e-11)) 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 <= -2e-7) || ~((z <= 9.5e-11))) tmp = x * (z + 1.0); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2e-7], N[Not[LessEqual[z, 9.5e-11]], $MachinePrecision]], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{-7} \lor \neg \left(z \leq 9.5 \cdot 10^{-11}\right):\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -1.9999999999999999e-7 or 9.49999999999999951e-11 < z Initial program 99.9%
Taylor expanded in x around inf 55.9%
if -1.9999999999999999e-7 < z < 9.49999999999999951e-11Initial program 100.0%
Taylor expanded in z around 0 99.1%
+-commutative99.1%
Simplified99.1%
Final simplification76.7%
(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 98.0%
+-commutative98.0%
Simplified98.0%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.1%
+-commutative97.1%
Simplified97.1%
Final simplification97.6%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* z x) (if (<= z 1.0) x (* z x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = z * x;
} else if (z <= 1.0) {
tmp = x;
} else {
tmp = z * 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 (z <= (-1.0d0)) then
tmp = z * x
else if (z <= 1.0d0) then
tmp = x
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = z * x;
} else if (z <= 1.0) {
tmp = x;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = z * x elif z <= 1.0: tmp = x else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(z * x); elseif (z <= 1.0) tmp = x; else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = z * x; elseif (z <= 1.0) tmp = x; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(z * x), $MachinePrecision], If[LessEqual[z, 1.0], x, N[(z * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in x around inf 56.1%
distribute-rgt-in56.1%
*-lft-identity56.1%
+-commutative56.1%
Applied egg-rr56.1%
Taylor expanded in z around inf 56.1%
if -1 < z < 1Initial program 100.0%
Taylor expanded in x around inf 52.0%
Taylor expanded in z around 0 50.7%
Final simplification53.4%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* z x) (if (<= z 280000000.0) (+ x y) (* z x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = z * x;
} else if (z <= 280000000.0) {
tmp = x + y;
} else {
tmp = z * 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 (z <= (-1.0d0)) then
tmp = z * x
else if (z <= 280000000.0d0) then
tmp = x + y
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = z * x;
} else if (z <= 280000000.0) {
tmp = x + y;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = z * x elif z <= 280000000.0: tmp = x + y else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(z * x); elseif (z <= 280000000.0) tmp = Float64(x + y); else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = z * x; elseif (z <= 280000000.0) tmp = x + y; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(z * x), $MachinePrecision], If[LessEqual[z, 280000000.0], N[(x + y), $MachinePrecision], N[(z * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;z \leq 280000000:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if z < -1 or 2.8e8 < z Initial program 100.0%
Taylor expanded in x around inf 56.6%
distribute-rgt-in56.6%
*-lft-identity56.6%
+-commutative56.6%
Applied egg-rr56.6%
Taylor expanded in z around inf 56.6%
if -1 < z < 2.8e8Initial program 100.0%
Taylor expanded in z around 0 95.2%
+-commutative95.2%
Simplified95.2%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.7e-93) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.7e-93) {
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 <= (-1.7d-93)) 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 <= -1.7e-93) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.7e-93: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.7e-93) 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 <= -1.7e-93) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.7e-93], 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 -1.7 \cdot 10^{-93}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if x < -1.70000000000000001e-93Initial program 100.0%
Taylor expanded in x around inf 68.1%
if -1.70000000000000001e-93 < x Initial program 100.0%
Taylor expanded in x around 0 57.2%
Final simplification61.1%
(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 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 54.1%
Taylor expanded in z around 0 26.6%
Final simplification26.6%
herbie shell --seed 2023297
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))