
(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}
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 (/ (sin y) (/ (cos 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 - (sin(y) / (cos(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 - (sin(y) / (cos(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.sin(y) / (Math.cos(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.sin(y) / (math.cos(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(sin(y) / Float64(cos(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 - (sin(y) / (cos(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[Sin[y], $MachinePrecision] / N[(N[Cos[y], $MachinePrecision] / N[Tan[z], $MachinePrecision]), $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 - \frac{\sin y}{\frac{\cos y}{\tan z}}} - \tan a\right)
\end{array}
Initial program 79.7%
tan-sum99.7%
div-inv99.7%
Applied egg-rr99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
*-commutative99.7%
tan-quot99.7%
associate-*r/99.7%
Applied egg-rr99.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.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
(if (<= (tan a) -0.005)
(+ x (+ (tan (+ y z)) (* (sin a) (/ -1.0 (cos a)))))
(if (<= (tan a) 5e-8)
(+ x (- (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z)))) a))
(+ x (- (/ 1.0 (/ (cos (+ y z)) (sin (+ y z)))) (tan a))))))assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double tmp;
if (tan(a) <= -0.005) {
tmp = x + (tan((y + z)) + (sin(a) * (-1.0 / cos(a))));
} else if (tan(a) <= 5e-8) {
tmp = x + (((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) - a);
} else {
tmp = x + ((1.0 / (cos((y + z)) / sin((y + z)))) - tan(a));
}
return tmp;
}
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
real(8) :: tmp
if (tan(a) <= (-0.005d0)) then
tmp = x + (tan((y + z)) + (sin(a) * ((-1.0d0) / cos(a))))
else if (tan(a) <= 5d-8) then
tmp = x + (((tan(y) + tan(z)) / (1.0d0 - (tan(y) * tan(z)))) - a)
else
tmp = x + ((1.0d0 / (cos((y + z)) / sin((y + z)))) - tan(a))
end if
code = tmp
end function
assert x < y && y < z && z < a;
public static double code(double x, double y, double z, double a) {
double tmp;
if (Math.tan(a) <= -0.005) {
tmp = x + (Math.tan((y + z)) + (Math.sin(a) * (-1.0 / Math.cos(a))));
} else if (Math.tan(a) <= 5e-8) {
tmp = x + (((Math.tan(y) + Math.tan(z)) / (1.0 - (Math.tan(y) * Math.tan(z)))) - a);
} else {
tmp = x + ((1.0 / (Math.cos((y + z)) / Math.sin((y + z)))) - Math.tan(a));
}
return tmp;
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): tmp = 0 if math.tan(a) <= -0.005: tmp = x + (math.tan((y + z)) + (math.sin(a) * (-1.0 / math.cos(a)))) elif math.tan(a) <= 5e-8: tmp = x + (((math.tan(y) + math.tan(z)) / (1.0 - (math.tan(y) * math.tan(z)))) - a) else: tmp = x + ((1.0 / (math.cos((y + z)) / math.sin((y + z)))) - math.tan(a)) return tmp
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) tmp = 0.0 if (tan(a) <= -0.005) tmp = Float64(x + Float64(tan(Float64(y + z)) + Float64(sin(a) * Float64(-1.0 / cos(a))))); elseif (tan(a) <= 5e-8) tmp = Float64(x + Float64(Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z)))) - a)); else tmp = Float64(x + Float64(Float64(1.0 / Float64(cos(Float64(y + z)) / sin(Float64(y + z)))) - tan(a))); end return tmp end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp_2 = code(x, y, z, a)
tmp = 0.0;
if (tan(a) <= -0.005)
tmp = x + (tan((y + z)) + (sin(a) * (-1.0 / cos(a))));
elseif (tan(a) <= 5e-8)
tmp = x + (((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) - a);
else
tmp = x + ((1.0 / (cos((y + z)) / sin((y + z)))) - tan(a));
end
tmp_2 = 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[N[Tan[a], $MachinePrecision], -0.005], N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] + N[(N[Sin[a], $MachinePrecision] * N[(-1.0 / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Tan[a], $MachinePrecision], 5e-8], 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] - a), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(1.0 / N[(N[Cos[N[(y + z), $MachinePrecision]], $MachinePrecision] / N[Sin[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
\mathbf{if}\;\tan a \leq -0.005:\\
\;\;\;\;x + \left(\tan \left(y + z\right) + \sin a \cdot \frac{-1}{\cos a}\right)\\
\mathbf{elif}\;\tan a \leq 5 \cdot 10^{-8}:\\
\;\;\;\;x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - a\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(\frac{1}{\frac{\cos \left(y + z\right)}{\sin \left(y + z\right)}} - \tan a\right)\\
\end{array}
\end{array}
if (tan.f64 a) < -0.0050000000000000001Initial program 87.6%
tan-quot87.6%
div-inv87.7%
Applied egg-rr87.7%
if -0.0050000000000000001 < (tan.f64 a) < 4.9999999999999998e-8Initial program 78.8%
Taylor expanded in a around 0 78.8%
tan-sum99.8%
div-inv99.8%
Applied egg-rr99.8%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
if 4.9999999999999998e-8 < (tan.f64 a) Initial program 75.1%
tan-quot75.1%
clear-num75.1%
Applied egg-rr75.1%
Final simplification90.1%
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 79.7%
tan-sum99.7%
div-inv99.7%
Applied egg-rr99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.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 (+ x (- (tan (+ y z)) (/ (sin a) (cos a)))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return x + (tan((y + z)) - (sin(a) / cos(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)) - (sin(a) / cos(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.sin(a) / Math.cos(a)));
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): return x + (math.tan((y + z)) - (math.sin(a) / math.cos(a)))
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return Float64(x + Float64(tan(Float64(y + z)) - Float64(sin(a) / cos(a)))) end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp = code(x, y, z, a)
tmp = x + (tan((y + z)) - (sin(a) / cos(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[(N[Sin[a], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
x + \left(\tan \left(y + z\right) - \frac{\sin a}{\cos a}\right)
\end{array}
Initial program 79.7%
Taylor expanded in a around inf 79.7%
Final simplification79.7%
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 79.7%
Final simplification79.7%
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))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return x + tan((y + z));
}
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))
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));
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): return x + math.tan((y + z))
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return Float64(x + tan(Float64(y + z))) end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp = code(x, y, z, a)
tmp = x + tan((y + z));
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[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
x + \tan \left(y + z\right)
\end{array}
Initial program 79.7%
add-cbrt-cube79.2%
pow1/373.2%
pow373.2%
+-commutative73.2%
associate-+l-73.2%
Applied egg-rr73.2%
Taylor expanded in a around 0 47.8%
+-commutative47.8%
Simplified47.8%
pow-pow50.6%
tan-quot50.6%
metadata-eval50.6%
pow150.6%
Applied egg-rr50.6%
Final simplification50.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)
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return x;
}
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
end function
assert x < y && y < z && z < a;
public static double code(double x, double y, double z, double a) {
return x;
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): return x
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return x end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp = code(x, y, z, a)
tmp = x;
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. code[x_, y_, z_, a_] := x
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
x
\end{array}
Initial program 79.7%
Taylor expanded in x around inf 32.4%
Final simplification32.4%
herbie shell --seed 2024019
(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))))