
(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 9 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 (* (/ (sin z) (cos y)) (/ (sin y) (cos z))))) (tan a))))
double code(double x, double y, double z, double a) {
return x + (((tan(y) + tan(z)) / (1.0 - ((sin(z) / cos(y)) * (sin(y) / cos(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 - ((sin(z) / cos(y)) * (sin(y) / cos(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.sin(z) / Math.cos(y)) * (Math.sin(y) / Math.cos(z))))) - Math.tan(a));
}
def code(x, y, z, a): return x + (((math.tan(y) + math.tan(z)) / (1.0 - ((math.sin(z) / math.cos(y)) * (math.sin(y) / math.cos(z))))) - math.tan(a))
function code(x, y, z, a) return Float64(x + Float64(Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(Float64(sin(z) / cos(y)) * Float64(sin(y) / cos(z))))) - tan(a))) end
function tmp = code(x, y, z, a) tmp = x + (((tan(y) + tan(z)) / (1.0 - ((sin(z) / cos(y)) * (sin(y) / cos(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[(N[Sin[z], $MachinePrecision] / N[Cos[y], $MachinePrecision]), $MachinePrecision] * N[(N[Sin[y], $MachinePrecision] / N[Cos[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\frac{\tan y + \tan z}{1 - \frac{\sin z}{\cos y} \cdot \frac{\sin y}{\cos z}} - \tan a\right)
\end{array}
Initial program 78.7%
tan-sum99.7%
div-inv99.7%
Applied egg-rr99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
Taylor expanded in y around inf 99.7%
*-commutative99.7%
times-frac99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y z a) :precision binary64 (if (or (<= (tan a) -0.01) (not (<= (tan a) 4e-20))) (+ x (- (tan (+ y z)) (tan a))) (- (+ x (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z))))) a)))
double code(double x, double y, double z, double a) {
double tmp;
if ((tan(a) <= -0.01) || !(tan(a) <= 4e-20)) {
tmp = x + (tan((y + z)) - tan(a));
} else {
tmp = (x + ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z))))) - 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 ((tan(a) <= (-0.01d0)) .or. (.not. (tan(a) <= 4d-20))) then
tmp = x + (tan((y + z)) - tan(a))
else
tmp = (x + ((tan(y) + tan(z)) / (1.0d0 - (tan(y) * tan(z))))) - a
end if
code = tmp
end function
public static double code(double x, double y, double z, double a) {
double tmp;
if ((Math.tan(a) <= -0.01) || !(Math.tan(a) <= 4e-20)) {
tmp = x + (Math.tan((y + z)) - Math.tan(a));
} else {
tmp = (x + ((Math.tan(y) + Math.tan(z)) / (1.0 - (Math.tan(y) * Math.tan(z))))) - a;
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if (math.tan(a) <= -0.01) or not (math.tan(a) <= 4e-20): tmp = x + (math.tan((y + z)) - math.tan(a)) else: tmp = (x + ((math.tan(y) + math.tan(z)) / (1.0 - (math.tan(y) * math.tan(z))))) - a return tmp
function code(x, y, z, a) tmp = 0.0 if ((tan(a) <= -0.01) || !(tan(a) <= 4e-20)) tmp = Float64(x + Float64(tan(Float64(y + z)) - tan(a))); else tmp = Float64(Float64(x + Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z))))) - a); end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if ((tan(a) <= -0.01) || ~((tan(a) <= 4e-20))) tmp = x + (tan((y + z)) - tan(a)); else tmp = (x + ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z))))) - a; end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[Or[LessEqual[N[Tan[a], $MachinePrecision], -0.01], N[Not[LessEqual[N[Tan[a], $MachinePrecision], 4e-20]], $MachinePrecision]], N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x + 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]), $MachinePrecision] - a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\tan a \leq -0.01 \lor \neg \left(\tan a \leq 4 \cdot 10^{-20}\right):\\
\;\;\;\;x + \left(\tan \left(y + z\right) - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\right) - a\\
\end{array}
\end{array}
if (tan.f64 a) < -0.0100000000000000002 or 3.99999999999999978e-20 < (tan.f64 a) Initial program 77.7%
if -0.0100000000000000002 < (tan.f64 a) < 3.99999999999999978e-20Initial program 79.7%
associate-+r-79.7%
Simplified79.7%
Taylor expanded in a around 0 79.7%
tan-sum99.7%
div-inv99.7%
Applied egg-rr99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
Final simplification88.7%
(FPCore (x y z a) :precision binary64 (+ x (- (/ 1.0 (/ (- 1.0 (* (tan y) (tan z))) (+ (tan y) (tan z)))) (tan a))))
double code(double x, double y, double z, double a) {
return x + ((1.0 / ((1.0 - (tan(y) * tan(z))) / (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 + ((1.0d0 / ((1.0d0 - (tan(y) * tan(z))) / (tan(y) + tan(z)))) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
return x + ((1.0 / ((1.0 - (Math.tan(y) * Math.tan(z))) / (Math.tan(y) + Math.tan(z)))) - Math.tan(a));
}
def code(x, y, z, a): return x + ((1.0 / ((1.0 - (math.tan(y) * math.tan(z))) / (math.tan(y) + math.tan(z)))) - math.tan(a))
function code(x, y, z, a) return Float64(x + Float64(Float64(1.0 / Float64(Float64(1.0 - Float64(tan(y) * tan(z))) / Float64(tan(y) + tan(z)))) - tan(a))) end
function tmp = code(x, y, z, a) tmp = x + ((1.0 / ((1.0 - (tan(y) * tan(z))) / (tan(y) + tan(z)))) - tan(a)); end
code[x_, y_, z_, a_] := N[(x + N[(N[(1.0 / N[(N[(1.0 - N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\frac{1}{\frac{1 - \tan y \cdot \tan z}{\tan y + \tan z}} - \tan a\right)
\end{array}
Initial program 78.7%
tan-sum99.7%
clear-num99.7%
Applied egg-rr99.7%
Final simplification99.7%
(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 78.7%
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 (if (<= (tan a) -0.01) x (if (<= (tan a) 1e-42) (- (+ x (tan (+ y z))) a) (- x 1.0))))
double code(double x, double y, double z, double a) {
double tmp;
if (tan(a) <= -0.01) {
tmp = x;
} else if (tan(a) <= 1e-42) {
tmp = (x + tan((y + z))) - a;
} else {
tmp = x - 1.0;
}
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 (tan(a) <= (-0.01d0)) then
tmp = x
else if (tan(a) <= 1d-42) then
tmp = (x + tan((y + z))) - a
else
tmp = x - 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z, double a) {
double tmp;
if (Math.tan(a) <= -0.01) {
tmp = x;
} else if (Math.tan(a) <= 1e-42) {
tmp = (x + Math.tan((y + z))) - a;
} else {
tmp = x - 1.0;
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if math.tan(a) <= -0.01: tmp = x elif math.tan(a) <= 1e-42: tmp = (x + math.tan((y + z))) - a else: tmp = x - 1.0 return tmp
function code(x, y, z, a) tmp = 0.0 if (tan(a) <= -0.01) tmp = x; elseif (tan(a) <= 1e-42) tmp = Float64(Float64(x + tan(Float64(y + z))) - a); else tmp = Float64(x - 1.0); end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if (tan(a) <= -0.01) tmp = x; elseif (tan(a) <= 1e-42) tmp = (x + tan((y + z))) - a; else tmp = x - 1.0; end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[N[Tan[a], $MachinePrecision], -0.01], x, If[LessEqual[N[Tan[a], $MachinePrecision], 1e-42], N[(N[(x + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision], N[(x - 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\tan a \leq -0.01:\\
\;\;\;\;x\\
\mathbf{elif}\;\tan a \leq 10^{-42}:\\
\;\;\;\;\left(x + \tan \left(y + z\right)\right) - a\\
\mathbf{else}:\\
\;\;\;\;x - 1\\
\end{array}
\end{array}
if (tan.f64 a) < -0.0100000000000000002Initial program 77.7%
Taylor expanded in x around inf 23.9%
if -0.0100000000000000002 < (tan.f64 a) < 1.00000000000000004e-42Initial program 80.6%
associate-+r-80.6%
Simplified80.6%
Taylor expanded in a around 0 80.6%
if 1.00000000000000004e-42 < (tan.f64 a) Initial program 75.9%
associate-+r-75.8%
expm1-log1p-u62.8%
+-commutative62.8%
associate--l+62.8%
Applied egg-rr62.8%
Taylor expanded in x around inf 20.9%
mul-1-neg20.9%
log-rec20.9%
remove-double-neg20.9%
Simplified20.9%
Taylor expanded in x around 0 20.9%
Final simplification50.8%
(FPCore (x y z a) :precision binary64 (+ x (- (/ 1.0 (/ 1.0 (tan (+ y z)))) (tan a))))
double code(double x, double y, double z, double a) {
return x + ((1.0 / (1.0 / 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 + ((1.0d0 / (1.0d0 / tan((y + z)))) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
return x + ((1.0 / (1.0 / Math.tan((y + z)))) - Math.tan(a));
}
def code(x, y, z, a): return x + ((1.0 / (1.0 / math.tan((y + z)))) - math.tan(a))
function code(x, y, z, a) return Float64(x + Float64(Float64(1.0 / Float64(1.0 / tan(Float64(y + z)))) - tan(a))) end
function tmp = code(x, y, z, a) tmp = x + ((1.0 / (1.0 / tan((y + z)))) - tan(a)); end
code[x_, y_, z_, a_] := N[(x + N[(N[(1.0 / N[(1.0 / N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\frac{1}{\frac{1}{\tan \left(y + z\right)}} - \tan a\right)
\end{array}
Initial program 78.7%
tan-sum99.7%
clear-num99.7%
Applied egg-rr99.7%
expm1-log1p-u65.3%
expm1-udef65.2%
clear-num65.3%
tan-sum50.7%
Applied egg-rr50.7%
expm1-def50.8%
expm1-log1p78.7%
+-commutative78.7%
Simplified78.7%
Final simplification78.7%
(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 78.7%
+-commutative78.7%
associate-+l-78.7%
Applied egg-rr78.7%
associate-+l-78.7%
+-commutative78.7%
sub-neg78.7%
associate-+r+78.7%
rem-square-sqrt41.3%
fabs-sqr41.3%
rem-square-sqrt65.1%
fabs-neg65.1%
rem-square-sqrt23.8%
fabs-sqr23.8%
rem-square-sqrt49.8%
associate-+l+49.8%
+-commutative49.8%
Simplified49.8%
Final simplification49.8%
(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 78.7%
Final simplification78.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 78.7%
Taylor expanded in x around inf 31.9%
Final simplification31.9%
herbie shell --seed 2023224
(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))))