(acos (+ (* (sin z0) (sin z1)) (* (* (cos (- z3 z2)) (cos z1)) (cos z0))))

Percentage Accurate: 73.9% → 93.7%
Time: 9.9s
Alternatives: 6
Speedup: 1.0×

Specification

?
\[\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
(FPCore (z0 z1 z3 z2)
  :precision binary64
  (acos
 (+ (* (sin z0) (sin z1)) (* (* (cos (- z3 z2)) (cos z1)) (cos z0)))))
double code(double z0, double z1, double z3, double z2) {
	return acos(((sin(z0) * sin(z1)) + ((cos((z3 - z2)) * cos(z1)) * cos(z0))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(z0, z1, z3, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z3
    real(8), intent (in) :: z2
    code = acos(((sin(z0) * sin(z1)) + ((cos((z3 - z2)) * cos(z1)) * cos(z0))))
end function
public static double code(double z0, double z1, double z3, double z2) {
	return Math.acos(((Math.sin(z0) * Math.sin(z1)) + ((Math.cos((z3 - z2)) * Math.cos(z1)) * Math.cos(z0))));
}
def code(z0, z1, z3, z2):
	return math.acos(((math.sin(z0) * math.sin(z1)) + ((math.cos((z3 - z2)) * math.cos(z1)) * math.cos(z0))))
function code(z0, z1, z3, z2)
	return acos(Float64(Float64(sin(z0) * sin(z1)) + Float64(Float64(cos(Float64(z3 - z2)) * cos(z1)) * cos(z0))))
end
function tmp = code(z0, z1, z3, z2)
	tmp = acos(((sin(z0) * sin(z1)) + ((cos((z3 - z2)) * cos(z1)) * cos(z0))));
end
code[z0_, z1_, z3_, z2_] := N[ArcCos[N[(N[(N[Sin[z0], $MachinePrecision] * N[Sin[z1], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[N[(z3 - z2), $MachinePrecision]], $MachinePrecision] * N[Cos[z1], $MachinePrecision]), $MachinePrecision] * N[Cos[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right)

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 73.9% accurate, 1.0× speedup?

\[\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
(FPCore (z0 z1 z3 z2)
  :precision binary64
  (acos
 (+ (* (sin z0) (sin z1)) (* (* (cos (- z3 z2)) (cos z1)) (cos z0)))))
double code(double z0, double z1, double z3, double z2) {
	return acos(((sin(z0) * sin(z1)) + ((cos((z3 - z2)) * cos(z1)) * cos(z0))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(z0, z1, z3, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z3
    real(8), intent (in) :: z2
    code = acos(((sin(z0) * sin(z1)) + ((cos((z3 - z2)) * cos(z1)) * cos(z0))))
end function
public static double code(double z0, double z1, double z3, double z2) {
	return Math.acos(((Math.sin(z0) * Math.sin(z1)) + ((Math.cos((z3 - z2)) * Math.cos(z1)) * Math.cos(z0))));
}
def code(z0, z1, z3, z2):
	return math.acos(((math.sin(z0) * math.sin(z1)) + ((math.cos((z3 - z2)) * math.cos(z1)) * math.cos(z0))))
function code(z0, z1, z3, z2)
	return acos(Float64(Float64(sin(z0) * sin(z1)) + Float64(Float64(cos(Float64(z3 - z2)) * cos(z1)) * cos(z0))))
end
function tmp = code(z0, z1, z3, z2)
	tmp = acos(((sin(z0) * sin(z1)) + ((cos((z3 - z2)) * cos(z1)) * cos(z0))));
end
code[z0_, z1_, z3_, z2_] := N[ArcCos[N[(N[(N[Sin[z0], $MachinePrecision] * N[Sin[z1], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[N[(z3 - z2), $MachinePrecision]], $MachinePrecision] * N[Cos[z1], $MachinePrecision]), $MachinePrecision] * N[Cos[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right)

Alternative 1: 93.7% accurate, 0.5× speedup?

\[\begin{array}{l} t_0 := \cos z2 \cdot \cos z3\\ \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{t\_0}\right) \cdot t\_0\right) \cdot \cos z1\right) \cdot \cos z0\right) \end{array} \]
(FPCore (z0 z1 z3 z2)
  :precision binary64
  (let* ((t_0 (* (cos z2) (cos z3))))
  (acos
   (+
    (* (sin z0) (sin z1))
    (*
     (* (* (+ 1 (/ (* (sin z2) (sin z3)) t_0)) t_0) (cos z1))
     (cos z0))))))
double code(double z0, double z1, double z3, double z2) {
	double t_0 = cos(z2) * cos(z3);
	return acos(((sin(z0) * sin(z1)) + ((((1.0 + ((sin(z2) * sin(z3)) / t_0)) * t_0) * cos(z1)) * cos(z0))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(z0, z1, z3, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z3
    real(8), intent (in) :: z2
    real(8) :: t_0
    t_0 = cos(z2) * cos(z3)
    code = acos(((sin(z0) * sin(z1)) + ((((1.0d0 + ((sin(z2) * sin(z3)) / t_0)) * t_0) * cos(z1)) * cos(z0))))
end function
public static double code(double z0, double z1, double z3, double z2) {
	double t_0 = Math.cos(z2) * Math.cos(z3);
	return Math.acos(((Math.sin(z0) * Math.sin(z1)) + ((((1.0 + ((Math.sin(z2) * Math.sin(z3)) / t_0)) * t_0) * Math.cos(z1)) * Math.cos(z0))));
}
def code(z0, z1, z3, z2):
	t_0 = math.cos(z2) * math.cos(z3)
	return math.acos(((math.sin(z0) * math.sin(z1)) + ((((1.0 + ((math.sin(z2) * math.sin(z3)) / t_0)) * t_0) * math.cos(z1)) * math.cos(z0))))
function code(z0, z1, z3, z2)
	t_0 = Float64(cos(z2) * cos(z3))
	return acos(Float64(Float64(sin(z0) * sin(z1)) + Float64(Float64(Float64(Float64(1.0 + Float64(Float64(sin(z2) * sin(z3)) / t_0)) * t_0) * cos(z1)) * cos(z0))))
end
function tmp = code(z0, z1, z3, z2)
	t_0 = cos(z2) * cos(z3);
	tmp = acos(((sin(z0) * sin(z1)) + ((((1.0 + ((sin(z2) * sin(z3)) / t_0)) * t_0) * cos(z1)) * cos(z0))));
end
code[z0_, z1_, z3_, z2_] := Block[{t$95$0 = N[(N[Cos[z2], $MachinePrecision] * N[Cos[z3], $MachinePrecision]), $MachinePrecision]}, N[ArcCos[N[(N[(N[Sin[z0], $MachinePrecision] * N[Sin[z1], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(1 + N[(N[(N[Sin[z2], $MachinePrecision] * N[Sin[z3], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Cos[z1], $MachinePrecision]), $MachinePrecision] * N[Cos[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
t_0 := \cos z2 \cdot \cos z3\\
\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{t\_0}\right) \cdot t\_0\right) \cdot \cos z1\right) \cdot \cos z0\right)
\end{array}
Derivation
  1. Initial program 73.9%

    \[\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
  2. Step-by-step derivation
    1. lift-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\cos \left(z3 - z2\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    2. lift--.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \color{blue}{\left(z3 - z2\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    3. cos-diffN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\left(\cos z3 \cdot \cos z2 + \sin z3 \cdot \sin z2\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    4. sum-to-multN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\left(\left(1 + \frac{\sin z3 \cdot \sin z2}{\cos z3 \cdot \cos z2}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    5. lower-unsound-*.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\left(\left(1 + \frac{\sin z3 \cdot \sin z2}{\cos z3 \cdot \cos z2}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    6. lower-unsound-+.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\color{blue}{\left(1 + \frac{\sin z3 \cdot \sin z2}{\cos z3 \cdot \cos z2}\right)} \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    7. lower-unsound-/.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \color{blue}{\frac{\sin z3 \cdot \sin z2}{\cos z3 \cdot \cos z2}}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    8. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\color{blue}{\sin z2 \cdot \sin z3}}{\cos z3 \cdot \cos z2}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    9. lower-*.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\color{blue}{\sin z2 \cdot \sin z3}}{\cos z3 \cdot \cos z2}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    10. lower-sin.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\color{blue}{\sin z2} \cdot \sin z3}{\cos z3 \cdot \cos z2}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    11. lower-sin.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \color{blue}{\sin z3}}{\cos z3 \cdot \cos z2}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    12. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\color{blue}{\cos z2 \cdot \cos z3}}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    13. lower-*.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\color{blue}{\cos z2 \cdot \cos z3}}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    14. lower-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\color{blue}{\cos z2} \cdot \cos z3}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    15. lower-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\cos z2 \cdot \color{blue}{\cos z3}}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    16. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\cos z2 \cdot \cos z3}\right) \cdot \color{blue}{\left(\cos z2 \cdot \cos z3\right)}\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    17. lower-*.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\cos z2 \cdot \cos z3}\right) \cdot \color{blue}{\left(\cos z2 \cdot \cos z3\right)}\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    18. lower-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\cos z2 \cdot \cos z3}\right) \cdot \left(\color{blue}{\cos z2} \cdot \cos z3\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    19. lower-cos.f6493.7%

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\cos z2 \cdot \cos z3}\right) \cdot \left(\cos z2 \cdot \color{blue}{\cos z3}\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
  3. Applied rewrites93.7%

    \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\cos z2 \cdot \cos z3}\right) \cdot \left(\cos z2 \cdot \cos z3\right)\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
  4. Add Preprocessing

Alternative 2: 93.7% accurate, 0.7× speedup?

\[\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(\tan z3 \cdot \tan z2 - -1\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
(FPCore (z0 z1 z3 z2)
  :precision binary64
  (acos
 (+
  (* (sin z0) (sin z1))
  (*
   (* (* (- (* (tan z3) (tan z2)) -1) (* (cos z3) (cos z2))) (cos z1))
   (cos z0)))))
double code(double z0, double z1, double z3, double z2) {
	return acos(((sin(z0) * sin(z1)) + (((((tan(z3) * tan(z2)) - -1.0) * (cos(z3) * cos(z2))) * cos(z1)) * cos(z0))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(z0, z1, z3, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z3
    real(8), intent (in) :: z2
    code = acos(((sin(z0) * sin(z1)) + (((((tan(z3) * tan(z2)) - (-1.0d0)) * (cos(z3) * cos(z2))) * cos(z1)) * cos(z0))))
end function
public static double code(double z0, double z1, double z3, double z2) {
	return Math.acos(((Math.sin(z0) * Math.sin(z1)) + (((((Math.tan(z3) * Math.tan(z2)) - -1.0) * (Math.cos(z3) * Math.cos(z2))) * Math.cos(z1)) * Math.cos(z0))));
}
def code(z0, z1, z3, z2):
	return math.acos(((math.sin(z0) * math.sin(z1)) + (((((math.tan(z3) * math.tan(z2)) - -1.0) * (math.cos(z3) * math.cos(z2))) * math.cos(z1)) * math.cos(z0))))
function code(z0, z1, z3, z2)
	return acos(Float64(Float64(sin(z0) * sin(z1)) + Float64(Float64(Float64(Float64(Float64(tan(z3) * tan(z2)) - -1.0) * Float64(cos(z3) * cos(z2))) * cos(z1)) * cos(z0))))
end
function tmp = code(z0, z1, z3, z2)
	tmp = acos(((sin(z0) * sin(z1)) + (((((tan(z3) * tan(z2)) - -1.0) * (cos(z3) * cos(z2))) * cos(z1)) * cos(z0))));
end
code[z0_, z1_, z3_, z2_] := N[ArcCos[N[(N[(N[Sin[z0], $MachinePrecision] * N[Sin[z1], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[(N[Tan[z3], $MachinePrecision] * N[Tan[z2], $MachinePrecision]), $MachinePrecision] - -1), $MachinePrecision] * N[(N[Cos[z3], $MachinePrecision] * N[Cos[z2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[z1], $MachinePrecision]), $MachinePrecision] * N[Cos[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(\tan z3 \cdot \tan z2 - -1\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right)
Derivation
  1. Initial program 73.9%

    \[\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
  2. Step-by-step derivation
    1. lift-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\cos \left(z3 - z2\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    2. lift--.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \color{blue}{\left(z3 - z2\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    3. cos-diffN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\left(\cos z3 \cdot \cos z2 + \sin z3 \cdot \sin z2\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    4. sum-to-multN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\left(\left(1 + \frac{\sin z3 \cdot \sin z2}{\cos z3 \cdot \cos z2}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    5. lower-unsound-*.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\left(\left(1 + \frac{\sin z3 \cdot \sin z2}{\cos z3 \cdot \cos z2}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    6. lower-unsound-+.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\color{blue}{\left(1 + \frac{\sin z3 \cdot \sin z2}{\cos z3 \cdot \cos z2}\right)} \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    7. lower-unsound-/.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \color{blue}{\frac{\sin z3 \cdot \sin z2}{\cos z3 \cdot \cos z2}}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    8. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\color{blue}{\sin z2 \cdot \sin z3}}{\cos z3 \cdot \cos z2}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    9. lower-*.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\color{blue}{\sin z2 \cdot \sin z3}}{\cos z3 \cdot \cos z2}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    10. lower-sin.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\color{blue}{\sin z2} \cdot \sin z3}{\cos z3 \cdot \cos z2}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    11. lower-sin.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \color{blue}{\sin z3}}{\cos z3 \cdot \cos z2}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    12. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\color{blue}{\cos z2 \cdot \cos z3}}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    13. lower-*.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\color{blue}{\cos z2 \cdot \cos z3}}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    14. lower-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\color{blue}{\cos z2} \cdot \cos z3}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    15. lower-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\cos z2 \cdot \color{blue}{\cos z3}}\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    16. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\cos z2 \cdot \cos z3}\right) \cdot \color{blue}{\left(\cos z2 \cdot \cos z3\right)}\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    17. lower-*.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\cos z2 \cdot \cos z3}\right) \cdot \color{blue}{\left(\cos z2 \cdot \cos z3\right)}\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    18. lower-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\cos z2 \cdot \cos z3}\right) \cdot \left(\color{blue}{\cos z2} \cdot \cos z3\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    19. lower-cos.f6493.7%

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\cos z2 \cdot \cos z3}\right) \cdot \left(\cos z2 \cdot \color{blue}{\cos z3}\right)\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
  3. Applied rewrites93.7%

    \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\left(\left(1 + \frac{\sin z2 \cdot \sin z3}{\cos z2 \cdot \cos z3}\right) \cdot \left(\cos z2 \cdot \cos z3\right)\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
  4. Applied rewrites93.7%

    \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\left(\left(\tan z3 \cdot \tan z2 - -1\right) \cdot \left(\cos z3 \cdot \cos z2\right)\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
  5. Add Preprocessing

Alternative 3: 93.7% accurate, 0.7× speedup?

\[\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\sin z2 \cdot \sin z3 + \cos z2 \cdot \cos z3\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
(FPCore (z0 z1 z3 z2)
  :precision binary64
  (acos
 (+
  (* (sin z0) (sin z1))
  (*
   (* (+ (* (sin z2) (sin z3)) (* (cos z2) (cos z3))) (cos z1))
   (cos z0)))))
double code(double z0, double z1, double z3, double z2) {
	return acos(((sin(z0) * sin(z1)) + ((((sin(z2) * sin(z3)) + (cos(z2) * cos(z3))) * cos(z1)) * cos(z0))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(z0, z1, z3, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z3
    real(8), intent (in) :: z2
    code = acos(((sin(z0) * sin(z1)) + ((((sin(z2) * sin(z3)) + (cos(z2) * cos(z3))) * cos(z1)) * cos(z0))))
end function
public static double code(double z0, double z1, double z3, double z2) {
	return Math.acos(((Math.sin(z0) * Math.sin(z1)) + ((((Math.sin(z2) * Math.sin(z3)) + (Math.cos(z2) * Math.cos(z3))) * Math.cos(z1)) * Math.cos(z0))));
}
def code(z0, z1, z3, z2):
	return math.acos(((math.sin(z0) * math.sin(z1)) + ((((math.sin(z2) * math.sin(z3)) + (math.cos(z2) * math.cos(z3))) * math.cos(z1)) * math.cos(z0))))
function code(z0, z1, z3, z2)
	return acos(Float64(Float64(sin(z0) * sin(z1)) + Float64(Float64(Float64(Float64(sin(z2) * sin(z3)) + Float64(cos(z2) * cos(z3))) * cos(z1)) * cos(z0))))
end
function tmp = code(z0, z1, z3, z2)
	tmp = acos(((sin(z0) * sin(z1)) + ((((sin(z2) * sin(z3)) + (cos(z2) * cos(z3))) * cos(z1)) * cos(z0))));
end
code[z0_, z1_, z3_, z2_] := N[ArcCos[N[(N[(N[Sin[z0], $MachinePrecision] * N[Sin[z1], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[Sin[z2], $MachinePrecision] * N[Sin[z3], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[z2], $MachinePrecision] * N[Cos[z3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[z1], $MachinePrecision]), $MachinePrecision] * N[Cos[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\sin z2 \cdot \sin z3 + \cos z2 \cdot \cos z3\right) \cdot \cos z1\right) \cdot \cos z0\right)
Derivation
  1. Initial program 73.9%

    \[\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
  2. Step-by-step derivation
    1. lift-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\cos \left(z3 - z2\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    2. lift--.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \color{blue}{\left(z3 - z2\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    3. cos-diffN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\left(\cos z3 \cdot \cos z2 + \sin z3 \cdot \sin z2\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    4. +-commutativeN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\left(\sin z3 \cdot \sin z2 + \cos z3 \cdot \cos z2\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    5. lower-+.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\left(\sin z3 \cdot \sin z2 + \cos z3 \cdot \cos z2\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
    6. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\color{blue}{\sin z2 \cdot \sin z3} + \cos z3 \cdot \cos z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    7. lower-*.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\color{blue}{\sin z2 \cdot \sin z3} + \cos z3 \cdot \cos z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    8. lower-sin.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\color{blue}{\sin z2} \cdot \sin z3 + \cos z3 \cdot \cos z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    9. lower-sin.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\sin z2 \cdot \color{blue}{\sin z3} + \cos z3 \cdot \cos z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    10. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\sin z2 \cdot \sin z3 + \color{blue}{\cos z2 \cdot \cos z3}\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    11. lower-*.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\sin z2 \cdot \sin z3 + \color{blue}{\cos z2 \cdot \cos z3}\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    12. lower-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\sin z2 \cdot \sin z3 + \color{blue}{\cos z2} \cdot \cos z3\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    13. lower-cos.f6493.7%

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\left(\sin z2 \cdot \sin z3 + \cos z2 \cdot \color{blue}{\cos z3}\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
  3. Applied rewrites93.7%

    \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\color{blue}{\left(\sin z2 \cdot \sin z3 + \cos z2 \cdot \cos z3\right)} \cdot \cos z1\right) \cdot \cos z0\right) \]
  4. Add Preprocessing

Alternative 4: 73.9% accurate, 1.0× speedup?

\[\pi \cdot \frac{1}{2} - \left(\pi \cdot \frac{1}{2} - \cos^{-1} \left(\left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0 + \sin z1 \cdot \sin z0\right)\right) \]
(FPCore (z0 z1 z3 z2)
  :precision binary64
  (-
 (* PI 1/2)
 (-
  (* PI 1/2)
  (acos
   (+
    (* (* (cos (- z3 z2)) (cos z1)) (cos z0))
    (* (sin z1) (sin z0)))))))
double code(double z0, double z1, double z3, double z2) {
	return (((double) M_PI) * 0.5) - ((((double) M_PI) * 0.5) - acos((((cos((z3 - z2)) * cos(z1)) * cos(z0)) + (sin(z1) * sin(z0)))));
}
public static double code(double z0, double z1, double z3, double z2) {
	return (Math.PI * 0.5) - ((Math.PI * 0.5) - Math.acos((((Math.cos((z3 - z2)) * Math.cos(z1)) * Math.cos(z0)) + (Math.sin(z1) * Math.sin(z0)))));
}
def code(z0, z1, z3, z2):
	return (math.pi * 0.5) - ((math.pi * 0.5) - math.acos((((math.cos((z3 - z2)) * math.cos(z1)) * math.cos(z0)) + (math.sin(z1) * math.sin(z0)))))
function code(z0, z1, z3, z2)
	return Float64(Float64(pi * 0.5) - Float64(Float64(pi * 0.5) - acos(Float64(Float64(Float64(cos(Float64(z3 - z2)) * cos(z1)) * cos(z0)) + Float64(sin(z1) * sin(z0))))))
end
function tmp = code(z0, z1, z3, z2)
	tmp = (pi * 0.5) - ((pi * 0.5) - acos((((cos((z3 - z2)) * cos(z1)) * cos(z0)) + (sin(z1) * sin(z0)))));
end
code[z0_, z1_, z3_, z2_] := N[(N[(Pi * 1/2), $MachinePrecision] - N[(N[(Pi * 1/2), $MachinePrecision] - N[ArcCos[N[(N[(N[(N[Cos[N[(z3 - z2), $MachinePrecision]], $MachinePrecision] * N[Cos[z1], $MachinePrecision]), $MachinePrecision] * N[Cos[z0], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[z1], $MachinePrecision] * N[Sin[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\pi \cdot \frac{1}{2} - \left(\pi \cdot \frac{1}{2} - \cos^{-1} \left(\left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0 + \sin z1 \cdot \sin z0\right)\right)
Derivation
  1. Initial program 73.9%

    \[\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
  2. Step-by-step derivation
    1. lift-acos.f64N/A

      \[\leadsto \color{blue}{\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right)} \]
    2. acos-asinN/A

      \[\leadsto \color{blue}{\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right)} \]
    3. lower--.f64N/A

      \[\leadsto \color{blue}{\frac{\mathsf{PI}\left(\right)}{2} - \sin^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right)} \]
    4. mult-flipN/A

      \[\leadsto \color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}} - \sin^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    5. lower-*.f64N/A

      \[\leadsto \color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}} - \sin^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    6. lower-PI.f64N/A

      \[\leadsto \color{blue}{\pi} \cdot \frac{1}{2} - \sin^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    7. metadata-evalN/A

      \[\leadsto \pi \cdot \color{blue}{\frac{1}{2}} - \sin^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
    8. lower-asin.f6473.7%

      \[\leadsto \pi \cdot \frac{1}{2} - \color{blue}{\sin^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right)} \]
    9. lift-+.f64N/A

      \[\leadsto \pi \cdot \frac{1}{2} - \sin^{-1} \color{blue}{\left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right)} \]
    10. +-commutativeN/A

      \[\leadsto \pi \cdot \frac{1}{2} - \sin^{-1} \color{blue}{\left(\left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0 + \sin z0 \cdot \sin z1\right)} \]
    11. lower-+.f6473.7%

      \[\leadsto \pi \cdot \frac{1}{2} - \sin^{-1} \color{blue}{\left(\left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0 + \sin z0 \cdot \sin z1\right)} \]
  3. Applied rewrites73.7%

    \[\leadsto \color{blue}{\pi \cdot \frac{1}{2} - \sin^{-1} \left(\cos z0 \cdot \left(\cos z1 \cdot \cos \left(z2 - z3\right)\right) + \sin z1 \cdot \sin z0\right)} \]
  4. Applied rewrites73.9%

    \[\leadsto \pi \cdot \frac{1}{2} - \color{blue}{\left(\pi \cdot \frac{1}{2} - \cos^{-1} \left(\left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0 + \sin z1 \cdot \sin z0\right)\right)} \]
  5. Add Preprocessing

Alternative 5: 73.9% accurate, 1.0× speedup?

\[\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos z0 \cdot \cos z1\right) \cdot \cos \left(z2 - z3\right)\right) \]
(FPCore (z0 z1 z3 z2)
  :precision binary64
  (acos
 (+ (* (sin z0) (sin z1)) (* (* (cos z0) (cos z1)) (cos (- z2 z3))))))
double code(double z0, double z1, double z3, double z2) {
	return acos(((sin(z0) * sin(z1)) + ((cos(z0) * cos(z1)) * cos((z2 - z3)))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(z0, z1, z3, z2)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8), intent (in) :: z1
    real(8), intent (in) :: z3
    real(8), intent (in) :: z2
    code = acos(((sin(z0) * sin(z1)) + ((cos(z0) * cos(z1)) * cos((z2 - z3)))))
end function
public static double code(double z0, double z1, double z3, double z2) {
	return Math.acos(((Math.sin(z0) * Math.sin(z1)) + ((Math.cos(z0) * Math.cos(z1)) * Math.cos((z2 - z3)))));
}
def code(z0, z1, z3, z2):
	return math.acos(((math.sin(z0) * math.sin(z1)) + ((math.cos(z0) * math.cos(z1)) * math.cos((z2 - z3)))))
function code(z0, z1, z3, z2)
	return acos(Float64(Float64(sin(z0) * sin(z1)) + Float64(Float64(cos(z0) * cos(z1)) * cos(Float64(z2 - z3)))))
end
function tmp = code(z0, z1, z3, z2)
	tmp = acos(((sin(z0) * sin(z1)) + ((cos(z0) * cos(z1)) * cos((z2 - z3)))));
end
code[z0_, z1_, z3_, z2_] := N[ArcCos[N[(N[(N[Sin[z0], $MachinePrecision] * N[Sin[z1], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[z0], $MachinePrecision] * N[Cos[z1], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(z2 - z3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos z0 \cdot \cos z1\right) \cdot \cos \left(z2 - z3\right)\right)
Derivation
  1. Initial program 73.9%

    \[\cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0\right) \]
  2. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \color{blue}{\left(\cos \left(z3 - z2\right) \cdot \cos z1\right) \cdot \cos z0}\right) \]
    2. lift-*.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \color{blue}{\left(\cos \left(z3 - z2\right) \cdot \cos z1\right)} \cdot \cos z0\right) \]
    3. associate-*l*N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \color{blue}{\cos \left(z3 - z2\right) \cdot \left(\cos z1 \cdot \cos z0\right)}\right) \]
    4. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \color{blue}{\left(\cos z1 \cdot \cos z0\right) \cdot \cos \left(z3 - z2\right)}\right) \]
    5. lower-*.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \color{blue}{\left(\cos z1 \cdot \cos z0\right) \cdot \cos \left(z3 - z2\right)}\right) \]
    6. *-commutativeN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \color{blue}{\left(\cos z0 \cdot \cos z1\right)} \cdot \cos \left(z3 - z2\right)\right) \]
    7. lower-*.f6473.9%

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \color{blue}{\left(\cos z0 \cdot \cos z1\right)} \cdot \cos \left(z3 - z2\right)\right) \]
    8. lift-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos z0 \cdot \cos z1\right) \cdot \color{blue}{\cos \left(z3 - z2\right)}\right) \]
    9. cos-neg-revN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos z0 \cdot \cos z1\right) \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\left(z3 - z2\right)\right)\right)}\right) \]
    10. lower-cos.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos z0 \cdot \cos z1\right) \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\left(z3 - z2\right)\right)\right)}\right) \]
    11. lift--.f64N/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos z0 \cdot \cos z1\right) \cdot \cos \left(\mathsf{neg}\left(\color{blue}{\left(z3 - z2\right)}\right)\right)\right) \]
    12. sub-negate-revN/A

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos z0 \cdot \cos z1\right) \cdot \cos \color{blue}{\left(z2 - z3\right)}\right) \]
    13. lower--.f6473.9%

      \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \left(\cos z0 \cdot \cos z1\right) \cdot \cos \color{blue}{\left(z2 - z3\right)}\right) \]
  3. Applied rewrites73.9%

    \[\leadsto \cos^{-1} \left(\sin z0 \cdot \sin z1 + \color{blue}{\left(\cos z0 \cdot \cos z1\right) \cdot \cos \left(z2 - z3\right)}\right) \]
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2025277 -o generate:taylor -o generate:evaluate
(FPCore (z0 z1 z3 z2)
  :name "(acos (+ (* (sin z0) (sin z1)) (* (* (cos (- z3 z2)) (cos z1)) (cos z0))))"
  :precision binary64
  (acos (+ (* (sin z0) (sin z1)) (* (* (cos (- z3 z2)) (cos z1)) (cos z0)))))