
(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 (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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= x -4.5e-21) (+ (+ x (sin y)) z) (if (<= x 4.1e+14) (+ (sin y) (* z (cos y))) (+ x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.5e-21) {
tmp = (x + sin(y)) + z;
} else if (x <= 4.1e+14) {
tmp = sin(y) + (z * cos(y));
} else {
tmp = x + 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 (x <= (-4.5d-21)) then
tmp = (x + sin(y)) + z
else if (x <= 4.1d+14) then
tmp = sin(y) + (z * cos(y))
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.5e-21) {
tmp = (x + Math.sin(y)) + z;
} else if (x <= 4.1e+14) {
tmp = Math.sin(y) + (z * Math.cos(y));
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.5e-21: tmp = (x + math.sin(y)) + z elif x <= 4.1e+14: tmp = math.sin(y) + (z * math.cos(y)) else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.5e-21) tmp = Float64(Float64(x + sin(y)) + z); elseif (x <= 4.1e+14) tmp = Float64(sin(y) + Float64(z * cos(y))); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.5e-21) tmp = (x + sin(y)) + z; elseif (x <= 4.1e+14) tmp = sin(y) + (z * cos(y)); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.5e-21], N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision], If[LessEqual[x, 4.1e+14], N[(N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{-21}:\\
\;\;\;\;\left(x + \sin y\right) + z\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{+14}:\\
\;\;\;\;\sin y + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if x < -4.49999999999999968e-21Initial program 99.9%
Taylor expanded in y around 0 89.5%
if -4.49999999999999968e-21 < x < 4.1e14Initial program 99.9%
Taylor expanded in x around 0 92.5%
if 4.1e14 < x Initial program 99.9%
Taylor expanded in y around 0 86.4%
+-commutative86.4%
Simplified86.4%
Final simplification90.3%
(FPCore (x y z)
:precision binary64
(if (or (<= z -1.8e+29)
(and (not (<= z 1.1e+42))
(or (<= z 9.2e+144) (not (<= z 1.35e+181)))))
(* z (cos y))
(+ (+ x (sin y)) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.8e+29) || (!(z <= 1.1e+42) && ((z <= 9.2e+144) || !(z <= 1.35e+181)))) {
tmp = z * cos(y);
} else {
tmp = (x + sin(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 <= (-1.8d+29)) .or. (.not. (z <= 1.1d+42)) .and. (z <= 9.2d+144) .or. (.not. (z <= 1.35d+181))) then
tmp = z * cos(y)
else
tmp = (x + sin(y)) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.8e+29) || (!(z <= 1.1e+42) && ((z <= 9.2e+144) || !(z <= 1.35e+181)))) {
tmp = z * Math.cos(y);
} else {
tmp = (x + Math.sin(y)) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.8e+29) or (not (z <= 1.1e+42) and ((z <= 9.2e+144) or not (z <= 1.35e+181))): tmp = z * math.cos(y) else: tmp = (x + math.sin(y)) + z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.8e+29) || (!(z <= 1.1e+42) && ((z <= 9.2e+144) || !(z <= 1.35e+181)))) tmp = Float64(z * cos(y)); else tmp = Float64(Float64(x + sin(y)) + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.8e+29) || (~((z <= 1.1e+42)) && ((z <= 9.2e+144) || ~((z <= 1.35e+181))))) tmp = z * cos(y); else tmp = (x + sin(y)) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.8e+29], And[N[Not[LessEqual[z, 1.1e+42]], $MachinePrecision], Or[LessEqual[z, 9.2e+144], N[Not[LessEqual[z, 1.35e+181]], $MachinePrecision]]]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.8 \cdot 10^{+29} \lor \neg \left(z \leq 1.1 \cdot 10^{+42}\right) \land \left(z \leq 9.2 \cdot 10^{+144} \lor \neg \left(z \leq 1.35 \cdot 10^{+181}\right)\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\left(x + \sin y\right) + z\\
\end{array}
\end{array}
if z < -1.79999999999999988e29 or 1.1000000000000001e42 < z < 9.2000000000000006e144 or 1.35000000000000004e181 < z Initial program 99.8%
Taylor expanded in z around inf 87.8%
if -1.79999999999999988e29 < z < 1.1000000000000001e42 or 9.2000000000000006e144 < z < 1.35000000000000004e181Initial program 100.0%
Taylor expanded in y around 0 96.6%
Final simplification92.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -20.5)
t_0
(if (<= z 4.3e+39)
(+ x (sin y))
(if (or (<= z 1.25e+145) (not (<= z 1.25e+181))) t_0 (+ x z))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -20.5) {
tmp = t_0;
} else if (z <= 4.3e+39) {
tmp = x + sin(y);
} else if ((z <= 1.25e+145) || !(z <= 1.25e+181)) {
tmp = t_0;
} else {
tmp = x + 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) :: t_0
real(8) :: tmp
t_0 = z * cos(y)
if (z <= (-20.5d0)) then
tmp = t_0
else if (z <= 4.3d+39) then
tmp = x + sin(y)
else if ((z <= 1.25d+145) .or. (.not. (z <= 1.25d+181))) then
tmp = t_0
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double tmp;
if (z <= -20.5) {
tmp = t_0;
} else if (z <= 4.3e+39) {
tmp = x + Math.sin(y);
} else if ((z <= 1.25e+145) || !(z <= 1.25e+181)) {
tmp = t_0;
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -20.5: tmp = t_0 elif z <= 4.3e+39: tmp = x + math.sin(y) elif (z <= 1.25e+145) or not (z <= 1.25e+181): tmp = t_0 else: tmp = x + z return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -20.5) tmp = t_0; elseif (z <= 4.3e+39) tmp = Float64(x + sin(y)); elseif ((z <= 1.25e+145) || !(z <= 1.25e+181)) tmp = t_0; else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -20.5) tmp = t_0; elseif (z <= 4.3e+39) tmp = x + sin(y); elseif ((z <= 1.25e+145) || ~((z <= 1.25e+181))) tmp = t_0; else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -20.5], t$95$0, If[LessEqual[z, 4.3e+39], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[z, 1.25e+145], N[Not[LessEqual[z, 1.25e+181]], $MachinePrecision]], t$95$0, N[(x + z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -20.5:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4.3 \cdot 10^{+39}:\\
\;\;\;\;x + \sin y\\
\mathbf{elif}\;z \leq 1.25 \cdot 10^{+145} \lor \neg \left(z \leq 1.25 \cdot 10^{+181}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if z < -20.5 or 4.3e39 < z < 1.24999999999999992e145 or 1.2500000000000001e181 < z Initial program 99.8%
Taylor expanded in z around inf 85.4%
if -20.5 < z < 4.3e39Initial program 100.0%
Taylor expanded in z around 0 92.1%
+-commutative92.1%
Simplified92.1%
if 1.24999999999999992e145 < z < 1.2500000000000001e181Initial program 100.0%
Taylor expanded in y around 0 88.1%
+-commutative88.1%
Simplified88.1%
Final simplification88.7%
(FPCore (x y z)
:precision binary64
(if (<= x -2.4e-48)
(+ x z)
(if (<= x 7.2e-93)
(+ (sin y) z)
(if (<= x 19000000.0) (* z (cos y)) (+ x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e-48) {
tmp = x + z;
} else if (x <= 7.2e-93) {
tmp = sin(y) + z;
} else if (x <= 19000000.0) {
tmp = z * cos(y);
} else {
tmp = x + 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 (x <= (-2.4d-48)) then
tmp = x + z
else if (x <= 7.2d-93) then
tmp = sin(y) + z
else if (x <= 19000000.0d0) then
tmp = z * cos(y)
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e-48) {
tmp = x + z;
} else if (x <= 7.2e-93) {
tmp = Math.sin(y) + z;
} else if (x <= 19000000.0) {
tmp = z * Math.cos(y);
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.4e-48: tmp = x + z elif x <= 7.2e-93: tmp = math.sin(y) + z elif x <= 19000000.0: tmp = z * math.cos(y) else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.4e-48) tmp = Float64(x + z); elseif (x <= 7.2e-93) tmp = Float64(sin(y) + z); elseif (x <= 19000000.0) tmp = Float64(z * cos(y)); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.4e-48) tmp = x + z; elseif (x <= 7.2e-93) tmp = sin(y) + z; elseif (x <= 19000000.0) tmp = z * cos(y); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.4e-48], N[(x + z), $MachinePrecision], If[LessEqual[x, 7.2e-93], N[(N[Sin[y], $MachinePrecision] + z), $MachinePrecision], If[LessEqual[x, 19000000.0], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{-48}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;x \leq 7.2 \cdot 10^{-93}:\\
\;\;\;\;\sin y + z\\
\mathbf{elif}\;x \leq 19000000:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if x < -2.4e-48 or 1.9e7 < x Initial program 99.9%
Taylor expanded in y around 0 86.0%
+-commutative86.0%
Simplified86.0%
if -2.4e-48 < x < 7.2000000000000003e-93Initial program 99.9%
Taylor expanded in y around 0 74.6%
Taylor expanded in x around 0 68.0%
if 7.2000000000000003e-93 < x < 1.9e7Initial program 99.9%
Taylor expanded in z around inf 86.3%
Final simplification79.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.2e-20) (not (<= x 14500000.0))) (+ x z) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e-20) || !(x <= 14500000.0)) {
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 <= (-6.2d-20)) .or. (.not. (x <= 14500000.0d0))) 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 <= -6.2e-20) || !(x <= 14500000.0)) {
tmp = x + z;
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.2e-20) or not (x <= 14500000.0): tmp = x + z else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.2e-20) || !(x <= 14500000.0)) 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 <= -6.2e-20) || ~((x <= 14500000.0))) tmp = x + z; else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.2e-20], N[Not[LessEqual[x, 14500000.0]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-20} \lor \neg \left(x \leq 14500000\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -6.19999999999999999e-20 or 1.45e7 < x Initial program 99.9%
Taylor expanded in y around 0 87.2%
+-commutative87.2%
Simplified87.2%
if -6.19999999999999999e-20 < x < 1.45e7Initial program 99.9%
Taylor expanded in z around inf 67.1%
Final simplification77.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.65e+50) (not (<= y 3.2))) (+ x z) (+ z (+ x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.65e+50) || !(y <= 3.2)) {
tmp = x + z;
} else {
tmp = z + (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 <= (-2.65d+50)) .or. (.not. (y <= 3.2d0))) then
tmp = x + z
else
tmp = z + (x + y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.65e+50) || !(y <= 3.2)) {
tmp = x + z;
} else {
tmp = z + (x + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.65e+50) or not (y <= 3.2): tmp = x + z else: tmp = z + (x + y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.65e+50) || !(y <= 3.2)) tmp = Float64(x + z); else tmp = Float64(z + Float64(x + y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.65e+50) || ~((y <= 3.2))) tmp = x + z; else tmp = z + (x + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.65e+50], N[Not[LessEqual[y, 3.2]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.65 \cdot 10^{+50} \lor \neg \left(y \leq 3.2\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;z + \left(x + y\right)\\
\end{array}
\end{array}
if y < -2.6500000000000001e50 or 3.2000000000000002 < y Initial program 99.9%
Taylor expanded in y around 0 43.5%
+-commutative43.5%
Simplified43.5%
if -2.6500000000000001e50 < y < 3.2000000000000002Initial program 100.0%
Taylor expanded in y around 0 91.7%
+-commutative91.7%
+-commutative91.7%
associate-+l+91.7%
Simplified91.7%
Final simplification70.8%
(FPCore (x y z) :precision binary64 (+ x z))
double code(double x, double y, double z) {
return x + 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 + z
end function
public static double code(double x, double y, double z) {
return x + z;
}
def code(x, y, z): return x + z
function code(x, y, z) return Float64(x + z) end
function tmp = code(x, y, z) tmp = x + z; end
code[x_, y_, z_] := N[(x + z), $MachinePrecision]
\begin{array}{l}
\\
x + z
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 67.6%
+-commutative67.6%
Simplified67.6%
Final simplification67.6%
(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.3%
Final simplification41.3%
herbie shell --seed 2024040
(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))))