
(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 10 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
(let* ((t_0 (* (tan z) (tan y)))
(t_1 (- 1.0 t_0))
(t_2 (/ (tan y) t_1))
(t_3 (/ (tan z) t_1))
(t_4 (+ -1.0 t_0)))
(-
x
(+
(/ (- (* (/ (tan y) t_4) t_2) (* (/ (tan z) t_4) t_3)) (- t_2 t_3))
(tan a)))))
double code(double x, double y, double z, double a) {
double t_0 = tan(z) * tan(y);
double t_1 = 1.0 - t_0;
double t_2 = tan(y) / t_1;
double t_3 = tan(z) / t_1;
double t_4 = -1.0 + t_0;
return x - (((((tan(y) / t_4) * t_2) - ((tan(z) / t_4) * t_3)) / (t_2 - t_3)) + 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
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: t_4
t_0 = tan(z) * tan(y)
t_1 = 1.0d0 - t_0
t_2 = tan(y) / t_1
t_3 = tan(z) / t_1
t_4 = (-1.0d0) + t_0
code = x - (((((tan(y) / t_4) * t_2) - ((tan(z) / t_4) * t_3)) / (t_2 - t_3)) + tan(a))
end function
public static double code(double x, double y, double z, double a) {
double t_0 = Math.tan(z) * Math.tan(y);
double t_1 = 1.0 - t_0;
double t_2 = Math.tan(y) / t_1;
double t_3 = Math.tan(z) / t_1;
double t_4 = -1.0 + t_0;
return x - (((((Math.tan(y) / t_4) * t_2) - ((Math.tan(z) / t_4) * t_3)) / (t_2 - t_3)) + Math.tan(a));
}
def code(x, y, z, a): t_0 = math.tan(z) * math.tan(y) t_1 = 1.0 - t_0 t_2 = math.tan(y) / t_1 t_3 = math.tan(z) / t_1 t_4 = -1.0 + t_0 return x - (((((math.tan(y) / t_4) * t_2) - ((math.tan(z) / t_4) * t_3)) / (t_2 - t_3)) + math.tan(a))
function code(x, y, z, a) t_0 = Float64(tan(z) * tan(y)) t_1 = Float64(1.0 - t_0) t_2 = Float64(tan(y) / t_1) t_3 = Float64(tan(z) / t_1) t_4 = Float64(-1.0 + t_0) return Float64(x - Float64(Float64(Float64(Float64(Float64(tan(y) / t_4) * t_2) - Float64(Float64(tan(z) / t_4) * t_3)) / Float64(t_2 - t_3)) + tan(a))) end
function tmp = code(x, y, z, a) t_0 = tan(z) * tan(y); t_1 = 1.0 - t_0; t_2 = tan(y) / t_1; t_3 = tan(z) / t_1; t_4 = -1.0 + t_0; tmp = x - (((((tan(y) / t_4) * t_2) - ((tan(z) / t_4) * t_3)) / (t_2 - t_3)) + tan(a)); end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[z], $MachinePrecision] * N[Tan[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Tan[y], $MachinePrecision] / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[Tan[z], $MachinePrecision] / t$95$1), $MachinePrecision]}, Block[{t$95$4 = N[(-1.0 + t$95$0), $MachinePrecision]}, N[(x - N[(N[(N[(N[(N[(N[Tan[y], $MachinePrecision] / t$95$4), $MachinePrecision] * t$95$2), $MachinePrecision] - N[(N[(N[Tan[z], $MachinePrecision] / t$95$4), $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision] / N[(t$95$2 - t$95$3), $MachinePrecision]), $MachinePrecision] + N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan z \cdot \tan y\\
t_1 := 1 - t\_0\\
t_2 := \frac{\tan y}{t\_1}\\
t_3 := \frac{\tan z}{t\_1}\\
t_4 := -1 + t\_0\\
x - \left(\frac{\frac{\tan y}{t\_4} \cdot t\_2 - \frac{\tan z}{t\_4} \cdot t\_3}{t\_2 - t\_3} + \tan a\right)
\end{array}
\end{array}
Initial program 79.0%
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z a) :precision binary64 (let* ((t_0 (fma (- (tan z)) (tan y) 1.0))) (+ x (- (/ (fma t_0 (tan z) (* t_0 (tan y))) (pow t_0 2.0)) (tan a)))))
double code(double x, double y, double z, double a) {
double t_0 = fma(-tan(z), tan(y), 1.0);
return x + ((fma(t_0, tan(z), (t_0 * tan(y))) / pow(t_0, 2.0)) - tan(a));
}
function code(x, y, z, a) t_0 = fma(Float64(-tan(z)), tan(y), 1.0) return Float64(x + Float64(Float64(fma(t_0, tan(z), Float64(t_0 * tan(y))) / (t_0 ^ 2.0)) - tan(a))) end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[((-N[Tan[z], $MachinePrecision]) * N[Tan[y], $MachinePrecision] + 1.0), $MachinePrecision]}, N[(x + N[(N[(N[(t$95$0 * N[Tan[z], $MachinePrecision] + N[(t$95$0 * N[Tan[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-\tan z, \tan y, 1\right)\\
x + \left(\frac{\mathsf{fma}\left(t\_0, \tan z, t\_0 \cdot \tan y\right)}{{t\_0}^{2}} - \tan a\right)
\end{array}
\end{array}
Initial program 79.0%
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites99.8%
lift-/.f64N/A
Applied rewrites99.7%
(FPCore (x y z a)
:precision binary64
(if (<= (tan a) -0.05)
(+ x (- (tan (+ y z)) (tan a)))
(if (<= (tan a) 1e-12)
(-
x
(+
(/ (+ (tan z) (tan y)) (+ -1.0 (* (tan z) (tan y))))
(* (fma (* a a) 0.3333333333333333 1.0) a)))
(fma (/ (- (/ (sin (+ z y)) (cos (+ z y))) (/ (sin a) (cos a))) x) x x))))
double code(double x, double y, double z, double a) {
double tmp;
if (tan(a) <= -0.05) {
tmp = x + (tan((y + z)) - tan(a));
} else if (tan(a) <= 1e-12) {
tmp = x - (((tan(z) + tan(y)) / (-1.0 + (tan(z) * tan(y)))) + (fma((a * a), 0.3333333333333333, 1.0) * a));
} else {
tmp = fma((((sin((z + y)) / cos((z + y))) - (sin(a) / cos(a))) / x), x, x);
}
return tmp;
}
function code(x, y, z, a) tmp = 0.0 if (tan(a) <= -0.05) tmp = Float64(x + Float64(tan(Float64(y + z)) - tan(a))); elseif (tan(a) <= 1e-12) tmp = Float64(x - Float64(Float64(Float64(tan(z) + tan(y)) / Float64(-1.0 + Float64(tan(z) * tan(y)))) + Float64(fma(Float64(a * a), 0.3333333333333333, 1.0) * a))); else tmp = fma(Float64(Float64(Float64(sin(Float64(z + y)) / cos(Float64(z + y))) - Float64(sin(a) / cos(a))) / x), x, x); end return tmp end
code[x_, y_, z_, a_] := If[LessEqual[N[Tan[a], $MachinePrecision], -0.05], N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Tan[a], $MachinePrecision], 1e-12], N[(x - N[(N[(N[(N[Tan[z], $MachinePrecision] + N[Tan[y], $MachinePrecision]), $MachinePrecision] / N[(-1.0 + N[(N[Tan[z], $MachinePrecision] * N[Tan[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(a * a), $MachinePrecision] * 0.3333333333333333 + 1.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[Sin[N[(z + y), $MachinePrecision]], $MachinePrecision] / N[Cos[N[(z + y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[a], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\tan a \leq -0.05:\\
\;\;\;\;x + \left(\tan \left(y + z\right) - \tan a\right)\\
\mathbf{elif}\;\tan a \leq 10^{-12}:\\
\;\;\;\;x - \left(\frac{\tan z + \tan y}{-1 + \tan z \cdot \tan y} + \mathsf{fma}\left(a \cdot a, 0.3333333333333333, 1\right) \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{\sin \left(z + y\right)}{\cos \left(z + y\right)} - \frac{\sin a}{\cos a}}{x}, x, x\right)\\
\end{array}
\end{array}
if (tan.f64 a) < -0.050000000000000003Initial program 74.9%
if -0.050000000000000003 < (tan.f64 a) < 9.9999999999999998e-13Initial program 82.8%
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-tan.f64N/A
lower-tan.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-tan.f64N/A
lower-tan.f6499.9
Applied rewrites99.9%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.9
Applied rewrites99.9%
if 9.9999999999999998e-13 < (tan.f64 a) Initial program 76.8%
Taylor expanded in x around inf
associate--l+N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
Applied rewrites76.8%
Final simplification87.1%
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (tan (+ y z))))
(if (<= (tan a) -0.0002)
(+ x (- t_0 (tan a)))
(if (<= (tan a) 0.05)
(fma (/ (+ (tan y) (tan z)) (* (fma (- (tan z)) (tan y) 1.0) x)) x x)
(+ x (- t_0 (/ (sin a) (cos a))))))))
double code(double x, double y, double z, double a) {
double t_0 = tan((y + z));
double tmp;
if (tan(a) <= -0.0002) {
tmp = x + (t_0 - tan(a));
} else if (tan(a) <= 0.05) {
tmp = fma(((tan(y) + tan(z)) / (fma(-tan(z), tan(y), 1.0) * x)), x, x);
} else {
tmp = x + (t_0 - (sin(a) / cos(a)));
}
return tmp;
}
function code(x, y, z, a) t_0 = tan(Float64(y + z)) tmp = 0.0 if (tan(a) <= -0.0002) tmp = Float64(x + Float64(t_0 - tan(a))); elseif (tan(a) <= 0.05) tmp = fma(Float64(Float64(tan(y) + tan(z)) / Float64(fma(Float64(-tan(z)), tan(y), 1.0) * x)), x, x); else tmp = Float64(x + Float64(t_0 - Float64(sin(a) / cos(a)))); end return tmp end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -0.0002], N[(x + N[(t$95$0 - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Tan[a], $MachinePrecision], 0.05], N[(N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] / N[(N[((-N[Tan[z], $MachinePrecision]) * N[Tan[y], $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] * x + x), $MachinePrecision], N[(x + N[(t$95$0 - N[(N[Sin[a], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \left(y + z\right)\\
\mathbf{if}\;\tan a \leq -0.0002:\\
\;\;\;\;x + \left(t\_0 - \tan a\right)\\
\mathbf{elif}\;\tan a \leq 0.05:\\
\;\;\;\;\mathsf{fma}\left(\frac{\tan y + \tan z}{\mathsf{fma}\left(-\tan z, \tan y, 1\right) \cdot x}, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(t\_0 - \frac{\sin a}{\cos a}\right)\\
\end{array}
\end{array}
if (tan.f64 a) < -2.0000000000000001e-4Initial program 75.5%
if -2.0000000000000001e-4 < (tan.f64 a) < 0.050000000000000003Initial program 81.3%
Taylor expanded in a around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-cos.f64N/A
+-commutativeN/A
lower-+.f6481.1
Applied rewrites81.1%
Taylor expanded in x around inf
Applied rewrites81.1%
Applied rewrites98.0%
if 0.050000000000000003 < (tan.f64 a) Initial program 78.8%
lift-tan.f64N/A
tan-quotN/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6478.8
Applied rewrites78.8%
(FPCore (x y z a) :precision binary64 (- x (+ (/ (+ (tan z) (tan y)) (+ -1.0 (* (tan z) (tan y)))) (/ (sin a) (cos a)))))
double code(double x, double y, double z, double a) {
return x - (((tan(z) + tan(y)) / (-1.0 + (tan(z) * tan(y)))) + (sin(a) / cos(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(z) + tan(y)) / ((-1.0d0) + (tan(z) * tan(y)))) + (sin(a) / cos(a)))
end function
public static double code(double x, double y, double z, double a) {
return x - (((Math.tan(z) + Math.tan(y)) / (-1.0 + (Math.tan(z) * Math.tan(y)))) + (Math.sin(a) / Math.cos(a)));
}
def code(x, y, z, a): return x - (((math.tan(z) + math.tan(y)) / (-1.0 + (math.tan(z) * math.tan(y)))) + (math.sin(a) / math.cos(a)))
function code(x, y, z, a) return Float64(x - Float64(Float64(Float64(tan(z) + tan(y)) / Float64(-1.0 + Float64(tan(z) * tan(y)))) + Float64(sin(a) / cos(a)))) end
function tmp = code(x, y, z, a) tmp = x - (((tan(z) + tan(y)) / (-1.0 + (tan(z) * tan(y)))) + (sin(a) / cos(a))); end
code[x_, y_, z_, a_] := N[(x - N[(N[(N[(N[Tan[z], $MachinePrecision] + N[Tan[y], $MachinePrecision]), $MachinePrecision] / N[(-1.0 + N[(N[Tan[z], $MachinePrecision] * N[Tan[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[a], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(\frac{\tan z + \tan y}{-1 + \tan z \cdot \tan y} + \frac{\sin a}{\cos a}\right)
\end{array}
Initial program 79.0%
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-tan.f64N/A
lower-tan.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-tan.f64N/A
lower-tan.f6499.8
Applied rewrites99.8%
lift-tan.f64N/A
tan-quotN/A
lift-cos.f64N/A
lower-/.f64N/A
lower-sin.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z a) :precision binary64 (+ x (- (/ (+ (tan z) (tan y)) (- 1.0 (* (tan z) (tan y)))) (tan a))))
double code(double x, double y, double z, double a) {
return x + (((tan(z) + tan(y)) / (1.0 - (tan(z) * tan(y)))) - 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(z) + tan(y)) / (1.0d0 - (tan(z) * tan(y)))) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
return x + (((Math.tan(z) + Math.tan(y)) / (1.0 - (Math.tan(z) * Math.tan(y)))) - Math.tan(a));
}
def code(x, y, z, a): return x + (((math.tan(z) + math.tan(y)) / (1.0 - (math.tan(z) * math.tan(y)))) - math.tan(a))
function code(x, y, z, a) return Float64(x + Float64(Float64(Float64(tan(z) + tan(y)) / Float64(1.0 - Float64(tan(z) * tan(y)))) - tan(a))) end
function tmp = code(x, y, z, a) tmp = x + (((tan(z) + tan(y)) / (1.0 - (tan(z) * tan(y)))) - tan(a)); end
code[x_, y_, z_, a_] := N[(x + N[(N[(N[(N[Tan[z], $MachinePrecision] + N[Tan[y], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[z], $MachinePrecision] * N[Tan[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \tan a\right)
\end{array}
Initial program 79.0%
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-tan.f64N/A
lower-tan.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-tan.f64N/A
lower-tan.f6499.8
Applied rewrites99.8%
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (tan (+ y z))))
(if (<= a -0.0046)
(+ x (- t_0 (tan a)))
(if (<= a 0.0072)
(-
x
(+
(/ (+ (tan z) (tan y)) (+ -1.0 (* (tan z) (tan y))))
(* (fma (* a a) 0.3333333333333333 1.0) a)))
(+ x (- t_0 (/ (sin a) (cos a))))))))
double code(double x, double y, double z, double a) {
double t_0 = tan((y + z));
double tmp;
if (a <= -0.0046) {
tmp = x + (t_0 - tan(a));
} else if (a <= 0.0072) {
tmp = x - (((tan(z) + tan(y)) / (-1.0 + (tan(z) * tan(y)))) + (fma((a * a), 0.3333333333333333, 1.0) * a));
} else {
tmp = x + (t_0 - (sin(a) / cos(a)));
}
return tmp;
}
function code(x, y, z, a) t_0 = tan(Float64(y + z)) tmp = 0.0 if (a <= -0.0046) tmp = Float64(x + Float64(t_0 - tan(a))); elseif (a <= 0.0072) tmp = Float64(x - Float64(Float64(Float64(tan(z) + tan(y)) / Float64(-1.0 + Float64(tan(z) * tan(y)))) + Float64(fma(Float64(a * a), 0.3333333333333333, 1.0) * a))); else tmp = Float64(x + Float64(t_0 - Float64(sin(a) / cos(a)))); end return tmp end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[a, -0.0046], N[(x + N[(t$95$0 - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 0.0072], N[(x - N[(N[(N[(N[Tan[z], $MachinePrecision] + N[Tan[y], $MachinePrecision]), $MachinePrecision] / N[(-1.0 + N[(N[Tan[z], $MachinePrecision] * N[Tan[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(a * a), $MachinePrecision] * 0.3333333333333333 + 1.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(t$95$0 - N[(N[Sin[a], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \left(y + z\right)\\
\mathbf{if}\;a \leq -0.0046:\\
\;\;\;\;x + \left(t\_0 - \tan a\right)\\
\mathbf{elif}\;a \leq 0.0072:\\
\;\;\;\;x - \left(\frac{\tan z + \tan y}{-1 + \tan z \cdot \tan y} + \mathsf{fma}\left(a \cdot a, 0.3333333333333333, 1\right) \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(t\_0 - \frac{\sin a}{\cos a}\right)\\
\end{array}
\end{array}
if a < -0.0045999999999999999Initial program 74.5%
if -0.0045999999999999999 < a < 0.0071999999999999998Initial program 82.8%
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-tan.f64N/A
lower-tan.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-tan.f64N/A
lower-tan.f6499.9
Applied rewrites99.9%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.9
Applied rewrites99.9%
if 0.0071999999999999998 < a Initial program 76.9%
lift-tan.f64N/A
tan-quotN/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6476.9
Applied rewrites76.9%
Final simplification87.1%
(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.0%
(FPCore (x y z a) :precision binary64 (fma (/ (tan (+ y z)) x) x x))
double code(double x, double y, double z, double a) {
return fma((tan((y + z)) / x), x, x);
}
function code(x, y, z, a) return fma(Float64(tan(Float64(y + z)) / x), x, x) end
code[x_, y_, z_, a_] := N[(N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision] * x + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{\tan \left(y + z\right)}{x}, x, x\right)
\end{array}
Initial program 79.0%
Taylor expanded in a around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-cos.f64N/A
+-commutativeN/A
lower-+.f6450.6
Applied rewrites50.6%
Taylor expanded in x around inf
Applied rewrites50.6%
Applied rewrites50.6%
(FPCore (x y z a) :precision binary64 (+ (tan (+ z y)) x))
double code(double x, double y, double z, double a) {
return tan((z + y)) + 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 = tan((z + y)) + x
end function
public static double code(double x, double y, double z, double a) {
return Math.tan((z + y)) + x;
}
def code(x, y, z, a): return math.tan((z + y)) + x
function code(x, y, z, a) return Float64(tan(Float64(z + y)) + x) end
function tmp = code(x, y, z, a) tmp = tan((z + y)) + x; end
code[x_, y_, z_, a_] := N[(N[Tan[N[(z + y), $MachinePrecision]], $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\tan \left(z + y\right) + x
\end{array}
Initial program 79.0%
Taylor expanded in a around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-cos.f64N/A
+-commutativeN/A
lower-+.f6450.6
Applied rewrites50.6%
Applied rewrites50.6%
herbie shell --seed 2024344
(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))))