expfmod (used to be hard to sample)

?

Percentage Accurate: 8.5% → 8.5%
Time: 39.5s
Precision: binary64
Cost: 57856

?

\[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
\[\frac{e^{\log \log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}}{e^{x}} \]
(FPCore (x) :precision binary64 (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))
(FPCore (x)
 :precision binary64
 (/ (exp (log (log (exp (fmod (exp x) (sqrt (cos x))))))) (exp x)))
double code(double x) {
	return fmod(exp(x), sqrt(cos(x))) * exp(-x);
}
double code(double x) {
	return exp(log(log(exp(fmod(exp(x), sqrt(cos(x))))))) / exp(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = mod(exp(x), sqrt(cos(x))) * exp(-x)
end function
real(8) function code(x)
    real(8), intent (in) :: x
    code = exp(log(log(exp(mod(exp(x), sqrt(cos(x))))))) / exp(x)
end function
def code(x):
	return math.fmod(math.exp(x), math.sqrt(math.cos(x))) * math.exp(-x)
def code(x):
	return math.exp(math.log(math.log(math.exp(math.fmod(math.exp(x), math.sqrt(math.cos(x))))))) / math.exp(x)
function code(x)
	return Float64(rem(exp(x), sqrt(cos(x))) * exp(Float64(-x)))
end
function code(x)
	return Float64(exp(log(log(exp(rem(exp(x), sqrt(cos(x))))))) / exp(x))
end
code[x_] := N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[Exp[N[Log[N[Log[N[Exp[N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x}
\frac{e^{\log \log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}}{e^{x}}

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 8 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

Derivation?

  1. Initial program 7.8%

    \[\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]
  2. Simplified7.8%

    \[\leadsto \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}} \]
    Step-by-step derivation

    [Start]7.8%

    \[ \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot e^{-x} \]

    exp-neg [=>]7.8%

    \[ \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot \color{blue}{\frac{1}{e^{x}}} \]

    associate-*r/ [=>]7.8%

    \[ \color{blue}{\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right) \cdot 1}{e^{x}}} \]

    *-rgt-identity [=>]7.8%

    \[ \frac{\color{blue}{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}}{e^{x}} \]
  3. Applied egg-rr7.8%

    \[\leadsto \frac{\color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}}}{e^{x}} \]
    Step-by-step derivation

    [Start]7.8%

    \[ \frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]

    add-exp-log [=>]7.8%

    \[ \frac{\color{blue}{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}}}{e^{x}} \]
  4. Applied egg-rr7.8%

    \[\leadsto \frac{e^{\log \color{blue}{\log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}}}{e^{x}} \]
    Step-by-step derivation

    [Start]7.8%

    \[ \frac{e^{\log \left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}}{e^{x}} \]

    add-log-exp [=>]7.8%

    \[ \frac{e^{\log \color{blue}{\log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}}}{e^{x}} \]
  5. Final simplification7.8%

    \[\leadsto \frac{e^{\log \log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}}{e^{x}} \]

Alternatives

Alternative 1
Accuracy8.5%
Cost57856
\[\frac{e^{\log \log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}}{e^{x}} \]
Alternative 2
Accuracy8.5%
Cost45056
\[\frac{\log \left(e^{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}\right)}{e^{x}} \]
Alternative 3
Accuracy8.5%
Cost32512
\[\frac{\left(\left(e^{x}\right) \bmod \left(\left(\sqrt{\cos x} + 1\right) + -1\right)\right)}{e^{x}} \]
Alternative 4
Accuracy8.5%
Cost32256
\[\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}} \]
Alternative 5
Accuracy7.9%
Cost19840
\[\frac{\left(\left(e^{x}\right) \bmod \left(1 + \left(x \cdot x\right) \cdot -0.25\right)\right)}{e^{x}} \]
Alternative 6
Accuracy7.6%
Cost13568
\[\left(\left(e^{x}\right) \bmod \left(1 + \left(x \cdot x\right) \cdot -0.25\right)\right) \cdot \left(1 - x\right) \]
Alternative 7
Accuracy7.2%
Cost12928
\[\left(\left(e^{x}\right) \bmod 1\right) \]
Alternative 8
Accuracy5.5%
Cost6528
\[e^{-x} \]

Reproduce?

herbie shell --seed 2023272 
(FPCore (x)
  :name "expfmod (used to be hard to sample)"
  :precision binary64
  (* (fmod (exp x) (sqrt (cos x))) (exp (- x))))