approx-inv-d-term

Percentage Accurate: 100.0% → 99.9%
Time: 1.3min
Alternatives: 12
Speedup: N/A×

Specification

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

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

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

Alternative 1: 99.9% accurate, 1.5× speedup?

\[\left(es \geq 0 \land es < 1\right) \land k0 > 0\]
\[\frac{x \cdot \sqrt{1 - es \cdot \mathsf{fma}\left(\cos \left(\phi + \phi\right), -0.5, 0.5\right)}}{k0} \]
(FPCore (phi x es k0)
  :precision binary64
  :pre (and (and (>= es 0.0) (< es 1.0)) (> k0 0.0))
  (/ (* x (sqrt (- 1.0 (* es (fma (cos (+ phi phi)) -0.5 0.5))))) k0))
double code(double phi, double x, double es, double k0) {
	return (x * sqrt((1.0 - (es * fma(cos((phi + phi)), -0.5, 0.5))))) / k0;
}
function code(phi, x, es, k0)
	return Float64(Float64(x * sqrt(Float64(1.0 - Float64(es * fma(cos(Float64(phi + phi)), -0.5, 0.5))))) / k0)
end
code[phi_, x_, es_, k0_] := N[(N[(x * N[Sqrt[N[(1.0 - N[(es * N[(N[Cos[N[(phi + phi), $MachinePrecision]], $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / k0), $MachinePrecision]
f(phi, x, es, k0):
	phi in [-inf, +inf],
	x in [-inf, +inf],
	es in [0, 1],
	k0 in [0, +inf]
code: THEORY
BEGIN
f(phi, x, es, k0: real): real =
	(x * (sqrt(((1) - (es * (((cos((phi + phi))) * (-5e-1)) + (5e-1))))))) / k0
END code
\frac{x \cdot \sqrt{1 - es \cdot \mathsf{fma}\left(\cos \left(\phi + \phi\right), -0.5, 0.5\right)}}{k0}
Derivation
  1. Initial program 100.0%

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

    \[\leadsto \frac{x \cdot \sqrt{1 - es \cdot {\sin \phi}^{2}}}{k0} \]
  3. Applied rewrites100.0%

    \[\leadsto \frac{x \cdot \sqrt{1 - es \cdot {\sin \phi}^{2}}}{k0} \]
  4. Applied rewrites99.9%

    \[\leadsto \frac{x \cdot \sqrt{1 - es \cdot \mathsf{fma}\left(\cos \left(\phi + \phi\right), -0.5, 0.5\right)}}{k0} \]
  5. Add Preprocessing

Alternative 2: 99.3% accurate, 17.8× speedup?

\[\left(es \geq 0 \land es < 1\right) \land k0 > 0\]
\[\frac{x}{k0} \]
(FPCore (phi x es k0)
  :precision binary64
  :pre (and (and (>= es 0.0) (< es 1.0)) (> k0 0.0))
  (/ x k0))
double code(double phi, double x, double es, double k0) {
	return x / k0;
}
real(8) function code(phi, x, es, k0)
use fmin_fmax_functions
    real(8), intent (in) :: phi
    real(8), intent (in) :: x
    real(8), intent (in) :: es
    real(8), intent (in) :: k0
    code = x / k0
end function
public static double code(double phi, double x, double es, double k0) {
	return x / k0;
}
def code(phi, x, es, k0):
	return x / k0
function code(phi, x, es, k0)
	return Float64(x / k0)
end
function tmp = code(phi, x, es, k0)
	tmp = x / k0;
end
code[phi_, x_, es_, k0_] := N[(x / k0), $MachinePrecision]
f(phi, x, es, k0):
	phi in [-inf, +inf],
	x in [-inf, +inf],
	es in [0, 1],
	k0 in [0, +inf]
code: THEORY
BEGIN
f(phi, x, es, k0: real): real =
	x / k0
END code
\frac{x}{k0}
Derivation
  1. Initial program 100.0%

    \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
  2. Taylor expanded in phi around 0

    \[\leadsto \frac{x}{k0} \]
  3. Applied rewrites99.3%

    \[\leadsto \frac{x}{k0} \]
  4. Add Preprocessing

Alternative 3: 17.4% accurate, 0.9× speedup?

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

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi)))))) k0) < 5e-205

    1. Initial program 100.0%

      \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
    2. Applied rewrites15.0%

      \[\leadsto 0 \]

    if 5e-205 < (/.f64 (*.f64 x (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi)))))) k0)

    1. Initial program 100.0%

      \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
    2. Applied rewrites5.9%

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

Alternative 4: 17.2% accurate, 0.9× speedup?

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

\mathbf{else}:\\
\;\;\;\;5\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi)))))) k0) < 9.9999999999999997e-155

    1. Initial program 100.0%

      \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
    2. Applied rewrites15.0%

      \[\leadsto 0 \]

    if 9.9999999999999997e-155 < (/.f64 (*.f64 x (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi)))))) k0)

    1. Initial program 100.0%

      \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
    2. Applied rewrites98.6%

      \[\leadsto \frac{x \cdot \sqrt{1 - es \cdot 0.5}}{k0} \]
    3. Applied rewrites98.3%

      \[\leadsto \left(-x\right) \cdot \left(\sqrt{\mathsf{fma}\left(-0.5, es, 1\right)} \cdot \frac{-1}{k0}\right) \]
    4. Applied rewrites3.4%

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

Alternative 5: 17.2% accurate, 0.9× speedup?

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

\mathbf{else}:\\
\;\;\;\;4\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi)))))) k0) < 9.283953195393688e-154

    1. Initial program 100.0%

      \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
    2. Applied rewrites15.0%

      \[\leadsto 0 \]

    if 9.283953195393688e-154 < (/.f64 (*.f64 x (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi)))))) k0)

    1. Initial program 100.0%

      \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
    2. Applied rewrites3.4%

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

Alternative 6: 17.2% accurate, 0.9× speedup?

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

\mathbf{else}:\\
\;\;\;\;0.00390625\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi)))))) k0) < 3.6415987898463463e-155

    1. Initial program 100.0%

      \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
    2. Applied rewrites15.0%

      \[\leadsto 0 \]

    if 3.6415987898463463e-155 < (/.f64 (*.f64 x (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 es (*.f64 (sin.f64 phi) (sin.f64 phi)))))) k0)

    1. Initial program 100.0%

      \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
    2. Applied rewrites98.6%

      \[\leadsto \frac{x \cdot \sqrt{1 - es \cdot 0.5}}{k0} \]
    3. Applied rewrites98.3%

      \[\leadsto \left(-x\right) \cdot \left(\sqrt{\mathsf{fma}\left(-0.5, es, 1\right)} \cdot \frac{-1}{k0}\right) \]
    4. Applied rewrites3.4%

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

Alternative 7: 15.0% accurate, 85.6× speedup?

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

    \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
  2. Applied rewrites15.0%

    \[\leadsto 0 \]
  3. Add Preprocessing

Alternative 8: 3.4% accurate, 85.6× speedup?

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

    \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
  2. Applied rewrites98.6%

    \[\leadsto \frac{x \cdot \sqrt{1 - es \cdot 0.5}}{k0} \]
  3. Applied rewrites98.3%

    \[\leadsto \left(-x\right) \cdot \left(\sqrt{\mathsf{fma}\left(-0.5, es, 1\right)} \cdot \frac{-1}{k0}\right) \]
  4. Applied rewrites3.4%

    \[\leadsto -0.015625 \]
  5. Add Preprocessing

Alternative 9: 3.4% accurate, 85.6× speedup?

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

    \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
  2. Applied rewrites3.4%

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

Alternative 10: 3.4% accurate, 85.6× speedup?

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

    \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
  2. Applied rewrites3.4%

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

Alternative 11: 3.4% accurate, 85.6× speedup?

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

    \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
  2. Applied rewrites3.4%

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

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

Alternative 12: 3.4% accurate, 85.6× speedup?

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

    \[\frac{x \cdot \sqrt{1 - es \cdot \left(\sin \phi \cdot \sin \phi\right)}}{k0} \]
  2. Applied rewrites98.6%

    \[\leadsto \frac{x \cdot \sqrt{1 - es \cdot 0.5}}{k0} \]
  3. Applied rewrites98.3%

    \[\leadsto \left(-x\right) \cdot \left(\sqrt{\mathsf{fma}\left(-0.5, es, 1\right)} \cdot \frac{-1}{k0}\right) \]
  4. Applied rewrites3.4%

    \[\leadsto -16 \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 2026050 +o generate:egglog
(FPCore (phi x es k0)
  :name "approx-inv-d-term"
  :precision binary64
  :pre (and (and (>= es 0.0) (< es 1.0)) (> k0 0.0))
  (/ (* x (sqrt (- 1.0 (* es (* (sin phi) (sin phi)))))) k0))