
(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 -150000000000.0)
(* x z)
(if (<= z -1.05e-246)
x
(if (<= z 1.2e-234)
y
(if (<= z 1.2e-183)
x
(if (<= z 3.8e-111)
y
(if (<= z 4.5e-85) x (if (<= z 0.00172) y (* x z)))))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -150000000000.0) {
tmp = x * z;
} else if (z <= -1.05e-246) {
tmp = x;
} else if (z <= 1.2e-234) {
tmp = y;
} else if (z <= 1.2e-183) {
tmp = x;
} else if (z <= 3.8e-111) {
tmp = y;
} else if (z <= 4.5e-85) {
tmp = x;
} else if (z <= 0.00172) {
tmp = 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 <= (-150000000000.0d0)) then
tmp = x * z
else if (z <= (-1.05d-246)) then
tmp = x
else if (z <= 1.2d-234) then
tmp = y
else if (z <= 1.2d-183) then
tmp = x
else if (z <= 3.8d-111) then
tmp = y
else if (z <= 4.5d-85) then
tmp = x
else if (z <= 0.00172d0) then
tmp = 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 <= -150000000000.0) {
tmp = x * z;
} else if (z <= -1.05e-246) {
tmp = x;
} else if (z <= 1.2e-234) {
tmp = y;
} else if (z <= 1.2e-183) {
tmp = x;
} else if (z <= 3.8e-111) {
tmp = y;
} else if (z <= 4.5e-85) {
tmp = x;
} else if (z <= 0.00172) {
tmp = y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -150000000000.0: tmp = x * z elif z <= -1.05e-246: tmp = x elif z <= 1.2e-234: tmp = y elif z <= 1.2e-183: tmp = x elif z <= 3.8e-111: tmp = y elif z <= 4.5e-85: tmp = x elif z <= 0.00172: tmp = y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -150000000000.0) tmp = Float64(x * z); elseif (z <= -1.05e-246) tmp = x; elseif (z <= 1.2e-234) tmp = y; elseif (z <= 1.2e-183) tmp = x; elseif (z <= 3.8e-111) tmp = y; elseif (z <= 4.5e-85) tmp = x; elseif (z <= 0.00172) tmp = y; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -150000000000.0) tmp = x * z; elseif (z <= -1.05e-246) tmp = x; elseif (z <= 1.2e-234) tmp = y; elseif (z <= 1.2e-183) tmp = x; elseif (z <= 3.8e-111) tmp = y; elseif (z <= 4.5e-85) tmp = x; elseif (z <= 0.00172) tmp = y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -150000000000.0], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.05e-246], x, If[LessEqual[z, 1.2e-234], y, If[LessEqual[z, 1.2e-183], x, If[LessEqual[z, 3.8e-111], y, If[LessEqual[z, 4.5e-85], x, If[LessEqual[z, 0.00172], y, N[(x * z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -150000000000:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -1.05 \cdot 10^{-246}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{-234}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{-183}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-111}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{-85}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 0.00172:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -1.5e11 or 0.00171999999999999996 < z Initial program 100.0%
Taylor expanded in z around inf 98.7%
Taylor expanded in y around 0 53.3%
if -1.5e11 < z < -1.04999999999999997e-246 or 1.1999999999999999e-234 < z < 1.19999999999999996e-183 or 3.80000000000000022e-111 < z < 4.50000000000000004e-85Initial program 100.0%
Taylor expanded in x around inf 48.1%
Taylor expanded in z around 0 47.0%
if -1.04999999999999997e-246 < z < 1.1999999999999999e-234 or 1.19999999999999996e-183 < z < 3.80000000000000022e-111 or 4.50000000000000004e-85 < z < 0.00171999999999999996Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 51.4%
Taylor expanded in z around 0 51.4%
Final simplification50.9%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* x z) (if (<= z 2.15e+15) (+ x y) (if (<= z 3.6e+90) (* y (+ z 1.0)) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= 2.15e+15) {
tmp = x + y;
} else if (z <= 3.6e+90) {
tmp = y * (z + 1.0);
} 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 <= 2.15d+15) then
tmp = x + y
else if (z <= 3.6d+90) then
tmp = y * (z + 1.0d0)
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 <= 2.15e+15) {
tmp = x + y;
} else if (z <= 3.6e+90) {
tmp = y * (z + 1.0);
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x * z elif z <= 2.15e+15: tmp = x + y elif z <= 3.6e+90: tmp = y * (z + 1.0) else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(x * z); elseif (z <= 2.15e+15) tmp = Float64(x + y); elseif (z <= 3.6e+90) tmp = Float64(y * Float64(z + 1.0)); 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 <= 2.15e+15) tmp = x + y; elseif (z <= 3.6e+90) tmp = y * (z + 1.0); 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, 2.15e+15], N[(x + y), $MachinePrecision], If[LessEqual[z, 3.6e+90], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 2.15 \cdot 10^{+15}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+90}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -1 or 3.6e90 < z Initial program 100.0%
Taylor expanded in z around inf 99.7%
Taylor expanded in y around 0 54.3%
if -1 < z < 2.15e15Initial program 100.0%
Taylor expanded in z around 0 95.5%
if 2.15e15 < z < 3.6e90Initial program 99.9%
Taylor expanded in x around 0 44.6%
Final simplification76.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* x z) (if (<= z 2.15e+15) (+ x y) (if (<= z 2.7e+90) (* y z) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= 2.15e+15) {
tmp = x + y;
} else if (z <= 2.7e+90) {
tmp = y * z;
} 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 <= 2.15d+15) then
tmp = x + y
else if (z <= 2.7d+90) then
tmp = y * z
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 <= 2.15e+15) {
tmp = x + y;
} else if (z <= 2.7e+90) {
tmp = y * z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x * z elif z <= 2.15e+15: tmp = x + y elif z <= 2.7e+90: tmp = y * z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(x * z); elseif (z <= 2.15e+15) tmp = Float64(x + y); elseif (z <= 2.7e+90) tmp = Float64(y * z); 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 <= 2.15e+15) tmp = x + y; elseif (z <= 2.7e+90) tmp = y * z; 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, 2.15e+15], N[(x + y), $MachinePrecision], If[LessEqual[z, 2.7e+90], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 2.15 \cdot 10^{+15}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{+90}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -1 or 2.7e90 < z Initial program 100.0%
Taylor expanded in z around inf 99.7%
Taylor expanded in y around 0 54.3%
if -1 < z < 2.15e15Initial program 100.0%
Taylor expanded in z around 0 95.5%
if 2.15e15 < z < 2.7e90Initial program 99.9%
Taylor expanded in z around inf 99.8%
Taylor expanded in y around inf 44.4%
*-commutative44.4%
Simplified44.4%
Final simplification76.8%
(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 99.2%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.3%
Final simplification98.2%
(FPCore (x y z) :precision binary64 (if (<= y 4e-83) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= 4e-83) {
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 (y <= 4d-83) 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 (y <= 4e-83) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 4e-83: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 4e-83) 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 (y <= 4e-83) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 4e-83], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4 \cdot 10^{-83}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if y < 4.0000000000000001e-83Initial program 100.0%
Taylor expanded in x around inf 59.5%
if 4.0000000000000001e-83 < y Initial program 100.0%
Taylor expanded in x around 0 69.4%
Final simplification62.5%
(FPCore (x y z) :precision binary64 (if (<= y 4.8e-83) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 4.8e-83) {
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 <= 4.8d-83) 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 <= 4.8e-83) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 4.8e-83: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 4.8e-83) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 4.8e-83) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 4.8e-83], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.8 \cdot 10^{-83}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 4.8000000000000002e-83Initial program 100.0%
Taylor expanded in x around inf 59.5%
Taylor expanded in z around 0 33.5%
if 4.8000000000000002e-83 < y Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 69.4%
Taylor expanded in z around 0 40.4%
Final simplification35.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 x around inf 51.6%
Taylor expanded in z around 0 28.4%
Final simplification28.4%
herbie shell --seed 2023185
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))