
(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 (fma x (cos y) (* z (sin y))))
double code(double x, double y, double z) {
return fma(x, cos(y), (z * sin(y)));
}
function code(x, y, z) return fma(x, cos(y), Float64(z * sin(y))) end
code[x_, y_, z_] := N[(x * N[Cos[y], $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \cos y, z \cdot \sin y\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ (* z (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return (z * sin(y)) + (x * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (z * sin(y)) + (x * cos(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.sin(y)) + (x * Math.cos(y));
}
def code(x, y, z): return (z * math.sin(y)) + (x * math.cos(y))
function code(x, y, z) return Float64(Float64(z * sin(y)) + Float64(x * cos(y))) end
function tmp = code(x, y, z) tmp = (z * sin(y)) + (x * cos(y)); end
code[x_, y_, z_] := N[(N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \sin y + x \cdot \cos y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))) (t_1 (* z (sin y))))
(if (<= y -5.5e+230)
t_0
(if (<= y -4e+207)
t_1
(if (<= y -3.2e+125)
t_0
(if (<= y -4.7e+58)
t_1
(if (<= y -7.5e+18)
t_0
(if (or (<= y -0.0245) (not (<= y 0.0025)))
t_1
(+ x (* y (+ z (* y (* x -0.5)))))))))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double t_1 = z * sin(y);
double tmp;
if (y <= -5.5e+230) {
tmp = t_0;
} else if (y <= -4e+207) {
tmp = t_1;
} else if (y <= -3.2e+125) {
tmp = t_0;
} else if (y <= -4.7e+58) {
tmp = t_1;
} else if (y <= -7.5e+18) {
tmp = t_0;
} else if ((y <= -0.0245) || !(y <= 0.0025)) {
tmp = t_1;
} else {
tmp = x + (y * (z + (y * (x * -0.5))));
}
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) :: t_1
real(8) :: tmp
t_0 = x * cos(y)
t_1 = z * sin(y)
if (y <= (-5.5d+230)) then
tmp = t_0
else if (y <= (-4d+207)) then
tmp = t_1
else if (y <= (-3.2d+125)) then
tmp = t_0
else if (y <= (-4.7d+58)) then
tmp = t_1
else if (y <= (-7.5d+18)) then
tmp = t_0
else if ((y <= (-0.0245d0)) .or. (.not. (y <= 0.0025d0))) then
tmp = t_1
else
tmp = x + (y * (z + (y * (x * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.cos(y);
double t_1 = z * Math.sin(y);
double tmp;
if (y <= -5.5e+230) {
tmp = t_0;
} else if (y <= -4e+207) {
tmp = t_1;
} else if (y <= -3.2e+125) {
tmp = t_0;
} else if (y <= -4.7e+58) {
tmp = t_1;
} else if (y <= -7.5e+18) {
tmp = t_0;
} else if ((y <= -0.0245) || !(y <= 0.0025)) {
tmp = t_1;
} else {
tmp = x + (y * (z + (y * (x * -0.5))));
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) t_1 = z * math.sin(y) tmp = 0 if y <= -5.5e+230: tmp = t_0 elif y <= -4e+207: tmp = t_1 elif y <= -3.2e+125: tmp = t_0 elif y <= -4.7e+58: tmp = t_1 elif y <= -7.5e+18: tmp = t_0 elif (y <= -0.0245) or not (y <= 0.0025): tmp = t_1 else: tmp = x + (y * (z + (y * (x * -0.5)))) return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) t_1 = Float64(z * sin(y)) tmp = 0.0 if (y <= -5.5e+230) tmp = t_0; elseif (y <= -4e+207) tmp = t_1; elseif (y <= -3.2e+125) tmp = t_0; elseif (y <= -4.7e+58) tmp = t_1; elseif (y <= -7.5e+18) tmp = t_0; elseif ((y <= -0.0245) || !(y <= 0.0025)) tmp = t_1; else tmp = Float64(x + Float64(y * Float64(z + Float64(y * Float64(x * -0.5))))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); t_1 = z * sin(y); tmp = 0.0; if (y <= -5.5e+230) tmp = t_0; elseif (y <= -4e+207) tmp = t_1; elseif (y <= -3.2e+125) tmp = t_0; elseif (y <= -4.7e+58) tmp = t_1; elseif (y <= -7.5e+18) tmp = t_0; elseif ((y <= -0.0245) || ~((y <= 0.0025))) tmp = t_1; else tmp = x + (y * (z + (y * (x * -0.5)))); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.5e+230], t$95$0, If[LessEqual[y, -4e+207], t$95$1, If[LessEqual[y, -3.2e+125], t$95$0, If[LessEqual[y, -4.7e+58], t$95$1, If[LessEqual[y, -7.5e+18], t$95$0, If[Or[LessEqual[y, -0.0245], N[Not[LessEqual[y, 0.0025]], $MachinePrecision]], t$95$1, N[(x + N[(y * N[(z + N[(y * N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
t_1 := z \cdot \sin y\\
\mathbf{if}\;y \leq -5.5 \cdot 10^{+230}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -4 \cdot 10^{+207}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -3.2 \cdot 10^{+125}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -4.7 \cdot 10^{+58}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -7.5 \cdot 10^{+18}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -0.0245 \lor \neg \left(y \leq 0.0025\right):\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z + y \cdot \left(x \cdot -0.5\right)\right)\\
\end{array}
\end{array}
if y < -5.49999999999999979e230 or -4.0000000000000002e207 < y < -3.19999999999999983e125 or -4.69999999999999972e58 < y < -7.5e18Initial program 99.7%
Taylor expanded in x around inf 76.3%
if -5.49999999999999979e230 < y < -4.0000000000000002e207 or -3.19999999999999983e125 < y < -4.69999999999999972e58 or -7.5e18 < y < -0.024500000000000001 or 0.00250000000000000005 < y Initial program 99.7%
Taylor expanded in x around 0 73.3%
if -0.024500000000000001 < y < 0.00250000000000000005Initial program 100.0%
Taylor expanded in y around 0 99.7%
associate-*r*99.7%
unpow299.7%
associate-*r*99.7%
*-commutative99.7%
distribute-rgt-out99.7%
*-commutative99.7%
Simplified99.7%
Final simplification86.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.8e-152) (not (<= z 2.5e-64))) (+ x (* z (sin y))) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e-152) || !(z <= 2.5e-64)) {
tmp = x + (z * sin(y));
} else {
tmp = x * cos(y);
}
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 ((z <= (-4.8d-152)) .or. (.not. (z <= 2.5d-64))) then
tmp = x + (z * sin(y))
else
tmp = x * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e-152) || !(z <= 2.5e-64)) {
tmp = x + (z * Math.sin(y));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.8e-152) or not (z <= 2.5e-64): tmp = x + (z * math.sin(y)) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.8e-152) || !(z <= 2.5e-64)) tmp = Float64(x + Float64(z * sin(y))); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.8e-152) || ~((z <= 2.5e-64))) tmp = x + (z * sin(y)); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.8e-152], N[Not[LessEqual[z, 2.5e-64]], $MachinePrecision]], N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{-152} \lor \neg \left(z \leq 2.5 \cdot 10^{-64}\right):\\
\;\;\;\;x + z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -4.8e-152 or 2.50000000000000017e-64 < z Initial program 99.8%
Taylor expanded in y around 0 90.1%
if -4.8e-152 < z < 2.50000000000000017e-64Initial program 99.8%
Taylor expanded in x around inf 90.1%
Final simplification90.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00205) (not (<= y 420000.0))) (* x (cos y)) (+ x (* y (+ z (* y (* x -0.5)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00205) || !(y <= 420000.0)) {
tmp = x * cos(y);
} else {
tmp = x + (y * (z + (y * (x * -0.5))));
}
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 ((y <= (-0.00205d0)) .or. (.not. (y <= 420000.0d0))) then
tmp = x * cos(y)
else
tmp = x + (y * (z + (y * (x * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00205) || !(y <= 420000.0)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * (z + (y * (x * -0.5))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00205) or not (y <= 420000.0): tmp = x * math.cos(y) else: tmp = x + (y * (z + (y * (x * -0.5)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00205) || !(y <= 420000.0)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(z + Float64(y * Float64(x * -0.5))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00205) || ~((y <= 420000.0))) tmp = x * cos(y); else tmp = x + (y * (z + (y * (x * -0.5)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00205], N[Not[LessEqual[y, 420000.0]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z + N[(y * N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00205 \lor \neg \left(y \leq 420000\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z + y \cdot \left(x \cdot -0.5\right)\right)\\
\end{array}
\end{array}
if y < -0.00205000000000000017 or 4.2e5 < y Initial program 99.7%
Taylor expanded in x around inf 45.7%
if -0.00205000000000000017 < y < 4.2e5Initial program 100.0%
Taylor expanded in y around 0 97.1%
associate-*r*97.1%
unpow297.1%
associate-*r*97.1%
*-commutative97.1%
distribute-rgt-out97.1%
*-commutative97.1%
Simplified97.1%
Final simplification71.4%
(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 51.2%
Final simplification51.2%
(FPCore (x y z) :precision binary64 (* y z))
double code(double x, double y, double z) {
return 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 = y * z
end function
public static double code(double x, double y, double z) {
return y * z;
}
def code(x, y, z): return y * z
function code(x, y, z) return Float64(y * z) end
function tmp = code(x, y, z) tmp = y * z; end
code[x_, y_, z_] := N[(y * z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 51.2%
Taylor expanded in x around 0 19.8%
Final simplification19.8%
herbie shell --seed 2023290
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))