
(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 10 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)) (- (fma (tan y) (tan z) -1.0))) (tan a))))
double code(double x, double y, double z, double a) {
return x + (((tan(y) + tan(z)) / -fma(tan(y), tan(z), -1.0)) - tan(a));
}
function code(x, y, z, a) return Float64(x + Float64(Float64(Float64(tan(y) + tan(z)) / Float64(-fma(tan(y), tan(z), -1.0))) - tan(a))) end
code[x_, y_, z_, a_] := N[(x + N[(N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] / (-N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision] + -1.0), $MachinePrecision])), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\frac{\tan y + \tan z}{-\mathsf{fma}\left(\tan y, \tan z, -1\right)} - \tan a\right)
\end{array}
Initial program 79.5%
tan-sum99.6%
div-inv99.6%
Applied egg-rr99.6%
associate-*r/99.6%
*-rgt-identity99.6%
Simplified99.6%
expm1-log1p-u94.9%
expm1-udef94.9%
log1p-udef94.9%
add-exp-log99.6%
Applied egg-rr99.6%
associate--l+99.6%
Applied egg-rr99.6%
fma-neg99.6%
metadata-eval99.6%
Simplified99.6%
associate-+r-99.5%
associate--r+99.5%
metadata-eval99.5%
Applied egg-rr99.5%
associate--l+99.6%
sub0-neg99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (tan (+ y z))))
(if (<= (tan a) -1e-11)
(log (/ (+ 1.0 (expm1 (+ x t_0))) (exp (tan a))))
(if (<= (tan a) 5e-20)
(fma (+ (tan y) (tan z)) (/ 1.0 (- 1.0 (* (tan y) (tan z)))) x)
(+ x (- t_0 (tan a)))))))
double code(double x, double y, double z, double a) {
double t_0 = tan((y + z));
double tmp;
if (tan(a) <= -1e-11) {
tmp = log(((1.0 + expm1((x + t_0))) / exp(tan(a))));
} else if (tan(a) <= 5e-20) {
tmp = fma((tan(y) + tan(z)), (1.0 / (1.0 - (tan(y) * tan(z)))), x);
} else {
tmp = x + (t_0 - tan(a));
}
return tmp;
}
function code(x, y, z, a) t_0 = tan(Float64(y + z)) tmp = 0.0 if (tan(a) <= -1e-11) tmp = log(Float64(Float64(1.0 + expm1(Float64(x + t_0))) / exp(tan(a)))); elseif (tan(a) <= 5e-20) tmp = fma(Float64(tan(y) + tan(z)), Float64(1.0 / Float64(1.0 - Float64(tan(y) * tan(z)))), x); else tmp = Float64(x + Float64(t_0 - tan(a))); end return tmp end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -1e-11], N[Log[N[(N[(1.0 + N[(Exp[N[(x + t$95$0), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] / N[Exp[N[Tan[a], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Tan[a], $MachinePrecision], 5e-20], 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] + x), $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}\;\tan a \leq -1 \cdot 10^{-11}:\\
\;\;\;\;\log \left(\frac{1 + \mathsf{expm1}\left(x + t_0\right)}{e^{\tan a}}\right)\\
\mathbf{elif}\;\tan a \leq 5 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(\tan y + \tan z, \frac{1}{1 - \tan y \cdot \tan z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(t_0 - \tan a\right)\\
\end{array}
\end{array}
if (tan.f64 a) < -9.99999999999999939e-12Initial program 73.8%
associate-+r-73.8%
log1p-expm1-u73.8%
log1p-udef73.8%
add-log-exp73.8%
diff-log73.9%
+-commutative73.9%
Applied egg-rr73.9%
if -9.99999999999999939e-12 < (tan.f64 a) < 4.9999999999999999e-20Initial program 80.0%
+-commutative80.0%
associate-+l-80.0%
Applied egg-rr80.0%
Taylor expanded in a around 0 80.0%
neg-mul-180.0%
Simplified80.0%
sub-neg80.0%
Applied egg-rr80.0%
remove-double-neg80.0%
+-commutative80.0%
+-commutative80.0%
Simplified80.0%
+-commutative80.0%
+-commutative80.0%
tan-sum99.6%
div-inv99.6%
fma-def99.6%
Applied egg-rr99.6%
if 4.9999999999999999e-20 < (tan.f64 a) Initial program 82.8%
Final simplification89.3%
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (tan (+ y z))))
(if (<= (tan a) -1e-11)
(log (/ (+ 1.0 (expm1 (+ x t_0))) (exp (tan a))))
(if (<= (tan a) 5e-20)
(+
x
(/ (+ (tan y) (tan z)) (- 1.0 (+ -1.0 (+ 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 (tan(a) <= -1e-11) {
tmp = log(((1.0 + expm1((x + t_0))) / exp(tan(a))));
} else if (tan(a) <= 5e-20) {
tmp = x + ((tan(y) + tan(z)) / (1.0 - (-1.0 + (1.0 + (tan(y) * tan(z))))));
} else {
tmp = x + (t_0 - tan(a));
}
return tmp;
}
public static double code(double x, double y, double z, double a) {
double t_0 = Math.tan((y + z));
double tmp;
if (Math.tan(a) <= -1e-11) {
tmp = Math.log(((1.0 + Math.expm1((x + t_0))) / Math.exp(Math.tan(a))));
} else if (Math.tan(a) <= 5e-20) {
tmp = x + ((Math.tan(y) + Math.tan(z)) / (1.0 - (-1.0 + (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 math.tan(a) <= -1e-11: tmp = math.log(((1.0 + math.expm1((x + t_0))) / math.exp(math.tan(a)))) elif math.tan(a) <= 5e-20: tmp = x + ((math.tan(y) + math.tan(z)) / (1.0 - (-1.0 + (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 (tan(a) <= -1e-11) tmp = log(Float64(Float64(1.0 + expm1(Float64(x + t_0))) / exp(tan(a)))); elseif (tan(a) <= 5e-20) tmp = Float64(x + Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(-1.0 + Float64(1.0 + Float64(tan(y) * tan(z))))))); else tmp = Float64(x + Float64(t_0 - tan(a))); end return tmp end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -1e-11], N[Log[N[(N[(1.0 + N[(Exp[N[(x + t$95$0), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] / N[Exp[N[Tan[a], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Tan[a], $MachinePrecision], 5e-20], N[(x + N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(-1.0 + N[(1.0 + N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $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}\;\tan a \leq -1 \cdot 10^{-11}:\\
\;\;\;\;\log \left(\frac{1 + \mathsf{expm1}\left(x + t_0\right)}{e^{\tan a}}\right)\\
\mathbf{elif}\;\tan a \leq 5 \cdot 10^{-20}:\\
\;\;\;\;x + \frac{\tan y + \tan z}{1 - \left(-1 + \left(1 + \tan y \cdot \tan z\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;x + \left(t_0 - \tan a\right)\\
\end{array}
\end{array}
if (tan.f64 a) < -9.99999999999999939e-12Initial program 73.8%
associate-+r-73.8%
log1p-expm1-u73.8%
log1p-udef73.8%
add-log-exp73.8%
diff-log73.9%
+-commutative73.9%
Applied egg-rr73.9%
if -9.99999999999999939e-12 < (tan.f64 a) < 4.9999999999999999e-20Initial program 80.0%
+-commutative80.0%
associate-+l-80.0%
Applied egg-rr80.0%
Taylor expanded in a around 0 80.0%
neg-mul-180.0%
Simplified80.0%
tan-sum99.7%
div-inv99.7%
Applied egg-rr99.6%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.6%
expm1-log1p-u95.0%
expm1-udef95.0%
log1p-udef95.0%
add-exp-log99.7%
Applied egg-rr99.6%
if 4.9999999999999999e-20 < (tan.f64 a) Initial program 82.8%
Final simplification89.3%
(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 79.5%
tan-sum99.6%
div-inv99.6%
Applied egg-rr99.6%
associate-*r/99.6%
*-rgt-identity99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (tan (+ y z))))
(if (<= a -3.5e-12)
(+ x (- t_0 (tan a)))
(if (<= a 1.25e-17)
(+
x
(/ (+ (tan y) (tan z)) (- 1.0 (+ -1.0 (+ 1.0 (* (tan y) (tan z)))))))
(log (exp (+ t_0 (- x (tan a)))))))))
double code(double x, double y, double z, double a) {
double t_0 = tan((y + z));
double tmp;
if (a <= -3.5e-12) {
tmp = x + (t_0 - tan(a));
} else if (a <= 1.25e-17) {
tmp = x + ((tan(y) + tan(z)) / (1.0 - (-1.0 + (1.0 + (tan(y) * tan(z))))));
} else {
tmp = log(exp((t_0 + (x - 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 <= (-3.5d-12)) then
tmp = x + (t_0 - tan(a))
else if (a <= 1.25d-17) then
tmp = x + ((tan(y) + tan(z)) / (1.0d0 - ((-1.0d0) + (1.0d0 + (tan(y) * tan(z))))))
else
tmp = log(exp((t_0 + (x - 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 <= -3.5e-12) {
tmp = x + (t_0 - Math.tan(a));
} else if (a <= 1.25e-17) {
tmp = x + ((Math.tan(y) + Math.tan(z)) / (1.0 - (-1.0 + (1.0 + (Math.tan(y) * Math.tan(z))))));
} else {
tmp = Math.log(Math.exp((t_0 + (x - Math.tan(a)))));
}
return tmp;
}
def code(x, y, z, a): t_0 = math.tan((y + z)) tmp = 0 if a <= -3.5e-12: tmp = x + (t_0 - math.tan(a)) elif a <= 1.25e-17: tmp = x + ((math.tan(y) + math.tan(z)) / (1.0 - (-1.0 + (1.0 + (math.tan(y) * math.tan(z)))))) else: tmp = math.log(math.exp((t_0 + (x - math.tan(a))))) return tmp
function code(x, y, z, a) t_0 = tan(Float64(y + z)) tmp = 0.0 if (a <= -3.5e-12) tmp = Float64(x + Float64(t_0 - tan(a))); elseif (a <= 1.25e-17) tmp = Float64(x + Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(-1.0 + Float64(1.0 + Float64(tan(y) * tan(z))))))); else tmp = log(exp(Float64(t_0 + Float64(x - tan(a))))); end return tmp end
function tmp_2 = code(x, y, z, a) t_0 = tan((y + z)); tmp = 0.0; if (a <= -3.5e-12) tmp = x + (t_0 - tan(a)); elseif (a <= 1.25e-17) tmp = x + ((tan(y) + tan(z)) / (1.0 - (-1.0 + (1.0 + (tan(y) * tan(z)))))); else tmp = log(exp((t_0 + (x - 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, -3.5e-12], N[(x + N[(t$95$0 - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1.25e-17], N[(x + N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(-1.0 + N[(1.0 + N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[N[Exp[N[(t$95$0 + N[(x - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \left(y + z\right)\\
\mathbf{if}\;a \leq -3.5 \cdot 10^{-12}:\\
\;\;\;\;x + \left(t_0 - \tan a\right)\\
\mathbf{elif}\;a \leq 1.25 \cdot 10^{-17}:\\
\;\;\;\;x + \frac{\tan y + \tan z}{1 - \left(-1 + \left(1 + \tan y \cdot \tan z\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{t_0 + \left(x - \tan a\right)}\right)\\
\end{array}
\end{array}
if a < -3.5e-12Initial program 79.1%
if -3.5e-12 < a < 1.25e-17Initial program 80.0%
+-commutative80.0%
associate-+l-80.0%
Applied egg-rr80.0%
Taylor expanded in a around 0 80.0%
neg-mul-180.0%
Simplified80.0%
tan-sum99.7%
div-inv99.7%
Applied egg-rr99.6%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.6%
expm1-log1p-u95.0%
expm1-udef95.0%
log1p-udef95.0%
add-exp-log99.7%
Applied egg-rr99.6%
if 1.25e-17 < a Initial program 78.9%
associate-+r-78.9%
add-log-exp78.9%
+-commutative78.9%
associate--l+79.0%
Applied egg-rr79.0%
Final simplification89.3%
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (tan (+ y z))))
(if (<= a -1.26e-11)
(+ x (- t_0 (tan a)))
(if (<= a 1.25e-17)
(+ x (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z)))))
(log (exp (+ t_0 (- x (tan a)))))))))
double code(double x, double y, double z, double a) {
double t_0 = tan((y + z));
double tmp;
if (a <= -1.26e-11) {
tmp = x + (t_0 - tan(a));
} else if (a <= 1.25e-17) {
tmp = x + ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z))));
} else {
tmp = log(exp((t_0 + (x - 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 <= (-1.26d-11)) then
tmp = x + (t_0 - tan(a))
else if (a <= 1.25d-17) then
tmp = x + ((tan(y) + tan(z)) / (1.0d0 - (tan(y) * tan(z))))
else
tmp = log(exp((t_0 + (x - 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 <= -1.26e-11) {
tmp = x + (t_0 - Math.tan(a));
} else if (a <= 1.25e-17) {
tmp = x + ((Math.tan(y) + Math.tan(z)) / (1.0 - (Math.tan(y) * Math.tan(z))));
} else {
tmp = Math.log(Math.exp((t_0 + (x - Math.tan(a)))));
}
return tmp;
}
def code(x, y, z, a): t_0 = math.tan((y + z)) tmp = 0 if a <= -1.26e-11: tmp = x + (t_0 - math.tan(a)) elif a <= 1.25e-17: tmp = x + ((math.tan(y) + math.tan(z)) / (1.0 - (math.tan(y) * math.tan(z)))) else: tmp = math.log(math.exp((t_0 + (x - math.tan(a))))) return tmp
function code(x, y, z, a) t_0 = tan(Float64(y + z)) tmp = 0.0 if (a <= -1.26e-11) tmp = Float64(x + Float64(t_0 - tan(a))); elseif (a <= 1.25e-17) tmp = Float64(x + Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z))))); else tmp = log(exp(Float64(t_0 + Float64(x - tan(a))))); end return tmp end
function tmp_2 = code(x, y, z, a) t_0 = tan((y + z)); tmp = 0.0; if (a <= -1.26e-11) tmp = x + (t_0 - tan(a)); elseif (a <= 1.25e-17) tmp = x + ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))); else tmp = log(exp((t_0 + (x - 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, -1.26e-11], N[(x + N[(t$95$0 - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1.25e-17], 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[Log[N[Exp[N[(t$95$0 + N[(x - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \left(y + z\right)\\
\mathbf{if}\;a \leq -1.26 \cdot 10^{-11}:\\
\;\;\;\;x + \left(t_0 - \tan a\right)\\
\mathbf{elif}\;a \leq 1.25 \cdot 10^{-17}:\\
\;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{t_0 + \left(x - \tan a\right)}\right)\\
\end{array}
\end{array}
if a < -1.26e-11Initial program 79.1%
if -1.26e-11 < a < 1.25e-17Initial program 80.0%
+-commutative80.0%
associate-+l-80.0%
Applied egg-rr80.0%
Taylor expanded in a around 0 80.0%
neg-mul-180.0%
Simplified80.0%
sub-neg80.0%
Applied egg-rr80.0%
remove-double-neg80.0%
+-commutative80.0%
+-commutative80.0%
Simplified80.0%
+-commutative80.0%
+-commutative80.0%
tan-sum99.6%
div-inv99.6%
fma-def99.6%
Applied egg-rr99.6%
fma-udef99.6%
associate-*r/99.6%
*-rgt-identity99.6%
Simplified99.6%
if 1.25e-17 < a Initial program 78.9%
associate-+r-78.9%
add-log-exp78.9%
+-commutative78.9%
associate--l+79.0%
Applied egg-rr79.0%
Final simplification89.3%
(FPCore (x y z a) :precision binary64 (if (<= z 0.052) (+ x (- (tan y) (tan a))) (+ x (tan (+ y z)))))
double code(double x, double y, double z, double a) {
double tmp;
if (z <= 0.052) {
tmp = x + (tan(y) - tan(a));
} else {
tmp = x + 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 (z <= 0.052d0) then
tmp = x + (tan(y) - tan(a))
else
tmp = x + tan((y + z))
end if
code = tmp
end function
public static double code(double x, double y, double z, double a) {
double tmp;
if (z <= 0.052) {
tmp = x + (Math.tan(y) - Math.tan(a));
} else {
tmp = x + Math.tan((y + z));
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if z <= 0.052: tmp = x + (math.tan(y) - math.tan(a)) else: tmp = x + math.tan((y + z)) return tmp
function code(x, y, z, a) tmp = 0.0 if (z <= 0.052) tmp = Float64(x + Float64(tan(y) - tan(a))); else tmp = Float64(x + tan(Float64(y + z))); end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if (z <= 0.052) tmp = x + (tan(y) - tan(a)); else tmp = x + tan((y + z)); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[z, 0.052], N[(x + N[(N[Tan[y], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.052:\\
\;\;\;\;x + \left(\tan y - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;x + \tan \left(y + z\right)\\
\end{array}
\end{array}
if z < 0.0519999999999999976Initial program 86.3%
Taylor expanded in z around 0 71.0%
tan-quot71.1%
tan-quot71.1%
associate--l+71.1%
Applied egg-rr71.1%
associate-+r-71.1%
+-commutative71.1%
associate--l+71.1%
Simplified71.1%
if 0.0519999999999999976 < z Initial program 60.6%
+-commutative60.6%
associate-+l-60.5%
Applied egg-rr60.5%
Taylor expanded in a around 0 50.0%
neg-mul-150.0%
Simplified50.0%
sub-neg50.0%
Applied egg-rr50.0%
remove-double-neg50.0%
+-commutative50.0%
+-commutative50.0%
Simplified50.0%
Final simplification65.5%
(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 79.5%
Final simplification79.5%
(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 79.5%
+-commutative79.5%
associate-+l-79.5%
Applied egg-rr79.5%
Taylor expanded in a around 0 51.6%
neg-mul-151.6%
Simplified51.6%
sub-neg51.6%
Applied egg-rr51.6%
remove-double-neg51.6%
+-commutative51.6%
+-commutative51.6%
Simplified51.6%
Final simplification51.6%
(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 79.5%
Taylor expanded in x around inf 29.6%
Final simplification29.6%
herbie shell --seed 2023257
(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))))