
(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 (cos y) x (* (sin y) (- z))))
double code(double x, double y, double z) {
return fma(cos(y), x, (sin(y) * -z));
}
function code(x, y, z) return fma(cos(y), x, Float64(sin(y) * Float64(-z))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, \sin y \cdot \left(-z\right)\right)
\end{array}
Initial program 99.8%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- (* (cos y) x) (* z (sin y))))
double code(double x, double y, double z) {
return (cos(y) * x) - (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 = (cos(y) * x) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (Math.cos(y) * x) - (z * Math.sin(y));
}
def code(x, y, z): return (math.cos(y) * x) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(cos(y) * x) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (cos(y) * x) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos y \cdot x - z \cdot \sin y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= z -5.2e-124) (fma (sin y) (- z) (* x 1.0)) (if (<= z 1.45e-130) (* (cos y) x) (- (* x 1.0) (* z (sin y))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.2e-124) {
tmp = fma(sin(y), -z, (x * 1.0));
} else if (z <= 1.45e-130) {
tmp = cos(y) * x;
} else {
tmp = (x * 1.0) - (z * sin(y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -5.2e-124) tmp = fma(sin(y), Float64(-z), Float64(x * 1.0)); elseif (z <= 1.45e-130) tmp = Float64(cos(y) * x); else tmp = Float64(Float64(x * 1.0) - Float64(z * sin(y))); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -5.2e-124], N[(N[Sin[y], $MachinePrecision] * (-z) + N[(x * 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.45e-130], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[(x * 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{-124}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, -z, x \cdot 1\right)\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{-130}:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1 - z \cdot \sin y\\
\end{array}
\end{array}
if z < -5.1999999999999999e-124Initial 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
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites87.8%
if -5.1999999999999999e-124 < z < 1.45e-130Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6493.2
Applied rewrites93.2%
if 1.45e-130 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites89.0%
Final simplification89.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* x 1.0) (* z (sin y))))) (if (<= z -5.2e-124) t_0 (if (<= z 1.45e-130) (* (cos y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = (x * 1.0) - (z * sin(y));
double tmp;
if (z <= -5.2e-124) {
tmp = t_0;
} else if (z <= 1.45e-130) {
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 = (x * 1.0d0) - (z * sin(y))
if (z <= (-5.2d-124)) then
tmp = t_0
else if (z <= 1.45d-130) 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 = (x * 1.0) - (z * Math.sin(y));
double tmp;
if (z <= -5.2e-124) {
tmp = t_0;
} else if (z <= 1.45e-130) {
tmp = Math.cos(y) * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * 1.0) - (z * math.sin(y)) tmp = 0 if z <= -5.2e-124: tmp = t_0 elif z <= 1.45e-130: tmp = math.cos(y) * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * 1.0) - Float64(z * sin(y))) tmp = 0.0 if (z <= -5.2e-124) tmp = t_0; elseif (z <= 1.45e-130) tmp = Float64(cos(y) * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * 1.0) - (z * sin(y)); tmp = 0.0; if (z <= -5.2e-124) tmp = t_0; elseif (z <= 1.45e-130) tmp = cos(y) * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -5.2e-124], t$95$0, If[LessEqual[z, 1.45e-130], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot 1 - z \cdot \sin y\\
\mathbf{if}\;z \leq -5.2 \cdot 10^{-124}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{-130}:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.1999999999999999e-124 or 1.45e-130 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites88.4%
if -5.1999999999999999e-124 < z < 1.45e-130Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6493.2
Applied rewrites93.2%
Final simplification89.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -3e+116)
t_0
(if (<= y -27000000000.0)
(* (sin y) (- z))
(if (<= y 3.3e-7)
(fma
(fma
(* y (* y y))
(fma
(* y y)
(fma (* y y) -0.0001984126984126984 0.008333333333333333)
-0.16666666666666666)
y)
(- z)
(* x 1.0))
t_0)))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -3e+116) {
tmp = t_0;
} else if (y <= -27000000000.0) {
tmp = sin(y) * -z;
} else if (y <= 3.3e-7) {
tmp = fma(fma((y * (y * y)), fma((y * y), fma((y * y), -0.0001984126984126984, 0.008333333333333333), -0.16666666666666666), y), -z, (x * 1.0));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (y <= -3e+116) tmp = t_0; elseif (y <= -27000000000.0) tmp = Float64(sin(y) * Float64(-z)); elseif (y <= 3.3e-7) tmp = fma(fma(Float64(y * Float64(y * y)), fma(Float64(y * y), fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333), -0.16666666666666666), y), Float64(-z), Float64(x * 1.0)); 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, -3e+116], t$95$0, If[LessEqual[y, -27000000000.0], N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision], If[LessEqual[y, 3.3e-7], N[(N[(N[(y * N[(y * y), $MachinePrecision]), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] + y), $MachinePrecision] * (-z) + N[(x * 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -3 \cdot 10^{+116}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -27000000000:\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot \left(y \cdot y\right), \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right), y\right), -z, x \cdot 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.9999999999999999e116 or 3.3000000000000002e-7 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6455.8
Applied rewrites55.8%
if -2.9999999999999999e116 < y < -2.7e10Initial program 99.7%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-sin.f6478.7
Applied rewrites78.7%
if -2.7e10 < y < 3.3000000000000002e-7Initial program 100.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites98.8%
Taylor expanded in y around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
unpow2N/A
cube-multN/A
*-rgt-identityN/A
lower-fma.f64N/A
Applied rewrites98.8%
Final simplification79.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -1.5)
t_0
(if (<= y 3.3e-7)
(fma
(fma
(* y (* y y))
(fma
(* y y)
(fma (* y y) -0.0001984126984126984 0.008333333333333333)
-0.16666666666666666)
y)
(- z)
(* x 1.0))
t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -1.5) {
tmp = t_0;
} else if (y <= 3.3e-7) {
tmp = fma(fma((y * (y * y)), fma((y * y), fma((y * y), -0.0001984126984126984, 0.008333333333333333), -0.16666666666666666), y), -z, (x * 1.0));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (y <= -1.5) tmp = t_0; elseif (y <= 3.3e-7) tmp = fma(fma(Float64(y * Float64(y * y)), fma(Float64(y * y), fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333), -0.16666666666666666), y), Float64(-z), Float64(x * 1.0)); 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.5], t$95$0, If[LessEqual[y, 3.3e-7], N[(N[(N[(y * N[(y * y), $MachinePrecision]), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] + y), $MachinePrecision] * (-z) + N[(x * 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -1.5:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot \left(y \cdot y\right), \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right), y\right), -z, x \cdot 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.5 or 3.3000000000000002e-7 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6450.0
Applied rewrites50.0%
if -1.5 < y < 3.3000000000000002e-7Initial program 100.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites100.0%
Taylor expanded in y around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
unpow2N/A
cube-multN/A
*-rgt-identityN/A
lower-fma.f64N/A
Applied rewrites100.0%
Final simplification75.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- z)))) (if (<= z -2.8e+237) t_0 (if (<= z 2e+217) (* x 1.0) t_0))))
double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (z <= -2.8e+237) {
tmp = t_0;
} else if (z <= 2e+217) {
tmp = x * 1.0;
} 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 = y * -z
if (z <= (-2.8d+237)) then
tmp = t_0
else if (z <= 2d+217) then
tmp = x * 1.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (z <= -2.8e+237) {
tmp = t_0;
} else if (z <= 2e+217) {
tmp = x * 1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -z tmp = 0 if z <= -2.8e+237: tmp = t_0 elif z <= 2e+217: tmp = x * 1.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-z)) tmp = 0.0 if (z <= -2.8e+237) tmp = t_0; elseif (z <= 2e+217) tmp = Float64(x * 1.0); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -z; tmp = 0.0; if (z <= -2.8e+237) tmp = t_0; elseif (z <= 2e+217) tmp = x * 1.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[z, -2.8e+237], t$95$0, If[LessEqual[z, 2e+217], N[(x * 1.0), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -2.8 \cdot 10^{+237}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2 \cdot 10^{+217}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.79999999999999983e237 or 1.99999999999999992e217 < z Initial program 99.9%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6465.8
Applied rewrites65.8%
Taylor expanded in x around 0
Applied rewrites50.8%
if -2.79999999999999983e237 < z < 1.99999999999999992e217Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6468.1
Applied rewrites68.1%
Taylor expanded in y around 0
Applied rewrites44.2%
(FPCore (x y z) :precision binary64 (- x (* y z)))
double code(double x, double y, double z) {
return x - (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 = x - (y * z)
end function
public static double code(double x, double y, double z) {
return x - (y * z);
}
def code(x, y, z): return x - (y * z)
function code(x, y, z) return Float64(x - Float64(y * z)) end
function tmp = code(x, y, z) tmp = x - (y * z); end
code[x_, y_, z_] := N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - y \cdot z
\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-*.f6453.7
Applied rewrites53.7%
Final simplification53.7%
(FPCore (x y z) :precision binary64 (* x 1.0))
double code(double x, double y, double z) {
return x * 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * 1.0d0
end function
public static double code(double x, double y, double z) {
return x * 1.0;
}
def code(x, y, z): return x * 1.0
function code(x, y, z) return Float64(x * 1.0) end
function tmp = code(x, y, z) tmp = x * 1.0; end
code[x_, y_, z_] := N[(x * 1.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 1
\end{array}
Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6460.6
Applied rewrites60.6%
Taylor expanded in y around 0
Applied rewrites40.2%
herbie shell --seed 2024223
(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))))