
(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 14 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}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (+ (- (/ (fma (sin z) (/ 1.0 (cos z)) (tan y)) (fma (- (tan z)) (tan y) 1.0)) (tan a)) x))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return ((fma(sin(z), (1.0 / cos(z)), tan(y)) / fma(-tan(z), tan(y), 1.0)) - tan(a)) + x;
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return Float64(Float64(Float64(fma(sin(z), Float64(1.0 / cos(z)), tan(y)) / fma(Float64(-tan(z)), tan(y), 1.0)) - tan(a)) + x) end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. code[x_, y_, z_, a_] := N[(N[(N[(N[(N[Sin[z], $MachinePrecision] * N[(1.0 / N[Cos[z], $MachinePrecision]), $MachinePrecision] + N[Tan[y], $MachinePrecision]), $MachinePrecision] / N[((-N[Tan[z], $MachinePrecision]) * N[Tan[y], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\left(\frac{\mathsf{fma}\left(\sin z, \frac{1}{\cos z}, \tan y\right)}{\mathsf{fma}\left(-\tan z, \tan y, 1\right)} - \tan a\right) + x
\end{array}
Initial program 80.2%
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-tan.f64N/A
lower-tan.f64N/A
sub-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-tan.f64N/A
lower-tan.f6499.7
Applied rewrites99.7%
lift-+.f64N/A
lift-tan.f64N/A
tan-quotN/A
div-invN/A
lower-fma.f64N/A
lower-sin.f64N/A
inv-powN/A
lower-pow.f64N/A
lower-cos.f6499.7
Applied rewrites99.7%
lift-pow.f64N/A
unpow-1N/A
lower-/.f6499.7
Applied rewrites99.7%
Final simplification99.7%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (- (tan z))) (t_1 (- t_0 (tan y))))
(if (<= (tan a) -0.0002)
(+ (- (tan (+ y z)) (/ 1.0 (/ 1.0 (tan a)))) x)
(if (<= (tan a) 5e-43)
(fma t_1 (/ -1.0 (fma t_0 (tan y) 1.0)) (- x a))
(fma t_1 -1.0 (- x (tan a)))))))assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double t_0 = -tan(z);
double t_1 = t_0 - tan(y);
double tmp;
if (tan(a) <= -0.0002) {
tmp = (tan((y + z)) - (1.0 / (1.0 / tan(a)))) + x;
} else if (tan(a) <= 5e-43) {
tmp = fma(t_1, (-1.0 / fma(t_0, tan(y), 1.0)), (x - a));
} else {
tmp = fma(t_1, -1.0, (x - tan(a)));
}
return tmp;
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) t_0 = Float64(-tan(z)) t_1 = Float64(t_0 - tan(y)) tmp = 0.0 if (tan(a) <= -0.0002) tmp = Float64(Float64(tan(Float64(y + z)) - Float64(1.0 / Float64(1.0 / tan(a)))) + x); elseif (tan(a) <= 5e-43) tmp = fma(t_1, Float64(-1.0 / fma(t_0, tan(y), 1.0)), Float64(x - a)); else tmp = fma(t_1, -1.0, Float64(x - tan(a))); end return tmp end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = (-N[Tan[z], $MachinePrecision])}, Block[{t$95$1 = N[(t$95$0 - N[Tan[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -0.0002], N[(N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[(1.0 / N[(1.0 / N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[N[Tan[a], $MachinePrecision], 5e-43], N[(t$95$1 * N[(-1.0 / N[(t$95$0 * N[Tan[y], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + N[(x - a), $MachinePrecision]), $MachinePrecision], N[(t$95$1 * -1.0 + N[(x - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := -\tan z\\
t_1 := t\_0 - \tan y\\
\mathbf{if}\;\tan a \leq -0.0002:\\
\;\;\;\;\left(\tan \left(y + z\right) - \frac{1}{\frac{1}{\tan a}}\right) + x\\
\mathbf{elif}\;\tan a \leq 5 \cdot 10^{-43}:\\
\;\;\;\;\mathsf{fma}\left(t\_1, \frac{-1}{\mathsf{fma}\left(t\_0, \tan y, 1\right)}, x - a\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_1, -1, x - \tan a\right)\\
\end{array}
\end{array}
if (tan.f64 a) < -2.0000000000000001e-4Initial program 81.5%
lift-tan.f64N/A
tan-quotN/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
tan-quotN/A
lift-tan.f64N/A
lower-/.f6481.5
Applied rewrites81.5%
if -2.0000000000000001e-4 < (tan.f64 a) < 5.00000000000000019e-43Initial program 76.4%
lift-+.f64N/A
lift--.f64N/A
associate-+r-N/A
+-commutativeN/A
associate--l+N/A
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
frac-2negN/A
div-invN/A
lower-fma.f64N/A
Applied rewrites99.7%
Taylor expanded in a around 0
mul-1-negN/A
unsub-negN/A
lower--.f6499.7
Applied rewrites99.7%
if 5.00000000000000019e-43 < (tan.f64 a) Initial program 85.6%
lift-+.f64N/A
lift--.f64N/A
associate-+r-N/A
+-commutativeN/A
associate--l+N/A
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
frac-2negN/A
div-invN/A
lower-fma.f64N/A
Applied rewrites99.6%
Taylor expanded in z around 0
Applied rewrites86.1%
Final simplification91.1%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (+ (- (/ (+ (tan z) (tan y)) (fma (- (tan z)) (tan y) 1.0)) (tan a)) x))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return (((tan(z) + tan(y)) / fma(-tan(z), tan(y), 1.0)) - tan(a)) + x;
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return Float64(Float64(Float64(Float64(tan(z) + tan(y)) / fma(Float64(-tan(z)), tan(y), 1.0)) - tan(a)) + x) end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. code[x_, y_, z_, a_] := N[(N[(N[(N[(N[Tan[z], $MachinePrecision] + N[Tan[y], $MachinePrecision]), $MachinePrecision] / N[((-N[Tan[z], $MachinePrecision]) * N[Tan[y], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\left(\frac{\tan z + \tan y}{\mathsf{fma}\left(-\tan z, \tan y, 1\right)} - \tan a\right) + x
\end{array}
Initial program 80.2%
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-tan.f64N/A
lower-tan.f64N/A
sub-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-tan.f64N/A
lower-tan.f6499.7
Applied rewrites99.7%
Final simplification99.7%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (- x (tan a))))
(if (<= (tan a) -0.175)
t_0
(if (<= (tan a) 2e-13) (- (tan (+ y z)) (- x)) t_0))))assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double t_0 = x - tan(a);
double tmp;
if (tan(a) <= -0.175) {
tmp = t_0;
} else if (tan(a) <= 2e-13) {
tmp = tan((y + z)) - -x;
} else {
tmp = t_0;
}
return tmp;
}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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 = x - tan(a)
if (tan(a) <= (-0.175d0)) then
tmp = t_0
else if (tan(a) <= 2d-13) then
tmp = tan((y + z)) - -x
else
tmp = t_0
end if
code = tmp
end function
assert x < y && y < z && z < a;
public static double code(double x, double y, double z, double a) {
double t_0 = x - Math.tan(a);
double tmp;
if (Math.tan(a) <= -0.175) {
tmp = t_0;
} else if (Math.tan(a) <= 2e-13) {
tmp = Math.tan((y + z)) - -x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): t_0 = x - math.tan(a) tmp = 0 if math.tan(a) <= -0.175: tmp = t_0 elif math.tan(a) <= 2e-13: tmp = math.tan((y + z)) - -x else: tmp = t_0 return tmp
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) t_0 = Float64(x - tan(a)) tmp = 0.0 if (tan(a) <= -0.175) tmp = t_0; elseif (tan(a) <= 2e-13) tmp = Float64(tan(Float64(y + z)) - Float64(-x)); else tmp = t_0; end return tmp end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp_2 = code(x, y, z, a)
t_0 = x - tan(a);
tmp = 0.0;
if (tan(a) <= -0.175)
tmp = t_0;
elseif (tan(a) <= 2e-13)
tmp = tan((y + z)) - -x;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(x - N[Tan[a], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -0.175], t$95$0, If[LessEqual[N[Tan[a], $MachinePrecision], 2e-13], N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - (-x)), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := x - \tan a\\
\mathbf{if}\;\tan a \leq -0.175:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\tan a \leq 2 \cdot 10^{-13}:\\
\;\;\;\;\tan \left(y + z\right) - \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (tan.f64 a) < -0.17499999999999999 or 2.0000000000000001e-13 < (tan.f64 a) Initial program 82.0%
Taylor expanded in z around 0
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6460.1
Applied rewrites60.1%
Taylor expanded in y around 0
Applied rewrites41.9%
Applied rewrites41.9%
if -0.17499999999999999 < (tan.f64 a) < 2.0000000000000001e-13Initial program 78.4%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
associate-+l-N/A
lower--.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6478.3
Applied rewrites78.3%
Taylor expanded in a around 0
mul-1-negN/A
lower-neg.f6476.0
Applied rewrites76.0%
Final simplification59.1%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (fma (- (- (tan z)) (tan y)) -1.0 (- x (tan a))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return fma((-tan(z) - tan(y)), -1.0, (x - tan(a)));
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return fma(Float64(Float64(-tan(z)) - tan(y)), -1.0, Float64(x - tan(a))) end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. code[x_, y_, z_, a_] := N[(N[((-N[Tan[z], $MachinePrecision]) - N[Tan[y], $MachinePrecision]), $MachinePrecision] * -1.0 + N[(x - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\mathsf{fma}\left(\left(-\tan z\right) - \tan y, -1, x - \tan a\right)
\end{array}
Initial program 80.2%
lift-+.f64N/A
lift--.f64N/A
associate-+r-N/A
+-commutativeN/A
associate--l+N/A
lift-tan.f64N/A
lift-+.f64N/A
tan-sumN/A
frac-2negN/A
div-invN/A
lower-fma.f64N/A
Applied rewrites99.6%
Taylor expanded in z around 0
Applied rewrites80.7%
Final simplification80.7%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (+ (- (tan (+ y z)) (/ 1.0 (/ 1.0 (tan a)))) x))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return (tan((y + z)) - (1.0 / (1.0 / tan(a)))) + x;
}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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 = (tan((y + z)) - (1.0d0 / (1.0d0 / tan(a)))) + x
end function
assert x < y && y < z && z < a;
public static double code(double x, double y, double z, double a) {
return (Math.tan((y + z)) - (1.0 / (1.0 / Math.tan(a)))) + x;
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): return (math.tan((y + z)) - (1.0 / (1.0 / math.tan(a)))) + x
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return Float64(Float64(tan(Float64(y + z)) - Float64(1.0 / Float64(1.0 / tan(a)))) + x) end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp = code(x, y, z, a)
tmp = (tan((y + z)) - (1.0 / (1.0 / tan(a)))) + x;
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. code[x_, y_, z_, a_] := N[(N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[(1.0 / N[(1.0 / N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\left(\tan \left(y + z\right) - \frac{1}{\frac{1}{\tan a}}\right) + x
\end{array}
Initial program 80.2%
lift-tan.f64N/A
tan-quotN/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
tan-quotN/A
lift-tan.f64N/A
lower-/.f6480.2
Applied rewrites80.2%
Final simplification80.2%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (if (<= (+ y z) 1e-12) (+ (- (tan y) (tan a)) x) (- (tan (+ y z)) (- x))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double tmp;
if ((y + z) <= 1e-12) {
tmp = (tan(y) - tan(a)) + x;
} else {
tmp = tan((y + z)) - -x;
}
return tmp;
}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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 = (tan(y) - tan(a)) + x
else
tmp = tan((y + z)) - -x
end if
code = tmp
end function
assert x < y && y < z && z < a;
public static double code(double x, double y, double z, double a) {
double tmp;
if ((y + z) <= 1e-12) {
tmp = (Math.tan(y) - Math.tan(a)) + x;
} else {
tmp = Math.tan((y + z)) - -x;
}
return tmp;
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): tmp = 0 if (y + z) <= 1e-12: tmp = (math.tan(y) - math.tan(a)) + x else: tmp = math.tan((y + z)) - -x return tmp
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) tmp = 0.0 if (Float64(y + z) <= 1e-12) tmp = Float64(Float64(tan(y) - tan(a)) + x); else tmp = Float64(tan(Float64(y + z)) - Float64(-x)); end return tmp end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp_2 = code(x, y, z, a)
tmp = 0.0;
if ((y + z) <= 1e-12)
tmp = (tan(y) - tan(a)) + x;
else
tmp = tan((y + z)) - -x;
end
tmp_2 = tmp;
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. code[x_, y_, z_, a_] := If[LessEqual[N[(y + z), $MachinePrecision], 1e-12], N[(N[(N[Tan[y], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - (-x)), $MachinePrecision]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
\mathbf{if}\;y + z \leq 10^{-12}:\\
\;\;\;\;\left(\tan y - \tan a\right) + x\\
\mathbf{else}:\\
\;\;\;\;\tan \left(y + z\right) - \left(-x\right)\\
\end{array}
\end{array}
if (+.f64 y z) < 9.9999999999999998e-13Initial program 84.9%
Taylor expanded in z around 0
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6465.7
Applied rewrites65.7%
Applied rewrites65.7%
if 9.9999999999999998e-13 < (+.f64 y z) Initial program 73.0%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
associate-+l-N/A
lower--.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6472.8
Applied rewrites72.8%
Taylor expanded in a around 0
mul-1-negN/A
lower-neg.f6449.4
Applied rewrites49.4%
Final simplification59.2%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (+ (- (tan (+ y z)) (tan a)) x))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return (tan((y + z)) - tan(a)) + x;
}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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 = (tan((y + z)) - tan(a)) + x
end function
assert x < y && y < z && z < a;
public static double code(double x, double y, double z, double a) {
return (Math.tan((y + z)) - Math.tan(a)) + x;
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): return (math.tan((y + z)) - math.tan(a)) + x
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return Float64(Float64(tan(Float64(y + z)) - tan(a)) + x) end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp = code(x, y, z, a)
tmp = (tan((y + z)) - tan(a)) + x;
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. code[x_, y_, z_, a_] := N[(N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\left(\tan \left(y + z\right) - \tan a\right) + x
\end{array}
Initial program 80.2%
Final simplification80.2%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (- x (tan a))))
(if (<= a -0.085)
t_0
(if (<= a 17.0)
(- (tan (+ y z)) (- (* (fma 0.3333333333333333 (* a a) 1.0) a) x))
t_0))))assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double t_0 = x - tan(a);
double tmp;
if (a <= -0.085) {
tmp = t_0;
} else if (a <= 17.0) {
tmp = tan((y + z)) - ((fma(0.3333333333333333, (a * a), 1.0) * a) - x);
} else {
tmp = t_0;
}
return tmp;
}
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) t_0 = Float64(x - tan(a)) tmp = 0.0 if (a <= -0.085) tmp = t_0; elseif (a <= 17.0) tmp = Float64(tan(Float64(y + z)) - Float64(Float64(fma(0.3333333333333333, Float64(a * a), 1.0) * a) - x)); else tmp = t_0; end return tmp end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(x - N[Tan[a], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.085], t$95$0, If[LessEqual[a, 17.0], N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[(N[(N[(0.3333333333333333 * N[(a * a), $MachinePrecision] + 1.0), $MachinePrecision] * a), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := x - \tan a\\
\mathbf{if}\;a \leq -0.085:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;a \leq 17:\\
\;\;\;\;\tan \left(y + z\right) - \left(\mathsf{fma}\left(0.3333333333333333, a \cdot a, 1\right) \cdot a - x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if a < -0.0850000000000000061 or 17 < a Initial program 82.1%
Taylor expanded in z around 0
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6460.4
Applied rewrites60.4%
Taylor expanded in y around 0
Applied rewrites41.4%
Applied rewrites41.4%
if -0.0850000000000000061 < a < 17Initial program 78.2%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
associate-+l-N/A
lower--.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6478.2
Applied rewrites78.2%
Taylor expanded in x around 0
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f648.4
Applied rewrites8.4%
Taylor expanded in a around 0
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6477.5
Applied rewrites77.5%
Final simplification59.5%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (let* ((t_0 (- x (tan a)))) (if (<= a -0.035) t_0 (if (<= a 17.0) (- (tan (+ y z)) (- a x)) t_0))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
double t_0 = x - tan(a);
double tmp;
if (a <= -0.035) {
tmp = t_0;
} else if (a <= 17.0) {
tmp = tan((y + z)) - (a - x);
} else {
tmp = t_0;
}
return tmp;
}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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 = x - tan(a)
if (a <= (-0.035d0)) then
tmp = t_0
else if (a <= 17.0d0) then
tmp = tan((y + z)) - (a - x)
else
tmp = t_0
end if
code = tmp
end function
assert x < y && y < z && z < a;
public static double code(double x, double y, double z, double a) {
double t_0 = x - Math.tan(a);
double tmp;
if (a <= -0.035) {
tmp = t_0;
} else if (a <= 17.0) {
tmp = Math.tan((y + z)) - (a - x);
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): t_0 = x - math.tan(a) tmp = 0 if a <= -0.035: tmp = t_0 elif a <= 17.0: tmp = math.tan((y + z)) - (a - x) else: tmp = t_0 return tmp
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) t_0 = Float64(x - tan(a)) tmp = 0.0 if (a <= -0.035) tmp = t_0; elseif (a <= 17.0) tmp = Float64(tan(Float64(y + z)) - Float64(a - x)); else tmp = t_0; end return tmp end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp_2 = code(x, y, z, a)
t_0 = x - tan(a);
tmp = 0.0;
if (a <= -0.035)
tmp = t_0;
elseif (a <= 17.0)
tmp = tan((y + z)) - (a - x);
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(x - N[Tan[a], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.035], t$95$0, If[LessEqual[a, 17.0], N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[(a - x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := x - \tan a\\
\mathbf{if}\;a \leq -0.035:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;a \leq 17:\\
\;\;\;\;\tan \left(y + z\right) - \left(a - x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if a < -0.035000000000000003 or 17 < a Initial program 82.1%
Taylor expanded in z around 0
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6460.4
Applied rewrites60.4%
Taylor expanded in y around 0
Applied rewrites41.4%
Applied rewrites41.4%
if -0.035000000000000003 < a < 17Initial program 78.2%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
associate-+l-N/A
lower--.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f6478.2
Applied rewrites78.2%
Taylor expanded in a around 0
lower--.f6477.4
Applied rewrites77.4%
Final simplification59.4%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (- x (tan a)))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return x - tan(a);
}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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)
end function
assert x < y && y < z && z < a;
public static double code(double x, double y, double z, double a) {
return x - Math.tan(a);
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): return x - math.tan(a)
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return Float64(x - tan(a)) end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp = code(x, y, z, a)
tmp = x - tan(a);
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. code[x_, y_, z_, a_] := N[(x - N[Tan[a], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
x - \tan a
\end{array}
Initial program 80.2%
Taylor expanded in z around 0
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6460.4
Applied rewrites60.4%
Taylor expanded in y around 0
Applied rewrites39.4%
Applied rewrites39.4%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (/ 1.0 (/ 1.0 x)))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return 1.0 / (1.0 / x);
}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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 / (1.0d0 / x)
end function
assert x < y && y < z && z < a;
public static double code(double x, double y, double z, double a) {
return 1.0 / (1.0 / x);
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): return 1.0 / (1.0 / x)
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return Float64(1.0 / Float64(1.0 / x)) end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp = code(x, y, z, a)
tmp = 1.0 / (1.0 / x);
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. code[x_, y_, z_, a_] := N[(1.0 / N[(1.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\frac{1}{\frac{1}{x}}
\end{array}
Initial program 80.2%
lift-+.f64N/A
flip3-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip3-+N/A
lift-+.f64N/A
lower-/.f6480.0
Applied rewrites79.9%
Taylor expanded in x around inf
lower-/.f6429.6
Applied rewrites29.6%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (- x a))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return x - a;
}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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 - a
end function
assert x < y && y < z && z < a;
public static double code(double x, double y, double z, double a) {
return x - a;
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): return x - a
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return Float64(x - a) end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp = code(x, y, z, a)
tmp = x - a;
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. code[x_, y_, z_, a_] := N[(x - a), $MachinePrecision]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
x - a
\end{array}
Initial program 80.2%
Taylor expanded in z around 0
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6460.4
Applied rewrites60.4%
Taylor expanded in y around 0
Applied rewrites39.4%
Taylor expanded in a around 0
Applied rewrites20.5%
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. (FPCore (x y z a) :precision binary64 (- a))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
return -a;
}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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 = -a
end function
assert x < y && y < z && z < a;
public static double code(double x, double y, double z, double a) {
return -a;
}
[x, y, z, a] = sort([x, y, z, a]) def code(x, y, z, a): return -a
x, y, z, a = sort([x, y, z, a]) function code(x, y, z, a) return Float64(-a) end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp = code(x, y, z, a)
tmp = -a;
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function. code[x_, y_, z_, a_] := (-a)
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
-a
\end{array}
Initial program 80.2%
Taylor expanded in z around 0
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6460.4
Applied rewrites60.4%
Taylor expanded in y around 0
Applied rewrites39.4%
Taylor expanded in a around 0
Applied rewrites20.5%
Taylor expanded in a around inf
Applied rewrites3.6%
herbie shell --seed 2024276
(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))))