
(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}
(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 82.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 (or (<= (tan a) -0.05) (not (<= (tan a) 5e-15))) (+ 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.05) || !(tan(a) <= 5e-15)) {
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.05d0)) .or. (.not. (tan(a) <= 5d-15))) 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.05) || !(Math.tan(a) <= 5e-15)) {
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.05) or not (math.tan(a) <= 5e-15): 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.05) || !(tan(a) <= 5e-15)) 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.05) || ~((tan(a) <= 5e-15))) 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.05], N[Not[LessEqual[N[Tan[a], $MachinePrecision], 5e-15]], $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.05 \lor \neg \left(\tan a \leq 5 \cdot 10^{-15}\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.050000000000000003 or 4.99999999999999999e-15 < (tan.f64 a) Initial program 81.8%
if -0.050000000000000003 < (tan.f64 a) < 4.99999999999999999e-15Initial program 83.7%
associate-+r-83.7%
Simplified83.7%
Taylor expanded in a around 0 83.7%
tan-sum99.7%
div-inv99.7%
Applied egg-rr99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
Final simplification90.6%
(FPCore (x y z a) :precision binary64 (if (or (<= (tan a) -2e-26) (not (<= (tan a) 5e-19))) (+ x (- (tan z) (tan a))) (- (+ x (tan (+ y z))) a)))
double code(double x, double y, double z, double a) {
double tmp;
if ((tan(a) <= -2e-26) || !(tan(a) <= 5e-19)) {
tmp = x + (tan(z) - tan(a));
} else {
tmp = (x + tan((y + 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) <= (-2d-26)) .or. (.not. (tan(a) <= 5d-19))) then
tmp = x + (tan(z) - tan(a))
else
tmp = (x + tan((y + 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) <= -2e-26) || !(Math.tan(a) <= 5e-19)) {
tmp = x + (Math.tan(z) - Math.tan(a));
} else {
tmp = (x + Math.tan((y + z))) - a;
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if (math.tan(a) <= -2e-26) or not (math.tan(a) <= 5e-19): tmp = x + (math.tan(z) - math.tan(a)) else: tmp = (x + math.tan((y + z))) - a return tmp
function code(x, y, z, a) tmp = 0.0 if ((tan(a) <= -2e-26) || !(tan(a) <= 5e-19)) tmp = Float64(x + Float64(tan(z) - tan(a))); else tmp = Float64(Float64(x + tan(Float64(y + z))) - a); end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if ((tan(a) <= -2e-26) || ~((tan(a) <= 5e-19))) tmp = x + (tan(z) - tan(a)); else tmp = (x + tan((y + z))) - a; end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[Or[LessEqual[N[Tan[a], $MachinePrecision], -2e-26], N[Not[LessEqual[N[Tan[a], $MachinePrecision], 5e-19]], $MachinePrecision]], N[(x + N[(N[Tan[z], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\tan a \leq -2 \cdot 10^{-26} \lor \neg \left(\tan a \leq 5 \cdot 10^{-19}\right):\\
\;\;\;\;x + \left(\tan z - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x + \tan \left(y + z\right)\right) - a\\
\end{array}
\end{array}
if (tan.f64 a) < -2.0000000000000001e-26 or 5.0000000000000004e-19 < (tan.f64 a) Initial program 81.7%
Taylor expanded in y around 0 66.8%
associate--l+66.8%
Simplified66.8%
tan-quot66.8%
tan-quot66.8%
associate-+r-66.9%
Applied egg-rr66.9%
+-commutative66.9%
associate--l+66.9%
Simplified66.9%
if -2.0000000000000001e-26 < (tan.f64 a) < 5.0000000000000004e-19Initial program 84.0%
associate-+r-84.0%
Simplified84.0%
Taylor expanded in a around 0 84.0%
Final simplification74.6%
(FPCore (x y z a) :precision binary64 (if (<= y -0.00295) (+ x (+ (tan a) (tan (+ y z)))) (+ x (- (tan z) (tan a)))))
double code(double x, double y, double z, double a) {
double tmp;
if (y <= -0.00295) {
tmp = x + (tan(a) + 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 <= (-0.00295d0)) then
tmp = x + (tan(a) + 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 <= -0.00295) {
tmp = x + (Math.tan(a) + 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 <= -0.00295: tmp = x + (math.tan(a) + 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 <= -0.00295) tmp = Float64(x + Float64(tan(a) + 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 <= -0.00295) tmp = x + (tan(a) + tan((y + z))); else tmp = x + (tan(z) - tan(a)); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[y, -0.00295], N[(x + N[(N[Tan[a], $MachinePrecision] + N[Tan[N[(y + z), $MachinePrecision]], $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 -0.00295:\\
\;\;\;\;x + \left(\tan a + \tan \left(y + z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(\tan z - \tan a\right)\\
\end{array}
\end{array}
if y < -0.00294999999999999993Initial program 59.6%
sub-neg59.6%
Applied egg-rr59.6%
+-commutative59.6%
rem-square-sqrt24.4%
fabs-sqr24.4%
rem-square-sqrt47.0%
fabs-neg47.0%
rem-square-sqrt22.6%
fabs-sqr22.6%
rem-square-sqrt36.9%
Simplified36.9%
if -0.00294999999999999993 < y Initial program 89.2%
Taylor expanded in y around 0 76.4%
associate--l+76.4%
Simplified76.4%
tan-quot76.4%
tan-quot76.4%
associate-+r-76.4%
Applied egg-rr76.4%
+-commutative76.4%
associate--l+76.5%
Simplified76.5%
Final simplification67.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 82.7%
Final simplification82.7%
(FPCore (x y z a) :precision binary64 (if (<= a -1.45) x (if (<= a 1.6) (- (+ x (tan (+ y z))) a) x)))
double code(double x, double y, double z, double a) {
double tmp;
if (a <= -1.45) {
tmp = x;
} else if (a <= 1.6) {
tmp = (x + tan((y + z))) - a;
} else {
tmp = x;
}
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 (a <= (-1.45d0)) then
tmp = x
else if (a <= 1.6d0) then
tmp = (x + tan((y + z))) - a
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double a) {
double tmp;
if (a <= -1.45) {
tmp = x;
} else if (a <= 1.6) {
tmp = (x + Math.tan((y + z))) - a;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if a <= -1.45: tmp = x elif a <= 1.6: tmp = (x + math.tan((y + z))) - a else: tmp = x return tmp
function code(x, y, z, a) tmp = 0.0 if (a <= -1.45) tmp = x; elseif (a <= 1.6) tmp = Float64(Float64(x + tan(Float64(y + z))) - a); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if (a <= -1.45) tmp = x; elseif (a <= 1.6) tmp = (x + tan((y + z))) - a; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[a, -1.45], x, If[LessEqual[a, 1.6], N[(N[(x + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.45:\\
\;\;\;\;x\\
\mathbf{elif}\;a \leq 1.6:\\
\;\;\;\;\left(x + \tan \left(y + z\right)\right) - a\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if a < -1.44999999999999996 or 1.6000000000000001 < a Initial program 81.5%
Taylor expanded in x around inf 22.8%
if -1.44999999999999996 < a < 1.6000000000000001Initial program 83.9%
associate-+r-83.9%
Simplified83.9%
Taylor expanded in a around 0 83.4%
Final simplification52.9%
(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 82.7%
Taylor expanded in x around inf 30.1%
Final simplification30.1%
herbie shell --seed 2023240
(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))))