
(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 (- (* (cos y) x) (* (sin y) z)))
double code(double x, double y, double z) {
return (cos(y) * x) - (sin(y) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (cos(y) * x) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (Math.cos(y) * x) - (Math.sin(y) * z);
}
def code(x, y, z): return (math.cos(y) * x) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(cos(y) * x) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (cos(y) * x) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos y \cdot x - \sin y \cdot z
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* 1.0 x) (* (sin y) z)))) (if (<= z -7.8e-143) t_0 (if (<= z 1.52e-99) (* (cos y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 * x) - (sin(y) * z);
double tmp;
if (z <= -7.8e-143) {
tmp = t_0;
} else if (z <= 1.52e-99) {
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) - (sin(y) * z)
if (z <= (-7.8d-143)) then
tmp = t_0
else if (z <= 1.52d-99) 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) - (Math.sin(y) * z);
double tmp;
if (z <= -7.8e-143) {
tmp = t_0;
} else if (z <= 1.52e-99) {
tmp = Math.cos(y) * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 * x) - (math.sin(y) * z) tmp = 0 if z <= -7.8e-143: tmp = t_0 elif z <= 1.52e-99: tmp = math.cos(y) * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 * x) - Float64(sin(y) * z)) tmp = 0.0 if (z <= -7.8e-143) tmp = t_0; elseif (z <= 1.52e-99) 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) - (sin(y) * z); tmp = 0.0; if (z <= -7.8e-143) tmp = t_0; elseif (z <= 1.52e-99) 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[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -7.8e-143], t$95$0, If[LessEqual[z, 1.52e-99], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 \cdot x - \sin y \cdot z\\
\mathbf{if}\;z \leq -7.8 \cdot 10^{-143}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.52 \cdot 10^{-99}:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -7.80000000000000007e-143 or 1.51999999999999999e-99 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites85.6%
if -7.80000000000000007e-143 < z < 1.51999999999999999e-99Initial 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
+-commutativeN/A
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/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 rewrites94.8%
Final simplification88.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -1.65e+171)
t_0
(if (<= y -0.84)
(* (- z) (sin y))
(if (<= y 8e-20)
(-
(*
(fma
(fma
(fma -0.001388888888888889 (* y y) 0.041666666666666664)
(* y y)
-0.5)
(* y y)
1.0)
x)
(* (* (fma -0.16666666666666666 (* y y) 1.0) z) y))
t_0)))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -1.65e+171) {
tmp = t_0;
} else if (y <= -0.84) {
tmp = -z * sin(y);
} else if (y <= 8e-20) {
tmp = (fma(fma(fma(-0.001388888888888889, (y * y), 0.041666666666666664), (y * y), -0.5), (y * y), 1.0) * x) - ((fma(-0.16666666666666666, (y * y), 1.0) * z) * y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (y <= -1.65e+171) tmp = t_0; elseif (y <= -0.84) tmp = Float64(Float64(-z) * sin(y)); elseif (y <= 8e-20) tmp = Float64(Float64(fma(fma(fma(-0.001388888888888889, Float64(y * y), 0.041666666666666664), Float64(y * y), -0.5), Float64(y * y), 1.0) * x) - Float64(Float64(fma(-0.16666666666666666, Float64(y * y), 1.0) * 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, -1.65e+171], t$95$0, If[LessEqual[y, -0.84], N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8e-20], N[(N[(N[(N[(N[(-0.001388888888888889 * N[(y * y), $MachinePrecision] + 0.041666666666666664), $MachinePrecision] * N[(y * y), $MachinePrecision] + -0.5), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision] - N[(N[(N[(-0.16666666666666666 * N[(y * y), $MachinePrecision] + 1.0), $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 -1.65 \cdot 10^{+171}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.84:\\
\;\;\;\;\left(-z\right) \cdot \sin y\\
\mathbf{elif}\;y \leq 8 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, y \cdot y, 0.041666666666666664\right), y \cdot y, -0.5\right), y \cdot y, 1\right) \cdot x - \left(\mathsf{fma}\left(-0.16666666666666666, y \cdot y, 1\right) \cdot z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.64999999999999996e171 or 7.99999999999999956e-20 < 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.6
Applied rewrites99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6492.0
Applied rewrites92.0%
Taylor expanded in x around inf
Applied rewrites64.5%
if -1.64999999999999996e171 < y < -0.839999999999999969Initial program 99.6%
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.6
Applied rewrites60.6%
if -0.839999999999999969 < y < 7.99999999999999956e-20Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites98.5%
Taylor expanded in y around 0
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*r*N/A
*-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6498.5
Applied rewrites98.5%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.2
Applied rewrites99.2%
Final simplification81.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (cos y) x))) (if (<= y -2.75e-5) t_0 (if (<= y 8e-20) (fma (- z) y x) t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -2.75e-5) {
tmp = t_0;
} else if (y <= 8e-20) {
tmp = fma(-z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (y <= -2.75e-5) tmp = t_0; elseif (y <= 8e-20) tmp = fma(Float64(-z), y, x); 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, -2.75e-5], t$95$0, If[LessEqual[y, 8e-20], N[((-z) * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -2.75 \cdot 10^{-5}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.7500000000000001e-5 or 7.99999999999999956e-20 < 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.6
Applied rewrites99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6489.4
Applied rewrites89.4%
Taylor expanded in x around inf
Applied rewrites57.3%
if -2.7500000000000001e-5 < y < 7.99999999999999956e-20Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.07e-192) (* 1.0 x) (if (<= x 8.5e-220) (* (- z) y) (* 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.07e-192) {
tmp = 1.0 * x;
} else if (x <= 8.5e-220) {
tmp = -z * y;
} 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 (x <= (-1.07d-192)) then
tmp = 1.0d0 * x
else if (x <= 8.5d-220) then
tmp = -z * y
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.07e-192) {
tmp = 1.0 * x;
} else if (x <= 8.5e-220) {
tmp = -z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.07e-192: tmp = 1.0 * x elif x <= 8.5e-220: tmp = -z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.07e-192) tmp = Float64(1.0 * x); elseif (x <= 8.5e-220) tmp = Float64(Float64(-z) * y); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.07e-192) tmp = 1.0 * x; elseif (x <= 8.5e-220) tmp = -z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.07e-192], N[(1.0 * x), $MachinePrecision], If[LessEqual[x, 8.5e-220], N[((-z) * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.07 \cdot 10^{-192}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;x \leq 8.5 \cdot 10^{-220}:\\
\;\;\;\;\left(-z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if x < -1.07e-192 or 8.4999999999999996e-220 < 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
+-commutativeN/A
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6498.0
Applied rewrites98.0%
Taylor expanded in y around 0
Applied rewrites47.1%
if -1.07e-192 < x < 8.4999999999999996e-220Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6450.4
Applied rewrites50.4%
Taylor expanded in x around 0
Applied rewrites41.9%
(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-*.f6454.0
Applied rewrites54.0%
Applied rewrites54.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-*.f6454.0
Applied rewrites54.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
+-commutativeN/A
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6492.7
Applied rewrites92.7%
Taylor expanded in y around 0
Applied rewrites40.7%
herbie shell --seed 2024332
(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))))