
(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 (- 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 / (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 / (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 / (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 / (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(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 / (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[(1.0 - N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(\tan y + \tan z\right) \cdot \frac{1}{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%
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
(let* ((t_0 (tan (+ y z))))
(if (or (<= t_0 -0.02) (not (<= t_0 5e-13)))
(+ x t_0)
(+ x (- y (tan a))))))
double code(double x, double y, double z, double a) {
double t_0 = tan((y + z));
double tmp;
if ((t_0 <= -0.02) || !(t_0 <= 5e-13)) {
tmp = x + t_0;
} else {
tmp = x + (y - 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 ((t_0 <= (-0.02d0)) .or. (.not. (t_0 <= 5d-13))) then
tmp = x + t_0
else
tmp = x + (y - 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 ((t_0 <= -0.02) || !(t_0 <= 5e-13)) {
tmp = x + t_0;
} else {
tmp = x + (y - Math.tan(a));
}
return tmp;
}
def code(x, y, z, a): t_0 = math.tan((y + z)) tmp = 0 if (t_0 <= -0.02) or not (t_0 <= 5e-13): tmp = x + t_0 else: tmp = x + (y - math.tan(a)) return tmp
function code(x, y, z, a) t_0 = tan(Float64(y + z)) tmp = 0.0 if ((t_0 <= -0.02) || !(t_0 <= 5e-13)) tmp = Float64(x + t_0); else tmp = Float64(x + Float64(y - tan(a))); end return tmp end
function tmp_2 = code(x, y, z, a) t_0 = tan((y + z)); tmp = 0.0; if ((t_0 <= -0.02) || ~((t_0 <= 5e-13))) tmp = x + t_0; else tmp = x + (y - tan(a)); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[t$95$0, -0.02], N[Not[LessEqual[t$95$0, 5e-13]], $MachinePrecision]], N[(x + t$95$0), $MachinePrecision], N[(x + N[(y - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan \left(y + z\right)\\
\mathbf{if}\;t\_0 \leq -0.02 \lor \neg \left(t\_0 \leq 5 \cdot 10^{-13}\right):\\
\;\;\;\;x + t\_0\\
\mathbf{else}:\\
\;\;\;\;x + \left(y - \tan a\right)\\
\end{array}
\end{array}
if (tan.f64 (+.f64 y z)) < -0.0200000000000000004 or 4.9999999999999999e-13 < (tan.f64 (+.f64 y z)) Initial program 68.9%
add-cbrt-cube68.5%
pow1/362.3%
pow362.2%
+-commutative62.2%
associate-+l-62.3%
Applied egg-rr62.3%
Taylor expanded in a around 0 41.9%
unpow1/345.4%
rem-cbrt-cube45.6%
+-commutative45.6%
quot-tan45.6%
Applied egg-rr45.6%
if -0.0200000000000000004 < (tan.f64 (+.f64 y z)) < 4.9999999999999999e-13Initial program 99.9%
add-sqr-sqrt47.7%
sqrt-unprod99.3%
pow299.3%
Applied egg-rr99.3%
Taylor expanded in z around 0 99.3%
Taylor expanded in y around 0 99.9%
Final simplification59.8%
(FPCore (x y z a) :precision binary64 (if (<= (+ y z) 5e-13) (+ x (- (tan y) (tan a))) (+ x (tan (+ y z)))))
double code(double x, double y, double z, double a) {
double tmp;
if ((y + z) <= 5e-13) {
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 ((y + z) <= 5d-13) 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 ((y + z) <= 5e-13) {
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 (y + z) <= 5e-13: 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 (Float64(y + z) <= 5e-13) 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 ((y + z) <= 5e-13) tmp = x + (tan(y) - tan(a)); else tmp = x + tan((y + z)); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[N[(y + z), $MachinePrecision], 5e-13], 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}\;y + z \leq 5 \cdot 10^{-13}:\\
\;\;\;\;x + \left(\tan y - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;x + \tan \left(y + z\right)\\
\end{array}
\end{array}
if (+.f64 y z) < 4.9999999999999999e-13Initial program 80.9%
add-sqr-sqrt36.7%
sqrt-unprod64.5%
pow264.5%
Applied egg-rr64.5%
Taylor expanded in z around 0 58.3%
tan-quot58.4%
sqrt-pow166.1%
metadata-eval66.1%
pow166.1%
*-un-lft-identity66.1%
Applied egg-rr66.1%
*-lft-identity66.1%
Simplified66.1%
if 4.9999999999999999e-13 < (+.f64 y z) Initial program 69.9%
add-cbrt-cube69.5%
pow1/362.3%
pow362.2%
+-commutative62.2%
associate-+l-62.3%
Applied egg-rr62.3%
Taylor expanded in a around 0 38.1%
unpow1/342.5%
rem-cbrt-cube42.7%
+-commutative42.7%
quot-tan42.7%
Applied egg-rr42.7%
Final simplification57.8%
(FPCore (x y z a) :precision binary64 (if (<= z 2.4e-7) (+ x (- (tan y) (tan a))) (+ x (- (tan z) (tan a)))))
double code(double x, double y, double z, double a) {
double tmp;
if (z <= 2.4e-7) {
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 (z <= 2.4d-7) 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 (z <= 2.4e-7) {
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 z <= 2.4e-7: 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 (z <= 2.4e-7) 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 (z <= 2.4e-7) 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[z, 2.4e-7], 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}\;z \leq 2.4 \cdot 10^{-7}:\\
\;\;\;\;x + \left(\tan y - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(\tan z - \tan a\right)\\
\end{array}
\end{array}
if z < 2.39999999999999979e-7Initial program 84.6%
add-sqr-sqrt37.3%
sqrt-unprod64.0%
pow264.0%
Applied egg-rr64.0%
Taylor expanded in z around 0 58.5%
tan-quot58.5%
sqrt-pow171.5%
metadata-eval71.5%
pow171.5%
*-un-lft-identity71.5%
Applied egg-rr71.5%
*-lft-identity71.5%
Simplified71.5%
if 2.39999999999999979e-7 < z Initial program 56.8%
Taylor expanded in y around 0 56.9%
tan-quot56.9%
tan-quot56.9%
associate-+r-56.9%
tan-quot56.9%
+-commutative56.9%
tan-quot56.9%
Applied egg-rr56.9%
Final simplification67.5%
(FPCore (x y z a) :precision binary64 (if (<= z 6.8e-7) (- (+ x (tan y)) (tan a)) (+ x (- (tan z) (tan a)))))
double code(double x, double y, double z, double a) {
double tmp;
if (z <= 6.8e-7) {
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 (z <= 6.8d-7) 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 (z <= 6.8e-7) {
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 z <= 6.8e-7: 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 (z <= 6.8e-7) tmp = Float64(Float64(x + 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 (z <= 6.8e-7) 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[z, 6.8e-7], N[(N[(x + N[Tan[y], $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision], N[(x + N[(N[Tan[z], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 6.8 \cdot 10^{-7}:\\
\;\;\;\;\left(x + \tan y\right) - \tan a\\
\mathbf{else}:\\
\;\;\;\;x + \left(\tan z - \tan a\right)\\
\end{array}
\end{array}
if z < 6.79999999999999948e-7Initial program 84.6%
add-sqr-sqrt37.3%
sqrt-unprod64.0%
pow264.0%
Applied egg-rr64.0%
Taylor expanded in z around 0 58.5%
tan-quot58.5%
sqrt-pow171.5%
metadata-eval71.5%
pow171.5%
log1p-expm1-u71.2%
Applied egg-rr71.2%
log1p-expm1-u71.5%
associate-+r-71.4%
Applied egg-rr71.4%
if 6.79999999999999948e-7 < z Initial program 56.8%
Taylor expanded in y around 0 56.9%
tan-quot56.9%
tan-quot56.9%
associate-+r-56.9%
tan-quot56.9%
+-commutative56.9%
tan-quot56.9%
Applied egg-rr56.9%
Final simplification67.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 77.0%
Final simplification77.0%
(FPCore (x y z a) :precision binary64 (if (<= y -1.15) x (+ x (- y (tan a)))))
double code(double x, double y, double z, double a) {
double tmp;
if (y <= -1.15) {
tmp = x;
} else {
tmp = x + (y - 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 <= (-1.15d0)) then
tmp = x
else
tmp = x + (y - tan(a))
end if
code = tmp
end function
public static double code(double x, double y, double z, double a) {
double tmp;
if (y <= -1.15) {
tmp = x;
} else {
tmp = x + (y - Math.tan(a));
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if y <= -1.15: tmp = x else: tmp = x + (y - math.tan(a)) return tmp
function code(x, y, z, a) tmp = 0.0 if (y <= -1.15) tmp = x; else tmp = Float64(x + Float64(y - tan(a))); end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if (y <= -1.15) tmp = x; else tmp = x + (y - tan(a)); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[y, -1.15], x, N[(x + N[(y - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x + \left(y - \tan a\right)\\
\end{array}
\end{array}
if y < -1.1499999999999999Initial program 51.8%
Taylor expanded in x around inf 24.0%
if -1.1499999999999999 < y Initial program 85.6%
add-sqr-sqrt40.3%
sqrt-unprod65.9%
pow265.9%
Applied egg-rr65.9%
Taylor expanded in z around 0 53.9%
Taylor expanded in y around 0 44.1%
Final simplification39.0%
(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 31.9%
Final simplification31.9%
herbie shell --seed 2024075
(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))))