
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * 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 = (x + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * 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 = (x + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (+ x (+ (* z (cos y)) (sin y))))
double code(double x, double y, double z) {
return x + ((z * cos(y)) + 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 + ((z * cos(y)) + sin(y))
end function
public static double code(double x, double y, double z) {
return x + ((z * Math.cos(y)) + Math.sin(y));
}
def code(x, y, z): return x + ((z * math.cos(y)) + math.sin(y))
function code(x, y, z) return Float64(x + Float64(Float64(z * cos(y)) + sin(y))) end
function tmp = code(x, y, z) tmp = x + ((z * cos(y)) + sin(y)); end
code[x_, y_, z_] := N[(x + N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(z \cdot \cos y + \sin y\right)
\end{array}
Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
fma-undefine99.9%
Applied egg-rr99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -480.0) (not (<= z 9.5e-24))) (+ x (* z (cos y))) (+ x (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -480.0) || !(z <= 9.5e-24)) {
tmp = x + (z * cos(y));
} else {
tmp = x + 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 ((z <= (-480.0d0)) .or. (.not. (z <= 9.5d-24))) then
tmp = x + (z * cos(y))
else
tmp = x + sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -480.0) || !(z <= 9.5e-24)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = x + Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -480.0) or not (z <= 9.5e-24): tmp = x + (z * math.cos(y)) else: tmp = x + math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -480.0) || !(z <= 9.5e-24)) tmp = Float64(x + Float64(z * cos(y))); else tmp = Float64(x + sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -480.0) || ~((z <= 9.5e-24))) tmp = x + (z * cos(y)); else tmp = x + sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -480.0], N[Not[LessEqual[z, 9.5e-24]], $MachinePrecision]], N[(x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -480 \lor \neg \left(z \leq 9.5 \cdot 10^{-24}\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \sin y\\
\end{array}
\end{array}
if z < -480 or 9.50000000000000029e-24 < z Initial program 99.9%
associate-+l+99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in z around inf 99.9%
if -480 < z < 9.50000000000000029e-24Initial program 100.0%
Taylor expanded in z around 0 92.6%
+-commutative92.6%
Simplified92.6%
Final simplification96.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -300000000.0) (not (<= z 1.55e+36))) (* z (cos y)) (+ x (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -300000000.0) || !(z <= 1.55e+36)) {
tmp = z * cos(y);
} else {
tmp = x + 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 ((z <= (-300000000.0d0)) .or. (.not. (z <= 1.55d+36))) then
tmp = z * cos(y)
else
tmp = x + sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -300000000.0) || !(z <= 1.55e+36)) {
tmp = z * Math.cos(y);
} else {
tmp = x + Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -300000000.0) or not (z <= 1.55e+36): tmp = z * math.cos(y) else: tmp = x + math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -300000000.0) || !(z <= 1.55e+36)) tmp = Float64(z * cos(y)); else tmp = Float64(x + sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -300000000.0) || ~((z <= 1.55e+36))) tmp = z * cos(y); else tmp = x + sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -300000000.0], N[Not[LessEqual[z, 1.55e+36]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -300000000 \lor \neg \left(z \leq 1.55 \cdot 10^{+36}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \sin y\\
\end{array}
\end{array}
if z < -3e8 or 1.55e36 < z Initial program 99.9%
Taylor expanded in z around -inf 99.8%
mul-1-neg99.8%
distribute-rgt-neg-in99.8%
distribute-lft-out99.8%
mul-1-neg99.8%
remove-double-neg99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in z around inf 81.0%
if -3e8 < z < 1.55e36Initial program 100.0%
Taylor expanded in z around 0 92.3%
+-commutative92.3%
Simplified92.3%
Final simplification86.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.8e-13) (not (<= x 2.1e-27))) (+ x z) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-13) || !(x <= 2.1e-27)) {
tmp = x + z;
} else {
tmp = z * 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 ((x <= (-5.8d-13)) .or. (.not. (x <= 2.1d-27))) then
tmp = x + z
else
tmp = z * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-13) || !(x <= 2.1e-27)) {
tmp = x + z;
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.8e-13) or not (x <= 2.1e-27): tmp = x + z else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.8e-13) || !(x <= 2.1e-27)) tmp = Float64(x + z); else tmp = Float64(z * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.8e-13) || ~((x <= 2.1e-27))) tmp = x + z; else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.8e-13], N[Not[LessEqual[x, 2.1e-27]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-13} \lor \neg \left(x \leq 2.1 \cdot 10^{-27}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -5.7999999999999995e-13 or 2.10000000000000015e-27 < x Initial program 100.0%
Taylor expanded in y around 0 88.8%
+-commutative88.8%
Simplified88.8%
if -5.7999999999999995e-13 < x < 2.10000000000000015e-27Initial program 99.9%
Taylor expanded in z around -inf 99.8%
mul-1-neg99.8%
distribute-rgt-neg-in99.8%
distribute-lft-out99.8%
mul-1-neg99.8%
remove-double-neg99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in z around inf 65.8%
Final simplification78.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -57000000000.0) (not (<= y 3.1e+51))) (+ x z) (+ x (+ z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -57000000000.0) || !(y <= 3.1e+51)) {
tmp = x + z;
} else {
tmp = x + (z + 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 <= (-57000000000.0d0)) .or. (.not. (y <= 3.1d+51))) then
tmp = x + z
else
tmp = x + (z + y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -57000000000.0) || !(y <= 3.1e+51)) {
tmp = x + z;
} else {
tmp = x + (z + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -57000000000.0) or not (y <= 3.1e+51): tmp = x + z else: tmp = x + (z + y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -57000000000.0) || !(y <= 3.1e+51)) tmp = Float64(x + z); else tmp = Float64(x + Float64(z + y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -57000000000.0) || ~((y <= 3.1e+51))) tmp = x + z; else tmp = x + (z + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -57000000000.0], N[Not[LessEqual[y, 3.1e+51]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(x + N[(z + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -57000000000 \lor \neg \left(y \leq 3.1 \cdot 10^{+51}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;x + \left(z + y\right)\\
\end{array}
\end{array}
if y < -5.7e10 or 3.10000000000000011e51 < y Initial program 99.8%
Taylor expanded in y around 0 47.1%
+-commutative47.1%
Simplified47.1%
if -5.7e10 < y < 3.10000000000000011e51Initial program 100.0%
Taylor expanded in y around 0 93.5%
+-commutative93.5%
Simplified93.5%
Final simplification72.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -4e-163) (not (<= x 2.3e-96))) (+ x z) (+ z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4e-163) || !(x <= 2.3e-96)) {
tmp = x + z;
} else {
tmp = z + 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 <= (-4d-163)) .or. (.not. (x <= 2.3d-96))) then
tmp = x + z
else
tmp = z + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4e-163) || !(x <= 2.3e-96)) {
tmp = x + z;
} else {
tmp = z + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4e-163) or not (x <= 2.3e-96): tmp = x + z else: tmp = z + y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4e-163) || !(x <= 2.3e-96)) tmp = Float64(x + z); else tmp = Float64(z + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4e-163) || ~((x <= 2.3e-96))) tmp = x + z; else tmp = z + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4e-163], N[Not[LessEqual[x, 2.3e-96]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(z + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-163} \lor \neg \left(x \leq 2.3 \cdot 10^{-96}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;z + y\\
\end{array}
\end{array}
if x < -3.99999999999999969e-163 or 2.3e-96 < x Initial program 99.9%
Taylor expanded in y around 0 76.6%
+-commutative76.6%
Simplified76.6%
if -3.99999999999999969e-163 < x < 2.3e-96Initial program 99.9%
add-cube-cbrt98.6%
pow398.6%
Applied egg-rr98.6%
Taylor expanded in x around 0 98.0%
+-commutative98.0%
Simplified98.0%
Taylor expanded in y around 0 55.2%
Final simplification71.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.65e+50) x (if (<= x 1150000000.0) (+ z y) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.65e+50) {
tmp = x;
} else if (x <= 1150000000.0) {
tmp = z + y;
} 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.65d+50)) then
tmp = x
else if (x <= 1150000000.0d0) then
tmp = z + y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.65e+50) {
tmp = x;
} else if (x <= 1150000000.0) {
tmp = z + y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.65e+50: tmp = x elif x <= 1150000000.0: tmp = z + y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.65e+50) tmp = x; elseif (x <= 1150000000.0) tmp = Float64(z + y); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.65e+50) tmp = x; elseif (x <= 1150000000.0) tmp = z + y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.65e+50], x, If[LessEqual[x, 1150000000.0], N[(z + y), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{+50}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1150000000:\\
\;\;\;\;z + y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.65e50 or 1.15e9 < x Initial program 100.0%
Taylor expanded in x around inf 78.7%
if -1.65e50 < x < 1.15e9Initial program 99.9%
add-cube-cbrt98.5%
pow398.5%
Applied egg-rr98.5%
Taylor expanded in x around 0 89.7%
+-commutative89.7%
Simplified89.7%
Taylor expanded in y around 0 49.0%
Final simplification62.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.65e+48) x (if (<= x 175000000000.0) z x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.65e+48) {
tmp = x;
} else if (x <= 175000000000.0) {
tmp = 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.65d+48)) then
tmp = x
else if (x <= 175000000000.0d0) then
tmp = 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.65e+48) {
tmp = x;
} else if (x <= 175000000000.0) {
tmp = z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.65e+48: tmp = x elif x <= 175000000000.0: tmp = z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.65e+48) tmp = x; elseif (x <= 175000000000.0) tmp = z; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.65e+48) tmp = x; elseif (x <= 175000000000.0) tmp = z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.65e+48], x, If[LessEqual[x, 175000000000.0], z, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{+48}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 175000000000:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.65000000000000011e48 or 1.75e11 < x Initial program 100.0%
Taylor expanded in x around inf 78.7%
if -1.65000000000000011e48 < x < 1.75e11Initial program 99.9%
add-cube-cbrt98.5%
pow398.5%
Applied egg-rr98.5%
Taylor expanded in x around 0 89.7%
+-commutative89.7%
Simplified89.7%
Taylor expanded in y around 0 41.9%
(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%
Taylor expanded in x around inf 41.0%
herbie shell --seed 2024085
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
:precision binary64
(+ (+ x (sin y)) (* z (cos y))))