
(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 9 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 (if (<= z -1.52e-149) (fma (sin y) z x) (if (<= z 4.5e-51) (* x (cos y)) (+ x (* z (sin y))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.52e-149) {
tmp = fma(sin(y), z, x);
} else if (z <= 4.5e-51) {
tmp = x * cos(y);
} else {
tmp = x + (z * sin(y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.52e-149) tmp = fma(sin(y), z, x); elseif (z <= 4.5e-51) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(z * sin(y))); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.52e-149], N[(N[Sin[y], $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[z, 4.5e-51], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.52 \cdot 10^{-149}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, z, x\right)\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{-51}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \sin y\\
\end{array}
\end{array}
if z < -1.5199999999999999e-149Initial program 99.8%
Taylor expanded in y around 0 91.5%
+-commutative91.5%
*-commutative91.5%
fma-def91.5%
Applied egg-rr91.5%
if -1.5199999999999999e-149 < z < 4.49999999999999974e-51Initial program 99.8%
Taylor expanded in x around inf 88.3%
if 4.49999999999999974e-51 < z Initial program 99.9%
Taylor expanded in y around 0 89.8%
Final simplification90.0%
(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 (* z (sin y))) (t_1 (* x (cos y))))
(if (<= y -4e+148)
t_0
(if (<= y -1.42e+20)
t_1
(if (<= y 6.5e-18)
(+ x (* y (+ z (* y (* x -0.5)))))
(if (or (<= y 1.36e+91) (not (<= y 1.7e+204))) 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 <= -4e+148) {
tmp = t_0;
} else if (y <= -1.42e+20) {
tmp = t_1;
} else if (y <= 6.5e-18) {
tmp = x + (y * (z + (y * (x * -0.5))));
} else if ((y <= 1.36e+91) || !(y <= 1.7e+204)) {
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 <= (-4d+148)) then
tmp = t_0
else if (y <= (-1.42d+20)) then
tmp = t_1
else if (y <= 6.5d-18) then
tmp = x + (y * (z + (y * (x * (-0.5d0)))))
else if ((y <= 1.36d+91) .or. (.not. (y <= 1.7d+204))) 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 <= -4e+148) {
tmp = t_0;
} else if (y <= -1.42e+20) {
tmp = t_1;
} else if (y <= 6.5e-18) {
tmp = x + (y * (z + (y * (x * -0.5))));
} else if ((y <= 1.36e+91) || !(y <= 1.7e+204)) {
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 <= -4e+148: tmp = t_0 elif y <= -1.42e+20: tmp = t_1 elif y <= 6.5e-18: tmp = x + (y * (z + (y * (x * -0.5)))) elif (y <= 1.36e+91) or not (y <= 1.7e+204): 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 <= -4e+148) tmp = t_0; elseif (y <= -1.42e+20) tmp = t_1; elseif (y <= 6.5e-18) tmp = Float64(x + Float64(y * Float64(z + Float64(y * Float64(x * -0.5))))); elseif ((y <= 1.36e+91) || !(y <= 1.7e+204)) 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 <= -4e+148) tmp = t_0; elseif (y <= -1.42e+20) tmp = t_1; elseif (y <= 6.5e-18) tmp = x + (y * (z + (y * (x * -0.5)))); elseif ((y <= 1.36e+91) || ~((y <= 1.7e+204))) 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, -4e+148], t$95$0, If[LessEqual[y, -1.42e+20], t$95$1, If[LessEqual[y, 6.5e-18], N[(x + N[(y * N[(z + N[(y * N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.36e+91], N[Not[LessEqual[y, 1.7e+204]], $MachinePrecision]], 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 -4 \cdot 10^{+148}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.42 \cdot 10^{+20}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-18}:\\
\;\;\;\;x + y \cdot \left(z + y \cdot \left(x \cdot -0.5\right)\right)\\
\mathbf{elif}\;y \leq 1.36 \cdot 10^{+91} \lor \neg \left(y \leq 1.7 \cdot 10^{+204}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -4.0000000000000002e148 or 6.50000000000000008e-18 < y < 1.36000000000000007e91 or 1.70000000000000005e204 < y Initial program 99.6%
Taylor expanded in x around 0 69.3%
if -4.0000000000000002e148 < y < -1.42e20 or 1.36000000000000007e91 < y < 1.70000000000000005e204Initial program 99.7%
Taylor expanded in x around inf 70.2%
if -1.42e20 < y < 6.50000000000000008e-18Initial program 100.0%
Taylor expanded in y around 0 98.6%
+-commutative98.6%
*-commutative98.6%
associate-*r*98.6%
unpow298.6%
associate-*r*98.6%
distribute-rgt-out98.6%
*-commutative98.6%
Simplified98.6%
Final simplification85.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.9e-149) (not (<= z 8.5e-53))) (+ x (* z (sin y))) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.9e-149) || !(z <= 8.5e-53)) {
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 <= (-3.9d-149)) .or. (.not. (z <= 8.5d-53))) 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 <= -3.9e-149) || !(z <= 8.5e-53)) {
tmp = x + (z * Math.sin(y));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.9e-149) or not (z <= 8.5e-53): tmp = x + (z * math.sin(y)) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.9e-149) || !(z <= 8.5e-53)) 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 <= -3.9e-149) || ~((z <= 8.5e-53))) tmp = x + (z * sin(y)); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.9e-149], N[Not[LessEqual[z, 8.5e-53]], $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 -3.9 \cdot 10^{-149} \lor \neg \left(z \leq 8.5 \cdot 10^{-53}\right):\\
\;\;\;\;x + z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -3.9000000000000002e-149 or 8.50000000000000044e-53 < z Initial program 99.8%
Taylor expanded in y around 0 90.8%
if -3.9000000000000002e-149 < z < 8.50000000000000044e-53Initial program 99.8%
Taylor expanded in x around inf 88.3%
Final simplification90.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.42e+20) (not (<= y 1050000000.0))) (* x (cos y)) (+ x (* y (+ z (* y (* x -0.5)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.42e+20) || !(y <= 1050000000.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 <= (-1.42d+20)) .or. (.not. (y <= 1050000000.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 <= -1.42e+20) || !(y <= 1050000000.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 <= -1.42e+20) or not (y <= 1050000000.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 <= -1.42e+20) || !(y <= 1050000000.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 <= -1.42e+20) || ~((y <= 1050000000.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, -1.42e+20], N[Not[LessEqual[y, 1050000000.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 -1.42 \cdot 10^{+20} \lor \neg \left(y \leq 1050000000\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 < -1.42e20 or 1.05e9 < y Initial program 99.6%
Taylor expanded in x around inf 50.6%
if -1.42e20 < y < 1.05e9Initial program 100.0%
Taylor expanded in y around 0 97.3%
+-commutative97.3%
*-commutative97.3%
associate-*r*97.3%
unpow297.3%
associate-*r*97.3%
distribute-rgt-out97.3%
*-commutative97.3%
Simplified97.3%
Final simplification77.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.45e-119) x (if (<= x 1e-18) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.45e-119) {
tmp = x;
} else if (x <= 1e-18) {
tmp = y * z;
} 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-119)) then
tmp = x
else if (x <= 1d-18) then
tmp = y * z
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-119) {
tmp = x;
} else if (x <= 1e-18) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.45e-119: tmp = x elif x <= 1e-18: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.45e-119) tmp = x; elseif (x <= 1e-18) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.45e-119) tmp = x; elseif (x <= 1e-18) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.45e-119], x, If[LessEqual[x, 1e-18], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-119}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 10^{-18}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.45e-119 or 1.0000000000000001e-18 < x Initial program 99.8%
Taylor expanded in y around 0 71.6%
Taylor expanded in x around inf 52.5%
if -1.45e-119 < x < 1.0000000000000001e-18Initial program 99.8%
Taylor expanded in y around 0 56.2%
+-commutative56.2%
Simplified56.2%
Taylor expanded in y around inf 39.2%
Final simplification47.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 58.1%
+-commutative58.1%
Simplified58.1%
Final simplification58.1%
(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 80.3%
Taylor expanded in x around inf 40.1%
Final simplification40.1%
herbie shell --seed 2024027
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))