
(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 7 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) (- 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
(let* ((t_0 (- (* y z))))
(if (<= z -3.6e+68)
(* x (- z))
(if (<= z -100000000.0)
t_0
(if (<= z 4.6e-9) (+ x y) (if (<= z 1.65e+28) (- x (* x z)) t_0))))))
double code(double x, double y, double z) {
double t_0 = -(y * z);
double tmp;
if (z <= -3.6e+68) {
tmp = x * -z;
} else if (z <= -100000000.0) {
tmp = t_0;
} else if (z <= 4.6e-9) {
tmp = x + y;
} else if (z <= 1.65e+28) {
tmp = x - (x * z);
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = -(y * z)
if (z <= (-3.6d+68)) then
tmp = x * -z
else if (z <= (-100000000.0d0)) then
tmp = t_0
else if (z <= 4.6d-9) then
tmp = x + y
else if (z <= 1.65d+28) then
tmp = x - (x * z)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -(y * z);
double tmp;
if (z <= -3.6e+68) {
tmp = x * -z;
} else if (z <= -100000000.0) {
tmp = t_0;
} else if (z <= 4.6e-9) {
tmp = x + y;
} else if (z <= 1.65e+28) {
tmp = x - (x * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -(y * z) tmp = 0 if z <= -3.6e+68: tmp = x * -z elif z <= -100000000.0: tmp = t_0 elif z <= 4.6e-9: tmp = x + y elif z <= 1.65e+28: tmp = x - (x * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(-Float64(y * z)) tmp = 0.0 if (z <= -3.6e+68) tmp = Float64(x * Float64(-z)); elseif (z <= -100000000.0) tmp = t_0; elseif (z <= 4.6e-9) tmp = Float64(x + y); elseif (z <= 1.65e+28) tmp = Float64(x - Float64(x * z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -(y * z); tmp = 0.0; if (z <= -3.6e+68) tmp = x * -z; elseif (z <= -100000000.0) tmp = t_0; elseif (z <= 4.6e-9) tmp = x + y; elseif (z <= 1.65e+28) tmp = x - (x * z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(y * z), $MachinePrecision])}, If[LessEqual[z, -3.6e+68], N[(x * (-z)), $MachinePrecision], If[LessEqual[z, -100000000.0], t$95$0, If[LessEqual[z, 4.6e-9], N[(x + y), $MachinePrecision], If[LessEqual[z, 1.65e+28], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -y \cdot z\\
\mathbf{if}\;z \leq -3.6 \cdot 10^{+68}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{elif}\;z \leq -100000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4.6 \cdot 10^{-9}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 1.65 \cdot 10^{+28}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.5999999999999999e68Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6452.2
Applied rewrites52.2%
Taylor expanded in z around inf
Applied rewrites52.2%
if -3.5999999999999999e68 < z < -1e8 or 1.65e28 < z Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
lower-*.f6452.9
Applied rewrites52.9%
Taylor expanded in z around inf
Applied rewrites52.7%
if -1e8 < z < 4.5999999999999998e-9Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6497.6
Applied rewrites97.6%
if 4.5999999999999998e-9 < z < 1.65e28Initial program 99.9%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6450.8
Applied rewrites50.8%
Final simplification74.5%
herbie shell --seed 2024228
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))