
(FPCore (x y z a) :precision binary64 (+ x (- (tan (+ y z)) (tan a))))
double code(double x, double y, double z, double a) {
return x + (tan((y + z)) - tan(a));
}
real(8) function code(x, y, z, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: a
code = x + (tan((y + z)) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
return x + (Math.tan((y + z)) - Math.tan(a));
}
def code(x, y, z, a): return x + (math.tan((y + z)) - math.tan(a))
function code(x, y, z, a) return Float64(x + Float64(tan(Float64(y + z)) - tan(a))) end
function tmp = code(x, y, z, a) tmp = x + (tan((y + z)) - tan(a)); end
code[x_, y_, z_, a_] := N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\tan \left(y + z\right) - \tan a\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z a) :precision binary64 (+ x (- (tan (+ y z)) (tan a))))
double code(double x, double y, double z, double a) {
return x + (tan((y + z)) - tan(a));
}
real(8) function code(x, y, z, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: a
code = x + (tan((y + z)) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
return x + (Math.tan((y + z)) - Math.tan(a));
}
def code(x, y, z, a): return x + (math.tan((y + z)) - math.tan(a))
function code(x, y, z, a) return Float64(x + Float64(tan(Float64(y + z)) - tan(a))) end
function tmp = code(x, y, z, a) tmp = x + (tan((y + z)) - tan(a)); end
code[x_, y_, z_, a_] := N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\tan \left(y + z\right) - \tan a\right)
\end{array}
(FPCore (x y z a) :precision binary64 (+ x (- (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z)))) (tan a))))
double code(double x, double y, double z, double a) {
return x + (((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) - tan(a));
}
real(8) function code(x, y, z, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: a
code = x + (((tan(y) + tan(z)) / (1.0d0 - (tan(y) * tan(z)))) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
return x + (((Math.tan(y) + Math.tan(z)) / (1.0 - (Math.tan(y) * Math.tan(z)))) - Math.tan(a));
}
def code(x, y, z, a): return x + (((math.tan(y) + math.tan(z)) / (1.0 - (math.tan(y) * math.tan(z)))) - math.tan(a))
function code(x, y, z, a) return Float64(x + Float64(Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z)))) - tan(a))) end
function tmp = code(x, y, z, a) tmp = x + (((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) - tan(a)); end
code[x_, y_, z_, a_] := N[(x + N[(N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - \tan a\right)
\end{array}
Initial program 79.5%
tan-sum99.7%
div-inv99.7%
Applied egg-rr99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (+ (tan y) (tan z))))
(if (or (<= (tan a) -0.0005) (not (<= (tan a) 5e-5)))
(fma t_0 1.0 (- x (tan a)))
(+ x (- (/ t_0 (- 1.0 (* (tan y) (tan z)))) a)))))
double code(double x, double y, double z, double a) {
double t_0 = tan(y) + tan(z);
double tmp;
if ((tan(a) <= -0.0005) || !(tan(a) <= 5e-5)) {
tmp = fma(t_0, 1.0, (x - tan(a)));
} else {
tmp = x + ((t_0 / (1.0 - (tan(y) * tan(z)))) - a);
}
return tmp;
}
function code(x, y, z, a) t_0 = Float64(tan(y) + tan(z)) tmp = 0.0 if ((tan(a) <= -0.0005) || !(tan(a) <= 5e-5)) tmp = fma(t_0, 1.0, Float64(x - tan(a))); else tmp = Float64(x + Float64(Float64(t_0 / Float64(1.0 - Float64(tan(y) * tan(z)))) - a)); end return tmp end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[N[Tan[a], $MachinePrecision], -0.0005], N[Not[LessEqual[N[Tan[a], $MachinePrecision], 5e-5]], $MachinePrecision]], N[(t$95$0 * 1.0 + N[(x - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(t$95$0 / N[(1.0 - N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan y + \tan z\\
\mathbf{if}\;\tan a \leq -0.0005 \lor \neg \left(\tan a \leq 5 \cdot 10^{-5}\right):\\
\;\;\;\;\mathsf{fma}\left(t_0, 1, x - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(\frac{t_0}{1 - \tan y \cdot \tan z} - a\right)\\
\end{array}
\end{array}
if (tan.f64 a) < -5.0000000000000001e-4 or 5.00000000000000024e-5 < (tan.f64 a) Initial program 78.9%
associate-+r-78.8%
+-commutative78.8%
associate--l+78.8%
tan-sum99.5%
div-inv99.5%
fma-def99.5%
Applied egg-rr99.5%
Taylor expanded in y around 0 79.4%
if -5.0000000000000001e-4 < (tan.f64 a) < 5.00000000000000024e-5Initial program 80.0%
Taylor expanded in a around 0 80.0%
tan-sum99.7%
div-inv99.6%
fma-neg99.6%
Applied egg-rr99.6%
fma-udef99.6%
unsub-neg99.6%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
Final simplification89.9%
(FPCore (x y z a) :precision binary64 (fma (+ (tan y) (tan z)) 1.0 (- x (tan a))))
double code(double x, double y, double z, double a) {
return fma((tan(y) + tan(z)), 1.0, (x - tan(a)));
}
function code(x, y, z, a) return fma(Float64(tan(y) + tan(z)), 1.0, Float64(x - tan(a))) end
code[x_, y_, z_, a_] := N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] * 1.0 + N[(x - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\tan y + \tan z, 1, x - \tan a\right)
\end{array}
Initial program 79.5%
associate-+r-79.4%
+-commutative79.4%
associate--l+79.4%
tan-sum99.6%
div-inv99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 79.8%
Final simplification79.8%
(FPCore (x y z a) :precision binary64 (+ x (+ (tan a) (tan (+ y z)))))
double code(double x, double y, double z, double a) {
return x + (tan(a) + tan((y + z)));
}
real(8) function code(x, y, z, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: a
code = x + (tan(a) + tan((y + z)))
end function
public static double code(double x, double y, double z, double a) {
return x + (Math.tan(a) + Math.tan((y + z)));
}
def code(x, y, z, a): return x + (math.tan(a) + math.tan((y + z)))
function code(x, y, z, a) return Float64(x + Float64(tan(a) + tan(Float64(y + z)))) end
function tmp = code(x, y, z, a) tmp = x + (tan(a) + tan((y + z))); end
code[x_, y_, z_, a_] := N[(x + N[(N[Tan[a], $MachinePrecision] + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\tan a + \tan \left(y + z\right)\right)
\end{array}
Initial program 79.5%
+-commutative79.5%
associate-+l-79.4%
Applied egg-rr79.4%
associate-+l-79.5%
+-commutative79.5%
sub-neg79.5%
associate-+r+79.4%
rem-square-sqrt37.4%
fabs-sqr37.4%
rem-square-sqrt65.0%
fabs-neg65.0%
rem-square-sqrt27.5%
fabs-sqr27.5%
rem-square-sqrt51.6%
associate-+l+51.6%
+-commutative51.6%
Simplified51.6%
Final simplification51.6%
(FPCore (x y z a) :precision binary64 (+ x (- (tan (+ y z)) (tan a))))
double code(double x, double y, double z, double a) {
return x + (tan((y + z)) - tan(a));
}
real(8) function code(x, y, z, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: a
code = x + (tan((y + z)) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
return x + (Math.tan((y + z)) - Math.tan(a));
}
def code(x, y, z, a): return x + (math.tan((y + z)) - math.tan(a))
function code(x, y, z, a) return Float64(x + Float64(tan(Float64(y + z)) - tan(a))) end
function tmp = code(x, y, z, a) tmp = x + (tan((y + z)) - tan(a)); end
code[x_, y_, z_, a_] := N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\tan \left(y + z\right) - \tan a\right)
\end{array}
Initial program 79.5%
Final simplification79.5%
(FPCore (x y z a) :precision binary64 (if (<= a -5.0) x (if (<= a 1.48e-19) (+ x (- (tan (+ y z)) a)) x)))
double code(double x, double y, double z, double a) {
double tmp;
if (a <= -5.0) {
tmp = x;
} else if (a <= 1.48e-19) {
tmp = x + (tan((y + z)) - a);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: a
real(8) :: tmp
if (a <= (-5.0d0)) then
tmp = x
else if (a <= 1.48d-19) then
tmp = x + (tan((y + z)) - a)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double a) {
double tmp;
if (a <= -5.0) {
tmp = x;
} else if (a <= 1.48e-19) {
tmp = x + (Math.tan((y + z)) - a);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if a <= -5.0: tmp = x elif a <= 1.48e-19: tmp = x + (math.tan((y + z)) - a) else: tmp = x return tmp
function code(x, y, z, a) tmp = 0.0 if (a <= -5.0) tmp = x; elseif (a <= 1.48e-19) tmp = Float64(x + Float64(tan(Float64(y + z)) - a)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if (a <= -5.0) tmp = x; elseif (a <= 1.48e-19) tmp = x + (tan((y + z)) - a); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[a, -5.0], x, If[LessEqual[a, 1.48e-19], N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5:\\
\;\;\;\;x\\
\mathbf{elif}\;a \leq 1.48 \cdot 10^{-19}:\\
\;\;\;\;x + \left(\tan \left(y + z\right) - a\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if a < -5 or 1.48e-19 < a Initial program 78.0%
Taylor expanded in x around inf 21.7%
if -5 < a < 1.48e-19Initial program 80.9%
Taylor expanded in a around 0 80.8%
Final simplification51.7%
(FPCore (x y z a) :precision binary64 x)
double code(double x, double y, double z, double a) {
return x;
}
real(8) function code(x, y, z, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: a
code = x
end function
public static double code(double x, double y, double z, double a) {
return x;
}
def code(x, y, z, a): return x
function code(x, y, z, a) return x end
function tmp = code(x, y, z, a) tmp = x; end
code[x_, y_, z_, a_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 79.5%
Taylor expanded in x around inf 32.4%
Final simplification32.4%
herbie shell --seed 2023238
(FPCore (x y z a)
:name "tan-example (used to crash)"
:precision binary64
:pre (and (and (and (or (== x 0.0) (and (<= 0.5884142 x) (<= x 505.5909))) (or (and (<= -1.796658e+308 y) (<= y -9.425585e-310)) (and (<= 1.284938e-309 y) (<= y 1.751224e+308)))) (or (and (<= -1.776707e+308 z) (<= z -8.599796e-310)) (and (<= 3.293145e-311 z) (<= z 1.725154e+308)))) (or (and (<= -1.796658e+308 a) (<= a -9.425585e-310)) (and (<= 1.284938e-309 a) (<= a 1.751224e+308))))
(+ x (- (tan (+ y z)) (tan a))))