exact-inv-cosh-arg

Percentage Accurate: 100.0% → 100.0%
Time: 1.7min
Alternatives: 6
Speedup: 2.3×

Specification

?
\[\begin{array}{l} t_0 := e^{2 \cdot Ce}\\ 0.5 \cdot t\_0 + \frac{0.5}{t\_0} \end{array} \]
(FPCore (Ce)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (exp (* 2.0 Ce)))) (+ (* 0.5 t_0) (/ 0.5 t_0))))
double code(double Ce) {
	double t_0 = exp((2.0 * Ce));
	return (0.5 * t_0) + (0.5 / t_0);
}
real(8) function code(ce)
use fmin_fmax_functions
    real(8), intent (in) :: ce
    real(8) :: t_0
    t_0 = exp((2.0d0 * ce))
    code = (0.5d0 * t_0) + (0.5d0 / t_0)
end function
public static double code(double Ce) {
	double t_0 = Math.exp((2.0 * Ce));
	return (0.5 * t_0) + (0.5 / t_0);
}
def code(Ce):
	t_0 = math.exp((2.0 * Ce))
	return (0.5 * t_0) + (0.5 / t_0)
function code(Ce)
	t_0 = exp(Float64(2.0 * Ce))
	return Float64(Float64(0.5 * t_0) + Float64(0.5 / t_0))
end
function tmp = code(Ce)
	t_0 = exp((2.0 * Ce));
	tmp = (0.5 * t_0) + (0.5 / t_0);
end
code[Ce_] := Block[{t$95$0 = N[Exp[N[(2.0 * Ce), $MachinePrecision]], $MachinePrecision]}, N[(N[(0.5 * t$95$0), $MachinePrecision] + N[(0.5 / t$95$0), $MachinePrecision]), $MachinePrecision]]
f(Ce):
	Ce in [-inf, +inf]
code: THEORY
BEGIN
f(Ce: real): real =
	LET t_0 = (exp(((2) * Ce))) IN
	((5e-1) * t_0) + ((5e-1) / t_0)
END code
\begin{array}{l}
t_0 := e^{2 \cdot Ce}\\
0.5 \cdot t\_0 + \frac{0.5}{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 6 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?

\[\begin{array}{l} t_0 := e^{2 \cdot Ce}\\ 0.5 \cdot t\_0 + \frac{0.5}{t\_0} \end{array} \]
(FPCore (Ce)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (exp (* 2.0 Ce)))) (+ (* 0.5 t_0) (/ 0.5 t_0))))
double code(double Ce) {
	double t_0 = exp((2.0 * Ce));
	return (0.5 * t_0) + (0.5 / t_0);
}
real(8) function code(ce)
use fmin_fmax_functions
    real(8), intent (in) :: ce
    real(8) :: t_0
    t_0 = exp((2.0d0 * ce))
    code = (0.5d0 * t_0) + (0.5d0 / t_0)
end function
public static double code(double Ce) {
	double t_0 = Math.exp((2.0 * Ce));
	return (0.5 * t_0) + (0.5 / t_0);
}
def code(Ce):
	t_0 = math.exp((2.0 * Ce))
	return (0.5 * t_0) + (0.5 / t_0)
function code(Ce)
	t_0 = exp(Float64(2.0 * Ce))
	return Float64(Float64(0.5 * t_0) + Float64(0.5 / t_0))
end
function tmp = code(Ce)
	t_0 = exp((2.0 * Ce));
	tmp = (0.5 * t_0) + (0.5 / t_0);
end
code[Ce_] := Block[{t$95$0 = N[Exp[N[(2.0 * Ce), $MachinePrecision]], $MachinePrecision]}, N[(N[(0.5 * t$95$0), $MachinePrecision] + N[(0.5 / t$95$0), $MachinePrecision]), $MachinePrecision]]
f(Ce):
	Ce in [-inf, +inf]
code: THEORY
BEGIN
f(Ce: real): real =
	LET t_0 = (exp(((2) * Ce))) IN
	((5e-1) * t_0) + ((5e-1) / t_0)
END code
\begin{array}{l}
t_0 := e^{2 \cdot Ce}\\
0.5 \cdot t\_0 + \frac{0.5}{t\_0}
\end{array}

Alternative 1: 100.0% accurate, 2.3× speedup?

\[\cosh \left(Ce + Ce\right) \]
(FPCore (Ce)
  :precision binary64
  :pre TRUE
  (cosh (+ Ce Ce)))
double code(double Ce) {
	return cosh((Ce + Ce));
}
real(8) function code(ce)
use fmin_fmax_functions
    real(8), intent (in) :: ce
    code = cosh((ce + ce))
end function
public static double code(double Ce) {
	return Math.cosh((Ce + Ce));
}
def code(Ce):
	return math.cosh((Ce + Ce))
function code(Ce)
	return cosh(Float64(Ce + Ce))
end
function tmp = code(Ce)
	tmp = cosh((Ce + Ce));
end
code[Ce_] := N[Cosh[N[(Ce + Ce), $MachinePrecision]], $MachinePrecision]
f(Ce):
	Ce in [-inf, +inf]
code: THEORY
BEGIN
f(Ce: real): real =
	((1) / (2)) * ((exp((Ce + Ce))) + ((1) / (exp((Ce + Ce)))))
END code
\cosh \left(Ce + Ce\right)
Derivation
  1. Initial program 100.0%

    \[0.5 \cdot e^{2 \cdot Ce} + \frac{0.5}{e^{2 \cdot Ce}} \]
  2. Applied rewrites100.0%

    \[\leadsto \cosh \left(Ce + Ce\right) \]
  3. Add Preprocessing

Alternative 2: 82.7% accurate, 2.3× speedup?

\[\mathsf{fma}\left(\left|Ce\right| - -1, \left|Ce\right|, 0.5\right) + \frac{0.5}{1} \]
(FPCore (Ce)
  :precision binary64
  :pre TRUE
  (+ (fma (- (fabs Ce) -1.0) (fabs Ce) 0.5) (/ 0.5 1.0)))
double code(double Ce) {
	return fma((fabs(Ce) - -1.0), fabs(Ce), 0.5) + (0.5 / 1.0);
}
function code(Ce)
	return Float64(fma(Float64(abs(Ce) - -1.0), abs(Ce), 0.5) + Float64(0.5 / 1.0))
end
code[Ce_] := N[(N[(N[(N[Abs[Ce], $MachinePrecision] - -1.0), $MachinePrecision] * N[Abs[Ce], $MachinePrecision] + 0.5), $MachinePrecision] + N[(0.5 / 1.0), $MachinePrecision]), $MachinePrecision]
f(Ce):
	Ce in [-inf, +inf]
code: THEORY
BEGIN
f(Ce: real): real =
	((((abs(Ce)) - (-1)) * (abs(Ce))) + (5e-1)) + ((5e-1) / (1))
END code
\mathsf{fma}\left(\left|Ce\right| - -1, \left|Ce\right|, 0.5\right) + \frac{0.5}{1}
Derivation
  1. Initial program 100.0%

    \[0.5 \cdot e^{2 \cdot Ce} + \frac{0.5}{e^{2 \cdot Ce}} \]
  2. Taylor expanded in Ce around 0

    \[\leadsto 0.5 \cdot 1 + \frac{0.5}{1} \]
  3. Applied rewrites67.1%

    \[\leadsto 0.5 \cdot 1 + \frac{0.5}{1} \]
  4. Taylor expanded in Ce around 0

    \[\leadsto \left(\frac{1}{2} + Ce \cdot \left(1 + Ce\right)\right) + \frac{0.5}{1} \]
  5. Applied rewrites82.7%

    \[\leadsto \left(0.5 + Ce \cdot \left(1 + Ce\right)\right) + \frac{0.5}{1} \]
  6. Applied rewrites82.7%

    \[\leadsto \mathsf{fma}\left(Ce - -1, Ce, 0.5\right) + \frac{0.5}{1} \]
  7. Add Preprocessing

Alternative 3: 82.7% accurate, 2.7× speedup?

\[0.5 \cdot 1 + \mathsf{fma}\left(Ce - 1, Ce, 0.5\right) \]
(FPCore (Ce)
  :precision binary64
  :pre TRUE
  (+ (* 0.5 1.0) (fma (- Ce 1.0) Ce 0.5)))
double code(double Ce) {
	return (0.5 * 1.0) + fma((Ce - 1.0), Ce, 0.5);
}
function code(Ce)
	return Float64(Float64(0.5 * 1.0) + fma(Float64(Ce - 1.0), Ce, 0.5))
end
code[Ce_] := N[(N[(0.5 * 1.0), $MachinePrecision] + N[(N[(Ce - 1.0), $MachinePrecision] * Ce + 0.5), $MachinePrecision]), $MachinePrecision]
f(Ce):
	Ce in [-inf, +inf]
code: THEORY
BEGIN
f(Ce: real): real =
	((5e-1) * (1)) + (((Ce - (1)) * Ce) + (5e-1))
END code
0.5 \cdot 1 + \mathsf{fma}\left(Ce - 1, Ce, 0.5\right)
Derivation
  1. Initial program 100.0%

    \[0.5 \cdot e^{2 \cdot Ce} + \frac{0.5}{e^{2 \cdot Ce}} \]
  2. Taylor expanded in Ce around 0

    \[\leadsto 0.5 \cdot 1 + \frac{0.5}{1} \]
  3. Applied rewrites67.1%

    \[\leadsto 0.5 \cdot 1 + \frac{0.5}{1} \]
  4. Taylor expanded in Ce around 0

    \[\leadsto 0.5 \cdot 1 + \left(\frac{1}{2} + Ce \cdot \left(Ce - 1\right)\right) \]
  5. Applied rewrites82.7%

    \[\leadsto 0.5 \cdot 1 + \left(0.5 + Ce \cdot \left(Ce - 1\right)\right) \]
  6. Applied rewrites82.7%

    \[\leadsto 0.5 \cdot 1 + \mathsf{fma}\left(Ce - 1, Ce, 0.5\right) \]
  7. Add Preprocessing

Alternative 4: 82.7% accurate, 2.7× speedup?

\[0.5 \cdot 1 + \left(\mathsf{fma}\left(Ce, Ce, 0.5\right) - Ce\right) \]
(FPCore (Ce)
  :precision binary64
  :pre TRUE
  (+ (* 0.5 1.0) (- (fma Ce Ce 0.5) Ce)))
double code(double Ce) {
	return (0.5 * 1.0) + (fma(Ce, Ce, 0.5) - Ce);
}
function code(Ce)
	return Float64(Float64(0.5 * 1.0) + Float64(fma(Ce, Ce, 0.5) - Ce))
end
code[Ce_] := N[(N[(0.5 * 1.0), $MachinePrecision] + N[(N[(Ce * Ce + 0.5), $MachinePrecision] - Ce), $MachinePrecision]), $MachinePrecision]
f(Ce):
	Ce in [-inf, +inf]
code: THEORY
BEGIN
f(Ce: real): real =
	((5e-1) * (1)) + (((Ce * Ce) + (5e-1)) - Ce)
END code
0.5 \cdot 1 + \left(\mathsf{fma}\left(Ce, Ce, 0.5\right) - Ce\right)
Derivation
  1. Initial program 100.0%

    \[0.5 \cdot e^{2 \cdot Ce} + \frac{0.5}{e^{2 \cdot Ce}} \]
  2. Taylor expanded in Ce around 0

    \[\leadsto 0.5 \cdot 1 + \frac{0.5}{1} \]
  3. Applied rewrites67.1%

    \[\leadsto 0.5 \cdot 1 + \frac{0.5}{1} \]
  4. Taylor expanded in Ce around 0

    \[\leadsto 0.5 \cdot 1 + \left(\frac{1}{2} + Ce \cdot \left(Ce - 1\right)\right) \]
  5. Applied rewrites82.7%

    \[\leadsto 0.5 \cdot 1 + \left(0.5 + Ce \cdot \left(Ce - 1\right)\right) \]
  6. Applied rewrites82.7%

    \[\leadsto 0.5 \cdot 1 + \left(\mathsf{fma}\left(Ce, Ce, 0.5\right) - Ce\right) \]
  7. Add Preprocessing

Alternative 5: 67.1% accurate, 3.5× speedup?

\[\left(0.5 + \left|Ce\right|\right) + \frac{0.5}{1} \]
(FPCore (Ce)
  :precision binary64
  :pre TRUE
  (+ (+ 0.5 (fabs Ce)) (/ 0.5 1.0)))
double code(double Ce) {
	return (0.5 + fabs(Ce)) + (0.5 / 1.0);
}
real(8) function code(ce)
use fmin_fmax_functions
    real(8), intent (in) :: ce
    code = (0.5d0 + abs(ce)) + (0.5d0 / 1.0d0)
end function
public static double code(double Ce) {
	return (0.5 + Math.abs(Ce)) + (0.5 / 1.0);
}
def code(Ce):
	return (0.5 + math.fabs(Ce)) + (0.5 / 1.0)
function code(Ce)
	return Float64(Float64(0.5 + abs(Ce)) + Float64(0.5 / 1.0))
end
function tmp = code(Ce)
	tmp = (0.5 + abs(Ce)) + (0.5 / 1.0);
end
code[Ce_] := N[(N[(0.5 + N[Abs[Ce], $MachinePrecision]), $MachinePrecision] + N[(0.5 / 1.0), $MachinePrecision]), $MachinePrecision]
f(Ce):
	Ce in [-inf, +inf]
code: THEORY
BEGIN
f(Ce: real): real =
	((5e-1) + (abs(Ce))) + ((5e-1) / (1))
END code
\left(0.5 + \left|Ce\right|\right) + \frac{0.5}{1}
Derivation
  1. Initial program 100.0%

    \[0.5 \cdot e^{2 \cdot Ce} + \frac{0.5}{e^{2 \cdot Ce}} \]
  2. Taylor expanded in Ce around 0

    \[\leadsto 0.5 \cdot 1 + \frac{0.5}{1} \]
  3. Applied rewrites67.1%

    \[\leadsto 0.5 \cdot 1 + \frac{0.5}{1} \]
  4. Taylor expanded in Ce around 0

    \[\leadsto \left(\frac{1}{2} + Ce\right) + \frac{0.5}{1} \]
  5. Applied rewrites67.0%

    \[\leadsto \left(0.5 + Ce\right) + \frac{0.5}{1} \]
  6. Add Preprocessing

Alternative 6: 67.1% accurate, 5.2× speedup?

\[0.5 + \frac{0.5}{1} \]
(FPCore (Ce)
  :precision binary64
  :pre TRUE
  (+ 0.5 (/ 0.5 1.0)))
double code(double Ce) {
	return 0.5 + (0.5 / 1.0);
}
real(8) function code(ce)
use fmin_fmax_functions
    real(8), intent (in) :: ce
    code = 0.5d0 + (0.5d0 / 1.0d0)
end function
public static double code(double Ce) {
	return 0.5 + (0.5 / 1.0);
}
def code(Ce):
	return 0.5 + (0.5 / 1.0)
function code(Ce)
	return Float64(0.5 + Float64(0.5 / 1.0))
end
function tmp = code(Ce)
	tmp = 0.5 + (0.5 / 1.0);
end
code[Ce_] := N[(0.5 + N[(0.5 / 1.0), $MachinePrecision]), $MachinePrecision]
f(Ce):
	Ce in [-inf, +inf]
code: THEORY
BEGIN
f(Ce: real): real =
	(5e-1) + ((5e-1) / (1))
END code
0.5 + \frac{0.5}{1}
Derivation
  1. Initial program 100.0%

    \[0.5 \cdot e^{2 \cdot Ce} + \frac{0.5}{e^{2 \cdot Ce}} \]
  2. Taylor expanded in Ce around 0

    \[\leadsto 0.5 \cdot 1 + \frac{0.5}{1} \]
  3. Applied rewrites67.1%

    \[\leadsto 0.5 \cdot 1 + \frac{0.5}{1} \]
  4. Taylor expanded in Ce around 0

    \[\leadsto \frac{1}{2} + \frac{0.5}{1} \]
  5. Applied rewrites67.1%

    \[\leadsto 0.5 + \frac{0.5}{1} \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2026050 +o generate:egglog
(FPCore (Ce)
  :name "exact-inv-cosh-arg"
  :precision binary64
  (+ (* 0.5 (exp (* 2.0 Ce))) (/ 0.5 (exp (* 2.0 Ce)))))