
(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 9 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) (* (+ x y) z)))
double code(double x, double y, double z) {
return (x + y) + ((x + y) * z);
}
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) + ((x + y) * z)
end function
public static double code(double x, double y, double z) {
return (x + y) + ((x + y) * z);
}
def code(x, y, z): return (x + y) + ((x + y) * z)
function code(x, y, z) return Float64(Float64(x + y) + Float64(Float64(x + y) * z)) end
function tmp = code(x, y, z) tmp = (x + y) + ((x + y) * z); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] + N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) + \left(x + y\right) \cdot z
\end{array}
Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -0.0075)
(* y z)
(if (<= z -1.35e-199)
y
(if (<= z 2.45e-163) x (if (<= z 9e+24) y (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.0075) {
tmp = y * z;
} else if (z <= -1.35e-199) {
tmp = y;
} else if (z <= 2.45e-163) {
tmp = x;
} else if (z <= 9e+24) {
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 <= (-0.0075d0)) then
tmp = y * z
else if (z <= (-1.35d-199)) then
tmp = y
else if (z <= 2.45d-163) then
tmp = x
else if (z <= 9d+24) 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 <= -0.0075) {
tmp = y * z;
} else if (z <= -1.35e-199) {
tmp = y;
} else if (z <= 2.45e-163) {
tmp = x;
} else if (z <= 9e+24) {
tmp = y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.0075: tmp = y * z elif z <= -1.35e-199: tmp = y elif z <= 2.45e-163: tmp = x elif z <= 9e+24: tmp = y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.0075) tmp = Float64(y * z); elseif (z <= -1.35e-199) tmp = y; elseif (z <= 2.45e-163) tmp = x; elseif (z <= 9e+24) tmp = y; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -0.0075) tmp = y * z; elseif (z <= -1.35e-199) tmp = y; elseif (z <= 2.45e-163) tmp = x; elseif (z <= 9e+24) tmp = y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.0075], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.35e-199], y, If[LessEqual[z, 2.45e-163], x, If[LessEqual[z, 9e+24], y, N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.0075:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.35 \cdot 10^{-199}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 2.45 \cdot 10^{-163}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 9 \cdot 10^{+24}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -0.0074999999999999997Initial program 100.0%
Taylor expanded in z around inf 98.0%
Taylor expanded in x around 0 60.8%
if -0.0074999999999999997 < z < -1.34999999999999995e-199 or 2.4500000000000001e-163 < z < 9.00000000000000039e24Initial program 99.9%
Taylor expanded in z around 0 94.0%
+-commutative94.0%
Simplified94.0%
Taylor expanded in y around inf 61.8%
if -1.34999999999999995e-199 < z < 2.4500000000000001e-163Initial program 100.0%
Taylor expanded in z around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 55.4%
if 9.00000000000000039e24 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 44.7%
*-commutative44.7%
Simplified44.7%
Final simplification55.6%
(FPCore (x y z) :precision binary64 (if (<= z -0.0075) (* y z) (if (<= z -1.2e-200) y (if (<= z 2.1e-163) x (if (<= z 1.0) y (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.0075) {
tmp = y * z;
} else if (z <= -1.2e-200) {
tmp = y;
} else if (z <= 2.1e-163) {
tmp = x;
} else if (z <= 1.0) {
tmp = y;
} 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 <= (-0.0075d0)) then
tmp = y * z
else if (z <= (-1.2d-200)) then
tmp = y
else if (z <= 2.1d-163) then
tmp = x
else if (z <= 1.0d0) then
tmp = y
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -0.0075) {
tmp = y * z;
} else if (z <= -1.2e-200) {
tmp = y;
} else if (z <= 2.1e-163) {
tmp = x;
} else if (z <= 1.0) {
tmp = y;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.0075: tmp = y * z elif z <= -1.2e-200: tmp = y elif z <= 2.1e-163: tmp = x elif z <= 1.0: tmp = y else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.0075) tmp = Float64(y * z); elseif (z <= -1.2e-200) tmp = y; elseif (z <= 2.1e-163) tmp = x; elseif (z <= 1.0) tmp = y; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -0.0075) tmp = y * z; elseif (z <= -1.2e-200) tmp = y; elseif (z <= 2.1e-163) tmp = x; elseif (z <= 1.0) tmp = y; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.0075], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.2e-200], y, If[LessEqual[z, 2.1e-163], x, If[LessEqual[z, 1.0], y, N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.0075:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.2 \cdot 10^{-200}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-163}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -0.0074999999999999997 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 98.9%
Taylor expanded in x around 0 60.9%
if -0.0074999999999999997 < z < -1.20000000000000001e-200 or 2.09999999999999998e-163 < z < 1Initial program 99.9%
Taylor expanded in z around 0 97.1%
+-commutative97.1%
Simplified97.1%
Taylor expanded in y around inf 63.8%
if -1.20000000000000001e-200 < z < 2.09999999999999998e-163Initial program 100.0%
Taylor expanded in z around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 55.4%
(FPCore (x y z) :precision binary64 (if (<= (+ z 1.0) -200000.0) (* y z) (if (<= (+ z 1.0) 1.0) (+ x y) (* x (+ z 1.0)))))
double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= -200000.0) {
tmp = y * z;
} else if ((z + 1.0) <= 1.0) {
tmp = x + y;
} else {
tmp = x * (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 ((z + 1.0d0) <= (-200000.0d0)) then
tmp = y * z
else if ((z + 1.0d0) <= 1.0d0) then
tmp = x + y
else
tmp = x * (z + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z + 1.0) <= -200000.0) {
tmp = y * z;
} else if ((z + 1.0) <= 1.0) {
tmp = x + y;
} else {
tmp = x * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z + 1.0) <= -200000.0: tmp = y * z elif (z + 1.0) <= 1.0: tmp = x + y else: tmp = x * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z + 1.0) <= -200000.0) tmp = Float64(y * z); elseif (Float64(z + 1.0) <= 1.0) tmp = Float64(x + y); else tmp = Float64(x * Float64(z + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z + 1.0) <= -200000.0) tmp = y * z; elseif ((z + 1.0) <= 1.0) tmp = x + y; else tmp = x * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z + 1.0), $MachinePrecision], -200000.0], N[(y * z), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 1.0], N[(x + y), $MachinePrecision], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z + 1 \leq -200000:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z + 1 \leq 1:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < -2e5Initial program 100.0%
Taylor expanded in z around inf 99.3%
Taylor expanded in x around 0 61.6%
if -2e5 < (+.f64 z #s(literal 1 binary64)) < 1Initial program 100.0%
Taylor expanded in z around 0 98.3%
+-commutative98.3%
Simplified98.3%
if 1 < (+.f64 z #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in x around inf 43.5%
Final simplification72.3%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* y z) (if (<= z 9e+24) (+ x y) (* x z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = y * z;
} else if (z <= 9e+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 = y * z
else if (z <= 9d+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 = y * z;
} else if (z <= 9e+24) {
tmp = x + y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = y * z elif z <= 9e+24: tmp = x + y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(y * z); elseif (z <= 9e+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 = y * z; elseif (z <= 9e+24) tmp = x + y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 9e+24], N[(x + y), $MachinePrecision], N[(x * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 9 \cdot 10^{+24}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -1Initial program 100.0%
Taylor expanded in z around inf 99.3%
Taylor expanded in x around 0 61.6%
if -1 < z < 9.00000000000000039e24Initial program 100.0%
Taylor expanded in z around 0 96.4%
+-commutative96.4%
Simplified96.4%
if 9.00000000000000039e24 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 44.7%
*-commutative44.7%
Simplified44.7%
Final simplification72.4%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -5e-256) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -5e-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) <= (-5d-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) <= -5e-256) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -5e-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) <= -5e-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) <= -5e-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], -5e-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 -5 \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) < -5e-256Initial program 100.0%
Taylor expanded in x around inf 48.3%
if -5e-256 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 62.3%
(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%
(FPCore (x y z) :precision binary64 (if (<= y 2.5e-160) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.5e-160) {
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.5d-160) 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.5e-160) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.5e-160: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.5e-160) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2.5e-160) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.5e-160], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.5 \cdot 10^{-160}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 2.49999999999999997e-160Initial program 100.0%
Taylor expanded in z around 0 45.8%
+-commutative45.8%
Simplified45.8%
Taylor expanded in y around 0 27.3%
if 2.49999999999999997e-160 < y Initial program 100.0%
Taylor expanded in z around 0 40.8%
+-commutative40.8%
Simplified40.8%
Taylor expanded in y around inf 31.5%
(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 43.9%
+-commutative43.9%
Simplified43.9%
Taylor expanded in y around 0 21.2%
herbie shell --seed 2024157
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))