
(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 (let* ((t_0 (- x (* z (sin y))))) (if (<= z -1.02e-69) t_0 (if (<= z 2.9e-102) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (z * sin(y));
double tmp;
if (z <= -1.02e-69) {
tmp = t_0;
} else if (z <= 2.9e-102) {
tmp = x * cos(y);
} 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 - (z * sin(y))
if (z <= (-1.02d-69)) then
tmp = t_0
else if (z <= 2.9d-102) then
tmp = x * cos(y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x - (z * Math.sin(y));
double tmp;
if (z <= -1.02e-69) {
tmp = t_0;
} else if (z <= 2.9e-102) {
tmp = x * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (z * math.sin(y)) tmp = 0 if z <= -1.02e-69: tmp = t_0 elif z <= 2.9e-102: tmp = x * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x - Float64(z * sin(y))) tmp = 0.0 if (z <= -1.02e-69) tmp = t_0; elseif (z <= 2.9e-102) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x - (z * sin(y)); tmp = 0.0; if (z <= -1.02e-69) tmp = t_0; elseif (z <= 2.9e-102) tmp = x * cos(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.02e-69], t$95$0, If[LessEqual[z, 2.9e-102], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - z \cdot \sin y\\
\mathbf{if}\;z \leq -1.02 \cdot 10^{-69}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.9 \cdot 10^{-102}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.02000000000000005e-69 or 2.89999999999999986e-102 < z Initial program 99.7%
Taylor expanded in y around 0
Simplified83.5%
if -1.02000000000000005e-69 < z < 2.89999999999999986e-102Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6491.6
Simplified91.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (cos y)))) (if (<= x -1.7e-28) t_0 (if (<= x 1.4e-152) (* (sin y) (- z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -1.7e-28) {
tmp = t_0;
} else if (x <= 1.4e-152) {
tmp = sin(y) * -z;
} 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 * cos(y)
if (x <= (-1.7d-28)) then
tmp = t_0
else if (x <= 1.4d-152) then
tmp = sin(y) * -z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.cos(y);
double tmp;
if (x <= -1.7e-28) {
tmp = t_0;
} else if (x <= 1.4e-152) {
tmp = Math.sin(y) * -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if x <= -1.7e-28: tmp = t_0 elif x <= 1.4e-152: tmp = math.sin(y) * -z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (x <= -1.7e-28) tmp = t_0; elseif (x <= 1.4e-152) tmp = Float64(sin(y) * Float64(-z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (x <= -1.7e-28) tmp = t_0; elseif (x <= 1.4e-152) tmp = sin(y) * -z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.7e-28], t$95$0, If[LessEqual[x, 1.4e-152], N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -1.7 \cdot 10^{-28}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{-152}:\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.7e-28 or 1.39999999999999992e-152 < x Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6480.3
Simplified80.3%
if -1.7e-28 < x < 1.39999999999999992e-152Initial program 99.7%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6474.6
Simplified74.6%
Final simplification78.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -740.0)
t_0
(if (<= y 0.11)
(-
x
(*
z
(fma
(* y y)
(*
y
(fma
(* y y)
(fma (* y y) -0.0001984126984126984 0.008333333333333333)
-0.16666666666666666))
y)))
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -740.0) {
tmp = t_0;
} else if (y <= 0.11) {
tmp = x - (z * fma((y * y), (y * fma((y * y), fma((y * y), -0.0001984126984126984, 0.008333333333333333), -0.16666666666666666)), y));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -740.0) tmp = t_0; elseif (y <= 0.11) tmp = Float64(x - Float64(z * fma(Float64(y * y), Float64(y * fma(Float64(y * y), fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333), -0.16666666666666666)), y))); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -740.0], t$95$0, If[LessEqual[y, 0.11], N[(x - N[(z * N[(N[(y * y), $MachinePrecision] * N[(y * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision] + -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -740:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.11:\\
\;\;\;\;x - z \cdot \mathsf{fma}\left(y \cdot y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right), y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -740 or 0.110000000000000001 < y Initial program 99.5%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6453.5
Simplified53.5%
if -740 < y < 0.110000000000000001Initial program 100.0%
Taylor expanded in y around 0
Simplified100.0%
Taylor expanded in y around 0
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
Simplified98.8%
Final simplification75.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* y z)))) (if (<= z -1.5e+186) t_0 (if (<= z 4.4e+135) x t_0))))
double code(double x, double y, double z) {
double t_0 = -(y * z);
double tmp;
if (z <= -1.5e+186) {
tmp = t_0;
} else if (z <= 4.4e+135) {
tmp = 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 = -(y * z)
if (z <= (-1.5d+186)) then
tmp = t_0
else if (z <= 4.4d+135) then
tmp = x
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 <= -1.5e+186) {
tmp = t_0;
} else if (z <= 4.4e+135) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -(y * z) tmp = 0 if z <= -1.5e+186: tmp = t_0 elif z <= 4.4e+135: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(-Float64(y * z)) tmp = 0.0 if (z <= -1.5e+186) tmp = t_0; elseif (z <= 4.4e+135) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -(y * z); tmp = 0.0; if (z <= -1.5e+186) tmp = t_0; elseif (z <= 4.4e+135) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(y * z), $MachinePrecision])}, If[LessEqual[z, -1.5e+186], t$95$0, If[LessEqual[z, 4.4e+135], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -y \cdot z\\
\mathbf{if}\;z \leq -1.5 \cdot 10^{+186}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4.4 \cdot 10^{+135}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.49999999999999991e186 or 4.3999999999999999e135 < z Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
sub-negN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
neg-lowering-neg.f6448.3
Simplified48.3%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6449.5
Simplified49.5%
Taylor expanded in y around inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6435.0
Simplified35.0%
if -1.49999999999999991e186 < z < 4.3999999999999999e135Initial program 99.7%
Taylor expanded in y around 0
Simplified45.3%
Final simplification42.8%
(FPCore (x y z) :precision binary64 (fma y (- z) x))
double code(double x, double y, double z) {
return fma(y, -z, x);
}
function code(x, y, z) return fma(y, Float64(-z), x) end
code[x_, y_, z_] := N[(y * (-z) + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, -z, x\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
sub-negN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
neg-lowering-neg.f6449.5
Simplified49.5%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6451.3
Simplified51.3%
(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
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f6451.3
Simplified51.3%
Final simplification51.3%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
Simplified38.4%
herbie shell --seed 2024198
(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))))