
(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 6 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 97.2%
*-commutative97.2%
distribute-rgt-out--97.2%
cancel-sign-sub-inv97.2%
metadata-eval97.2%
neg-mul-197.2%
associate-+r+97.2%
unsub-neg97.2%
+-commutative97.2%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -2.8e+121)
(* x z)
(if (<= x -2.3e-9)
(* x y)
(if (<= x 5e-44) (- z) (if (<= x 2.7e+214) (* x y) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.8e+121) {
tmp = x * z;
} else if (x <= -2.3e-9) {
tmp = x * y;
} else if (x <= 5e-44) {
tmp = -z;
} else if (x <= 2.7e+214) {
tmp = x * 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.8d+121)) then
tmp = x * z
else if (x <= (-2.3d-9)) then
tmp = x * y
else if (x <= 5d-44) then
tmp = -z
else if (x <= 2.7d+214) then
tmp = x * 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.8e+121) {
tmp = x * z;
} else if (x <= -2.3e-9) {
tmp = x * y;
} else if (x <= 5e-44) {
tmp = -z;
} else if (x <= 2.7e+214) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.8e+121: tmp = x * z elif x <= -2.3e-9: tmp = x * y elif x <= 5e-44: tmp = -z elif x <= 2.7e+214: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.8e+121) tmp = Float64(x * z); elseif (x <= -2.3e-9) tmp = Float64(x * y); elseif (x <= 5e-44) tmp = Float64(-z); elseif (x <= 2.7e+214) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.8e+121) tmp = x * z; elseif (x <= -2.3e-9) tmp = x * y; elseif (x <= 5e-44) tmp = -z; elseif (x <= 2.7e+214) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.8e+121], N[(x * z), $MachinePrecision], If[LessEqual[x, -2.3e-9], N[(x * y), $MachinePrecision], If[LessEqual[x, 5e-44], (-z), If[LessEqual[x, 2.7e+214], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{+121}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -2.3 \cdot 10^{-9}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-44}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{+214}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -2.80000000000000006e121 or 2.70000000000000009e214 < x Initial program 93.5%
Taylor expanded in y around 0 73.2%
Taylor expanded in x around inf 73.2%
*-commutative73.2%
Simplified73.2%
if -2.80000000000000006e121 < x < -2.2999999999999999e-9 or 5.00000000000000039e-44 < x < 2.70000000000000009e214Initial program 96.4%
Taylor expanded in y around inf 66.6%
if -2.2999999999999999e-9 < x < 5.00000000000000039e-44Initial program 100.0%
Taylor expanded in x around 0 76.7%
mul-1-neg76.7%
Simplified76.7%
Final simplification72.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -8e-11) (not (<= x 6.8e-46))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8e-11) || !(x <= 6.8e-46)) {
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 <= (-8d-11)) .or. (.not. (x <= 6.8d-46))) 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 <= -8e-11) || !(x <= 6.8e-46)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8e-11) or not (x <= 6.8e-46): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8e-11) || !(x <= 6.8e-46)) 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 <= -8e-11) || ~((x <= 6.8e-46))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8e-11], N[Not[LessEqual[x, 6.8e-46]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{-11} \lor \neg \left(x \leq 6.8 \cdot 10^{-46}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -7.99999999999999952e-11 or 6.79999999999999992e-46 < x Initial program 95.2%
Taylor expanded in x around inf 99.0%
+-commutative99.0%
Simplified99.0%
if -7.99999999999999952e-11 < x < 6.79999999999999992e-46Initial program 100.0%
Taylor expanded in x around 0 76.7%
mul-1-neg76.7%
Simplified76.7%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.7e-10) (not (<= x 1.55e-47))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e-10) || !(x <= 1.55e-47)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.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) :: tmp
if ((x <= (-1.7d-10)) .or. (.not. (x <= 1.55d-47))) then
tmp = x * (z + y)
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e-10) || !(x <= 1.55e-47)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.7e-10) or not (x <= 1.55e-47): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.7e-10) || !(x <= 1.55e-47)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.7e-10) || ~((x <= 1.55e-47))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.7e-10], N[Not[LessEqual[x, 1.55e-47]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{-10} \lor \neg \left(x \leq 1.55 \cdot 10^{-47}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -1.70000000000000007e-10 or 1.5499999999999999e-47 < x Initial program 95.2%
Taylor expanded in x around inf 99.0%
+-commutative99.0%
Simplified99.0%
if -1.70000000000000007e-10 < x < 1.5499999999999999e-47Initial program 100.0%
Taylor expanded in y around 0 77.4%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.3e-9) (not (<= x 1.5e-43))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.3e-9) || !(x <= 1.5e-43)) {
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 <= (-1.3d-9)) .or. (.not. (x <= 1.5d-43))) 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 <= -1.3e-9) || !(x <= 1.5e-43)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.3e-9) or not (x <= 1.5e-43): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.3e-9) || !(x <= 1.5e-43)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.3e-9) || ~((x <= 1.5e-43))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.3e-9], N[Not[LessEqual[x, 1.5e-43]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{-9} \lor \neg \left(x \leq 1.5 \cdot 10^{-43}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.3000000000000001e-9 or 1.50000000000000002e-43 < x Initial program 95.2%
Taylor expanded in y around inf 53.5%
if -1.3000000000000001e-9 < x < 1.50000000000000002e-43Initial program 100.0%
Taylor expanded in x around 0 76.7%
mul-1-neg76.7%
Simplified76.7%
Final simplification63.5%
(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 97.2%
Taylor expanded in x around 0 34.7%
mul-1-neg34.7%
Simplified34.7%
Final simplification34.7%
herbie shell --seed 2024020
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))