
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + 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 * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 98.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
unsub-neg98.0%
+-commutative98.0%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -4.3e+105) (* x z) (if (or (<= x -1.5e-9) (not (<= x 1.55e-114))) (* x y) (- z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.3e+105) {
tmp = x * z;
} else if ((x <= -1.5e-9) || !(x <= 1.55e-114)) {
tmp = x * y;
} else {
tmp = -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.3d+105)) then
tmp = x * z
else if ((x <= (-1.5d-9)) .or. (.not. (x <= 1.55d-114))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.3e+105) {
tmp = x * z;
} else if ((x <= -1.5e-9) || !(x <= 1.55e-114)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.3e+105: tmp = x * z elif (x <= -1.5e-9) or not (x <= 1.55e-114): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.3e+105) tmp = Float64(x * z); elseif ((x <= -1.5e-9) || !(x <= 1.55e-114)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.3e+105) tmp = x * z; elseif ((x <= -1.5e-9) || ~((x <= 1.55e-114))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.3e+105], N[(x * z), $MachinePrecision], If[Or[LessEqual[x, -1.5e-9], N[Not[LessEqual[x, 1.55e-114]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.3 \cdot 10^{+105}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.5 \cdot 10^{-9} \lor \neg \left(x \leq 1.55 \cdot 10^{-114}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.3000000000000002e105Initial program 92.7%
Taylor expanded in y around 0 62.6%
Taylor expanded in x around inf 62.6%
*-commutative62.6%
Simplified62.6%
if -4.3000000000000002e105 < x < -1.49999999999999999e-9 or 1.55e-114 < x Initial program 98.1%
Taylor expanded in y around inf 57.7%
if -1.49999999999999999e-9 < x < 1.55e-114Initial program 100.0%
Taylor expanded in x around 0 78.2%
neg-mul-178.2%
Simplified78.2%
Final simplification67.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.022))) (* x (+ z y)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 0.022)) {
tmp = x * (z + 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 ((x <= (-1.0d0)) .or. (.not. (x <= 0.022d0))) then
tmp = x * (z + 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 ((x <= -1.0) || !(x <= 0.022)) {
tmp = x * (z + y);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 0.022): tmp = x * (z + y) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.022)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.022))) tmp = x * (z + y); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.022]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.022\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -1 or 0.021999999999999999 < x Initial program 95.7%
Taylor expanded in x around inf 97.9%
+-commutative97.9%
Simplified97.9%
if -1 < x < 0.021999999999999999Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 99.7%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.5e-38) (not (<= z 5.6e-21))) (* z (+ x -1.0)) (* x (+ z y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e-38) || !(z <= 5.6e-21)) {
tmp = z * (x + -1.0);
} 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 ((z <= (-8.5d-38)) .or. (.not. (z <= 5.6d-21))) then
tmp = z * (x + (-1.0d0))
else
tmp = x * (z + y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e-38) || !(z <= 5.6e-21)) {
tmp = z * (x + -1.0);
} else {
tmp = x * (z + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.5e-38) or not (z <= 5.6e-21): tmp = z * (x + -1.0) else: tmp = x * (z + y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.5e-38) || !(z <= 5.6e-21)) tmp = Float64(z * Float64(x + -1.0)); else tmp = Float64(x * Float64(z + y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8.5e-38) || ~((z <= 5.6e-21))) tmp = z * (x + -1.0); else tmp = x * (z + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.5e-38], N[Not[LessEqual[z, 5.6e-21]], $MachinePrecision]], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{-38} \lor \neg \left(z \leq 5.6 \cdot 10^{-21}\right):\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z + y\right)\\
\end{array}
\end{array}
if z < -8.50000000000000046e-38 or 5.60000000000000008e-21 < z Initial program 96.5%
Taylor expanded in y around 0 87.0%
if -8.50000000000000046e-38 < z < 5.60000000000000008e-21Initial program 100.0%
Taylor expanded in x around inf 82.0%
+-commutative82.0%
Simplified82.0%
Final simplification84.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.2e-14) (not (<= x 1.75e-113))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.2e-14) || !(x <= 1.75e-113)) {
tmp = x * (z + y);
} else {
tmp = -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 <= (-7.2d-14)) .or. (.not. (x <= 1.75d-113))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7.2e-14) || !(x <= 1.75e-113)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.2e-14) or not (x <= 1.75e-113): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.2e-14) || !(x <= 1.75e-113)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.2e-14) || ~((x <= 1.75e-113))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.2e-14], N[Not[LessEqual[x, 1.75e-113]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-14} \lor \neg \left(x \leq 1.75 \cdot 10^{-113}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -7.1999999999999996e-14 or 1.75000000000000014e-113 < x Initial program 96.6%
Taylor expanded in x around inf 89.0%
+-commutative89.0%
Simplified89.0%
if -7.1999999999999996e-14 < x < 1.75000000000000014e-113Initial program 100.0%
Taylor expanded in x around 0 78.2%
neg-mul-178.2%
Simplified78.2%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.2e-14) (not (<= x 5.6e-114))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.2e-14) || !(x <= 5.6e-114)) {
tmp = x * y;
} else {
tmp = -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 <= (-9.2d-14)) .or. (.not. (x <= 5.6d-114))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9.2e-14) || !(x <= 5.6e-114)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.2e-14) or not (x <= 5.6e-114): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.2e-14) || !(x <= 5.6e-114)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9.2e-14) || ~((x <= 5.6e-114))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.2e-14], N[Not[LessEqual[x, 5.6e-114]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.2 \cdot 10^{-14} \lor \neg \left(x \leq 5.6 \cdot 10^{-114}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -9.19999999999999993e-14 or 5.6000000000000003e-114 < x Initial program 96.6%
Taylor expanded in y around inf 53.9%
if -9.19999999999999993e-14 < x < 5.6000000000000003e-114Initial program 100.0%
Taylor expanded in x around 0 78.2%
neg-mul-178.2%
Simplified78.2%
Final simplification64.3%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 40.1%
neg-mul-140.1%
Simplified40.1%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 40.1%
neg-mul-140.1%
Simplified40.1%
neg-sub040.1%
sub-neg40.1%
add-sqr-sqrt22.5%
sqrt-unprod15.6%
sqr-neg15.6%
sqrt-unprod1.0%
add-sqr-sqrt2.5%
Applied egg-rr2.5%
+-lft-identity2.5%
Simplified2.5%
herbie shell --seed 2024116
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))