
(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.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (sin y))) (t_1 (* x (cos y))))
(if (<= y -8.4e+160)
t_0
(if (<= y 1.35e+81) (+ t_1 (* y z)) (if (<= y 2.05e+161) t_0 t_1)))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double t_1 = x * cos(y);
double tmp;
if (y <= -8.4e+160) {
tmp = t_0;
} else if (y <= 1.35e+81) {
tmp = t_1 + (y * z);
} else if (y <= 2.05e+161) {
tmp = t_0;
} else {
tmp = t_1;
}
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 = z * sin(y)
t_1 = x * cos(y)
if (y <= (-8.4d+160)) then
tmp = t_0
else if (y <= 1.35d+81) then
tmp = t_1 + (y * z)
else if (y <= 2.05d+161) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.sin(y);
double t_1 = x * Math.cos(y);
double tmp;
if (y <= -8.4e+160) {
tmp = t_0;
} else if (y <= 1.35e+81) {
tmp = t_1 + (y * z);
} else if (y <= 2.05e+161) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.sin(y) t_1 = x * math.cos(y) tmp = 0 if y <= -8.4e+160: tmp = t_0 elif y <= 1.35e+81: tmp = t_1 + (y * z) elif y <= 2.05e+161: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(z * sin(y)) t_1 = Float64(x * cos(y)) tmp = 0.0 if (y <= -8.4e+160) tmp = t_0; elseif (y <= 1.35e+81) tmp = Float64(t_1 + Float64(y * z)); elseif (y <= 2.05e+161) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * sin(y); t_1 = x * cos(y); tmp = 0.0; if (y <= -8.4e+160) tmp = t_0; elseif (y <= 1.35e+81) tmp = t_1 + (y * z); elseif (y <= 2.05e+161) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8.4e+160], t$95$0, If[LessEqual[y, 1.35e+81], N[(t$95$1 + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.05e+161], t$95$0, t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
t_1 := x \cdot \cos y\\
\mathbf{if}\;y \leq -8.4 \cdot 10^{+160}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{+81}:\\
\;\;\;\;t\_1 + y \cdot z\\
\mathbf{elif}\;y \leq 2.05 \cdot 10^{+161}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -8.39999999999999987e160 or 1.35e81 < y < 2.0500000000000001e161Initial program 99.7%
Taylor expanded in x around 0 66.4%
if -8.39999999999999987e160 < y < 1.35e81Initial program 99.9%
Taylor expanded in y around 0 90.2%
if 2.0500000000000001e161 < y Initial program 99.8%
Taylor expanded in x around inf 75.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.2e-109) (not (<= x 6.8e-52))) (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.2e-109) || !(x <= 6.8e-52)) {
tmp = x * cos(y);
} 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) :: tmp
if ((x <= (-4.2d-109)) .or. (.not. (x <= 6.8d-52))) then
tmp = x * cos(y)
else
tmp = z * sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.2e-109) || !(x <= 6.8e-52)) {
tmp = x * Math.cos(y);
} else {
tmp = z * Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.2e-109) or not (x <= 6.8e-52): tmp = x * math.cos(y) else: tmp = z * math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.2e-109) || !(x <= 6.8e-52)) tmp = Float64(x * cos(y)); else tmp = Float64(z * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.2e-109) || ~((x <= 6.8e-52))) tmp = x * cos(y); else tmp = z * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.2e-109], N[Not[LessEqual[x, 6.8e-52]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{-109} \lor \neg \left(x \leq 6.8 \cdot 10^{-52}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \sin y\\
\end{array}
\end{array}
if x < -4.19999999999999992e-109 or 6.80000000000000035e-52 < x Initial program 99.9%
Taylor expanded in x around inf 85.0%
if -4.19999999999999992e-109 < x < 6.80000000000000035e-52Initial program 99.9%
Taylor expanded in x around 0 74.5%
Final simplification81.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.038) (not (<= y 0.08))) (* x (cos y)) (+ x (* y (+ z (* y (+ (* x -0.5) (* (* y z) -0.16666666666666666))))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.038) || !(y <= 0.08)) {
tmp = x * cos(y);
} else {
tmp = x + (y * (z + (y * ((x * -0.5) + ((y * z) * -0.16666666666666666)))));
}
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.038d0)) .or. (.not. (y <= 0.08d0))) then
tmp = x * cos(y)
else
tmp = x + (y * (z + (y * ((x * (-0.5d0)) + ((y * z) * (-0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.038) || !(y <= 0.08)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * (z + (y * ((x * -0.5) + ((y * z) * -0.16666666666666666)))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.038) or not (y <= 0.08): tmp = x * math.cos(y) else: tmp = x + (y * (z + (y * ((x * -0.5) + ((y * z) * -0.16666666666666666))))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.038) || !(y <= 0.08)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(z + Float64(y * Float64(Float64(x * -0.5) + Float64(Float64(y * z) * -0.16666666666666666)))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.038) || ~((y <= 0.08))) tmp = x * cos(y); else tmp = x + (y * (z + (y * ((x * -0.5) + ((y * z) * -0.16666666666666666))))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.038], N[Not[LessEqual[y, 0.08]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z + N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(N[(y * z), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.038 \lor \neg \left(y \leq 0.08\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z + y \cdot \left(x \cdot -0.5 + \left(y \cdot z\right) \cdot -0.16666666666666666\right)\right)\\
\end{array}
\end{array}
if y < -0.0379999999999999991 or 0.0800000000000000017 < y Initial program 99.7%
Taylor expanded in x around inf 55.7%
if -0.0379999999999999991 < y < 0.0800000000000000017Initial program 100.0%
Taylor expanded in y around 0 99.7%
Final simplification79.1%
(FPCore (x y z) :precision binary64 (if (<= z 3.8e+112) x (* y z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 3.8e+112) {
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 <= 3.8d+112) 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 <= 3.8e+112) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 3.8e+112: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 3.8e+112) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 3.8e+112) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 3.8e+112], x, N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3.8 \cdot 10^{+112}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < 3.80000000000000008e112Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
add-cube-cbrt99.4%
associate-*r*99.4%
fma-define99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in y around 0 46.0%
if 3.80000000000000008e112 < z Initial program 99.8%
Taylor expanded in y around 0 53.9%
Taylor expanded in x around 0 43.8%
*-commutative43.8%
Simplified43.8%
Final simplification45.7%
(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.9%
Taylor expanded in y around 0 55.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.9%
+-commutative99.9%
*-commutative99.9%
add-cube-cbrt99.2%
associate-*r*99.2%
fma-define99.2%
pow299.2%
Applied egg-rr99.2%
Taylor expanded in y around 0 40.4%
herbie shell --seed 2024101
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))