
(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)
use fmin_fmax_functions
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]
x + \left(\tan \left(y + z\right) - \tan a\right)
Herbie found 5 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)
use fmin_fmax_functions
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]
x + \left(\tan \left(y + z\right) - \tan a\right)
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (- (* (cos y) (cos z)) (* (sin z) (sin y)))))
(+
x
(-
(+ (/ (* (sin z) (cos y)) t_0) (/ (* (cos z) (sin y)) t_0))
(tan a)))))double code(double x, double y, double z, double a) {
double t_0 = (cos(y) * cos(z)) - (sin(z) * sin(y));
return x + ((((sin(z) * cos(y)) / t_0) + ((cos(z) * sin(y)) / t_0)) - tan(a));
}
real(8) function code(x, y, z, a)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: a
real(8) :: t_0
t_0 = (cos(y) * cos(z)) - (sin(z) * sin(y))
code = x + ((((sin(z) * cos(y)) / t_0) + ((cos(z) * sin(y)) / t_0)) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
double t_0 = (Math.cos(y) * Math.cos(z)) - (Math.sin(z) * Math.sin(y));
return x + ((((Math.sin(z) * Math.cos(y)) / t_0) + ((Math.cos(z) * Math.sin(y)) / t_0)) - Math.tan(a));
}
def code(x, y, z, a): t_0 = (math.cos(y) * math.cos(z)) - (math.sin(z) * math.sin(y)) return x + ((((math.sin(z) * math.cos(y)) / t_0) + ((math.cos(z) * math.sin(y)) / t_0)) - math.tan(a))
function code(x, y, z, a) t_0 = Float64(Float64(cos(y) * cos(z)) - Float64(sin(z) * sin(y))) return Float64(x + Float64(Float64(Float64(Float64(sin(z) * cos(y)) / t_0) + Float64(Float64(cos(z) * sin(y)) / t_0)) - tan(a))) end
function tmp = code(x, y, z, a) t_0 = (cos(y) * cos(z)) - (sin(z) * sin(y)); tmp = x + ((((sin(z) * cos(y)) / t_0) + ((cos(z) * sin(y)) / t_0)) - tan(a)); end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[(N[Cos[y], $MachinePrecision] * N[Cos[z], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[z], $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(x + N[(N[(N[(N[(N[Sin[z], $MachinePrecision] * N[Cos[y], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] + N[(N[(N[Cos[z], $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \cos y \cdot \cos z - \sin z \cdot \sin y\\
x + \left(\left(\frac{\sin z \cdot \cos y}{t\_0} + \frac{\cos z \cdot \sin y}{t\_0}\right) - \tan a\right)
\end{array}
Initial program 79.2%
lift-tan.f64N/A
tan-quotN/A
lift-+.f64N/A
+-commutativeN/A
sin-sumN/A
div-addN/A
*-commutativeN/A
lower-+.f64N/A
add-sound-/N/A
lower-/.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
add-sound-/N/A
lower-/.f64N/A
Applied rewrites79.7%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
lower--.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lower-*.f6480.5%
Applied rewrites80.5%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
lower--.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lower-*.f6499.7%
Applied rewrites99.7%
(FPCore (x y z a) :precision binary64 (- (+ (/ (+ (* (- (cos z)) (sin y)) (* (- (cos y)) (sin z))) (- (* (sin z) (sin y)) (* (cos y) (cos z)))) x) (tan a)))
double code(double x, double y, double z, double a) {
return ((((-cos(z) * sin(y)) + (-cos(y) * sin(z))) / ((sin(z) * sin(y)) - (cos(y) * cos(z)))) + x) - tan(a);
}
real(8) function code(x, y, z, a)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: a
code = ((((-cos(z) * sin(y)) + (-cos(y) * sin(z))) / ((sin(z) * sin(y)) - (cos(y) * cos(z)))) + x) - tan(a)
end function
public static double code(double x, double y, double z, double a) {
return ((((-Math.cos(z) * Math.sin(y)) + (-Math.cos(y) * Math.sin(z))) / ((Math.sin(z) * Math.sin(y)) - (Math.cos(y) * Math.cos(z)))) + x) - Math.tan(a);
}
def code(x, y, z, a): return ((((-math.cos(z) * math.sin(y)) + (-math.cos(y) * math.sin(z))) / ((math.sin(z) * math.sin(y)) - (math.cos(y) * math.cos(z)))) + x) - math.tan(a)
function code(x, y, z, a) return Float64(Float64(Float64(Float64(Float64(Float64(-cos(z)) * sin(y)) + Float64(Float64(-cos(y)) * sin(z))) / Float64(Float64(sin(z) * sin(y)) - Float64(cos(y) * cos(z)))) + x) - tan(a)) end
function tmp = code(x, y, z, a) tmp = ((((-cos(z) * sin(y)) + (-cos(y) * sin(z))) / ((sin(z) * sin(y)) - (cos(y) * cos(z)))) + x) - tan(a); end
code[x_, y_, z_, a_] := N[(N[(N[(N[(N[((-N[Cos[z], $MachinePrecision]) * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[((-N[Cos[y], $MachinePrecision]) * N[Sin[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Sin[z], $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision] - N[(N[Cos[y], $MachinePrecision] * N[Cos[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]
\left(\frac{\left(-\cos z\right) \cdot \sin y + \left(-\cos y\right) \cdot \sin z}{\sin z \cdot \sin y - \cos y \cdot \cos z} + x\right) - \tan a
Initial program 79.2%
lift-+.f64N/A
add-flipN/A
lift--.f64N/A
sub-negate-revN/A
lift-tan.f64N/A
tan-quotN/A
sub-to-fractionN/A
sub-to-fractionN/A
add-sound-/N/A
lower-/.f64N/A
Applied rewrites78.9%
Applied rewrites79.1%
lift-tan.f64N/A
quot-tanN/A
lift-sin.f64N/A
lift-cos.f64N/A
mult-flipN/A
*-commutativeN/A
lift-sin.f64N/A
lift-+.f64N/A
sin-sumN/A
lift-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
+-commutativeN/A
distribute-rgt-outN/A
mult-flipN/A
mult-flip-revN/A
frac-2neg-revN/A
Applied rewrites79.6%
lift-neg.f64N/A
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
sub-negate-revN/A
lower--.f6499.6%
Applied rewrites99.6%
(FPCore (x y z a) :precision binary64 (+ x (- (/ (sin (+ z y)) (- (* (cos y) (cos z)) (* (sin z) (sin y)))) (tan a))))
double code(double x, double y, double z, double a) {
return x + ((sin((z + y)) / ((cos(y) * cos(z)) - (sin(z) * sin(y)))) - tan(a));
}
real(8) function code(x, y, z, a)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: a
code = x + ((sin((z + y)) / ((cos(y) * cos(z)) - (sin(z) * sin(y)))) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
return x + ((Math.sin((z + y)) / ((Math.cos(y) * Math.cos(z)) - (Math.sin(z) * Math.sin(y)))) - Math.tan(a));
}
def code(x, y, z, a): return x + ((math.sin((z + y)) / ((math.cos(y) * math.cos(z)) - (math.sin(z) * math.sin(y)))) - math.tan(a))
function code(x, y, z, a) return Float64(x + Float64(Float64(sin(Float64(z + y)) / Float64(Float64(cos(y) * cos(z)) - Float64(sin(z) * sin(y)))) - tan(a))) end
function tmp = code(x, y, z, a) tmp = x + ((sin((z + y)) / ((cos(y) * cos(z)) - (sin(z) * sin(y)))) - tan(a)); end
code[x_, y_, z_, a_] := N[(x + N[(N[(N[Sin[N[(z + y), $MachinePrecision]], $MachinePrecision] / N[(N[(N[Cos[y], $MachinePrecision] * N[Cos[z], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[z], $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x + \left(\frac{\sin \left(z + y\right)}{\cos y \cdot \cos z - \sin z \cdot \sin y} - \tan a\right)
Initial program 79.2%
lift-tan.f64N/A
tan-quotN/A
div-flipN/A
lower-/.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-sin.f6479.1%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6479.1%
Applied rewrites79.1%
lift-/.f64N/A
lift-/.f64N/A
div-flip-revN/A
add-sound-/N/A
lower-/.f6479.1%
Applied rewrites79.1%
lift-cos.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-+.f64N/A
associate-+l+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lift-PI.f64N/A
mult-flipN/A
metadata-evalN/A
lower-*.f6443.2%
Applied rewrites43.2%
lift-sin.f64N/A
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
metadata-evalN/A
mult-flipN/A
lift-PI.f64N/A
associate-+l+N/A
lift-+.f64N/A
sin-+PI/2-revN/A
lift-+.f64N/A
cos-sumN/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
lift--.f6479.8%
Applied rewrites79.8%
(FPCore (x y z a) :precision binary64 (+ x (- (/ 1 (/ 1 (tan (+ z y)))) (tan a))))
double code(double x, double y, double z, double a) {
return x + ((1.0 / (1.0 / tan((z + y)))) - tan(a));
}
real(8) function code(x, y, z, a)
use fmin_fmax_functions
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 / tan((z + y)))) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
return x + ((1.0 / (1.0 / Math.tan((z + y)))) - Math.tan(a));
}
def code(x, y, z, a): return x + ((1.0 / (1.0 / math.tan((z + y)))) - math.tan(a))
function code(x, y, z, a) return Float64(x + Float64(Float64(1.0 / Float64(1.0 / tan(Float64(z + y)))) - tan(a))) end
function tmp = code(x, y, z, a) tmp = x + ((1.0 / (1.0 / tan((z + y)))) - tan(a)); end
code[x_, y_, z_, a_] := N[(x + N[(N[(1 / N[(1 / N[Tan[N[(z + y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x + \left(\frac{1}{\frac{1}{\tan \left(z + y\right)}} - \tan a\right)
Initial program 79.2%
lift-tan.f64N/A
tan-quotN/A
div-flipN/A
lower-/.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-sin.f6479.1%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6479.1%
Applied rewrites79.1%
lift-/.f64N/A
frac-2negN/A
div-flipN/A
add-sound-/N/A
frac-2negN/A
lift-sin.f64N/A
lift-+.f64N/A
sin-sumN/A
lift-sin.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
div-add-revN/A
lift-/.f64N/A
lift-/.f64N/A
lift-+.f64N/A
Applied rewrites79.2%
herbie shell --seed 2025326 -o generate:taylor -o generate:evaluate
(FPCore (x y z a)
:name "tan-example (used to crash)"
:precision binary64
:pre (and (and (and (or (== x 0) (and (<= 2942071/5000000 x) (<= x 5055909/10000))) (or (and (<= -179665800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 y) (<= y -1885117/2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)) (and (<= 642469/500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 y) (<= y 175122400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)))) (or (and (<= -177670700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 z) (<= z -2149949/2500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)) (and (<= 658629/20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 z) (<= z 172515400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)))) (or (and (<= -179665800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 a) (<= a -1885117/2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)) (and (<= 642469/500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 a) (<= a 175122400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000))))
(+ x (- (tan (+ y z)) (tan a))))