
(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 (let* ((t_0 (* (tan y) (tan z))) (t_1 (/ (cos a) (sin a)))) (+ x (/ (+ (* (+ (tan y) (tan z)) t_1) (+ t_0 -1.0)) (* t_1 (- 1.0 t_0))))))
double code(double x, double y, double z, double a) {
double t_0 = tan(y) * tan(z);
double t_1 = cos(a) / sin(a);
return x + ((((tan(y) + tan(z)) * t_1) + (t_0 + -1.0)) / (t_1 * (1.0 - t_0)));
}
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) :: t_1
t_0 = tan(y) * tan(z)
t_1 = cos(a) / sin(a)
code = x + ((((tan(y) + tan(z)) * t_1) + (t_0 + (-1.0d0))) / (t_1 * (1.0d0 - t_0)))
end function
public static double code(double x, double y, double z, double a) {
double t_0 = Math.tan(y) * Math.tan(z);
double t_1 = Math.cos(a) / Math.sin(a);
return x + ((((Math.tan(y) + Math.tan(z)) * t_1) + (t_0 + -1.0)) / (t_1 * (1.0 - t_0)));
}
def code(x, y, z, a): t_0 = math.tan(y) * math.tan(z) t_1 = math.cos(a) / math.sin(a) return x + ((((math.tan(y) + math.tan(z)) * t_1) + (t_0 + -1.0)) / (t_1 * (1.0 - t_0)))
function code(x, y, z, a) t_0 = Float64(tan(y) * tan(z)) t_1 = Float64(cos(a) / sin(a)) return Float64(x + Float64(Float64(Float64(Float64(tan(y) + tan(z)) * t_1) + Float64(t_0 + -1.0)) / Float64(t_1 * Float64(1.0 - t_0)))) end
function tmp = code(x, y, z, a) t_0 = tan(y) * tan(z); t_1 = cos(a) / sin(a); tmp = x + ((((tan(y) + tan(z)) * t_1) + (t_0 + -1.0)) / (t_1 * (1.0 - t_0))); end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[a], $MachinePrecision] / N[Sin[a], $MachinePrecision]), $MachinePrecision]}, N[(x + N[(N[(N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision] + N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision] / N[(t$95$1 * N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan y \cdot \tan z\\
t_1 := \frac{\cos a}{\sin a}\\
x + \frac{\left(\tan y + \tan z\right) \cdot t\_1 + \left(t\_0 + -1\right)}{t\_1 \cdot \left(1 - t\_0\right)}
\end{array}
\end{array}
Initial program 77.0%
add-sqr-sqrt36.2%
sqrt-unprod56.8%
pow256.8%
Applied egg-rr56.8%
sqrt-pow177.0%
metadata-eval77.0%
pow177.0%
tan-sum99.7%
tan-quot99.7%
clear-num99.7%
frac-sub99.7%
Applied egg-rr99.7%
*-rgt-identity99.7%
Simplified99.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 77.0%
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 (<= y -9.2e-8) (+ x (- (tan y) (tan a))) (+ x (- (tan z) (tan a)))))
double code(double x, double y, double z, double a) {
double tmp;
if (y <= -9.2e-8) {
tmp = x + (tan(y) - tan(a));
} 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 <= (-9.2d-8)) then
tmp = x + (tan(y) - tan(a))
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 <= -9.2e-8) {
tmp = x + (Math.tan(y) - Math.tan(a));
} else {
tmp = x + (Math.tan(z) - Math.tan(a));
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if y <= -9.2e-8: tmp = x + (math.tan(y) - math.tan(a)) else: tmp = x + (math.tan(z) - math.tan(a)) return tmp
function code(x, y, z, a) tmp = 0.0 if (y <= -9.2e-8) tmp = Float64(x + Float64(tan(y) - tan(a))); 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 <= -9.2e-8) tmp = x + (tan(y) - tan(a)); else tmp = x + (tan(z) - tan(a)); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[y, -9.2e-8], N[(x + N[(N[Tan[y], $MachinePrecision] - N[Tan[a], $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 -9.2 \cdot 10^{-8}:\\
\;\;\;\;x + \left(\tan y - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(\tan z - \tan a\right)\\
\end{array}
\end{array}
if y < -9.2000000000000003e-8Initial program 59.5%
add-exp-log53.5%
+-commutative53.5%
associate-+l-53.5%
Applied egg-rr53.5%
Taylor expanded in z around 0 53.4%
rem-exp-log59.5%
tan-quot59.4%
associate--r-59.5%
Applied egg-rr59.5%
if -9.2000000000000003e-8 < y Initial program 83.9%
Taylor expanded in y around 0 69.7%
tan-quot69.7%
*-un-lft-identity69.7%
Applied egg-rr69.7%
*-lft-identity69.7%
Simplified69.7%
Final simplification66.8%
(FPCore (x y z a) :precision binary64 (if (<= z 1.6) (+ x (- z (tan a))) (pow (cbrt x) 3.0)))
double code(double x, double y, double z, double a) {
double tmp;
if (z <= 1.6) {
tmp = x + (z - tan(a));
} else {
tmp = pow(cbrt(x), 3.0);
}
return tmp;
}
public static double code(double x, double y, double z, double a) {
double tmp;
if (z <= 1.6) {
tmp = x + (z - Math.tan(a));
} else {
tmp = Math.pow(Math.cbrt(x), 3.0);
}
return tmp;
}
function code(x, y, z, a) tmp = 0.0 if (z <= 1.6) tmp = Float64(x + Float64(z - tan(a))); else tmp = cbrt(x) ^ 3.0; end return tmp end
code[x_, y_, z_, a_] := If[LessEqual[z, 1.6], N[(x + N[(z - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[N[Power[x, 1/3], $MachinePrecision], 3.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.6:\\
\;\;\;\;x + \left(z - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\sqrt[3]{x}\right)}^{3}\\
\end{array}
\end{array}
if z < 1.6000000000000001Initial program 82.8%
Taylor expanded in y around 0 55.7%
Taylor expanded in z around 0 39.8%
if 1.6000000000000001 < z Initial program 59.3%
add-exp-log55.4%
+-commutative55.4%
associate-+l-55.3%
Applied egg-rr55.3%
Taylor expanded in x around inf 22.9%
mul-1-neg22.9%
log-rec22.9%
remove-double-neg22.9%
Simplified22.9%
add-cube-cbrt22.9%
pow322.9%
rem-exp-log22.9%
Applied egg-rr22.9%
Final simplification35.6%
(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 77.0%
Final simplification77.0%
(FPCore (x y z a) :precision binary64 (if (<= z 1.6) (+ x (- z (tan a))) (exp (log x))))
double code(double x, double y, double z, double a) {
double tmp;
if (z <= 1.6) {
tmp = x + (z - tan(a));
} else {
tmp = exp(log(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 (z <= 1.6d0) then
tmp = x + (z - tan(a))
else
tmp = exp(log(x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double a) {
double tmp;
if (z <= 1.6) {
tmp = x + (z - Math.tan(a));
} else {
tmp = Math.exp(Math.log(x));
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if z <= 1.6: tmp = x + (z - math.tan(a)) else: tmp = math.exp(math.log(x)) return tmp
function code(x, y, z, a) tmp = 0.0 if (z <= 1.6) tmp = Float64(x + Float64(z - tan(a))); else tmp = exp(log(x)); end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if (z <= 1.6) tmp = x + (z - tan(a)); else tmp = exp(log(x)); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[z, 1.6], N[(x + N[(z - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Exp[N[Log[x], $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.6:\\
\;\;\;\;x + \left(z - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;e^{\log x}\\
\end{array}
\end{array}
if z < 1.6000000000000001Initial program 82.8%
Taylor expanded in y around 0 55.7%
Taylor expanded in z around 0 39.8%
if 1.6000000000000001 < z Initial program 59.3%
add-exp-log55.4%
+-commutative55.4%
associate-+l-55.3%
Applied egg-rr55.3%
Taylor expanded in x around inf 22.9%
mul-1-neg22.9%
log-rec22.9%
remove-double-neg22.9%
Simplified22.9%
Final simplification35.6%
(FPCore (x y z a) :precision binary64 (+ x (- (tan z) (tan a))))
double code(double x, double y, double z, double a) {
return x + (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(z) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
return x + (Math.tan(z) - Math.tan(a));
}
def code(x, y, z, a): return x + (math.tan(z) - math.tan(a))
function code(x, y, z, a) return Float64(x + Float64(tan(z) - tan(a))) end
function tmp = code(x, y, z, a) tmp = x + (tan(z) - tan(a)); end
code[x_, y_, z_, a_] := N[(x + N[(N[Tan[z], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\tan z - \tan a\right)
\end{array}
Initial program 77.0%
Taylor expanded in y around 0 56.5%
tan-quot56.5%
*-un-lft-identity56.5%
Applied egg-rr56.5%
*-lft-identity56.5%
Simplified56.5%
Final simplification56.5%
(FPCore (x y z a) :precision binary64 (if (<= z 1.8) (+ x (- z (tan a))) x))
double code(double x, double y, double z, double a) {
double tmp;
if (z <= 1.8) {
tmp = x + (z - tan(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 (z <= 1.8d0) then
tmp = x + (z - tan(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 (z <= 1.8) {
tmp = x + (z - Math.tan(a));
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if z <= 1.8: tmp = x + (z - math.tan(a)) else: tmp = x return tmp
function code(x, y, z, a) tmp = 0.0 if (z <= 1.8) tmp = Float64(x + Float64(z - tan(a))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if (z <= 1.8) tmp = x + (z - tan(a)); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[z, 1.8], N[(x + N[(z - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.8:\\
\;\;\;\;x + \left(z - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < 1.80000000000000004Initial program 82.8%
Taylor expanded in y around 0 55.7%
Taylor expanded in z around 0 39.8%
if 1.80000000000000004 < z Initial program 59.3%
Taylor expanded in x around inf 22.9%
Final simplification35.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 77.0%
Taylor expanded in x around inf 32.1%
Final simplification32.1%
herbie shell --seed 2024080
(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))))