
(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 13 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}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (* (tan y) (tan z))))
(fma
(+ (* (cos a) (tan y)) (fma (cos a) (tan z) (* (sin a) (+ t_0 -1.0))))
(/ 1.0 (* (cos a) (- 1.0 t_0)))
x)))assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double t_0 = tan(y) * tan(z);
return fma(((cos(a) * tan(y)) + fma(cos(a), tan(z), (sin(a) * (t_0 + -1.0)))), (1.0 / (cos(a) * (1.0 - t_0))), x);
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) t_0 = Float64(tan(y) * tan(z)) return fma(Float64(Float64(cos(a) * tan(y)) + fma(cos(a), tan(z), Float64(sin(a) * Float64(t_0 + -1.0)))), Float64(1.0 / Float64(cos(a) * Float64(1.0 - t_0))), x) end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[Cos[a], $MachinePrecision] * N[Tan[y], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[a], $MachinePrecision] * N[Tan[z], $MachinePrecision] + N[(N[Sin[a], $MachinePrecision] * N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(N[Cos[a], $MachinePrecision] * N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := \tan y \cdot \tan z\\
\mathsf{fma}\left(\cos a \cdot \tan y + \mathsf{fma}\left(\cos a, \tan z, \sin a \cdot \left(t\_0 + -1\right)\right), \frac{1}{\cos a \cdot \left(1 - t\_0\right)}, x\right)
\end{array}
\end{array}
Initial program 82.7%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
lift-tan.f64N/A
tan-quotN/A
frac-subN/A
div-invN/A
lower-fma.f64N/A
Applied rewrites99.7%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lift-+.f64N/A
distribute-lft-inN/A
associate-+l+N/A
lower-+.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
lower-neg.f6499.7
Applied rewrites99.7%
Final simplification99.7%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (* (tan y) (tan z))))
(fma
(+ (* (sin a) (+ t_0 -1.0)) (* (cos a) (+ (tan y) (tan z))))
(/ 1.0 (* (cos a) (- 1.0 t_0)))
x)))assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double t_0 = tan(y) * tan(z);
return fma(((sin(a) * (t_0 + -1.0)) + (cos(a) * (tan(y) + tan(z)))), (1.0 / (cos(a) * (1.0 - t_0))), x);
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) t_0 = Float64(tan(y) * tan(z)) return fma(Float64(Float64(sin(a) * Float64(t_0 + -1.0)) + Float64(cos(a) * Float64(tan(y) + tan(z)))), Float64(1.0 / Float64(cos(a) * Float64(1.0 - t_0))), x) end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[Sin[a], $MachinePrecision] * N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[a], $MachinePrecision] * N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(N[Cos[a], $MachinePrecision] * N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := \tan y \cdot \tan z\\
\mathsf{fma}\left(\sin a \cdot \left(t\_0 + -1\right) + \cos a \cdot \left(\tan y + \tan z\right), \frac{1}{\cos a \cdot \left(1 - t\_0\right)}, x\right)
\end{array}
\end{array}
Initial program 82.7%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
lift-tan.f64N/A
tan-quotN/A
frac-subN/A
div-invN/A
lower-fma.f64N/A
Applied rewrites99.7%
Final simplification99.7%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (* (tan y) (tan z))))
(+
x
(/
(fma (cos a) (+ (tan y) (tan z)) (* (sin a) (+ t_0 -1.0)))
(* (cos a) (- 1.0 t_0))))))assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double t_0 = tan(y) * tan(z);
return x + (fma(cos(a), (tan(y) + tan(z)), (sin(a) * (t_0 + -1.0))) / (cos(a) * (1.0 - t_0)));
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) t_0 = Float64(tan(y) * tan(z)) return Float64(x + Float64(fma(cos(a), Float64(tan(y) + tan(z)), Float64(sin(a) * Float64(t_0 + -1.0))) / Float64(cos(a) * Float64(1.0 - t_0)))) end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]}, N[(x + N[(N[(N[Cos[a], $MachinePrecision] * N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[a], $MachinePrecision] * N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[a], $MachinePrecision] * N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := \tan y \cdot \tan z\\
x + \frac{\mathsf{fma}\left(\cos a, \tan y + \tan z, \sin a \cdot \left(t\_0 + -1\right)\right)}{\cos a \cdot \left(1 - t\_0\right)}
\end{array}
\end{array}
Initial program 82.7%
lift--.f64N/A
sub-negN/A
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
lift-tan.f64N/A
tan-quotN/A
distribute-neg-fracN/A
frac-addN/A
lower-/.f64N/A
Applied rewrites99.7%
Final simplification99.7%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (tan (+ y z))))
(if (<= (tan a) -0.005)
(+ x (- t_0 (tan a)))
(if (<= (tan a) 5e-15)
(fma
(+ (tan y) (tan z))
(/ 1.0 (- 1.0 (* (tan y) (tan z))))
(- x (fma (* a a) (* a 0.3333333333333333) a)))
(+ x (fma (sin a) (/ -1.0 (cos a)) t_0))))))assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double t_0 = tan((y + z));
double tmp;
if (tan(a) <= -0.005) {
tmp = x + (t_0 - tan(a));
} else if (tan(a) <= 5e-15) {
tmp = fma((tan(y) + tan(z)), (1.0 / (1.0 - (tan(y) * tan(z)))), (x - fma((a * a), (a * 0.3333333333333333), a)));
} else {
tmp = x + fma(sin(a), (-1.0 / cos(a)), t_0);
}
return tmp;
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) t_0 = tan(Float64(y + z)) tmp = 0.0 if (tan(a) <= -0.005) tmp = Float64(x + Float64(t_0 - tan(a))); elseif (tan(a) <= 5e-15) tmp = fma(Float64(tan(y) + tan(z)), Float64(1.0 / Float64(1.0 - Float64(tan(y) * tan(z)))), Float64(x - fma(Float64(a * a), Float64(a * 0.3333333333333333), a))); else tmp = Float64(x + fma(sin(a), Float64(-1.0 / cos(a)), t_0)); end return tmp end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -0.005], N[(x + N[(t$95$0 - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Tan[a], $MachinePrecision], 5e-15], N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(1.0 - N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x - N[(N[(a * a), $MachinePrecision] * N[(a * 0.3333333333333333), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[Sin[a], $MachinePrecision] * N[(-1.0 / N[Cos[a], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := \tan \left(y + z\right)\\
\mathbf{if}\;\tan a \leq -0.005:\\
\;\;\;\;x + \left(t\_0 - \tan a\right)\\
\mathbf{elif}\;\tan a \leq 5 \cdot 10^{-15}:\\
\;\;\;\;\mathsf{fma}\left(\tan y + \tan z, \frac{1}{1 - \tan y \cdot \tan z}, x - \mathsf{fma}\left(a \cdot a, a \cdot 0.3333333333333333, a\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x + \mathsf{fma}\left(\sin a, \frac{-1}{\cos a}, t\_0\right)\\
\end{array}
\end{array}
if (tan.f64 a) < -0.0050000000000000001Initial program 83.9%
if -0.0050000000000000001 < (tan.f64 a) < 4.99999999999999999e-15Initial program 83.8%
Taylor expanded in a around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6483.8
Applied rewrites83.8%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
sub-negN/A
associate-+l+N/A
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
lift-tan.f64N/A
lift-tan.f64N/A
lift-+.f64N/A
lift-tan.f64N/A
lift-tan.f64N/A
lift-*.f64N/A
lift--.f64N/A
div-invN/A
Applied rewrites99.9%
if 4.99999999999999999e-15 < (tan.f64 a) Initial program 79.6%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-tan.f64N/A
tan-quotN/A
distribute-neg-frac2N/A
div-invN/A
lower-fma.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-neg.f64N/A
lower-cos.f6479.7
Applied rewrites79.7%
Final simplification89.8%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (tan (+ y z))))
(if (<= (tan a) -0.005)
(+ x (- t_0 (tan a)))
(if (<= (tan a) 1e-25)
(+
x
(-
(/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z))))
(fma (* a a) (* a 0.3333333333333333) a)))
(+ x (fma (sin a) (/ -1.0 (cos a)) t_0))))))assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double t_0 = tan((y + z));
double tmp;
if (tan(a) <= -0.005) {
tmp = x + (t_0 - tan(a));
} else if (tan(a) <= 1e-25) {
tmp = x + (((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) - fma((a * a), (a * 0.3333333333333333), a));
} else {
tmp = x + fma(sin(a), (-1.0 / cos(a)), t_0);
}
return tmp;
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) t_0 = tan(Float64(y + z)) tmp = 0.0 if (tan(a) <= -0.005) tmp = Float64(x + Float64(t_0 - tan(a))); elseif (tan(a) <= 1e-25) tmp = Float64(x + Float64(Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z)))) - fma(Float64(a * a), Float64(a * 0.3333333333333333), a))); else tmp = Float64(x + fma(sin(a), Float64(-1.0 / cos(a)), t_0)); end return tmp end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -0.005], N[(x + N[(t$95$0 - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Tan[a], $MachinePrecision], 1e-25], 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[(N[(a * a), $MachinePrecision] * N[(a * 0.3333333333333333), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[Sin[a], $MachinePrecision] * N[(-1.0 / N[Cos[a], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := \tan \left(y + z\right)\\
\mathbf{if}\;\tan a \leq -0.005:\\
\;\;\;\;x + \left(t\_0 - \tan a\right)\\
\mathbf{elif}\;\tan a \leq 10^{-25}:\\
\;\;\;\;x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - \mathsf{fma}\left(a \cdot a, a \cdot 0.3333333333333333, a\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x + \mathsf{fma}\left(\sin a, \frac{-1}{\cos a}, t\_0\right)\\
\end{array}
\end{array}
if (tan.f64 a) < -0.0050000000000000001Initial program 83.9%
if -0.0050000000000000001 < (tan.f64 a) < 1.00000000000000004e-25Initial program 83.0%
Taylor expanded in a around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6483.0
Applied rewrites83.0%
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
lift-tan.f64N/A
lift-tan.f64N/A
lift-+.f64N/A
lift-tan.f64N/A
lift-tan.f64N/A
lift-*.f64N/A
lift--.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
if 1.00000000000000004e-25 < (tan.f64 a) Initial program 81.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-tan.f64N/A
tan-quotN/A
distribute-neg-frac2N/A
div-invN/A
lower-fma.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-neg.f64N/A
lower-cos.f6481.1
Applied rewrites81.1%
Final simplification89.8%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (+ x (- (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z)))) (tan a))))
assert(x < y && y < z && z < 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));
}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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
assert x < y && y < z && z < a;
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));
}
[x, y, z, a] = sort([x, y, z, 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))
x, y, z, a = sort([x, y, z, 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
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp = code(x, y, z, a)
tmp = x + (((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) - tan(a));
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. 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, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - \tan a\right)
\end{array}
Initial program 82.7%
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
lower-/.f64N/A
lower-+.f64N/A
lower-tan.f64N/A
lower-tan.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-tan.f64N/A
lower-tan.f6499.7
Applied rewrites99.7%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (+ x (- (tan z) (tan a)))))
(if (<= a -0.0064)
t_0
(if (<= a 0.07)
(+ x (- (tan (+ y z)) (fma a (* (* a a) 0.3333333333333333) a)))
t_0))))assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double t_0 = x + (tan(z) - tan(a));
double tmp;
if (a <= -0.0064) {
tmp = t_0;
} else if (a <= 0.07) {
tmp = x + (tan((y + z)) - fma(a, ((a * a) * 0.3333333333333333), a));
} else {
tmp = t_0;
}
return tmp;
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) t_0 = Float64(x + Float64(tan(z) - tan(a))) tmp = 0.0 if (a <= -0.0064) tmp = t_0; elseif (a <= 0.07) tmp = Float64(x + Float64(tan(Float64(y + z)) - fma(a, Float64(Float64(a * a) * 0.3333333333333333), a))); else tmp = t_0; end return tmp end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(x + N[(N[Tan[z], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.0064], t$95$0, If[LessEqual[a, 0.07], N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[(a * N[(N[(a * a), $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := x + \left(\tan z - \tan a\right)\\
\mathbf{if}\;a \leq -0.0064:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;a \leq 0.07:\\
\;\;\;\;x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a, \left(a \cdot a\right) \cdot 0.3333333333333333, a\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if a < -0.00640000000000000031 or 0.070000000000000007 < a Initial program 81.2%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
lower-/.f6471.6
Applied rewrites71.6%
lift-/.f64N/A
inv-powN/A
sqr-powN/A
pow2N/A
lower-pow.f64N/A
lift-/.f64N/A
inv-powN/A
pow-powN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-eval23.6
Applied rewrites23.6%
Taylor expanded in y around 0
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6461.4
Applied rewrites61.4%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6461.4
Applied rewrites61.4%
if -0.00640000000000000031 < a < 0.070000000000000007Initial program 84.5%
Taylor expanded in a around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6484.5
Applied rewrites84.5%
Taylor expanded in a around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6484.5
Applied rewrites84.5%
Final simplification72.0%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (+ x (- (tan (+ y z)) (tan a))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return x + (tan((y + z)) - tan(a));
}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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
assert x < y && y < z && z < a;
public static double code(double x, double y, double z, double a) {
return x + (Math.tan((y + z)) - Math.tan(a));
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): return x + (math.tan((y + z)) - math.tan(a))
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return Float64(x + Float64(tan(Float64(y + z)) - tan(a))) end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp = code(x, y, z, a)
tmp = x + (tan((y + z)) - tan(a));
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. 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, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
x + \left(\tan \left(y + z\right) - \tan a\right)
\end{array}
Initial program 82.7%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (- (* (* x x) (/ 1.0 x)) (tan a))))
(if (<= a -0.235)
t_0
(if (<= a 0.21)
(+
x
(-
(tan (+ y z))
(fma
(fma a (* a 0.13333333333333333) 0.3333333333333333)
(* a (* a a))
a)))
t_0))))assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double t_0 = ((x * x) * (1.0 / x)) - tan(a);
double tmp;
if (a <= -0.235) {
tmp = t_0;
} else if (a <= 0.21) {
tmp = x + (tan((y + z)) - fma(fma(a, (a * 0.13333333333333333), 0.3333333333333333), (a * (a * a)), a));
} else {
tmp = t_0;
}
return tmp;
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) t_0 = Float64(Float64(Float64(x * x) * Float64(1.0 / x)) - tan(a)) tmp = 0.0 if (a <= -0.235) tmp = t_0; elseif (a <= 0.21) tmp = Float64(x + Float64(tan(Float64(y + z)) - fma(fma(a, Float64(a * 0.13333333333333333), 0.3333333333333333), Float64(a * Float64(a * a)), a))); else tmp = t_0; end return tmp end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[(N[(x * x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.235], t$95$0, If[LessEqual[a, 0.21], N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[(N[(a * N[(a * 0.13333333333333333), $MachinePrecision] + 0.3333333333333333), $MachinePrecision] * N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := \left(x \cdot x\right) \cdot \frac{1}{x} - \tan a\\
\mathbf{if}\;a \leq -0.235:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;a \leq 0.21:\\
\;\;\;\;x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\mathsf{fma}\left(a, a \cdot 0.13333333333333333, 0.3333333333333333\right), a \cdot \left(a \cdot a\right), a\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if a < -0.23499999999999999 or 0.209999999999999992 < a Initial program 81.1%
lift-+.f64N/A
lift--.f64N/A
associate-+r-N/A
sub-negN/A
flip-+N/A
div-invN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-neg.f6480.5
Applied rewrites80.5%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6446.0
Applied rewrites46.0%
Taylor expanded in x around inf
lower-/.f6443.0
Applied rewrites43.0%
lift-fma.f64N/A
lift-neg.f64N/A
unsub-negN/A
lower--.f64N/A
lower-*.f6443.1
Applied rewrites43.1%
if -0.23499999999999999 < a < 0.209999999999999992Initial program 84.6%
Taylor expanded in a around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6484.6
Applied rewrites84.6%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (- (* (* x x) (/ 1.0 x)) (tan a))))
(if (<= a -0.19)
t_0
(if (<= a 0.205)
(+ x (- (tan (+ y z)) (fma a (* (* a a) 0.3333333333333333) a)))
t_0))))assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double t_0 = ((x * x) * (1.0 / x)) - tan(a);
double tmp;
if (a <= -0.19) {
tmp = t_0;
} else if (a <= 0.205) {
tmp = x + (tan((y + z)) - fma(a, ((a * a) * 0.3333333333333333), a));
} else {
tmp = t_0;
}
return tmp;
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) t_0 = Float64(Float64(Float64(x * x) * Float64(1.0 / x)) - tan(a)) tmp = 0.0 if (a <= -0.19) tmp = t_0; elseif (a <= 0.205) tmp = Float64(x + Float64(tan(Float64(y + z)) - fma(a, Float64(Float64(a * a) * 0.3333333333333333), a))); else tmp = t_0; end return tmp end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[(N[(x * x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.19], t$95$0, If[LessEqual[a, 0.205], N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[(a * N[(N[(a * a), $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := \left(x \cdot x\right) \cdot \frac{1}{x} - \tan a\\
\mathbf{if}\;a \leq -0.19:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;a \leq 0.205:\\
\;\;\;\;x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a, \left(a \cdot a\right) \cdot 0.3333333333333333, a\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if a < -0.19 or 0.204999999999999988 < a Initial program 81.1%
lift-+.f64N/A
lift--.f64N/A
associate-+r-N/A
sub-negN/A
flip-+N/A
div-invN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-neg.f6480.5
Applied rewrites80.5%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6446.0
Applied rewrites46.0%
Taylor expanded in x around inf
lower-/.f6443.0
Applied rewrites43.0%
lift-fma.f64N/A
lift-neg.f64N/A
unsub-negN/A
lower--.f64N/A
lower-*.f6443.1
Applied rewrites43.1%
if -0.19 < a < 0.204999999999999988Initial program 84.6%
Taylor expanded in a around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6484.5
Applied rewrites84.5%
Taylor expanded in a around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6484.5
Applied rewrites84.5%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (if (<= z 6500000000.0) (+ x (- (fma z (* 0.3333333333333333 (* z z)) z) (tan a))) (fma (* x x) (/ 1.0 x) (- a))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double tmp;
if (z <= 6500000000.0) {
tmp = x + (fma(z, (0.3333333333333333 * (z * z)), z) - tan(a));
} else {
tmp = fma((x * x), (1.0 / x), -a);
}
return tmp;
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) tmp = 0.0 if (z <= 6500000000.0) tmp = Float64(x + Float64(fma(z, Float64(0.3333333333333333 * Float64(z * z)), z) - tan(a))); else tmp = fma(Float64(x * x), Float64(1.0 / x), Float64(-a)); end return tmp end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. code[x_, y_, z_, a_] := If[LessEqual[z, 6500000000.0], N[(x + N[(N[(z * N[(0.3333333333333333 * N[(z * z), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision] + (-a)), $MachinePrecision]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 6500000000:\\
\;\;\;\;x + \left(\mathsf{fma}\left(z, 0.3333333333333333 \cdot \left(z \cdot z\right), z\right) - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot x, \frac{1}{x}, -a\right)\\
\end{array}
\end{array}
if z < 6.5e9Initial program 89.9%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
lower-/.f6482.3
Applied rewrites82.3%
lift-/.f64N/A
inv-powN/A
sqr-powN/A
pow2N/A
lower-pow.f64N/A
lift-/.f64N/A
inv-powN/A
pow-powN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-eval23.2
Applied rewrites23.2%
Taylor expanded in y around 0
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6463.8
Applied rewrites63.8%
Taylor expanded in z around 0
Applied rewrites44.2%
if 6.5e9 < z Initial program 61.7%
lift-+.f64N/A
lift--.f64N/A
associate-+r-N/A
sub-negN/A
flip-+N/A
div-invN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-neg.f6461.4
Applied rewrites61.4%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6428.4
Applied rewrites28.4%
Taylor expanded in x around inf
lower-/.f6425.1
Applied rewrites25.1%
Taylor expanded in a around 0
mul-1-negN/A
lower-neg.f6414.6
Applied rewrites14.6%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (- (* (* x x) (/ 1.0 x)) (tan a)))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return ((x * x) * (1.0 / x)) - tan(a);
}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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 * x) * (1.0d0 / x)) - tan(a)
end function
assert x < y && y < z && z < a;
public static double code(double x, double y, double z, double a) {
return ((x * x) * (1.0 / x)) - Math.tan(a);
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): return ((x * x) * (1.0 / x)) - math.tan(a)
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return Float64(Float64(Float64(x * x) * Float64(1.0 / x)) - tan(a)) end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp = code(x, y, z, a)
tmp = ((x * x) * (1.0 / x)) - tan(a);
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. code[x_, y_, z_, a_] := N[(N[(N[(x * x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\left(x \cdot x\right) \cdot \frac{1}{x} - \tan a
\end{array}
Initial program 82.7%
lift-+.f64N/A
lift--.f64N/A
associate-+r-N/A
sub-negN/A
flip-+N/A
div-invN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-neg.f6482.2
Applied rewrites82.2%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6446.6
Applied rewrites46.6%
Taylor expanded in x around inf
lower-/.f6443.4
Applied rewrites43.4%
lift-fma.f64N/A
lift-neg.f64N/A
unsub-negN/A
lower--.f64N/A
lower-*.f6443.5
Applied rewrites43.5%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (fma (* x x) (/ 1.0 x) (- a)))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return fma((x * x), (1.0 / x), -a);
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return fma(Float64(x * x), Float64(1.0 / x), Float64(-a)) end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. code[x_, y_, z_, a_] := N[(N[(x * x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision] + (-a)), $MachinePrecision]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\mathsf{fma}\left(x \cdot x, \frac{1}{x}, -a\right)
\end{array}
Initial program 82.7%
lift-+.f64N/A
lift--.f64N/A
associate-+r-N/A
sub-negN/A
flip-+N/A
div-invN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-neg.f6482.2
Applied rewrites82.2%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6446.6
Applied rewrites46.6%
Taylor expanded in x around inf
lower-/.f6443.4
Applied rewrites43.4%
Taylor expanded in a around 0
mul-1-negN/A
lower-neg.f6422.3
Applied rewrites22.3%
herbie shell --seed 2024238
(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))))