init-kR

Percentage Accurate: 99.6% → 99.6%
Time: 1.9min
Alternatives: 9
Speedup: 1.0×

Specification

?
\[\left(\left(k0 > 0 \land one\_es > 0\right) \land ecc > 0\right) \land ecc < 1\]
\[\begin{array}{l} t_0 := ecc \cdot \sin phi0\\ \frac{k0 \cdot \sqrt{one\_es}}{1 - t\_0 \cdot t\_0} \end{array} \]
(FPCore (k0 one_es ecc phi0)
  :precision binary64
  :pre (and (and (and (> k0 0.0) (> one_es 0.0)) (> ecc 0.0))
     (< ecc 1.0))
  (let* ((t_0 (* ecc (sin phi0))))
  (/ (* k0 (sqrt one_es)) (- 1.0 (* t_0 t_0)))))
double code(double k0, double one_es, double ecc, double phi0) {
	double t_0 = ecc * sin(phi0);
	return (k0 * sqrt(one_es)) / (1.0 - (t_0 * t_0));
}
real(8) function code(k0, one_es, ecc, phi0)
use fmin_fmax_functions
    real(8), intent (in) :: k0
    real(8), intent (in) :: one_es
    real(8), intent (in) :: ecc
    real(8), intent (in) :: phi0
    real(8) :: t_0
    t_0 = ecc * sin(phi0)
    code = (k0 * sqrt(one_es)) / (1.0d0 - (t_0 * t_0))
end function
public static double code(double k0, double one_es, double ecc, double phi0) {
	double t_0 = ecc * Math.sin(phi0);
	return (k0 * Math.sqrt(one_es)) / (1.0 - (t_0 * t_0));
}
def code(k0, one_es, ecc, phi0):
	t_0 = ecc * math.sin(phi0)
	return (k0 * math.sqrt(one_es)) / (1.0 - (t_0 * t_0))
function code(k0, one_es, ecc, phi0)
	t_0 = Float64(ecc * sin(phi0))
	return Float64(Float64(k0 * sqrt(one_es)) / Float64(1.0 - Float64(t_0 * t_0)))
end
function tmp = code(k0, one_es, ecc, phi0)
	t_0 = ecc * sin(phi0);
	tmp = (k0 * sqrt(one_es)) / (1.0 - (t_0 * t_0));
end
code[k0_, one$95$es_, ecc_, phi0_] := Block[{t$95$0 = N[(ecc * N[Sin[phi0], $MachinePrecision]), $MachinePrecision]}, N[(N[(k0 * N[Sqrt[one$95$es], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
f(k0, one_es, ecc, phi0):
	k0 in [0, +inf],
	one_es in [0, +inf],
	ecc in [0, 1],
	phi0 in [-inf, +inf]
code: THEORY
BEGIN
f(k0, one_es, ecc, phi0: real): real =
	LET t_0 = (ecc * (sin(phi0))) IN
	(k0 * (sqrt(one_es))) / ((1) - (t_0 * t_0))
END code
\begin{array}{l}
t_0 := ecc \cdot \sin phi0\\
\frac{k0 \cdot \sqrt{one\_es}}{1 - t\_0 \cdot t\_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 9 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.6% accurate, 1.0× speedup?

\[\left(\left(k0 > 0 \land one\_es > 0\right) \land ecc > 0\right) \land ecc < 1\]
\[\begin{array}{l} t_0 := ecc \cdot \sin phi0\\ \frac{k0 \cdot \sqrt{one\_es}}{1 - t\_0 \cdot t\_0} \end{array} \]
(FPCore (k0 one_es ecc phi0)
  :precision binary64
  :pre (and (and (and (> k0 0.0) (> one_es 0.0)) (> ecc 0.0))
     (< ecc 1.0))
  (let* ((t_0 (* ecc (sin phi0))))
  (/ (* k0 (sqrt one_es)) (- 1.0 (* t_0 t_0)))))
double code(double k0, double one_es, double ecc, double phi0) {
	double t_0 = ecc * sin(phi0);
	return (k0 * sqrt(one_es)) / (1.0 - (t_0 * t_0));
}
real(8) function code(k0, one_es, ecc, phi0)
use fmin_fmax_functions
    real(8), intent (in) :: k0
    real(8), intent (in) :: one_es
    real(8), intent (in) :: ecc
    real(8), intent (in) :: phi0
    real(8) :: t_0
    t_0 = ecc * sin(phi0)
    code = (k0 * sqrt(one_es)) / (1.0d0 - (t_0 * t_0))
end function
public static double code(double k0, double one_es, double ecc, double phi0) {
	double t_0 = ecc * Math.sin(phi0);
	return (k0 * Math.sqrt(one_es)) / (1.0 - (t_0 * t_0));
}
def code(k0, one_es, ecc, phi0):
	t_0 = ecc * math.sin(phi0)
	return (k0 * math.sqrt(one_es)) / (1.0 - (t_0 * t_0))
function code(k0, one_es, ecc, phi0)
	t_0 = Float64(ecc * sin(phi0))
	return Float64(Float64(k0 * sqrt(one_es)) / Float64(1.0 - Float64(t_0 * t_0)))
end
function tmp = code(k0, one_es, ecc, phi0)
	t_0 = ecc * sin(phi0);
	tmp = (k0 * sqrt(one_es)) / (1.0 - (t_0 * t_0));
end
code[k0_, one$95$es_, ecc_, phi0_] := Block[{t$95$0 = N[(ecc * N[Sin[phi0], $MachinePrecision]), $MachinePrecision]}, N[(N[(k0 * N[Sqrt[one$95$es], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
f(k0, one_es, ecc, phi0):
	k0 in [0, +inf],
	one_es in [0, +inf],
	ecc in [0, 1],
	phi0 in [-inf, +inf]
code: THEORY
BEGIN
f(k0, one_es, ecc, phi0: real): real =
	LET t_0 = (ecc * (sin(phi0))) IN
	(k0 * (sqrt(one_es))) / ((1) - (t_0 * t_0))
END code
\begin{array}{l}
t_0 := ecc \cdot \sin phi0\\
\frac{k0 \cdot \sqrt{one\_es}}{1 - t\_0 \cdot t\_0}
\end{array}

Alternative 1: 99.6% accurate, 1.5× speedup?

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

    \[\frac{k0 \cdot \sqrt{one\_es}}{1 - \left(ecc \cdot \sin phi0\right) \cdot \left(ecc \cdot \sin phi0\right)} \]
  2. Applied rewrites99.6%

    \[\leadsto \frac{\sqrt{one\_es}}{\mathsf{fma}\left(\mathsf{fma}\left(\cos \left(phi0 + phi0\right), 0.5, -0.5\right), ecc \cdot ecc, 1\right)} \cdot k0 \]
  3. Add Preprocessing

Alternative 2: 99.2% accurate, 8.4× speedup?

\[\left(\left(k0 > 0 \land one\_es > 0\right) \land ecc > 0\right) \land ecc < 1\]
\[\frac{k0}{\sqrt{\frac{1}{one\_es}}} \]
(FPCore (k0 one_es ecc phi0)
  :precision binary64
  :pre (and (and (and (> k0 0.0) (> one_es 0.0)) (> ecc 0.0))
     (< ecc 1.0))
  (/ k0 (sqrt (/ 1.0 one_es))))
double code(double k0, double one_es, double ecc, double phi0) {
	return k0 / sqrt((1.0 / one_es));
}
real(8) function code(k0, one_es, ecc, phi0)
use fmin_fmax_functions
    real(8), intent (in) :: k0
    real(8), intent (in) :: one_es
    real(8), intent (in) :: ecc
    real(8), intent (in) :: phi0
    code = k0 / sqrt((1.0d0 / one_es))
end function
public static double code(double k0, double one_es, double ecc, double phi0) {
	return k0 / Math.sqrt((1.0 / one_es));
}
def code(k0, one_es, ecc, phi0):
	return k0 / math.sqrt((1.0 / one_es))
function code(k0, one_es, ecc, phi0)
	return Float64(k0 / sqrt(Float64(1.0 / one_es)))
end
function tmp = code(k0, one_es, ecc, phi0)
	tmp = k0 / sqrt((1.0 / one_es));
end
code[k0_, one$95$es_, ecc_, phi0_] := N[(k0 / N[Sqrt[N[(1.0 / one$95$es), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
f(k0, one_es, ecc, phi0):
	k0 in [0, +inf],
	one_es in [0, +inf],
	ecc in [0, 1],
	phi0 in [-inf, +inf]
code: THEORY
BEGIN
f(k0, one_es, ecc, phi0: real): real =
	k0 / (sqrt(((1) / one_es)))
END code
\frac{k0}{\sqrt{\frac{1}{one\_es}}}
Derivation
  1. Initial program 99.6%

    \[\frac{k0 \cdot \sqrt{one\_es}}{1 - \left(ecc \cdot \sin phi0\right) \cdot \left(ecc \cdot \sin phi0\right)} \]
  2. Taylor expanded in one_es around inf

    \[\leadsto \frac{k0 \cdot \left(one\_es \cdot \sqrt{\frac{1}{one\_es}}\right)}{1 - {ecc}^{2} \cdot {\sin phi0}^{2}} \]
  3. Applied rewrites99.5%

    \[\leadsto \frac{k0 \cdot \left(one\_es \cdot \sqrt{\frac{1}{one\_es}}\right)}{1 - {ecc}^{2} \cdot {\sin phi0}^{2}} \]
  4. Applied rewrites98.3%

    \[\leadsto \frac{k0 \cdot \left(one\_es \cdot \sqrt{\frac{1}{one\_es}}\right)}{1 - \sin \left(\pi \cdot 1\right)} \]
  5. Applied rewrites88.0%

    \[\leadsto \frac{one\_es \cdot k0}{\sqrt{one\_es}} \]
  6. Taylor expanded in one_es around inf

    \[\leadsto \frac{k0}{\sqrt{\frac{1}{one\_es}}} \]
  7. Applied rewrites99.2%

    \[\leadsto \frac{k0}{\sqrt{\frac{1}{one\_es}}} \]
  8. Add Preprocessing

Alternative 3: 99.2% accurate, 14.8× speedup?

\[\left(\left(k0 > 0 \land one\_es > 0\right) \land ecc > 0\right) \land ecc < 1\]
\[\sqrt{one\_es} \cdot k0 \]
(FPCore (k0 one_es ecc phi0)
  :precision binary64
  :pre (and (and (and (> k0 0.0) (> one_es 0.0)) (> ecc 0.0))
     (< ecc 1.0))
  (* (sqrt one_es) k0))
double code(double k0, double one_es, double ecc, double phi0) {
	return sqrt(one_es) * k0;
}
real(8) function code(k0, one_es, ecc, phi0)
use fmin_fmax_functions
    real(8), intent (in) :: k0
    real(8), intent (in) :: one_es
    real(8), intent (in) :: ecc
    real(8), intent (in) :: phi0
    code = sqrt(one_es) * k0
end function
public static double code(double k0, double one_es, double ecc, double phi0) {
	return Math.sqrt(one_es) * k0;
}
def code(k0, one_es, ecc, phi0):
	return math.sqrt(one_es) * k0
function code(k0, one_es, ecc, phi0)
	return Float64(sqrt(one_es) * k0)
end
function tmp = code(k0, one_es, ecc, phi0)
	tmp = sqrt(one_es) * k0;
end
code[k0_, one$95$es_, ecc_, phi0_] := N[(N[Sqrt[one$95$es], $MachinePrecision] * k0), $MachinePrecision]
f(k0, one_es, ecc, phi0):
	k0 in [0, +inf],
	one_es in [0, +inf],
	ecc in [0, 1],
	phi0 in [-inf, +inf]
code: THEORY
BEGIN
f(k0, one_es, ecc, phi0: real): real =
	(sqrt(one_es)) * k0
END code
\sqrt{one\_es} \cdot k0
Derivation
  1. Initial program 99.6%

    \[\frac{k0 \cdot \sqrt{one\_es}}{1 - \left(ecc \cdot \sin phi0\right) \cdot \left(ecc \cdot \sin phi0\right)} \]
  2. Applied rewrites99.6%

    \[\leadsto \frac{\sqrt{one\_es}}{\mathsf{fma}\left(\mathsf{fma}\left(\cos \left(phi0 + phi0\right), 0.5, -0.5\right), ecc \cdot ecc, 1\right)} \cdot k0 \]
  3. Applied rewrites99.2%

    \[\leadsto \sqrt{one\_es} \cdot k0 \]
  4. Add Preprocessing

Alternative 4: 18.6% accurate, 22.1× speedup?

\[\left(\left(k0 > 0 \land one\_es > 0\right) \land ecc > 0\right) \land ecc < 1\]
\[one\_es \cdot k0 \]
(FPCore (k0 one_es ecc phi0)
  :precision binary64
  :pre (and (and (and (> k0 0.0) (> one_es 0.0)) (> ecc 0.0))
     (< ecc 1.0))
  (* one_es k0))
double code(double k0, double one_es, double ecc, double phi0) {
	return one_es * k0;
}
real(8) function code(k0, one_es, ecc, phi0)
use fmin_fmax_functions
    real(8), intent (in) :: k0
    real(8), intent (in) :: one_es
    real(8), intent (in) :: ecc
    real(8), intent (in) :: phi0
    code = one_es * k0
end function
public static double code(double k0, double one_es, double ecc, double phi0) {
	return one_es * k0;
}
def code(k0, one_es, ecc, phi0):
	return one_es * k0
function code(k0, one_es, ecc, phi0)
	return Float64(one_es * k0)
end
function tmp = code(k0, one_es, ecc, phi0)
	tmp = one_es * k0;
end
code[k0_, one$95$es_, ecc_, phi0_] := N[(one$95$es * k0), $MachinePrecision]
f(k0, one_es, ecc, phi0):
	k0 in [0, +inf],
	one_es in [0, +inf],
	ecc in [0, 1],
	phi0 in [-inf, +inf]
code: THEORY
BEGIN
f(k0, one_es, ecc, phi0: real): real =
	one_es * k0
END code
one\_es \cdot k0
Derivation
  1. Initial program 99.6%

    \[\frac{k0 \cdot \sqrt{one\_es}}{1 - \left(ecc \cdot \sin phi0\right) \cdot \left(ecc \cdot \sin phi0\right)} \]
  2. Applied rewrites99.6%

    \[\leadsto \frac{\sqrt{one\_es}}{\mathsf{fma}\left(\mathsf{fma}\left(\cos \left(phi0 + phi0\right), 0.5, -0.5\right), ecc \cdot ecc, 1\right)} \cdot k0 \]
  3. Applied rewrites18.6%

    \[\leadsto one\_es \cdot k0 \]
  4. Add Preprocessing

Alternative 5: 17.6% accurate, 22.1× speedup?

\[\left(\left(k0 > 0 \land one\_es > 0\right) \land ecc > 0\right) \land ecc < 1\]
\[k0 \cdot k0 \]
(FPCore (k0 one_es ecc phi0)
  :precision binary64
  :pre (and (and (and (> k0 0.0) (> one_es 0.0)) (> ecc 0.0))
     (< ecc 1.0))
  (* k0 k0))
double code(double k0, double one_es, double ecc, double phi0) {
	return k0 * k0;
}
real(8) function code(k0, one_es, ecc, phi0)
use fmin_fmax_functions
    real(8), intent (in) :: k0
    real(8), intent (in) :: one_es
    real(8), intent (in) :: ecc
    real(8), intent (in) :: phi0
    code = k0 * k0
end function
public static double code(double k0, double one_es, double ecc, double phi0) {
	return k0 * k0;
}
def code(k0, one_es, ecc, phi0):
	return k0 * k0
function code(k0, one_es, ecc, phi0)
	return Float64(k0 * k0)
end
function tmp = code(k0, one_es, ecc, phi0)
	tmp = k0 * k0;
end
code[k0_, one$95$es_, ecc_, phi0_] := N[(k0 * k0), $MachinePrecision]
f(k0, one_es, ecc, phi0):
	k0 in [0, +inf],
	one_es in [0, +inf],
	ecc in [0, 1],
	phi0 in [-inf, +inf]
code: THEORY
BEGIN
f(k0, one_es, ecc, phi0: real): real =
	k0 * k0
END code
k0 \cdot k0
Derivation
  1. Initial program 99.6%

    \[\frac{k0 \cdot \sqrt{one\_es}}{1 - \left(ecc \cdot \sin phi0\right) \cdot \left(ecc \cdot \sin phi0\right)} \]
  2. Applied rewrites99.6%

    \[\leadsto \frac{\sqrt{one\_es}}{\mathsf{fma}\left(\mathsf{fma}\left(\cos \left(phi0 + phi0\right), 0.5, -0.5\right), ecc \cdot ecc, 1\right)} \cdot k0 \]
  3. Applied rewrites99.2%

    \[\leadsto \sqrt{one\_es} \cdot k0 \]
  4. Applied rewrites99.1%

    \[\leadsto \frac{\sqrt{one\_es}}{\frac{1}{k0}} \]
  5. Applied rewrites17.6%

    \[\leadsto k0 \cdot k0 \]
  6. Add Preprocessing

Alternative 6: 13.8% accurate, 6.4× speedup?

\[\left(\left(k0 > 0 \land one\_es > 0\right) \land ecc > 0\right) \land ecc < 1\]
\[\begin{array}{l} \mathbf{if}\;k0 \cdot \sqrt{one\_es} \leq 10^{-198}:\\ \;\;\;\;k0 - k0\\ \mathbf{else}:\\ \;\;\;\;k0 \cdot \left|phi0\right|\\ \end{array} \]
(FPCore (k0 one_es ecc phi0)
  :precision binary64
  :pre (and (and (and (> k0 0.0) (> one_es 0.0)) (> ecc 0.0))
     (< ecc 1.0))
  (if (<= (* k0 (sqrt one_es)) 1e-198) (- k0 k0) (* k0 (fabs phi0))))
double code(double k0, double one_es, double ecc, double phi0) {
	double tmp;
	if ((k0 * sqrt(one_es)) <= 1e-198) {
		tmp = k0 - k0;
	} else {
		tmp = k0 * fabs(phi0);
	}
	return tmp;
}
real(8) function code(k0, one_es, ecc, phi0)
use fmin_fmax_functions
    real(8), intent (in) :: k0
    real(8), intent (in) :: one_es
    real(8), intent (in) :: ecc
    real(8), intent (in) :: phi0
    real(8) :: tmp
    if ((k0 * sqrt(one_es)) <= 1d-198) then
        tmp = k0 - k0
    else
        tmp = k0 * abs(phi0)
    end if
    code = tmp
end function
public static double code(double k0, double one_es, double ecc, double phi0) {
	double tmp;
	if ((k0 * Math.sqrt(one_es)) <= 1e-198) {
		tmp = k0 - k0;
	} else {
		tmp = k0 * Math.abs(phi0);
	}
	return tmp;
}
def code(k0, one_es, ecc, phi0):
	tmp = 0
	if (k0 * math.sqrt(one_es)) <= 1e-198:
		tmp = k0 - k0
	else:
		tmp = k0 * math.fabs(phi0)
	return tmp
function code(k0, one_es, ecc, phi0)
	tmp = 0.0
	if (Float64(k0 * sqrt(one_es)) <= 1e-198)
		tmp = Float64(k0 - k0);
	else
		tmp = Float64(k0 * abs(phi0));
	end
	return tmp
end
function tmp_2 = code(k0, one_es, ecc, phi0)
	tmp = 0.0;
	if ((k0 * sqrt(one_es)) <= 1e-198)
		tmp = k0 - k0;
	else
		tmp = k0 * abs(phi0);
	end
	tmp_2 = tmp;
end
code[k0_, one$95$es_, ecc_, phi0_] := If[LessEqual[N[(k0 * N[Sqrt[one$95$es], $MachinePrecision]), $MachinePrecision], 1e-198], N[(k0 - k0), $MachinePrecision], N[(k0 * N[Abs[phi0], $MachinePrecision]), $MachinePrecision]]
f(k0, one_es, ecc, phi0):
	k0 in [0, +inf],
	one_es in [0, +inf],
	ecc in [0, 1],
	phi0 in [-inf, +inf]
code: THEORY
BEGIN
f(k0, one_es, ecc, phi0: real): real =
	LET tmp = IF ((k0 * (sqrt(one_es))) <= (9999999999999999124802099224533715278754906771643890943097115679663244864890241489099268701300224747096620592506163636511458147080229307187686231418190870453248079045903136497403860177328871032921253477527517381647903616019374090502989225614211093036170293774649807043557627102989961482478123917402578427471263639364172725828851513302974451006929804660161786807414215058738258826728830198486282936879197000185087711763102436423213435887235808111997818538852504458228488519455634531141186016611754894256591796875e-709)) THEN (k0 - k0) ELSE (k0 * (abs(phi0))) ENDIF IN
	tmp
END code
\begin{array}{l}
\mathbf{if}\;k0 \cdot \sqrt{one\_es} \leq 10^{-198}:\\
\;\;\;\;k0 - k0\\

\mathbf{else}:\\
\;\;\;\;k0 \cdot \left|phi0\right|\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 k0 (sqrt.f64 one_es)) < 9.9999999999999991e-199

    1. Initial program 99.6%

      \[\frac{k0 \cdot \sqrt{one\_es}}{1 - \left(ecc \cdot \sin phi0\right) \cdot \left(ecc \cdot \sin phi0\right)} \]
    2. Applied rewrites99.6%

      \[\leadsto \frac{\sqrt{one\_es}}{\mathsf{fma}\left(\mathsf{fma}\left(\cos \left(phi0 + phi0\right), 0.5, -0.5\right), ecc \cdot ecc, 1\right)} \cdot k0 \]
    3. Applied rewrites99.2%

      \[\leadsto \sqrt{one\_es} \cdot k0 \]
    4. Applied rewrites99.1%

      \[\leadsto \frac{\sqrt{one\_es}}{\frac{1}{k0}} \]
    5. Applied rewrites9.1%

      \[\leadsto k0 - k0 \]

    if 9.9999999999999991e-199 < (*.f64 k0 (sqrt.f64 one_es))

    1. Initial program 99.6%

      \[\frac{k0 \cdot \sqrt{one\_es}}{1 - \left(ecc \cdot \sin phi0\right) \cdot \left(ecc \cdot \sin phi0\right)} \]
    2. Taylor expanded in one_es around inf

      \[\leadsto \frac{k0 \cdot \left(one\_es \cdot \sqrt{\frac{1}{one\_es}}\right)}{1 - {ecc}^{2} \cdot {\sin phi0}^{2}} \]
    3. Applied rewrites99.5%

      \[\leadsto \frac{k0 \cdot \left(one\_es \cdot \sqrt{\frac{1}{one\_es}}\right)}{1 - {ecc}^{2} \cdot {\sin phi0}^{2}} \]
    4. Applied rewrites98.3%

      \[\leadsto \frac{k0 \cdot \left(one\_es \cdot \sqrt{\frac{1}{one\_es}}\right)}{1 - \sin \left(\pi \cdot 1\right)} \]
    5. Applied rewrites99.0%

      \[\leadsto k0 \cdot \frac{one\_es}{\sqrt{one\_es}} \]
    6. Applied rewrites7.5%

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

Alternative 7: 12.4% accurate, 7.1× speedup?

\[\left(\left(k0 > 0 \land one\_es > 0\right) \land ecc > 0\right) \land ecc < 1\]
\[\begin{array}{l} \mathbf{if}\;k0 \cdot \sqrt{one\_es} \leq 10^{-198}:\\ \;\;\;\;k0 - k0\\ \mathbf{else}:\\ \;\;\;\;\sqrt{k0}\\ \end{array} \]
(FPCore (k0 one_es ecc phi0)
  :precision binary64
  :pre (and (and (and (> k0 0.0) (> one_es 0.0)) (> ecc 0.0))
     (< ecc 1.0))
  (if (<= (* k0 (sqrt one_es)) 1e-198) (- k0 k0) (sqrt k0)))
double code(double k0, double one_es, double ecc, double phi0) {
	double tmp;
	if ((k0 * sqrt(one_es)) <= 1e-198) {
		tmp = k0 - k0;
	} else {
		tmp = sqrt(k0);
	}
	return tmp;
}
real(8) function code(k0, one_es, ecc, phi0)
use fmin_fmax_functions
    real(8), intent (in) :: k0
    real(8), intent (in) :: one_es
    real(8), intent (in) :: ecc
    real(8), intent (in) :: phi0
    real(8) :: tmp
    if ((k0 * sqrt(one_es)) <= 1d-198) then
        tmp = k0 - k0
    else
        tmp = sqrt(k0)
    end if
    code = tmp
end function
public static double code(double k0, double one_es, double ecc, double phi0) {
	double tmp;
	if ((k0 * Math.sqrt(one_es)) <= 1e-198) {
		tmp = k0 - k0;
	} else {
		tmp = Math.sqrt(k0);
	}
	return tmp;
}
def code(k0, one_es, ecc, phi0):
	tmp = 0
	if (k0 * math.sqrt(one_es)) <= 1e-198:
		tmp = k0 - k0
	else:
		tmp = math.sqrt(k0)
	return tmp
function code(k0, one_es, ecc, phi0)
	tmp = 0.0
	if (Float64(k0 * sqrt(one_es)) <= 1e-198)
		tmp = Float64(k0 - k0);
	else
		tmp = sqrt(k0);
	end
	return tmp
end
function tmp_2 = code(k0, one_es, ecc, phi0)
	tmp = 0.0;
	if ((k0 * sqrt(one_es)) <= 1e-198)
		tmp = k0 - k0;
	else
		tmp = sqrt(k0);
	end
	tmp_2 = tmp;
end
code[k0_, one$95$es_, ecc_, phi0_] := If[LessEqual[N[(k0 * N[Sqrt[one$95$es], $MachinePrecision]), $MachinePrecision], 1e-198], N[(k0 - k0), $MachinePrecision], N[Sqrt[k0], $MachinePrecision]]
f(k0, one_es, ecc, phi0):
	k0 in [0, +inf],
	one_es in [0, +inf],
	ecc in [0, 1],
	phi0 in [-inf, +inf]
code: THEORY
BEGIN
f(k0, one_es, ecc, phi0: real): real =
	LET tmp = IF ((k0 * (sqrt(one_es))) <= (9999999999999999124802099224533715278754906771643890943097115679663244864890241489099268701300224747096620592506163636511458147080229307187686231418190870453248079045903136497403860177328871032921253477527517381647903616019374090502989225614211093036170293774649807043557627102989961482478123917402578427471263639364172725828851513302974451006929804660161786807414215058738258826728830198486282936879197000185087711763102436423213435887235808111997818538852504458228488519455634531141186016611754894256591796875e-709)) THEN (k0 - k0) ELSE (sqrt(k0)) ENDIF IN
	tmp
END code
\begin{array}{l}
\mathbf{if}\;k0 \cdot \sqrt{one\_es} \leq 10^{-198}:\\
\;\;\;\;k0 - k0\\

\mathbf{else}:\\
\;\;\;\;\sqrt{k0}\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 k0 (sqrt.f64 one_es)) < 9.9999999999999991e-199

    1. Initial program 99.6%

      \[\frac{k0 \cdot \sqrt{one\_es}}{1 - \left(ecc \cdot \sin phi0\right) \cdot \left(ecc \cdot \sin phi0\right)} \]
    2. Applied rewrites99.6%

      \[\leadsto \frac{\sqrt{one\_es}}{\mathsf{fma}\left(\mathsf{fma}\left(\cos \left(phi0 + phi0\right), 0.5, -0.5\right), ecc \cdot ecc, 1\right)} \cdot k0 \]
    3. Applied rewrites99.2%

      \[\leadsto \sqrt{one\_es} \cdot k0 \]
    4. Applied rewrites99.1%

      \[\leadsto \frac{\sqrt{one\_es}}{\frac{1}{k0}} \]
    5. Applied rewrites9.1%

      \[\leadsto k0 - k0 \]

    if 9.9999999999999991e-199 < (*.f64 k0 (sqrt.f64 one_es))

    1. Initial program 99.6%

      \[\frac{k0 \cdot \sqrt{one\_es}}{1 - \left(ecc \cdot \sin phi0\right) \cdot \left(ecc \cdot \sin phi0\right)} \]
    2. Applied rewrites99.6%

      \[\leadsto \frac{\sqrt{one\_es}}{\mathsf{fma}\left(\mathsf{fma}\left(\cos \left(phi0 + phi0\right), 0.5, -0.5\right), ecc \cdot ecc, 1\right)} \cdot k0 \]
    3. Applied rewrites99.2%

      \[\leadsto \sqrt{one\_es} \cdot k0 \]
    4. Applied rewrites99.1%

      \[\leadsto \frac{\sqrt{one\_es}}{\frac{1}{k0}} \]
    5. Applied rewrites6.6%

      \[\leadsto \sqrt{k0} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 7.2% accurate, 88.6× speedup?

\[\left(\left(k0 > 0 \land one\_es > 0\right) \land ecc > 0\right) \land ecc < 1\]
\[k0 \]
(FPCore (k0 one_es ecc phi0)
  :precision binary64
  :pre (and (and (and (> k0 0.0) (> one_es 0.0)) (> ecc 0.0))
     (< ecc 1.0))
  k0)
double code(double k0, double one_es, double ecc, double phi0) {
	return k0;
}
real(8) function code(k0, one_es, ecc, phi0)
use fmin_fmax_functions
    real(8), intent (in) :: k0
    real(8), intent (in) :: one_es
    real(8), intent (in) :: ecc
    real(8), intent (in) :: phi0
    code = k0
end function
public static double code(double k0, double one_es, double ecc, double phi0) {
	return k0;
}
def code(k0, one_es, ecc, phi0):
	return k0
function code(k0, one_es, ecc, phi0)
	return k0
end
function tmp = code(k0, one_es, ecc, phi0)
	tmp = k0;
end
code[k0_, one$95$es_, ecc_, phi0_] := k0
f(k0, one_es, ecc, phi0):
	k0 in [0, +inf],
	one_es in [0, +inf],
	ecc in [0, 1],
	phi0 in [-inf, +inf]
code: THEORY
BEGIN
f(k0, one_es, ecc, phi0: real): real =
	k0
END code
k0
Derivation
  1. Initial program 99.6%

    \[\frac{k0 \cdot \sqrt{one\_es}}{1 - \left(ecc \cdot \sin phi0\right) \cdot \left(ecc \cdot \sin phi0\right)} \]
  2. Taylor expanded in one_es around inf

    \[\leadsto \frac{k0 \cdot \left(one\_es \cdot \sqrt{\frac{1}{one\_es}}\right)}{1 - {ecc}^{2} \cdot {\sin phi0}^{2}} \]
  3. Applied rewrites99.5%

    \[\leadsto \frac{k0 \cdot \left(one\_es \cdot \sqrt{\frac{1}{one\_es}}\right)}{1 - {ecc}^{2} \cdot {\sin phi0}^{2}} \]
  4. Applied rewrites98.3%

    \[\leadsto \frac{k0 \cdot \left(one\_es \cdot \sqrt{\frac{1}{one\_es}}\right)}{1 - \sin \left(\pi \cdot 1\right)} \]
  5. Applied rewrites99.0%

    \[\leadsto k0 \cdot \frac{one\_es}{\sqrt{one\_es}} \]
  6. Applied rewrites7.2%

    \[\leadsto k0 \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2026050 +o generate:egglog
(FPCore (k0 one_es ecc phi0)
  :name "init-kR"
  :precision binary64
  :pre (and (and (and (> k0 0.0) (> one_es 0.0)) (> ecc 0.0)) (< ecc 1.0))
  (/ (* k0 (sqrt one_es)) (- 1.0 (* (* ecc (sin phi0)) (* ecc (sin phi0))))))