
(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 (- (* (/ 1.0 (- 1.0 (/ (sin z) (/ (cos z) (tan y))))) (+ (tan y) (tan z))) (tan a))))
double code(double x, double y, double z, double a) {
return x + (((1.0 / (1.0 - (sin(z) / (cos(z) / tan(y))))) * (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 + (((1.0d0 / (1.0d0 - (sin(z) / (cos(z) / tan(y))))) * (tan(y) + tan(z))) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
return x + (((1.0 / (1.0 - (Math.sin(z) / (Math.cos(z) / Math.tan(y))))) * (Math.tan(y) + Math.tan(z))) - Math.tan(a));
}
def code(x, y, z, a): return x + (((1.0 / (1.0 - (math.sin(z) / (math.cos(z) / math.tan(y))))) * (math.tan(y) + math.tan(z))) - math.tan(a))
function code(x, y, z, a) return Float64(x + Float64(Float64(Float64(1.0 / Float64(1.0 - Float64(sin(z) / Float64(cos(z) / tan(y))))) * Float64(tan(y) + tan(z))) - tan(a))) end
function tmp = code(x, y, z, a) tmp = x + (((1.0 / (1.0 - (sin(z) / (cos(z) / tan(y))))) * (tan(y) + tan(z))) - tan(a)); end
code[x_, y_, z_, a_] := N[(x + N[(N[(N[(1.0 / N[(1.0 - N[(N[Sin[z], $MachinePrecision] / N[(N[Cos[z], $MachinePrecision] / N[Tan[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\frac{1}{1 - \frac{\sin z}{\frac{\cos z}{\tan y}}} \cdot \left(\tan y + \tan z\right) - \tan a\right)
\end{array}
Initial program 80.0%
tan-sum99.7%
div-inv99.7%
Applied egg-rr99.7%
tan-quot99.7%
associate-*r/99.7%
Applied egg-rr99.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y z a) :precision binary64 (- x (+ (tan a) (* (+ (tan y) (tan z)) (/ -1.0 (- 1.0 (* (tan y) (tan z))))))))
double code(double x, double y, double z, double a) {
return x - (tan(a) + ((tan(y) + tan(z)) * (-1.0 / (1.0 - (tan(y) * tan(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(a) + ((tan(y) + tan(z)) * ((-1.0d0) / (1.0d0 - (tan(y) * tan(z))))))
end function
public static double code(double x, double y, double z, double a) {
return x - (Math.tan(a) + ((Math.tan(y) + Math.tan(z)) * (-1.0 / (1.0 - (Math.tan(y) * Math.tan(z))))));
}
def code(x, y, z, a): return x - (math.tan(a) + ((math.tan(y) + math.tan(z)) * (-1.0 / (1.0 - (math.tan(y) * math.tan(z))))))
function code(x, y, z, a) return Float64(x - Float64(tan(a) + Float64(Float64(tan(y) + tan(z)) * Float64(-1.0 / Float64(1.0 - Float64(tan(y) * tan(z))))))) end
function tmp = code(x, y, z, a) tmp = x - (tan(a) + ((tan(y) + tan(z)) * (-1.0 / (1.0 - (tan(y) * tan(z)))))); end
code[x_, y_, z_, a_] := N[(x - N[(N[Tan[a], $MachinePrecision] + 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]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(\tan a + \left(\tan y + \tan z\right) \cdot \frac{-1}{1 - \tan y \cdot \tan z}\right)
\end{array}
Initial program 80.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 80.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 (+ x (- (+ (tan y) (tan z)) (tan a))))
double code(double x, double y, double z, double a) {
return x + ((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)) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
return x + ((Math.tan(y) + Math.tan(z)) - Math.tan(a));
}
def code(x, y, z, a): return x + ((math.tan(y) + math.tan(z)) - math.tan(a))
function code(x, y, z, a) return Float64(x + Float64(Float64(tan(y) + tan(z)) - tan(a))) end
function tmp = code(x, y, z, a) tmp = x + ((tan(y) + tan(z)) - tan(a)); end
code[x_, y_, z_, a_] := N[(x + N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(\tan y + \tan z\right) - \tan a\right)
\end{array}
Initial program 80.0%
tan-sum99.7%
div-inv99.7%
Applied egg-rr99.7%
tan-quot99.7%
associate-*r/99.7%
Applied egg-rr99.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.7%
fma-neg99.7%
associate-/r/99.7%
tan-quot99.6%
Applied egg-rr99.6%
fma-undefine99.7%
*-commutative99.7%
unsub-neg99.7%
associate-*l/99.7%
*-lft-identity99.7%
+-commutative99.7%
Simplified99.7%
Taylor expanded in z around 0 80.1%
Final simplification80.1%
(FPCore (x y z a) :precision binary64 (if (<= z 8e-8) (+ (tan y) (- x (tan a))) (+ x (- (tan z) (tan a)))))
double code(double x, double y, double z, double a) {
double tmp;
if (z <= 8e-8) {
tmp = tan(y) + (x - 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 <= 8d-8) then
tmp = tan(y) + (x - 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 <= 8e-8) {
tmp = Math.tan(y) + (x - Math.tan(a));
} else {
tmp = x + (Math.tan(z) - Math.tan(a));
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if z <= 8e-8: tmp = math.tan(y) + (x - 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 <= 8e-8) tmp = Float64(tan(y) + Float64(x - 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 <= 8e-8) tmp = tan(y) + (x - tan(a)); else tmp = x + (tan(z) - tan(a)); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[z, 8e-8], N[(N[Tan[y], $MachinePrecision] + N[(x - 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 8 \cdot 10^{-8}:\\
\;\;\;\;\tan y + \left(x - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(\tan z - \tan a\right)\\
\end{array}
\end{array}
if z < 8.0000000000000002e-8Initial program 87.9%
add-sqr-sqrt81.1%
sqrt-unprod81.9%
pow281.9%
+-commutative81.9%
associate-+l-81.8%
Applied egg-rr81.8%
Taylor expanded in z around 0 70.8%
sqrt-pow176.1%
tan-quot76.1%
metadata-eval76.1%
pow176.1%
Applied egg-rr76.1%
if 8.0000000000000002e-8 < z Initial program 58.0%
Taylor expanded in y around 0 57.7%
tan-quot57.7%
add057.7%
Applied egg-rr57.7%
add057.7%
Simplified57.7%
Final simplification71.2%
(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.0%
Final simplification80.0%
(FPCore (x y z a) :precision binary64 (if (<= z 1.35) (+ x (- z (tan a))) (expm1 (log1p x))))
double code(double x, double y, double z, double a) {
double tmp;
if (z <= 1.35) {
tmp = x + (z - tan(a));
} else {
tmp = expm1(log1p(x));
}
return tmp;
}
public static double code(double x, double y, double z, double a) {
double tmp;
if (z <= 1.35) {
tmp = x + (z - Math.tan(a));
} else {
tmp = Math.expm1(Math.log1p(x));
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if z <= 1.35: tmp = x + (z - math.tan(a)) else: tmp = math.expm1(math.log1p(x)) return tmp
function code(x, y, z, a) tmp = 0.0 if (z <= 1.35) tmp = Float64(x + Float64(z - tan(a))); else tmp = expm1(log1p(x)); end return tmp end
code[x_, y_, z_, a_] := If[LessEqual[z, 1.35], N[(x + N[(z - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(Exp[N[Log[1 + x], $MachinePrecision]] - 1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.35:\\
\;\;\;\;x + \left(z - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(x\right)\right)\\
\end{array}
\end{array}
if z < 1.3500000000000001Initial program 87.9%
Taylor expanded in y around 0 63.1%
Taylor expanded in z around 0 44.9%
if 1.3500000000000001 < z Initial program 58.0%
add-exp-log54.6%
+-commutative54.6%
associate-+l-54.6%
Applied egg-rr54.6%
Taylor expanded in x around inf 23.0%
mul-1-neg23.0%
log-rec23.0%
remove-double-neg23.0%
Simplified23.0%
rem-exp-log23.0%
expm1-log1p-u23.0%
expm1-undefine23.0%
Applied egg-rr23.0%
expm1-define23.0%
Simplified23.0%
Final simplification39.1%
(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 80.0%
Taylor expanded in y around 0 61.6%
tan-quot61.6%
add061.6%
Applied egg-rr61.6%
add061.6%
Simplified61.6%
Final simplification61.6%
(FPCore (x y z a) :precision binary64 (if (<= z 1.75) (+ x (- z (tan a))) x))
double code(double x, double y, double z, double a) {
double tmp;
if (z <= 1.75) {
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.75d0) 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.75) {
tmp = x + (z - Math.tan(a));
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if z <= 1.75: tmp = x + (z - math.tan(a)) else: tmp = x return tmp
function code(x, y, z, a) tmp = 0.0 if (z <= 1.75) 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.75) tmp = x + (z - tan(a)); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[z, 1.75], N[(x + N[(z - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.75:\\
\;\;\;\;x + \left(z - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < 1.75Initial program 87.9%
Taylor expanded in y around 0 63.1%
Taylor expanded in z around 0 44.9%
if 1.75 < z Initial program 58.0%
Taylor expanded in x around inf 23.0%
Final simplification39.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.0%
Taylor expanded in x around inf 32.6%
Final simplification32.6%
herbie shell --seed 2024034
(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))))