
(FPCore (Cn Ce) :precision binary64 :pre TRUE (let* ((t_0 (sqrt (+ (* (sinh Ce) (sinh Ce)) (* (cos Cn) (cos Cn)))))) (sqrt (+ (* (sin Cn) (sin Cn)) (* t_0 t_0)))))
double code(double Cn, double Ce) {
double t_0 = sqrt(((sinh(Ce) * sinh(Ce)) + (cos(Cn) * cos(Cn))));
return sqrt(((sin(Cn) * sin(Cn)) + (t_0 * t_0)));
}
real(8) function code(cn, ce)
use fmin_fmax_functions
real(8), intent (in) :: cn
real(8), intent (in) :: ce
real(8) :: t_0
t_0 = sqrt(((sinh(ce) * sinh(ce)) + (cos(cn) * cos(cn))))
code = sqrt(((sin(cn) * sin(cn)) + (t_0 * t_0)))
end function
public static double code(double Cn, double Ce) {
double t_0 = Math.sqrt(((Math.sinh(Ce) * Math.sinh(Ce)) + (Math.cos(Cn) * Math.cos(Cn))));
return Math.sqrt(((Math.sin(Cn) * Math.sin(Cn)) + (t_0 * t_0)));
}
def code(Cn, Ce): t_0 = math.sqrt(((math.sinh(Ce) * math.sinh(Ce)) + (math.cos(Cn) * math.cos(Cn)))) return math.sqrt(((math.sin(Cn) * math.sin(Cn)) + (t_0 * t_0)))
function code(Cn, Ce) t_0 = sqrt(Float64(Float64(sinh(Ce) * sinh(Ce)) + Float64(cos(Cn) * cos(Cn)))) return sqrt(Float64(Float64(sin(Cn) * sin(Cn)) + Float64(t_0 * t_0))) end
function tmp = code(Cn, Ce) t_0 = sqrt(((sinh(Ce) * sinh(Ce)) + (cos(Cn) * cos(Cn)))); tmp = sqrt(((sin(Cn) * sin(Cn)) + (t_0 * t_0))); end
code[Cn_, Ce_] := Block[{t$95$0 = N[Sqrt[N[(N[(N[Sinh[Ce], $MachinePrecision] * N[Sinh[Ce], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[Cn], $MachinePrecision] * N[Cos[Cn], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[Sqrt[N[(N[(N[Sin[Cn], $MachinePrecision] * N[Sin[Cn], $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
f(Cn, Ce): Cn in [-inf, +inf], Ce in [-inf, +inf] code: THEORY BEGIN f(Cn, Ce: real): real = LET t_0 = (sqrt((((((1) / (2)) * ((exp(Ce)) + ((- (1)) / (exp(Ce))))) * (((1) / (2)) * ((exp(Ce)) + ((- (1)) / (exp(Ce)))))) + ((cos(Cn)) * (cos(Cn)))))) IN sqrt((((sin(Cn)) * (sin(Cn))) + (t_0 * t_0))) END code
\begin{array}{l}
t_0 := \sqrt{\sinh Ce \cdot \sinh Ce + \cos Cn \cdot \cos Cn}\\
\sqrt{\sin Cn \cdot \sin Cn + t\_0 \cdot t\_0}
\end{array}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (Cn Ce) :precision binary64 :pre TRUE (let* ((t_0 (sqrt (+ (* (sinh Ce) (sinh Ce)) (* (cos Cn) (cos Cn)))))) (sqrt (+ (* (sin Cn) (sin Cn)) (* t_0 t_0)))))
double code(double Cn, double Ce) {
double t_0 = sqrt(((sinh(Ce) * sinh(Ce)) + (cos(Cn) * cos(Cn))));
return sqrt(((sin(Cn) * sin(Cn)) + (t_0 * t_0)));
}
real(8) function code(cn, ce)
use fmin_fmax_functions
real(8), intent (in) :: cn
real(8), intent (in) :: ce
real(8) :: t_0
t_0 = sqrt(((sinh(ce) * sinh(ce)) + (cos(cn) * cos(cn))))
code = sqrt(((sin(cn) * sin(cn)) + (t_0 * t_0)))
end function
public static double code(double Cn, double Ce) {
double t_0 = Math.sqrt(((Math.sinh(Ce) * Math.sinh(Ce)) + (Math.cos(Cn) * Math.cos(Cn))));
return Math.sqrt(((Math.sin(Cn) * Math.sin(Cn)) + (t_0 * t_0)));
}
def code(Cn, Ce): t_0 = math.sqrt(((math.sinh(Ce) * math.sinh(Ce)) + (math.cos(Cn) * math.cos(Cn)))) return math.sqrt(((math.sin(Cn) * math.sin(Cn)) + (t_0 * t_0)))
function code(Cn, Ce) t_0 = sqrt(Float64(Float64(sinh(Ce) * sinh(Ce)) + Float64(cos(Cn) * cos(Cn)))) return sqrt(Float64(Float64(sin(Cn) * sin(Cn)) + Float64(t_0 * t_0))) end
function tmp = code(Cn, Ce) t_0 = sqrt(((sinh(Ce) * sinh(Ce)) + (cos(Cn) * cos(Cn)))); tmp = sqrt(((sin(Cn) * sin(Cn)) + (t_0 * t_0))); end
code[Cn_, Ce_] := Block[{t$95$0 = N[Sqrt[N[(N[(N[Sinh[Ce], $MachinePrecision] * N[Sinh[Ce], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[Cn], $MachinePrecision] * N[Cos[Cn], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[Sqrt[N[(N[(N[Sin[Cn], $MachinePrecision] * N[Sin[Cn], $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
f(Cn, Ce): Cn in [-inf, +inf], Ce in [-inf, +inf] code: THEORY BEGIN f(Cn, Ce: real): real = LET t_0 = (sqrt((((((1) / (2)) * ((exp(Ce)) + ((- (1)) / (exp(Ce))))) * (((1) / (2)) * ((exp(Ce)) + ((- (1)) / (exp(Ce)))))) + ((cos(Cn)) * (cos(Cn)))))) IN sqrt((((sin(Cn)) * (sin(Cn))) + (t_0 * t_0))) END code
\begin{array}{l}
t_0 := \sqrt{\sinh Ce \cdot \sinh Ce + \cos Cn \cdot \cos Cn}\\
\sqrt{\sin Cn \cdot \sin Cn + t\_0 \cdot t\_0}
\end{array}
(FPCore (Cn Ce) :precision binary64 :pre TRUE (cosh Ce))
double code(double Cn, double Ce) {
return cosh(Ce);
}
real(8) function code(cn, ce)
use fmin_fmax_functions
real(8), intent (in) :: cn
real(8), intent (in) :: ce
code = cosh(ce)
end function
public static double code(double Cn, double Ce) {
return Math.cosh(Ce);
}
def code(Cn, Ce): return math.cosh(Ce)
function code(Cn, Ce) return cosh(Ce) end
function tmp = code(Cn, Ce) tmp = cosh(Ce); end
code[Cn_, Ce_] := N[Cosh[Ce], $MachinePrecision]
f(Cn, Ce): Cn in [-inf, +inf], Ce in [-inf, +inf] code: THEORY BEGIN f(Cn, Ce: real): real = ((1) / (2)) * ((exp(Ce)) + ((1) / (exp(Ce)))) END code
\cosh Ce
Initial program 99.9%
Applied rewrites100.0%
Applied rewrites100.0%
(FPCore (Cn Ce) :precision binary64 :pre TRUE (if (<= (sinh (fabs Ce)) 0.05) 1.0 (expm1 (- (fabs Ce) 1.0))))
double code(double Cn, double Ce) {
double tmp;
if (sinh(fabs(Ce)) <= 0.05) {
tmp = 1.0;
} else {
tmp = expm1((fabs(Ce) - 1.0));
}
return tmp;
}
public static double code(double Cn, double Ce) {
double tmp;
if (Math.sinh(Math.abs(Ce)) <= 0.05) {
tmp = 1.0;
} else {
tmp = Math.expm1((Math.abs(Ce) - 1.0));
}
return tmp;
}
def code(Cn, Ce): tmp = 0 if math.sinh(math.fabs(Ce)) <= 0.05: tmp = 1.0 else: tmp = math.expm1((math.fabs(Ce) - 1.0)) return tmp
function code(Cn, Ce) tmp = 0.0 if (sinh(abs(Ce)) <= 0.05) tmp = 1.0; else tmp = expm1(Float64(abs(Ce) - 1.0)); end return tmp end
code[Cn_, Ce_] := If[LessEqual[N[Sinh[N[Abs[Ce], $MachinePrecision]], $MachinePrecision], 0.05], 1.0, N[(Exp[N[(N[Abs[Ce], $MachinePrecision] - 1.0), $MachinePrecision]] - 1), $MachinePrecision]]
f(Cn, Ce): Cn in [-inf, +inf], Ce in [-inf, +inf] code: THEORY BEGIN f(Cn, Ce: real): real = LET tmp = IF ((((1) / (2)) * ((exp((abs(Ce)))) + ((- (1)) / (exp((abs(Ce))))))) <= (5000000000000000277555756156289135105907917022705078125e-56)) THEN (1) ELSE ((exp(((abs(Ce)) - (1)))) - (1)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\sinh \left(\left|Ce\right|\right) \leq 0.05:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\left|Ce\right| - 1\right)\\
\end{array}
if (sinh.f64 Ce) < 0.050000000000000003Initial program 99.9%
Applied rewrites100.0%
Applied rewrites50.6%
if 0.050000000000000003 < (sinh.f64 Ce) Initial program 99.9%
Applied rewrites100.0%
Applied rewrites25.7%
(FPCore (Cn Ce) :precision binary64 :pre TRUE (if (<= (sinh (fabs Ce)) 0.05) 1.0 (expm1 (fabs Ce))))
double code(double Cn, double Ce) {
double tmp;
if (sinh(fabs(Ce)) <= 0.05) {
tmp = 1.0;
} else {
tmp = expm1(fabs(Ce));
}
return tmp;
}
public static double code(double Cn, double Ce) {
double tmp;
if (Math.sinh(Math.abs(Ce)) <= 0.05) {
tmp = 1.0;
} else {
tmp = Math.expm1(Math.abs(Ce));
}
return tmp;
}
def code(Cn, Ce): tmp = 0 if math.sinh(math.fabs(Ce)) <= 0.05: tmp = 1.0 else: tmp = math.expm1(math.fabs(Ce)) return tmp
function code(Cn, Ce) tmp = 0.0 if (sinh(abs(Ce)) <= 0.05) tmp = 1.0; else tmp = expm1(abs(Ce)); end return tmp end
code[Cn_, Ce_] := If[LessEqual[N[Sinh[N[Abs[Ce], $MachinePrecision]], $MachinePrecision], 0.05], 1.0, N[(Exp[N[Abs[Ce], $MachinePrecision]] - 1), $MachinePrecision]]
f(Cn, Ce): Cn in [-inf, +inf], Ce in [-inf, +inf] code: THEORY BEGIN f(Cn, Ce: real): real = LET tmp = IF ((((1) / (2)) * ((exp((abs(Ce)))) + ((- (1)) / (exp((abs(Ce))))))) <= (5000000000000000277555756156289135105907917022705078125e-56)) THEN (1) ELSE ((exp((abs(Ce)))) - (1)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\sinh \left(\left|Ce\right|\right) \leq 0.05:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\left|Ce\right|\right)\\
\end{array}
if (sinh.f64 Ce) < 0.050000000000000003Initial program 99.9%
Applied rewrites100.0%
Applied rewrites50.6%
if 0.050000000000000003 < (sinh.f64 Ce) Initial program 99.9%
Applied rewrites100.0%
Applied rewrites26.8%
(FPCore (Cn Ce) :precision binary64 :pre TRUE 1.0)
double code(double Cn, double Ce) {
return 1.0;
}
real(8) function code(cn, ce)
use fmin_fmax_functions
real(8), intent (in) :: cn
real(8), intent (in) :: ce
code = 1.0d0
end function
public static double code(double Cn, double Ce) {
return 1.0;
}
def code(Cn, Ce): return 1.0
function code(Cn, Ce) return 1.0 end
function tmp = code(Cn, Ce) tmp = 1.0; end
code[Cn_, Ce_] := 1.0
f(Cn, Ce): Cn in [-inf, +inf], Ce in [-inf, +inf] code: THEORY BEGIN f(Cn, Ce: real): real = 1 END code
1
Initial program 99.9%
Applied rewrites100.0%
Applied rewrites50.6%
herbie shell --seed 2026050 +o generate:egglog
(FPCore (Cn Ce)
:name "exact-inv-rr"
:precision binary64
(sqrt (+ (* (sin Cn) (sin Cn)) (* (sqrt (+ (* (sinh Ce) (sinh Ce)) (* (cos Cn) (cos Cn)))) (sqrt (+ (* (sinh Ce) (sinh Ce)) (* (cos Cn) (cos Cn))))))))