
(FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
double code(double x, double y, double z) {
return (x + y) * (1.0 - 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) * (1.0d0 - z)
end function
public static double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
def code(x, y, z): return (x + y) * (1.0 - z)
function code(x, y, z) return Float64(Float64(x + y) * Float64(1.0 - z)) end
function tmp = code(x, y, z) tmp = (x + y) * (1.0 - z); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(1 - z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
double code(double x, double y, double z) {
return (x + y) * (1.0 - 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) * (1.0d0 - z)
end function
public static double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
def code(x, y, z): return (x + y) * (1.0 - z)
function code(x, y, z) return Float64(Float64(x + y) * Float64(1.0 - z)) end
function tmp = code(x, y, z) tmp = (x + y) * (1.0 - z); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(1 - z\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%
sub-neg100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= (- 1.0 z) -9e+256)
t_0
(if (<= (- 1.0 z) -10000000.0)
(* y (- 1.0 z))
(if (<= (- 1.0 z) 2.0)
(+ x y)
(if (<= (- 1.0 z) 2e+93) t_0 (* y (- z))))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if ((1.0 - z) <= -9e+256) {
tmp = t_0;
} else if ((1.0 - z) <= -10000000.0) {
tmp = y * (1.0 - z);
} else if ((1.0 - z) <= 2.0) {
tmp = x + y;
} else if ((1.0 - z) <= 2e+93) {
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
if ((1.0d0 - z) <= (-9d+256)) then
tmp = t_0
else if ((1.0d0 - z) <= (-10000000.0d0)) then
tmp = y * (1.0d0 - z)
else if ((1.0d0 - z) <= 2.0d0) then
tmp = x + y
else if ((1.0d0 - z) <= 2d+93) 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;
double tmp;
if ((1.0 - z) <= -9e+256) {
tmp = t_0;
} else if ((1.0 - z) <= -10000000.0) {
tmp = y * (1.0 - z);
} else if ((1.0 - z) <= 2.0) {
tmp = x + y;
} else if ((1.0 - z) <= 2e+93) {
tmp = t_0;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if (1.0 - z) <= -9e+256: tmp = t_0 elif (1.0 - z) <= -10000000.0: tmp = y * (1.0 - z) elif (1.0 - z) <= 2.0: tmp = x + y elif (1.0 - z) <= 2e+93: tmp = t_0 else: tmp = y * -z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (Float64(1.0 - z) <= -9e+256) tmp = t_0; elseif (Float64(1.0 - z) <= -10000000.0) tmp = Float64(y * Float64(1.0 - z)); elseif (Float64(1.0 - z) <= 2.0) tmp = Float64(x + y); elseif (Float64(1.0 - z) <= 2e+93) tmp = t_0; else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if ((1.0 - z) <= -9e+256) tmp = t_0; elseif ((1.0 - z) <= -10000000.0) tmp = y * (1.0 - z); elseif ((1.0 - z) <= 2.0) tmp = x + y; elseif ((1.0 - z) <= 2e+93) tmp = t_0; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[N[(1.0 - z), $MachinePrecision], -9e+256], t$95$0, If[LessEqual[N[(1.0 - z), $MachinePrecision], -10000000.0], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 - z), $MachinePrecision], 2.0], N[(x + y), $MachinePrecision], If[LessEqual[N[(1.0 - z), $MachinePrecision], 2e+93], t$95$0, N[(y * (-z)), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;1 - z \leq -9 \cdot 10^{+256}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;1 - z \leq -10000000:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\mathbf{elif}\;1 - z \leq 2:\\
\;\;\;\;x + y\\
\mathbf{elif}\;1 - z \leq 2 \cdot 10^{+93}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) z) < -8.9999999999999996e256 or 2 < (-.f64 #s(literal 1 binary64) z) < 2.00000000000000009e93Initial program 100.0%
Taylor expanded in x around inf 45.2%
*-commutative45.2%
Simplified45.2%
Taylor expanded in z around inf 43.3%
neg-mul-143.3%
Simplified43.3%
if -8.9999999999999996e256 < (-.f64 #s(literal 1 binary64) z) < -1e7Initial program 100.0%
Taylor expanded in x around 0 56.2%
if -1e7 < (-.f64 #s(literal 1 binary64) z) < 2Initial program 99.9%
Taylor expanded in z around 0 97.0%
+-commutative97.0%
Simplified97.0%
if 2.00000000000000009e93 < (-.f64 #s(literal 1 binary64) z) Initial program 100.0%
Taylor expanded in z around inf 100.0%
neg-mul-166.5%
Simplified100.0%
Taylor expanded in x around 0 50.9%
associate-*r*50.9%
mul-1-neg50.9%
Simplified50.9%
Final simplification72.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- z))) (t_1 (* x (- z))))
(if (<= z -1.15e+94)
t_0
(if (<= z -300.0)
t_1
(if (<= z 1.0) (+ x y) (if (<= z 5e+256) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = y * -z;
double t_1 = x * -z;
double tmp;
if (z <= -1.15e+94) {
tmp = t_0;
} else if (z <= -300.0) {
tmp = t_1;
} else if (z <= 1.0) {
tmp = x + y;
} else if (z <= 5e+256) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = y * -z
t_1 = x * -z
if (z <= (-1.15d+94)) then
tmp = t_0
else if (z <= (-300.0d0)) then
tmp = t_1
else if (z <= 1.0d0) then
tmp = x + y
else if (z <= 5d+256) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * -z;
double t_1 = x * -z;
double tmp;
if (z <= -1.15e+94) {
tmp = t_0;
} else if (z <= -300.0) {
tmp = t_1;
} else if (z <= 1.0) {
tmp = x + y;
} else if (z <= 5e+256) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = y * -z t_1 = x * -z tmp = 0 if z <= -1.15e+94: tmp = t_0 elif z <= -300.0: tmp = t_1 elif z <= 1.0: tmp = x + y elif z <= 5e+256: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-z)) t_1 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -1.15e+94) tmp = t_0; elseif (z <= -300.0) tmp = t_1; elseif (z <= 1.0) tmp = Float64(x + y); elseif (z <= 5e+256) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -z; t_1 = x * -z; tmp = 0.0; if (z <= -1.15e+94) tmp = t_0; elseif (z <= -300.0) tmp = t_1; elseif (z <= 1.0) tmp = x + y; elseif (z <= 5e+256) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-z)), $MachinePrecision]}, Block[{t$95$1 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -1.15e+94], t$95$0, If[LessEqual[z, -300.0], t$95$1, If[LessEqual[z, 1.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 5e+256], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-z\right)\\
t_1 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -1.15 \cdot 10^{+94}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -300:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 5 \cdot 10^{+256}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1.15e94 or 1 < z < 5.00000000000000015e256Initial program 100.0%
Taylor expanded in z around inf 99.2%
neg-mul-157.6%
Simplified99.2%
Taylor expanded in x around 0 52.5%
associate-*r*52.5%
mul-1-neg52.5%
Simplified52.5%
if -1.15e94 < z < -300 or 5.00000000000000015e256 < z Initial program 100.0%
Taylor expanded in x around inf 46.9%
*-commutative46.9%
Simplified46.9%
Taylor expanded in z around inf 45.0%
neg-mul-145.0%
Simplified45.0%
if -300 < z < 1Initial program 99.9%
Taylor expanded in z around 0 97.0%
+-commutative97.0%
Simplified97.0%
Final simplification72.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -3600000000.0) (not (<= z 1.0))) (* y (- z)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3600000000.0) || !(z <= 1.0)) {
tmp = y * -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 <= (-3600000000.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = y * -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 <= -3600000000.0) || !(z <= 1.0)) {
tmp = y * -z;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3600000000.0) or not (z <= 1.0): tmp = y * -z else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3600000000.0) || !(z <= 1.0)) tmp = Float64(y * Float64(-z)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3600000000.0) || ~((z <= 1.0))) tmp = y * -z; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3600000000.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(y * (-z)), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3600000000 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -3.6e9 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 99.0%
neg-mul-154.9%
Simplified99.0%
Taylor expanded in x around 0 53.9%
associate-*r*53.9%
mul-1-neg53.9%
Simplified53.9%
if -3.6e9 < z < 1Initial program 99.9%
Taylor expanded in z around 0 95.6%
+-commutative95.6%
Simplified95.6%
Final simplification73.7%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -1e-287) (- x (* x z)) (* y (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -1e-287) {
tmp = x - (x * z);
} else {
tmp = y * (1.0 - 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 + y) <= (-1d-287)) then
tmp = x - (x * z)
else
tmp = y * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -1e-287) {
tmp = x - (x * z);
} else {
tmp = y * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -1e-287: tmp = x - (x * z) else: tmp = y * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -1e-287) tmp = Float64(x - Float64(x * z)); else tmp = Float64(y * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x + y) <= -1e-287) tmp = x - (x * z); else tmp = y * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -1e-287], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -1 \cdot 10^{-287}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -1.00000000000000002e-287Initial program 99.9%
sub-neg99.9%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 52.5%
mul-1-neg52.5%
*-commutative52.5%
unsub-neg52.5%
Applied egg-rr52.5%
if -1.00000000000000002e-287 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0 51.7%
Final simplification52.1%
(FPCore (x y z) :precision binary64 (if (<= y 2.2e-19) (* x (- 1.0 z)) (* y (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.2e-19) {
tmp = x * (1.0 - z);
} else {
tmp = y * (1.0 - 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 (y <= 2.2d-19) then
tmp = x * (1.0d0 - z)
else
tmp = y * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 2.2e-19) {
tmp = x * (1.0 - z);
} else {
tmp = y * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.2e-19: tmp = x * (1.0 - z) else: tmp = y * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.2e-19) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(y * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2.2e-19) tmp = x * (1.0 - z); else tmp = y * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.2e-19], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.2 \cdot 10^{-19}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < 2.1999999999999998e-19Initial program 99.9%
Taylor expanded in x around inf 61.9%
*-commutative61.9%
Simplified61.9%
if 2.1999999999999998e-19 < y Initial program 100.0%
Taylor expanded in x around 0 82.1%
Final simplification67.5%
(FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
double code(double x, double y, double z) {
return (x + y) * (1.0 - 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) * (1.0d0 - z)
end function
public static double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
def code(x, y, z): return (x + y) * (1.0 - z)
function code(x, y, z) return Float64(Float64(x + y) * Float64(1.0 - z)) end
function tmp = code(x, y, z) tmp = (x + y) * (1.0 - z); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(1 - z\right)
\end{array}
Initial program 100.0%
(FPCore (x y z) :precision binary64 (if (<= y 3.4e-19) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 3.4e-19) {
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 <= 3.4d-19) 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 <= 3.4e-19) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 3.4e-19: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 3.4e-19) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 3.4e-19) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 3.4e-19], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.4 \cdot 10^{-19}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 3.4000000000000002e-19Initial program 99.9%
Taylor expanded in z around 0 47.6%
+-commutative47.6%
Simplified47.6%
Taylor expanded in y around 0 28.5%
if 3.4000000000000002e-19 < y Initial program 100.0%
Taylor expanded in z around 0 47.2%
+-commutative47.2%
Simplified47.2%
Taylor expanded in y around inf 35.8%
(FPCore (x y z) :precision binary64 (+ x y))
double code(double x, double y, double z) {
return 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
end function
public static double code(double x, double y, double z) {
return x + y;
}
def code(x, y, z): return x + y
function code(x, y, z) return Float64(x + y) end
function tmp = code(x, y, z) tmp = x + y; end
code[x_, y_, z_] := N[(x + y), $MachinePrecision]
\begin{array}{l}
\\
x + y
\end{array}
Initial program 100.0%
Taylor expanded in z around 0 47.5%
+-commutative47.5%
Simplified47.5%
Final simplification47.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 47.5%
+-commutative47.5%
Simplified47.5%
Taylor expanded in y around 0 24.3%
herbie shell --seed 2024137
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))