(FPCore (x y z) :precision binary64 (acos (/ (- (+ (+ x y) z) 1.0) 2.0)))
double code(double x, double y, double z) { return acos(((((x + y) + z) - 1.0) / 2.0)); }
real(8) function code(x, y, z) real(8), intent (in) :: x real(8), intent (in) :: y real(8), intent (in) :: z code = acos(((((x + y) + z) - 1.0d0) / 2.0d0)) end function
public static double code(double x, double y, double z) { return Math.acos(((((x + y) + z) - 1.0) / 2.0)); }
def code(x, y, z): return math.acos(((((x + y) + z) - 1.0) / 2.0))
function code(x, y, z) return acos(Float64(Float64(Float64(Float64(x + y) + z) - 1.0) / 2.0)) end
function tmp = code(x, y, z) tmp = acos(((((x + y) + z) - 1.0) / 2.0)); end
code[x_, y_, z_] := N[ArcCos[N[(N[(N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision] - 1.0), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \cos^{-1} \left(\frac{\left(\left(x + y\right) + z\right) - 1}{2}\right) \end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x y z) :precision binary64 (acos (/ (- (+ (+ x y) z) 1.0) 2.0)))
double code(double x, double y, double z) { return acos(((((x + y) + z) - 1.0) / 2.0)); }
real(8) function code(x, y, z) real(8), intent (in) :: x real(8), intent (in) :: y real(8), intent (in) :: z code = acos(((((x + y) + z) - 1.0d0) / 2.0d0)) end function
public static double code(double x, double y, double z) { return Math.acos(((((x + y) + z) - 1.0) / 2.0)); }
def code(x, y, z): return math.acos(((((x + y) + z) - 1.0) / 2.0))
function code(x, y, z) return acos(Float64(Float64(Float64(Float64(x + y) + z) - 1.0) / 2.0)) end
function tmp = code(x, y, z) tmp = acos(((((x + y) + z) - 1.0) / 2.0)); end
code[x_, y_, z_] := N[ArcCos[N[(N[(N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision] - 1.0), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \cos^{-1} \left(\frac{\left(\left(x + y\right) + z\right) - 1}{2}\right) \end{array}
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ x (+ y z)))) (acos (/ (fma t_0 t_0 -1.0) (fma t_0 2.0 2.0)))))
double code(double x, double y, double z) { double t_0 = x + (y + z); return acos((fma(t_0, t_0, -1.0) / fma(t_0, 2.0, 2.0))); }
function code(x, y, z) t_0 = Float64(x + Float64(y + z)) return acos(Float64(fma(t_0, t_0, -1.0) / fma(t_0, 2.0, 2.0))) end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y + z), $MachinePrecision]), $MachinePrecision]}, N[ArcCos[N[(N[(t$95$0 * t$95$0 + -1.0), $MachinePrecision] / N[(t$95$0 * 2.0 + 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l} \\ \begin{array}{l} t_0 := x + \left(y + z\right)\\ \cos^{-1} \left(\frac{\mathsf{fma}\left(t_0, t_0, -1\right)}{\mathsf{fma}\left(t_0, 2, 2\right)}\right) \end{array} \end{array}
Initial program 100.0%
flip--
N/A
associate-/l/
N/A
/-lowering-/.f64
N/A
metadata-eval
N/A
sub-neg
N/A
accelerator-lowering-fma.f64
N/A
associate-+l+
N/A
+-lowering-+.f64
N/A
+-lowering-+.f64
N/A
associate-+l+
N/A
+-lowering-+.f64
N/A
+-lowering-+.f64
N/A
metadata-eval
N/A
distribute-rgt-in
N/A
metadata-eval
N/A
accelerator-lowering-fma.f64
N/A
associate-+l+
N/A
+-lowering-+.f64
N/A
+-lowering-+.f64
100.0
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (acos (/ (+ (+ z (+ x y)) -1.0) 2.0)))
double code(double x, double y, double z) { return acos((((z + (x + y)) + -1.0) / 2.0)); }
real(8) function code(x, y, z) real(8), intent (in) :: x real(8), intent (in) :: y real(8), intent (in) :: z code = acos((((z + (x + y)) + (-1.0d0)) / 2.0d0)) end function
public static double code(double x, double y, double z) { return Math.acos((((z + (x + y)) + -1.0) / 2.0)); }
def code(x, y, z): return math.acos((((z + (x + y)) + -1.0) / 2.0))
function code(x, y, z) return acos(Float64(Float64(Float64(z + Float64(x + y)) + -1.0) / 2.0)) end
function tmp = code(x, y, z) tmp = acos((((z + (x + y)) + -1.0) / 2.0)); end
code[x_, y_, z_] := N[ArcCos[N[(N[(N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \cos^{-1} \left(\frac{\left(z + \left(x + y\right)\right) + -1}{2}\right) \end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -4e-15) (acos (fma x 0.5 -0.5)) (acos (fma 0.5 (+ y z) -0.5))))
double code(double x, double y, double z) { double tmp; if ((x + y) <= -4e-15) { tmp = acos(fma(x, 0.5, -0.5)); } else { tmp = acos(fma(0.5, (y + z), -0.5)); } return tmp; }
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -4e-15) tmp = acos(fma(x, 0.5, -0.5)); else tmp = acos(fma(0.5, Float64(y + z), -0.5)); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -4e-15], N[ArcCos[N[(x * 0.5 + -0.5), $MachinePrecision]], $MachinePrecision], N[ArcCos[N[(0.5 * N[(y + z), $MachinePrecision] + -0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x + y \leq -4 \cdot 10^{-15}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(x, 0.5, -0.5\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(0.5, y + z, -0.5\right)\right)\\ \end{array} \end{array}
if (+.f64 x y) < -4.0000000000000003e-15
Initial program 99.7%
Taylor expanded in y around 0
sub-neg
N/A
metadata-eval
N/A
distribute-lft-in
N/A
metadata-eval
N/A
accelerator-lowering-fma.f64
N/A
+-commutative
N/A
+-lowering-+.f64
83.0
Simplified83.0%
Taylor expanded in z around 0
sub-neg
N/A
*-commutative
N/A
metadata-eval
N/A
accelerator-lowering-fma.f64
81.8
Simplified81.8%
if -4.0000000000000003e-15 < (+.f64 x y)
Initial program 100.0%
Taylor expanded in x around 0
sub-neg
N/A
metadata-eval
N/A
distribute-lft-in
N/A
metadata-eval
N/A
accelerator-lowering-fma.f64
N/A
+-lowering-+.f64
98.8
Simplified98.8%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -4e-15) (acos (fma x 0.5 -0.5)) (acos (fma z 0.5 -0.5))))
double code(double x, double y, double z) { double tmp; if ((x + y) <= -4e-15) { tmp = acos(fma(x, 0.5, -0.5)); } else { tmp = acos(fma(z, 0.5, -0.5)); } return tmp; }
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -4e-15) tmp = acos(fma(x, 0.5, -0.5)); else tmp = acos(fma(z, 0.5, -0.5)); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -4e-15], N[ArcCos[N[(x * 0.5 + -0.5), $MachinePrecision]], $MachinePrecision], N[ArcCos[N[(z * 0.5 + -0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x + y \leq -4 \cdot 10^{-15}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(x, 0.5, -0.5\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos^{-1} \left(\mathsf{fma}\left(z, 0.5, -0.5\right)\right)\\ \end{array} \end{array}
if (+.f64 x y) < -4.0000000000000003e-15
Initial program 99.7%
Taylor expanded in y around 0
sub-neg
N/A
metadata-eval
N/A
distribute-lft-in
N/A
metadata-eval
N/A
accelerator-lowering-fma.f64
N/A
+-commutative
N/A
+-lowering-+.f64
83.0
Simplified83.0%
Taylor expanded in z around 0
sub-neg
N/A
*-commutative
N/A
metadata-eval
N/A
accelerator-lowering-fma.f64
81.8
Simplified81.8%
if -4.0000000000000003e-15 < (+.f64 x y)
Initial program 100.0%
Taylor expanded in x around 0
sub-neg
N/A
metadata-eval
N/A
distribute-lft-in
N/A
metadata-eval
N/A
accelerator-lowering-fma.f64
N/A
+-lowering-+.f64
98.8
Simplified98.8%
Taylor expanded in y around 0
sub-neg
N/A
*-commutative
N/A
metadata-eval
N/A
accelerator-lowering-fma.f64
98.4
Simplified98.4%
(FPCore (x y z) :precision binary64 (acos (fma 0.5 (+ x z) -0.5)))
double code(double x, double y, double z) { return acos(fma(0.5, (x + z), -0.5)); }
function code(x, y, z) return acos(fma(0.5, Float64(x + z), -0.5)) end
code[x_, y_, z_] := N[ArcCos[N[(0.5 * N[(x + z), $MachinePrecision] + -0.5), $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \cos^{-1} \left(\mathsf{fma}\left(0.5, x + z, -0.5\right)\right) \end{array}
Initial program 100.0%
Taylor expanded in y around 0
sub-neg
N/A
metadata-eval
N/A
distribute-lft-in
N/A
metadata-eval
N/A
accelerator-lowering-fma.f64
N/A
+-commutative
N/A
+-lowering-+.f64
98.9
Simplified98.9%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (acos (fma x 0.5 -0.5)))
double code(double x, double y, double z) { return acos(fma(x, 0.5, -0.5)); }
function code(x, y, z) return acos(fma(x, 0.5, -0.5)) end
code[x_, y_, z_] := N[ArcCos[N[(x * 0.5 + -0.5), $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \cos^{-1} \left(\mathsf{fma}\left(x, 0.5, -0.5\right)\right) \end{array}
Initial program 100.0%
Taylor expanded in y around 0
sub-neg
N/A
metadata-eval
N/A
distribute-lft-in
N/A
metadata-eval
N/A
accelerator-lowering-fma.f64
N/A
+-commutative
N/A
+-lowering-+.f64
98.9
Simplified98.9%
Taylor expanded in z around 0
sub-neg
N/A
*-commutative
N/A
metadata-eval
N/A
accelerator-lowering-fma.f64
97.4
Simplified97.4%
(FPCore (x y z) :precision binary64 (acos (* x 0.5)))
double code(double x, double y, double z) { return acos((x * 0.5)); }
real(8) function code(x, y, z) real(8), intent (in) :: x real(8), intent (in) :: y real(8), intent (in) :: z code = acos((x * 0.5d0)) end function
public static double code(double x, double y, double z) { return Math.acos((x * 0.5)); }
def code(x, y, z): return math.acos((x * 0.5))
function code(x, y, z) return acos(Float64(x * 0.5)) end
function tmp = code(x, y, z) tmp = acos((x * 0.5)); end
code[x_, y_, z_] := N[ArcCos[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]
\begin{array}{l} \\ \cos^{-1} \left(x \cdot 0.5\right) \end{array}
Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64
20.4
Simplified20.4%
Final simplification20.4%
herbie shell --seed 5
(FPCore (x y z)
:name "acos(((x + y + z) - 1)/2)"
:precision binary64
:pre (and (and (and (<= -1.0 x) (<= x 1.0)) (and (<= -1.0 y) (<= y 1.0))) (and (<= -1.0 z) (<= z 1.0)))
(acos (/ (- (+ (+ x y) z) 1.0) 2.0)))