
(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 (* (- 1.0 z) (+ x y)))
double code(double x, double y, double z) {
return (1.0 - z) * (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 = (1.0d0 - z) * (x + y)
end function
public static double code(double x, double y, double z) {
return (1.0 - z) * (x + y);
}
def code(x, y, z): return (1.0 - z) * (x + y)
function code(x, y, z) return Float64(Float64(1.0 - z) * Float64(x + y)) end
function tmp = code(x, y, z) tmp = (1.0 - z) * (x + y); end
code[x_, y_, z_] := N[(N[(1.0 - z), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - z\right) \cdot \left(x + y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (* y z))) (t_1 (- (* x z))))
(if (<= z -2.45e+156)
t_0
(if (<= z -1.4e+80)
t_1
(if (<= z -65.0)
t_0
(if (<= z 1.0) (+ x y) (if (<= z 4.9e+261) 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 <= -2.45e+156) {
tmp = t_0;
} else if (z <= -1.4e+80) {
tmp = t_1;
} else if (z <= -65.0) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = x + y;
} else if (z <= 4.9e+261) {
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 <= (-2.45d+156)) then
tmp = t_0
else if (z <= (-1.4d+80)) then
tmp = t_1
else if (z <= (-65.0d0)) then
tmp = t_0
else if (z <= 1.0d0) then
tmp = x + y
else if (z <= 4.9d+261) 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 <= -2.45e+156) {
tmp = t_0;
} else if (z <= -1.4e+80) {
tmp = t_1;
} else if (z <= -65.0) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = x + y;
} else if (z <= 4.9e+261) {
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 <= -2.45e+156: tmp = t_0 elif z <= -1.4e+80: tmp = t_1 elif z <= -65.0: tmp = t_0 elif z <= 1.0: tmp = x + y elif z <= 4.9e+261: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(-Float64(y * z)) t_1 = Float64(-Float64(x * z)) tmp = 0.0 if (z <= -2.45e+156) tmp = t_0; elseif (z <= -1.4e+80) tmp = t_1; elseif (z <= -65.0) tmp = t_0; elseif (z <= 1.0) tmp = Float64(x + y); elseif (z <= 4.9e+261) 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 <= -2.45e+156) tmp = t_0; elseif (z <= -1.4e+80) tmp = t_1; elseif (z <= -65.0) tmp = t_0; elseif (z <= 1.0) tmp = x + y; elseif (z <= 4.9e+261) 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, -2.45e+156], t$95$0, If[LessEqual[z, -1.4e+80], t$95$1, If[LessEqual[z, -65.0], t$95$0, If[LessEqual[z, 1.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 4.9e+261], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -y \cdot z\\
t_1 := -x \cdot z\\
\mathbf{if}\;z \leq -2.45 \cdot 10^{+156}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.4 \cdot 10^{+80}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq -65:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 4.9 \cdot 10^{+261}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -2.44999999999999984e156 or -1.39999999999999992e80 < z < -65 or 1 < z < 4.9e261Initial program 100.0%
Taylor expanded in x around 0
Simplified53.7%
Taylor expanded in z around inf
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6453.7
Simplified53.7%
if -2.44999999999999984e156 < z < -1.39999999999999992e80 or 4.9e261 < z Initial program 100.0%
Taylor expanded in z around inf
mul-1-negN/A
neg-lowering-neg.f64100.0
Simplified100.0%
Taylor expanded in x around inf
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6465.2
Simplified65.2%
if -65 < z < 1Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6499.4
Simplified99.4%
Final simplification77.3%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-5) (- (* x z)) (if (<= (+ x y) -2e-228) (+ x y) (* y (- 1.0 z)))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-5) {
tmp = -(x * z);
} else if ((x + y) <= -2e-228) {
tmp = x + y;
} 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) <= (-2d-5)) then
tmp = -(x * z)
else if ((x + y) <= (-2d-228)) then
tmp = x + y
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) <= -2e-5) {
tmp = -(x * z);
} else if ((x + y) <= -2e-228) {
tmp = x + y;
} else {
tmp = y * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -2e-5: tmp = -(x * z) elif (x + y) <= -2e-228: tmp = x + y else: tmp = y * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-5) tmp = Float64(-Float64(x * z)); elseif (Float64(x + y) <= -2e-228) tmp = Float64(x + y); 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) <= -2e-5) tmp = -(x * z); elseif ((x + y) <= -2e-228) tmp = x + y; else tmp = y * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-5], (-N[(x * z), $MachinePrecision]), If[LessEqual[N[(x + y), $MachinePrecision], -2e-228], N[(x + y), $MachinePrecision], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-5}:\\
\;\;\;\;-x \cdot z\\
\mathbf{elif}\;x + y \leq -2 \cdot 10^{-228}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -2.00000000000000016e-5Initial program 100.0%
Taylor expanded in z around inf
mul-1-negN/A
neg-lowering-neg.f6454.9
Simplified54.9%
Taylor expanded in x around inf
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6430.6
Simplified30.6%
if -2.00000000000000016e-5 < (+.f64 x y) < -2.00000000000000007e-228Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6476.5
Simplified76.5%
if -2.00000000000000007e-228 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
Simplified52.5%
Final simplification47.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* x z)))) (if (<= (- 1.0 z) -0.5) t_0 (if (<= (- 1.0 z) 3e+19) (+ x y) t_0))))
double code(double x, double y, double z) {
double t_0 = -(x * z);
double tmp;
if ((1.0 - z) <= -0.5) {
tmp = t_0;
} else if ((1.0 - z) <= 3e+19) {
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) <= (-0.5d0)) then
tmp = t_0
else if ((1.0d0 - z) <= 3d+19) 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) <= -0.5) {
tmp = t_0;
} else if ((1.0 - z) <= 3e+19) {
tmp = x + y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -(x * z) tmp = 0 if (1.0 - z) <= -0.5: tmp = t_0 elif (1.0 - z) <= 3e+19: tmp = x + y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(-Float64(x * z)) tmp = 0.0 if (Float64(1.0 - z) <= -0.5) tmp = t_0; elseif (Float64(1.0 - z) <= 3e+19) 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) <= -0.5) tmp = t_0; elseif ((1.0 - z) <= 3e+19) 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], -0.5], t$95$0, If[LessEqual[N[(1.0 - z), $MachinePrecision], 3e+19], N[(x + y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -x \cdot z\\
\mathbf{if}\;1 - z \leq -0.5:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;1 - z \leq 3 \cdot 10^{+19}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) z) < -0.5 or 3e19 < (-.f64 #s(literal 1 binary64) z) Initial program 100.0%
Taylor expanded in z around inf
mul-1-negN/A
neg-lowering-neg.f6498.5
Simplified98.5%
Taylor expanded in x around inf
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6453.3
Simplified53.3%
if -0.5 < (-.f64 #s(literal 1 binary64) z) < 3e19Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6498.7
Simplified98.7%
Final simplification75.8%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-228) (- x (* x z)) (* y (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-228) {
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) <= (-2d-228)) 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) <= -2e-228) {
tmp = x - (x * z);
} else {
tmp = y * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -2e-228: tmp = x - (x * z) else: tmp = y * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-228) 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) <= -2e-228) 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], -2e-228], 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 -2 \cdot 10^{-228}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -2.00000000000000007e-228Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f6445.2
Simplified45.2%
if -2.00000000000000007e-228 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
Simplified52.5%
Final simplification49.0%
(FPCore (x y z) :precision binary64 (if (<= (* (- 1.0 z) (+ x y)) -2e-228) x y))
double code(double x, double y, double z) {
double tmp;
if (((1.0 - z) * (x + y)) <= -2e-228) {
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 (((1.0d0 - z) * (x + y)) <= (-2d-228)) 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 (((1.0 - z) * (x + y)) <= -2e-228) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((1.0 - z) * (x + y)) <= -2e-228: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (Float64(Float64(1.0 - z) * Float64(x + y)) <= -2e-228) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((1.0 - z) * (x + y)) <= -2e-228) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(N[(1.0 - z), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision], -2e-228], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - z\right) \cdot \left(x + y\right) \leq -2 \cdot 10^{-228}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) < -2.00000000000000007e-228Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6451.6
Simplified51.6%
Taylor expanded in y around 0
Simplified20.0%
if -2.00000000000000007e-228 < (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) Initial program 100.0%
Taylor expanded in x around 0
Simplified53.3%
Taylor expanded in z around 0
Simplified28.1%
Final simplification24.0%
(FPCore (x y z) :precision binary64 (if (<= z 1.8) (+ x y) (* y z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.8) {
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 (z <= 1.8d0) 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 (z <= 1.8) {
tmp = x + y;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.8: tmp = x + y else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.8) tmp = Float64(x + y); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.8) tmp = x + y; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.8], N[(x + y), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.8:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < 1.80000000000000004Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6465.2
Simplified65.2%
if 1.80000000000000004 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified57.1%
sub-negN/A
+-commutativeN/A
distribute-rgt-inN/A
neg-sub0N/A
flip3--N/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
metadata-evalN/A
neg-sub0N/A
cube-negN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow1N/A
*-lft-identityN/A
Applied egg-rr5.2%
Taylor expanded in z around inf
*-lowering-*.f645.2
Simplified5.2%
Final simplification51.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
+-commutativeN/A
+-lowering-+.f6450.8
Simplified50.8%
Final simplification50.8%
(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
+-commutativeN/A
+-lowering-+.f6450.8
Simplified50.8%
Taylor expanded in y around 0
Simplified21.5%
herbie shell --seed 2024198
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))