
(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 (cbrt (pow (* (tan y) (tan z)) 3.0)))) (tan a))))
double code(double x, double y, double z, double a) {
return x + (((tan(y) + tan(z)) / (1.0 - cbrt(pow((tan(y) * tan(z)), 3.0)))) - tan(a));
}
public static double code(double x, double y, double z, double a) {
return x + (((Math.tan(y) + Math.tan(z)) / (1.0 - Math.cbrt(Math.pow((Math.tan(y) * Math.tan(z)), 3.0)))) - Math.tan(a));
}
function code(x, y, z, a) return Float64(x + Float64(Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - cbrt((Float64(tan(y) * tan(z)) ^ 3.0)))) - 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[Power[N[Power[N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\frac{\tan y + \tan z}{1 - \sqrt[3]{{\left(\tan y \cdot \tan z\right)}^{3}}} - \tan a\right)
\end{array}
Initial program 77.4%
tan-sum99.7%
div-inv99.7%
Applied egg-rr99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
add-cbrt-cube99.8%
pow399.8%
Applied egg-rr99.8%
Final simplification99.8%
(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.4%
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 z) 4e-14) (+ x (- (tan y) (tan a))) (+ x (tan (+ y z)))))
double code(double x, double y, double z, double a) {
double tmp;
if ((y + z) <= 4e-14) {
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) <= 4d-14) 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) <= 4e-14) {
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) <= 4e-14: 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) <= 4e-14) 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) <= 4e-14) 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], 4e-14], 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 4 \cdot 10^{-14}:\\
\;\;\;\;x + \left(\tan y - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;x + \tan \left(y + z\right)\\
\end{array}
\end{array}
if (+.f64 y z) < 4e-14Initial program 80.3%
Taylor expanded in z around 0 67.3%
+-commutative67.3%
associate--l+67.3%
Simplified67.3%
tan-quot67.3%
tan-quot67.4%
associate-+r-67.3%
Applied egg-rr67.3%
+-commutative67.3%
associate--l+67.4%
Simplified67.4%
if 4e-14 < (+.f64 y z) Initial program 72.1%
expm1-log1p-u66.8%
+-commutative66.8%
associate-+l-66.7%
Applied egg-rr66.7%
Taylor expanded in a around 0 44.7%
associate-+r+44.7%
Simplified44.7%
associate-+l+44.7%
log1p-define44.7%
expm1-log1p-u45.4%
quot-tan45.4%
Applied egg-rr45.4%
Final simplification59.6%
(FPCore (x y z a) :precision binary64 (if (<= (+ y z) -1e-12) (+ x (- (tan y) (tan a))) (+ x (- (tan z) (tan a)))))
double code(double x, double y, double z, double a) {
double tmp;
if ((y + z) <= -1e-12) {
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 + z) <= (-1d-12)) 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 + z) <= -1e-12) {
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 + z) <= -1e-12: 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 (Float64(y + z) <= -1e-12) 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 + z) <= -1e-12) 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[N[(y + z), $MachinePrecision], -1e-12], 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 + z \leq -1 \cdot 10^{-12}:\\
\;\;\;\;x + \left(\tan y - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(\tan z - \tan a\right)\\
\end{array}
\end{array}
if (+.f64 y z) < -9.9999999999999998e-13Initial program 68.9%
Taylor expanded in z around 0 48.2%
+-commutative48.2%
associate--l+48.2%
Simplified48.2%
tan-quot48.3%
tan-quot48.3%
associate-+r-48.3%
Applied egg-rr48.3%
+-commutative48.3%
associate--l+48.3%
Simplified48.3%
if -9.9999999999999998e-13 < (+.f64 y z) Initial program 83.3%
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 simplification61.0%
(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.4%
Final simplification77.4%
(FPCore (x y z a) :precision binary64 (if (or (<= (+ y z) -1e-12) (not (<= (+ y z) 4e-14))) (+ x (tan (+ y z))) (+ x (- z (tan a)))))
double code(double x, double y, double z, double a) {
double tmp;
if (((y + z) <= -1e-12) || !((y + z) <= 4e-14)) {
tmp = x + tan((y + z));
} else {
tmp = x + (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 + z) <= (-1d-12)) .or. (.not. ((y + z) <= 4d-14))) then
tmp = x + tan((y + z))
else
tmp = x + (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 + z) <= -1e-12) || !((y + z) <= 4e-14)) {
tmp = x + Math.tan((y + z));
} else {
tmp = x + (z - Math.tan(a));
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if ((y + z) <= -1e-12) or not ((y + z) <= 4e-14): tmp = x + math.tan((y + z)) else: tmp = x + (z - math.tan(a)) return tmp
function code(x, y, z, a) tmp = 0.0 if ((Float64(y + z) <= -1e-12) || !(Float64(y + z) <= 4e-14)) tmp = Float64(x + tan(Float64(y + z))); else tmp = Float64(x + Float64(z - tan(a))); end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if (((y + z) <= -1e-12) || ~(((y + z) <= 4e-14))) tmp = x + tan((y + z)); else tmp = x + (z - tan(a)); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[Or[LessEqual[N[(y + z), $MachinePrecision], -1e-12], N[Not[LessEqual[N[(y + z), $MachinePrecision], 4e-14]], $MachinePrecision]], N[(x + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(x + N[(z - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y + z \leq -1 \cdot 10^{-12} \lor \neg \left(y + z \leq 4 \cdot 10^{-14}\right):\\
\;\;\;\;x + \tan \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(z - \tan a\right)\\
\end{array}
\end{array}
if (+.f64 y z) < -9.9999999999999998e-13 or 4e-14 < (+.f64 y z) Initial program 70.4%
expm1-log1p-u64.9%
+-commutative64.9%
associate-+l-64.9%
Applied egg-rr64.9%
Taylor expanded in a around 0 44.8%
associate-+r+44.8%
Simplified44.8%
associate-+l+44.8%
log1p-define44.8%
expm1-log1p-u46.2%
quot-tan46.2%
Applied egg-rr46.2%
if -9.9999999999999998e-13 < (+.f64 y z) < 4e-14Initial program 99.9%
Taylor expanded in y around 0 99.9%
Taylor expanded in z around 0 99.9%
Final simplification59.0%
(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 77.4%
expm1-log1p-u73.0%
+-commutative73.0%
associate-+l-73.0%
Applied egg-rr73.0%
Taylor expanded in a around 0 47.1%
associate-+r+47.1%
Simplified47.1%
associate-+l+47.1%
log1p-define47.1%
expm1-log1p-u48.2%
quot-tan48.2%
Applied egg-rr48.2%
Final simplification48.2%
(FPCore (x y z a) :precision binary64 -1.0)
double code(double x, double y, double z, double a) {
return -1.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
code = -1.0d0
end function
public static double code(double x, double y, double z, double a) {
return -1.0;
}
def code(x, y, z, a): return -1.0
function code(x, y, z, a) return -1.0 end
function tmp = code(x, y, z, a) tmp = -1.0; end
code[x_, y_, z_, a_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 77.4%
expm1-log1p-u73.0%
+-commutative73.0%
associate-+l-73.0%
Applied egg-rr73.0%
Taylor expanded in x around inf 21.6%
mul-1-neg21.6%
log-rec21.6%
remove-double-neg21.6%
Simplified21.6%
Taylor expanded in x around 0 2.5%
Final simplification2.5%
(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.4%
Taylor expanded in x around inf 30.5%
Final simplification30.5%
herbie shell --seed 2024048
(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))))