
(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 7 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
(let* ((t_0 (* x (+ z 1.0))))
(if (<= z -1.7e+51)
(* y z)
(if (<= z -8.5e-11)
t_0
(if (<= z 3.8e-5) (+ x y) (if (<= z 1.8e+185) t_0 (* y z)))))))
double code(double x, double y, double z) {
double t_0 = x * (z + 1.0);
double tmp;
if (z <= -1.7e+51) {
tmp = y * z;
} else if (z <= -8.5e-11) {
tmp = t_0;
} else if (z <= 3.8e-5) {
tmp = x + y;
} else if (z <= 1.8e+185) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * (z + 1.0d0)
if (z <= (-1.7d+51)) then
tmp = y * z
else if (z <= (-8.5d-11)) then
tmp = t_0
else if (z <= 3.8d-5) then
tmp = x + y
else if (z <= 1.8d+185) then
tmp = t_0
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (z + 1.0);
double tmp;
if (z <= -1.7e+51) {
tmp = y * z;
} else if (z <= -8.5e-11) {
tmp = t_0;
} else if (z <= 3.8e-5) {
tmp = x + y;
} else if (z <= 1.8e+185) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + 1.0) tmp = 0 if z <= -1.7e+51: tmp = y * z elif z <= -8.5e-11: tmp = t_0 elif z <= 3.8e-5: tmp = x + y elif z <= 1.8e+185: tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z + 1.0)) tmp = 0.0 if (z <= -1.7e+51) tmp = Float64(y * z); elseif (z <= -8.5e-11) tmp = t_0; elseif (z <= 3.8e-5) tmp = Float64(x + y); elseif (z <= 1.8e+185) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z + 1.0); tmp = 0.0; if (z <= -1.7e+51) tmp = y * z; elseif (z <= -8.5e-11) tmp = t_0; elseif (z <= 3.8e-5) tmp = x + y; elseif (z <= 1.8e+185) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.7e+51], N[(y * z), $MachinePrecision], If[LessEqual[z, -8.5e-11], t$95$0, If[LessEqual[z, 3.8e-5], N[(x + y), $MachinePrecision], If[LessEqual[z, 1.8e+185], t$95$0, N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + 1\right)\\
\mathbf{if}\;z \leq -1.7 \cdot 10^{+51}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -8.5 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-5}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{+185}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.69999999999999992e51 or 1.80000000000000014e185 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
Simplified100.0%
distribute-lft-in94.9%
Applied egg-rr94.9%
Taylor expanded in y around inf 56.8%
*-commutative56.8%
Simplified56.8%
if -1.69999999999999992e51 < z < -8.50000000000000037e-11 or 3.8000000000000002e-5 < z < 1.80000000000000014e185Initial program 100.0%
Taylor expanded in x around inf 51.2%
if -8.50000000000000037e-11 < z < 3.8000000000000002e-5Initial program 100.0%
Taylor expanded in z around 0 100.0%
+-commutative100.0%
Simplified100.0%
Final simplification77.3%
(FPCore (x y z)
:precision binary64
(if (<= z -3.1e+52)
(* y z)
(if (<= z -1.0)
(* x z)
(if (<= z 600000000000.0) (+ x y) (if (<= z 2e+185) (* x z) (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.1e+52) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = x * z;
} else if (z <= 600000000000.0) {
tmp = x + y;
} else if (z <= 2e+185) {
tmp = x * z;
} 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 <= (-3.1d+52)) then
tmp = y * z
else if (z <= (-1.0d0)) then
tmp = x * z
else if (z <= 600000000000.0d0) then
tmp = x + y
else if (z <= 2d+185) then
tmp = x * z
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -3.1e+52) {
tmp = y * z;
} else if (z <= -1.0) {
tmp = x * z;
} else if (z <= 600000000000.0) {
tmp = x + y;
} else if (z <= 2e+185) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.1e+52: tmp = y * z elif z <= -1.0: tmp = x * z elif z <= 600000000000.0: tmp = x + y elif z <= 2e+185: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.1e+52) tmp = Float64(y * z); elseif (z <= -1.0) tmp = Float64(x * z); elseif (z <= 600000000000.0) tmp = Float64(x + y); elseif (z <= 2e+185) tmp = Float64(x * z); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.1e+52) tmp = y * z; elseif (z <= -1.0) tmp = x * z; elseif (z <= 600000000000.0) tmp = x + y; elseif (z <= 2e+185) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.1e+52], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, 600000000000.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 2e+185], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{+52}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 600000000000:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 2 \cdot 10^{+185}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -3.1e52 or 2e185 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
Simplified100.0%
distribute-lft-in94.9%
Applied egg-rr94.9%
Taylor expanded in y around inf 56.8%
*-commutative56.8%
Simplified56.8%
if -3.1e52 < z < -1 or 6e11 < z < 2e185Initial program 100.0%
Taylor expanded in z around inf 97.9%
+-commutative97.9%
Simplified97.9%
Taylor expanded in y around 0 52.1%
if -1 < z < 6e11Initial program 100.0%
Taylor expanded in z around 0 96.9%
+-commutative96.9%
Simplified96.9%
Final simplification77.0%
(FPCore (x y z) :precision binary64 (if (or (<= y 4.1e-170) (and (not (<= y 1.7e-100)) (<= y 2.5e-40))) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= 4.1e-170) || (!(y <= 1.7e-100) && (y <= 2.5e-40))) {
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 <= 4.1d-170) .or. (.not. (y <= 1.7d-100)) .and. (y <= 2.5d-40)) 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 <= 4.1e-170) || (!(y <= 1.7e-100) && (y <= 2.5e-40))) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= 4.1e-170) or (not (y <= 1.7e-100) and (y <= 2.5e-40)): tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= 4.1e-170) || (!(y <= 1.7e-100) && (y <= 2.5e-40))) 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 <= 4.1e-170) || (~((y <= 1.7e-100)) && (y <= 2.5e-40))) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, 4.1e-170], And[N[Not[LessEqual[y, 1.7e-100]], $MachinePrecision], LessEqual[y, 2.5e-40]]], 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.1 \cdot 10^{-170} \lor \neg \left(y \leq 1.7 \cdot 10^{-100}\right) \land y \leq 2.5 \cdot 10^{-40}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if y < 4.09999999999999966e-170 or 1.69999999999999988e-100 < y < 2.49999999999999982e-40Initial program 100.0%
Taylor expanded in x around inf 65.4%
if 4.09999999999999966e-170 < y < 1.69999999999999988e-100 or 2.49999999999999982e-40 < y Initial program 100.0%
Taylor expanded in x around 0 68.8%
Final simplification66.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 98.9%
+-commutative98.9%
Simplified98.9%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.2%
+-commutative98.2%
Simplified98.2%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (<= x -4.65e-138) (* x z) (* y z)))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.65e-138) {
tmp = x * z;
} 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 (x <= (-4.65d-138)) then
tmp = x * z
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.65e-138) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.65e-138: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.65e-138) tmp = Float64(x * z); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.65e-138) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.65e-138], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.65 \cdot 10^{-138}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -4.65000000000000026e-138Initial program 100.0%
Taylor expanded in z around inf 55.1%
+-commutative55.1%
Simplified55.1%
Taylor expanded in y around 0 38.6%
if -4.65000000000000026e-138 < x Initial program 100.0%
Taylor expanded in z around inf 45.5%
+-commutative45.5%
Simplified45.5%
distribute-lft-in44.1%
Applied egg-rr44.1%
Taylor expanded in y around inf 31.5%
*-commutative31.5%
Simplified31.5%
Final simplification34.6%
(FPCore (x y z) :precision binary64 (* x z))
double code(double x, double y, double z) {
return x * 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 * z
end function
public static double code(double x, double y, double z) {
return x * z;
}
def code(x, y, z): return x * z
function code(x, y, z) return Float64(x * z) end
function tmp = code(x, y, z) tmp = x * z; end
code[x_, y_, z_] := N[(x * z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in z around inf 49.6%
+-commutative49.6%
Simplified49.6%
Taylor expanded in y around 0 26.0%
Final simplification26.0%
herbie shell --seed 2024115
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))