
(FPCore (phip ecc) :precision binary64 :pre (and (> ecc 0.0) (< ecc 1.0)) (* ecc (sin phip)))
double code(double phip, double ecc) {
return ecc * sin(phip);
}
real(8) function code(phip, ecc)
use fmin_fmax_functions
real(8), intent (in) :: phip
real(8), intent (in) :: ecc
code = ecc * sin(phip)
end function
public static double code(double phip, double ecc) {
return ecc * Math.sin(phip);
}
def code(phip, ecc): return ecc * math.sin(phip)
function code(phip, ecc) return Float64(ecc * sin(phip)) end
function tmp = code(phip, ecc) tmp = ecc * sin(phip); end
code[phip_, ecc_] := N[(ecc * N[Sin[phip], $MachinePrecision]), $MachinePrecision]
f(phip, ecc): phip in [-inf, +inf], ecc in [0, 1] code: THEORY BEGIN f(phip, ecc: real): real = ecc * (sin(phip)) END code
ecc \cdot \sin phip
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (phip ecc) :precision binary64 :pre (and (> ecc 0.0) (< ecc 1.0)) (* ecc (sin phip)))
double code(double phip, double ecc) {
return ecc * sin(phip);
}
real(8) function code(phip, ecc)
use fmin_fmax_functions
real(8), intent (in) :: phip
real(8), intent (in) :: ecc
code = ecc * sin(phip)
end function
public static double code(double phip, double ecc) {
return ecc * Math.sin(phip);
}
def code(phip, ecc): return ecc * math.sin(phip)
function code(phip, ecc) return Float64(ecc * sin(phip)) end
function tmp = code(phip, ecc) tmp = ecc * sin(phip); end
code[phip_, ecc_] := N[(ecc * N[Sin[phip], $MachinePrecision]), $MachinePrecision]
f(phip, ecc): phip in [-inf, +inf], ecc in [0, 1] code: THEORY BEGIN f(phip, ecc: real): real = ecc * (sin(phip)) END code
ecc \cdot \sin phip
(FPCore (phip ecc)
:precision binary64
:pre (and (> ecc 0.0) (< ecc 1.0))
(let* ((t_0 (sin (fabs phip))))
(*
(copysign 1.0 phip)
(if (<= t_0 -0.02)
(- ecc)
(if (<= t_0 4e-7) (* ecc (fabs phip)) ecc)))))double code(double phip, double ecc) {
double t_0 = sin(fabs(phip));
double tmp;
if (t_0 <= -0.02) {
tmp = -ecc;
} else if (t_0 <= 4e-7) {
tmp = ecc * fabs(phip);
} else {
tmp = ecc;
}
return copysign(1.0, phip) * tmp;
}
public static double code(double phip, double ecc) {
double t_0 = Math.sin(Math.abs(phip));
double tmp;
if (t_0 <= -0.02) {
tmp = -ecc;
} else if (t_0 <= 4e-7) {
tmp = ecc * Math.abs(phip);
} else {
tmp = ecc;
}
return Math.copySign(1.0, phip) * tmp;
}
def code(phip, ecc): t_0 = math.sin(math.fabs(phip)) tmp = 0 if t_0 <= -0.02: tmp = -ecc elif t_0 <= 4e-7: tmp = ecc * math.fabs(phip) else: tmp = ecc return math.copysign(1.0, phip) * tmp
function code(phip, ecc) t_0 = sin(abs(phip)) tmp = 0.0 if (t_0 <= -0.02) tmp = Float64(-ecc); elseif (t_0 <= 4e-7) tmp = Float64(ecc * abs(phip)); else tmp = ecc; end return Float64(copysign(1.0, phip) * tmp) end
function tmp_2 = code(phip, ecc) t_0 = sin(abs(phip)); tmp = 0.0; if (t_0 <= -0.02) tmp = -ecc; elseif (t_0 <= 4e-7) tmp = ecc * abs(phip); else tmp = ecc; end tmp_2 = (sign(phip) * abs(1.0)) * tmp; end
code[phip_, ecc_] := Block[{t$95$0 = N[Sin[N[Abs[phip], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[phip]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$0, -0.02], (-ecc), If[LessEqual[t$95$0, 4e-7], N[(ecc * N[Abs[phip], $MachinePrecision]), $MachinePrecision], ecc]]), $MachinePrecision]]
\begin{array}{l}
t_0 := \sin \left(\left|phip\right|\right)\\
\mathsf{copysign}\left(1, phip\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq -0.02:\\
\;\;\;\;-ecc\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-7}:\\
\;\;\;\;ecc \cdot \left|phip\right|\\
\mathbf{else}:\\
\;\;\;\;ecc\\
\end{array}
\end{array}
if (sin.f64 phip) < -0.02Initial program 99.8%
Taylor expanded in phip around 0
Applied rewrites51.7%
Applied rewrites51.7%
Applied rewrites9.2%
Applied rewrites9.2%
if -0.02 < (sin.f64 phip) < 3.9999999999999998e-7Initial program 99.8%
Taylor expanded in phip around 0
Applied rewrites51.7%
if 3.9999999999999998e-7 < (sin.f64 phip) Initial program 99.8%
Taylor expanded in phip around 0
Applied rewrites51.7%
Applied rewrites51.7%
Applied rewrites9.1%
(FPCore (phip ecc) :precision binary64 :pre (and (> ecc 0.0) (< ecc 1.0)) (let* ((t_0 (sin (fabs phip)))) (* (copysign 1.0 phip) (if (<= t_0 -0.02) (- ecc) (if (<= t_0 2e-28) 0.0 ecc)))))
double code(double phip, double ecc) {
double t_0 = sin(fabs(phip));
double tmp;
if (t_0 <= -0.02) {
tmp = -ecc;
} else if (t_0 <= 2e-28) {
tmp = 0.0;
} else {
tmp = ecc;
}
return copysign(1.0, phip) * tmp;
}
public static double code(double phip, double ecc) {
double t_0 = Math.sin(Math.abs(phip));
double tmp;
if (t_0 <= -0.02) {
tmp = -ecc;
} else if (t_0 <= 2e-28) {
tmp = 0.0;
} else {
tmp = ecc;
}
return Math.copySign(1.0, phip) * tmp;
}
def code(phip, ecc): t_0 = math.sin(math.fabs(phip)) tmp = 0 if t_0 <= -0.02: tmp = -ecc elif t_0 <= 2e-28: tmp = 0.0 else: tmp = ecc return math.copysign(1.0, phip) * tmp
function code(phip, ecc) t_0 = sin(abs(phip)) tmp = 0.0 if (t_0 <= -0.02) tmp = Float64(-ecc); elseif (t_0 <= 2e-28) tmp = 0.0; else tmp = ecc; end return Float64(copysign(1.0, phip) * tmp) end
function tmp_2 = code(phip, ecc) t_0 = sin(abs(phip)); tmp = 0.0; if (t_0 <= -0.02) tmp = -ecc; elseif (t_0 <= 2e-28) tmp = 0.0; else tmp = ecc; end tmp_2 = (sign(phip) * abs(1.0)) * tmp; end
code[phip_, ecc_] := Block[{t$95$0 = N[Sin[N[Abs[phip], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[phip]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$0, -0.02], (-ecc), If[LessEqual[t$95$0, 2e-28], 0.0, ecc]]), $MachinePrecision]]
\begin{array}{l}
t_0 := \sin \left(\left|phip\right|\right)\\
\mathsf{copysign}\left(1, phip\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq -0.02:\\
\;\;\;\;-ecc\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-28}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;ecc\\
\end{array}
\end{array}
if (sin.f64 phip) < -0.02Initial program 99.8%
Taylor expanded in phip around 0
Applied rewrites51.7%
Applied rewrites51.7%
Applied rewrites9.2%
Applied rewrites9.2%
if -0.02 < (sin.f64 phip) < 1.9999999999999999e-28Initial program 99.8%
Taylor expanded in phip around 0
Applied rewrites51.7%
Applied rewrites51.7%
Applied rewrites28.1%
if 1.9999999999999999e-28 < (sin.f64 phip) Initial program 99.8%
Taylor expanded in phip around 0
Applied rewrites51.7%
Applied rewrites51.7%
Applied rewrites9.1%
(FPCore (phip ecc) :precision binary64 :pre (and (> ecc 0.0) (< ecc 1.0)) (* (copysign 1.0 phip) (if (<= (sin (fabs phip)) 2e-28) 0.0 ecc)))
double code(double phip, double ecc) {
double tmp;
if (sin(fabs(phip)) <= 2e-28) {
tmp = 0.0;
} else {
tmp = ecc;
}
return copysign(1.0, phip) * tmp;
}
public static double code(double phip, double ecc) {
double tmp;
if (Math.sin(Math.abs(phip)) <= 2e-28) {
tmp = 0.0;
} else {
tmp = ecc;
}
return Math.copySign(1.0, phip) * tmp;
}
def code(phip, ecc): tmp = 0 if math.sin(math.fabs(phip)) <= 2e-28: tmp = 0.0 else: tmp = ecc return math.copysign(1.0, phip) * tmp
function code(phip, ecc) tmp = 0.0 if (sin(abs(phip)) <= 2e-28) tmp = 0.0; else tmp = ecc; end return Float64(copysign(1.0, phip) * tmp) end
function tmp_2 = code(phip, ecc) tmp = 0.0; if (sin(abs(phip)) <= 2e-28) tmp = 0.0; else tmp = ecc; end tmp_2 = (sign(phip) * abs(1.0)) * tmp; end
code[phip_, ecc_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[phip]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Sin[N[Abs[phip], $MachinePrecision]], $MachinePrecision], 2e-28], 0.0, ecc]), $MachinePrecision]
\mathsf{copysign}\left(1, phip\right) \cdot \begin{array}{l}
\mathbf{if}\;\sin \left(\left|phip\right|\right) \leq 2 \cdot 10^{-28}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;ecc\\
\end{array}
if (sin.f64 phip) < 1.9999999999999999e-28Initial program 99.8%
Taylor expanded in phip around 0
Applied rewrites51.7%
Applied rewrites51.7%
Applied rewrites28.1%
if 1.9999999999999999e-28 < (sin.f64 phip) Initial program 99.8%
Taylor expanded in phip around 0
Applied rewrites51.7%
Applied rewrites51.7%
Applied rewrites9.1%
(FPCore (phip ecc) :precision binary64 :pre (and (> ecc 0.0) (< ecc 1.0)) 0.0)
double code(double phip, double ecc) {
return 0.0;
}
real(8) function code(phip, ecc)
use fmin_fmax_functions
real(8), intent (in) :: phip
real(8), intent (in) :: ecc
code = 0.0d0
end function
public static double code(double phip, double ecc) {
return 0.0;
}
def code(phip, ecc): return 0.0
function code(phip, ecc) return 0.0 end
function tmp = code(phip, ecc) tmp = 0.0; end
code[phip_, ecc_] := 0.0
f(phip, ecc): phip in [-inf, +inf], ecc in [0, 1] code: THEORY BEGIN f(phip, ecc: real): real = 0 END code
0
Initial program 99.8%
Taylor expanded in phip around 0
Applied rewrites51.7%
Applied rewrites51.7%
Applied rewrites28.1%
(FPCore (phip ecc) :precision binary64 :pre (and (> ecc 0.0) (< ecc 1.0)) -0.08333333333333333)
double code(double phip, double ecc) {
return -0.08333333333333333;
}
real(8) function code(phip, ecc)
use fmin_fmax_functions
real(8), intent (in) :: phip
real(8), intent (in) :: ecc
code = -0.08333333333333333d0
end function
public static double code(double phip, double ecc) {
return -0.08333333333333333;
}
def code(phip, ecc): return -0.08333333333333333
function code(phip, ecc) return -0.08333333333333333 end
function tmp = code(phip, ecc) tmp = -0.08333333333333333; end
code[phip_, ecc_] := -0.08333333333333333
f(phip, ecc): phip in [-inf, +inf], ecc in [0, 1] code: THEORY BEGIN f(phip, ecc: real): real = -8333333333333332870740406406184774823486804962158203125e-56 END code
-0.08333333333333333
Initial program 99.8%
Taylor expanded in phip around 0
Applied rewrites51.2%
Applied rewrites51.2%
Applied rewrites3.6%
herbie shell --seed 2026050 +o generate:egglog
(FPCore (phip ecc)
:name "inverse-esp"
:precision binary64
:pre (and (> ecc 0.0) (< ecc 1.0))
(* ecc (sin phip)))