
(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 (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) - 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)) - z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) - z;
}
def code(x, y, z): return (x * (y + z)) - z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) - z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) - z
\end{array}
Initial program 95.7%
*-commutative95.7%
sub-neg95.7%
distribute-rgt-in95.7%
metadata-eval95.7%
neg-mul-195.7%
associate-+r+95.7%
unsub-neg95.7%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -7.8e-10)
(not
(or (<= x -5.7e-34) (and (not (<= x -6.2e-74)) (<= x 1.25e-15)))))
(* x (+ y z))
(- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.8e-10) || !((x <= -5.7e-34) || (!(x <= -6.2e-74) && (x <= 1.25e-15)))) {
tmp = x * (y + z);
} 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.8d-10)) .or. (.not. (x <= (-5.7d-34)) .or. (.not. (x <= (-6.2d-74))) .and. (x <= 1.25d-15))) then
tmp = x * (y + z)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7.8e-10) || !((x <= -5.7e-34) || (!(x <= -6.2e-74) && (x <= 1.25e-15)))) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.8e-10) or not ((x <= -5.7e-34) or (not (x <= -6.2e-74) and (x <= 1.25e-15))): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.8e-10) || !((x <= -5.7e-34) || (!(x <= -6.2e-74) && (x <= 1.25e-15)))) tmp = Float64(x * Float64(y + z)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.8e-10) || ~(((x <= -5.7e-34) || (~((x <= -6.2e-74)) && (x <= 1.25e-15))))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.8e-10], N[Not[Or[LessEqual[x, -5.7e-34], And[N[Not[LessEqual[x, -6.2e-74]], $MachinePrecision], LessEqual[x, 1.25e-15]]]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.8 \cdot 10^{-10} \lor \neg \left(x \leq -5.7 \cdot 10^{-34} \lor \neg \left(x \leq -6.2 \cdot 10^{-74}\right) \land x \leq 1.25 \cdot 10^{-15}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -7.7999999999999999e-10 or -5.69999999999999974e-34 < x < -6.2000000000000003e-74 or 1.25e-15 < x Initial program 92.2%
Taylor expanded in x around inf 97.0%
+-commutative97.0%
Simplified97.0%
if -7.7999999999999999e-10 < x < -5.69999999999999974e-34 or -6.2000000000000003e-74 < x < 1.25e-15Initial program 100.0%
Taylor expanded in x around 0 73.4%
mul-1-neg73.4%
Simplified73.4%
Final simplification86.5%
(FPCore (x y z)
:precision binary64
(if (<= x -2.4e+96)
(* x z)
(if (<= x -2.4e-9)
(* x y)
(if (<= x 1.6e-16) (- z) (if (<= x 2.5e+98) (* x y) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e+96) {
tmp = x * z;
} else if (x <= -2.4e-9) {
tmp = x * y;
} else if (x <= 1.6e-16) {
tmp = -z;
} else if (x <= 2.5e+98) {
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.4d+96)) then
tmp = x * z
else if (x <= (-2.4d-9)) then
tmp = x * y
else if (x <= 1.6d-16) then
tmp = -z
else if (x <= 2.5d+98) 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.4e+96) {
tmp = x * z;
} else if (x <= -2.4e-9) {
tmp = x * y;
} else if (x <= 1.6e-16) {
tmp = -z;
} else if (x <= 2.5e+98) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.4e+96: tmp = x * z elif x <= -2.4e-9: tmp = x * y elif x <= 1.6e-16: tmp = -z elif x <= 2.5e+98: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.4e+96) tmp = Float64(x * z); elseif (x <= -2.4e-9) tmp = Float64(x * y); elseif (x <= 1.6e-16) tmp = Float64(-z); elseif (x <= 2.5e+98) 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.4e+96) tmp = x * z; elseif (x <= -2.4e-9) tmp = x * y; elseif (x <= 1.6e-16) tmp = -z; elseif (x <= 2.5e+98) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.4e+96], N[(x * z), $MachinePrecision], If[LessEqual[x, -2.4e-9], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.6e-16], (-z), If[LessEqual[x, 2.5e+98], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+96}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -2.4 \cdot 10^{-9}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{-16}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{+98}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -2.39999999999999993e96 or 2.4999999999999999e98 < x Initial program 87.8%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 62.5%
if -2.39999999999999993e96 < x < -2.4e-9 or 1.60000000000000011e-16 < x < 2.4999999999999999e98Initial program 99.9%
Taylor expanded in y around inf 62.6%
if -2.4e-9 < x < 1.60000000000000011e-16Initial program 100.0%
Taylor expanded in x around 0 70.4%
mul-1-neg70.4%
Simplified70.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.5e+23) (not (<= y 1e+33))) (* x (+ y z)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.5e+23) || !(y <= 1e+33)) {
tmp = x * (y + z);
} 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 ((y <= (-5.5d+23)) .or. (.not. (y <= 1d+33))) then
tmp = x * (y + z)
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 ((y <= -5.5e+23) || !(y <= 1e+33)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.5e+23) or not (y <= 1e+33): tmp = x * (y + z) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.5e+23) || !(y <= 1e+33)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.5e+23) || ~((y <= 1e+33))) tmp = x * (y + z); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.5e+23], N[Not[LessEqual[y, 1e+33]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{+23} \lor \neg \left(y \leq 10^{+33}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if y < -5.50000000000000004e23 or 9.9999999999999995e32 < y Initial program 91.2%
Taylor expanded in x around inf 81.7%
+-commutative81.7%
Simplified81.7%
if -5.50000000000000004e23 < y < 9.9999999999999995e32Initial program 100.0%
Taylor expanded in y around 0 88.1%
Final simplification84.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.4e+24) (not (<= y 2.4e+31))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.4e+24) || !(y <= 2.4e+31)) {
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 ((y <= (-1.4d+24)) .or. (.not. (y <= 2.4d+31))) 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 ((y <= -1.4e+24) || !(y <= 2.4e+31)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.4e+24) or not (y <= 2.4e+31): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.4e+24) || !(y <= 2.4e+31)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.4e+24) || ~((y <= 2.4e+31))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.4e+24], N[Not[LessEqual[y, 2.4e+31]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{+24} \lor \neg \left(y \leq 2.4 \cdot 10^{+31}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if y < -1.4000000000000001e24 or 2.39999999999999982e31 < y Initial program 91.2%
Taylor expanded in y around inf 68.3%
if -1.4000000000000001e24 < y < 2.39999999999999982e31Initial program 100.0%
Taylor expanded in x around 0 50.3%
mul-1-neg50.3%
Simplified50.3%
Final simplification59.0%
(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 95.7%
Taylor expanded in x around 0 35.5%
mul-1-neg35.5%
Simplified35.5%
herbie shell --seed 2024096
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))