
(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-define99.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))))
(if (<= y -0.002)
t_0
(if (<= y 0.0115)
(+ x (* y (+ z (* -0.5 (* x y)))))
(if (or (<= y 1.05e+71) (and (not (<= y 5.6e+248)) (<= y 2.4e+287)))
t_0
(* z (sin y)))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.002) {
tmp = t_0;
} else if (y <= 0.0115) {
tmp = x + (y * (z + (-0.5 * (x * y))));
} else if ((y <= 1.05e+71) || (!(y <= 5.6e+248) && (y <= 2.4e+287))) {
tmp = t_0;
} else {
tmp = z * sin(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) :: t_0
real(8) :: tmp
t_0 = x * cos(y)
if (y <= (-0.002d0)) then
tmp = t_0
else if (y <= 0.0115d0) then
tmp = x + (y * (z + ((-0.5d0) * (x * y))))
else if ((y <= 1.05d+71) .or. (.not. (y <= 5.6d+248)) .and. (y <= 2.4d+287)) then
tmp = t_0
else
tmp = z * sin(y)
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.002) {
tmp = t_0;
} else if (y <= 0.0115) {
tmp = x + (y * (z + (-0.5 * (x * y))));
} else if ((y <= 1.05e+71) || (!(y <= 5.6e+248) && (y <= 2.4e+287))) {
tmp = t_0;
} else {
tmp = z * Math.sin(y);
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if y <= -0.002: tmp = t_0 elif y <= 0.0115: tmp = x + (y * (z + (-0.5 * (x * y)))) elif (y <= 1.05e+71) or (not (y <= 5.6e+248) and (y <= 2.4e+287)): tmp = t_0 else: tmp = z * math.sin(y) return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.002) tmp = t_0; elseif (y <= 0.0115) tmp = Float64(x + Float64(y * Float64(z + Float64(-0.5 * Float64(x * y))))); elseif ((y <= 1.05e+71) || (!(y <= 5.6e+248) && (y <= 2.4e+287))) tmp = t_0; else tmp = Float64(z * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (y <= -0.002) tmp = t_0; elseif (y <= 0.0115) tmp = x + (y * (z + (-0.5 * (x * y)))); elseif ((y <= 1.05e+71) || (~((y <= 5.6e+248)) && (y <= 2.4e+287))) tmp = t_0; else tmp = z * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.002], t$95$0, If[LessEqual[y, 0.0115], N[(x + N[(y * N[(z + N[(-0.5 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.05e+71], And[N[Not[LessEqual[y, 5.6e+248]], $MachinePrecision], LessEqual[y, 2.4e+287]]], t$95$0, N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.002:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0115:\\
\;\;\;\;x + y \cdot \left(z + -0.5 \cdot \left(x \cdot y\right)\right)\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{+71} \lor \neg \left(y \leq 5.6 \cdot 10^{+248}\right) \land y \leq 2.4 \cdot 10^{+287}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \sin y\\
\end{array}
\end{array}
if y < -2e-3 or 0.0115 < y < 1.04999999999999995e71 or 5.6000000000000004e248 < y < 2.3999999999999999e287Initial program 99.6%
Taylor expanded in x around inf 69.9%
if -2e-3 < y < 0.0115Initial program 100.0%
Taylor expanded in y around 0 100.0%
*-commutative100.0%
Simplified100.0%
if 1.04999999999999995e71 < y < 5.6000000000000004e248 or 2.3999999999999999e287 < y Initial program 99.5%
Taylor expanded in x around 0 72.6%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.002) (not (<= y 0.0185))) (* x (cos y)) (+ x (* y (+ z (* -0.5 (* x y)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.002) || !(y <= 0.0185)) {
tmp = x * cos(y);
} else {
tmp = x + (y * (z + (-0.5 * (x * 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 ((y <= (-0.002d0)) .or. (.not. (y <= 0.0185d0))) then
tmp = x * cos(y)
else
tmp = x + (y * (z + ((-0.5d0) * (x * y))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.002) || !(y <= 0.0185)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * (z + (-0.5 * (x * y))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.002) or not (y <= 0.0185): tmp = x * math.cos(y) else: tmp = x + (y * (z + (-0.5 * (x * y)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.002) || !(y <= 0.0185)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(z + Float64(-0.5 * Float64(x * y))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.002) || ~((y <= 0.0185))) tmp = x * cos(y); else tmp = x + (y * (z + (-0.5 * (x * y)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.002], N[Not[LessEqual[y, 0.0185]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z + N[(-0.5 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.002 \lor \neg \left(y \leq 0.0185\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z + -0.5 \cdot \left(x \cdot y\right)\right)\\
\end{array}
\end{array}
if y < -2e-3 or 0.0184999999999999991 < y Initial program 99.5%
Taylor expanded in x around inf 56.3%
if -2e-3 < y < 0.0184999999999999991Initial program 100.0%
Taylor expanded in y around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (<= z 3e+63) x (* y z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 3e+63) {
tmp = x;
} else {
tmp = y * z;
}
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 <= 3d+63) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 3e+63) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 3e+63: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 3e+63) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 3e+63) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 3e+63], x, N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3 \cdot 10^{+63}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < 2.99999999999999999e63Initial program 99.8%
Taylor expanded in z around inf 86.5%
associate-/l*85.9%
Simplified85.9%
Taylor expanded in y around 0 46.0%
if 2.99999999999999999e63 < z Initial program 99.7%
Taylor expanded in x around 0 70.7%
Taylor expanded in y around 0 41.6%
Final simplification45.1%
(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 54.4%
+-commutative54.4%
Simplified54.4%
Final simplification54.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 z around inf 89.2%
associate-/l*88.7%
Simplified88.7%
Taylor expanded in y around 0 40.9%
Final simplification40.9%
herbie shell --seed 2024059
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))