expax (section 3.5)

?

Percentage Accurate: 65.9% → 100.0%
Time: 4.7s
Precision: binary64
Cost: 6592

?

\[e^{a \cdot x} - 1 \]
\[\mathsf{expm1}\left(a \cdot x\right) \]
(FPCore (a x) :precision binary64 (- (exp (* a x)) 1.0))
(FPCore (a x) :precision binary64 (expm1 (* a x)))
double code(double a, double x) {
	return exp((a * x)) - 1.0;
}
double code(double a, double x) {
	return expm1((a * x));
}
public static double code(double a, double x) {
	return Math.exp((a * x)) - 1.0;
}
public static double code(double a, double x) {
	return Math.expm1((a * x));
}
def code(a, x):
	return math.exp((a * x)) - 1.0
def code(a, x):
	return math.expm1((a * x))
function code(a, x)
	return Float64(exp(Float64(a * x)) - 1.0)
end
function code(a, x)
	return expm1(Float64(a * x))
end
code[a_, x_] := N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]
code[a_, x_] := N[(Exp[N[(a * x), $MachinePrecision]] - 1), $MachinePrecision]
e^{a \cdot x} - 1
\mathsf{expm1}\left(a \cdot x\right)

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.

Herbie found 4 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original65.9%
Target99.8%
Herbie100.0%
\[\begin{array}{l} \mathbf{if}\;\left|a \cdot x\right| < 0.1:\\ \;\;\;\;\left(a \cdot x\right) \cdot \left(1 + \left(\frac{a \cdot x}{2} + \frac{{\left(a \cdot x\right)}^{2}}{6}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;e^{a \cdot x} - 1\\ \end{array} \]

Derivation?

  1. Initial program 62.3%

    \[e^{a \cdot x} - 1 \]
  2. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{expm1}\left(a \cdot x\right)} \]
    Step-by-step derivation

    [Start]62.3%

    \[ e^{a \cdot x} - 1 \]

    expm1-def [=>]100.0%

    \[ \color{blue}{\mathsf{expm1}\left(a \cdot x\right)} \]
  3. Final simplification100.0%

    \[\leadsto \mathsf{expm1}\left(a \cdot x\right) \]

Alternatives

Alternative 1
Accuracy100.0%
Cost6592
\[\mathsf{expm1}\left(a \cdot x\right) \]
Alternative 2
Accuracy67.8%
Cost964
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq 10^{-13}:\\ \;\;\;\;a \cdot x\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(x + a \cdot \left(x \cdot \left(x \cdot 0.5\right)\right)\right)\\ \end{array} \]
Alternative 3
Accuracy67.7%
Cost836
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq 2 \cdot 10^{+51}:\\ \;\;\;\;a \cdot x\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(x \cdot x\right) \cdot \left(a \cdot a\right)\right)\\ \end{array} \]
Alternative 4
Accuracy57.3%
Cost192
\[a \cdot x \]

Reproduce?

herbie shell --seed 2023271 
(FPCore (a x)
  :name "expax (section 3.5)"
  :precision binary64

  :herbie-target
  (if (< (fabs (* a x)) 0.1) (* (* a x) (+ 1.0 (+ (/ (* a x) 2.0) (/ (pow (* a x) 2.0) 6.0)))) (- (exp (* a x)) 1.0))

  (- (exp (* a x)) 1.0))