
(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 8 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 76.1%
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 (<= a -1.02e-14) (not (<= a 4.5e-12)))
(fma t_0 1.0 (- x (tan a)))
(fma t_0 (/ 1.0 (- 1.0 (* (tan y) (tan z)))) x))))
double code(double x, double y, double z, double a) {
double t_0 = tan(y) + tan(z);
double tmp;
if ((a <= -1.02e-14) || !(a <= 4.5e-12)) {
tmp = fma(t_0, 1.0, (x - tan(a)));
} else {
tmp = fma(t_0, (1.0 / (1.0 - (tan(y) * tan(z)))), x);
}
return tmp;
}
function code(x, y, z, a) t_0 = Float64(tan(y) + tan(z)) tmp = 0.0 if ((a <= -1.02e-14) || !(a <= 4.5e-12)) tmp = fma(t_0, 1.0, Float64(x - tan(a))); else tmp = fma(t_0, Float64(1.0 / Float64(1.0 - Float64(tan(y) * tan(z)))), x); 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[a, -1.02e-14], N[Not[LessEqual[a, 4.5e-12]], $MachinePrecision]], N[(t$95$0 * 1.0 + N[(x - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(1.0 / N[(1.0 - N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan y + \tan z\\
\mathbf{if}\;a \leq -1.02 \cdot 10^{-14} \lor \neg \left(a \leq 4.5 \cdot 10^{-12}\right):\\
\;\;\;\;\mathsf{fma}\left(t_0, 1, x - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_0, \frac{1}{1 - \tan y \cdot \tan z}, x\right)\\
\end{array}
\end{array}
if a < -1.02e-14 or 4.49999999999999981e-12 < a Initial program 78.8%
+-commutative78.8%
associate-+l-78.8%
Applied egg-rr78.8%
associate--r-78.8%
sub-neg78.8%
associate-+l+78.8%
+-commutative78.8%
sub-neg78.8%
tan-sum99.6%
div-inv99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 79.6%
if -1.02e-14 < a < 4.49999999999999981e-12Initial program 72.7%
add-exp-log67.9%
+-commutative67.9%
associate-+l-67.9%
Applied egg-rr67.9%
Taylor expanded in a around 0 67.8%
Applied egg-rr99.6%
Final simplification88.6%
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (+ (tan y) (tan z))))
(if (or (<= a -1.02e-14) (not (<= a 4.2e-12)))
(fma t_0 1.0 (- x (tan a)))
(+ x (/ t_0 (- 1.0 (* (tan y) (tan z))))))))
double code(double x, double y, double z, double a) {
double t_0 = tan(y) + tan(z);
double tmp;
if ((a <= -1.02e-14) || !(a <= 4.2e-12)) {
tmp = fma(t_0, 1.0, (x - tan(a)));
} else {
tmp = x + (t_0 / (1.0 - (tan(y) * tan(z))));
}
return tmp;
}
function code(x, y, z, a) t_0 = Float64(tan(y) + tan(z)) tmp = 0.0 if ((a <= -1.02e-14) || !(a <= 4.2e-12)) tmp = fma(t_0, 1.0, Float64(x - tan(a))); else tmp = Float64(x + Float64(t_0 / Float64(1.0 - Float64(tan(y) * tan(z))))); 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[a, -1.02e-14], N[Not[LessEqual[a, 4.2e-12]], $MachinePrecision]], N[(t$95$0 * 1.0 + N[(x - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(t$95$0 / N[(1.0 - N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan y + \tan z\\
\mathbf{if}\;a \leq -1.02 \cdot 10^{-14} \lor \neg \left(a \leq 4.2 \cdot 10^{-12}\right):\\
\;\;\;\;\mathsf{fma}\left(t_0, 1, x - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{t_0}{1 - \tan y \cdot \tan z}\\
\end{array}
\end{array}
if a < -1.02e-14 or 4.19999999999999988e-12 < a Initial program 78.8%
+-commutative78.8%
associate-+l-78.8%
Applied egg-rr78.8%
associate--r-78.8%
sub-neg78.8%
associate-+l+78.8%
+-commutative78.8%
sub-neg78.8%
tan-sum99.6%
div-inv99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 79.6%
if -1.02e-14 < a < 4.19999999999999988e-12Initial program 72.7%
add-exp-log67.9%
+-commutative67.9%
associate-+l-67.9%
Applied egg-rr67.9%
Taylor expanded in a around 0 67.8%
Applied egg-rr99.6%
fma-udef99.6%
associate-*r/99.6%
*-rgt-identity99.6%
Simplified99.6%
Final simplification88.6%
(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 76.1%
+-commutative76.1%
associate-+l-76.0%
Applied egg-rr76.0%
associate--r-76.1%
sub-neg76.1%
associate-+l+76.0%
+-commutative76.0%
sub-neg76.0%
tan-sum99.6%
div-inv99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 76.8%
Final simplification76.8%
(FPCore (x y z a) :precision binary64 (if (<= y -2.9e-7) (+ x (tan (+ y z))) (+ x (- (tan z) (tan a)))))
double code(double x, double y, double z, double a) {
double tmp;
if (y <= -2.9e-7) {
tmp = x + tan((y + z));
} else {
tmp = x + (tan(z) - tan(a));
}
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 (y <= (-2.9d-7)) then
tmp = x + tan((y + z))
else
tmp = x + (tan(z) - tan(a))
end if
code = tmp
end function
public static double code(double x, double y, double z, double a) {
double tmp;
if (y <= -2.9e-7) {
tmp = x + Math.tan((y + z));
} else {
tmp = x + (Math.tan(z) - Math.tan(a));
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if y <= -2.9e-7: tmp = x + math.tan((y + z)) else: tmp = x + (math.tan(z) - math.tan(a)) return tmp
function code(x, y, z, a) tmp = 0.0 if (y <= -2.9e-7) tmp = Float64(x + tan(Float64(y + z))); else tmp = Float64(x + Float64(tan(z) - tan(a))); end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if (y <= -2.9e-7) tmp = x + tan((y + z)); else tmp = x + (tan(z) - tan(a)); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[y, -2.9e-7], N[(x + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(x + N[(N[Tan[z], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{-7}:\\
\;\;\;\;x + \tan \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(\tan z - \tan a\right)\\
\end{array}
\end{array}
if y < -2.8999999999999998e-7Initial program 57.2%
add-exp-log50.6%
+-commutative50.6%
associate-+l-50.6%
Applied egg-rr50.6%
Taylor expanded in a around 0 37.1%
rem-exp-log39.0%
tan-quot39.0%
+-commutative39.0%
Applied egg-rr39.0%
if -2.8999999999999998e-7 < y Initial program 82.5%
add-exp-log77.1%
+-commutative77.1%
associate-+l-77.1%
Applied egg-rr77.1%
Taylor expanded in y around 0 66.7%
rem-exp-log69.1%
tan-quot69.1%
associate--r-69.2%
Applied egg-rr69.2%
Final simplification61.5%
(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 76.1%
Final simplification76.1%
(FPCore (x y z a) :precision binary64 (+ x (tan (+ y z))))
double code(double x, double y, double z, double a) {
return x + 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((y + z))
end function
public static double code(double x, double y, double z, double a) {
return x + Math.tan((y + z));
}
def code(x, y, z, a): return x + math.tan((y + z))
function code(x, y, z, a) return Float64(x + tan(Float64(y + z))) end
function tmp = code(x, y, z, a) tmp = x + tan((y + z)); end
code[x_, y_, z_, a_] := N[(x + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \tan \left(y + z\right)
\end{array}
Initial program 76.1%
add-exp-log70.4%
+-commutative70.4%
associate-+l-70.4%
Applied egg-rr70.4%
Taylor expanded in a around 0 44.1%
rem-exp-log46.6%
tan-quot46.7%
+-commutative46.7%
Applied egg-rr46.7%
Final simplification46.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 76.1%
Taylor expanded in x around inf 30.0%
Final simplification30.0%
herbie shell --seed 2023310
(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))))