
(FPCore (z1 z0 z2 z3) :precision binary64 (sqrt (- (* 1/2 (+ 1 (cos (- z1 z0)))) (* (* -1/2 (+ -1 (cos (* (- z2 z3) 1)))) (* (cos z1) (cos z0))))))
double code(double z1, double z0, double z2, double z3) {
return sqrt(((0.5 * (1.0 + cos((z1 - z0)))) - ((-0.5 * (-1.0 + cos(((z2 - z3) * 1.0)))) * (cos(z1) * cos(z0)))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(z1, z0, z2, z3)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
real(8), intent (in) :: z3
code = sqrt(((0.5d0 * (1.0d0 + cos((z1 - z0)))) - (((-0.5d0) * ((-1.0d0) + cos(((z2 - z3) * 1.0d0)))) * (cos(z1) * cos(z0)))))
end function
public static double code(double z1, double z0, double z2, double z3) {
return Math.sqrt(((0.5 * (1.0 + Math.cos((z1 - z0)))) - ((-0.5 * (-1.0 + Math.cos(((z2 - z3) * 1.0)))) * (Math.cos(z1) * Math.cos(z0)))));
}
def code(z1, z0, z2, z3): return math.sqrt(((0.5 * (1.0 + math.cos((z1 - z0)))) - ((-0.5 * (-1.0 + math.cos(((z2 - z3) * 1.0)))) * (math.cos(z1) * math.cos(z0)))))
function code(z1, z0, z2, z3) return sqrt(Float64(Float64(0.5 * Float64(1.0 + cos(Float64(z1 - z0)))) - Float64(Float64(-0.5 * Float64(-1.0 + cos(Float64(Float64(z2 - z3) * 1.0)))) * Float64(cos(z1) * cos(z0))))) end
function tmp = code(z1, z0, z2, z3) tmp = sqrt(((0.5 * (1.0 + cos((z1 - z0)))) - ((-0.5 * (-1.0 + cos(((z2 - z3) * 1.0)))) * (cos(z1) * cos(z0))))); end
code[z1_, z0_, z2_, z3_] := N[Sqrt[N[(N[(1/2 * N[(1 + N[Cos[N[(z1 - z0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(-1/2 * N[(-1 + N[Cos[N[(N[(z2 - z3), $MachinePrecision] * 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[z1], $MachinePrecision] * N[Cos[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{\frac{1}{2} \cdot \left(1 + \cos \left(z1 - z0\right)\right) - \left(\frac{-1}{2} \cdot \left(-1 + \cos \left(\left(z2 - z3\right) \cdot 1\right)\right)\right) \cdot \left(\cos z1 \cdot \cos z0\right)}
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (z1 z0 z2 z3) :precision binary64 (sqrt (- (* 1/2 (+ 1 (cos (- z1 z0)))) (* (* -1/2 (+ -1 (cos (* (- z2 z3) 1)))) (* (cos z1) (cos z0))))))
double code(double z1, double z0, double z2, double z3) {
return sqrt(((0.5 * (1.0 + cos((z1 - z0)))) - ((-0.5 * (-1.0 + cos(((z2 - z3) * 1.0)))) * (cos(z1) * cos(z0)))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(z1, z0, z2, z3)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
real(8), intent (in) :: z3
code = sqrt(((0.5d0 * (1.0d0 + cos((z1 - z0)))) - (((-0.5d0) * ((-1.0d0) + cos(((z2 - z3) * 1.0d0)))) * (cos(z1) * cos(z0)))))
end function
public static double code(double z1, double z0, double z2, double z3) {
return Math.sqrt(((0.5 * (1.0 + Math.cos((z1 - z0)))) - ((-0.5 * (-1.0 + Math.cos(((z2 - z3) * 1.0)))) * (Math.cos(z1) * Math.cos(z0)))));
}
def code(z1, z0, z2, z3): return math.sqrt(((0.5 * (1.0 + math.cos((z1 - z0)))) - ((-0.5 * (-1.0 + math.cos(((z2 - z3) * 1.0)))) * (math.cos(z1) * math.cos(z0)))))
function code(z1, z0, z2, z3) return sqrt(Float64(Float64(0.5 * Float64(1.0 + cos(Float64(z1 - z0)))) - Float64(Float64(-0.5 * Float64(-1.0 + cos(Float64(Float64(z2 - z3) * 1.0)))) * Float64(cos(z1) * cos(z0))))) end
function tmp = code(z1, z0, z2, z3) tmp = sqrt(((0.5 * (1.0 + cos((z1 - z0)))) - ((-0.5 * (-1.0 + cos(((z2 - z3) * 1.0)))) * (cos(z1) * cos(z0))))); end
code[z1_, z0_, z2_, z3_] := N[Sqrt[N[(N[(1/2 * N[(1 + N[Cos[N[(z1 - z0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(-1/2 * N[(-1 + N[Cos[N[(N[(z2 - z3), $MachinePrecision] * 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[z1], $MachinePrecision] * N[Cos[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{\frac{1}{2} \cdot \left(1 + \cos \left(z1 - z0\right)\right) - \left(\frac{-1}{2} \cdot \left(-1 + \cos \left(\left(z2 - z3\right) \cdot 1\right)\right)\right) \cdot \left(\cos z1 \cdot \cos z0\right)}
(FPCore (z1 z0 z2 z3)
:precision binary64
(sqrt
(-
(* 1/2 (+ (* (cos z0) (cos z1)) (+ (* (sin z0) (sin z1)) 1)))
(*
(*
-1/2
(+ -1 (* (- (* (tan z3) (tan z2)) -1) (* (cos z2) (cos z3)))))
(304-z0z1z2z3z4
(cos z1)
(sin (- z0))
(cos (* PI 1/2))
(cos z0)
(sin (* PI -1/2)))))))\sqrt{\frac{1}{2} \cdot \left(\cos z0 \cdot \cos z1 + \left(\sin z0 \cdot \sin z1 + 1\right)\right) - \left(\frac{-1}{2} \cdot \left(-1 + \left(\tan z3 \cdot \tan z2 - -1\right) \cdot \left(\cos z2 \cdot \cos z3\right)\right)\right) \cdot \mathsf{304\_z0z1z2z3z4}\left(\cos z1, \sin \left(-z0\right), \cos \left(\pi \cdot \frac{1}{2}\right), \cos z0, \sin \left(\pi \cdot \frac{-1}{2}\right)\right)}
Initial program 63.7%
lift-+.f64N/A
+-commutativeN/A
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6479.0%
Applied rewrites79.0%
lift-cos.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lift--.f64N/A
cos-diffN/A
*-commutativeN/A
*-commutativeN/A
sum-to-multN/A
lower-unsound-*.f64N/A
lower-unsound-+.f64N/A
lower-unsound-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
*-commutativeN/A
Applied rewrites99.1%
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
metadata-evalN/A
lower--.f6499.1%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lift-sin.f64N/A
lift-cos.f64N/A
quot-tanN/A
lower-tan.f64N/A
lift-sin.f64N/A
lift-cos.f64N/A
quot-tanN/A
lower-tan.f6499.1%
Applied rewrites99.1%
lift-*.f64N/A
lift-cos.f64N/A
cos-neg-revN/A
lift-neg.f64N/A
sin-+PI/2-revN/A
lift-PI.f64N/A
mult-flip-revN/A
metadata-evalN/A
lift-*.f64N/A
add-flipN/A
sin-diffN/A
Applied rewrites99.1%
(FPCore (z1 z0 z2 z3)
:precision binary64
(sqrt
(-
(* 1/2 (+ (* (cos z0) (cos z1)) (+ (* (sin z0) (sin z1)) 1)))
(*
(*
-1/2
(+ -1 (* (- (* (tan z3) (tan z2)) -1) (* (cos z2) (cos z3)))))
(* (cos z1) (cos z0))))))double code(double z1, double z0, double z2, double z3) {
return sqrt(((0.5 * ((cos(z0) * cos(z1)) + ((sin(z0) * sin(z1)) + 1.0))) - ((-0.5 * (-1.0 + (((tan(z3) * tan(z2)) - -1.0) * (cos(z2) * cos(z3))))) * (cos(z1) * cos(z0)))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(z1, z0, z2, z3)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
real(8), intent (in) :: z3
code = sqrt(((0.5d0 * ((cos(z0) * cos(z1)) + ((sin(z0) * sin(z1)) + 1.0d0))) - (((-0.5d0) * ((-1.0d0) + (((tan(z3) * tan(z2)) - (-1.0d0)) * (cos(z2) * cos(z3))))) * (cos(z1) * cos(z0)))))
end function
public static double code(double z1, double z0, double z2, double z3) {
return Math.sqrt(((0.5 * ((Math.cos(z0) * Math.cos(z1)) + ((Math.sin(z0) * Math.sin(z1)) + 1.0))) - ((-0.5 * (-1.0 + (((Math.tan(z3) * Math.tan(z2)) - -1.0) * (Math.cos(z2) * Math.cos(z3))))) * (Math.cos(z1) * Math.cos(z0)))));
}
def code(z1, z0, z2, z3): return math.sqrt(((0.5 * ((math.cos(z0) * math.cos(z1)) + ((math.sin(z0) * math.sin(z1)) + 1.0))) - ((-0.5 * (-1.0 + (((math.tan(z3) * math.tan(z2)) - -1.0) * (math.cos(z2) * math.cos(z3))))) * (math.cos(z1) * math.cos(z0)))))
function code(z1, z0, z2, z3) return sqrt(Float64(Float64(0.5 * Float64(Float64(cos(z0) * cos(z1)) + Float64(Float64(sin(z0) * sin(z1)) + 1.0))) - Float64(Float64(-0.5 * Float64(-1.0 + Float64(Float64(Float64(tan(z3) * tan(z2)) - -1.0) * Float64(cos(z2) * cos(z3))))) * Float64(cos(z1) * cos(z0))))) end
function tmp = code(z1, z0, z2, z3) tmp = sqrt(((0.5 * ((cos(z0) * cos(z1)) + ((sin(z0) * sin(z1)) + 1.0))) - ((-0.5 * (-1.0 + (((tan(z3) * tan(z2)) - -1.0) * (cos(z2) * cos(z3))))) * (cos(z1) * cos(z0))))); end
code[z1_, z0_, z2_, z3_] := N[Sqrt[N[(N[(1/2 * N[(N[(N[Cos[z0], $MachinePrecision] * N[Cos[z1], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Sin[z0], $MachinePrecision] * N[Sin[z1], $MachinePrecision]), $MachinePrecision] + 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(-1/2 * N[(-1 + N[(N[(N[(N[Tan[z3], $MachinePrecision] * N[Tan[z2], $MachinePrecision]), $MachinePrecision] - -1), $MachinePrecision] * N[(N[Cos[z2], $MachinePrecision] * N[Cos[z3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[z1], $MachinePrecision] * N[Cos[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{\frac{1}{2} \cdot \left(\cos z0 \cdot \cos z1 + \left(\sin z0 \cdot \sin z1 + 1\right)\right) - \left(\frac{-1}{2} \cdot \left(-1 + \left(\tan z3 \cdot \tan z2 - -1\right) \cdot \left(\cos z2 \cdot \cos z3\right)\right)\right) \cdot \left(\cos z1 \cdot \cos z0\right)}
Initial program 63.7%
lift-+.f64N/A
+-commutativeN/A
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6479.0%
Applied rewrites79.0%
lift-cos.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lift--.f64N/A
cos-diffN/A
*-commutativeN/A
*-commutativeN/A
sum-to-multN/A
lower-unsound-*.f64N/A
lower-unsound-+.f64N/A
lower-unsound-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
*-commutativeN/A
Applied rewrites99.1%
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
metadata-evalN/A
lower--.f6499.1%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lift-sin.f64N/A
lift-cos.f64N/A
quot-tanN/A
lower-tan.f64N/A
lift-sin.f64N/A
lift-cos.f64N/A
quot-tanN/A
lower-tan.f6499.1%
Applied rewrites99.1%
(FPCore (z1 z0 z2 z3) :precision binary64 (sqrt (- (* 1/2 (+ (* (cos z0) (cos z1)) (+ (* (sin z0) (sin z1)) 1))) (* (* -1/2 (+ (+ -1 (* (cos z2) (cos z3))) (* (sin z2) (sin z3)))) (* (cos z1) (cos z0))))))
double code(double z1, double z0, double z2, double z3) {
return sqrt(((0.5 * ((cos(z0) * cos(z1)) + ((sin(z0) * sin(z1)) + 1.0))) - ((-0.5 * ((-1.0 + (cos(z2) * cos(z3))) + (sin(z2) * sin(z3)))) * (cos(z1) * cos(z0)))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(z1, z0, z2, z3)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
real(8), intent (in) :: z3
code = sqrt(((0.5d0 * ((cos(z0) * cos(z1)) + ((sin(z0) * sin(z1)) + 1.0d0))) - (((-0.5d0) * (((-1.0d0) + (cos(z2) * cos(z3))) + (sin(z2) * sin(z3)))) * (cos(z1) * cos(z0)))))
end function
public static double code(double z1, double z0, double z2, double z3) {
return Math.sqrt(((0.5 * ((Math.cos(z0) * Math.cos(z1)) + ((Math.sin(z0) * Math.sin(z1)) + 1.0))) - ((-0.5 * ((-1.0 + (Math.cos(z2) * Math.cos(z3))) + (Math.sin(z2) * Math.sin(z3)))) * (Math.cos(z1) * Math.cos(z0)))));
}
def code(z1, z0, z2, z3): return math.sqrt(((0.5 * ((math.cos(z0) * math.cos(z1)) + ((math.sin(z0) * math.sin(z1)) + 1.0))) - ((-0.5 * ((-1.0 + (math.cos(z2) * math.cos(z3))) + (math.sin(z2) * math.sin(z3)))) * (math.cos(z1) * math.cos(z0)))))
function code(z1, z0, z2, z3) return sqrt(Float64(Float64(0.5 * Float64(Float64(cos(z0) * cos(z1)) + Float64(Float64(sin(z0) * sin(z1)) + 1.0))) - Float64(Float64(-0.5 * Float64(Float64(-1.0 + Float64(cos(z2) * cos(z3))) + Float64(sin(z2) * sin(z3)))) * Float64(cos(z1) * cos(z0))))) end
function tmp = code(z1, z0, z2, z3) tmp = sqrt(((0.5 * ((cos(z0) * cos(z1)) + ((sin(z0) * sin(z1)) + 1.0))) - ((-0.5 * ((-1.0 + (cos(z2) * cos(z3))) + (sin(z2) * sin(z3)))) * (cos(z1) * cos(z0))))); end
code[z1_, z0_, z2_, z3_] := N[Sqrt[N[(N[(1/2 * N[(N[(N[Cos[z0], $MachinePrecision] * N[Cos[z1], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Sin[z0], $MachinePrecision] * N[Sin[z1], $MachinePrecision]), $MachinePrecision] + 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(-1/2 * N[(N[(-1 + N[(N[Cos[z2], $MachinePrecision] * N[Cos[z3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[z2], $MachinePrecision] * N[Sin[z3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[z1], $MachinePrecision] * N[Cos[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{\frac{1}{2} \cdot \left(\cos z0 \cdot \cos z1 + \left(\sin z0 \cdot \sin z1 + 1\right)\right) - \left(\frac{-1}{2} \cdot \left(\left(-1 + \cos z2 \cdot \cos z3\right) + \sin z2 \cdot \sin z3\right)\right) \cdot \left(\cos z1 \cdot \cos z0\right)}
Initial program 63.7%
lift-+.f64N/A
+-commutativeN/A
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6479.0%
Applied rewrites79.0%
lift-+.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lift--.f64N/A
cos-diffN/A
*-commutativeN/A
*-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6499.1%
Applied rewrites99.1%
(FPCore (z1 z0 z2 z3)
:precision binary64
(let* ((t_0 (cos (fmax z1 z0)))
(t_1 (cos (fmin z1 z0)))
(t_2 (* t_0 t_1))
(t_3
(sqrt
(+
1/2
(-
(304-z0z1z2z3z4
1/2
t_1
t_0
(sin (fmin z1 z0))
(sin (- (fmax z1 z0))))
(* (* t_2 -1/2) (- (cos (- z3 z2)) 1)))))))
(if (<= (fmax z1 z0) -6165521680034609/604462909807314587353088)
t_3
(if (<= (fmax z1 z0) 7791904696734915/590295810358705651712)
(sqrt
(-
(* (- (cos (- (fmax z1 z0) (fmin z1 z0))) -1) 1/2)
(*
(*
(- (* (- (* (tan z2) (tan z3)) -1) (* (cos z2) (cos z3))) 1)
-1/2)
t_2)))
t_3))))\begin{array}{l}
t_0 := \cos \left(\mathsf{max}\left(z1, z0\right)\right)\\
t_1 := \cos \left(\mathsf{min}\left(z1, z0\right)\right)\\
t_2 := t\_0 \cdot t\_1\\
t_3 := \sqrt{\frac{1}{2} + \left(\mathsf{304\_z0z1z2z3z4}\left(\frac{1}{2}, t\_1, t\_0, \sin \left(\mathsf{min}\left(z1, z0\right)\right), \sin \left(-\mathsf{max}\left(z1, z0\right)\right)\right) - \left(t\_2 \cdot \frac{-1}{2}\right) \cdot \left(\cos \left(z3 - z2\right) - 1\right)\right)}\\
\mathbf{if}\;\mathsf{max}\left(z1, z0\right) \leq \frac{-6165521680034609}{604462909807314587353088}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;\mathsf{max}\left(z1, z0\right) \leq \frac{7791904696734915}{590295810358705651712}:\\
\;\;\;\;\sqrt{\left(\cos \left(\mathsf{max}\left(z1, z0\right) - \mathsf{min}\left(z1, z0\right)\right) - -1\right) \cdot \frac{1}{2} - \left(\left(\left(\tan z2 \cdot \tan z3 - -1\right) \cdot \left(\cos z2 \cdot \cos z3\right) - 1\right) \cdot \frac{-1}{2}\right) \cdot t\_2}\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}
if z0 < -1.02e-8 or 1.3200000000000001e-5 < z0 Initial program 63.7%
lift--.f64N/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
metadata-evalN/A
associate--l+N/A
lower-+.f64N/A
lower--.f64N/A
Applied rewrites63.8%
Applied rewrites79.0%
if -1.02e-8 < z0 < 1.3200000000000001e-5Initial program 63.7%
lift-+.f64N/A
+-commutativeN/A
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6479.0%
Applied rewrites79.0%
lift-cos.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lift--.f64N/A
cos-diffN/A
*-commutativeN/A
*-commutativeN/A
sum-to-multN/A
lower-unsound-*.f64N/A
lower-unsound-+.f64N/A
lower-unsound-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
*-commutativeN/A
Applied rewrites99.1%
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
metadata-evalN/A
lower--.f6499.1%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lift-sin.f64N/A
lift-cos.f64N/A
quot-tanN/A
lower-tan.f64N/A
lift-sin.f64N/A
lift-cos.f64N/A
quot-tanN/A
lower-tan.f6499.1%
Applied rewrites99.1%
Applied rewrites78.8%
(FPCore (z1 z0 z2 z3)
:precision binary64
(let* ((t_0 (cos (fmax z1 z0)))
(t_1 (cos (fmin z1 z0)))
(t_2
(sqrt
(+
1/2
(-
(304-z0z1z2z3z4
1/2
t_1
t_0
(sin (fmin z1 z0))
(sin (- (fmax z1 z0))))
(* (* (* t_0 t_1) -1/2) (- (cos (- z3 z2)) 1)))))))
(if (<= (fmax z1 z0) -6165521680034609/604462909807314587353088)
t_2
(if (<= (fmax z1 z0) 7791904696734915/590295810358705651712)
(sqrt
(-
(* 1/2 (+ 1 (cos (- (fmin z1 z0) (fmax z1 z0)))))
(*
(*
-1/2
(+ -1 (+ (* (cos z3) (cos z2)) (* (sin z3) (sin z2)))))
(* t_1 t_0))))
t_2))))\begin{array}{l}
t_0 := \cos \left(\mathsf{max}\left(z1, z0\right)\right)\\
t_1 := \cos \left(\mathsf{min}\left(z1, z0\right)\right)\\
t_2 := \sqrt{\frac{1}{2} + \left(\mathsf{304\_z0z1z2z3z4}\left(\frac{1}{2}, t\_1, t\_0, \sin \left(\mathsf{min}\left(z1, z0\right)\right), \sin \left(-\mathsf{max}\left(z1, z0\right)\right)\right) - \left(\left(t\_0 \cdot t\_1\right) \cdot \frac{-1}{2}\right) \cdot \left(\cos \left(z3 - z2\right) - 1\right)\right)}\\
\mathbf{if}\;\mathsf{max}\left(z1, z0\right) \leq \frac{-6165521680034609}{604462909807314587353088}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;\mathsf{max}\left(z1, z0\right) \leq \frac{7791904696734915}{590295810358705651712}:\\
\;\;\;\;\sqrt{\frac{1}{2} \cdot \left(1 + \cos \left(\mathsf{min}\left(z1, z0\right) - \mathsf{max}\left(z1, z0\right)\right)\right) - \left(\frac{-1}{2} \cdot \left(-1 + \left(\cos z3 \cdot \cos z2 + \sin z3 \cdot \sin z2\right)\right)\right) \cdot \left(t\_1 \cdot t\_0\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
if z0 < -1.02e-8 or 1.3200000000000001e-5 < z0 Initial program 63.7%
lift--.f64N/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
metadata-evalN/A
associate--l+N/A
lower-+.f64N/A
lower--.f64N/A
Applied rewrites63.8%
Applied rewrites79.0%
if -1.02e-8 < z0 < 1.3200000000000001e-5Initial program 63.7%
lift-cos.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lift--.f64N/A
sub-negate-revN/A
cos-negN/A
cos-diffN/A
cos-neg-revN/A
lower-+.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6478.8%
Applied rewrites78.8%
(FPCore (z1 z0 z2 z3)
:precision binary64
(let* ((t_0 (cos (fmax z1 z0)))
(t_1 (cos (fmin z1 z0)))
(t_2 (sin (fmax z1 z0)))
(t_3 (sin (fmin z1 z0)))
(t_4 (- (cos (- z3 z2)) 1))
(t_5 (* t_0 t_1)))
(if (<= (fmax z1 z0) -6165521680034609/604462909807314587353088)
(sqrt
(-
(* 1/2 (+ t_5 (+ (* t_2 t_3) 1)))
(* t_4 (* (* -1/2 t_0) t_1))))
(if (<= (fmax z1 z0) 7791904696734915/590295810358705651712)
(sqrt
(-
(* 1/2 (+ 1 (cos (- (fmin z1 z0) (fmax z1 z0)))))
(*
(*
-1/2
(+ -1 (+ (* (cos z3) (cos z2)) (* (sin z3) (sin z2)))))
(* t_1 t_0))))
(sqrt
(-
(* 1/2 (+ 1 (+ t_5 (* t_3 t_2))))
(* (* t_1 (* t_4 -1/2)) t_0)))))))double code(double z1, double z0, double z2, double z3) {
double t_0 = cos(fmax(z1, z0));
double t_1 = cos(fmin(z1, z0));
double t_2 = sin(fmax(z1, z0));
double t_3 = sin(fmin(z1, z0));
double t_4 = cos((z3 - z2)) - 1.0;
double t_5 = t_0 * t_1;
double tmp;
if (fmax(z1, z0) <= -1.02e-8) {
tmp = sqrt(((0.5 * (t_5 + ((t_2 * t_3) + 1.0))) - (t_4 * ((-0.5 * t_0) * t_1))));
} else if (fmax(z1, z0) <= 1.32e-5) {
tmp = sqrt(((0.5 * (1.0 + cos((fmin(z1, z0) - fmax(z1, z0))))) - ((-0.5 * (-1.0 + ((cos(z3) * cos(z2)) + (sin(z3) * sin(z2))))) * (t_1 * t_0))));
} else {
tmp = sqrt(((0.5 * (1.0 + (t_5 + (t_3 * t_2)))) - ((t_1 * (t_4 * -0.5)) * t_0)));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(z1, z0, z2, z3)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
real(8), intent (in) :: z3
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: t_4
real(8) :: t_5
real(8) :: tmp
t_0 = cos(fmax(z1, z0))
t_1 = cos(fmin(z1, z0))
t_2 = sin(fmax(z1, z0))
t_3 = sin(fmin(z1, z0))
t_4 = cos((z3 - z2)) - 1.0d0
t_5 = t_0 * t_1
if (fmax(z1, z0) <= (-1.02d-8)) then
tmp = sqrt(((0.5d0 * (t_5 + ((t_2 * t_3) + 1.0d0))) - (t_4 * (((-0.5d0) * t_0) * t_1))))
else if (fmax(z1, z0) <= 1.32d-5) then
tmp = sqrt(((0.5d0 * (1.0d0 + cos((fmin(z1, z0) - fmax(z1, z0))))) - (((-0.5d0) * ((-1.0d0) + ((cos(z3) * cos(z2)) + (sin(z3) * sin(z2))))) * (t_1 * t_0))))
else
tmp = sqrt(((0.5d0 * (1.0d0 + (t_5 + (t_3 * t_2)))) - ((t_1 * (t_4 * (-0.5d0))) * t_0)))
end if
code = tmp
end function
public static double code(double z1, double z0, double z2, double z3) {
double t_0 = Math.cos(fmax(z1, z0));
double t_1 = Math.cos(fmin(z1, z0));
double t_2 = Math.sin(fmax(z1, z0));
double t_3 = Math.sin(fmin(z1, z0));
double t_4 = Math.cos((z3 - z2)) - 1.0;
double t_5 = t_0 * t_1;
double tmp;
if (fmax(z1, z0) <= -1.02e-8) {
tmp = Math.sqrt(((0.5 * (t_5 + ((t_2 * t_3) + 1.0))) - (t_4 * ((-0.5 * t_0) * t_1))));
} else if (fmax(z1, z0) <= 1.32e-5) {
tmp = Math.sqrt(((0.5 * (1.0 + Math.cos((fmin(z1, z0) - fmax(z1, z0))))) - ((-0.5 * (-1.0 + ((Math.cos(z3) * Math.cos(z2)) + (Math.sin(z3) * Math.sin(z2))))) * (t_1 * t_0))));
} else {
tmp = Math.sqrt(((0.5 * (1.0 + (t_5 + (t_3 * t_2)))) - ((t_1 * (t_4 * -0.5)) * t_0)));
}
return tmp;
}
def code(z1, z0, z2, z3): t_0 = math.cos(fmax(z1, z0)) t_1 = math.cos(fmin(z1, z0)) t_2 = math.sin(fmax(z1, z0)) t_3 = math.sin(fmin(z1, z0)) t_4 = math.cos((z3 - z2)) - 1.0 t_5 = t_0 * t_1 tmp = 0 if fmax(z1, z0) <= -1.02e-8: tmp = math.sqrt(((0.5 * (t_5 + ((t_2 * t_3) + 1.0))) - (t_4 * ((-0.5 * t_0) * t_1)))) elif fmax(z1, z0) <= 1.32e-5: tmp = math.sqrt(((0.5 * (1.0 + math.cos((fmin(z1, z0) - fmax(z1, z0))))) - ((-0.5 * (-1.0 + ((math.cos(z3) * math.cos(z2)) + (math.sin(z3) * math.sin(z2))))) * (t_1 * t_0)))) else: tmp = math.sqrt(((0.5 * (1.0 + (t_5 + (t_3 * t_2)))) - ((t_1 * (t_4 * -0.5)) * t_0))) return tmp
function code(z1, z0, z2, z3) t_0 = cos(fmax(z1, z0)) t_1 = cos(fmin(z1, z0)) t_2 = sin(fmax(z1, z0)) t_3 = sin(fmin(z1, z0)) t_4 = Float64(cos(Float64(z3 - z2)) - 1.0) t_5 = Float64(t_0 * t_1) tmp = 0.0 if (fmax(z1, z0) <= -1.02e-8) tmp = sqrt(Float64(Float64(0.5 * Float64(t_5 + Float64(Float64(t_2 * t_3) + 1.0))) - Float64(t_4 * Float64(Float64(-0.5 * t_0) * t_1)))); elseif (fmax(z1, z0) <= 1.32e-5) tmp = sqrt(Float64(Float64(0.5 * Float64(1.0 + cos(Float64(fmin(z1, z0) - fmax(z1, z0))))) - Float64(Float64(-0.5 * Float64(-1.0 + Float64(Float64(cos(z3) * cos(z2)) + Float64(sin(z3) * sin(z2))))) * Float64(t_1 * t_0)))); else tmp = sqrt(Float64(Float64(0.5 * Float64(1.0 + Float64(t_5 + Float64(t_3 * t_2)))) - Float64(Float64(t_1 * Float64(t_4 * -0.5)) * t_0))); end return tmp end
function tmp_2 = code(z1, z0, z2, z3) t_0 = cos(max(z1, z0)); t_1 = cos(min(z1, z0)); t_2 = sin(max(z1, z0)); t_3 = sin(min(z1, z0)); t_4 = cos((z3 - z2)) - 1.0; t_5 = t_0 * t_1; tmp = 0.0; if (max(z1, z0) <= -1.02e-8) tmp = sqrt(((0.5 * (t_5 + ((t_2 * t_3) + 1.0))) - (t_4 * ((-0.5 * t_0) * t_1)))); elseif (max(z1, z0) <= 1.32e-5) tmp = sqrt(((0.5 * (1.0 + cos((min(z1, z0) - max(z1, z0))))) - ((-0.5 * (-1.0 + ((cos(z3) * cos(z2)) + (sin(z3) * sin(z2))))) * (t_1 * t_0)))); else tmp = sqrt(((0.5 * (1.0 + (t_5 + (t_3 * t_2)))) - ((t_1 * (t_4 * -0.5)) * t_0))); end tmp_2 = tmp; end
code[z1_, z0_, z2_, z3_] := Block[{t$95$0 = N[Cos[N[Max[z1, z0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[Min[z1, z0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[Max[z1, z0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[Min[z1, z0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[(N[Cos[N[(z3 - z2), $MachinePrecision]], $MachinePrecision] - 1), $MachinePrecision]}, Block[{t$95$5 = N[(t$95$0 * t$95$1), $MachinePrecision]}, If[LessEqual[N[Max[z1, z0], $MachinePrecision], -6165521680034609/604462909807314587353088], N[Sqrt[N[(N[(1/2 * N[(t$95$5 + N[(N[(t$95$2 * t$95$3), $MachinePrecision] + 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(t$95$4 * N[(N[(-1/2 * t$95$0), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Max[z1, z0], $MachinePrecision], 7791904696734915/590295810358705651712], N[Sqrt[N[(N[(1/2 * N[(1 + N[Cos[N[(N[Min[z1, z0], $MachinePrecision] - N[Max[z1, z0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(-1/2 * N[(-1 + N[(N[(N[Cos[z3], $MachinePrecision] * N[Cos[z2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[z3], $MachinePrecision] * N[Sin[z2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(t$95$1 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(N[(1/2 * N[(1 + N[(t$95$5 + N[(t$95$3 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(t$95$1 * N[(t$95$4 * -1/2), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]]]]
\begin{array}{l}
t_0 := \cos \left(\mathsf{max}\left(z1, z0\right)\right)\\
t_1 := \cos \left(\mathsf{min}\left(z1, z0\right)\right)\\
t_2 := \sin \left(\mathsf{max}\left(z1, z0\right)\right)\\
t_3 := \sin \left(\mathsf{min}\left(z1, z0\right)\right)\\
t_4 := \cos \left(z3 - z2\right) - 1\\
t_5 := t\_0 \cdot t\_1\\
\mathbf{if}\;\mathsf{max}\left(z1, z0\right) \leq \frac{-6165521680034609}{604462909807314587353088}:\\
\;\;\;\;\sqrt{\frac{1}{2} \cdot \left(t\_5 + \left(t\_2 \cdot t\_3 + 1\right)\right) - t\_4 \cdot \left(\left(\frac{-1}{2} \cdot t\_0\right) \cdot t\_1\right)}\\
\mathbf{elif}\;\mathsf{max}\left(z1, z0\right) \leq \frac{7791904696734915}{590295810358705651712}:\\
\;\;\;\;\sqrt{\frac{1}{2} \cdot \left(1 + \cos \left(\mathsf{min}\left(z1, z0\right) - \mathsf{max}\left(z1, z0\right)\right)\right) - \left(\frac{-1}{2} \cdot \left(-1 + \left(\cos z3 \cdot \cos z2 + \sin z3 \cdot \sin z2\right)\right)\right) \cdot \left(t\_1 \cdot t\_0\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{2} \cdot \left(1 + \left(t\_5 + t\_3 \cdot t\_2\right)\right) - \left(t\_1 \cdot \left(t\_4 \cdot \frac{-1}{2}\right)\right) \cdot t\_0}\\
\end{array}
if z0 < -1.02e-8Initial program 63.7%
lift-+.f64N/A
+-commutativeN/A
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6479.0%
Applied rewrites79.0%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
lower-*.f6479.0%
Applied rewrites79.0%
if -1.02e-8 < z0 < 1.3200000000000001e-5Initial program 63.7%
lift-cos.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lift--.f64N/A
sub-negate-revN/A
cos-negN/A
cos-diffN/A
cos-neg-revN/A
lower-+.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6478.8%
Applied rewrites78.8%
if 1.3200000000000001e-5 < z0 Initial program 63.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites63.7%
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
*-commutativeN/A
lift-*.f64N/A
lower-+.f6479.0%
lift-*.f64N/A
*-commutativeN/A
lift-*.f6479.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6479.0%
Applied rewrites79.0%
(FPCore (z1 z0 z2 z3)
:precision binary64
(let* ((t_0 (cos (fmax z1 z0)))
(t_1 (cos (fmin z1 z0)))
(t_2 (sin (fmax z1 z0)))
(t_3 (sin (fmin z1 z0)))
(t_4 (* (* t_1 (* (- (cos (- z3 z2)) 1) -1/2)) t_0))
(t_5 (* t_0 t_1)))
(if (<= (fmax z1 z0) -6165521680034609/604462909807314587353088)
(sqrt (- (* 1/2 (+ t_5 (+ (* t_2 t_3) 1))) t_4))
(if (<= (fmax z1 z0) 7791904696734915/590295810358705651712)
(sqrt
(-
(* 1/2 (+ 1 (cos (- (fmin z1 z0) (fmax z1 z0)))))
(*
(*
-1/2
(+ -1 (+ (* (cos z3) (cos z2)) (* (sin z3) (sin z2)))))
(* t_1 t_0))))
(sqrt (- (* 1/2 (+ 1 (+ t_5 (* t_3 t_2)))) t_4))))))double code(double z1, double z0, double z2, double z3) {
double t_0 = cos(fmax(z1, z0));
double t_1 = cos(fmin(z1, z0));
double t_2 = sin(fmax(z1, z0));
double t_3 = sin(fmin(z1, z0));
double t_4 = (t_1 * ((cos((z3 - z2)) - 1.0) * -0.5)) * t_0;
double t_5 = t_0 * t_1;
double tmp;
if (fmax(z1, z0) <= -1.02e-8) {
tmp = sqrt(((0.5 * (t_5 + ((t_2 * t_3) + 1.0))) - t_4));
} else if (fmax(z1, z0) <= 1.32e-5) {
tmp = sqrt(((0.5 * (1.0 + cos((fmin(z1, z0) - fmax(z1, z0))))) - ((-0.5 * (-1.0 + ((cos(z3) * cos(z2)) + (sin(z3) * sin(z2))))) * (t_1 * t_0))));
} else {
tmp = sqrt(((0.5 * (1.0 + (t_5 + (t_3 * t_2)))) - t_4));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(z1, z0, z2, z3)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
real(8), intent (in) :: z3
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: t_4
real(8) :: t_5
real(8) :: tmp
t_0 = cos(fmax(z1, z0))
t_1 = cos(fmin(z1, z0))
t_2 = sin(fmax(z1, z0))
t_3 = sin(fmin(z1, z0))
t_4 = (t_1 * ((cos((z3 - z2)) - 1.0d0) * (-0.5d0))) * t_0
t_5 = t_0 * t_1
if (fmax(z1, z0) <= (-1.02d-8)) then
tmp = sqrt(((0.5d0 * (t_5 + ((t_2 * t_3) + 1.0d0))) - t_4))
else if (fmax(z1, z0) <= 1.32d-5) then
tmp = sqrt(((0.5d0 * (1.0d0 + cos((fmin(z1, z0) - fmax(z1, z0))))) - (((-0.5d0) * ((-1.0d0) + ((cos(z3) * cos(z2)) + (sin(z3) * sin(z2))))) * (t_1 * t_0))))
else
tmp = sqrt(((0.5d0 * (1.0d0 + (t_5 + (t_3 * t_2)))) - t_4))
end if
code = tmp
end function
public static double code(double z1, double z0, double z2, double z3) {
double t_0 = Math.cos(fmax(z1, z0));
double t_1 = Math.cos(fmin(z1, z0));
double t_2 = Math.sin(fmax(z1, z0));
double t_3 = Math.sin(fmin(z1, z0));
double t_4 = (t_1 * ((Math.cos((z3 - z2)) - 1.0) * -0.5)) * t_0;
double t_5 = t_0 * t_1;
double tmp;
if (fmax(z1, z0) <= -1.02e-8) {
tmp = Math.sqrt(((0.5 * (t_5 + ((t_2 * t_3) + 1.0))) - t_4));
} else if (fmax(z1, z0) <= 1.32e-5) {
tmp = Math.sqrt(((0.5 * (1.0 + Math.cos((fmin(z1, z0) - fmax(z1, z0))))) - ((-0.5 * (-1.0 + ((Math.cos(z3) * Math.cos(z2)) + (Math.sin(z3) * Math.sin(z2))))) * (t_1 * t_0))));
} else {
tmp = Math.sqrt(((0.5 * (1.0 + (t_5 + (t_3 * t_2)))) - t_4));
}
return tmp;
}
def code(z1, z0, z2, z3): t_0 = math.cos(fmax(z1, z0)) t_1 = math.cos(fmin(z1, z0)) t_2 = math.sin(fmax(z1, z0)) t_3 = math.sin(fmin(z1, z0)) t_4 = (t_1 * ((math.cos((z3 - z2)) - 1.0) * -0.5)) * t_0 t_5 = t_0 * t_1 tmp = 0 if fmax(z1, z0) <= -1.02e-8: tmp = math.sqrt(((0.5 * (t_5 + ((t_2 * t_3) + 1.0))) - t_4)) elif fmax(z1, z0) <= 1.32e-5: tmp = math.sqrt(((0.5 * (1.0 + math.cos((fmin(z1, z0) - fmax(z1, z0))))) - ((-0.5 * (-1.0 + ((math.cos(z3) * math.cos(z2)) + (math.sin(z3) * math.sin(z2))))) * (t_1 * t_0)))) else: tmp = math.sqrt(((0.5 * (1.0 + (t_5 + (t_3 * t_2)))) - t_4)) return tmp
function code(z1, z0, z2, z3) t_0 = cos(fmax(z1, z0)) t_1 = cos(fmin(z1, z0)) t_2 = sin(fmax(z1, z0)) t_3 = sin(fmin(z1, z0)) t_4 = Float64(Float64(t_1 * Float64(Float64(cos(Float64(z3 - z2)) - 1.0) * -0.5)) * t_0) t_5 = Float64(t_0 * t_1) tmp = 0.0 if (fmax(z1, z0) <= -1.02e-8) tmp = sqrt(Float64(Float64(0.5 * Float64(t_5 + Float64(Float64(t_2 * t_3) + 1.0))) - t_4)); elseif (fmax(z1, z0) <= 1.32e-5) tmp = sqrt(Float64(Float64(0.5 * Float64(1.0 + cos(Float64(fmin(z1, z0) - fmax(z1, z0))))) - Float64(Float64(-0.5 * Float64(-1.0 + Float64(Float64(cos(z3) * cos(z2)) + Float64(sin(z3) * sin(z2))))) * Float64(t_1 * t_0)))); else tmp = sqrt(Float64(Float64(0.5 * Float64(1.0 + Float64(t_5 + Float64(t_3 * t_2)))) - t_4)); end return tmp end
function tmp_2 = code(z1, z0, z2, z3) t_0 = cos(max(z1, z0)); t_1 = cos(min(z1, z0)); t_2 = sin(max(z1, z0)); t_3 = sin(min(z1, z0)); t_4 = (t_1 * ((cos((z3 - z2)) - 1.0) * -0.5)) * t_0; t_5 = t_0 * t_1; tmp = 0.0; if (max(z1, z0) <= -1.02e-8) tmp = sqrt(((0.5 * (t_5 + ((t_2 * t_3) + 1.0))) - t_4)); elseif (max(z1, z0) <= 1.32e-5) tmp = sqrt(((0.5 * (1.0 + cos((min(z1, z0) - max(z1, z0))))) - ((-0.5 * (-1.0 + ((cos(z3) * cos(z2)) + (sin(z3) * sin(z2))))) * (t_1 * t_0)))); else tmp = sqrt(((0.5 * (1.0 + (t_5 + (t_3 * t_2)))) - t_4)); end tmp_2 = tmp; end
code[z1_, z0_, z2_, z3_] := Block[{t$95$0 = N[Cos[N[Max[z1, z0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[Min[z1, z0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[Max[z1, z0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[Min[z1, z0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[(N[(t$95$1 * N[(N[(N[Cos[N[(z3 - z2), $MachinePrecision]], $MachinePrecision] - 1), $MachinePrecision] * -1/2), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]}, Block[{t$95$5 = N[(t$95$0 * t$95$1), $MachinePrecision]}, If[LessEqual[N[Max[z1, z0], $MachinePrecision], -6165521680034609/604462909807314587353088], N[Sqrt[N[(N[(1/2 * N[(t$95$5 + N[(N[(t$95$2 * t$95$3), $MachinePrecision] + 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$4), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Max[z1, z0], $MachinePrecision], 7791904696734915/590295810358705651712], N[Sqrt[N[(N[(1/2 * N[(1 + N[Cos[N[(N[Min[z1, z0], $MachinePrecision] - N[Max[z1, z0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(-1/2 * N[(-1 + N[(N[(N[Cos[z3], $MachinePrecision] * N[Cos[z2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[z3], $MachinePrecision] * N[Sin[z2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(t$95$1 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(N[(1/2 * N[(1 + N[(t$95$5 + N[(t$95$3 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$4), $MachinePrecision]], $MachinePrecision]]]]]]]]]
\begin{array}{l}
t_0 := \cos \left(\mathsf{max}\left(z1, z0\right)\right)\\
t_1 := \cos \left(\mathsf{min}\left(z1, z0\right)\right)\\
t_2 := \sin \left(\mathsf{max}\left(z1, z0\right)\right)\\
t_3 := \sin \left(\mathsf{min}\left(z1, z0\right)\right)\\
t_4 := \left(t\_1 \cdot \left(\left(\cos \left(z3 - z2\right) - 1\right) \cdot \frac{-1}{2}\right)\right) \cdot t\_0\\
t_5 := t\_0 \cdot t\_1\\
\mathbf{if}\;\mathsf{max}\left(z1, z0\right) \leq \frac{-6165521680034609}{604462909807314587353088}:\\
\;\;\;\;\sqrt{\frac{1}{2} \cdot \left(t\_5 + \left(t\_2 \cdot t\_3 + 1\right)\right) - t\_4}\\
\mathbf{elif}\;\mathsf{max}\left(z1, z0\right) \leq \frac{7791904696734915}{590295810358705651712}:\\
\;\;\;\;\sqrt{\frac{1}{2} \cdot \left(1 + \cos \left(\mathsf{min}\left(z1, z0\right) - \mathsf{max}\left(z1, z0\right)\right)\right) - \left(\frac{-1}{2} \cdot \left(-1 + \left(\cos z3 \cdot \cos z2 + \sin z3 \cdot \sin z2\right)\right)\right) \cdot \left(t\_1 \cdot t\_0\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{2} \cdot \left(1 + \left(t\_5 + t\_3 \cdot t\_2\right)\right) - t\_4}\\
\end{array}
if z0 < -1.02e-8Initial program 63.7%
lift-+.f64N/A
+-commutativeN/A
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
associate-+l+N/A
lower-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6479.0%
Applied rewrites79.0%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites79.0%
if -1.02e-8 < z0 < 1.3200000000000001e-5Initial program 63.7%
lift-cos.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lift--.f64N/A
sub-negate-revN/A
cos-negN/A
cos-diffN/A
cos-neg-revN/A
lower-+.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6478.8%
Applied rewrites78.8%
if 1.3200000000000001e-5 < z0 Initial program 63.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites63.7%
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
*-commutativeN/A
lift-*.f64N/A
lower-+.f6479.0%
lift-*.f64N/A
*-commutativeN/A
lift-*.f6479.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6479.0%
Applied rewrites79.0%
(FPCore (z1 z0 z2 z3)
:precision binary64
(let* ((t_0 (cos (fmax z1 z0)))
(t_1 (cos (fmin z1 z0)))
(t_2
(sqrt
(-
(*
1/2
(+
1
(+
(* t_0 t_1)
(* (sin (fmin z1 z0)) (sin (fmax z1 z0))))))
(* (* t_1 (* (- (cos (- z3 z2)) 1) -1/2)) t_0)))))
(if (<= (fmax z1 z0) -6165521680034609/604462909807314587353088)
t_2
(if (<= (fmax z1 z0) 7791904696734915/590295810358705651712)
(sqrt
(-
(* 1/2 (+ 1 (cos (- (fmin z1 z0) (fmax z1 z0)))))
(*
(*
-1/2
(+ -1 (+ (* (cos z3) (cos z2)) (* (sin z3) (sin z2)))))
(* t_1 t_0))))
t_2))))double code(double z1, double z0, double z2, double z3) {
double t_0 = cos(fmax(z1, z0));
double t_1 = cos(fmin(z1, z0));
double t_2 = sqrt(((0.5 * (1.0 + ((t_0 * t_1) + (sin(fmin(z1, z0)) * sin(fmax(z1, z0)))))) - ((t_1 * ((cos((z3 - z2)) - 1.0) * -0.5)) * t_0)));
double tmp;
if (fmax(z1, z0) <= -1.02e-8) {
tmp = t_2;
} else if (fmax(z1, z0) <= 1.32e-5) {
tmp = sqrt(((0.5 * (1.0 + cos((fmin(z1, z0) - fmax(z1, z0))))) - ((-0.5 * (-1.0 + ((cos(z3) * cos(z2)) + (sin(z3) * sin(z2))))) * (t_1 * t_0))));
} else {
tmp = t_2;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(z1, z0, z2, z3)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
real(8), intent (in) :: z3
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = cos(fmax(z1, z0))
t_1 = cos(fmin(z1, z0))
t_2 = sqrt(((0.5d0 * (1.0d0 + ((t_0 * t_1) + (sin(fmin(z1, z0)) * sin(fmax(z1, z0)))))) - ((t_1 * ((cos((z3 - z2)) - 1.0d0) * (-0.5d0))) * t_0)))
if (fmax(z1, z0) <= (-1.02d-8)) then
tmp = t_2
else if (fmax(z1, z0) <= 1.32d-5) then
tmp = sqrt(((0.5d0 * (1.0d0 + cos((fmin(z1, z0) - fmax(z1, z0))))) - (((-0.5d0) * ((-1.0d0) + ((cos(z3) * cos(z2)) + (sin(z3) * sin(z2))))) * (t_1 * t_0))))
else
tmp = t_2
end if
code = tmp
end function
public static double code(double z1, double z0, double z2, double z3) {
double t_0 = Math.cos(fmax(z1, z0));
double t_1 = Math.cos(fmin(z1, z0));
double t_2 = Math.sqrt(((0.5 * (1.0 + ((t_0 * t_1) + (Math.sin(fmin(z1, z0)) * Math.sin(fmax(z1, z0)))))) - ((t_1 * ((Math.cos((z3 - z2)) - 1.0) * -0.5)) * t_0)));
double tmp;
if (fmax(z1, z0) <= -1.02e-8) {
tmp = t_2;
} else if (fmax(z1, z0) <= 1.32e-5) {
tmp = Math.sqrt(((0.5 * (1.0 + Math.cos((fmin(z1, z0) - fmax(z1, z0))))) - ((-0.5 * (-1.0 + ((Math.cos(z3) * Math.cos(z2)) + (Math.sin(z3) * Math.sin(z2))))) * (t_1 * t_0))));
} else {
tmp = t_2;
}
return tmp;
}
def code(z1, z0, z2, z3): t_0 = math.cos(fmax(z1, z0)) t_1 = math.cos(fmin(z1, z0)) t_2 = math.sqrt(((0.5 * (1.0 + ((t_0 * t_1) + (math.sin(fmin(z1, z0)) * math.sin(fmax(z1, z0)))))) - ((t_1 * ((math.cos((z3 - z2)) - 1.0) * -0.5)) * t_0))) tmp = 0 if fmax(z1, z0) <= -1.02e-8: tmp = t_2 elif fmax(z1, z0) <= 1.32e-5: tmp = math.sqrt(((0.5 * (1.0 + math.cos((fmin(z1, z0) - fmax(z1, z0))))) - ((-0.5 * (-1.0 + ((math.cos(z3) * math.cos(z2)) + (math.sin(z3) * math.sin(z2))))) * (t_1 * t_0)))) else: tmp = t_2 return tmp
function code(z1, z0, z2, z3) t_0 = cos(fmax(z1, z0)) t_1 = cos(fmin(z1, z0)) t_2 = sqrt(Float64(Float64(0.5 * Float64(1.0 + Float64(Float64(t_0 * t_1) + Float64(sin(fmin(z1, z0)) * sin(fmax(z1, z0)))))) - Float64(Float64(t_1 * Float64(Float64(cos(Float64(z3 - z2)) - 1.0) * -0.5)) * t_0))) tmp = 0.0 if (fmax(z1, z0) <= -1.02e-8) tmp = t_2; elseif (fmax(z1, z0) <= 1.32e-5) tmp = sqrt(Float64(Float64(0.5 * Float64(1.0 + cos(Float64(fmin(z1, z0) - fmax(z1, z0))))) - Float64(Float64(-0.5 * Float64(-1.0 + Float64(Float64(cos(z3) * cos(z2)) + Float64(sin(z3) * sin(z2))))) * Float64(t_1 * t_0)))); else tmp = t_2; end return tmp end
function tmp_2 = code(z1, z0, z2, z3) t_0 = cos(max(z1, z0)); t_1 = cos(min(z1, z0)); t_2 = sqrt(((0.5 * (1.0 + ((t_0 * t_1) + (sin(min(z1, z0)) * sin(max(z1, z0)))))) - ((t_1 * ((cos((z3 - z2)) - 1.0) * -0.5)) * t_0))); tmp = 0.0; if (max(z1, z0) <= -1.02e-8) tmp = t_2; elseif (max(z1, z0) <= 1.32e-5) tmp = sqrt(((0.5 * (1.0 + cos((min(z1, z0) - max(z1, z0))))) - ((-0.5 * (-1.0 + ((cos(z3) * cos(z2)) + (sin(z3) * sin(z2))))) * (t_1 * t_0)))); else tmp = t_2; end tmp_2 = tmp; end
code[z1_, z0_, z2_, z3_] := Block[{t$95$0 = N[Cos[N[Max[z1, z0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[Min[z1, z0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(N[(1/2 * N[(1 + N[(N[(t$95$0 * t$95$1), $MachinePrecision] + N[(N[Sin[N[Min[z1, z0], $MachinePrecision]], $MachinePrecision] * N[Sin[N[Max[z1, z0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(t$95$1 * N[(N[(N[Cos[N[(z3 - z2), $MachinePrecision]], $MachinePrecision] - 1), $MachinePrecision] * -1/2), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Max[z1, z0], $MachinePrecision], -6165521680034609/604462909807314587353088], t$95$2, If[LessEqual[N[Max[z1, z0], $MachinePrecision], 7791904696734915/590295810358705651712], N[Sqrt[N[(N[(1/2 * N[(1 + N[Cos[N[(N[Min[z1, z0], $MachinePrecision] - N[Max[z1, z0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(-1/2 * N[(-1 + N[(N[(N[Cos[z3], $MachinePrecision] * N[Cos[z2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[z3], $MachinePrecision] * N[Sin[z2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(t$95$1 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
t_0 := \cos \left(\mathsf{max}\left(z1, z0\right)\right)\\
t_1 := \cos \left(\mathsf{min}\left(z1, z0\right)\right)\\
t_2 := \sqrt{\frac{1}{2} \cdot \left(1 + \left(t\_0 \cdot t\_1 + \sin \left(\mathsf{min}\left(z1, z0\right)\right) \cdot \sin \left(\mathsf{max}\left(z1, z0\right)\right)\right)\right) - \left(t\_1 \cdot \left(\left(\cos \left(z3 - z2\right) - 1\right) \cdot \frac{-1}{2}\right)\right) \cdot t\_0}\\
\mathbf{if}\;\mathsf{max}\left(z1, z0\right) \leq \frac{-6165521680034609}{604462909807314587353088}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;\mathsf{max}\left(z1, z0\right) \leq \frac{7791904696734915}{590295810358705651712}:\\
\;\;\;\;\sqrt{\frac{1}{2} \cdot \left(1 + \cos \left(\mathsf{min}\left(z1, z0\right) - \mathsf{max}\left(z1, z0\right)\right)\right) - \left(\frac{-1}{2} \cdot \left(-1 + \left(\cos z3 \cdot \cos z2 + \sin z3 \cdot \sin z2\right)\right)\right) \cdot \left(t\_1 \cdot t\_0\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
if z0 < -1.02e-8 or 1.3200000000000001e-5 < z0 Initial program 63.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites63.7%
lift-cos.f64N/A
lift--.f64N/A
cos-diffN/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
*-commutativeN/A
lift-*.f64N/A
lower-+.f6479.0%
lift-*.f64N/A
*-commutativeN/A
lift-*.f6479.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6479.0%
Applied rewrites79.0%
if -1.02e-8 < z0 < 1.3200000000000001e-5Initial program 63.7%
lift-cos.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lift--.f64N/A
sub-negate-revN/A
cos-negN/A
cos-diffN/A
cos-neg-revN/A
lower-+.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6478.8%
Applied rewrites78.8%
(FPCore (z1 z0 z2 z3) :precision binary64 (sqrt (- (* 1/2 (+ 1 (cos (- z1 z0)))) (* (* -1/2 (+ -1 (+ (* (cos z3) (cos z2)) (* (sin z3) (sin z2))))) (* (cos z1) (cos z0))))))
double code(double z1, double z0, double z2, double z3) {
return sqrt(((0.5 * (1.0 + cos((z1 - z0)))) - ((-0.5 * (-1.0 + ((cos(z3) * cos(z2)) + (sin(z3) * sin(z2))))) * (cos(z1) * cos(z0)))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(z1, z0, z2, z3)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
real(8), intent (in) :: z3
code = sqrt(((0.5d0 * (1.0d0 + cos((z1 - z0)))) - (((-0.5d0) * ((-1.0d0) + ((cos(z3) * cos(z2)) + (sin(z3) * sin(z2))))) * (cos(z1) * cos(z0)))))
end function
public static double code(double z1, double z0, double z2, double z3) {
return Math.sqrt(((0.5 * (1.0 + Math.cos((z1 - z0)))) - ((-0.5 * (-1.0 + ((Math.cos(z3) * Math.cos(z2)) + (Math.sin(z3) * Math.sin(z2))))) * (Math.cos(z1) * Math.cos(z0)))));
}
def code(z1, z0, z2, z3): return math.sqrt(((0.5 * (1.0 + math.cos((z1 - z0)))) - ((-0.5 * (-1.0 + ((math.cos(z3) * math.cos(z2)) + (math.sin(z3) * math.sin(z2))))) * (math.cos(z1) * math.cos(z0)))))
function code(z1, z0, z2, z3) return sqrt(Float64(Float64(0.5 * Float64(1.0 + cos(Float64(z1 - z0)))) - Float64(Float64(-0.5 * Float64(-1.0 + Float64(Float64(cos(z3) * cos(z2)) + Float64(sin(z3) * sin(z2))))) * Float64(cos(z1) * cos(z0))))) end
function tmp = code(z1, z0, z2, z3) tmp = sqrt(((0.5 * (1.0 + cos((z1 - z0)))) - ((-0.5 * (-1.0 + ((cos(z3) * cos(z2)) + (sin(z3) * sin(z2))))) * (cos(z1) * cos(z0))))); end
code[z1_, z0_, z2_, z3_] := N[Sqrt[N[(N[(1/2 * N[(1 + N[Cos[N[(z1 - z0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(-1/2 * N[(-1 + N[(N[(N[Cos[z3], $MachinePrecision] * N[Cos[z2], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[z3], $MachinePrecision] * N[Sin[z2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[z1], $MachinePrecision] * N[Cos[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{\frac{1}{2} \cdot \left(1 + \cos \left(z1 - z0\right)\right) - \left(\frac{-1}{2} \cdot \left(-1 + \left(\cos z3 \cdot \cos z2 + \sin z3 \cdot \sin z2\right)\right)\right) \cdot \left(\cos z1 \cdot \cos z0\right)}
Initial program 63.7%
lift-cos.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lift--.f64N/A
sub-negate-revN/A
cos-negN/A
cos-diffN/A
cos-neg-revN/A
lower-+.f64N/A
lower-*.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6478.8%
Applied rewrites78.8%
(FPCore (z1 z0 z2 z3) :precision binary64 (sqrt (- (* 1/2 (+ 1 (cos (- z1 z0)))) (* (* -1/2 (+ -1 (cos (* (- z2 z3) 1)))) (* (+ (cos (+ z0 z1)) (cos (- z0 z1))) 1/2)))))
double code(double z1, double z0, double z2, double z3) {
return sqrt(((0.5 * (1.0 + cos((z1 - z0)))) - ((-0.5 * (-1.0 + cos(((z2 - z3) * 1.0)))) * ((cos((z0 + z1)) + cos((z0 - z1))) * 0.5))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(z1, z0, z2, z3)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
real(8), intent (in) :: z3
code = sqrt(((0.5d0 * (1.0d0 + cos((z1 - z0)))) - (((-0.5d0) * ((-1.0d0) + cos(((z2 - z3) * 1.0d0)))) * ((cos((z0 + z1)) + cos((z0 - z1))) * 0.5d0))))
end function
public static double code(double z1, double z0, double z2, double z3) {
return Math.sqrt(((0.5 * (1.0 + Math.cos((z1 - z0)))) - ((-0.5 * (-1.0 + Math.cos(((z2 - z3) * 1.0)))) * ((Math.cos((z0 + z1)) + Math.cos((z0 - z1))) * 0.5))));
}
def code(z1, z0, z2, z3): return math.sqrt(((0.5 * (1.0 + math.cos((z1 - z0)))) - ((-0.5 * (-1.0 + math.cos(((z2 - z3) * 1.0)))) * ((math.cos((z0 + z1)) + math.cos((z0 - z1))) * 0.5))))
function code(z1, z0, z2, z3) return sqrt(Float64(Float64(0.5 * Float64(1.0 + cos(Float64(z1 - z0)))) - Float64(Float64(-0.5 * Float64(-1.0 + cos(Float64(Float64(z2 - z3) * 1.0)))) * Float64(Float64(cos(Float64(z0 + z1)) + cos(Float64(z0 - z1))) * 0.5)))) end
function tmp = code(z1, z0, z2, z3) tmp = sqrt(((0.5 * (1.0 + cos((z1 - z0)))) - ((-0.5 * (-1.0 + cos(((z2 - z3) * 1.0)))) * ((cos((z0 + z1)) + cos((z0 - z1))) * 0.5)))); end
code[z1_, z0_, z2_, z3_] := N[Sqrt[N[(N[(1/2 * N[(1 + N[Cos[N[(z1 - z0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(-1/2 * N[(-1 + N[Cos[N[(N[(z2 - z3), $MachinePrecision] * 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(N[Cos[N[(z0 + z1), $MachinePrecision]], $MachinePrecision] + N[Cos[N[(z0 - z1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{\frac{1}{2} \cdot \left(1 + \cos \left(z1 - z0\right)\right) - \left(\frac{-1}{2} \cdot \left(-1 + \cos \left(\left(z2 - z3\right) \cdot 1\right)\right)\right) \cdot \left(\left(\cos \left(z0 + z1\right) + \cos \left(z0 - z1\right)\right) \cdot \frac{1}{2}\right)}
Initial program 63.7%
lift-*.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
cos-multN/A
mult-flipN/A
metadata-evalN/A
lower-*.f64N/A
lift--.f64N/A
lift-cos.f64N/A
lower-+.f64N/A
lower-cos.f64N/A
+-commutativeN/A
lower-+.f6464.3%
lift-cos.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
lift--.f64N/A
sub-negate-revN/A
lower--.f6464.3%
Applied rewrites64.3%
(FPCore (z1 z0 z2 z3) :precision binary64 (sqrt (fabs (- (* (- (cos (- z0 z1)) -1) 1/2) (* (* (* (cos z0) (cos z1)) -1/2) (- (cos (- z3 z2)) 1))))))
double code(double z1, double z0, double z2, double z3) {
return sqrt(fabs((((cos((z0 - z1)) - -1.0) * 0.5) - (((cos(z0) * cos(z1)) * -0.5) * (cos((z3 - z2)) - 1.0)))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(z1, z0, z2, z3)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
real(8), intent (in) :: z3
code = sqrt(abs((((cos((z0 - z1)) - (-1.0d0)) * 0.5d0) - (((cos(z0) * cos(z1)) * (-0.5d0)) * (cos((z3 - z2)) - 1.0d0)))))
end function
public static double code(double z1, double z0, double z2, double z3) {
return Math.sqrt(Math.abs((((Math.cos((z0 - z1)) - -1.0) * 0.5) - (((Math.cos(z0) * Math.cos(z1)) * -0.5) * (Math.cos((z3 - z2)) - 1.0)))));
}
def code(z1, z0, z2, z3): return math.sqrt(math.fabs((((math.cos((z0 - z1)) - -1.0) * 0.5) - (((math.cos(z0) * math.cos(z1)) * -0.5) * (math.cos((z3 - z2)) - 1.0)))))
function code(z1, z0, z2, z3) return sqrt(abs(Float64(Float64(Float64(cos(Float64(z0 - z1)) - -1.0) * 0.5) - Float64(Float64(Float64(cos(z0) * cos(z1)) * -0.5) * Float64(cos(Float64(z3 - z2)) - 1.0))))) end
function tmp = code(z1, z0, z2, z3) tmp = sqrt(abs((((cos((z0 - z1)) - -1.0) * 0.5) - (((cos(z0) * cos(z1)) * -0.5) * (cos((z3 - z2)) - 1.0))))); end
code[z1_, z0_, z2_, z3_] := N[Sqrt[N[Abs[N[(N[(N[(N[Cos[N[(z0 - z1), $MachinePrecision]], $MachinePrecision] - -1), $MachinePrecision] * 1/2), $MachinePrecision] - N[(N[(N[(N[Cos[z0], $MachinePrecision] * N[Cos[z1], $MachinePrecision]), $MachinePrecision] * -1/2), $MachinePrecision] * N[(N[Cos[N[(z3 - z2), $MachinePrecision]], $MachinePrecision] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\sqrt{\left|\left(\cos \left(z0 - z1\right) - -1\right) \cdot \frac{1}{2} - \left(\left(\cos z0 \cdot \cos z1\right) \cdot \frac{-1}{2}\right) \cdot \left(\cos \left(z3 - z2\right) - 1\right)\right|}
Initial program 63.7%
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqr-abs-revN/A
mul-fabsN/A
Applied rewrites64.2%
(FPCore (z1 z0 z2 z3) :precision binary64 (sqrt (- (* (cos (- z0 z1)) 1/2) (- (* (* (* -1/2 (cos z0)) (cos z1)) (- (cos (- z3 z2)) 1)) 1/2))))
double code(double z1, double z0, double z2, double z3) {
return sqrt(((cos((z0 - z1)) * 0.5) - ((((-0.5 * cos(z0)) * cos(z1)) * (cos((z3 - z2)) - 1.0)) - 0.5)));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(z1, z0, z2, z3)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
real(8), intent (in) :: z3
code = sqrt(((cos((z0 - z1)) * 0.5d0) - (((((-0.5d0) * cos(z0)) * cos(z1)) * (cos((z3 - z2)) - 1.0d0)) - 0.5d0)))
end function
public static double code(double z1, double z0, double z2, double z3) {
return Math.sqrt(((Math.cos((z0 - z1)) * 0.5) - ((((-0.5 * Math.cos(z0)) * Math.cos(z1)) * (Math.cos((z3 - z2)) - 1.0)) - 0.5)));
}
def code(z1, z0, z2, z3): return math.sqrt(((math.cos((z0 - z1)) * 0.5) - ((((-0.5 * math.cos(z0)) * math.cos(z1)) * (math.cos((z3 - z2)) - 1.0)) - 0.5)))
function code(z1, z0, z2, z3) return sqrt(Float64(Float64(cos(Float64(z0 - z1)) * 0.5) - Float64(Float64(Float64(Float64(-0.5 * cos(z0)) * cos(z1)) * Float64(cos(Float64(z3 - z2)) - 1.0)) - 0.5))) end
function tmp = code(z1, z0, z2, z3) tmp = sqrt(((cos((z0 - z1)) * 0.5) - ((((-0.5 * cos(z0)) * cos(z1)) * (cos((z3 - z2)) - 1.0)) - 0.5))); end
code[z1_, z0_, z2_, z3_] := N[Sqrt[N[(N[(N[Cos[N[(z0 - z1), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision] - N[(N[(N[(N[(-1/2 * N[Cos[z0], $MachinePrecision]), $MachinePrecision] * N[Cos[z1], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[N[(z3 - z2), $MachinePrecision]], $MachinePrecision] - 1), $MachinePrecision]), $MachinePrecision] - 1/2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{\cos \left(z0 - z1\right) \cdot \frac{1}{2} - \left(\left(\left(\frac{-1}{2} \cdot \cos z0\right) \cdot \cos z1\right) \cdot \left(\cos \left(z3 - z2\right) - 1\right) - \frac{1}{2}\right)}
Initial program 63.7%
lift--.f64N/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
metadata-evalN/A
associate--l+N/A
lower-+.f64N/A
lower--.f64N/A
Applied rewrites63.8%
Applied rewrites63.7%
(FPCore (z1 z0 z2 z3) :precision binary64 (sqrt (+ 1/2 (- (* (cos (- z0 z1)) 1/2) (* (* (* (cos z0) (cos z1)) -1/2) (- (cos (- z3 z2)) 1))))))
double code(double z1, double z0, double z2, double z3) {
return sqrt((0.5 + ((cos((z0 - z1)) * 0.5) - (((cos(z0) * cos(z1)) * -0.5) * (cos((z3 - z2)) - 1.0)))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(z1, z0, z2, z3)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
real(8), intent (in) :: z3
code = sqrt((0.5d0 + ((cos((z0 - z1)) * 0.5d0) - (((cos(z0) * cos(z1)) * (-0.5d0)) * (cos((z3 - z2)) - 1.0d0)))))
end function
public static double code(double z1, double z0, double z2, double z3) {
return Math.sqrt((0.5 + ((Math.cos((z0 - z1)) * 0.5) - (((Math.cos(z0) * Math.cos(z1)) * -0.5) * (Math.cos((z3 - z2)) - 1.0)))));
}
def code(z1, z0, z2, z3): return math.sqrt((0.5 + ((math.cos((z0 - z1)) * 0.5) - (((math.cos(z0) * math.cos(z1)) * -0.5) * (math.cos((z3 - z2)) - 1.0)))))
function code(z1, z0, z2, z3) return sqrt(Float64(0.5 + Float64(Float64(cos(Float64(z0 - z1)) * 0.5) - Float64(Float64(Float64(cos(z0) * cos(z1)) * -0.5) * Float64(cos(Float64(z3 - z2)) - 1.0))))) end
function tmp = code(z1, z0, z2, z3) tmp = sqrt((0.5 + ((cos((z0 - z1)) * 0.5) - (((cos(z0) * cos(z1)) * -0.5) * (cos((z3 - z2)) - 1.0))))); end
code[z1_, z0_, z2_, z3_] := N[Sqrt[N[(1/2 + N[(N[(N[Cos[N[(z0 - z1), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision] - N[(N[(N[(N[Cos[z0], $MachinePrecision] * N[Cos[z1], $MachinePrecision]), $MachinePrecision] * -1/2), $MachinePrecision] * N[(N[Cos[N[(z3 - z2), $MachinePrecision]], $MachinePrecision] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sqrt{\frac{1}{2} + \left(\cos \left(z0 - z1\right) \cdot \frac{1}{2} - \left(\left(\cos z0 \cdot \cos z1\right) \cdot \frac{-1}{2}\right) \cdot \left(\cos \left(z3 - z2\right) - 1\right)\right)}
Initial program 63.7%
lift--.f64N/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
metadata-evalN/A
associate--l+N/A
lower-+.f64N/A
lower--.f64N/A
Applied rewrites63.8%
herbie shell --seed 2025277 -o generate:taylor -o generate:evaluate
(FPCore (z1 z0 z2 z3)
:name "(sqrt (- (* 1/2 (+ 1 (cos (- z1 z0)))) (* (* -1/2 (+ -1 (cos (* (- z2 z3) 1)))) (* (cos z1) (cos z0)))))"
:precision binary64
(sqrt (- (* 1/2 (+ 1 (cos (- z1 z0)))) (* (* -1/2 (+ -1 (cos (* (- z2 z3) 1)))) (* (cos z1) (cos z0))))))