
(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 6 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%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.0021)
t_0
(if (<= y 1.32e+20)
(+ x (* y z))
(if (or (<= y 2.05e+210) (not (<= y 2.75e+287))) (* z (sin y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.0021) {
tmp = t_0;
} else if (y <= 1.32e+20) {
tmp = x + (y * z);
} else if ((y <= 2.05e+210) || !(y <= 2.75e+287)) {
tmp = 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 (y <= (-0.0021d0)) then
tmp = t_0
else if (y <= 1.32d+20) then
tmp = x + (y * z)
else if ((y <= 2.05d+210) .or. (.not. (y <= 2.75d+287))) then
tmp = 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 (y <= -0.0021) {
tmp = t_0;
} else if (y <= 1.32e+20) {
tmp = x + (y * z);
} else if ((y <= 2.05e+210) || !(y <= 2.75e+287)) {
tmp = z * Math.sin(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if y <= -0.0021: tmp = t_0 elif y <= 1.32e+20: tmp = x + (y * z) elif (y <= 2.05e+210) or not (y <= 2.75e+287): tmp = 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 (y <= -0.0021) tmp = t_0; elseif (y <= 1.32e+20) tmp = Float64(x + Float64(y * z)); elseif ((y <= 2.05e+210) || !(y <= 2.75e+287)) tmp = 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 (y <= -0.0021) tmp = t_0; elseif (y <= 1.32e+20) tmp = x + (y * z); elseif ((y <= 2.05e+210) || ~((y <= 2.75e+287))) tmp = 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[y, -0.0021], t$95$0, If[LessEqual[y, 1.32e+20], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 2.05e+210], N[Not[LessEqual[y, 2.75e+287]], $MachinePrecision]], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.0021:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.32 \cdot 10^{+20}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{elif}\;y \leq 2.05 \cdot 10^{+210} \lor \neg \left(y \leq 2.75 \cdot 10^{+287}\right):\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -0.00209999999999999987 or 2.05e210 < y < 2.75e287Initial program 99.6%
Taylor expanded in x around inf 66.6%
if -0.00209999999999999987 < y < 1.32e20Initial program 100.0%
Taylor expanded in y around 0 97.8%
+-commutative97.8%
Simplified97.8%
if 1.32e20 < y < 2.05e210 or 2.75e287 < y Initial program 99.5%
Taylor expanded in x around 0 62.7%
Final simplification84.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.0003)
t_0
(if (<= y 1.32e+20)
(fma y z x)
(if (or (<= y 1.85e+211) (not (<= y 2.65e+287))) (* z (sin y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.0003) {
tmp = t_0;
} else if (y <= 1.32e+20) {
tmp = fma(y, z, x);
} else if ((y <= 1.85e+211) || !(y <= 2.65e+287)) {
tmp = z * sin(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.0003) tmp = t_0; elseif (y <= 1.32e+20) tmp = fma(y, z, x); elseif ((y <= 1.85e+211) || !(y <= 2.65e+287)) tmp = Float64(z * sin(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, -0.0003], t$95$0, If[LessEqual[y, 1.32e+20], N[(y * z + x), $MachinePrecision], If[Or[LessEqual[y, 1.85e+211], N[Not[LessEqual[y, 2.65e+287]], $MachinePrecision]], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.0003:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.32 \cdot 10^{+20}:\\
\;\;\;\;\mathsf{fma}\left(y, z, x\right)\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{+211} \lor \neg \left(y \leq 2.65 \cdot 10^{+287}\right):\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -2.99999999999999974e-4 or 1.85000000000000005e211 < y < 2.6499999999999998e287Initial program 99.6%
Taylor expanded in x around inf 66.6%
if -2.99999999999999974e-4 < y < 1.32e20Initial program 100.0%
Taylor expanded in y around 0 97.8%
+-commutative97.8%
fma-def97.8%
Simplified97.8%
if 1.32e20 < y < 1.85000000000000005e211 or 2.6499999999999998e287 < y Initial program 99.5%
Taylor expanded in x around 0 62.7%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00012) (not (<= y 6.4e-35))) (* x (cos y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00012) || !(y <= 6.4e-35)) {
tmp = x * cos(y);
} else {
tmp = x + (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 ((y <= (-0.00012d0)) .or. (.not. (y <= 6.4d-35))) then
tmp = x * cos(y)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00012) || !(y <= 6.4e-35)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00012) or not (y <= 6.4e-35): tmp = x * math.cos(y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00012) || !(y <= 6.4e-35)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00012) || ~((y <= 6.4e-35))) tmp = x * cos(y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00012], N[Not[LessEqual[y, 6.4e-35]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00012 \lor \neg \left(y \leq 6.4 \cdot 10^{-35}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1.20000000000000003e-4 or 6.3999999999999996e-35 < y Initial program 99.6%
Taylor expanded in x around inf 57.9%
if -1.20000000000000003e-4 < y < 6.3999999999999996e-35Initial program 100.0%
Taylor expanded in y around 0 100.0%
+-commutative100.0%
Simplified100.0%
Final simplification81.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 59.9%
+-commutative59.9%
Simplified59.9%
Final simplification59.9%
(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 x around 0 36.3%
Taylor expanded in y around 0 19.4%
Final simplification19.4%
herbie shell --seed 2024019
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))