
(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 (* (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 76.3%
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
(let* ((t_0 (+ (tan y) (tan z))))
(if (or (<= (tan a) -0.005) (not (<= (tan a) 1e-11)))
(fma t_0 1.0 (- x (tan a)))
(+ (/ t_0 (- 1.0 (* (tan y) (tan z)))) (- x a)))))
double code(double x, double y, double z, double a) {
double t_0 = tan(y) + tan(z);
double tmp;
if ((tan(a) <= -0.005) || !(tan(a) <= 1e-11)) {
tmp = fma(t_0, 1.0, (x - tan(a)));
} else {
tmp = (t_0 / (1.0 - (tan(y) * tan(z)))) + (x - a);
}
return tmp;
}
function code(x, y, z, a) t_0 = Float64(tan(y) + tan(z)) tmp = 0.0 if ((tan(a) <= -0.005) || !(tan(a) <= 1e-11)) tmp = fma(t_0, 1.0, Float64(x - tan(a))); else tmp = Float64(Float64(t_0 / Float64(1.0 - Float64(tan(y) * tan(z)))) + Float64(x - a)); end return tmp end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[N[Tan[a], $MachinePrecision], -0.005], N[Not[LessEqual[N[Tan[a], $MachinePrecision], 1e-11]], $MachinePrecision]], N[(t$95$0 * 1.0 + N[(x - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / N[(1.0 - N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x - a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan y + \tan z\\
\mathbf{if}\;\tan a \leq -0.005 \lor \neg \left(\tan a \leq 10^{-11}\right):\\
\;\;\;\;\mathsf{fma}\left(t_0, 1, x - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{1 - \tan y \cdot \tan z} + \left(x - a\right)\\
\end{array}
\end{array}
if (tan.f64 a) < -0.0050000000000000001 or 9.99999999999999939e-12 < (tan.f64 a) Initial program 76.7%
associate-+r-76.6%
+-commutative76.6%
associate-+r-76.5%
tan-sum99.5%
div-inv99.4%
fma-def99.4%
Applied egg-rr99.4%
Taylor expanded in y around 0 77.3%
if -0.0050000000000000001 < (tan.f64 a) < 9.99999999999999939e-12Initial program 75.9%
associate-+r-75.9%
+-commutative75.9%
associate--l+75.9%
Simplified75.9%
Taylor expanded in a around 0 75.9%
mul-1-neg75.9%
unsub-neg75.9%
Simplified75.9%
tan-sum99.8%
div-inv99.8%
Applied egg-rr99.7%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
Final simplification88.6%
(FPCore (x y z a) :precision binary64 (fma (+ (tan y) (tan z)) 1.0 (- x (tan a))))
double code(double x, double y, double z, double a) {
return fma((tan(y) + tan(z)), 1.0, (x - tan(a)));
}
function code(x, y, z, a) return fma(Float64(tan(y) + tan(z)), 1.0, Float64(x - tan(a))) end
code[x_, y_, z_, a_] := N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] * 1.0 + N[(x - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\tan y + \tan z, 1, x - \tan a\right)
\end{array}
Initial program 76.3%
associate-+r-76.2%
+-commutative76.2%
associate-+r-76.2%
tan-sum99.6%
div-inv99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 76.7%
Final simplification76.7%
(FPCore (x y z a) :precision binary64 (if (or (<= a -0.0008) (not (<= a 250000.0))) (+ x (- (tan z) (tan a))) (+ (- x a) (tan (+ y z)))))
double code(double x, double y, double z, double a) {
double tmp;
if ((a <= -0.0008) || !(a <= 250000.0)) {
tmp = x + (tan(z) - tan(a));
} else {
tmp = (x - a) + tan((y + z));
}
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 <= (-0.0008d0)) .or. (.not. (a <= 250000.0d0))) then
tmp = x + (tan(z) - tan(a))
else
tmp = (x - a) + tan((y + z))
end if
code = tmp
end function
public static double code(double x, double y, double z, double a) {
double tmp;
if ((a <= -0.0008) || !(a <= 250000.0)) {
tmp = x + (Math.tan(z) - Math.tan(a));
} else {
tmp = (x - a) + Math.tan((y + z));
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if (a <= -0.0008) or not (a <= 250000.0): tmp = x + (math.tan(z) - math.tan(a)) else: tmp = (x - a) + math.tan((y + z)) return tmp
function code(x, y, z, a) tmp = 0.0 if ((a <= -0.0008) || !(a <= 250000.0)) tmp = Float64(x + Float64(tan(z) - tan(a))); else tmp = Float64(Float64(x - a) + tan(Float64(y + z))); end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if ((a <= -0.0008) || ~((a <= 250000.0))) tmp = x + (tan(z) - tan(a)); else tmp = (x - a) + tan((y + z)); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[Or[LessEqual[a, -0.0008], N[Not[LessEqual[a, 250000.0]], $MachinePrecision]], N[(x + N[(N[Tan[z], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - a), $MachinePrecision] + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.0008 \lor \neg \left(a \leq 250000\right):\\
\;\;\;\;x + \left(\tan z - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - a\right) + \tan \left(y + z\right)\\
\end{array}
\end{array}
if a < -8.00000000000000038e-4 or 2.5e5 < a Initial program 76.7%
Taylor expanded in y around 0 60.8%
tan-quot60.8%
tan-quot60.8%
associate--l+60.9%
Applied egg-rr60.9%
if -8.00000000000000038e-4 < a < 2.5e5Initial program 75.9%
associate-+r-75.8%
+-commutative75.8%
associate--l+75.8%
Simplified75.8%
Taylor expanded in a around 0 75.5%
mul-1-neg75.5%
unsub-neg75.5%
Simplified75.5%
Final simplification68.4%
(FPCore (x y z a) :precision binary64 (if (<= a -0.00059) (+ x (- (tan z) (tan a))) (if (<= a 250000.0) (+ (- x a) (tan (+ y z))) (- (+ x (tan z)) (tan a)))))
double code(double x, double y, double z, double a) {
double tmp;
if (a <= -0.00059) {
tmp = x + (tan(z) - tan(a));
} else if (a <= 250000.0) {
tmp = (x - 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 (a <= (-0.00059d0)) then
tmp = x + (tan(z) - tan(a))
else if (a <= 250000.0d0) then
tmp = (x - 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 (a <= -0.00059) {
tmp = x + (Math.tan(z) - Math.tan(a));
} else if (a <= 250000.0) {
tmp = (x - 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 a <= -0.00059: tmp = x + (math.tan(z) - math.tan(a)) elif a <= 250000.0: tmp = (x - 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 (a <= -0.00059) tmp = Float64(x + Float64(tan(z) - tan(a))); elseif (a <= 250000.0) tmp = Float64(Float64(x - a) + tan(Float64(y + z))); else tmp = Float64(Float64(x + tan(z)) - tan(a)); end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if (a <= -0.00059) tmp = x + (tan(z) - tan(a)); elseif (a <= 250000.0) tmp = (x - a) + tan((y + z)); else tmp = (x + tan(z)) - tan(a); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[a, -0.00059], N[(x + N[(N[Tan[z], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 250000.0], N[(N[(x - a), $MachinePrecision] + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(x + N[Tan[z], $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.00059:\\
\;\;\;\;x + \left(\tan z - \tan a\right)\\
\mathbf{elif}\;a \leq 250000:\\
\;\;\;\;\left(x - a\right) + \tan \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x + \tan z\right) - \tan a\\
\end{array}
\end{array}
if a < -5.9000000000000003e-4Initial program 83.6%
Taylor expanded in y around 0 64.4%
tan-quot64.4%
tan-quot64.5%
associate--l+64.6%
Applied egg-rr64.6%
if -5.9000000000000003e-4 < a < 2.5e5Initial program 75.9%
associate-+r-75.8%
+-commutative75.8%
associate--l+75.8%
Simplified75.8%
Taylor expanded in a around 0 75.5%
mul-1-neg75.5%
unsub-neg75.5%
Simplified75.5%
if 2.5e5 < a Initial program 67.9%
Taylor expanded in y around 0 56.1%
tan-quot56.1%
sub-neg56.1%
tan-quot56.1%
+-commutative56.1%
Applied egg-rr56.1%
Final simplification68.4%
(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 76.3%
Final simplification76.3%
(FPCore (x y z a) :precision binary64 (if (<= a -1.4) x (if (<= a 250000.0) (+ (- x a) (tan (+ y z))) (cbrt (pow x 3.0)))))
double code(double x, double y, double z, double a) {
double tmp;
if (a <= -1.4) {
tmp = x;
} else if (a <= 250000.0) {
tmp = (x - a) + tan((y + z));
} else {
tmp = cbrt(pow(x, 3.0));
}
return tmp;
}
public static double code(double x, double y, double z, double a) {
double tmp;
if (a <= -1.4) {
tmp = x;
} else if (a <= 250000.0) {
tmp = (x - a) + Math.tan((y + z));
} else {
tmp = Math.cbrt(Math.pow(x, 3.0));
}
return tmp;
}
function code(x, y, z, a) tmp = 0.0 if (a <= -1.4) tmp = x; elseif (a <= 250000.0) tmp = Float64(Float64(x - a) + tan(Float64(y + z))); else tmp = cbrt((x ^ 3.0)); end return tmp end
code[x_, y_, z_, a_] := If[LessEqual[a, -1.4], x, If[LessEqual[a, 250000.0], N[(N[(x - a), $MachinePrecision] + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Power[N[Power[x, 3.0], $MachinePrecision], 1/3], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.4:\\
\;\;\;\;x\\
\mathbf{elif}\;a \leq 250000:\\
\;\;\;\;\left(x - a\right) + \tan \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{x}^{3}}\\
\end{array}
\end{array}
if a < -1.3999999999999999Initial program 83.6%
Taylor expanded in x around inf 20.7%
if -1.3999999999999999 < a < 2.5e5Initial program 75.9%
associate-+r-75.8%
+-commutative75.8%
associate--l+75.8%
Simplified75.8%
Taylor expanded in a around 0 75.5%
mul-1-neg75.5%
unsub-neg75.5%
Simplified75.5%
if 2.5e5 < a Initial program 67.9%
associate-+r-67.8%
+-commutative67.8%
associate--l+67.8%
Simplified67.8%
Taylor expanded in a around 0 1.1%
mul-1-neg1.1%
unsub-neg1.1%
Simplified1.1%
add-cbrt-cube0.9%
pow30.9%
Applied egg-rr0.9%
Taylor expanded in x around inf 22.6%
Final simplification49.3%
(FPCore (x y z a) :precision binary64 (if (<= a -1.0) x (if (<= a 250000.0) (+ (- x a) (tan (+ y z))) x)))
double code(double x, double y, double z, double a) {
double tmp;
if (a <= -1.0) {
tmp = x;
} else if (a <= 250000.0) {
tmp = (x - a) + tan((y + z));
} 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.0d0)) then
tmp = x
else if (a <= 250000.0d0) then
tmp = (x - a) + tan((y + z))
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.0) {
tmp = x;
} else if (a <= 250000.0) {
tmp = (x - a) + Math.tan((y + z));
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if a <= -1.0: tmp = x elif a <= 250000.0: tmp = (x - a) + math.tan((y + z)) else: tmp = x return tmp
function code(x, y, z, a) tmp = 0.0 if (a <= -1.0) tmp = x; elseif (a <= 250000.0) tmp = Float64(Float64(x - a) + tan(Float64(y + z))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if (a <= -1.0) tmp = x; elseif (a <= 250000.0) tmp = (x - a) + tan((y + z)); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[a, -1.0], x, If[LessEqual[a, 250000.0], N[(N[(x - a), $MachinePrecision] + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1:\\
\;\;\;\;x\\
\mathbf{elif}\;a \leq 250000:\\
\;\;\;\;\left(x - a\right) + \tan \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if a < -1 or 2.5e5 < a Initial program 76.7%
Taylor expanded in x around inf 21.5%
if -1 < a < 2.5e5Initial program 75.9%
associate-+r-75.8%
+-commutative75.8%
associate--l+75.8%
Simplified75.8%
Taylor expanded in a around 0 75.5%
mul-1-neg75.5%
unsub-neg75.5%
Simplified75.5%
Final simplification49.3%
(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 76.3%
Taylor expanded in x around inf 29.0%
Final simplification29.0%
herbie shell --seed 2023271
(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))))