
(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.15e-202) (not (<= z 5.4e-105))) (- (* x 1.0) (* z (sin y))) (* (cos y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.15e-202) || !(z <= 5.4e-105)) {
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.15d-202)) .or. (.not. (z <= 5.4d-105))) 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.15e-202) || !(z <= 5.4e-105)) {
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.15e-202) or not (z <= 5.4e-105): 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.15e-202) || !(z <= 5.4e-105)) 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.15e-202) || ~((z <= 5.4e-105))) 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.15e-202], N[Not[LessEqual[z, 5.4e-105]], $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.15 \cdot 10^{-202} \lor \neg \left(z \leq 5.4 \cdot 10^{-105}\right):\\
\;\;\;\;x \cdot 1 - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot x\\
\end{array}
\end{array}
if z < -1.1499999999999999e-202 or 5.39999999999999985e-105 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites88.7%
if -1.1499999999999999e-202 < z < 5.39999999999999985e-105Initial program 99.7%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
inv-powN/A
lower-pow.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6499.7
Applied rewrites99.7%
Taylor expanded in x around inf
Applied rewrites90.4%
Final simplification89.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.3e-10) (not (<= x 3.2e-208))) (* (cos y) x) (* (- z) (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.3e-10) || !(x <= 3.2e-208)) {
tmp = cos(y) * x;
} else {
tmp = -z * sin(y);
}
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 <= (-1.3d-10)) .or. (.not. (x <= 3.2d-208))) then
tmp = cos(y) * x
else
tmp = -z * sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.3e-10) || !(x <= 3.2e-208)) {
tmp = Math.cos(y) * x;
} else {
tmp = -z * Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.3e-10) or not (x <= 3.2e-208): tmp = math.cos(y) * x else: tmp = -z * math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.3e-10) || !(x <= 3.2e-208)) tmp = Float64(cos(y) * x); else tmp = Float64(Float64(-z) * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.3e-10) || ~((x <= 3.2e-208))) tmp = cos(y) * x; else tmp = -z * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.3e-10], N[Not[LessEqual[x, 3.2e-208]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{-10} \lor \neg \left(x \leq 3.2 \cdot 10^{-208}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot \sin y\\
\end{array}
\end{array}
if x < -1.29999999999999991e-10 or 3.2000000000000001e-208 < x Initial program 99.8%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
inv-powN/A
lower-pow.f6499.7
Applied rewrites99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6497.0
Applied rewrites97.0%
Taylor expanded in x around inf
Applied rewrites80.2%
if -1.29999999999999991e-10 < x < 3.2000000000000001e-208Initial 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.f6482.9
Applied rewrites82.9%
Final simplification81.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.12) (not (<= y 2100000.0))) (* (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.12) || !(y <= 2100000.0)) {
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.12) || !(y <= 2100000.0)) 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.12], N[Not[LessEqual[y, 2100000.0]], $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.12 \lor \neg \left(y \leq 2100000\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.12 or 2.1e6 < y Initial program 99.7%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
inv-powN/A
lower-pow.f6499.5
Applied rewrites99.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6485.6
Applied rewrites85.6%
Taylor expanded in x around inf
Applied rewrites44.5%
if -0.12 < y < 2.1e6Initial 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.2
Applied rewrites99.2%
Final simplification69.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -9.2e+92) (not (<= z 5.8e+126))) (* (- y) z) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9.2e+92) || !(z <= 5.8e+126)) {
tmp = -y * z;
} else {
tmp = 1.0 * 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 <= (-9.2d+92)) .or. (.not. (z <= 5.8d+126))) then
tmp = -y * z
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -9.2e+92) || !(z <= 5.8e+126)) {
tmp = -y * z;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9.2e+92) or not (z <= 5.8e+126): tmp = -y * z else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9.2e+92) || !(z <= 5.8e+126)) tmp = Float64(Float64(-y) * z); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -9.2e+92) || ~((z <= 5.8e+126))) tmp = -y * z; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9.2e+92], N[Not[LessEqual[z, 5.8e+126]], $MachinePrecision]], N[((-y) * z), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{+92} \lor \neg \left(z \leq 5.8 \cdot 10^{+126}\right):\\
\;\;\;\;\left(-y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -9.19999999999999994e92 or 5.79999999999999971e126 < z Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6443.7
Applied rewrites43.7%
Taylor expanded in x around 0
Applied rewrites31.8%
if -9.19999999999999994e92 < z < 5.79999999999999971e126Initial program 99.8%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
inv-powN/A
lower-pow.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6498.8
Applied rewrites98.8%
Taylor expanded in y around 0
Applied rewrites47.4%
Final simplification43.2%
(FPCore (x y z) :precision binary64 (fma (- z) y x))
double code(double x, double y, double z) {
return fma(-z, y, x);
}
function code(x, y, z) return fma(Float64(-z), y, x) end
code[x_, y_, z_] := N[((-z) * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-z, y, x\right)
\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-*.f6449.0
Applied rewrites49.0%
Applied rewrites49.0%
(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-*.f6449.0
Applied rewrites49.0%
(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
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
inv-powN/A
lower-pow.f6499.7
Applied rewrites99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6489.9
Applied rewrites89.9%
Taylor expanded in y around 0
Applied rewrites38.5%
Final simplification38.5%
herbie shell --seed 2024318
(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))))