
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) - (z * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y - z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) - (z * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y - z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) - (z * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y - z \cdot \sin y
\end{array}
Initial program 99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.25e-122) (not (<= z 2.15e-8))) (- (* x 1.0) (* z (sin y))) (* (cos y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.25e-122) || !(z <= 2.15e-8)) {
tmp = (x * 1.0) - (z * sin(y));
} else {
tmp = cos(y) * x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-1.25d-122)) .or. (.not. (z <= 2.15d-8))) then
tmp = (x * 1.0d0) - (z * sin(y))
else
tmp = cos(y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.25e-122) || !(z <= 2.15e-8)) {
tmp = (x * 1.0) - (z * Math.sin(y));
} else {
tmp = Math.cos(y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.25e-122) or not (z <= 2.15e-8): tmp = (x * 1.0) - (z * math.sin(y)) else: tmp = math.cos(y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.25e-122) || !(z <= 2.15e-8)) tmp = Float64(Float64(x * 1.0) - Float64(z * sin(y))); else tmp = Float64(cos(y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.25e-122) || ~((z <= 2.15e-8))) tmp = (x * 1.0) - (z * sin(y)); else tmp = cos(y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.25e-122], N[Not[LessEqual[z, 2.15e-8]], $MachinePrecision]], N[(N[(x * 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{-122} \lor \neg \left(z \leq 2.15 \cdot 10^{-8}\right):\\
\;\;\;\;x \cdot 1 - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot x\\
\end{array}
\end{array}
if z < -1.25e-122 or 2.1500000000000001e-8 < z Initial program 99.9%
Taylor expanded in y around 0
Applied rewrites89.7%
if -1.25e-122 < z < 2.1500000000000001e-8Initial program 99.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
neg-sub0N/A
mul0-lftN/A
metadata-evalN/A
distribute-lft1-inN/A
lower-*.f64N/A
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites88.3%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (<= z -1.25e-122) (- (* x 1.0) (* z (sin y))) (if (<= z 2.15e-8) (* (cos y) x) (fma (sin y) (- z) (* 1.0 x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.25e-122) {
tmp = (x * 1.0) - (z * sin(y));
} else if (z <= 2.15e-8) {
tmp = cos(y) * x;
} else {
tmp = fma(sin(y), -z, (1.0 * x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.25e-122) tmp = Float64(Float64(x * 1.0) - Float64(z * sin(y))); elseif (z <= 2.15e-8) tmp = Float64(cos(y) * x); else tmp = fma(sin(y), Float64(-z), Float64(1.0 * x)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.25e-122], N[(N[(x * 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.15e-8], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * (-z) + N[(1.0 * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{-122}:\\
\;\;\;\;x \cdot 1 - z \cdot \sin y\\
\mathbf{elif}\;z \leq 2.15 \cdot 10^{-8}:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, -z, 1 \cdot x\right)\\
\end{array}
\end{array}
if z < -1.25e-122Initial program 99.9%
Taylor expanded in y around 0
Applied rewrites91.0%
if -1.25e-122 < z < 2.1500000000000001e-8Initial program 99.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
neg-sub0N/A
mul0-lftN/A
metadata-evalN/A
distribute-lft1-inN/A
lower-*.f64N/A
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites88.3%
if 2.1500000000000001e-8 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites88.1%
lift--.f64N/A
lift-*.f64N/A
cancel-sign-sub-invN/A
lift-neg.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6488.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6488.1
Applied rewrites88.1%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -5e+60) (not (<= z 2.6e+130))) (* (- z) (sin y)) (* (cos y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5e+60) || !(z <= 2.6e+130)) {
tmp = -z * sin(y);
} else {
tmp = cos(y) * x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-5d+60)) .or. (.not. (z <= 2.6d+130))) then
tmp = -z * sin(y)
else
tmp = cos(y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -5e+60) || !(z <= 2.6e+130)) {
tmp = -z * Math.sin(y);
} else {
tmp = Math.cos(y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5e+60) or not (z <= 2.6e+130): tmp = -z * math.sin(y) else: tmp = math.cos(y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5e+60) || !(z <= 2.6e+130)) tmp = Float64(Float64(-z) * sin(y)); else tmp = Float64(cos(y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5e+60) || ~((z <= 2.6e+130))) tmp = -z * sin(y); else tmp = cos(y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5e+60], N[Not[LessEqual[z, 2.6e+130]], $MachinePrecision]], N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{+60} \lor \neg \left(z \leq 2.6 \cdot 10^{+130}\right):\\
\;\;\;\;\left(-z\right) \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot x\\
\end{array}
\end{array}
if z < -4.99999999999999975e60 or 2.5999999999999998e130 < z Initial program 99.8%
Taylor expanded in x around 0
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6477.7
Applied rewrites77.7%
if -4.99999999999999975e60 < z < 2.5999999999999998e130Initial program 99.9%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
neg-sub0N/A
mul0-lftN/A
metadata-evalN/A
distribute-lft1-inN/A
lower-*.f64N/A
Applied rewrites98.6%
Taylor expanded in x around inf
Applied rewrites80.5%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.058) (not (<= y 0.07))) (* (cos y) x) (fma (- (* (fma 0.16666666666666666 (* z y) (* -0.5 x)) y) z) y x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.058) || !(y <= 0.07)) {
tmp = cos(y) * x;
} else {
tmp = fma(((fma(0.16666666666666666, (z * y), (-0.5 * x)) * y) - z), y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -0.058) || !(y <= 0.07)) tmp = Float64(cos(y) * x); else tmp = fma(Float64(Float64(fma(0.16666666666666666, Float64(z * y), Float64(-0.5 * x)) * y) - z), y, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.058], N[Not[LessEqual[y, 0.07]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(N[(0.16666666666666666 * N[(z * y), $MachinePrecision] + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.058 \lor \neg \left(y \leq 0.07\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, z \cdot y, -0.5 \cdot x\right) \cdot y - z, y, x\right)\\
\end{array}
\end{array}
if y < -0.0580000000000000029 or 0.070000000000000007 < y Initial program 99.7%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
Taylor expanded in x around inf
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
neg-sub0N/A
mul0-lftN/A
metadata-evalN/A
distribute-lft1-inN/A
lower-*.f64N/A
Applied rewrites86.7%
Taylor expanded in x around inf
Applied rewrites50.5%
if -0.0580000000000000029 < y < 0.070000000000000007Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6499.7
Applied rewrites99.7%
Final simplification74.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -2e-191) (not (<= x 3.8e-155))) (* 1.0 x) (* (- y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e-191) || !(x <= 3.8e-155)) {
tmp = 1.0 * x;
} else {
tmp = -y * z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-2d-191)) .or. (.not. (x <= 3.8d-155))) then
tmp = 1.0d0 * x
else
tmp = -y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2e-191) || !(x <= 3.8e-155)) {
tmp = 1.0 * x;
} else {
tmp = -y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e-191) or not (x <= 3.8e-155): tmp = 1.0 * x else: tmp = -y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e-191) || !(x <= 3.8e-155)) tmp = Float64(1.0 * x); else tmp = Float64(Float64(-y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2e-191) || ~((x <= 3.8e-155))) tmp = 1.0 * x; else tmp = -y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e-191], N[Not[LessEqual[x, 3.8e-155]], $MachinePrecision]], N[(1.0 * x), $MachinePrecision], N[((-y) * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-191} \lor \neg \left(x \leq 3.8 \cdot 10^{-155}\right):\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot z\\
\end{array}
\end{array}
if x < -2e-191 or 3.7999999999999998e-155 < x Initial program 99.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
neg-sub0N/A
mul0-lftN/A
metadata-evalN/A
distribute-lft1-inN/A
lower-*.f64N/A
Applied rewrites95.1%
Taylor expanded in y around 0
Applied rewrites44.8%
if -2e-191 < x < 3.7999999999999998e-155Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6464.5
Applied rewrites64.5%
Taylor expanded in x around 0
Applied rewrites46.7%
Final simplification45.2%
(FPCore (x y z) :precision binary64 (- x (* z y)))
double code(double x, double y, double z) {
return x - (z * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x - (z * y)
end function
public static double code(double x, double y, double z) {
return x - (z * y);
}
def code(x, y, z): return x - (z * y)
function code(x, y, z) return Float64(x - Float64(z * y)) end
function tmp = code(x, y, z) tmp = x - (z * y); end
code[x_, y_, z_] := N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - z \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6452.1
Applied rewrites52.1%
(FPCore (x y z) :precision binary64 (* 1.0 x))
double code(double x, double y, double z) {
return 1.0 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 * x
end function
public static double code(double x, double y, double z) {
return 1.0 * x;
}
def code(x, y, z): return 1.0 * x
function code(x, y, z) return Float64(1.0 * x) end
function tmp = code(x, y, z) tmp = 1.0 * x; end
code[x_, y_, z_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 99.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
neg-sub0N/A
mul0-lftN/A
metadata-evalN/A
distribute-lft1-inN/A
lower-*.f64N/A
Applied rewrites91.3%
Taylor expanded in y around 0
Applied rewrites39.3%
Final simplification39.3%
herbie shell --seed 2024321
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, A"
:precision binary64
(- (* x (cos y)) (* z (sin y))))