approx-scaled-lambda

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

Specification

?
\[es \geq 0 \land es < 1\]
\[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  (/ (* (cos phi) lam) (sqrt (- 1.0 (* es (* (sin phi) (sin phi)))))))
double code(double phi, double lam, double es) {
	return (cos(phi) * lam) / sqrt((1.0 - (es * (sin(phi) * sin(phi)))));
}
real(8) function code(phi, lam, es)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    real(8), intent (in) :: lam
    real(8), intent (in) :: es
    code = (cos(phi) * lam) / sqrt((1.0d0 - (es * (sin(phi) * sin(phi)))))
end function
public static double code(double phi, double lam, double es) {
	return (Math.cos(phi) * lam) / Math.sqrt((1.0 - (es * (Math.sin(phi) * Math.sin(phi)))));
}
def code(phi, lam, es):
	return (math.cos(phi) * lam) / math.sqrt((1.0 - (es * (math.sin(phi) * math.sin(phi)))))
function code(phi, lam, es)
	return Float64(Float64(cos(phi) * lam) / sqrt(Float64(1.0 - Float64(es * Float64(sin(phi) * sin(phi))))))
end
function tmp = code(phi, lam, es)
	tmp = (cos(phi) * lam) / sqrt((1.0 - (es * (sin(phi) * sin(phi)))));
end
code[phi_, lam_, es_] := N[(N[(N[Cos[phi], $MachinePrecision] * lam), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(es * N[(N[Sin[phi], $MachinePrecision] * N[Sin[phi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
f(phi, lam, es):
	phi in [-inf, +inf],
	lam in [-inf, +inf],
	es in [0, 1]
code: THEORY
BEGIN
f(phi, lam, es: real): real =
	((cos(phi)) * lam) / (sqrt(((1) - (es * ((sin(phi)) * (sin(phi)))))))
END code
\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\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 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?

\[es \geq 0 \land es < 1\]
\[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  (/ (* (cos phi) lam) (sqrt (- 1.0 (* es (* (sin phi) (sin phi)))))))
double code(double phi, double lam, double es) {
	return (cos(phi) * lam) / sqrt((1.0 - (es * (sin(phi) * sin(phi)))));
}
real(8) function code(phi, lam, es)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    real(8), intent (in) :: lam
    real(8), intent (in) :: es
    code = (cos(phi) * lam) / sqrt((1.0d0 - (es * (sin(phi) * sin(phi)))))
end function
public static double code(double phi, double lam, double es) {
	return (Math.cos(phi) * lam) / Math.sqrt((1.0 - (es * (Math.sin(phi) * Math.sin(phi)))));
}
def code(phi, lam, es):
	return (math.cos(phi) * lam) / math.sqrt((1.0 - (es * (math.sin(phi) * math.sin(phi)))))
function code(phi, lam, es)
	return Float64(Float64(cos(phi) * lam) / sqrt(Float64(1.0 - Float64(es * Float64(sin(phi) * sin(phi))))))
end
function tmp = code(phi, lam, es)
	tmp = (cos(phi) * lam) / sqrt((1.0 - (es * (sin(phi) * sin(phi)))));
end
code[phi_, lam_, es_] := N[(N[(N[Cos[phi], $MachinePrecision] * lam), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(es * N[(N[Sin[phi], $MachinePrecision] * N[Sin[phi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
f(phi, lam, es):
	phi in [-inf, +inf],
	lam in [-inf, +inf],
	es in [0, 1]
code: THEORY
BEGIN
f(phi, lam, es: real): real =
	((cos(phi)) * lam) / (sqrt(((1) - (es * ((sin(phi)) * (sin(phi)))))))
END code
\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}

Alternative 1: 99.8% accurate, 1.2× speedup?

\[es \geq 0 \land es < 1\]
\[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot {\sin \phi}^{2}}} \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  (/ (* (cos phi) lam) (sqrt (- 1.0 (* es (pow (sin phi) 2.0))))))
double code(double phi, double lam, double es) {
	return (cos(phi) * lam) / sqrt((1.0 - (es * pow(sin(phi), 2.0))));
}
real(8) function code(phi, lam, es)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    real(8), intent (in) :: lam
    real(8), intent (in) :: es
    code = (cos(phi) * lam) / sqrt((1.0d0 - (es * (sin(phi) ** 2.0d0))))
end function
public static double code(double phi, double lam, double es) {
	return (Math.cos(phi) * lam) / Math.sqrt((1.0 - (es * Math.pow(Math.sin(phi), 2.0))));
}
def code(phi, lam, es):
	return (math.cos(phi) * lam) / math.sqrt((1.0 - (es * math.pow(math.sin(phi), 2.0))))
function code(phi, lam, es)
	return Float64(Float64(cos(phi) * lam) / sqrt(Float64(1.0 - Float64(es * (sin(phi) ^ 2.0)))))
end
function tmp = code(phi, lam, es)
	tmp = (cos(phi) * lam) / sqrt((1.0 - (es * (sin(phi) ^ 2.0))));
end
code[phi_, lam_, es_] := N[(N[(N[Cos[phi], $MachinePrecision] * lam), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(es * N[Power[N[Sin[phi], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
f(phi, lam, es):
	phi in [-inf, +inf],
	lam in [-inf, +inf],
	es in [0, 1]
code: THEORY
BEGIN
f(phi, lam, es: real): real =
	((cos(phi)) * lam) / (sqrt(((1) - (es * ((sin(phi)) ^ (2))))))
END code
\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot {\sin \phi}^{2}}}
Derivation
  1. Initial program 99.8%

    \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
  2. Taylor expanded in phi around inf

    \[\leadsto \frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot {\sin \phi}^{2}}} \]
  3. Applied rewrites99.8%

    \[\leadsto \frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot {\sin \phi}^{2}}} \]
  4. Add Preprocessing

Alternative 2: 98.9% accurate, 3.2× speedup?

\[es \geq 0 \land es < 1\]
\[\cos \phi \cdot lam \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  (* (cos phi) lam))
double code(double phi, double lam, double es) {
	return cos(phi) * lam;
}
real(8) function code(phi, lam, es)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    real(8), intent (in) :: lam
    real(8), intent (in) :: es
    code = cos(phi) * lam
end function
public static double code(double phi, double lam, double es) {
	return Math.cos(phi) * lam;
}
def code(phi, lam, es):
	return math.cos(phi) * lam
function code(phi, lam, es)
	return Float64(cos(phi) * lam)
end
function tmp = code(phi, lam, es)
	tmp = cos(phi) * lam;
end
code[phi_, lam_, es_] := N[(N[Cos[phi], $MachinePrecision] * lam), $MachinePrecision]
f(phi, lam, es):
	phi in [-inf, +inf],
	lam in [-inf, +inf],
	es in [0, 1]
code: THEORY
BEGIN
f(phi, lam, es: real): real =
	(cos(phi)) * lam
END code
\cos \phi \cdot lam
Derivation
  1. Initial program 99.8%

    \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
  2. Applied rewrites97.6%

    \[\leadsto \frac{\cos \phi \cdot lam}{\sqrt{1 - \sin \pi}} \]
  3. Applied rewrites50.3%

    \[\leadsto \frac{\cos \phi \cdot lam}{e^{\phi} \cdot e^{-\phi}} \]
  4. Applied rewrites98.9%

    \[\leadsto \cos \phi \cdot lam \]
  5. Add Preprocessing

Alternative 3: 60.3% accurate, 0.7× speedup?

\[es \geq 0 \land es < 1\]
\[\mathsf{copysign}\left(1, lam\right) \cdot \begin{array}{l} \mathbf{if}\;\frac{\cos \phi \cdot \left|lam\right|}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \leq -2 \cdot 10^{-308}:\\ \;\;\;\;\frac{-0.25 \cdot \left|lam\right|}{{0.5}^{\left(\mathsf{expm1}\left(1\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\left|lam\right|\\ \end{array} \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  (*
 (copysign 1.0 lam)
 (if (<=
      (/
       (* (cos phi) (fabs lam))
       (sqrt (- 1.0 (* es (* (sin phi) (sin phi))))))
      -2e-308)
   (/ (* -0.25 (fabs lam)) (pow 0.5 (expm1 1.0)))
   (fabs lam))))
double code(double phi, double lam, double es) {
	double tmp;
	if (((cos(phi) * fabs(lam)) / sqrt((1.0 - (es * (sin(phi) * sin(phi)))))) <= -2e-308) {
		tmp = (-0.25 * fabs(lam)) / pow(0.5, expm1(1.0));
	} else {
		tmp = fabs(lam);
	}
	return copysign(1.0, lam) * tmp;
}
public static double code(double phi, double lam, double es) {
	double tmp;
	if (((Math.cos(phi) * Math.abs(lam)) / Math.sqrt((1.0 - (es * (Math.sin(phi) * Math.sin(phi)))))) <= -2e-308) {
		tmp = (-0.25 * Math.abs(lam)) / Math.pow(0.5, Math.expm1(1.0));
	} else {
		tmp = Math.abs(lam);
	}
	return Math.copySign(1.0, lam) * tmp;
}
def code(phi, lam, es):
	tmp = 0
	if ((math.cos(phi) * math.fabs(lam)) / math.sqrt((1.0 - (es * (math.sin(phi) * math.sin(phi)))))) <= -2e-308:
		tmp = (-0.25 * math.fabs(lam)) / math.pow(0.5, math.expm1(1.0))
	else:
		tmp = math.fabs(lam)
	return math.copysign(1.0, lam) * tmp
function code(phi, lam, es)
	tmp = 0.0
	if (Float64(Float64(cos(phi) * abs(lam)) / sqrt(Float64(1.0 - Float64(es * Float64(sin(phi) * sin(phi)))))) <= -2e-308)
		tmp = Float64(Float64(-0.25 * abs(lam)) / (0.5 ^ expm1(1.0)));
	else
		tmp = abs(lam);
	end
	return Float64(copysign(1.0, lam) * tmp)
end
code[phi_, lam_, es_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[lam]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[(N[Cos[phi], $MachinePrecision] * N[Abs[lam], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(es * N[(N[Sin[phi], $MachinePrecision] * N[Sin[phi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-308], N[(N[(-0.25 * N[Abs[lam], $MachinePrecision]), $MachinePrecision] / N[Power[0.5, N[(Exp[1.0] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Abs[lam], $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, lam\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{\cos \phi \cdot \left|lam\right|}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \leq -2 \cdot 10^{-308}:\\
\;\;\;\;\frac{-0.25 \cdot \left|lam\right|}{{0.5}^{\left(\mathsf{expm1}\left(1\right)\right)}}\\

\mathbf{else}:\\
\;\;\;\;\left|lam\right|\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (cos.f64 phi) lam) (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi)))))) < -1.9999999999999998e-308

    1. Initial program 99.8%

      \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
    2. Applied rewrites20.3%

      \[\leadsto \frac{\cos \phi \cdot lam}{\sqrt{0.5}} \]
    3. Applied rewrites6.5%

      \[\leadsto \frac{-0.25 \cdot lam}{\sqrt{0.5}} \]
    4. Applied rewrites6.4%

      \[\leadsto \frac{-0.25 \cdot lam}{{0.5}^{\left(\frac{0.5}{2}\right)}} \]
    5. Applied rewrites6.9%

      \[\leadsto \frac{-0.25 \cdot lam}{{0.5}^{\left(\mathsf{expm1}\left(1\right)\right)}} \]

    if -1.9999999999999998e-308 < (/.f64 (*.f64 (cos.f64 phi) lam) (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi))))))

    1. Initial program 99.8%

      \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
    2. Applied rewrites55.5%

      \[\leadsto lam \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 60.2% accurate, 0.8× speedup?

\[es \geq 0 \land es < 1\]
\[\mathsf{copysign}\left(1, lam\right) \cdot \begin{array}{l} \mathbf{if}\;\frac{\cos \phi \cdot \left|lam\right|}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \leq -2 \cdot 10^{-308}:\\ \;\;\;\;\frac{\sqrt{0.5} \cdot \left(-\left|lam\right|\right)}{\sqrt{\sqrt{0.5}}}\\ \mathbf{else}:\\ \;\;\;\;\left|lam\right|\\ \end{array} \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  (*
 (copysign 1.0 lam)
 (if (<=
      (/
       (* (cos phi) (fabs lam))
       (sqrt (- 1.0 (* es (* (sin phi) (sin phi))))))
      -2e-308)
   (/ (* (sqrt 0.5) (- (fabs lam))) (sqrt (sqrt 0.5)))
   (fabs lam))))
double code(double phi, double lam, double es) {
	double tmp;
	if (((cos(phi) * fabs(lam)) / sqrt((1.0 - (es * (sin(phi) * sin(phi)))))) <= -2e-308) {
		tmp = (sqrt(0.5) * -fabs(lam)) / sqrt(sqrt(0.5));
	} else {
		tmp = fabs(lam);
	}
	return copysign(1.0, lam) * tmp;
}
public static double code(double phi, double lam, double es) {
	double tmp;
	if (((Math.cos(phi) * Math.abs(lam)) / Math.sqrt((1.0 - (es * (Math.sin(phi) * Math.sin(phi)))))) <= -2e-308) {
		tmp = (Math.sqrt(0.5) * -Math.abs(lam)) / Math.sqrt(Math.sqrt(0.5));
	} else {
		tmp = Math.abs(lam);
	}
	return Math.copySign(1.0, lam) * tmp;
}
def code(phi, lam, es):
	tmp = 0
	if ((math.cos(phi) * math.fabs(lam)) / math.sqrt((1.0 - (es * (math.sin(phi) * math.sin(phi)))))) <= -2e-308:
		tmp = (math.sqrt(0.5) * -math.fabs(lam)) / math.sqrt(math.sqrt(0.5))
	else:
		tmp = math.fabs(lam)
	return math.copysign(1.0, lam) * tmp
function code(phi, lam, es)
	tmp = 0.0
	if (Float64(Float64(cos(phi) * abs(lam)) / sqrt(Float64(1.0 - Float64(es * Float64(sin(phi) * sin(phi)))))) <= -2e-308)
		tmp = Float64(Float64(sqrt(0.5) * Float64(-abs(lam))) / sqrt(sqrt(0.5)));
	else
		tmp = abs(lam);
	end
	return Float64(copysign(1.0, lam) * tmp)
end
function tmp_2 = code(phi, lam, es)
	tmp = 0.0;
	if (((cos(phi) * abs(lam)) / sqrt((1.0 - (es * (sin(phi) * sin(phi)))))) <= -2e-308)
		tmp = (sqrt(0.5) * -abs(lam)) / sqrt(sqrt(0.5));
	else
		tmp = abs(lam);
	end
	tmp_2 = (sign(lam) * abs(1.0)) * tmp;
end
code[phi_, lam_, es_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[lam]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[(N[Cos[phi], $MachinePrecision] * N[Abs[lam], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(es * N[(N[Sin[phi], $MachinePrecision] * N[Sin[phi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-308], N[(N[(N[Sqrt[0.5], $MachinePrecision] * (-N[Abs[lam], $MachinePrecision])), $MachinePrecision] / N[Sqrt[N[Sqrt[0.5], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Abs[lam], $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, lam\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{\cos \phi \cdot \left|lam\right|}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \leq -2 \cdot 10^{-308}:\\
\;\;\;\;\frac{\sqrt{0.5} \cdot \left(-\left|lam\right|\right)}{\sqrt{\sqrt{0.5}}}\\

\mathbf{else}:\\
\;\;\;\;\left|lam\right|\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (cos.f64 phi) lam) (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi)))))) < -1.9999999999999998e-308

    1. Initial program 99.8%

      \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
    2. Applied rewrites20.3%

      \[\leadsto \frac{\cos \phi \cdot lam}{\sqrt{0.5}} \]
    3. Applied rewrites15.9%

      \[\leadsto \frac{0.5 \cdot lam}{\sqrt{0.5}} \]
    4. Applied rewrites16.8%

      \[\leadsto \frac{\sqrt{0.5} \cdot lam}{\sqrt{\sqrt{0.5}}} \]
    5. Applied rewrites6.9%

      \[\leadsto \frac{\sqrt{0.5} \cdot \left(-lam\right)}{\sqrt{\sqrt{0.5}}} \]

    if -1.9999999999999998e-308 < (/.f64 (*.f64 (cos.f64 phi) lam) (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi))))))

    1. Initial program 99.8%

      \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
    2. Applied rewrites55.5%

      \[\leadsto lam \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 60.2% accurate, 0.9× speedup?

\[es \geq 0 \land es < 1\]
\[\mathsf{copysign}\left(1, lam\right) \cdot \begin{array}{l} \mathbf{if}\;\frac{\cos \phi \cdot \left|lam\right|}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \leq -2 \cdot 10^{-308}:\\ \;\;\;\;-0.7071067811865475 \cdot \left|lam\right|\\ \mathbf{else}:\\ \;\;\;\;\left|lam\right|\\ \end{array} \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  (*
 (copysign 1.0 lam)
 (if (<=
      (/
       (* (cos phi) (fabs lam))
       (sqrt (- 1.0 (* es (* (sin phi) (sin phi))))))
      -2e-308)
   (* -0.7071067811865475 (fabs lam))
   (fabs lam))))
double code(double phi, double lam, double es) {
	double tmp;
	if (((cos(phi) * fabs(lam)) / sqrt((1.0 - (es * (sin(phi) * sin(phi)))))) <= -2e-308) {
		tmp = -0.7071067811865475 * fabs(lam);
	} else {
		tmp = fabs(lam);
	}
	return copysign(1.0, lam) * tmp;
}
public static double code(double phi, double lam, double es) {
	double tmp;
	if (((Math.cos(phi) * Math.abs(lam)) / Math.sqrt((1.0 - (es * (Math.sin(phi) * Math.sin(phi)))))) <= -2e-308) {
		tmp = -0.7071067811865475 * Math.abs(lam);
	} else {
		tmp = Math.abs(lam);
	}
	return Math.copySign(1.0, lam) * tmp;
}
def code(phi, lam, es):
	tmp = 0
	if ((math.cos(phi) * math.fabs(lam)) / math.sqrt((1.0 - (es * (math.sin(phi) * math.sin(phi)))))) <= -2e-308:
		tmp = -0.7071067811865475 * math.fabs(lam)
	else:
		tmp = math.fabs(lam)
	return math.copysign(1.0, lam) * tmp
function code(phi, lam, es)
	tmp = 0.0
	if (Float64(Float64(cos(phi) * abs(lam)) / sqrt(Float64(1.0 - Float64(es * Float64(sin(phi) * sin(phi)))))) <= -2e-308)
		tmp = Float64(-0.7071067811865475 * abs(lam));
	else
		tmp = abs(lam);
	end
	return Float64(copysign(1.0, lam) * tmp)
end
function tmp_2 = code(phi, lam, es)
	tmp = 0.0;
	if (((cos(phi) * abs(lam)) / sqrt((1.0 - (es * (sin(phi) * sin(phi)))))) <= -2e-308)
		tmp = -0.7071067811865475 * abs(lam);
	else
		tmp = abs(lam);
	end
	tmp_2 = (sign(lam) * abs(1.0)) * tmp;
end
code[phi_, lam_, es_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[lam]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[(N[Cos[phi], $MachinePrecision] * N[Abs[lam], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(es * N[(N[Sin[phi], $MachinePrecision] * N[Sin[phi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-308], N[(-0.7071067811865475 * N[Abs[lam], $MachinePrecision]), $MachinePrecision], N[Abs[lam], $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, lam\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{\cos \phi \cdot \left|lam\right|}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \leq -2 \cdot 10^{-308}:\\
\;\;\;\;-0.7071067811865475 \cdot \left|lam\right|\\

\mathbf{else}:\\
\;\;\;\;\left|lam\right|\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (cos.f64 phi) lam) (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi)))))) < -1.9999999999999998e-308

    1. Initial program 99.8%

      \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
    2. Applied rewrites20.3%

      \[\leadsto \frac{\cos \phi \cdot lam}{\sqrt{0.5}} \]
    3. Applied rewrites6.9%

      \[\leadsto \frac{-0.5 \cdot lam}{\sqrt{0.5}} \]
    4. Evaluated real constant6.9%

      \[\leadsto \frac{-0.5 \cdot lam}{0.7071067811865476} \]
    5. Taylor expanded in lam around 0

      \[\leadsto \frac{-4503599627370496}{6369051672525773} \cdot lam \]
    6. Applied rewrites6.9%

      \[\leadsto -0.7071067811865475 \cdot lam \]

    if -1.9999999999999998e-308 < (/.f64 (*.f64 (cos.f64 phi) lam) (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi))))))

    1. Initial program 99.8%

      \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
    2. Applied rewrites55.5%

      \[\leadsto lam \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 60.1% accurate, 0.9× speedup?

\[es \geq 0 \land es < 1\]
\[\mathsf{copysign}\left(1, lam\right) \cdot \begin{array}{l} \mathbf{if}\;\frac{\cos \phi \cdot \left|lam\right|}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \leq -2 \cdot 10^{-308}:\\ \;\;\;\;\frac{\sqrt{0.5} \cdot \left|lam\right|}{-1}\\ \mathbf{else}:\\ \;\;\;\;\left|lam\right|\\ \end{array} \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  (*
 (copysign 1.0 lam)
 (if (<=
      (/
       (* (cos phi) (fabs lam))
       (sqrt (- 1.0 (* es (* (sin phi) (sin phi))))))
      -2e-308)
   (/ (* (sqrt 0.5) (fabs lam)) -1.0)
   (fabs lam))))
double code(double phi, double lam, double es) {
	double tmp;
	if (((cos(phi) * fabs(lam)) / sqrt((1.0 - (es * (sin(phi) * sin(phi)))))) <= -2e-308) {
		tmp = (sqrt(0.5) * fabs(lam)) / -1.0;
	} else {
		tmp = fabs(lam);
	}
	return copysign(1.0, lam) * tmp;
}
public static double code(double phi, double lam, double es) {
	double tmp;
	if (((Math.cos(phi) * Math.abs(lam)) / Math.sqrt((1.0 - (es * (Math.sin(phi) * Math.sin(phi)))))) <= -2e-308) {
		tmp = (Math.sqrt(0.5) * Math.abs(lam)) / -1.0;
	} else {
		tmp = Math.abs(lam);
	}
	return Math.copySign(1.0, lam) * tmp;
}
def code(phi, lam, es):
	tmp = 0
	if ((math.cos(phi) * math.fabs(lam)) / math.sqrt((1.0 - (es * (math.sin(phi) * math.sin(phi)))))) <= -2e-308:
		tmp = (math.sqrt(0.5) * math.fabs(lam)) / -1.0
	else:
		tmp = math.fabs(lam)
	return math.copysign(1.0, lam) * tmp
function code(phi, lam, es)
	tmp = 0.0
	if (Float64(Float64(cos(phi) * abs(lam)) / sqrt(Float64(1.0 - Float64(es * Float64(sin(phi) * sin(phi)))))) <= -2e-308)
		tmp = Float64(Float64(sqrt(0.5) * abs(lam)) / -1.0);
	else
		tmp = abs(lam);
	end
	return Float64(copysign(1.0, lam) * tmp)
end
function tmp_2 = code(phi, lam, es)
	tmp = 0.0;
	if (((cos(phi) * abs(lam)) / sqrt((1.0 - (es * (sin(phi) * sin(phi)))))) <= -2e-308)
		tmp = (sqrt(0.5) * abs(lam)) / -1.0;
	else
		tmp = abs(lam);
	end
	tmp_2 = (sign(lam) * abs(1.0)) * tmp;
end
code[phi_, lam_, es_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[lam]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[(N[Cos[phi], $MachinePrecision] * N[Abs[lam], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(es * N[(N[Sin[phi], $MachinePrecision] * N[Sin[phi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-308], N[(N[(N[Sqrt[0.5], $MachinePrecision] * N[Abs[lam], $MachinePrecision]), $MachinePrecision] / -1.0), $MachinePrecision], N[Abs[lam], $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, lam\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{\cos \phi \cdot \left|lam\right|}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \leq -2 \cdot 10^{-308}:\\
\;\;\;\;\frac{\sqrt{0.5} \cdot \left|lam\right|}{-1}\\

\mathbf{else}:\\
\;\;\;\;\left|lam\right|\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (cos.f64 phi) lam) (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi)))))) < -1.9999999999999998e-308

    1. Initial program 99.8%

      \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
    2. Applied rewrites20.3%

      \[\leadsto \frac{\cos \phi \cdot lam}{\sqrt{0.5}} \]
    3. Applied rewrites15.9%

      \[\leadsto \frac{0.5 \cdot lam}{\sqrt{0.5}} \]
    4. Applied rewrites16.8%

      \[\leadsto \frac{\sqrt{0.5} \cdot lam}{\sqrt{\sqrt{0.5}}} \]
    5. Applied rewrites6.9%

      \[\leadsto \frac{\sqrt{0.5} \cdot lam}{-1} \]

    if -1.9999999999999998e-308 < (/.f64 (*.f64 (cos.f64 phi) lam) (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi))))))

    1. Initial program 99.8%

      \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
    2. Applied rewrites55.5%

      \[\leadsto lam \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 60.1% accurate, 0.9× speedup?

\[es \geq 0 \land es < 1\]
\[\mathsf{copysign}\left(1, lam\right) \cdot \begin{array}{l} \mathbf{if}\;\frac{\cos \phi \cdot \left|lam\right|}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \leq -2 \cdot 10^{-308}:\\ \;\;\;\;-\left|lam\right|\\ \mathbf{else}:\\ \;\;\;\;\left|lam\right|\\ \end{array} \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  (*
 (copysign 1.0 lam)
 (if (<=
      (/
       (* (cos phi) (fabs lam))
       (sqrt (- 1.0 (* es (* (sin phi) (sin phi))))))
      -2e-308)
   (- (fabs lam))
   (fabs lam))))
double code(double phi, double lam, double es) {
	double tmp;
	if (((cos(phi) * fabs(lam)) / sqrt((1.0 - (es * (sin(phi) * sin(phi)))))) <= -2e-308) {
		tmp = -fabs(lam);
	} else {
		tmp = fabs(lam);
	}
	return copysign(1.0, lam) * tmp;
}
public static double code(double phi, double lam, double es) {
	double tmp;
	if (((Math.cos(phi) * Math.abs(lam)) / Math.sqrt((1.0 - (es * (Math.sin(phi) * Math.sin(phi)))))) <= -2e-308) {
		tmp = -Math.abs(lam);
	} else {
		tmp = Math.abs(lam);
	}
	return Math.copySign(1.0, lam) * tmp;
}
def code(phi, lam, es):
	tmp = 0
	if ((math.cos(phi) * math.fabs(lam)) / math.sqrt((1.0 - (es * (math.sin(phi) * math.sin(phi)))))) <= -2e-308:
		tmp = -math.fabs(lam)
	else:
		tmp = math.fabs(lam)
	return math.copysign(1.0, lam) * tmp
function code(phi, lam, es)
	tmp = 0.0
	if (Float64(Float64(cos(phi) * abs(lam)) / sqrt(Float64(1.0 - Float64(es * Float64(sin(phi) * sin(phi)))))) <= -2e-308)
		tmp = Float64(-abs(lam));
	else
		tmp = abs(lam);
	end
	return Float64(copysign(1.0, lam) * tmp)
end
function tmp_2 = code(phi, lam, es)
	tmp = 0.0;
	if (((cos(phi) * abs(lam)) / sqrt((1.0 - (es * (sin(phi) * sin(phi)))))) <= -2e-308)
		tmp = -abs(lam);
	else
		tmp = abs(lam);
	end
	tmp_2 = (sign(lam) * abs(1.0)) * tmp;
end
code[phi_, lam_, es_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[lam]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[(N[Cos[phi], $MachinePrecision] * N[Abs[lam], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(1.0 - N[(es * N[(N[Sin[phi], $MachinePrecision] * N[Sin[phi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2e-308], (-N[Abs[lam], $MachinePrecision]), N[Abs[lam], $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, lam\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{\cos \phi \cdot \left|lam\right|}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \leq -2 \cdot 10^{-308}:\\
\;\;\;\;-\left|lam\right|\\

\mathbf{else}:\\
\;\;\;\;\left|lam\right|\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (cos.f64 phi) lam) (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi)))))) < -1.9999999999999998e-308

    1. Initial program 99.8%

      \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
    2. Applied rewrites3.5%

      \[\leadsto -\pi \]
    3. Applied rewrites7.0%

      \[\leadsto -lam \]

    if -1.9999999999999998e-308 < (/.f64 (*.f64 (cos.f64 phi) lam) (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi))))))

    1. Initial program 99.8%

      \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
    2. Applied rewrites55.5%

      \[\leadsto lam \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 55.5% accurate, 119.2× speedup?

\[es \geq 0 \land es < 1\]
\[lam \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  lam)
double code(double phi, double lam, double es) {
	return lam;
}
real(8) function code(phi, lam, es)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    real(8), intent (in) :: lam
    real(8), intent (in) :: es
    code = lam
end function
public static double code(double phi, double lam, double es) {
	return lam;
}
def code(phi, lam, es):
	return lam
function code(phi, lam, es)
	return lam
end
function tmp = code(phi, lam, es)
	tmp = lam;
end
code[phi_, lam_, es_] := lam
f(phi, lam, es):
	phi in [-inf, +inf],
	lam in [-inf, +inf],
	es in [0, 1]
code: THEORY
BEGIN
f(phi, lam, es: real): real =
	lam
END code
lam
Derivation
  1. Initial program 99.8%

    \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
  2. Applied rewrites55.5%

    \[\leadsto lam \]
  3. Add Preprocessing

Alternative 9: 4.5% accurate, 18.1× speedup?

\[es \geq 0 \land es < 1\]
\[\mathsf{copysign}\left(1, lam\right) \cdot 0.25 \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  (* (copysign 1.0 lam) 0.25))
double code(double phi, double lam, double es) {
	return copysign(1.0, lam) * 0.25;
}
public static double code(double phi, double lam, double es) {
	return Math.copySign(1.0, lam) * 0.25;
}
def code(phi, lam, es):
	return math.copysign(1.0, lam) * 0.25
function code(phi, lam, es)
	return Float64(copysign(1.0, lam) * 0.25)
end
function tmp = code(phi, lam, es)
	tmp = (sign(lam) * abs(1.0)) * 0.25;
end
code[phi_, lam_, es_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[lam]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * 0.25), $MachinePrecision]
\mathsf{copysign}\left(1, lam\right) \cdot 0.25
Derivation
  1. Initial program 99.8%

    \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
  2. Applied rewrites3.5%

    \[\leadsto 0.25 \]
  3. Add Preprocessing

Alternative 10: 3.9% accurate, 119.2× speedup?

\[es \geq 0 \land es < 1\]
\[0 \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  0.0)
double code(double phi, double lam, double es) {
	return 0.0;
}
real(8) function code(phi, lam, es)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    real(8), intent (in) :: lam
    real(8), intent (in) :: es
    code = 0.0d0
end function
public static double code(double phi, double lam, double es) {
	return 0.0;
}
def code(phi, lam, es):
	return 0.0
function code(phi, lam, es)
	return 0.0
end
function tmp = code(phi, lam, es)
	tmp = 0.0;
end
code[phi_, lam_, es_] := 0.0
f(phi, lam, es):
	phi in [-inf, +inf],
	lam in [-inf, +inf],
	es in [0, 1]
code: THEORY
BEGIN
f(phi, lam, es: real): real =
	0
END code
0
Derivation
  1. Initial program 99.8%

    \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
  2. Applied rewrites3.9%

    \[\leadsto 0 \]
  3. Add Preprocessing

Alternative 11: 3.5% accurate, 119.2× speedup?

\[es \geq 0 \land es < 1\]
\[-0.5 \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  -0.5)
double code(double phi, double lam, double es) {
	return -0.5;
}
real(8) function code(phi, lam, es)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    real(8), intent (in) :: lam
    real(8), intent (in) :: es
    code = -0.5d0
end function
public static double code(double phi, double lam, double es) {
	return -0.5;
}
def code(phi, lam, es):
	return -0.5
function code(phi, lam, es)
	return -0.5
end
function tmp = code(phi, lam, es)
	tmp = -0.5;
end
code[phi_, lam_, es_] := -0.5
f(phi, lam, es):
	phi in [-inf, +inf],
	lam in [-inf, +inf],
	es in [0, 1]
code: THEORY
BEGIN
f(phi, lam, es: real): real =
	-5e-1
END code
-0.5
Derivation
  1. Initial program 99.8%

    \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
  2. Applied rewrites3.5%

    \[\leadsto -0.5 \]
  3. Add Preprocessing

Alternative 12: 3.5% accurate, 119.2× speedup?

\[es \geq 0 \land es < 1\]
\[-2 \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  -2.0)
double code(double phi, double lam, double es) {
	return -2.0;
}
real(8) function code(phi, lam, es)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    real(8), intent (in) :: lam
    real(8), intent (in) :: es
    code = -2.0d0
end function
public static double code(double phi, double lam, double es) {
	return -2.0;
}
def code(phi, lam, es):
	return -2.0
function code(phi, lam, es)
	return -2.0
end
function tmp = code(phi, lam, es)
	tmp = -2.0;
end
code[phi_, lam_, es_] := -2.0
f(phi, lam, es):
	phi in [-inf, +inf],
	lam in [-inf, +inf],
	es in [0, 1]
code: THEORY
BEGIN
f(phi, lam, es: real): real =
	-2
END code
-2
Derivation
  1. Initial program 99.8%

    \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
  2. Applied rewrites3.5%

    \[\leadsto -2 \]
  3. Add Preprocessing

Alternative 13: 3.5% accurate, 119.2× speedup?

\[es \geq 0 \land es < 1\]
\[-3.141592653589793 \]
(FPCore (phi lam es)
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  -3.141592653589793)
double code(double phi, double lam, double es) {
	return -3.141592653589793;
}
real(8) function code(phi, lam, es)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    real(8), intent (in) :: lam
    real(8), intent (in) :: es
    code = -3.141592653589793d0
end function
public static double code(double phi, double lam, double es) {
	return -3.141592653589793;
}
def code(phi, lam, es):
	return -3.141592653589793
function code(phi, lam, es)
	return -3.141592653589793
end
function tmp = code(phi, lam, es)
	tmp = -3.141592653589793;
end
code[phi_, lam_, es_] := -3.141592653589793
f(phi, lam, es):
	phi in [-inf, +inf],
	lam in [-inf, +inf],
	es in [0, 1]
code: THEORY
BEGIN
f(phi, lam, es: real): real =
	-3141592653589793115997963468544185161590576171875e-48
END code
-3.141592653589793
Derivation
  1. Initial program 99.8%

    \[\frac{\cos \phi \cdot lam}{\sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}} \]
  2. Applied rewrites3.5%

    \[\leadsto -\pi \]
  3. Evaluated real constant3.5%

    \[\leadsto -3.141592653589793 \]
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2026050 +o generate:egglog
(FPCore (phi lam es)
  :name "approx-scaled-lambda"
  :precision binary64
  :pre (and (>= es 0.0) (< es 1.0))
  (/ (* (cos phi) lam) (sqrt (- 1.0 (* es (* (sin phi) (sin phi)))))))