
(FPCore (z0 z1) :precision binary64 (sin (- z0 z1)))
double code(double z0, double z1) {
return sin((z0 - z1));
}
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(z0, z1)
use fmin_fmax_functions
real(8), intent (in) :: z0
real(8), intent (in) :: z1
code = sin((z0 - z1))
end function
public static double code(double z0, double z1) {
return Math.sin((z0 - z1));
}
def code(z0, z1): return math.sin((z0 - z1))
function code(z0, z1) return sin(Float64(z0 - z1)) end
function tmp = code(z0, z1) tmp = sin((z0 - z1)); end
code[z0_, z1_] := N[Sin[N[(z0 - z1), $MachinePrecision]], $MachinePrecision]
\sin \left(z0 - z1\right)
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (z0 z1) :precision binary64 (sin (- z0 z1)))
double code(double z0, double z1) {
return sin((z0 - z1));
}
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(z0, z1)
use fmin_fmax_functions
real(8), intent (in) :: z0
real(8), intent (in) :: z1
code = sin((z0 - z1))
end function
public static double code(double z0, double z1) {
return Math.sin((z0 - z1));
}
def code(z0, z1): return math.sin((z0 - z1))
function code(z0, z1) return sin(Float64(z0 - z1)) end
function tmp = code(z0, z1) tmp = sin((z0 - z1)); end
code[z0_, z1_] := N[Sin[N[(z0 - z1), $MachinePrecision]], $MachinePrecision]
\sin \left(z0 - z1\right)
(FPCore (z0 z1) :precision binary64 (- (* (cos z1) (sin z0)) (* (sin z1) (cos z0))))
double code(double z0, double z1) {
return (cos(z1) * sin(z0)) - (sin(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(z0, z1)
use fmin_fmax_functions
real(8), intent (in) :: z0
real(8), intent (in) :: z1
code = (cos(z1) * sin(z0)) - (sin(z1) * cos(z0))
end function
public static double code(double z0, double z1) {
return (Math.cos(z1) * Math.sin(z0)) - (Math.sin(z1) * Math.cos(z0));
}
def code(z0, z1): return (math.cos(z1) * math.sin(z0)) - (math.sin(z1) * math.cos(z0))
function code(z0, z1) return Float64(Float64(cos(z1) * sin(z0)) - Float64(sin(z1) * cos(z0))) end
function tmp = code(z0, z1) tmp = (cos(z1) * sin(z0)) - (sin(z1) * cos(z0)); end
code[z0_, z1_] := N[(N[(N[Cos[z1], $MachinePrecision] * N[Sin[z0], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[z1], $MachinePrecision] * N[Cos[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\cos z1 \cdot \sin z0 - \sin z1 \cdot \cos z0
Initial program 77.1%
lift-sin.f64N/A
lift--.f64N/A
sin-diffN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-cos.f6499.8%
Applied rewrites99.8%
(FPCore (z0 z1) :precision binary64 (* (- (sin z0) (* (tan z1) (cos z0))) (cos z1)))
double code(double z0, double z1) {
return (sin(z0) - (tan(z1) * cos(z0))) * cos(z1);
}
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(z0, z1)
use fmin_fmax_functions
real(8), intent (in) :: z0
real(8), intent (in) :: z1
code = (sin(z0) - (tan(z1) * cos(z0))) * cos(z1)
end function
public static double code(double z0, double z1) {
return (Math.sin(z0) - (Math.tan(z1) * Math.cos(z0))) * Math.cos(z1);
}
def code(z0, z1): return (math.sin(z0) - (math.tan(z1) * math.cos(z0))) * math.cos(z1)
function code(z0, z1) return Float64(Float64(sin(z0) - Float64(tan(z1) * cos(z0))) * cos(z1)) end
function tmp = code(z0, z1) tmp = (sin(z0) - (tan(z1) * cos(z0))) * cos(z1); end
code[z0_, z1_] := N[(N[(N[Sin[z0], $MachinePrecision] - N[(N[Tan[z1], $MachinePrecision] * N[Cos[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[z1], $MachinePrecision]), $MachinePrecision]
\left(\sin z0 - \tan z1 \cdot \cos z0\right) \cdot \cos z1
Initial program 77.1%
lift-sin.f64N/A
lift--.f64N/A
sin-diffN/A
sub-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-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-sin.f6499.6%
Applied rewrites99.6%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
times-fracN/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
lift-sin.f64N/A
lift-cos.f64N/A
quot-tanN/A
lower-tan.f6499.5%
Applied rewrites99.5%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6499.5%
lower-unsound-/.f64N/A
*-lft-identityN/A
lower-unsound--.f64N/A
lower-unsound-*.f64N/A
*-lft-identityN/A
sub-to-multN/A
*-lft-identityN/A
lower--.f6499.6%
Applied rewrites99.6%
herbie shell --seed 2025277 -o generate:taylor -o generate:evaluate
(FPCore (z0 z1)
:name "(sin (- z0 z1))"
:precision binary64
(sin (- z0 z1)))