Example 2 from Robby

?

Percentage Accurate: 99.8% → 99.8%
Time: 24.9s
Precision: binary64
Cost: 71680

?

\[\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
\[\left|\left(ew \cdot \cos t\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \tan^{-1} \left(\frac{eh}{ew} \cdot \tan t\right)\right)\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{eh \cdot \left(-\tan t\right)}{ew}\right)\right| \]
(FPCore (eh ew t)
 :precision binary64
 (fabs
  (-
   (* (* ew (cos t)) (cos (atan (/ (* (- eh) (tan t)) ew))))
   (* (* eh (sin t)) (sin (atan (/ (* (- eh) (tan t)) ew)))))))
(FPCore (eh ew t)
 :precision binary64
 (fabs
  (-
   (* (* ew (cos t)) (expm1 (log1p (cos (atan (* (/ eh ew) (tan t)))))))
   (* (* eh (sin t)) (sin (atan (/ (* eh (- (tan t))) ew)))))))
double code(double eh, double ew, double t) {
	return fabs((((ew * cos(t)) * cos(atan(((-eh * tan(t)) / ew)))) - ((eh * sin(t)) * sin(atan(((-eh * tan(t)) / ew))))));
}
double code(double eh, double ew, double t) {
	return fabs((((ew * cos(t)) * expm1(log1p(cos(atan(((eh / ew) * tan(t))))))) - ((eh * sin(t)) * sin(atan(((eh * -tan(t)) / ew))))));
}
public static double code(double eh, double ew, double t) {
	return Math.abs((((ew * Math.cos(t)) * Math.cos(Math.atan(((-eh * Math.tan(t)) / ew)))) - ((eh * Math.sin(t)) * Math.sin(Math.atan(((-eh * Math.tan(t)) / ew))))));
}
public static double code(double eh, double ew, double t) {
	return Math.abs((((ew * Math.cos(t)) * Math.expm1(Math.log1p(Math.cos(Math.atan(((eh / ew) * Math.tan(t))))))) - ((eh * Math.sin(t)) * Math.sin(Math.atan(((eh * -Math.tan(t)) / ew))))));
}
def code(eh, ew, t):
	return math.fabs((((ew * math.cos(t)) * math.cos(math.atan(((-eh * math.tan(t)) / ew)))) - ((eh * math.sin(t)) * math.sin(math.atan(((-eh * math.tan(t)) / ew))))))
def code(eh, ew, t):
	return math.fabs((((ew * math.cos(t)) * math.expm1(math.log1p(math.cos(math.atan(((eh / ew) * math.tan(t))))))) - ((eh * math.sin(t)) * math.sin(math.atan(((eh * -math.tan(t)) / ew))))))
function code(eh, ew, t)
	return abs(Float64(Float64(Float64(ew * cos(t)) * cos(atan(Float64(Float64(Float64(-eh) * tan(t)) / ew)))) - Float64(Float64(eh * sin(t)) * sin(atan(Float64(Float64(Float64(-eh) * tan(t)) / ew))))))
end
function code(eh, ew, t)
	return abs(Float64(Float64(Float64(ew * cos(t)) * expm1(log1p(cos(atan(Float64(Float64(eh / ew) * tan(t))))))) - Float64(Float64(eh * sin(t)) * sin(atan(Float64(Float64(eh * Float64(-tan(t))) / ew))))))
end
code[eh_, ew_, t_] := N[Abs[N[(N[(N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision] * N[Cos[N[ArcTan[N[(N[((-eh) * N[Tan[t], $MachinePrecision]), $MachinePrecision] / ew), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[(eh * N[Sin[t], $MachinePrecision]), $MachinePrecision] * N[Sin[N[ArcTan[N[(N[((-eh) * N[Tan[t], $MachinePrecision]), $MachinePrecision] / ew), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[eh_, ew_, t_] := N[Abs[N[(N[(N[(ew * N[Cos[t], $MachinePrecision]), $MachinePrecision] * N[(Exp[N[Log[1 + N[Cos[N[ArcTan[N[(N[(eh / ew), $MachinePrecision] * N[Tan[t], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] - N[(N[(eh * N[Sin[t], $MachinePrecision]), $MachinePrecision] * N[Sin[N[ArcTan[N[(N[(eh * (-N[Tan[t], $MachinePrecision])), $MachinePrecision] / ew), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right|
\left|\left(ew \cdot \cos t\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \tan^{-1} \left(\frac{eh}{ew} \cdot \tan t\right)\right)\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{eh \cdot \left(-\tan t\right)}{ew}\right)\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 12 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

Derivation?

  1. Initial program 99.8%

    \[\left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
  2. Applied egg-rr99.8%

    \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \tan^{-1} \left(\frac{eh}{ew} \cdot \tan t\right)\right)\right)} - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
    Step-by-step derivation

    [Start]99.8%

    \[ \left|\left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]

    expm1-log1p-u [=>]99.8%

    \[ \left|\left(ew \cdot \cos t\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\cos \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right)\right)} - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]

    associate-/l* [=>]99.8%

    \[ \left|\left(ew \cdot \cos t\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \tan^{-1} \color{blue}{\left(\frac{-eh}{\frac{ew}{\tan t}}\right)}\right)\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]

    associate-/r/ [=>]99.8%

    \[ \left|\left(ew \cdot \cos t\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \tan^{-1} \color{blue}{\left(\frac{-eh}{ew} \cdot \tan t\right)}\right)\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]

    add-sqr-sqrt [=>]43.3%

    \[ \left|\left(ew \cdot \cos t\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \tan^{-1} \left(\frac{\color{blue}{\sqrt{-eh} \cdot \sqrt{-eh}}}{ew} \cdot \tan t\right)\right)\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]

    sqrt-unprod [=>]93.0%

    \[ \left|\left(ew \cdot \cos t\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \tan^{-1} \left(\frac{\color{blue}{\sqrt{\left(-eh\right) \cdot \left(-eh\right)}}}{ew} \cdot \tan t\right)\right)\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]

    sqr-neg [=>]93.0%

    \[ \left|\left(ew \cdot \cos t\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \tan^{-1} \left(\frac{\sqrt{\color{blue}{eh \cdot eh}}}{ew} \cdot \tan t\right)\right)\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]

    sqrt-unprod [<=]56.5%

    \[ \left|\left(ew \cdot \cos t\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \tan^{-1} \left(\frac{\color{blue}{\sqrt{eh} \cdot \sqrt{eh}}}{ew} \cdot \tan t\right)\right)\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]

    add-sqr-sqrt [<=]99.8%

    \[ \left|\left(ew \cdot \cos t\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \tan^{-1} \left(\frac{\color{blue}{eh}}{ew} \cdot \tan t\right)\right)\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{\left(-eh\right) \cdot \tan t}{ew}\right)\right| \]
  3. Final simplification99.8%

    \[\leadsto \left|\left(ew \cdot \cos t\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \tan^{-1} \left(\frac{eh}{ew} \cdot \tan t\right)\right)\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{eh \cdot \left(-\tan t\right)}{ew}\right)\right| \]

Alternatives

Alternative 1
Accuracy99.8%
Cost71680
\[\left|\left(ew \cdot \cos t\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\cos \tan^{-1} \left(\frac{eh}{ew} \cdot \tan t\right)\right)\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{eh \cdot \left(-\tan t\right)}{ew}\right)\right| \]
Alternative 2
Accuracy99.8%
Cost58944
\[\begin{array}{l} t_1 := \tan^{-1} \left(\frac{eh \cdot \left(-\tan t\right)}{ew}\right)\\ \left|\left(ew \cdot \cos t\right) \cdot \cos t_1 - \left(eh \cdot \sin t\right) \cdot \sin t_1\right| \end{array} \]
Alternative 3
Accuracy99.8%
Cost52672
\[\left|\left(ew \cdot \cos t\right) \cdot \frac{1}{\mathsf{hypot}\left(1, \frac{eh \cdot \tan t}{ew}\right)} - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{eh \cdot \left(-\tan t\right)}{ew}\right)\right| \]
Alternative 4
Accuracy99.0%
Cost52544
\[\left|\left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{t \cdot \left(-eh\right)}{ew}\right) - \left(ew \cdot \cos t\right) \cdot \cos \tan^{-1} \left(\frac{eh \cdot \left(-\tan t\right)}{ew}\right)\right| \]
Alternative 5
Accuracy99.0%
Cost46272
\[\left|\left(ew \cdot \cos t\right) \cdot \frac{1}{\mathsf{hypot}\left(1, \frac{eh \cdot \tan t}{ew}\right)} - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{t \cdot \left(-eh\right)}{ew}\right)\right| \]
Alternative 6
Accuracy98.6%
Cost46208
\[\left|\left(ew \cdot \cos t\right) \cdot \frac{1}{\mathsf{hypot}\left(1, \frac{eh \cdot \tan t}{ew}\right)} - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(eh \cdot \frac{t}{ew}\right)\right| \]
Alternative 7
Accuracy82.0%
Cost46148
\[\begin{array}{l} t_1 := \sin \tan^{-1} \left(\frac{t \cdot \left(-eh\right)}{ew}\right)\\ \mathbf{if}\;ew \leq 3.8 \cdot 10^{+84}:\\ \;\;\;\;\left|ew \cdot \cos \tan^{-1} \left(\frac{eh \cdot \left(-\tan t\right)}{ew}\right) - \left(eh \cdot \sin t\right) \cdot t_1\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\left(t \cdot eh\right) \cdot t_1 + \left(ew \cdot \cos t\right) \cdot \frac{-1}{\mathsf{hypot}\left(1, \frac{eh \cdot \tan t}{ew}\right)}\right|\\ \end{array} \]
Alternative 8
Accuracy82.0%
Cost40004
\[\begin{array}{l} t_1 := \mathsf{hypot}\left(1, \frac{eh \cdot \tan t}{ew}\right)\\ t_2 := \sin \tan^{-1} \left(\frac{t \cdot \left(-eh\right)}{ew}\right)\\ \mathbf{if}\;ew \leq 1.25 \cdot 10^{+84}:\\ \;\;\;\;\left|\left(eh \cdot \sin t\right) \cdot t_2 - ew \cdot \frac{1}{t_1}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\left(t \cdot eh\right) \cdot t_2 + \left(ew \cdot \cos t\right) \cdot \frac{-1}{t_1}\right|\\ \end{array} \]
Alternative 9
Accuracy79.8%
Cost39744
\[\left|\left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{t \cdot \left(-eh\right)}{ew}\right) - ew \cdot \frac{1}{\mathsf{hypot}\left(1, \frac{eh \cdot \tan t}{ew}\right)}\right| \]
Alternative 10
Accuracy78.7%
Cost39552
\[\left|ew \cdot \cos \tan^{-1} \left(eh \cdot \frac{t}{ew}\right) - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{t \cdot \left(-eh\right)}{ew}\right)\right| \]
Alternative 11
Accuracy78.5%
Cost33344
\[\left|ew \cdot \frac{1}{\mathsf{hypot}\left(1, \frac{t}{\frac{ew}{eh}}\right)} - \left(eh \cdot \sin t\right) \cdot \sin \tan^{-1} \left(\frac{t \cdot \left(-eh\right)}{ew}\right)\right| \]
Alternative 12
Accuracy55.3%
Cost33216
\[\begin{array}{l} t_1 := \tan^{-1} \left(\frac{t \cdot \left(-eh\right)}{ew}\right)\\ \left|ew \cdot \cos t_1 - \left(t \cdot eh\right) \cdot \sin t_1\right| \end{array} \]

Reproduce?

herbie shell --seed 2023272 
(FPCore (eh ew t)
  :name "Example 2 from Robby"
  :precision binary64
  (fabs (- (* (* ew (cos t)) (cos (atan (/ (* (- eh) (tan t)) ew)))) (* (* eh (sin t)) (sin (atan (/ (* (- eh) (tan t)) ew)))))))