
(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 9 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 (fma (+ x y) (- z) (+ x y)))
double code(double x, double y, double z) {
return fma((x + y), -z, (x + y));
}
function code(x, y, z) return fma(Float64(x + y), Float64(-z), Float64(x + y)) end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * (-z) + N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + y, -z, x + y\right)
\end{array}
Initial program 100.0%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= (- 1.0 z) 0.9999) (- x (* x z)) (if (<= (- 1.0 z) 100000000.0) (+ x y) (- (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((1.0 - z) <= 0.9999) {
tmp = x - (x * z);
} else if ((1.0 - z) <= 100000000.0) {
tmp = x + 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 ((1.0d0 - z) <= 0.9999d0) then
tmp = x - (x * z)
else if ((1.0d0 - z) <= 100000000.0d0) then
tmp = x + y
else
tmp = -(y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((1.0 - z) <= 0.9999) {
tmp = x - (x * z);
} else if ((1.0 - z) <= 100000000.0) {
tmp = x + y;
} else {
tmp = -(y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (1.0 - z) <= 0.9999: tmp = x - (x * z) elif (1.0 - z) <= 100000000.0: tmp = x + y else: tmp = -(y * z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(1.0 - z) <= 0.9999) tmp = Float64(x - Float64(x * z)); elseif (Float64(1.0 - z) <= 100000000.0) tmp = Float64(x + y); else tmp = Float64(-Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((1.0 - z) <= 0.9999) tmp = x - (x * z); elseif ((1.0 - z) <= 100000000.0) tmp = x + y; else tmp = -(y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(1.0 - z), $MachinePrecision], 0.9999], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 - z), $MachinePrecision], 100000000.0], N[(x + y), $MachinePrecision], (-N[(y * z), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - z \leq 0.9999:\\
\;\;\;\;x - x \cdot z\\
\mathbf{elif}\;1 - z \leq 100000000:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;-y \cdot z\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) z) < 0.99990000000000001Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6453.8
Applied rewrites53.8%
if 0.99990000000000001 < (-.f64 #s(literal 1 binary64) z) < 1e8Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6498.6
Applied rewrites98.6%
if 1e8 < (-.f64 #s(literal 1 binary64) z) Initial program 99.9%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
lower-*.f6458.5
Applied rewrites58.5%
Taylor expanded in z around inf
Applied rewrites57.9%
Final simplification79.3%
(FPCore (x y z) :precision binary64 (if (<= (- 1.0 z) -2.0) (* x (- z)) (if (<= (- 1.0 z) 100000000.0) (+ x y) (- (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((1.0 - z) <= -2.0) {
tmp = x * -z;
} else if ((1.0 - z) <= 100000000.0) {
tmp = x + 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 ((1.0d0 - z) <= (-2.0d0)) then
tmp = x * -z
else if ((1.0d0 - z) <= 100000000.0d0) then
tmp = x + y
else
tmp = -(y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((1.0 - z) <= -2.0) {
tmp = x * -z;
} else if ((1.0 - z) <= 100000000.0) {
tmp = x + y;
} else {
tmp = -(y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (1.0 - z) <= -2.0: tmp = x * -z elif (1.0 - z) <= 100000000.0: tmp = x + y else: tmp = -(y * z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(1.0 - z) <= -2.0) tmp = Float64(x * Float64(-z)); elseif (Float64(1.0 - z) <= 100000000.0) tmp = Float64(x + y); else tmp = Float64(-Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((1.0 - z) <= -2.0) tmp = x * -z; elseif ((1.0 - z) <= 100000000.0) tmp = x + y; else tmp = -(y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(1.0 - z), $MachinePrecision], -2.0], N[(x * (-z)), $MachinePrecision], If[LessEqual[N[(1.0 - z), $MachinePrecision], 100000000.0], N[(x + y), $MachinePrecision], (-N[(y * z), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - z \leq -2:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{elif}\;1 - z \leq 100000000:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;-y \cdot z\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) z) < -2Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6451.4
Applied rewrites51.4%
Taylor expanded in z around inf
Applied rewrites49.1%
if -2 < (-.f64 #s(literal 1 binary64) z) < 1e8Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6497.2
Applied rewrites97.2%
if 1e8 < (-.f64 #s(literal 1 binary64) z) Initial program 99.9%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
lower-*.f6458.5
Applied rewrites58.5%
Taylor expanded in z around inf
Applied rewrites57.9%
Final simplification78.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- z)))) (if (<= (- 1.0 z) -2.0) t_0 (if (<= (- 1.0 z) 2.0) (+ x y) t_0))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if ((1.0 - z) <= -2.0) {
tmp = t_0;
} else if ((1.0 - z) <= 2.0) {
tmp = x + y;
} 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 = x * -z
if ((1.0d0 - z) <= (-2.0d0)) then
tmp = t_0
else if ((1.0d0 - z) <= 2.0d0) then
tmp = x + y
else
tmp = t_0
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) <= -2.0) {
tmp = t_0;
} else if ((1.0 - z) <= 2.0) {
tmp = x + y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if (1.0 - z) <= -2.0: tmp = t_0 elif (1.0 - z) <= 2.0: tmp = x + y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (Float64(1.0 - z) <= -2.0) tmp = t_0; elseif (Float64(1.0 - z) <= 2.0) tmp = Float64(x + y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if ((1.0 - z) <= -2.0) tmp = t_0; elseif ((1.0 - z) <= 2.0) tmp = x + y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[N[(1.0 - z), $MachinePrecision], -2.0], t$95$0, If[LessEqual[N[(1.0 - z), $MachinePrecision], 2.0], N[(x + y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;1 - z \leq -2:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;1 - z \leq 2:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) z) < -2 or 2 < (-.f64 #s(literal 1 binary64) z) Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6447.7
Applied rewrites47.7%
Taylor expanded in z around inf
Applied rewrites46.6%
if -2 < (-.f64 #s(literal 1 binary64) z) < 2Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6497.8
Applied rewrites97.8%
Final simplification75.2%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-252) (fma (- z) x x) (fma (- z) y y)))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-252) {
tmp = fma(-z, x, x);
} else {
tmp = fma(-z, y, y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-252) tmp = fma(Float64(-z), x, x); else tmp = fma(Float64(-z), y, y); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-252], N[((-z) * x + x), $MachinePrecision], N[((-z) * y + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-252}:\\
\;\;\;\;\mathsf{fma}\left(-z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, y\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -1.99999999999999989e-252Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6446.1
Applied rewrites46.1%
Applied rewrites46.1%
if -1.99999999999999989e-252 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
lower-*.f6453.8
Applied rewrites53.8%
Applied rewrites53.8%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-252) (fma (- z) x x) (- y (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-252) {
tmp = fma(-z, x, x);
} else {
tmp = y - (y * z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-252) tmp = fma(Float64(-z), x, x); else tmp = Float64(y - Float64(y * z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-252], N[((-z) * x + x), $MachinePrecision], N[(y - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-252}:\\
\;\;\;\;\mathsf{fma}\left(-z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot z\\
\end{array}
\end{array}
if (+.f64 x y) < -1.99999999999999989e-252Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6446.1
Applied rewrites46.1%
Applied rewrites46.1%
if -1.99999999999999989e-252 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
lower-*.f6453.8
Applied rewrites53.8%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-252) (- x (* x z)) (- y (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-252) {
tmp = x - (x * z);
} else {
tmp = y - (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 + y) <= (-2d-252)) then
tmp = x - (x * z)
else
tmp = y - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-252) {
tmp = x - (x * z);
} else {
tmp = y - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -2e-252: tmp = x - (x * z) else: tmp = y - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-252) tmp = Float64(x - Float64(x * z)); else tmp = Float64(y - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x + y) <= -2e-252) tmp = x - (x * z); else tmp = y - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-252], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(y - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-252}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot z\\
\end{array}
\end{array}
if (+.f64 x y) < -1.99999999999999989e-252Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6446.1
Applied rewrites46.1%
if -1.99999999999999989e-252 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
lower-*.f6453.8
Applied rewrites53.8%
Final simplification50.1%
(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 (+ 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
+-commutativeN/A
lower-+.f6456.1
Applied rewrites56.1%
Final simplification56.1%
herbie shell --seed 2024233
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))