
(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 7 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 (cos y)))) (if (<= x -9.5e+122) t_0 (if (<= x 1.9e+74) (- x (* z (sin y))) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -9.5e+122) {
tmp = t_0;
} else if (x <= 1.9e+74) {
tmp = x - (z * sin(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 * cos(y)
if (x <= (-9.5d+122)) then
tmp = t_0
else if (x <= 1.9d+74) then
tmp = x - (z * sin(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 * Math.cos(y);
double tmp;
if (x <= -9.5e+122) {
tmp = t_0;
} else if (x <= 1.9e+74) {
tmp = x - (z * Math.sin(y));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if x <= -9.5e+122: tmp = t_0 elif x <= 1.9e+74: tmp = x - (z * math.sin(y)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (x <= -9.5e+122) tmp = t_0; elseif (x <= 1.9e+74) tmp = Float64(x - Float64(z * sin(y))); 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 <= -9.5e+122) tmp = t_0; elseif (x <= 1.9e+74) tmp = x - (z * sin(y)); 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, -9.5e+122], t$95$0, If[LessEqual[x, 1.9e+74], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -9.5 \cdot 10^{+122}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{+74}:\\
\;\;\;\;x - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -9.49999999999999986e122 or 1.8999999999999999e74 < x Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6490.4%
Simplified90.4%
if -9.49999999999999986e122 < x < 1.8999999999999999e74Initial program 99.8%
Taylor expanded in y around 0
Simplified86.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (cos y)))) (if (<= x -1.86e-115) t_0 (if (<= x 8.2e-80) (* z (- 0.0 (sin y))) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -1.86e-115) {
tmp = t_0;
} else if (x <= 8.2e-80) {
tmp = z * (0.0 - sin(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 * cos(y)
if (x <= (-1.86d-115)) then
tmp = t_0
else if (x <= 8.2d-80) then
tmp = z * (0.0d0 - sin(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 * Math.cos(y);
double tmp;
if (x <= -1.86e-115) {
tmp = t_0;
} else if (x <= 8.2e-80) {
tmp = z * (0.0 - Math.sin(y));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if x <= -1.86e-115: tmp = t_0 elif x <= 8.2e-80: tmp = z * (0.0 - math.sin(y)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (x <= -1.86e-115) tmp = t_0; elseif (x <= 8.2e-80) tmp = Float64(z * Float64(0.0 - sin(y))); 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.86e-115) tmp = t_0; elseif (x <= 8.2e-80) tmp = z * (0.0 - sin(y)); 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.86e-115], t$95$0, If[LessEqual[x, 8.2e-80], N[(z * N[(0.0 - N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -1.86 \cdot 10^{-115}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 8.2 \cdot 10^{-80}:\\
\;\;\;\;z \cdot \left(0 - \sin y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.86e-115 or 8.1999999999999999e-80 < x Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6476.5%
Simplified76.5%
if -1.86e-115 < x < 8.1999999999999999e-80Initial program 99.8%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6480.7%
Simplified80.7%
Final simplification77.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.038)
t_0
(if (<= y 0.34)
(-
x
(*
y
(+
z
(*
(* z (* y y))
(+
-0.16666666666666666
(*
(* y y)
(+ 0.008333333333333333 (* (* y y) -0.0001984126984126984))))))))
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.038) {
tmp = t_0;
} else if (y <= 0.34) {
tmp = x - (y * (z + ((z * (y * y)) * (-0.16666666666666666 + ((y * y) * (0.008333333333333333 + ((y * y) * -0.0001984126984126984)))))));
} 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 (y <= (-0.038d0)) then
tmp = t_0
else if (y <= 0.34d0) then
tmp = x - (y * (z + ((z * (y * y)) * ((-0.16666666666666666d0) + ((y * y) * (0.008333333333333333d0 + ((y * y) * (-0.0001984126984126984d0))))))))
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 (y <= -0.038) {
tmp = t_0;
} else if (y <= 0.34) {
tmp = x - (y * (z + ((z * (y * y)) * (-0.16666666666666666 + ((y * y) * (0.008333333333333333 + ((y * y) * -0.0001984126984126984)))))));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if y <= -0.038: tmp = t_0 elif y <= 0.34: tmp = x - (y * (z + ((z * (y * y)) * (-0.16666666666666666 + ((y * y) * (0.008333333333333333 + ((y * y) * -0.0001984126984126984))))))) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.038) tmp = t_0; elseif (y <= 0.34) tmp = Float64(x - Float64(y * Float64(z + Float64(Float64(z * Float64(y * y)) * Float64(-0.16666666666666666 + Float64(Float64(y * y) * Float64(0.008333333333333333 + Float64(Float64(y * y) * -0.0001984126984126984)))))))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (y <= -0.038) tmp = t_0; elseif (y <= 0.34) tmp = x - (y * (z + ((z * (y * y)) * (-0.16666666666666666 + ((y * y) * (0.008333333333333333 + ((y * y) * -0.0001984126984126984))))))); 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[y, -0.038], t$95$0, If[LessEqual[y, 0.34], N[(x - N[(y * N[(z + N[(N[(z * N[(y * y), $MachinePrecision]), $MachinePrecision] * N[(-0.16666666666666666 + N[(N[(y * y), $MachinePrecision] * N[(0.008333333333333333 + N[(N[(y * y), $MachinePrecision] * -0.0001984126984126984), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.038:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.34:\\
\;\;\;\;x - y \cdot \left(z + \left(z \cdot \left(y \cdot y\right)\right) \cdot \left(-0.16666666666666666 + \left(y \cdot y\right) \cdot \left(0.008333333333333333 + \left(y \cdot y\right) \cdot -0.0001984126984126984\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.0379999999999999991 or 0.340000000000000024 < y Initial program 99.6%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6449.8%
Simplified49.8%
if -0.0379999999999999991 < y < 0.340000000000000024Initial program 100.0%
Taylor expanded in y around 0
Simplified99.8%
Taylor expanded in y around 0
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
associate-*r*N/A
distribute-rgt-outN/A
+-commutativeN/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
Simplified99.8%
Taylor expanded in y around 0
+-commutativeN/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
metadata-evalN/A
sub-negN/A
associate-*r*N/A
*-lowering-*.f64N/A
Simplified99.8%
(FPCore (x y z) :precision binary64 (if (<= x -1.45e-123) x (if (<= x 1.2e-138) (* z (- 0.0 y)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.45e-123) {
tmp = x;
} else if (x <= 1.2e-138) {
tmp = z * (0.0 - y);
} else {
tmp = 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.45d-123)) then
tmp = x
else if (x <= 1.2d-138) then
tmp = z * (0.0d0 - y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.45e-123) {
tmp = x;
} else if (x <= 1.2e-138) {
tmp = z * (0.0 - y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.45e-123: tmp = x elif x <= 1.2e-138: tmp = z * (0.0 - y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.45e-123) tmp = x; elseif (x <= 1.2e-138) tmp = Float64(z * Float64(0.0 - y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.45e-123) tmp = x; elseif (x <= 1.2e-138) tmp = z * (0.0 - y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.45e-123], x, If[LessEqual[x, 1.2e-138], N[(z * N[(0.0 - y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-123}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-138}:\\
\;\;\;\;z \cdot \left(0 - y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.45000000000000002e-123 or 1.2e-138 < x Initial program 99.8%
Taylor expanded in y around 0
Simplified45.1%
if -1.45000000000000002e-123 < x < 1.2e-138Initial program 99.9%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f6456.7%
Simplified56.7%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f6443.8%
Simplified43.8%
sub0-negN/A
neg-lowering-neg.f64N/A
*-commutativeN/A
*-lowering-*.f6443.8%
Applied egg-rr43.8%
Final simplification44.8%
(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-*.f6452.4%
Simplified52.4%
Final simplification52.4%
(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
Simplified37.9%
herbie shell --seed 2024155
(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))))