approx-t-guarded

Percentage Accurate: 99.8% → 100.0%
Time: 2.2min
Alternatives: 13
Speedup: 2.6×

Specification

?
\[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  (if (> (fabs (cos phi)) 1e-10) (/ (sin phi) (cos phi)) 0.0))
double code(double phi) {
	double tmp;
	if (fabs(cos(phi)) > 1e-10) {
		tmp = sin(phi) / cos(phi);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
real(8) function code(phi)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    real(8) :: tmp
    if (abs(cos(phi)) > 1d-10) then
        tmp = sin(phi) / cos(phi)
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
public static double code(double phi) {
	double tmp;
	if (Math.abs(Math.cos(phi)) > 1e-10) {
		tmp = Math.sin(phi) / Math.cos(phi);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(phi):
	tmp = 0
	if math.fabs(math.cos(phi)) > 1e-10:
		tmp = math.sin(phi) / math.cos(phi)
	else:
		tmp = 0.0
	return tmp
function code(phi)
	tmp = 0.0
	if (abs(cos(phi)) > 1e-10)
		tmp = Float64(sin(phi) / cos(phi));
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp_2 = code(phi)
	tmp = 0.0;
	if (abs(cos(phi)) > 1e-10)
		tmp = sin(phi) / cos(phi);
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
code[phi_] := If[Greater[N[Abs[N[Cos[phi], $MachinePrecision]], $MachinePrecision], 1e-10], N[(N[Sin[phi], $MachinePrecision] / N[Cos[phi], $MachinePrecision]), $MachinePrecision], 0.0]
f(phi):
	phi in [-inf, +inf]
code: THEORY
BEGIN
f(phi: real): real =
	LET tmp = IF ((abs((cos(phi)))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((sin(phi)) / (cos(phi))) ELSE (0) ENDIF IN
	tmp
END code
\begin{array}{l}
\mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\
\;\;\;\;\frac{\sin \phi}{\cos \phi}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}

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 13 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: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  (if (> (fabs (cos phi)) 1e-10) (/ (sin phi) (cos phi)) 0.0))
double code(double phi) {
	double tmp;
	if (fabs(cos(phi)) > 1e-10) {
		tmp = sin(phi) / cos(phi);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
real(8) function code(phi)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    real(8) :: tmp
    if (abs(cos(phi)) > 1d-10) then
        tmp = sin(phi) / cos(phi)
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
public static double code(double phi) {
	double tmp;
	if (Math.abs(Math.cos(phi)) > 1e-10) {
		tmp = Math.sin(phi) / Math.cos(phi);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(phi):
	tmp = 0
	if math.fabs(math.cos(phi)) > 1e-10:
		tmp = math.sin(phi) / math.cos(phi)
	else:
		tmp = 0.0
	return tmp
function code(phi)
	tmp = 0.0
	if (abs(cos(phi)) > 1e-10)
		tmp = Float64(sin(phi) / cos(phi));
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp_2 = code(phi)
	tmp = 0.0;
	if (abs(cos(phi)) > 1e-10)
		tmp = sin(phi) / cos(phi);
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
code[phi_] := If[Greater[N[Abs[N[Cos[phi], $MachinePrecision]], $MachinePrecision], 1e-10], N[(N[Sin[phi], $MachinePrecision] / N[Cos[phi], $MachinePrecision]), $MachinePrecision], 0.0]
f(phi):
	phi in [-inf, +inf]
code: THEORY
BEGIN
f(phi: real): real =
	LET tmp = IF ((abs((cos(phi)))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((sin(phi)) / (cos(phi))) ELSE (0) ENDIF IN
	tmp
END code
\begin{array}{l}
\mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\
\;\;\;\;\frac{\sin \phi}{\cos \phi}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}

Alternative 1: 100.0% accurate, 2.6× speedup?

\[\begin{array}{l} \mathbf{if}\;\pi > 10^{-10}:\\ \;\;\;\;\tan \phi\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  (if (> PI 1e-10) (tan phi) 0.0))
double code(double phi) {
	double tmp;
	if (((double) M_PI) > 1e-10) {
		tmp = tan(phi);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
public static double code(double phi) {
	double tmp;
	if (Math.PI > 1e-10) {
		tmp = Math.tan(phi);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(phi):
	tmp = 0
	if math.pi > 1e-10:
		tmp = math.tan(phi)
	else:
		tmp = 0.0
	return tmp
function code(phi)
	tmp = 0.0
	if (pi > 1e-10)
		tmp = tan(phi);
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp_2 = code(phi)
	tmp = 0.0;
	if (pi > 1e-10)
		tmp = tan(phi);
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
code[phi_] := If[Greater[Pi, 1e-10], N[Tan[phi], $MachinePrecision], 0.0]
f(phi):
	phi in [-inf, +inf]
code: THEORY
BEGIN
f(phi: real): real =
	LET tmp = IF ((4 * atan(1)) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN (tan(phi)) ELSE (0) ENDIF IN
	tmp
END code
\begin{array}{l}
\mathbf{if}\;\pi > 10^{-10}:\\
\;\;\;\;\tan \phi\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
Derivation
  1. Initial program 99.8%

    \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  2. Applied rewrites100.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\tan \phi\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  3. Applied rewrites100.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\pi > 10^{-10}:\\ \;\;\;\;\tan \phi\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  4. Add Preprocessing

Alternative 2: 58.7% accurate, 0.5× speedup?

\[\begin{array}{l} t_0 := \begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{if}\;t\_0 \leq -0.04:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\mathsf{fma}\left(-1 + \pi, -2, \pi\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;\pi > 10^{-10}:\\ \;\;\;\;\mathsf{fma}\left(\left(\phi \cdot \phi\right) \cdot \phi, 0.3333333333333333, \phi\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{elif}\;\left|\pi\right| > 10^{-10}:\\ \;\;\;\;\frac{1.772453850905516}{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  (let* ((t_0
        (if (> (fabs (cos phi)) 1e-10) (/ (sin phi) (cos phi)) 0.0)))
  (if (<= t_0 -0.04)
    (if (> (fabs 1.0) 1e-10) (fma (+ -1.0 PI) -2.0 PI) 0.0)
    (if (<= t_0 5e-5)
      (if (> PI 1e-10)
        (fma (* (* phi phi) phi) 0.3333333333333333 phi)
        0.0)
      (if (> (fabs PI) 1e-10) (/ 1.772453850905516 PI) 0.0)))))
double code(double phi) {
	double tmp;
	if (fabs(cos(phi)) > 1e-10) {
		tmp = sin(phi) / cos(phi);
	} else {
		tmp = 0.0;
	}
	double t_0 = tmp;
	double tmp_2;
	if (t_0 <= -0.04) {
		double tmp_3;
		if (fabs(1.0) > 1e-10) {
			tmp_3 = fma((-1.0 + ((double) M_PI)), -2.0, ((double) M_PI));
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0 <= 5e-5) {
		double tmp_4;
		if (((double) M_PI) > 1e-10) {
			tmp_4 = fma(((phi * phi) * phi), 0.3333333333333333, phi);
		} else {
			tmp_4 = 0.0;
		}
		tmp_2 = tmp_4;
	} else if (fabs(((double) M_PI)) > 1e-10) {
		tmp_2 = 1.772453850905516 / ((double) M_PI);
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
function code(phi)
	tmp = 0.0
	if (abs(cos(phi)) > 1e-10)
		tmp = Float64(sin(phi) / cos(phi));
	else
		tmp = 0.0;
	end
	t_0 = tmp
	tmp_2 = 0.0
	if (t_0 <= -0.04)
		tmp_3 = 0.0
		if (abs(1.0) > 1e-10)
			tmp_3 = fma(Float64(-1.0 + pi), -2.0, pi);
		else
			tmp_3 = 0.0;
		end
		tmp_2 = tmp_3;
	elseif (t_0 <= 5e-5)
		tmp_4 = 0.0
		if (pi > 1e-10)
			tmp_4 = fma(Float64(Float64(phi * phi) * phi), 0.3333333333333333, phi);
		else
			tmp_4 = 0.0;
		end
		tmp_2 = tmp_4;
	elseif (abs(pi) > 1e-10)
		tmp_2 = Float64(1.772453850905516 / pi);
	else
		tmp_2 = 0.0;
	end
	return tmp_2
end
code[phi_] := Block[{t$95$0 = If[Greater[N[Abs[N[Cos[phi], $MachinePrecision]], $MachinePrecision], 1e-10], N[(N[Sin[phi], $MachinePrecision] / N[Cos[phi], $MachinePrecision]), $MachinePrecision], 0.0]}, If[LessEqual[t$95$0, -0.04], If[Greater[N[Abs[1.0], $MachinePrecision], 1e-10], N[(N[(-1.0 + Pi), $MachinePrecision] * -2.0 + Pi), $MachinePrecision], 0.0], If[LessEqual[t$95$0, 5e-5], If[Greater[Pi, 1e-10], N[(N[(N[(phi * phi), $MachinePrecision] * phi), $MachinePrecision] * 0.3333333333333333 + phi), $MachinePrecision], 0.0], If[Greater[N[Abs[Pi], $MachinePrecision], 1e-10], N[(1.772453850905516 / Pi), $MachinePrecision], 0.0]]]]
f(phi):
	phi in [-inf, +inf]
code: THEORY
BEGIN
f(phi: real): real =
	LET tmp = IF ((abs((cos(phi)))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((sin(phi)) / (cos(phi))) ELSE (0) ENDIF IN
	LET t_0 = tmp IN
		LET tmp_3 = IF ((abs((1))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((((-1) + (4 * atan(1))) * (-2)) + (4 * atan(1))) ELSE (0) ENDIF IN
		LET tmp_6 = IF ((4 * atan(1)) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((((phi * phi) * phi) * (333333333333333314829616256247390992939472198486328125e-54)) + phi) ELSE (0) ENDIF IN
		LET tmp_7 = IF ((abs((4 * atan(1)))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((17724538509055161039640324815991334617137908935546875e-52) / (4 * atan(1))) ELSE (0) ENDIF IN
		LET tmp_5 = IF (t_0 <= (500000000000000023960868011929647991564706899225711822509765625e-67)) THEN tmp_6 ELSE tmp_7 ENDIF IN
		LET tmp_2 = IF (t_0 <= (-40000000000000000832667268468867405317723751068115234375e-57)) THEN tmp_3 ELSE tmp_5 ENDIF IN
	tmp_2
END code
\begin{array}{l}
t_0 := \begin{array}{l}
\mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\
\;\;\;\;\frac{\sin \phi}{\cos \phi}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\
\mathbf{if}\;t\_0 \leq -0.04:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;\left|1\right| > 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(-1 + \pi, -2, \pi\right)\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;\pi > 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(\left(\phi \cdot \phi\right) \cdot \phi, 0.3333333333333333, \phi\right)\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\

\mathbf{elif}\;\left|\pi\right| > 10^{-10}:\\
\;\;\;\;\frac{1.772453850905516}{\pi}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64)) < -0.040000000000000001

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sqrt{\pi}}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\sqrt{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    6. Applied rewrites6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\sqrt{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    7. Applied rewrites7.0%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\mathsf{fma}\left(-1 + \pi, -2, \pi\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

    if -0.040000000000000001 < (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64)) < 5.0000000000000002e-5

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\phi \cdot \left(1 + \frac{1}{3} \cdot {\phi}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites50.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\phi \cdot \left(1 + 0.3333333333333333 \cdot {\phi}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites50.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\pi > 10^{-10}:\\ \;\;\;\;\phi \cdot \left(1 + 0.3333333333333333 \cdot {\phi}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Applied rewrites50.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\pi > 10^{-10}:\\ \;\;\;\;\mathsf{fma}\left(\left(\phi \cdot \phi\right) \cdot \phi, 0.3333333333333333, \phi\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

    if 5.0000000000000002e-5 < (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64))

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sqrt{\pi}}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Evaluated real constant6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{1.772453850905516}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    6. Applied rewrites6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|\pi\right| > 10^{-10}:\\ \;\;\;\;\frac{1.772453850905516}{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 58.5% accurate, 0.5× speedup?

\[\begin{array}{l} t_0 := \begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ t_1 := \left|1\right| > 10^{-10}\\ \mathbf{if}\;t\_0 \leq -0.04:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t\_1:\\ \;\;\;\;\mathsf{fma}\left(-1 + \pi, -2, \pi\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t\_1:\\ \;\;\;\;\frac{\phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{elif}\;\left|\pi\right| > 10^{-10}:\\ \;\;\;\;\frac{1.772453850905516}{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  (let* ((t_0
        (if (> (fabs (cos phi)) 1e-10) (/ (sin phi) (cos phi)) 0.0))
       (t_1 (> (fabs 1.0) 1e-10)))
  (if (<= t_0 -0.04)
    (if t_1 (fma (+ -1.0 PI) -2.0 PI) 0.0)
    (if (<= t_0 5e-5)
      (if t_1 (/ phi 1.0) 0.0)
      (if (> (fabs PI) 1e-10) (/ 1.772453850905516 PI) 0.0)))))
double code(double phi) {
	double tmp;
	if (fabs(cos(phi)) > 1e-10) {
		tmp = sin(phi) / cos(phi);
	} else {
		tmp = 0.0;
	}
	double t_0 = tmp;
	int t_1 = fabs(1.0) > 1e-10;
	double tmp_2;
	if (t_0 <= -0.04) {
		double tmp_3;
		if (t_1) {
			tmp_3 = fma((-1.0 + ((double) M_PI)), -2.0, ((double) M_PI));
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0 <= 5e-5) {
		double tmp_4;
		if (t_1) {
			tmp_4 = phi / 1.0;
		} else {
			tmp_4 = 0.0;
		}
		tmp_2 = tmp_4;
	} else if (fabs(((double) M_PI)) > 1e-10) {
		tmp_2 = 1.772453850905516 / ((double) M_PI);
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
function code(phi)
	tmp = 0.0
	if (abs(cos(phi)) > 1e-10)
		tmp = Float64(sin(phi) / cos(phi));
	else
		tmp = 0.0;
	end
	t_0 = tmp
	t_1 = abs(1.0) > 1e-10
	tmp_2 = 0.0
	if (t_0 <= -0.04)
		tmp_3 = 0.0
		if (t_1)
			tmp_3 = fma(Float64(-1.0 + pi), -2.0, pi);
		else
			tmp_3 = 0.0;
		end
		tmp_2 = tmp_3;
	elseif (t_0 <= 5e-5)
		tmp_4 = 0.0
		if (t_1)
			tmp_4 = Float64(phi / 1.0);
		else
			tmp_4 = 0.0;
		end
		tmp_2 = tmp_4;
	elseif (abs(pi) > 1e-10)
		tmp_2 = Float64(1.772453850905516 / pi);
	else
		tmp_2 = 0.0;
	end
	return tmp_2
end
code[phi_] := Block[{t$95$0 = If[Greater[N[Abs[N[Cos[phi], $MachinePrecision]], $MachinePrecision], 1e-10], N[(N[Sin[phi], $MachinePrecision] / N[Cos[phi], $MachinePrecision]), $MachinePrecision], 0.0]}, Block[{t$95$1 = Greater[N[Abs[1.0], $MachinePrecision], 1e-10]}, If[LessEqual[t$95$0, -0.04], If[t$95$1, N[(N[(-1.0 + Pi), $MachinePrecision] * -2.0 + Pi), $MachinePrecision], 0.0], If[LessEqual[t$95$0, 5e-5], If[t$95$1, N[(phi / 1.0), $MachinePrecision], 0.0], If[Greater[N[Abs[Pi], $MachinePrecision], 1e-10], N[(1.772453850905516 / Pi), $MachinePrecision], 0.0]]]]]
f(phi):
	phi in [-inf, +inf]
code: THEORY
BEGIN
f(phi: real): real =
	LET tmp = IF ((abs((cos(phi)))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((sin(phi)) / (cos(phi))) ELSE (0) ENDIF IN
	LET t_0 = tmp IN
		LET t_1 = ((abs((1))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) IN
			LET tmp_3 = IF t_1 THEN ((((-1) + (4 * atan(1))) * (-2)) + (4 * atan(1))) ELSE (0) ENDIF IN
			LET tmp_6 = IF t_1 THEN (phi / (1)) ELSE (0) ENDIF IN
			LET tmp_7 = IF ((abs((4 * atan(1)))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((17724538509055161039640324815991334617137908935546875e-52) / (4 * atan(1))) ELSE (0) ENDIF IN
			LET tmp_5 = IF (t_0 <= (500000000000000023960868011929647991564706899225711822509765625e-67)) THEN tmp_6 ELSE tmp_7 ENDIF IN
			LET tmp_2 = IF (t_0 <= (-40000000000000000832667268468867405317723751068115234375e-57)) THEN tmp_3 ELSE tmp_5 ENDIF IN
	tmp_2
END code
\begin{array}{l}
t_0 := \begin{array}{l}
\mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\
\;\;\;\;\frac{\sin \phi}{\cos \phi}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\
t_1 := \left|1\right| > 10^{-10}\\
\mathbf{if}\;t\_0 \leq -0.04:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t\_1:\\
\;\;\;\;\mathsf{fma}\left(-1 + \pi, -2, \pi\right)\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t\_1:\\
\;\;\;\;\frac{\phi}{1}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\

\mathbf{elif}\;\left|\pi\right| > 10^{-10}:\\
\;\;\;\;\frac{1.772453850905516}{\pi}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64)) < -0.040000000000000001

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sqrt{\pi}}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\sqrt{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    6. Applied rewrites6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\sqrt{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    7. Applied rewrites7.0%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\mathsf{fma}\left(-1 + \pi, -2, \pi\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

    if -0.040000000000000001 < (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64)) < 5.0000000000000002e-5

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites50.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

    if 5.0000000000000002e-5 < (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64))

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sqrt{\pi}}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Evaluated real constant6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{1.772453850905516}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    6. Applied rewrites6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|\pi\right| > 10^{-10}:\\ \;\;\;\;\frac{1.772453850905516}{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 58.4% accurate, 0.5× speedup?

\[\begin{array}{l} t_0 := \begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ t_1 := \left|1\right| > 10^{-10}\\ \mathbf{if}\;t\_0 \leq -0.04:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t\_1:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t\_1:\\ \;\;\;\;\frac{\phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{elif}\;\left|\pi\right| > 10^{-10}:\\ \;\;\;\;\frac{1.772453850905516}{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  (let* ((t_0
        (if (> (fabs (cos phi)) 1e-10) (/ (sin phi) (cos phi)) 0.0))
       (t_1 (> (fabs 1.0) 1e-10)))
  (if (<= t_0 -0.04)
    (if t_1 -2.0 0.0)
    (if (<= t_0 5e-5)
      (if t_1 (/ phi 1.0) 0.0)
      (if (> (fabs PI) 1e-10) (/ 1.772453850905516 PI) 0.0)))))
double code(double phi) {
	double tmp;
	if (fabs(cos(phi)) > 1e-10) {
		tmp = sin(phi) / cos(phi);
	} else {
		tmp = 0.0;
	}
	double t_0 = tmp;
	int t_1 = fabs(1.0) > 1e-10;
	double tmp_2;
	if (t_0 <= -0.04) {
		double tmp_3;
		if (t_1) {
			tmp_3 = -2.0;
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0 <= 5e-5) {
		double tmp_4;
		if (t_1) {
			tmp_4 = phi / 1.0;
		} else {
			tmp_4 = 0.0;
		}
		tmp_2 = tmp_4;
	} else if (fabs(((double) M_PI)) > 1e-10) {
		tmp_2 = 1.772453850905516 / ((double) M_PI);
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
public static double code(double phi) {
	double tmp;
	if (Math.abs(Math.cos(phi)) > 1e-10) {
		tmp = Math.sin(phi) / Math.cos(phi);
	} else {
		tmp = 0.0;
	}
	double t_0 = tmp;
	boolean t_1 = Math.abs(1.0) > 1e-10;
	double tmp_2;
	if (t_0 <= -0.04) {
		double tmp_3;
		if (t_1) {
			tmp_3 = -2.0;
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0 <= 5e-5) {
		double tmp_4;
		if (t_1) {
			tmp_4 = phi / 1.0;
		} else {
			tmp_4 = 0.0;
		}
		tmp_2 = tmp_4;
	} else if (Math.abs(Math.PI) > 1e-10) {
		tmp_2 = 1.772453850905516 / Math.PI;
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
def code(phi):
	tmp = 0
	if math.fabs(math.cos(phi)) > 1e-10:
		tmp = math.sin(phi) / math.cos(phi)
	else:
		tmp = 0.0
	t_0 = tmp
	t_1 = math.fabs(1.0) > 1e-10
	tmp_2 = 0
	if t_0 <= -0.04:
		tmp_3 = 0
		if t_1:
			tmp_3 = -2.0
		else:
			tmp_3 = 0.0
		tmp_2 = tmp_3
	elif t_0 <= 5e-5:
		tmp_4 = 0
		if t_1:
			tmp_4 = phi / 1.0
		else:
			tmp_4 = 0.0
		tmp_2 = tmp_4
	elif math.fabs(math.pi) > 1e-10:
		tmp_2 = 1.772453850905516 / math.pi
	else:
		tmp_2 = 0.0
	return tmp_2
function code(phi)
	tmp = 0.0
	if (abs(cos(phi)) > 1e-10)
		tmp = Float64(sin(phi) / cos(phi));
	else
		tmp = 0.0;
	end
	t_0 = tmp
	t_1 = abs(1.0) > 1e-10
	tmp_2 = 0.0
	if (t_0 <= -0.04)
		tmp_3 = 0.0
		if (t_1)
			tmp_3 = -2.0;
		else
			tmp_3 = 0.0;
		end
		tmp_2 = tmp_3;
	elseif (t_0 <= 5e-5)
		tmp_4 = 0.0
		if (t_1)
			tmp_4 = Float64(phi / 1.0);
		else
			tmp_4 = 0.0;
		end
		tmp_2 = tmp_4;
	elseif (abs(pi) > 1e-10)
		tmp_2 = Float64(1.772453850905516 / pi);
	else
		tmp_2 = 0.0;
	end
	return tmp_2
end
function tmp_6 = code(phi)
	tmp = 0.0;
	if (abs(cos(phi)) > 1e-10)
		tmp = sin(phi) / cos(phi);
	else
		tmp = 0.0;
	end
	t_0 = tmp;
	t_1 = abs(1.0) > 1e-10;
	tmp_3 = 0.0;
	if (t_0 <= -0.04)
		tmp_4 = 0.0;
		if (t_1)
			tmp_4 = -2.0;
		else
			tmp_4 = 0.0;
		end
		tmp_3 = tmp_4;
	elseif (t_0 <= 5e-5)
		tmp_5 = 0.0;
		if (t_1)
			tmp_5 = phi / 1.0;
		else
			tmp_5 = 0.0;
		end
		tmp_3 = tmp_5;
	elseif (abs(pi) > 1e-10)
		tmp_3 = 1.772453850905516 / pi;
	else
		tmp_3 = 0.0;
	end
	tmp_6 = tmp_3;
end
code[phi_] := Block[{t$95$0 = If[Greater[N[Abs[N[Cos[phi], $MachinePrecision]], $MachinePrecision], 1e-10], N[(N[Sin[phi], $MachinePrecision] / N[Cos[phi], $MachinePrecision]), $MachinePrecision], 0.0]}, Block[{t$95$1 = Greater[N[Abs[1.0], $MachinePrecision], 1e-10]}, If[LessEqual[t$95$0, -0.04], If[t$95$1, -2.0, 0.0], If[LessEqual[t$95$0, 5e-5], If[t$95$1, N[(phi / 1.0), $MachinePrecision], 0.0], If[Greater[N[Abs[Pi], $MachinePrecision], 1e-10], N[(1.772453850905516 / Pi), $MachinePrecision], 0.0]]]]]
f(phi):
	phi in [-inf, +inf]
code: THEORY
BEGIN
f(phi: real): real =
	LET tmp = IF ((abs((cos(phi)))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((sin(phi)) / (cos(phi))) ELSE (0) ENDIF IN
	LET t_0 = tmp IN
		LET t_1 = ((abs((1))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) IN
			LET tmp_3 = IF t_1 THEN (-2) ELSE (0) ENDIF IN
			LET tmp_6 = IF t_1 THEN (phi / (1)) ELSE (0) ENDIF IN
			LET tmp_7 = IF ((abs((4 * atan(1)))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((17724538509055161039640324815991334617137908935546875e-52) / (4 * atan(1))) ELSE (0) ENDIF IN
			LET tmp_5 = IF (t_0 <= (500000000000000023960868011929647991564706899225711822509765625e-67)) THEN tmp_6 ELSE tmp_7 ENDIF IN
			LET tmp_2 = IF (t_0 <= (-40000000000000000832667268468867405317723751068115234375e-57)) THEN tmp_3 ELSE tmp_5 ENDIF IN
	tmp_2
END code
\begin{array}{l}
t_0 := \begin{array}{l}
\mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\
\;\;\;\;\frac{\sin \phi}{\cos \phi}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\
t_1 := \left|1\right| > 10^{-10}\\
\mathbf{if}\;t\_0 \leq -0.04:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t\_1:\\
\;\;\;\;-2\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t\_1:\\
\;\;\;\;\frac{\phi}{1}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\

\mathbf{elif}\;\left|\pi\right| > 10^{-10}:\\
\;\;\;\;\frac{1.772453850905516}{\pi}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64)) < -0.040000000000000001

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{-2}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    6. Applied rewrites6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

    if -0.040000000000000001 < (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64)) < 5.0000000000000002e-5

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites50.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

    if 5.0000000000000002e-5 < (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64))

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sqrt{\pi}}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Evaluated real constant6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{1.772453850905516}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    6. Applied rewrites6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|\pi\right| > 10^{-10}:\\ \;\;\;\;\frac{1.772453850905516}{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 58.4% accurate, 0.5× speedup?

\[\begin{array}{l} t_0 := \begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ t_1 := \left|1\right| > 10^{-10}\\ \mathbf{if}\;t\_0 \leq -0.04:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t\_1:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t\_1:\\ \;\;\;\;\frac{\phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{elif}\;t\_1:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  (let* ((t_0
        (if (> (fabs (cos phi)) 1e-10) (/ (sin phi) (cos phi)) 0.0))
       (t_1 (> (fabs 1.0) 1e-10)))
  (if (<= t_0 -0.04)
    (if t_1 -2.0 0.0)
    (if (<= t_0 5e-5) (if t_1 (/ phi 1.0) 0.0) (if t_1 0.5 0.0)))))
double code(double phi) {
	double tmp;
	if (fabs(cos(phi)) > 1e-10) {
		tmp = sin(phi) / cos(phi);
	} else {
		tmp = 0.0;
	}
	double t_0 = tmp;
	int t_1 = fabs(1.0) > 1e-10;
	double tmp_2;
	if (t_0 <= -0.04) {
		double tmp_3;
		if (t_1) {
			tmp_3 = -2.0;
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0 <= 5e-5) {
		double tmp_4;
		if (t_1) {
			tmp_4 = phi / 1.0;
		} else {
			tmp_4 = 0.0;
		}
		tmp_2 = tmp_4;
	} else if (t_1) {
		tmp_2 = 0.5;
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
real(8) function code(phi)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    real(8) :: t_0
    logical :: t_1
    real(8) :: tmp
    real(8) :: tmp_1
    real(8) :: tmp_2
    real(8) :: tmp_3
    real(8) :: tmp_4
    if (abs(cos(phi)) > 1d-10) then
        tmp = sin(phi) / cos(phi)
    else
        tmp = 0.0d0
    end if
    t_0 = tmp
    t_1 = abs(1.0d0) > 1d-10
    if (t_0 <= (-0.04d0)) then
        if (t_1) then
            tmp_3 = -2.0d0
        else
            tmp_3 = 0.0d0
        end if
        tmp_2 = tmp_3
    else if (t_0 <= 5d-5) then
        if (t_1) then
            tmp_4 = phi / 1.0d0
        else
            tmp_4 = 0.0d0
        end if
        tmp_2 = tmp_4
    else if (t_1) then
        tmp_2 = 0.5d0
    else
        tmp_2 = 0.0d0
    end if
    code = tmp_2
end function
public static double code(double phi) {
	double tmp;
	if (Math.abs(Math.cos(phi)) > 1e-10) {
		tmp = Math.sin(phi) / Math.cos(phi);
	} else {
		tmp = 0.0;
	}
	double t_0 = tmp;
	boolean t_1 = Math.abs(1.0) > 1e-10;
	double tmp_2;
	if (t_0 <= -0.04) {
		double tmp_3;
		if (t_1) {
			tmp_3 = -2.0;
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0 <= 5e-5) {
		double tmp_4;
		if (t_1) {
			tmp_4 = phi / 1.0;
		} else {
			tmp_4 = 0.0;
		}
		tmp_2 = tmp_4;
	} else if (t_1) {
		tmp_2 = 0.5;
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
def code(phi):
	tmp = 0
	if math.fabs(math.cos(phi)) > 1e-10:
		tmp = math.sin(phi) / math.cos(phi)
	else:
		tmp = 0.0
	t_0 = tmp
	t_1 = math.fabs(1.0) > 1e-10
	tmp_2 = 0
	if t_0 <= -0.04:
		tmp_3 = 0
		if t_1:
			tmp_3 = -2.0
		else:
			tmp_3 = 0.0
		tmp_2 = tmp_3
	elif t_0 <= 5e-5:
		tmp_4 = 0
		if t_1:
			tmp_4 = phi / 1.0
		else:
			tmp_4 = 0.0
		tmp_2 = tmp_4
	elif t_1:
		tmp_2 = 0.5
	else:
		tmp_2 = 0.0
	return tmp_2
function code(phi)
	tmp = 0.0
	if (abs(cos(phi)) > 1e-10)
		tmp = Float64(sin(phi) / cos(phi));
	else
		tmp = 0.0;
	end
	t_0 = tmp
	t_1 = abs(1.0) > 1e-10
	tmp_2 = 0.0
	if (t_0 <= -0.04)
		tmp_3 = 0.0
		if (t_1)
			tmp_3 = -2.0;
		else
			tmp_3 = 0.0;
		end
		tmp_2 = tmp_3;
	elseif (t_0 <= 5e-5)
		tmp_4 = 0.0
		if (t_1)
			tmp_4 = Float64(phi / 1.0);
		else
			tmp_4 = 0.0;
		end
		tmp_2 = tmp_4;
	elseif (t_1)
		tmp_2 = 0.5;
	else
		tmp_2 = 0.0;
	end
	return tmp_2
end
function tmp_6 = code(phi)
	tmp = 0.0;
	if (abs(cos(phi)) > 1e-10)
		tmp = sin(phi) / cos(phi);
	else
		tmp = 0.0;
	end
	t_0 = tmp;
	t_1 = abs(1.0) > 1e-10;
	tmp_3 = 0.0;
	if (t_0 <= -0.04)
		tmp_4 = 0.0;
		if (t_1)
			tmp_4 = -2.0;
		else
			tmp_4 = 0.0;
		end
		tmp_3 = tmp_4;
	elseif (t_0 <= 5e-5)
		tmp_5 = 0.0;
		if (t_1)
			tmp_5 = phi / 1.0;
		else
			tmp_5 = 0.0;
		end
		tmp_3 = tmp_5;
	elseif (t_1)
		tmp_3 = 0.5;
	else
		tmp_3 = 0.0;
	end
	tmp_6 = tmp_3;
end
code[phi_] := Block[{t$95$0 = If[Greater[N[Abs[N[Cos[phi], $MachinePrecision]], $MachinePrecision], 1e-10], N[(N[Sin[phi], $MachinePrecision] / N[Cos[phi], $MachinePrecision]), $MachinePrecision], 0.0]}, Block[{t$95$1 = Greater[N[Abs[1.0], $MachinePrecision], 1e-10]}, If[LessEqual[t$95$0, -0.04], If[t$95$1, -2.0, 0.0], If[LessEqual[t$95$0, 5e-5], If[t$95$1, N[(phi / 1.0), $MachinePrecision], 0.0], If[t$95$1, 0.5, 0.0]]]]]
f(phi):
	phi in [-inf, +inf]
code: THEORY
BEGIN
f(phi: real): real =
	LET tmp = IF ((abs((cos(phi)))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((sin(phi)) / (cos(phi))) ELSE (0) ENDIF IN
	LET t_0 = tmp IN
		LET t_1 = ((abs((1))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) IN
			LET tmp_3 = IF t_1 THEN (-2) ELSE (0) ENDIF IN
			LET tmp_6 = IF t_1 THEN (phi / (1)) ELSE (0) ENDIF IN
			LET tmp_7 = IF t_1 THEN (5e-1) ELSE (0) ENDIF IN
			LET tmp_5 = IF (t_0 <= (500000000000000023960868011929647991564706899225711822509765625e-67)) THEN tmp_6 ELSE tmp_7 ENDIF IN
			LET tmp_2 = IF (t_0 <= (-40000000000000000832667268468867405317723751068115234375e-57)) THEN tmp_3 ELSE tmp_5 ENDIF IN
	tmp_2
END code
\begin{array}{l}
t_0 := \begin{array}{l}
\mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\
\;\;\;\;\frac{\sin \phi}{\cos \phi}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\
t_1 := \left|1\right| > 10^{-10}\\
\mathbf{if}\;t\_0 \leq -0.04:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t\_1:\\
\;\;\;\;-2\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t\_1:\\
\;\;\;\;\frac{\phi}{1}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\

\mathbf{elif}\;t\_1:\\
\;\;\;\;0.5\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64)) < -0.040000000000000001

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{-2}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    6. Applied rewrites6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

    if -0.040000000000000001 < (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64)) < 5.0000000000000002e-5

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites50.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

    if 5.0000000000000002e-5 < (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64))

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{0.5}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    6. Applied rewrites6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 12.0% accurate, 0.9× speedup?

\[\begin{array}{l} t_0 := \left|1\right| > 10^{-10}\\ \mathbf{if}\;\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \leq -2.230958397017838 \cdot 10^{-303}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t\_0:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{elif}\;t\_0:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (> (fabs 1.0) 1e-10)))
  (if (<=
       (if (> (fabs (cos phi)) 1e-10) (/ (sin phi) (cos phi)) 0.0)
       -2.230958397017838e-303)
    (if t_0 -1.0 0.0)
    (if t_0 0.5 0.0))))
double code(double phi) {
	int t_0 = fabs(1.0) > 1e-10;
	double tmp;
	if (fabs(cos(phi)) > 1e-10) {
		tmp = sin(phi) / cos(phi);
	} else {
		tmp = 0.0;
	}
	double tmp_2;
	if (tmp <= -2.230958397017838e-303) {
		double tmp_3;
		if (t_0) {
			tmp_3 = -1.0;
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0) {
		tmp_2 = 0.5;
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
real(8) function code(phi)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    logical :: t_0
    real(8) :: tmp
    real(8) :: tmp_1
    real(8) :: tmp_2
    real(8) :: tmp_3
    t_0 = abs(1.0d0) > 1d-10
    if (abs(cos(phi)) > 1d-10) then
        tmp = sin(phi) / cos(phi)
    else
        tmp = 0.0d0
    end if
    if (tmp <= (-2.230958397017838d-303)) then
        if (t_0) then
            tmp_3 = -1.0d0
        else
            tmp_3 = 0.0d0
        end if
        tmp_2 = tmp_3
    else if (t_0) then
        tmp_2 = 0.5d0
    else
        tmp_2 = 0.0d0
    end if
    code = tmp_2
end function
public static double code(double phi) {
	boolean t_0 = Math.abs(1.0) > 1e-10;
	double tmp;
	if (Math.abs(Math.cos(phi)) > 1e-10) {
		tmp = Math.sin(phi) / Math.cos(phi);
	} else {
		tmp = 0.0;
	}
	double tmp_2;
	if (tmp <= -2.230958397017838e-303) {
		double tmp_3;
		if (t_0) {
			tmp_3 = -1.0;
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0) {
		tmp_2 = 0.5;
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
def code(phi):
	t_0 = math.fabs(1.0) > 1e-10
	tmp = 0
	if math.fabs(math.cos(phi)) > 1e-10:
		tmp = math.sin(phi) / math.cos(phi)
	else:
		tmp = 0.0
	tmp_2 = 0
	if tmp <= -2.230958397017838e-303:
		tmp_3 = 0
		if t_0:
			tmp_3 = -1.0
		else:
			tmp_3 = 0.0
		tmp_2 = tmp_3
	elif t_0:
		tmp_2 = 0.5
	else:
		tmp_2 = 0.0
	return tmp_2
function code(phi)
	t_0 = abs(1.0) > 1e-10
	tmp = 0.0
	if (abs(cos(phi)) > 1e-10)
		tmp = Float64(sin(phi) / cos(phi));
	else
		tmp = 0.0;
	end
	tmp_2 = 0.0
	if (tmp <= -2.230958397017838e-303)
		tmp_3 = 0.0
		if (t_0)
			tmp_3 = -1.0;
		else
			tmp_3 = 0.0;
		end
		tmp_2 = tmp_3;
	elseif (t_0)
		tmp_2 = 0.5;
	else
		tmp_2 = 0.0;
	end
	return tmp_2
end
function tmp_5 = code(phi)
	t_0 = abs(1.0) > 1e-10;
	tmp = 0.0;
	if (abs(cos(phi)) > 1e-10)
		tmp = sin(phi) / cos(phi);
	else
		tmp = 0.0;
	end
	tmp_3 = 0.0;
	if (tmp <= -2.230958397017838e-303)
		tmp_4 = 0.0;
		if (t_0)
			tmp_4 = -1.0;
		else
			tmp_4 = 0.0;
		end
		tmp_3 = tmp_4;
	elseif (t_0)
		tmp_3 = 0.5;
	else
		tmp_3 = 0.0;
	end
	tmp_5 = tmp_3;
end
code[phi_] := Block[{t$95$0 = Greater[N[Abs[1.0], $MachinePrecision], 1e-10]}, If[LessEqual[If[Greater[N[Abs[N[Cos[phi], $MachinePrecision]], $MachinePrecision], 1e-10], N[(N[Sin[phi], $MachinePrecision] / N[Cos[phi], $MachinePrecision]), $MachinePrecision], 0.0], -2.230958397017838e-303], If[t$95$0, -1.0, 0.0], If[t$95$0, 0.5, 0.0]]]
f(phi):
	phi in [-inf, +inf]
code: THEORY
BEGIN
f(phi: real): real =
	LET t_0 = ((abs((1))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) IN
		LET tmp_2 = IF ((abs((cos(phi)))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((sin(phi)) / (cos(phi))) ELSE (0) ENDIF IN
		LET tmp_3 = IF t_0 THEN (-1) ELSE (0) ENDIF IN
		LET tmp_4 = IF t_0 THEN (5e-1) ELSE (0) ENDIF IN
		LET tmp_1 = IF (tmp_2 <= (-223095839701783796269183033742727118605456043305553169821576721257110973833219704311832989118169864862816735787935294227200607496751470058122937725402680479652706922657905283976347219053822968252590400997602593522416832139156037742322778691825214123589472517016827995289785665699375806358761630648867734554350715817255242980473656467734985570607578271505954846400846115696926923399217185678283346007339035078329809698268499223667881212685356491367958291484440527918807212360975977906897046834748198687197607560260948522851023082226468949093205504152580312056767672382645618261156093079836846934013066218232838021322231954655208924233089770474668540273806376813526222286159927544039178266832054897730124291213509133031955844472804528777487576007843017578125e-1058)) THEN tmp_3 ELSE tmp_4 ENDIF IN
	tmp_1
END code
\begin{array}{l}
t_0 := \left|1\right| > 10^{-10}\\
\mathbf{if}\;\begin{array}{l}
\mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\
\;\;\;\;\frac{\sin \phi}{\cos \phi}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array} \leq -2.230958397017838 \cdot 10^{-303}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t\_0:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\

\mathbf{elif}\;t\_0:\\
\;\;\;\;0.5\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64)) < -2.230958397017838e-303

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites7.0%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{-1}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    6. Applied rewrites7.0%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

    if -2.230958397017838e-303 < (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64))

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{0.5}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    6. Applied rewrites6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 12.0% accurate, 0.9× speedup?

\[\begin{array}{l} t_0 := \left|1\right| > 10^{-10}\\ \mathbf{if}\;\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \leq -2.230958397017838 \cdot 10^{-303}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t\_0:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{elif}\;t\_0:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (> (fabs 1.0) 1e-10)))
  (if (<=
       (if (> (fabs (cos phi)) 1e-10) (/ (sin phi) (cos phi)) 0.0)
       -2.230958397017838e-303)
    (if t_0 -1.0 0.0)
    (if t_0 1.0 0.0))))
double code(double phi) {
	int t_0 = fabs(1.0) > 1e-10;
	double tmp;
	if (fabs(cos(phi)) > 1e-10) {
		tmp = sin(phi) / cos(phi);
	} else {
		tmp = 0.0;
	}
	double tmp_2;
	if (tmp <= -2.230958397017838e-303) {
		double tmp_3;
		if (t_0) {
			tmp_3 = -1.0;
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0) {
		tmp_2 = 1.0;
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
real(8) function code(phi)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    logical :: t_0
    real(8) :: tmp
    real(8) :: tmp_1
    real(8) :: tmp_2
    real(8) :: tmp_3
    t_0 = abs(1.0d0) > 1d-10
    if (abs(cos(phi)) > 1d-10) then
        tmp = sin(phi) / cos(phi)
    else
        tmp = 0.0d0
    end if
    if (tmp <= (-2.230958397017838d-303)) then
        if (t_0) then
            tmp_3 = -1.0d0
        else
            tmp_3 = 0.0d0
        end if
        tmp_2 = tmp_3
    else if (t_0) then
        tmp_2 = 1.0d0
    else
        tmp_2 = 0.0d0
    end if
    code = tmp_2
end function
public static double code(double phi) {
	boolean t_0 = Math.abs(1.0) > 1e-10;
	double tmp;
	if (Math.abs(Math.cos(phi)) > 1e-10) {
		tmp = Math.sin(phi) / Math.cos(phi);
	} else {
		tmp = 0.0;
	}
	double tmp_2;
	if (tmp <= -2.230958397017838e-303) {
		double tmp_3;
		if (t_0) {
			tmp_3 = -1.0;
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0) {
		tmp_2 = 1.0;
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
def code(phi):
	t_0 = math.fabs(1.0) > 1e-10
	tmp = 0
	if math.fabs(math.cos(phi)) > 1e-10:
		tmp = math.sin(phi) / math.cos(phi)
	else:
		tmp = 0.0
	tmp_2 = 0
	if tmp <= -2.230958397017838e-303:
		tmp_3 = 0
		if t_0:
			tmp_3 = -1.0
		else:
			tmp_3 = 0.0
		tmp_2 = tmp_3
	elif t_0:
		tmp_2 = 1.0
	else:
		tmp_2 = 0.0
	return tmp_2
function code(phi)
	t_0 = abs(1.0) > 1e-10
	tmp = 0.0
	if (abs(cos(phi)) > 1e-10)
		tmp = Float64(sin(phi) / cos(phi));
	else
		tmp = 0.0;
	end
	tmp_2 = 0.0
	if (tmp <= -2.230958397017838e-303)
		tmp_3 = 0.0
		if (t_0)
			tmp_3 = -1.0;
		else
			tmp_3 = 0.0;
		end
		tmp_2 = tmp_3;
	elseif (t_0)
		tmp_2 = 1.0;
	else
		tmp_2 = 0.0;
	end
	return tmp_2
end
function tmp_5 = code(phi)
	t_0 = abs(1.0) > 1e-10;
	tmp = 0.0;
	if (abs(cos(phi)) > 1e-10)
		tmp = sin(phi) / cos(phi);
	else
		tmp = 0.0;
	end
	tmp_3 = 0.0;
	if (tmp <= -2.230958397017838e-303)
		tmp_4 = 0.0;
		if (t_0)
			tmp_4 = -1.0;
		else
			tmp_4 = 0.0;
		end
		tmp_3 = tmp_4;
	elseif (t_0)
		tmp_3 = 1.0;
	else
		tmp_3 = 0.0;
	end
	tmp_5 = tmp_3;
end
code[phi_] := Block[{t$95$0 = Greater[N[Abs[1.0], $MachinePrecision], 1e-10]}, If[LessEqual[If[Greater[N[Abs[N[Cos[phi], $MachinePrecision]], $MachinePrecision], 1e-10], N[(N[Sin[phi], $MachinePrecision] / N[Cos[phi], $MachinePrecision]), $MachinePrecision], 0.0], -2.230958397017838e-303], If[t$95$0, -1.0, 0.0], If[t$95$0, 1.0, 0.0]]]
f(phi):
	phi in [-inf, +inf]
code: THEORY
BEGIN
f(phi: real): real =
	LET t_0 = ((abs((1))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) IN
		LET tmp_2 = IF ((abs((cos(phi)))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((sin(phi)) / (cos(phi))) ELSE (0) ENDIF IN
		LET tmp_3 = IF t_0 THEN (-1) ELSE (0) ENDIF IN
		LET tmp_4 = IF t_0 THEN (1) ELSE (0) ENDIF IN
		LET tmp_1 = IF (tmp_2 <= (-223095839701783796269183033742727118605456043305553169821576721257110973833219704311832989118169864862816735787935294227200607496751470058122937725402680479652706922657905283976347219053822968252590400997602593522416832139156037742322778691825214123589472517016827995289785665699375806358761630648867734554350715817255242980473656467734985570607578271505954846400846115696926923399217185678283346007339035078329809698268499223667881212685356491367958291484440527918807212360975977906897046834748198687197607560260948522851023082226468949093205504152580312056767672382645618261156093079836846934013066218232838021322231954655208924233089770474668540273806376813526222286159927544039178266832054897730124291213509133031955844472804528777487576007843017578125e-1058)) THEN tmp_3 ELSE tmp_4 ENDIF IN
	tmp_1
END code
\begin{array}{l}
t_0 := \left|1\right| > 10^{-10}\\
\mathbf{if}\;\begin{array}{l}
\mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\
\;\;\;\;\frac{\sin \phi}{\cos \phi}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array} \leq -2.230958397017838 \cdot 10^{-303}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t\_0:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\

\mathbf{elif}\;t\_0:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64)) < -2.230958397017838e-303

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites7.0%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{-1}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    6. Applied rewrites7.0%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

    if -2.230958397017838e-303 < (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64))

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\pi}{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Evaluated real constant6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 11.9% accurate, 0.9× speedup?

\[\begin{array}{l} t_0 := \left|1\right| > 10^{-10}\\ \mathbf{if}\;\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \leq -4.4876674121164324 \cdot 10^{-302}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t\_0:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{elif}\;t\_0:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (> (fabs 1.0) 1e-10)))
  (if (<=
       (if (> (fabs (cos phi)) 1e-10) (/ (sin phi) (cos phi)) 0.0)
       -4.4876674121164324e-302)
    (if t_0 -2.0 0.0)
    (if t_0 1.0 0.0))))
double code(double phi) {
	int t_0 = fabs(1.0) > 1e-10;
	double tmp;
	if (fabs(cos(phi)) > 1e-10) {
		tmp = sin(phi) / cos(phi);
	} else {
		tmp = 0.0;
	}
	double tmp_2;
	if (tmp <= -4.4876674121164324e-302) {
		double tmp_3;
		if (t_0) {
			tmp_3 = -2.0;
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0) {
		tmp_2 = 1.0;
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
real(8) function code(phi)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    logical :: t_0
    real(8) :: tmp
    real(8) :: tmp_1
    real(8) :: tmp_2
    real(8) :: tmp_3
    t_0 = abs(1.0d0) > 1d-10
    if (abs(cos(phi)) > 1d-10) then
        tmp = sin(phi) / cos(phi)
    else
        tmp = 0.0d0
    end if
    if (tmp <= (-4.4876674121164324d-302)) then
        if (t_0) then
            tmp_3 = -2.0d0
        else
            tmp_3 = 0.0d0
        end if
        tmp_2 = tmp_3
    else if (t_0) then
        tmp_2 = 1.0d0
    else
        tmp_2 = 0.0d0
    end if
    code = tmp_2
end function
public static double code(double phi) {
	boolean t_0 = Math.abs(1.0) > 1e-10;
	double tmp;
	if (Math.abs(Math.cos(phi)) > 1e-10) {
		tmp = Math.sin(phi) / Math.cos(phi);
	} else {
		tmp = 0.0;
	}
	double tmp_2;
	if (tmp <= -4.4876674121164324e-302) {
		double tmp_3;
		if (t_0) {
			tmp_3 = -2.0;
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0) {
		tmp_2 = 1.0;
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
def code(phi):
	t_0 = math.fabs(1.0) > 1e-10
	tmp = 0
	if math.fabs(math.cos(phi)) > 1e-10:
		tmp = math.sin(phi) / math.cos(phi)
	else:
		tmp = 0.0
	tmp_2 = 0
	if tmp <= -4.4876674121164324e-302:
		tmp_3 = 0
		if t_0:
			tmp_3 = -2.0
		else:
			tmp_3 = 0.0
		tmp_2 = tmp_3
	elif t_0:
		tmp_2 = 1.0
	else:
		tmp_2 = 0.0
	return tmp_2
function code(phi)
	t_0 = abs(1.0) > 1e-10
	tmp = 0.0
	if (abs(cos(phi)) > 1e-10)
		tmp = Float64(sin(phi) / cos(phi));
	else
		tmp = 0.0;
	end
	tmp_2 = 0.0
	if (tmp <= -4.4876674121164324e-302)
		tmp_3 = 0.0
		if (t_0)
			tmp_3 = -2.0;
		else
			tmp_3 = 0.0;
		end
		tmp_2 = tmp_3;
	elseif (t_0)
		tmp_2 = 1.0;
	else
		tmp_2 = 0.0;
	end
	return tmp_2
end
function tmp_5 = code(phi)
	t_0 = abs(1.0) > 1e-10;
	tmp = 0.0;
	if (abs(cos(phi)) > 1e-10)
		tmp = sin(phi) / cos(phi);
	else
		tmp = 0.0;
	end
	tmp_3 = 0.0;
	if (tmp <= -4.4876674121164324e-302)
		tmp_4 = 0.0;
		if (t_0)
			tmp_4 = -2.0;
		else
			tmp_4 = 0.0;
		end
		tmp_3 = tmp_4;
	elseif (t_0)
		tmp_3 = 1.0;
	else
		tmp_3 = 0.0;
	end
	tmp_5 = tmp_3;
end
code[phi_] := Block[{t$95$0 = Greater[N[Abs[1.0], $MachinePrecision], 1e-10]}, If[LessEqual[If[Greater[N[Abs[N[Cos[phi], $MachinePrecision]], $MachinePrecision], 1e-10], N[(N[Sin[phi], $MachinePrecision] / N[Cos[phi], $MachinePrecision]), $MachinePrecision], 0.0], -4.4876674121164324e-302], If[t$95$0, -2.0, 0.0], If[t$95$0, 1.0, 0.0]]]
f(phi):
	phi in [-inf, +inf]
code: THEORY
BEGIN
f(phi: real): real =
	LET t_0 = ((abs((1))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) IN
		LET tmp_2 = IF ((abs((cos(phi)))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((sin(phi)) / (cos(phi))) ELSE (0) ENDIF IN
		LET tmp_3 = IF t_0 THEN (-2) ELSE (0) ENDIF IN
		LET tmp_4 = IF t_0 THEN (1) ELSE (0) ENDIF IN
		LET tmp_1 = IF (tmp_2 <= (-44876674121164323941935398940050111183100654158813773386218306225341014857441528929141445737884927137733703146506861468093684899202099290319996952532111055742174171455826575055757083387221656642765704248826391574702956956749932774891613940442911743821098089408361951326624960760088420006545176570074686344270389383678547111228425011552383058784229513516254052163587452637008242067511390406325953866185264592388646710080051644672826780482862078064667982520581177328266275338074536851582730662199698093370399477238980479856460892633199748337482626506384762975647575500035386046373658139776154359933970795721242096002159955397294188433548352501506044917676053580880852180846669452779913337459124654214707340966670177928588003624099656008183956146240234375e-1053)) THEN tmp_3 ELSE tmp_4 ENDIF IN
	tmp_1
END code
\begin{array}{l}
t_0 := \left|1\right| > 10^{-10}\\
\mathbf{if}\;\begin{array}{l}
\mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\
\;\;\;\;\frac{\sin \phi}{\cos \phi}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array} \leq -4.4876674121164324 \cdot 10^{-302}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t\_0:\\
\;\;\;\;-2\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\

\mathbf{elif}\;t\_0:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64)) < -4.4876674121164324e-302

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{-2}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    6. Applied rewrites6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

    if -4.4876674121164324e-302 < (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64))

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\pi}{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Evaluated real constant6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 11.8% accurate, 0.9× speedup?

\[\begin{array}{l} t_0 := \left|1\right| > 10^{-10}\\ \mathbf{if}\;\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \leq -4.4876674121164324 \cdot 10^{-302}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t\_0:\\ \;\;\;\;-3\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{elif}\;t\_0:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (> (fabs 1.0) 1e-10)))
  (if (<=
       (if (> (fabs (cos phi)) 1e-10) (/ (sin phi) (cos phi)) 0.0)
       -4.4876674121164324e-302)
    (if t_0 -3.0 0.0)
    (if t_0 1.0 0.0))))
double code(double phi) {
	int t_0 = fabs(1.0) > 1e-10;
	double tmp;
	if (fabs(cos(phi)) > 1e-10) {
		tmp = sin(phi) / cos(phi);
	} else {
		tmp = 0.0;
	}
	double tmp_2;
	if (tmp <= -4.4876674121164324e-302) {
		double tmp_3;
		if (t_0) {
			tmp_3 = -3.0;
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0) {
		tmp_2 = 1.0;
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
real(8) function code(phi)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    logical :: t_0
    real(8) :: tmp
    real(8) :: tmp_1
    real(8) :: tmp_2
    real(8) :: tmp_3
    t_0 = abs(1.0d0) > 1d-10
    if (abs(cos(phi)) > 1d-10) then
        tmp = sin(phi) / cos(phi)
    else
        tmp = 0.0d0
    end if
    if (tmp <= (-4.4876674121164324d-302)) then
        if (t_0) then
            tmp_3 = -3.0d0
        else
            tmp_3 = 0.0d0
        end if
        tmp_2 = tmp_3
    else if (t_0) then
        tmp_2 = 1.0d0
    else
        tmp_2 = 0.0d0
    end if
    code = tmp_2
end function
public static double code(double phi) {
	boolean t_0 = Math.abs(1.0) > 1e-10;
	double tmp;
	if (Math.abs(Math.cos(phi)) > 1e-10) {
		tmp = Math.sin(phi) / Math.cos(phi);
	} else {
		tmp = 0.0;
	}
	double tmp_2;
	if (tmp <= -4.4876674121164324e-302) {
		double tmp_3;
		if (t_0) {
			tmp_3 = -3.0;
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0) {
		tmp_2 = 1.0;
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
def code(phi):
	t_0 = math.fabs(1.0) > 1e-10
	tmp = 0
	if math.fabs(math.cos(phi)) > 1e-10:
		tmp = math.sin(phi) / math.cos(phi)
	else:
		tmp = 0.0
	tmp_2 = 0
	if tmp <= -4.4876674121164324e-302:
		tmp_3 = 0
		if t_0:
			tmp_3 = -3.0
		else:
			tmp_3 = 0.0
		tmp_2 = tmp_3
	elif t_0:
		tmp_2 = 1.0
	else:
		tmp_2 = 0.0
	return tmp_2
function code(phi)
	t_0 = abs(1.0) > 1e-10
	tmp = 0.0
	if (abs(cos(phi)) > 1e-10)
		tmp = Float64(sin(phi) / cos(phi));
	else
		tmp = 0.0;
	end
	tmp_2 = 0.0
	if (tmp <= -4.4876674121164324e-302)
		tmp_3 = 0.0
		if (t_0)
			tmp_3 = -3.0;
		else
			tmp_3 = 0.0;
		end
		tmp_2 = tmp_3;
	elseif (t_0)
		tmp_2 = 1.0;
	else
		tmp_2 = 0.0;
	end
	return tmp_2
end
function tmp_5 = code(phi)
	t_0 = abs(1.0) > 1e-10;
	tmp = 0.0;
	if (abs(cos(phi)) > 1e-10)
		tmp = sin(phi) / cos(phi);
	else
		tmp = 0.0;
	end
	tmp_3 = 0.0;
	if (tmp <= -4.4876674121164324e-302)
		tmp_4 = 0.0;
		if (t_0)
			tmp_4 = -3.0;
		else
			tmp_4 = 0.0;
		end
		tmp_3 = tmp_4;
	elseif (t_0)
		tmp_3 = 1.0;
	else
		tmp_3 = 0.0;
	end
	tmp_5 = tmp_3;
end
code[phi_] := Block[{t$95$0 = Greater[N[Abs[1.0], $MachinePrecision], 1e-10]}, If[LessEqual[If[Greater[N[Abs[N[Cos[phi], $MachinePrecision]], $MachinePrecision], 1e-10], N[(N[Sin[phi], $MachinePrecision] / N[Cos[phi], $MachinePrecision]), $MachinePrecision], 0.0], -4.4876674121164324e-302], If[t$95$0, -3.0, 0.0], If[t$95$0, 1.0, 0.0]]]
f(phi):
	phi in [-inf, +inf]
code: THEORY
BEGIN
f(phi: real): real =
	LET t_0 = ((abs((1))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) IN
		LET tmp_2 = IF ((abs((cos(phi)))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((sin(phi)) / (cos(phi))) ELSE (0) ENDIF IN
		LET tmp_3 = IF t_0 THEN (-3) ELSE (0) ENDIF IN
		LET tmp_4 = IF t_0 THEN (1) ELSE (0) ENDIF IN
		LET tmp_1 = IF (tmp_2 <= (-44876674121164323941935398940050111183100654158813773386218306225341014857441528929141445737884927137733703146506861468093684899202099290319996952532111055742174171455826575055757083387221656642765704248826391574702956956749932774891613940442911743821098089408361951326624960760088420006545176570074686344270389383678547111228425011552383058784229513516254052163587452637008242067511390406325953866185264592388646710080051644672826780482862078064667982520581177328266275338074536851582730662199698093370399477238980479856460892633199748337482626506384762975647575500035386046373658139776154359933970795721242096002159955397294188433548352501506044917676053580880852180846669452779913337459124654214707340966670177928588003624099656008183956146240234375e-1053)) THEN tmp_3 ELSE tmp_4 ENDIF IN
	tmp_1
END code
\begin{array}{l}
t_0 := \left|1\right| > 10^{-10}\\
\mathbf{if}\;\begin{array}{l}
\mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\
\;\;\;\;\frac{\sin \phi}{\cos \phi}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array} \leq -4.4876674121164324 \cdot 10^{-302}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t\_0:\\
\;\;\;\;-3\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\

\mathbf{elif}\;t\_0:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64)) < -4.4876674121164324e-302

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{-3}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;-3\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    6. Applied rewrites6.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;-3\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

    if -4.4876674121164324e-302 < (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64))

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\pi}{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Evaluated real constant6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 10: 11.7% accurate, 0.9× speedup?

\[\begin{array}{l} t_0 := \left|1\right| > 10^{-10}\\ \mathbf{if}\;\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \leq -4.4876674121164324 \cdot 10^{-302}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t\_0:\\ \;\;\;\;-4\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{elif}\;t\_0:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (> (fabs 1.0) 1e-10)))
  (if (<=
       (if (> (fabs (cos phi)) 1e-10) (/ (sin phi) (cos phi)) 0.0)
       -4.4876674121164324e-302)
    (if t_0 -4.0 0.0)
    (if t_0 1.0 0.0))))
double code(double phi) {
	int t_0 = fabs(1.0) > 1e-10;
	double tmp;
	if (fabs(cos(phi)) > 1e-10) {
		tmp = sin(phi) / cos(phi);
	} else {
		tmp = 0.0;
	}
	double tmp_2;
	if (tmp <= -4.4876674121164324e-302) {
		double tmp_3;
		if (t_0) {
			tmp_3 = -4.0;
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0) {
		tmp_2 = 1.0;
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
real(8) function code(phi)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    logical :: t_0
    real(8) :: tmp
    real(8) :: tmp_1
    real(8) :: tmp_2
    real(8) :: tmp_3
    t_0 = abs(1.0d0) > 1d-10
    if (abs(cos(phi)) > 1d-10) then
        tmp = sin(phi) / cos(phi)
    else
        tmp = 0.0d0
    end if
    if (tmp <= (-4.4876674121164324d-302)) then
        if (t_0) then
            tmp_3 = -4.0d0
        else
            tmp_3 = 0.0d0
        end if
        tmp_2 = tmp_3
    else if (t_0) then
        tmp_2 = 1.0d0
    else
        tmp_2 = 0.0d0
    end if
    code = tmp_2
end function
public static double code(double phi) {
	boolean t_0 = Math.abs(1.0) > 1e-10;
	double tmp;
	if (Math.abs(Math.cos(phi)) > 1e-10) {
		tmp = Math.sin(phi) / Math.cos(phi);
	} else {
		tmp = 0.0;
	}
	double tmp_2;
	if (tmp <= -4.4876674121164324e-302) {
		double tmp_3;
		if (t_0) {
			tmp_3 = -4.0;
		} else {
			tmp_3 = 0.0;
		}
		tmp_2 = tmp_3;
	} else if (t_0) {
		tmp_2 = 1.0;
	} else {
		tmp_2 = 0.0;
	}
	return tmp_2;
}
def code(phi):
	t_0 = math.fabs(1.0) > 1e-10
	tmp = 0
	if math.fabs(math.cos(phi)) > 1e-10:
		tmp = math.sin(phi) / math.cos(phi)
	else:
		tmp = 0.0
	tmp_2 = 0
	if tmp <= -4.4876674121164324e-302:
		tmp_3 = 0
		if t_0:
			tmp_3 = -4.0
		else:
			tmp_3 = 0.0
		tmp_2 = tmp_3
	elif t_0:
		tmp_2 = 1.0
	else:
		tmp_2 = 0.0
	return tmp_2
function code(phi)
	t_0 = abs(1.0) > 1e-10
	tmp = 0.0
	if (abs(cos(phi)) > 1e-10)
		tmp = Float64(sin(phi) / cos(phi));
	else
		tmp = 0.0;
	end
	tmp_2 = 0.0
	if (tmp <= -4.4876674121164324e-302)
		tmp_3 = 0.0
		if (t_0)
			tmp_3 = -4.0;
		else
			tmp_3 = 0.0;
		end
		tmp_2 = tmp_3;
	elseif (t_0)
		tmp_2 = 1.0;
	else
		tmp_2 = 0.0;
	end
	return tmp_2
end
function tmp_5 = code(phi)
	t_0 = abs(1.0) > 1e-10;
	tmp = 0.0;
	if (abs(cos(phi)) > 1e-10)
		tmp = sin(phi) / cos(phi);
	else
		tmp = 0.0;
	end
	tmp_3 = 0.0;
	if (tmp <= -4.4876674121164324e-302)
		tmp_4 = 0.0;
		if (t_0)
			tmp_4 = -4.0;
		else
			tmp_4 = 0.0;
		end
		tmp_3 = tmp_4;
	elseif (t_0)
		tmp_3 = 1.0;
	else
		tmp_3 = 0.0;
	end
	tmp_5 = tmp_3;
end
code[phi_] := Block[{t$95$0 = Greater[N[Abs[1.0], $MachinePrecision], 1e-10]}, If[LessEqual[If[Greater[N[Abs[N[Cos[phi], $MachinePrecision]], $MachinePrecision], 1e-10], N[(N[Sin[phi], $MachinePrecision] / N[Cos[phi], $MachinePrecision]), $MachinePrecision], 0.0], -4.4876674121164324e-302], If[t$95$0, -4.0, 0.0], If[t$95$0, 1.0, 0.0]]]
f(phi):
	phi in [-inf, +inf]
code: THEORY
BEGIN
f(phi: real): real =
	LET t_0 = ((abs((1))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) IN
		LET tmp_2 = IF ((abs((cos(phi)))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN ((sin(phi)) / (cos(phi))) ELSE (0) ENDIF IN
		LET tmp_3 = IF t_0 THEN (-4) ELSE (0) ENDIF IN
		LET tmp_4 = IF t_0 THEN (1) ELSE (0) ENDIF IN
		LET tmp_1 = IF (tmp_2 <= (-44876674121164323941935398940050111183100654158813773386218306225341014857441528929141445737884927137733703146506861468093684899202099290319996952532111055742174171455826575055757083387221656642765704248826391574702956956749932774891613940442911743821098089408361951326624960760088420006545176570074686344270389383678547111228425011552383058784229513516254052163587452637008242067511390406325953866185264592388646710080051644672826780482862078064667982520581177328266275338074536851582730662199698093370399477238980479856460892633199748337482626506384762975647575500035386046373658139776154359933970795721242096002159955397294188433548352501506044917676053580880852180846669452779913337459124654214707340966670177928588003624099656008183956146240234375e-1053)) THEN tmp_3 ELSE tmp_4 ENDIF IN
	tmp_1
END code
\begin{array}{l}
t_0 := \left|1\right| > 10^{-10}\\
\mathbf{if}\;\begin{array}{l}
\mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\
\;\;\;\;\frac{\sin \phi}{\cos \phi}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array} \leq -4.4876674121164324 \cdot 10^{-302}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t\_0:\\
\;\;\;\;-4\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}\\

\mathbf{elif}\;t\_0:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64)) < -4.4876674121164324e-302

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{-4}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;-4\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    6. Applied rewrites6.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;-4\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

    if -4.4876674121164324e-302 < (if.f64 (>.f64 (fabs.f64 (cos.f64 phi)) #s(literal 1/10000000000 binary64)) (/.f64 (sin.f64 phi) (cos.f64 phi)) #s(literal 0 binary64))

    1. Initial program 99.8%

      \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    2. Taylor expanded in phi around 0

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    3. Applied rewrites55.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    4. Applied rewrites6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\pi}{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
    5. Evaluated real constant6.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 11: 6.9% accurate, 19.0× speedup?

\[\begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  (if (> (fabs 1.0) 1e-10) 1.0 0.0))
double code(double phi) {
	double tmp;
	if (fabs(1.0) > 1e-10) {
		tmp = 1.0;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
real(8) function code(phi)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    real(8) :: tmp
    if (abs(1.0d0) > 1d-10) then
        tmp = 1.0d0
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
public static double code(double phi) {
	double tmp;
	if (Math.abs(1.0) > 1e-10) {
		tmp = 1.0;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(phi):
	tmp = 0
	if math.fabs(1.0) > 1e-10:
		tmp = 1.0
	else:
		tmp = 0.0
	return tmp
function code(phi)
	tmp = 0.0
	if (abs(1.0) > 1e-10)
		tmp = 1.0;
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp_2 = code(phi)
	tmp = 0.0;
	if (abs(1.0) > 1e-10)
		tmp = 1.0;
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
code[phi_] := If[Greater[N[Abs[1.0], $MachinePrecision], 1e-10], 1.0, 0.0]
f(phi):
	phi in [-inf, +inf]
code: THEORY
BEGIN
f(phi: real): real =
	LET tmp = IF ((abs((1))) > (10000000000000000364321973154977415791655470655996396089904010295867919921875e-86)) THEN (1) ELSE (0) ENDIF IN
	tmp
END code
\begin{array}{l}
\mathbf{if}\;\left|1\right| > 10^{-10}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
Derivation
  1. Initial program 99.8%

    \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  2. Taylor expanded in phi around 0

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  3. Applied rewrites55.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  4. Applied rewrites6.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;\frac{\pi}{\pi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  5. Evaluated real constant6.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|1\right| > 10^{-10}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  6. Add Preprocessing

Alternative 12: 6.7% accurate, 23.0× speedup?

\[\begin{array}{l} \mathbf{if}\;\left( \pi \right)_{\text{binary32}} > 10^{-10}:\\ \;\;\;\;0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;\pi\\ \end{array} \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  (if (> (! :precision binary32 PI) 1e-10) 0.3333333333333333 PI))
double code(double phi) {
	float tmp = (float) M_PI;
	double tmp_1;
	if (tmp > 1e-10) {
		tmp_1 = 0.3333333333333333;
	} else {
		tmp_1 = (double) M_PI;
	}
	return tmp_1;
}
function code(phi)
	tmp = Float32(pi)
	tmp_1 = 0.0
	if (tmp > 1e-10)
		tmp_1 = 0.3333333333333333;
	else
		tmp_1 = pi;
	end
	return tmp_1
end
function tmp_3 = code(phi)
	tmp = single(pi);
	tmp_2 = 0.0;
	if (tmp > 1e-10)
		tmp_2 = 0.3333333333333333;
	else
		tmp_2 = pi;
	end
	tmp_3 = tmp_2;
end
\begin{array}{l}
\mathbf{if}\;\left( \pi \right)_{\text{binary32}} > 10^{-10}:\\
\;\;\;\;0.3333333333333333\\

\mathbf{else}:\\
\;\;\;\;\pi\\


\end{array}
Derivation
  1. Initial program 99.8%

    \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  2. Taylor expanded in phi around 0

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\phi \cdot \left(1 + \frac{1}{3} \cdot {\phi}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  3. Applied rewrites50.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\phi \cdot \left(1 + 0.3333333333333333 \cdot {\phi}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  4. Applied rewrites6.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left( \pi \right)_{\text{binary32}} > 10^{-10}:\\ \;\;\;\;0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;\pi\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 6.7% accurate, 110.4× speedup?

\[3.141592653589793 \]
(FPCore (phi)
  :precision binary64
  :pre TRUE
  3.141592653589793)
double code(double phi) {
	return 3.141592653589793;
}
real(8) function code(phi)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    code = 3.141592653589793d0
end function
public static double code(double phi) {
	return 3.141592653589793;
}
def code(phi):
	return 3.141592653589793
function code(phi)
	return 3.141592653589793
end
function tmp = code(phi)
	tmp = 3.141592653589793;
end
code[phi_] := 3.141592653589793
f(phi):
	phi in [-inf, +inf]
code: THEORY
BEGIN
f(phi: real): real =
	3141592653589793115997963468544185161590576171875e-48
END code
3.141592653589793
Derivation
  1. Initial program 99.8%

    \[\begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\frac{\sin \phi}{\cos \phi}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  2. Applied rewrites100.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|\cos \phi\right| > 10^{-10}:\\ \;\;\;\;\tan \phi\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
  3. Applied rewrites6.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left( \pi \right)_{\text{binary32}} > 10^{-10}:\\ \;\;\;\;\pi\\ \mathbf{else}:\\ \;\;\;\;\pi\\ \end{array} \]
  4. Evaluated real constant6.7%

    \[\leadsto 3.141592653589793 \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 2026050 +o generate:egglog
(FPCore (phi)
  :name "approx-t-guarded"
  :precision binary64
  (if (> (fabs (cos phi)) 1e-10) (/ (sin phi) (cos phi)) 0.0))