
(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 9 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 (fma (sin y) (- z) (* x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), -z, (x * cos(y)));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, x \cdot \cos y\right)
\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%
Final simplification99.8%
(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
(let* ((t_0 (* (- z) (sin y))))
(if (<= y -1.05e+259)
(* (cos y) x)
(if (<= y -52000.0)
t_0
(if (<= y 0.044)
(fma (- (* (fma 0.16666666666666666 (* z y) (* -0.5 x)) y) z) y x)
t_0)))))
double code(double x, double y, double z) {
double t_0 = -z * sin(y);
double tmp;
if (y <= -1.05e+259) {
tmp = cos(y) * x;
} else if (y <= -52000.0) {
tmp = t_0;
} else if (y <= 0.044) {
tmp = fma(((fma(0.16666666666666666, (z * y), (-0.5 * x)) * y) - z), y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(-z) * sin(y)) tmp = 0.0 if (y <= -1.05e+259) tmp = Float64(cos(y) * x); elseif (y <= -52000.0) tmp = t_0; elseif (y <= 0.044) tmp = fma(Float64(Float64(fma(0.16666666666666666, Float64(z * y), Float64(-0.5 * x)) * y) - z), y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.05e+259], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], If[LessEqual[y, -52000.0], t$95$0, If[LessEqual[y, 0.044], N[(N[(N[(N[(0.16666666666666666 * N[(z * y), $MachinePrecision] + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision] * y + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot \sin y\\
\mathbf{if}\;y \leq -1.05 \cdot 10^{+259}:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{elif}\;y \leq -52000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.044:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, z \cdot y, -0.5 \cdot x\right) \cdot y - z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.05000000000000003e259Initial program 99.3%
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%
lift-pow.f64N/A
unpow-1N/A
lower-/.f6499.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6486.4
Applied rewrites86.4%
Taylor expanded in x around inf
Applied rewrites82.1%
if -1.05000000000000003e259 < y < -52000 or 0.043999999999999997 < y Initial program 99.7%
Taylor expanded in x around 0
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6460.9
Applied rewrites60.9%
if -52000 < y < 0.043999999999999997Initial 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%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* 1.0 x) (* z (sin y))))) (if (<= z -2.9e-62) t_0 (if (<= z 1.35e-20) (* (cos y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 * x) - (z * sin(y));
double tmp;
if (z <= -2.9e-62) {
tmp = t_0;
} else if (z <= 1.35e-20) {
tmp = cos(y) * x;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = (1.0d0 * x) - (z * sin(y))
if (z <= (-2.9d-62)) then
tmp = t_0
else if (z <= 1.35d-20) then
tmp = cos(y) * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (1.0 * x) - (z * Math.sin(y));
double tmp;
if (z <= -2.9e-62) {
tmp = t_0;
} else if (z <= 1.35e-20) {
tmp = Math.cos(y) * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 * x) - (z * math.sin(y)) tmp = 0 if z <= -2.9e-62: tmp = t_0 elif z <= 1.35e-20: tmp = math.cos(y) * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 * x) - Float64(z * sin(y))) tmp = 0.0 if (z <= -2.9e-62) tmp = t_0; elseif (z <= 1.35e-20) tmp = Float64(cos(y) * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 * x) - (z * sin(y)); tmp = 0.0; if (z <= -2.9e-62) tmp = t_0; elseif (z <= 1.35e-20) tmp = cos(y) * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 * x), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.9e-62], t$95$0, If[LessEqual[z, 1.35e-20], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 \cdot x - z \cdot \sin y\\
\mathbf{if}\;z \leq -2.9 \cdot 10^{-62}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{-20}:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.89999999999999986e-62 or 1.35e-20 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites93.9%
if -2.89999999999999986e-62 < z < 1.35e-20Initial 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%
lift-pow.f64N/A
unpow-1N/A
lower-/.f6499.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites91.3%
Final simplification92.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -0.125)
t_0
(if (<= y 7.4e-9)
(-
(* 1.0 x)
(*
(fma
(* (fma 0.008333333333333333 (* y y) -0.16666666666666666) z)
(* y y)
z)
y))
t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -0.125) {
tmp = t_0;
} else if (y <= 7.4e-9) {
tmp = (1.0 * x) - (fma((fma(0.008333333333333333, (y * y), -0.16666666666666666) * z), (y * y), z) * y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (y <= -0.125) tmp = t_0; elseif (y <= 7.4e-9) tmp = Float64(Float64(1.0 * x) - Float64(fma(Float64(fma(0.008333333333333333, Float64(y * y), -0.16666666666666666) * z), Float64(y * y), z) * y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -0.125], t$95$0, If[LessEqual[y, 7.4e-9], N[(N[(1.0 * x), $MachinePrecision] - N[(N[(N[(N[(0.008333333333333333 * N[(y * y), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] * z), $MachinePrecision] * N[(y * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -0.125:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7.4 \cdot 10^{-9}:\\
\;\;\;\;1 \cdot x - \mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, y \cdot y, -0.16666666666666666\right) \cdot z, y \cdot y, z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.125 or 7.4e-9 < y Initial program 99.6%
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%
lift-pow.f64N/A
unpow-1N/A
lower-/.f6499.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6483.8
Applied rewrites83.8%
Taylor expanded in x around inf
Applied rewrites44.8%
if -0.125 < y < 7.4e-9Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Final simplification75.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z) y))) (if (<= z -2.2e+18) t_0 (if (<= z 5.2e+151) (* 1.0 x) t_0))))
double code(double x, double y, double z) {
double t_0 = -z * y;
double tmp;
if (z <= -2.2e+18) {
tmp = t_0;
} else if (z <= 5.2e+151) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = -z * y
if (z <= (-2.2d+18)) then
tmp = t_0
else if (z <= 5.2d+151) then
tmp = 1.0d0 * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -z * y;
double tmp;
if (z <= -2.2e+18) {
tmp = t_0;
} else if (z <= 5.2e+151) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -z * y tmp = 0 if z <= -2.2e+18: tmp = t_0 elif z <= 5.2e+151: tmp = 1.0 * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-z) * y) tmp = 0.0 if (z <= -2.2e+18) tmp = t_0; elseif (z <= 5.2e+151) tmp = Float64(1.0 * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -z * y; tmp = 0.0; if (z <= -2.2e+18) tmp = t_0; elseif (z <= 5.2e+151) tmp = 1.0 * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * y), $MachinePrecision]}, If[LessEqual[z, -2.2e+18], t$95$0, If[LessEqual[z, 5.2e+151], N[(1.0 * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot y\\
\mathbf{if}\;z \leq -2.2 \cdot 10^{+18}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 5.2 \cdot 10^{+151}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.2e18 or 5.20000000000000026e151 < z Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6456.3
Applied rewrites56.3%
Taylor expanded in x around 0
Applied rewrites40.4%
if -2.2e18 < z < 5.20000000000000026e151Initial program 99.9%
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%
lift-pow.f64N/A
unpow-1N/A
lower-/.f6499.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.7
Applied rewrites99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6497.4
Applied rewrites97.4%
Taylor expanded in y around 0
Applied rewrites54.5%
(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-*.f6458.8
Applied rewrites58.8%
Applied rewrites58.8%
(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-*.f6458.8
Applied rewrites58.8%
(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.6
Applied rewrites99.6%
lift-pow.f64N/A
unpow-1N/A
lower-/.f6499.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6491.6
Applied rewrites91.6%
Taylor expanded in y around 0
Applied rewrites40.5%
herbie shell --seed 2024308
(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))))