
(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 8 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
(let* ((t_0 (* (tan y) (tan z))))
(+
x
(-
(* (/ (+ (tan y) (tan z)) (- 1.0 (cbrt (pow t_0 6.0)))) (+ 1.0 t_0))
(tan a)))))
double code(double x, double y, double z, double a) {
double t_0 = tan(y) * tan(z);
return x + ((((tan(y) + tan(z)) / (1.0 - cbrt(pow(t_0, 6.0)))) * (1.0 + t_0)) - tan(a));
}
public static double code(double x, double y, double z, double a) {
double t_0 = Math.tan(y) * Math.tan(z);
return x + ((((Math.tan(y) + Math.tan(z)) / (1.0 - Math.cbrt(Math.pow(t_0, 6.0)))) * (1.0 + t_0)) - Math.tan(a));
}
function code(x, y, z, a) t_0 = Float64(tan(y) * tan(z)) return Float64(x + Float64(Float64(Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - cbrt((t_0 ^ 6.0)))) * Float64(1.0 + t_0)) - tan(a))) end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]}, N[(x + N[(N[(N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[Power[N[Power[t$95$0, 6.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan y \cdot \tan z\\
x + \left(\frac{\tan y + \tan z}{1 - \sqrt[3]{{t_0}^{6}}} \cdot \left(1 + t_0\right) - \tan a\right)
\end{array}
\end{array}
Initial program 80.7%
add-cube-cbrt80.4%
pow380.4%
Applied egg-rr80.4%
rem-cube-cbrt80.7%
tan-sum99.6%
flip--99.6%
associate-/r/99.6%
metadata-eval99.6%
pow299.6%
+-commutative99.6%
Applied egg-rr99.6%
add-cbrt-cube99.6%
pow399.6%
pow-pow99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x y z a) :precision binary64 (+ x (fma (+ (tan y) (tan z)) (/ 1.0 (- 1.0 (* (tan y) (tan z)))) (- (tan a)))))
double code(double x, double y, double z, double a) {
return x + fma((tan(y) + tan(z)), (1.0 / (1.0 - (tan(y) * tan(z)))), -tan(a));
}
function code(x, y, z, a) return Float64(x + fma(Float64(tan(y) + tan(z)), Float64(1.0 / Float64(1.0 - Float64(tan(y) * tan(z)))), Float64(-tan(a)))) end
code[x_, y_, z_, a_] := N[(x + 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[Tan[a], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \mathsf{fma}\left(\tan y + \tan z, \frac{1}{1 - \tan y \cdot \tan z}, -\tan a\right)
\end{array}
Initial program 80.7%
tan-sum99.6%
div-inv99.6%
fma-neg99.6%
Applied egg-rr99.6%
Final simplification99.6%
(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 80.7%
tan-sum56.9%
div-inv56.9%
Applied egg-rr99.6%
associate-*r/56.9%
*-rgt-identity56.9%
Simplified99.6%
Final simplification99.6%
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (tan (+ y z))))
(if (<= a -0.00035)
(- (+ x t_0) (tan a))
(if (<= a 0.0023)
(+ (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z)))) (- x a))
(+ x (- t_0 (tan a)))))))
double code(double x, double y, double z, double a) {
double t_0 = tan((y + z));
double tmp;
if (a <= -0.00035) {
tmp = (x + t_0) - tan(a);
} else if (a <= 0.0023) {
tmp = ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) + (x - a);
} else {
tmp = x + (t_0 - 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) :: t_0
real(8) :: tmp
t_0 = tan((y + z))
if (a <= (-0.00035d0)) then
tmp = (x + t_0) - tan(a)
else if (a <= 0.0023d0) then
tmp = ((tan(y) + tan(z)) / (1.0d0 - (tan(y) * tan(z)))) + (x - a)
else
tmp = x + (t_0 - tan(a))
end if
code = tmp
end function
public static double code(double x, double y, double z, double a) {
double t_0 = Math.tan((y + z));
double tmp;
if (a <= -0.00035) {
tmp = (x + t_0) - Math.tan(a);
} else if (a <= 0.0023) {
tmp = ((Math.tan(y) + Math.tan(z)) / (1.0 - (Math.tan(y) * Math.tan(z)))) + (x - a);
} else {
tmp = x + (t_0 - Math.tan(a));
}
return tmp;
}
def code(x, y, z, a): t_0 = math.tan((y + z)) tmp = 0 if a <= -0.00035: tmp = (x + t_0) - math.tan(a) elif a <= 0.0023: tmp = ((math.tan(y) + math.tan(z)) / (1.0 - (math.tan(y) * math.tan(z)))) + (x - a) else: tmp = x + (t_0 - math.tan(a)) return tmp
function code(x, y, z, a) t_0 = tan(Float64(y + z)) tmp = 0.0 if (a <= -0.00035) tmp = Float64(Float64(x + t_0) - tan(a)); elseif (a <= 0.0023) tmp = Float64(Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z)))) + Float64(x - a)); else tmp = Float64(x + Float64(t_0 - tan(a))); end return tmp end
function tmp_2 = code(x, y, z, a) t_0 = tan((y + z)); tmp = 0.0; if (a <= -0.00035) tmp = (x + t_0) - tan(a); elseif (a <= 0.0023) tmp = ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) + (x - a); else tmp = x + (t_0 - tan(a)); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[a, -0.00035], N[(N[(x + t$95$0), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 0.0023], 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[(x - a), $MachinePrecision]), $MachinePrecision], N[(x + N[(t$95$0 - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \left(y + z\right)\\
\mathbf{if}\;a \leq -0.00035:\\
\;\;\;\;\left(x + t_0\right) - \tan a\\
\mathbf{elif}\;a \leq 0.0023:\\
\;\;\;\;\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} + \left(x - a\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(t_0 - \tan a\right)\\
\end{array}
\end{array}
if a < -3.49999999999999996e-4Initial program 83.3%
associate-+r-83.3%
+-commutative83.3%
Applied egg-rr83.3%
if -3.49999999999999996e-4 < a < 0.0023Initial program 77.7%
tan-sum99.8%
div-inv99.8%
fma-neg99.8%
Applied egg-rr99.8%
+-commutative99.8%
fma-udef99.8%
div-inv99.8%
tan-sum77.7%
sub-neg77.7%
associate--r-77.7%
tan-sum99.8%
div-inv99.8%
fma-neg99.8%
Applied egg-rr99.8%
fma-udef99.8%
unsub-neg99.8%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
Taylor expanded in a around 0 99.8%
neg-mul-199.8%
unsub-neg99.8%
Simplified99.8%
if 0.0023 < a Initial program 82.8%
Final simplification90.5%
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (tan (+ y z))))
(if (<= a -6.8e-7)
(- (+ x t_0) (tan a))
(if (<= a 1.05e-11)
(+ x (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z)))))
(+ x (- t_0 (tan a)))))))
double code(double x, double y, double z, double a) {
double t_0 = tan((y + z));
double tmp;
if (a <= -6.8e-7) {
tmp = (x + t_0) - tan(a);
} else if (a <= 1.05e-11) {
tmp = x + ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z))));
} else {
tmp = x + (t_0 - 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) :: t_0
real(8) :: tmp
t_0 = tan((y + z))
if (a <= (-6.8d-7)) then
tmp = (x + t_0) - tan(a)
else if (a <= 1.05d-11) then
tmp = x + ((tan(y) + tan(z)) / (1.0d0 - (tan(y) * tan(z))))
else
tmp = x + (t_0 - tan(a))
end if
code = tmp
end function
public static double code(double x, double y, double z, double a) {
double t_0 = Math.tan((y + z));
double tmp;
if (a <= -6.8e-7) {
tmp = (x + t_0) - Math.tan(a);
} else if (a <= 1.05e-11) {
tmp = x + ((Math.tan(y) + Math.tan(z)) / (1.0 - (Math.tan(y) * Math.tan(z))));
} else {
tmp = x + (t_0 - Math.tan(a));
}
return tmp;
}
def code(x, y, z, a): t_0 = math.tan((y + z)) tmp = 0 if a <= -6.8e-7: tmp = (x + t_0) - math.tan(a) elif a <= 1.05e-11: tmp = x + ((math.tan(y) + math.tan(z)) / (1.0 - (math.tan(y) * math.tan(z)))) else: tmp = x + (t_0 - math.tan(a)) return tmp
function code(x, y, z, a) t_0 = tan(Float64(y + z)) tmp = 0.0 if (a <= -6.8e-7) tmp = Float64(Float64(x + t_0) - tan(a)); elseif (a <= 1.05e-11) tmp = Float64(x + Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z))))); else tmp = Float64(x + Float64(t_0 - tan(a))); end return tmp end
function tmp_2 = code(x, y, z, a) t_0 = tan((y + z)); tmp = 0.0; if (a <= -6.8e-7) tmp = (x + t_0) - tan(a); elseif (a <= 1.05e-11) tmp = x + ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))); else tmp = x + (t_0 - tan(a)); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[a, -6.8e-7], N[(N[(x + t$95$0), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1.05e-11], 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], N[(x + N[(t$95$0 - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \left(y + z\right)\\
\mathbf{if}\;a \leq -6.8 \cdot 10^{-7}:\\
\;\;\;\;\left(x + t_0\right) - \tan a\\
\mathbf{elif}\;a \leq 1.05 \cdot 10^{-11}:\\
\;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\
\mathbf{else}:\\
\;\;\;\;x + \left(t_0 - \tan a\right)\\
\end{array}
\end{array}
if a < -6.79999999999999948e-7Initial program 83.3%
associate-+r-83.3%
+-commutative83.3%
Applied egg-rr83.3%
if -6.79999999999999948e-7 < a < 1.0499999999999999e-11Initial program 77.9%
+-commutative77.9%
associate-+l-77.9%
Applied egg-rr77.9%
Taylor expanded in a around 0 77.5%
neg-mul-177.5%
Simplified77.5%
sub-neg77.5%
add-sqr-sqrt0.0%
sqrt-unprod2.7%
sqr-neg2.7%
sqrt-unprod2.7%
add-sqr-sqrt2.7%
add-sqr-sqrt0.0%
sqrt-unprod77.5%
sqr-neg77.5%
sqrt-unprod77.0%
add-sqr-sqrt77.5%
Applied egg-rr77.5%
tan-sum98.6%
div-inv98.6%
Applied egg-rr98.6%
associate-*r/98.6%
*-rgt-identity98.6%
Simplified98.6%
if 1.0499999999999999e-11 < a Initial program 82.3%
Final simplification89.7%
(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 80.7%
Final simplification80.7%
(FPCore (x y z a) :precision binary64 (+ x (tan (+ y z))))
double code(double x, double y, double z, double a) {
return x + 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((y + z))
end function
public static double code(double x, double y, double z, double a) {
return x + Math.tan((y + z));
}
def code(x, y, z, a): return x + math.tan((y + z))
function code(x, y, z, a) return Float64(x + tan(Float64(y + z))) end
function tmp = code(x, y, z, a) tmp = x + tan((y + z)); end
code[x_, y_, z_, a_] := N[(x + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \tan \left(y + z\right)
\end{array}
Initial program 80.7%
+-commutative80.7%
associate-+l-80.6%
Applied egg-rr80.6%
Taylor expanded in a around 0 47.1%
neg-mul-147.1%
Simplified47.1%
sub-neg47.1%
add-sqr-sqrt0.0%
sqrt-unprod3.1%
sqr-neg3.1%
sqrt-unprod3.1%
add-sqr-sqrt3.1%
add-sqr-sqrt0.0%
sqrt-unprod47.1%
sqr-neg47.1%
sqrt-unprod46.9%
add-sqr-sqrt47.1%
Applied egg-rr47.1%
Final simplification47.1%
(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 80.7%
Taylor expanded in x around inf 29.5%
Final simplification29.5%
herbie shell --seed 2023312
(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))))