
(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 7 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 (* (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 78.1%
tan-sum99.8%
div-inv99.8%
Applied egg-rr99.8%
associate-*r/99.8%
*-rgt-identity99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z a) :precision binary64 (if (<= z 2.6) (+ x (- z (tan a))) (exp (- (log (/ 1.0 x))))))
double code(double x, double y, double z, double a) {
double tmp;
if (z <= 2.6) {
tmp = x + (z - tan(a));
} else {
tmp = exp(-log((1.0 / 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 <= 2.6d0) then
tmp = x + (z - tan(a))
else
tmp = exp(-log((1.0d0 / x)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double a) {
double tmp;
if (z <= 2.6) {
tmp = x + (z - Math.tan(a));
} else {
tmp = Math.exp(-Math.log((1.0 / x)));
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if z <= 2.6: tmp = x + (z - math.tan(a)) else: tmp = math.exp(-math.log((1.0 / x))) return tmp
function code(x, y, z, a) tmp = 0.0 if (z <= 2.6) tmp = Float64(x + Float64(z - tan(a))); else tmp = exp(Float64(-log(Float64(1.0 / x)))); end return tmp end
function tmp_2 = code(x, y, z, a) tmp = 0.0; if (z <= 2.6) tmp = x + (z - tan(a)); else tmp = exp(-log((1.0 / x))); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[z, 2.6], N[(x + N[(z - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Exp[(-N[Log[N[(1.0 / x), $MachinePrecision]], $MachinePrecision])], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.6:\\
\;\;\;\;x + \left(z - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;e^{-\log \left(\frac{1}{x}\right)}\\
\end{array}
\end{array}
if z < 2.60000000000000009Initial program 86.8%
add-sqr-sqrt42.1%
sqrt-unprod68.2%
pow268.2%
Applied egg-rr68.2%
Taylor expanded in y around 0 59.4%
Taylor expanded in z around 0 45.1%
if 2.60000000000000009 < z Initial program 51.3%
add-exp-log47.3%
+-commutative47.3%
associate-+l-47.3%
Applied egg-rr47.3%
Taylor expanded in x around inf 22.3%
Final simplification39.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 78.1%
Final simplification78.1%
(FPCore (x y z a) :precision binary64 (if (<= z 2.6) (+ x (- z (tan a))) (exp (log x))))
double code(double x, double y, double z, double a) {
double tmp;
if (z <= 2.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 <= 2.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 <= 2.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 <= 2.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 <= 2.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 <= 2.6) tmp = x + (z - tan(a)); else tmp = exp(log(x)); end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[z, 2.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 2.6:\\
\;\;\;\;x + \left(z - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;e^{\log x}\\
\end{array}
\end{array}
if z < 2.60000000000000009Initial program 86.8%
add-sqr-sqrt42.1%
sqrt-unprod68.2%
pow268.2%
Applied egg-rr68.2%
Taylor expanded in y around 0 59.4%
Taylor expanded in z around 0 45.1%
if 2.60000000000000009 < z Initial program 51.3%
add-exp-log47.3%
+-commutative47.3%
associate-+l-47.3%
Applied egg-rr47.3%
Taylor expanded in x around inf 22.3%
mul-1-neg22.3%
log-rec22.3%
remove-double-neg22.3%
Simplified22.3%
Final simplification39.5%
(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 78.1%
add-sqr-sqrt37.2%
sqrt-unprod59.8%
pow259.8%
Applied egg-rr59.8%
Taylor expanded in y around 0 53.3%
tan-quot53.3%
sqrt-pow161.4%
metadata-eval61.4%
pow161.4%
expm1-log1p-u54.1%
expm1-udef54.1%
Applied egg-rr54.1%
expm1-def54.1%
expm1-log1p61.4%
Simplified61.4%
Final simplification61.4%
(FPCore (x y z a) :precision binary64 (if (<= z 2.7) (+ x (- z (tan a))) x))
double code(double x, double y, double z, double a) {
double tmp;
if (z <= 2.7) {
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 <= 2.7d0) 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 <= 2.7) {
tmp = x + (z - Math.tan(a));
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, a): tmp = 0 if z <= 2.7: tmp = x + (z - math.tan(a)) else: tmp = x return tmp
function code(x, y, z, a) tmp = 0.0 if (z <= 2.7) 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 <= 2.7) tmp = x + (z - tan(a)); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, a_] := If[LessEqual[z, 2.7], N[(x + N[(z - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.7:\\
\;\;\;\;x + \left(z - \tan a\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < 2.7000000000000002Initial program 86.8%
add-sqr-sqrt42.1%
sqrt-unprod68.2%
pow268.2%
Applied egg-rr68.2%
Taylor expanded in y around 0 59.4%
Taylor expanded in z around 0 45.1%
if 2.7000000000000002 < z Initial program 51.3%
Taylor expanded in x around inf 22.3%
Final simplification39.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 78.1%
Taylor expanded in x around inf 33.9%
Final simplification33.9%
herbie shell --seed 2024026
(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))))